structure changes
This commit is contained in:
91
src/common/Application.cpp
Normal file
91
src/common/Application.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Application.cpp
|
||||
*
|
||||
* Created on: 14.01.2011
|
||||
* Author: gmueller
|
||||
*/
|
||||
|
||||
#include "Application.h"
|
||||
#include "Time.h"
|
||||
#include "Network.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Application::Application() :
|
||||
running(false), master(false), time(0.0), network(&game) {
|
||||
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
|
||||
}
|
||||
|
||||
bool Application::isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
void Application::start() {
|
||||
std::cout << "[Application] start" << std::endl;
|
||||
running = true;
|
||||
}
|
||||
|
||||
void Application::stop() {
|
||||
std::cout << "[Application] stop" << std::endl;
|
||||
running = false;
|
||||
}
|
||||
|
||||
void Application::initialize(Arguments &arg) {
|
||||
std::cout << "[Application] initialize" << std::endl;
|
||||
|
||||
// setup time
|
||||
PerformanceTimer::set(0.0);
|
||||
time = PerformanceTimer::get();
|
||||
|
||||
// setup game
|
||||
game_setup(&game);
|
||||
game_reset(&game);
|
||||
|
||||
// setup schedules
|
||||
gameUpdateSchudule.setExact(true);
|
||||
gameUpdateSchudule.setInterval(0.05);
|
||||
|
||||
std::string host = arg.getString("-h", std::string());
|
||||
network.initialize(host);
|
||||
|
||||
// setup network
|
||||
if (host.empty()) {
|
||||
setMaster(true);
|
||||
} else {
|
||||
setMaster(true);
|
||||
}
|
||||
|
||||
// start
|
||||
start();
|
||||
}
|
||||
|
||||
void Application::shutdown() {
|
||||
std::cout << "[Application] shutdown" << std::endl;
|
||||
|
||||
network.shutdown();
|
||||
}
|
||||
|
||||
void Application::update() {
|
||||
// update time values
|
||||
time = PerformanceTimer::get();
|
||||
dt = time - lastTime;
|
||||
lastTime = time;
|
||||
|
||||
// network stuff
|
||||
network.service(master ? 1 : 0);
|
||||
game_update(&game, dt);
|
||||
if (master && gameUpdateSchudule.next(time)) {
|
||||
network.sendGameUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::setMaster(bool master) {
|
||||
std::cout << "[Application] setMaster = " << master << std::endl;
|
||||
|
||||
this->master = master;
|
||||
game_set_master(&game, master ? 1 : 0);
|
||||
}
|
51
src/common/Application.h
Normal file
51
src/common/Application.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Application.h
|
||||
*
|
||||
* Created on: 14.01.2011
|
||||
* Author: gmueller
|
||||
*/
|
||||
|
||||
#ifndef APPLICATION_H_
|
||||
#define APPLICATION_H_
|
||||
|
||||
#include "game.h"
|
||||
|
||||
#include "Schedule.h"
|
||||
#include "Arguments.h"
|
||||
#include "Network.h"
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application();
|
||||
virtual ~Application();
|
||||
virtual void initialize(Arguments &arg);
|
||||
virtual void update();
|
||||
virtual void shutdown();
|
||||
|
||||
bool isRunning();
|
||||
virtual void start();
|
||||
virtual void stop();
|
||||
|
||||
inline bool isMaster() {
|
||||
return master;
|
||||
}
|
||||
void setMaster(bool master);
|
||||
|
||||
inline game_t *getGame() {
|
||||
return &game;
|
||||
}
|
||||
|
||||
private:
|
||||
bool running;
|
||||
double lastTime;
|
||||
Schedule gameUpdateSchudule;
|
||||
bool master;
|
||||
|
||||
protected:
|
||||
game_t game;
|
||||
Network network;
|
||||
double dt;
|
||||
double time;
|
||||
};
|
||||
|
||||
#endif /* APPLICATION_H_ */
|
96
src/common/Arguments.h
Normal file
96
src/common/Arguments.h
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* arguments.hpp
|
||||
*
|
||||
* Created on: 06.05.2010
|
||||
* Author: gmueller
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
|
||||
class Arguments {
|
||||
std::vector<std::string> arguments;
|
||||
public:
|
||||
Arguments() {
|
||||
}
|
||||
|
||||
Arguments(size_t c, const char **v) {
|
||||
for (size_t i = 0; i < c; i++)
|
||||
arguments.push_back(v[i]);
|
||||
}
|
||||
|
||||
void add(const std::string &argument) {
|
||||
arguments.push_back(argument);
|
||||
}
|
||||
|
||||
int getCount() {
|
||||
return arguments.size();
|
||||
}
|
||||
|
||||
bool hasFlag(const std::string &flag) {
|
||||
size_t i;
|
||||
for (i = 0; i < arguments.size(); i++) {
|
||||
if (flag == arguments[i])
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int getInt(const std::string &flag, int def) {
|
||||
size_t i;
|
||||
for (i = 0; i < arguments.size(); i++) {
|
||||
if (flag == arguments[i] && (i + 1 < arguments.size()))
|
||||
return std::atoi(arguments[i + 1].c_str());
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
float getFloat(const std::string &flag, float def) {
|
||||
size_t i;
|
||||
for (i = 0; i < arguments.size(); i++) {
|
||||
if (flag == arguments[i] && (i + 1 < arguments.size()))
|
||||
return std::atof(arguments[i + 1].c_str());
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
std::string getString(const std::string &flag, const std::string &def) {
|
||||
size_t i;
|
||||
for (i = 0; i < arguments.size(); i++) {
|
||||
if (flag == arguments[i] && (i + 1 < arguments.size()))
|
||||
return std::string(arguments[i + 1]);
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
std::string getString(const std::string &flag) {
|
||||
size_t i;
|
||||
for (i = 0; i < arguments.size(); i++) {
|
||||
if (flag == arguments[i] && (i + 1 < arguments.size()))
|
||||
return std::string(arguments[i + 1]);
|
||||
}
|
||||
throw std::runtime_error("Arguments: flag " + flag + " not found");
|
||||
}
|
||||
|
||||
void getVector(const std::string &flag, std::vector<std::string> &v) {
|
||||
size_t i;
|
||||
|
||||
// find flag
|
||||
for (i = 0; i < arguments.size(); i++) {
|
||||
if (flag == arguments[i])
|
||||
break;
|
||||
}
|
||||
|
||||
for (i++; i < arguments.size(); i++) {
|
||||
if (arguments[i][0] != '-')
|
||||
v.push_back(arguments[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
313
src/common/Network.cpp
Normal file
313
src/common/Network.cpp
Normal file
@ -0,0 +1,313 @@
|
||||
/*
|
||||
* network.cpp
|
||||
*
|
||||
* Created on: 12.01.2011
|
||||
* Author: gmueller
|
||||
*/
|
||||
|
||||
#include "Network.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
Network::Network(game_t *game) :
|
||||
game(game), client_peer(0) {
|
||||
}
|
||||
|
||||
void Network::initialize(const std::string &hostname) {
|
||||
if (enet_initialize() != 0) {
|
||||
throw "failed to initialize enet";
|
||||
}
|
||||
|
||||
if (hostname.empty()) {
|
||||
std::cout << "[Network] Start server." << std::endl;
|
||||
ENetAddress address;
|
||||
|
||||
address.host = ENET_HOST_ANY;
|
||||
address.port = 1234;
|
||||
|
||||
host = enet_host_create(&address, 32, 2, 0, 0);
|
||||
if (host == NULL) {
|
||||
throw "An error occurred while trying to create an ENet server host.";
|
||||
}
|
||||
} else {
|
||||
std::cout << "[Network] Start client." << std::endl;
|
||||
ENetAddress address;
|
||||
ENetEvent event;
|
||||
|
||||
host = enet_host_create(NULL, 1, 2, 57600 / 8, 14400 / 8);
|
||||
if (host == NULL) {
|
||||
throw "An error occurred while trying to create an ENet client host.";
|
||||
}
|
||||
|
||||
std::cout << "[Network] connect to " << host << std::endl;
|
||||
enet_address_set_host(&address, hostname.c_str());
|
||||
address.port = 1234;
|
||||
|
||||
/* Initiate the connection, allocating the two channels 0 and 1. */
|
||||
client_peer = enet_host_connect(host, &address, 2, 0);
|
||||
|
||||
if (client_peer == NULL) {
|
||||
throw "No available peers for initiating an ENet connection.";
|
||||
}
|
||||
|
||||
/* Wait up to 5 seconds for the connection attempt to succeed. */
|
||||
if (enet_host_service(host, &event, 2000) > 0 && event.type
|
||||
== ENET_EVENT_TYPE_CONNECT) {
|
||||
std::cout << "[Network] connected" << host << std::endl;
|
||||
} else {
|
||||
/* Either the 5 seconds are up or a disconnect event was */
|
||||
/* received. Reset the peer in the event the 5 seconds */
|
||||
/* had run out without any significant event. */
|
||||
enet_peer_reset(client_peer);
|
||||
|
||||
throw "[Network] connection failed.";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Network::shutdown() {
|
||||
enet_host_destroy(host);
|
||||
enet_deinitialize();
|
||||
}
|
||||
|
||||
void Network::sendGameUpdates() {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
||||
if (game->player[i].status == 0)
|
||||
continue;
|
||||
player_update_message_t msg;
|
||||
msg.msg_id = MESSAGE_PLAYER_UPDATE;
|
||||
msg.player_id = game->player[i].id;
|
||||
msg.x = game->player[i].x;
|
||||
msg.y = game->player[i].y;
|
||||
msg.z = game->player[i].z;
|
||||
msg.vx = game->player[i].vx;
|
||||
msg.vy = game->player[i].vy;
|
||||
msg.vz = game->player[i].vz;
|
||||
msg.points = game->player[i].points;
|
||||
ENetPacket * packet = enet_packet_create(&msg, sizeof(msg), 0);
|
||||
enet_host_broadcast(host, 0, packet);
|
||||
}
|
||||
for (i = 0; i < GAME_TEAM_COUNT; i++) {
|
||||
team_update_message_t msg;
|
||||
msg.msg_id = MESSAGE_TEAM_UPDATE;
|
||||
msg.team_id = game->team[i].id;
|
||||
msg.points = game->team[i].points;
|
||||
msg.wins = game->team[i].wins;
|
||||
ENetPacket * packet = enet_packet_create(&msg, sizeof(msg), 0);
|
||||
enet_host_broadcast(host, 0, packet);
|
||||
}
|
||||
|
||||
enet_host_flush(host);
|
||||
}
|
||||
|
||||
void Network::dispatch(enet_uint8 *data, size_t length) {
|
||||
message_t *msg = (message_t *) data;
|
||||
switch (msg->msg_id) {
|
||||
case MESSAGE_PLAYER_SPAWN: {
|
||||
player_spawn_message_t *sm = (player_spawn_message_t *) data;
|
||||
team_t *team = game_team(game, sm->team_id);
|
||||
player_t *player = game_spawn_player_id(game, team, sm->player_id);
|
||||
break;
|
||||
}
|
||||
case MESSAGE_PLAYER_KILL: {
|
||||
player_kill_message_t *sm = (player_kill_message_t *) data;
|
||||
player_t *player = game_player(game, sm->player_id);
|
||||
player->status = 0;
|
||||
player->team = 0;
|
||||
break;
|
||||
}
|
||||
case MESSAGE_ACCEPT: {
|
||||
accept_message_t *am = (accept_message_t *) data;
|
||||
game->local_player = game_player(game, am->player_id);
|
||||
break;
|
||||
}
|
||||
case MESSAGE_PLAYER_UPDATE: {
|
||||
player_update_message_t *um = (player_update_message_t *) data;
|
||||
player_t *player = game_player(game, um->player_id);
|
||||
if (player != game->local_player) {
|
||||
player->x = um->x + um->vx * 0.0001;
|
||||
player->y = um->y + um->vy * 0.0001;
|
||||
player->z = um->z + um->vz * 0.0001;
|
||||
player->vx = um->vx;
|
||||
player->vy = um->vy;
|
||||
player->vz = um->vz;
|
||||
} else {
|
||||
if (fabs(um->x - player->x) < 10.0) {
|
||||
player->vx = um->vx + (um->x - player->x);
|
||||
} else {
|
||||
player->x = um->x;
|
||||
player->vx = um->vx;
|
||||
}
|
||||
if (fabs(um->y - player->y) < 10.0) {
|
||||
player->vy = um->vy + (um->y - player->y);
|
||||
} else {
|
||||
player->y = um->y;
|
||||
player->vy = um->vy;
|
||||
}
|
||||
if (fabs(um->z - player->z) < 10.0) {
|
||||
player->vz = um->vz + (um->z - player->z);
|
||||
} else {
|
||||
player->z = um->z;
|
||||
player->vz = um->vz;
|
||||
}
|
||||
}
|
||||
player->points = um->points;
|
||||
break;
|
||||
}
|
||||
case MESSAGE_POINT_UPDATE: {
|
||||
point_update_mesage_t *msg = (point_update_mesage_t *) data;
|
||||
point_t *p = &game->point[msg->point_index];
|
||||
p->status = msg->status;
|
||||
p->x = msg->x;
|
||||
p->y = msg->y;
|
||||
p->z = msg->z;
|
||||
break;
|
||||
}
|
||||
case MESSAGE_PLAYER_ACCELERATE: {
|
||||
player_accelerate_message_t *um = (player_accelerate_message_t *) data;
|
||||
player_t *player = game_player(game, um->player_id);
|
||||
player->vx += um->x;
|
||||
player->vy += um->y;
|
||||
player->vz += um->z;
|
||||
break;
|
||||
}
|
||||
case MESSAGE_BOMB_DROP: {
|
||||
bomb_drop_meesage_t *m = (bomb_drop_meesage_t *) data;
|
||||
bomb_t *bomb = game_spawn_bomb(game);
|
||||
if (bomb == NULL)
|
||||
return;
|
||||
bomb->x = m->x + m->vx * 0.0001;
|
||||
bomb->y = m->y + m->vy * 0.0001;
|
||||
bomb->z = m->z + m->vz * 0.0001;
|
||||
bomb->vx = m->vx;
|
||||
bomb->vy = m->vy;
|
||||
bomb->vz = m->vz;
|
||||
bomb->ttl = m->ttl;
|
||||
if (client_peer == NULL) {
|
||||
ENetPacket * packet = enet_packet_create(data, length,
|
||||
ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_host_broadcast(host, 0, packet);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MESSAGE_TEAM_UPDATE: {
|
||||
team_update_message_t *m = (team_update_message_t *) data;
|
||||
team_t *team = game_team(game, m->team_id);
|
||||
if (team == NULL)
|
||||
return;
|
||||
team->points = m->points;
|
||||
team->wins = m->wins;
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void Network::service(uint32_t timeout) {
|
||||
ENetEvent event;
|
||||
|
||||
if (host == 0)
|
||||
throw "not connected";
|
||||
|
||||
/* Wait up to 1000 milliseconds for an event. */
|
||||
while (enet_host_service(host, &event, timeout) > 0) {
|
||||
switch (event.type) {
|
||||
case ENET_EVENT_TYPE_CONNECT: {
|
||||
std::cout << "A new client connected from "
|
||||
<< event.peer->address.host << " "
|
||||
<< event.peer->address.port << std::endl;
|
||||
|
||||
// bring new client up to date
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
||||
if (game->player[i].status == 0)
|
||||
continue;
|
||||
// send player spawn message
|
||||
player_spawn_message_t spwan_msg;
|
||||
spwan_msg.msg_id = MESSAGE_PLAYER_SPAWN;
|
||||
spwan_msg.team_id = game->player[i].team->id;
|
||||
spwan_msg.player_id = game->player[i].id;
|
||||
ENetPacket * packet = enet_packet_create(&spwan_msg,
|
||||
sizeof(spwan_msg), ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(event.peer, 0, packet);
|
||||
}
|
||||
|
||||
for (i = 0; i < GAME_POINT_COUNT; i++) {
|
||||
if (game->point[i].status == 0)
|
||||
continue;
|
||||
point_update_mesage_t msg;
|
||||
msg.msg_id = MESSAGE_POINT_UPDATE;
|
||||
msg.point_index = i;
|
||||
msg.status = game->point[i].status;
|
||||
msg.x = game->point[i].x;
|
||||
msg.y = game->point[i].y;
|
||||
msg.z = game->point[i].z;
|
||||
ENetPacket * packet = enet_packet_create(&msg, sizeof(msg),
|
||||
ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(event.peer, 0, packet);
|
||||
}
|
||||
|
||||
team_t *team = game_team_with_least_players(game);
|
||||
player_t *player = game_spawn_player(game, team);
|
||||
event.peer->data = player;
|
||||
|
||||
// send player spawn message
|
||||
player_spawn_message_t spwan_msg;
|
||||
spwan_msg.msg_id = MESSAGE_PLAYER_SPAWN;
|
||||
spwan_msg.team_id = team->id;
|
||||
spwan_msg.player_id = player->id;
|
||||
ENetPacket * packet = enet_packet_create(&spwan_msg,
|
||||
sizeof(spwan_msg), ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_host_broadcast(host, 0, packet);
|
||||
|
||||
// send team and player
|
||||
accept_message_t msg;
|
||||
msg.msg_id = MESSAGE_ACCEPT;
|
||||
msg.player_id = player->id;
|
||||
packet = enet_packet_create(&msg, sizeof(msg),
|
||||
ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(event.peer, 0, packet);
|
||||
|
||||
// send state
|
||||
}
|
||||
break;
|
||||
|
||||
case ENET_EVENT_TYPE_RECEIVE: {
|
||||
dispatch(event.packet->data, event.packet->dataLength);
|
||||
enet_packet_destroy(event.packet);
|
||||
break;
|
||||
}
|
||||
case ENET_EVENT_TYPE_DISCONNECT:
|
||||
//printf("%s disconected.\n", event.peer -> data);
|
||||
{
|
||||
/* Reset the peer's client information. */
|
||||
player_t *player = (player_t *) event.peer->data;
|
||||
player->status = 0;
|
||||
player->team = 0;
|
||||
|
||||
// send player spawn message
|
||||
player_kill_message_t msg;
|
||||
msg.msg_id = MESSAGE_PLAYER_KILL;
|
||||
msg.player_id = player->id;
|
||||
ENetPacket * packet = enet_packet_create(&msg, sizeof(msg),
|
||||
ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_host_broadcast(host, 0, packet);
|
||||
}
|
||||
event.peer->data = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Network::sendMessage(uint8_t *data, size_t length) {
|
||||
if (client_peer) {
|
||||
ENetPacket * packet = enet_packet_create(data, length,
|
||||
ENET_PACKET_FLAG_RELIABLE);
|
||||
enet_peer_send(client_peer, 0, packet);
|
||||
} else {
|
||||
dispatch(data, length);
|
||||
}
|
||||
}
|
107
src/common/Network.h
Normal file
107
src/common/Network.h
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* network.h
|
||||
*
|
||||
* Created on: 12.01.2011
|
||||
* Author: gmueller
|
||||
*/
|
||||
|
||||
#ifndef NETWORK_H_
|
||||
#define NETWORK_H_
|
||||
|
||||
#include "game.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <enet/enet.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#define MESSAGE_PLAYER_SPAWN 0
|
||||
#define MESSAGE_PLAYER_KILL 1
|
||||
#define MESSAGE_ACCEPT 2
|
||||
#define MESSAGE_PLAYER_UPDATE 3
|
||||
#define MESSAGE_PLAYER_ACCELERATE 4
|
||||
#define MESSAGE_BOMB_DROP 5
|
||||
#define MESSAGE_BOMB_UPDATE 6
|
||||
#define MESSAGE_POINT_UPDATE 7
|
||||
#define MESSAGE_TEAM_UPDATE 8
|
||||
|
||||
typedef struct message_t {
|
||||
uint16_t msg_id;
|
||||
} message_t;
|
||||
|
||||
typedef struct player_spawn_message_t {
|
||||
uint16_t msg_id;
|
||||
uint8_t team_id;
|
||||
uint16_t player_id;
|
||||
} player_spawn_message_t;
|
||||
|
||||
typedef struct player_kill_message_t {
|
||||
uint16_t msg_id;
|
||||
uint16_t player_id;
|
||||
} player_kill_message_t;
|
||||
|
||||
typedef struct accept_message_t {
|
||||
uint16_t msg_id;
|
||||
uint16_t player_id;
|
||||
} accept_message_t;
|
||||
|
||||
typedef struct player_update_message_t {
|
||||
uint16_t msg_id;
|
||||
uint16_t player_id;
|
||||
unsigned int session;
|
||||
double x, y, z;
|
||||
double vx, vy, vz;
|
||||
uint16_t points;
|
||||
} player_update_message_t;
|
||||
|
||||
typedef struct player_accelerate_message_t {
|
||||
uint16_t msg_id;
|
||||
uint16_t player_id;
|
||||
double x, y, z;
|
||||
} player_accelerate_message_t;
|
||||
|
||||
typedef struct bomb_drop_meesage_t {
|
||||
uint16_t msg_id;
|
||||
double x, y, z;
|
||||
double vx, vy, vz;
|
||||
double ttl;
|
||||
} bomb_drop_meesage_t;
|
||||
|
||||
typedef struct bomb_update_meesage_t {
|
||||
uint16_t msg_id;
|
||||
uint16_t bomb_index;
|
||||
double x, y, z;
|
||||
double vx, vy, vz;
|
||||
double ttl;
|
||||
} bomb_update_meesage_t;
|
||||
|
||||
typedef struct point_update_mesage_t {
|
||||
uint16_t msg_id;
|
||||
uint16_t point_index;
|
||||
uint8_t status;
|
||||
double x, y, z;
|
||||
} point_update_meesage_t;
|
||||
|
||||
struct team_update_message_t {
|
||||
uint16_t msg_id;
|
||||
uint16_t team_id;
|
||||
uint16_t points;
|
||||
uint16_t wins;
|
||||
};
|
||||
|
||||
class Network {
|
||||
public:
|
||||
Network(game_t *game);
|
||||
void initialize(const std::string &host);
|
||||
void shutdown();
|
||||
void dispatch(uint8_t *data, size_t length);
|
||||
void service(uint32_t timeout);
|
||||
void sendGameUpdates();
|
||||
void sendMessage(uint8_t *data, size_t length);
|
||||
protected:
|
||||
game_t *game;
|
||||
ENetHost *host;
|
||||
ENetPeer *client_peer;
|
||||
};
|
||||
|
||||
#endif /* NETWORK_H_ */
|
56
src/common/Schedule.h
Normal file
56
src/common/Schedule.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Schedule.h
|
||||
*
|
||||
* Created on: 12.06.2010
|
||||
* Author: gmueller
|
||||
*/
|
||||
|
||||
#ifndef SCHEDULE_H_
|
||||
#define SCHEDULE_H_
|
||||
|
||||
class Schedule {
|
||||
double last;
|
||||
double interval;
|
||||
bool exact;
|
||||
bool paused;
|
||||
public:
|
||||
Schedule() :
|
||||
last(0.0), interval(1.0), exact(true), paused(false) {
|
||||
}
|
||||
|
||||
void init(double now) {
|
||||
last = now;
|
||||
}
|
||||
|
||||
void setInterval(double interval) {
|
||||
this->interval = interval;
|
||||
}
|
||||
|
||||
double getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
void setExact(bool exact) {
|
||||
this->exact = exact;
|
||||
}
|
||||
|
||||
void setPaused(bool paused) {
|
||||
this->paused = paused;
|
||||
}
|
||||
|
||||
bool next(double now) {
|
||||
if (now > (last + interval)) {
|
||||
if (exact)
|
||||
last += interval;
|
||||
else
|
||||
last = now;
|
||||
if (paused)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif /* SCHEDULE_H_ */
|
128
src/common/Time.cpp
Normal file
128
src/common/Time.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Timer.cpp
|
||||
*
|
||||
* Created on: 12.01.2011
|
||||
* Author: gmueller
|
||||
*/
|
||||
|
||||
#include "Time.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define MEAN_AND_LEAN
|
||||
#include <windows.h>
|
||||
|
||||
static bool _hasPerformanceCounter;
|
||||
static unsigned int _t0_32;
|
||||
static __int64 _t0_64;
|
||||
static double _resolution = 0.0;
|
||||
static bool _initialized = false;
|
||||
|
||||
static void _init() {
|
||||
|
||||
__int64 freq;
|
||||
|
||||
// Check if we have a performance counter
|
||||
if( QueryPerformanceFrequency( (LARGE_INTEGER *)&freq ) )
|
||||
{
|
||||
// Performance counter is available => use it!
|
||||
_hasPerformanceCounter = true;
|
||||
|
||||
// Counter resolution is 1 / counter frequency
|
||||
_resolution = 1.0 / (double)freq;
|
||||
|
||||
// Set start time for timer
|
||||
QueryPerformanceCounter( (LARGE_INTEGER *)&_t0_64 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// No performace counter available => use the tick counter
|
||||
_hasPerformanceCounter = 0;
|
||||
|
||||
// Counter resolution is 1 ms
|
||||
_resolution = 0.001;
|
||||
|
||||
// Set start time for timer
|
||||
_t0_32 = timeGetTime();
|
||||
}
|
||||
}
|
||||
|
||||
double PerformanceTimer::get() {
|
||||
if (_initialized == false)
|
||||
_init();
|
||||
double t;
|
||||
__int64 t_64;
|
||||
|
||||
if( _hasPerformanceCounter ) {
|
||||
QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 );
|
||||
t = (double)(t_64 - _t0_64);
|
||||
}
|
||||
else
|
||||
{
|
||||
t = (double)(timeGetTime() - _t0_32);
|
||||
}
|
||||
|
||||
// Calculate the current time in seconds
|
||||
return t * _resolution;
|
||||
}
|
||||
|
||||
void PerformanceTimer::set(double t) {
|
||||
if (_initialized == false)
|
||||
_init();
|
||||
__int64 t_64;
|
||||
|
||||
if( _hasPerformanceCounter )
|
||||
{
|
||||
QueryPerformanceCounter( (LARGE_INTEGER *)&t_64 );
|
||||
_t0_64 = t_64 - (__int64)(t/_resolution);
|
||||
}
|
||||
else
|
||||
{
|
||||
_t0_32 = timeGetTime() - (int)(t*1000.0);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
static double _resolution = 0.0;
|
||||
static long long _t0 = 0;
|
||||
static bool _initialized = false;
|
||||
|
||||
static void _init() {
|
||||
// "Resolution" is 1 us
|
||||
_resolution = 1e-6;
|
||||
|
||||
// Set start-time for timer
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, 0);
|
||||
_t0 = (long long) tv.tv_sec * (long long) 1000000 + (long long) tv.tv_usec;
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
double PerformanceTimer::get() {
|
||||
if (_initialized == false)
|
||||
_init();
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, 0);
|
||||
long long t = (long long) tv.tv_sec * (long long) 1000000
|
||||
+ (long long) tv.tv_usec;
|
||||
return (double) (t - _t0) * _resolution;
|
||||
}
|
||||
|
||||
void PerformanceTimer::set(double t) {
|
||||
if (_initialized == false)
|
||||
_init();
|
||||
long long t1;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
t1 = (long long) tv.tv_sec * (long long) 1000000 + (long long) tv.tv_usec;
|
||||
|
||||
// Calulate new starting time
|
||||
_t0 = t1 - (long long) (t / _resolution);
|
||||
}
|
||||
|
||||
#endif // else _WIN32
|
17
src/common/Time.h
Normal file
17
src/common/Time.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Timer.h
|
||||
*
|
||||
* Created on: 12.01.2011
|
||||
* Author: gmueller
|
||||
*/
|
||||
|
||||
#ifndef TIME_H_
|
||||
#define TIME_H_
|
||||
|
||||
class PerformanceTimer {
|
||||
public:
|
||||
static double get();
|
||||
static void set(double);
|
||||
};
|
||||
|
||||
#endif /* TIME_H_ */
|
19
src/common/common.h
Normal file
19
src/common/common.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef GREMLIN_COMMON_H
|
||||
#define GREMLIN_COMMON_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
typedef __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#endif
|
387
src/common/game.cpp
Normal file
387
src/common/game.cpp
Normal file
@ -0,0 +1,387 @@
|
||||
#include "game.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
double rand2() {
|
||||
float u = (float) rand() / (float) RAND_MAX;
|
||||
return 2.0 * (u - 0.5);
|
||||
}
|
||||
|
||||
void game_reset_team(team_t *team) {
|
||||
team->points = 0;
|
||||
}
|
||||
|
||||
void game_reset_player(player_t *player) {
|
||||
if (player->team) {
|
||||
player->x = player->team->x + 100;
|
||||
player->y = player->team->y;
|
||||
player->z = player->team->z;
|
||||
} else {
|
||||
player->x = 0;
|
||||
player->y = 0;
|
||||
player->z = 0;
|
||||
}
|
||||
player->vx = 0.;
|
||||
player->vy = 0.;
|
||||
player->vz = 0.;
|
||||
}
|
||||
|
||||
void game_reset_point(point_t *point) {
|
||||
point->status = 1;
|
||||
point->x = 1000 + 500.0 * rand2();
|
||||
point->y = 500.0 * rand2();
|
||||
point->z = 500.0 * rand2();
|
||||
}
|
||||
|
||||
void game_setup_team(team_t *team, uint8_t id) {
|
||||
team->id = id;
|
||||
team->color[0] = .5f + .5f * (id & (1 << 0));
|
||||
team->color[1] = .5f + .5f * (id & (1 << 1));
|
||||
team->color[2] = .5f + .5f * (id & (1 << 2));
|
||||
team->color[3] = 1.0f;
|
||||
|
||||
team->x = 2000.0 * (id & (1 << 0));
|
||||
team->y = 2000.0 * (id & (1 << 1));
|
||||
team->z = 2000.0 * (id & (1 << 2));
|
||||
|
||||
team->points = 0;
|
||||
team->wins = 0;
|
||||
}
|
||||
|
||||
void game_setup_player(player_t *player) {
|
||||
player->id = 0;
|
||||
player->status = 0;
|
||||
player->team = NULL;
|
||||
player->x = 0.0;
|
||||
player->y = 0.0;
|
||||
player->z = 0.0;
|
||||
player->vx = 0.0;
|
||||
player->vy = 0.0;
|
||||
player->vz = 0.0;
|
||||
}
|
||||
|
||||
void game_setup_point(point_t *point) {
|
||||
point->status = 0;
|
||||
point->x = 0.0;
|
||||
point->y = 0.0;
|
||||
point->z = 0.0;
|
||||
}
|
||||
|
||||
void game_setup_bomb(bomb_t *bomb) {
|
||||
bomb->status = 0;
|
||||
bomb->x = 0.0;
|
||||
bomb->y = 0.0;
|
||||
bomb->z = 0.0;
|
||||
}
|
||||
|
||||
void game_setup(game_t *game) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < GAME_TEAM_COUNT; i++)
|
||||
game_setup_team(&game->team[i], i);
|
||||
|
||||
for (i = 0; i < GAME_BOMB_COUNT; i++)
|
||||
game_setup_bomb(&game->bomb[i]);
|
||||
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++)
|
||||
game_setup_player(&game->player[i]);
|
||||
|
||||
for (i = 0; i < GAME_POINT_COUNT; i++)
|
||||
game_setup_point(&game->point[i]);
|
||||
|
||||
game->max_player_id = 0;
|
||||
game->master = 0;
|
||||
game->updateTime = 0.0;
|
||||
game->explosion_callback = 0;
|
||||
game->local_player = 0;
|
||||
}
|
||||
|
||||
void game_reset(game_t *game) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < GAME_TEAM_COUNT; i++)
|
||||
game_reset_team(&game->team[i]);
|
||||
|
||||
for (i = 0; i < GAME_BOMB_COUNT; i++)
|
||||
game_setup_bomb(&game->bomb[i]);
|
||||
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++)
|
||||
game_reset_player(&game->player[i]);
|
||||
|
||||
for (i = 0; i < GAME_POINT_COUNT; i++)
|
||||
game_reset_point(&game->point[i]);
|
||||
}
|
||||
|
||||
player_t *_game_free_player(game_t *game) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
||||
if (game->player[i].status == 0)
|
||||
return &game->player[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
player_t *game_spawn_player(game_t *game, team_t *team) {
|
||||
player_t *player = _game_free_player(game);
|
||||
player->team = team;
|
||||
player->status = 1;
|
||||
player->id = game->max_player_id++;
|
||||
game_reset_player(player);
|
||||
return player;
|
||||
}
|
||||
|
||||
player_t *game_spawn_player_id(game_t *game, team_t *team, uint16_t id) {
|
||||
player_t *player = _game_free_player(game);
|
||||
player->team = team;
|
||||
player->id = id;
|
||||
if (game->max_player_id < id)
|
||||
game->max_player_id = id;
|
||||
player->status = 1;
|
||||
player->x = team->x + 100;
|
||||
player->y = team->y;
|
||||
player->z = team->z;
|
||||
player->vx = 0.;
|
||||
player->vy = 0.;
|
||||
player->vz = 0.;
|
||||
return player;
|
||||
}
|
||||
|
||||
void game_update_players(game_t *game, double dt) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
||||
player_t *player = &game->player[i];
|
||||
if (player->status == 0)
|
||||
return;
|
||||
if (player->vx > 1000.0)
|
||||
player->vx = 1000.0;
|
||||
if (player->vy > 1000.0)
|
||||
player->vy = 1000.0;
|
||||
if (player->vz > 1000.0)
|
||||
player->vz = 1000.0;
|
||||
player->x += player->vx * dt;
|
||||
player->y += player->vy * dt;
|
||||
player->z += player->vz * dt;
|
||||
|
||||
double distance2 = pow(player->x - player->team->x, 2) + pow(player->y
|
||||
- player->team->y, 2) + pow(player->z - player->team->z, 2);
|
||||
if (distance2 < 10000) {
|
||||
player->team->points += player->points;
|
||||
player->points = 0;
|
||||
}
|
||||
|
||||
if (player->x < (-1000 + 10)) {
|
||||
player->x = (-1000 + 10);
|
||||
player->vx *= -1;
|
||||
} else if (player->x > (5000 - 10)) {
|
||||
player->x = (5000 - 10);
|
||||
player->vx *= -1;
|
||||
}
|
||||
|
||||
if (player->y < (-3000 + 10)) {
|
||||
player->y = (-3000 + 10);
|
||||
player->vy *= -1;
|
||||
} else if (player->y > (3000 - 10)) {
|
||||
player->y = (3000 - 10);
|
||||
player->vy *= -1;
|
||||
}
|
||||
|
||||
if (player->z < (-3000 + 10)) {
|
||||
player->z = (-3000 + 10);
|
||||
player->vz *= -1;
|
||||
} else if (player->z > (3000 - 10)) {
|
||||
player->z = (3000 - 10);
|
||||
player->vz *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _explode_bomb(game_t *game, bomb_t *bomb) {
|
||||
size_t i, j;
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
||||
player_t *player = &game->player[i];
|
||||
if (player->status == 0)
|
||||
continue;
|
||||
double distance2 = pow(player->x - bomb->x, 2) + pow(player->y
|
||||
- bomb->y, 2) + pow(player->z - bomb->z, 2);
|
||||
if (distance2 < pow(150., 2.)) {
|
||||
if (game->explosion_callback)
|
||||
game->explosion_callback(player->x, player->y, player->z,
|
||||
game->explosion_callback_data);
|
||||
player->x = player->team->x + 100;
|
||||
player->y = player->team->y;
|
||||
player->z = player->team->z;
|
||||
player->vx = 0.;
|
||||
player->vy = 0.;
|
||||
player->vz = 0.;
|
||||
for (j = 0; j < player->points; j++) {
|
||||
point_t *point = game_spawn_point(game);
|
||||
point->x = player->x + 20.0 * rand2();
|
||||
point->y = player->x + 20.0 * rand2();
|
||||
point->z = player->x + 20.0 * rand2();
|
||||
}
|
||||
player->points = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void game_update_bombs(game_t *game, double dt) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_BOMB_COUNT; i++) {
|
||||
bomb_t *bomb = &game->bomb[i];
|
||||
if (bomb->status == 0)
|
||||
continue;
|
||||
bomb->x += bomb->vx * dt;
|
||||
bomb->y += bomb->vy * dt;
|
||||
bomb->z += bomb->vz * dt;
|
||||
bomb->ttl -= dt;
|
||||
|
||||
if (bomb->x < (-1000 + 10)) {
|
||||
bomb->x = (-1000 + 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->x > (5000 - 10)) {
|
||||
bomb->x = (5000 - 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->y < (-3000 + 10)) {
|
||||
bomb->y = (-3000 + 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->y > (3000 - 10)) {
|
||||
bomb->y = (3000 - 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->z < (-3000 + 10)) {
|
||||
bomb->z = (-3000 + 10);
|
||||
bomb->ttl = -0.1;
|
||||
} else if (bomb->z > (3000 - 10)) {
|
||||
bomb->z = (3000 - 10);
|
||||
bomb->ttl = -0.1;
|
||||
}
|
||||
|
||||
if (bomb->ttl < 0) {
|
||||
if (bomb->status == 1) {
|
||||
if (game->explosion_callback)
|
||||
game->explosion_callback(bomb->x, bomb->y, bomb->z,
|
||||
game->explosion_callback_data);
|
||||
bomb->status = 2;
|
||||
} else if (bomb->ttl < -0.2) {
|
||||
if (game->master) {
|
||||
_explode_bomb(game, bomb);
|
||||
}
|
||||
bomb->status = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _update_point(game_t *game, point_t *point) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
||||
player_t *player = &game->player[i];
|
||||
if (player->status == 0)
|
||||
continue;
|
||||
double distance2 = pow(player->x - point->x, 2) + pow(player->y
|
||||
- point->y, 2) + pow(player->z - point->z, 2);
|
||||
if (distance2 > 1000.0)
|
||||
continue;
|
||||
point->status = 0;
|
||||
player->points += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void game_update_points(game_t *game, double dt) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_POINT_COUNT; i++) {
|
||||
point_t *point = &game->point[i];
|
||||
if (point->status == 0)
|
||||
continue;
|
||||
_update_point(game, point);
|
||||
}
|
||||
}
|
||||
|
||||
void game_update(game_t *game, double dt) {
|
||||
const double delta = 1. / 120.;
|
||||
game->updateTime += dt;
|
||||
while (game->updateTime > delta) {
|
||||
game_update_players(game, delta);
|
||||
game_update_bombs(game, delta);
|
||||
game_update_points(game, delta);
|
||||
game->updateTime -= delta;
|
||||
}
|
||||
}
|
||||
|
||||
size_t game_active_team_players(game_t *game, team_t *team) {
|
||||
size_t i, count = 0;
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
||||
if (game->player[i].status == 0)
|
||||
continue;
|
||||
if (game->player[i].team == team)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
team_t *game_team_with_least_players(game_t *game) {
|
||||
size_t i, count = -1;
|
||||
team_t *team = NULL;
|
||||
for (i = 0; i < GAME_TEAM_COUNT; i++) {
|
||||
size_t players = game_active_team_players(game, &game->team[i]);
|
||||
if (players < count) {
|
||||
count = players;
|
||||
team = &game->team[i];
|
||||
}
|
||||
}
|
||||
return team;
|
||||
}
|
||||
|
||||
team_t *game_team(game_t *game, uint16_t id) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_TEAM_COUNT; i++) {
|
||||
if (game->team[i].id == id) {
|
||||
return &game->team[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
player_t *game_player(game_t *game, uint16_t id) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
||||
if (game->player[i].id == id) {
|
||||
return &game->player[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bomb_t *game_spawn_bomb(game_t *game) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_BOMB_COUNT; i++) {
|
||||
if (game->bomb[i].status == 0) {
|
||||
game->bomb[i].status = 1;
|
||||
return &game->bomb[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
point_t *game_spawn_point(game_t *game) {
|
||||
size_t i;
|
||||
for (i = 0; i < GAME_POINT_COUNT; i++) {
|
||||
if (game->point[i].status == 0) {
|
||||
game->point[i].status = 1;
|
||||
return &game->point[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void game_setup_explosion_callback(game_t *game, void(*explosion_callback)(
|
||||
double x, double y, double z, void *data), void *data) {
|
||||
game->explosion_callback = explosion_callback;
|
||||
game->explosion_callback_data = data;
|
||||
}
|
||||
|
||||
void game_set_master(game_t *game, int master) {
|
||||
game->master = master;
|
||||
}
|
76
src/common/game.h
Normal file
76
src/common/game.h
Normal file
@ -0,0 +1,76 @@
|
||||
#ifndef GREMLIN_GAME_H
|
||||
#define GREMLIN_GAME_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
typedef struct team_t team_t;
|
||||
typedef struct player_t player_t;
|
||||
typedef struct game_t game_t;
|
||||
|
||||
#define GAME_TEAM_COUNT 2
|
||||
#define GAME_PLAYER_COUNT 64
|
||||
#define GAME_BOMB_COUNT (GAME_PLAYER_COUNT * 5)
|
||||
#define GAME_POINT_COUNT 50
|
||||
|
||||
struct player_t {
|
||||
uint16_t id;
|
||||
uint16_t status;
|
||||
double x, y, z;
|
||||
double rx, ry, rz, rw;
|
||||
double vx, vy, vz;
|
||||
team_t *team;
|
||||
uint16_t points;
|
||||
};
|
||||
|
||||
struct bomb_t {
|
||||
uint8_t status;
|
||||
double x, y, z;
|
||||
double vx, vy, vz;
|
||||
double ttl;
|
||||
};
|
||||
|
||||
struct point_t {
|
||||
uint8_t status;
|
||||
double x, y, z;
|
||||
};
|
||||
|
||||
struct team_t {
|
||||
uint16_t id;
|
||||
double x, y, z;
|
||||
float color[4];
|
||||
uint16_t points;
|
||||
uint16_t wins;
|
||||
};
|
||||
|
||||
struct game_t {
|
||||
team_t team[GAME_TEAM_COUNT];
|
||||
player_t player[GAME_PLAYER_COUNT];
|
||||
bomb_t bomb[GAME_BOMB_COUNT];
|
||||
point_t point[GAME_POINT_COUNT];
|
||||
int16_t max_player_id;
|
||||
int master;
|
||||
double updateTime;
|
||||
player_t *local_player;
|
||||
void(*explosion_callback)(double x, double y, double z, void *data);
|
||||
void *explosion_callback_data;
|
||||
};
|
||||
|
||||
extern void game_setup(game_t *game);
|
||||
extern void game_reset(game_t *game);
|
||||
extern team_t *game_team_with_least_players(game_t *game);
|
||||
extern player_t *game_spawn_player(game_t *game, team_t *team);
|
||||
extern player_t *game_spawn_player_id(game_t *game, team_t *team, uint16_t id);
|
||||
extern team_t *game_team(game_t *game, uint16_t id);
|
||||
extern player_t *game_player(game_t *game, uint16_t id);
|
||||
extern bomb_t *game_bomb(game_t *game, uint16_t index);
|
||||
extern void game_update_players(game_t *game, double dt);
|
||||
extern bomb_t *game_spawn_bomb(game_t *game);
|
||||
extern point_t *game_spawn_point(game_t *game);
|
||||
extern void game_update_bombs(game_t *game, double dt);
|
||||
extern void game_update_points(game_t *game, double dt);
|
||||
extern void game_update(game_t *game, double dt);
|
||||
extern void game_setup_explosion_callback(game_t *game,
|
||||
void(*explosion_callback)(double x, double y, double z, void *data),
|
||||
void *data);
|
||||
extern void game_set_master(game_t *game, int master);
|
||||
#endif
|
Reference in New Issue
Block a user