completed switch to yaml for messages
This commit is contained in:
parent
1dbdb25f30
commit
d4dc19d358
@ -12,6 +12,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
#include <istream>
|
||||||
|
|
||||||
Network::Network(Game *game) :
|
Network::Network(Game *game) :
|
||||||
game(game), client_peer(0) {
|
game(game), client_peer(0) {
|
||||||
@ -93,16 +94,21 @@ void Network::sendGameUpdates() {
|
|||||||
msg.vy = v.y();
|
msg.vy = v.y();
|
||||||
msg.vz = v.z();
|
msg.vz = v.z();
|
||||||
msg.points = game->player[i].points;
|
msg.points = game->player[i].points;
|
||||||
ENetPacket * packet = enet_packet_create(&msg, sizeof(msg), 0);
|
YAML::Emitter em;
|
||||||
|
em << msg;
|
||||||
|
ENetPacket * packet = enet_packet_create((uint8_t *) em.c_str(),
|
||||||
|
em.size(), 0);
|
||||||
enet_host_broadcast(host, 0, packet);
|
enet_host_broadcast(host, 0, packet);
|
||||||
}
|
}
|
||||||
for (i = 0; i < game->teams.size(); i++) {
|
for (i = 0; i < game->teams.size(); i++) {
|
||||||
team_update_message_t msg;
|
team_update_message_t msg;
|
||||||
//msg.msg_id = MESSAGE_TEAM_UPDATE;
|
|
||||||
msg.team_id = game->teams[i].id;
|
msg.team_id = game->teams[i].id;
|
||||||
msg.points = game->teams[i].points;
|
msg.points = game->teams[i].points;
|
||||||
msg.wins = game->teams[i].wins;
|
msg.wins = game->teams[i].wins;
|
||||||
ENetPacket * packet = enet_packet_create(&msg, sizeof(msg), 0);
|
YAML::Emitter em;
|
||||||
|
em << msg;
|
||||||
|
ENetPacket * packet = enet_packet_create((uint8_t *) em.c_str(),
|
||||||
|
em.size(), 0);
|
||||||
enet_host_broadcast(host, 0, packet);
|
enet_host_broadcast(host, 0, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,40 +125,178 @@ T *_message_cast(void *p, size_t l) {
|
|||||||
return (T *) p;
|
return (T *) p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PARSE_START(msg) void operator >>(const YAML::Node& node, msg& m) {
|
||||||
|
#define PARSE_FIELD(name) node[#name] >> m.name;
|
||||||
|
#define PARSE_END() }
|
||||||
|
|
||||||
|
#define EMIT_START(msg) YAML::Emitter& operator <<(YAML::Emitter& out, const msg& m) { out << YAML::BeginMap; out << YAML::Key << "id" << YAML::Value << msg::id;
|
||||||
|
#define EMIT_FIELD(name) out << YAML::Key << #name << YAML::Value << m.name;
|
||||||
|
#define EMIT_END() out << YAML::EndMap;return out;}
|
||||||
|
|
||||||
|
// player_spawn_message_t
|
||||||
|
EMIT_START(player_spawn_message_t)
|
||||||
|
EMIT_FIELD(team_id)
|
||||||
|
EMIT_FIELD(player_id)
|
||||||
|
EMIT_END()
|
||||||
|
|
||||||
|
PARSE_START(player_spawn_message_t) PARSE_FIELD(team_id)
|
||||||
|
PARSE_FIELD(player_id)PARSE_END()
|
||||||
|
|
||||||
|
// player_kill_message_t
|
||||||
|
EMIT_START(player_kill_message_t)
|
||||||
|
EMIT_FIELD(player_id)
|
||||||
|
EMIT_END()
|
||||||
|
|
||||||
|
PARSE_START(player_kill_message_t) PARSE_FIELD(player_id)PARSE_END()
|
||||||
|
|
||||||
|
// accept_message_t
|
||||||
|
EMIT_START(accept_message_t)
|
||||||
|
EMIT_FIELD(player_id)
|
||||||
|
EMIT_END()
|
||||||
|
|
||||||
|
PARSE_START(accept_message_t) PARSE_FIELD(player_id)PARSE_END()
|
||||||
|
|
||||||
|
// player_update_message_t
|
||||||
|
EMIT_START(player_update_message_t)
|
||||||
|
EMIT_FIELD(player_id)
|
||||||
|
EMIT_FIELD(x)
|
||||||
|
EMIT_FIELD(y)
|
||||||
|
EMIT_FIELD(z)
|
||||||
|
EMIT_FIELD(vx)
|
||||||
|
EMIT_FIELD(vy)
|
||||||
|
EMIT_FIELD(vz)
|
||||||
|
EMIT_FIELD(points)
|
||||||
|
EMIT_END()
|
||||||
|
|
||||||
|
PARSE_START(player_update_message_t) PARSE_FIELD(player_id)
|
||||||
|
PARSE_FIELD(x)
|
||||||
|
PARSE_FIELD(y)
|
||||||
|
PARSE_FIELD(z)
|
||||||
|
PARSE_FIELD(vx)
|
||||||
|
PARSE_FIELD(vy)
|
||||||
|
PARSE_FIELD(vz)
|
||||||
|
PARSE_FIELD(points)PARSE_END()
|
||||||
|
|
||||||
|
// player_accelerate_message_t
|
||||||
|
EMIT_START(player_accelerate_message_t)
|
||||||
|
EMIT_FIELD(player_id)
|
||||||
|
EMIT_FIELD(x)
|
||||||
|
EMIT_FIELD(y)
|
||||||
|
EMIT_FIELD(z)
|
||||||
|
EMIT_END()
|
||||||
|
|
||||||
|
PARSE_START(player_accelerate_message_t) PARSE_FIELD(player_id)
|
||||||
|
PARSE_FIELD(x)
|
||||||
|
PARSE_FIELD(y)
|
||||||
|
PARSE_FIELD(z)PARSE_END()
|
||||||
|
|
||||||
|
// bomb_drop_meesage_t
|
||||||
|
EMIT_START(bomb_drop_meesage_t)
|
||||||
|
EMIT_FIELD(x)
|
||||||
|
EMIT_FIELD(y)
|
||||||
|
EMIT_FIELD(z)
|
||||||
|
EMIT_FIELD(vx)
|
||||||
|
EMIT_FIELD(vy)
|
||||||
|
EMIT_FIELD(vz)
|
||||||
|
EMIT_FIELD(ttl)
|
||||||
|
EMIT_END()
|
||||||
|
|
||||||
|
PARSE_START(bomb_drop_meesage_t) PARSE_FIELD(x)
|
||||||
|
PARSE_FIELD(y)
|
||||||
|
PARSE_FIELD(z)
|
||||||
|
PARSE_FIELD(vx)
|
||||||
|
PARSE_FIELD(vy)
|
||||||
|
PARSE_FIELD(vz)
|
||||||
|
PARSE_FIELD(ttl)PARSE_END()
|
||||||
|
|
||||||
|
// bomb_update_meesage_t
|
||||||
|
EMIT_START(bomb_update_meesage_t)
|
||||||
|
EMIT_FIELD(bomb_index)
|
||||||
|
EMIT_FIELD(x)
|
||||||
|
EMIT_FIELD(y)
|
||||||
|
EMIT_FIELD(z)
|
||||||
|
EMIT_FIELD(vx)
|
||||||
|
EMIT_FIELD(vy)
|
||||||
|
EMIT_FIELD(vz)
|
||||||
|
EMIT_FIELD(ttl)
|
||||||
|
EMIT_END()
|
||||||
|
|
||||||
|
PARSE_START(bomb_update_meesage_t) PARSE_FIELD(bomb_index)
|
||||||
|
PARSE_FIELD(x)
|
||||||
|
PARSE_FIELD(y)
|
||||||
|
PARSE_FIELD(z)
|
||||||
|
PARSE_FIELD(vx)
|
||||||
|
PARSE_FIELD(vy)
|
||||||
|
PARSE_FIELD(vz)
|
||||||
|
PARSE_FIELD(ttl)PARSE_END()
|
||||||
|
|
||||||
|
// point_update_mesage_t
|
||||||
|
EMIT_START(point_update_mesage_t)
|
||||||
|
EMIT_FIELD(point_index)
|
||||||
|
EMIT_FIELD(x)
|
||||||
|
EMIT_FIELD(y)
|
||||||
|
EMIT_FIELD(z)
|
||||||
|
EMIT_FIELD(status)
|
||||||
|
EMIT_END()
|
||||||
|
|
||||||
|
PARSE_START(point_update_mesage_t) PARSE_FIELD(point_index)
|
||||||
|
PARSE_FIELD(x)
|
||||||
|
PARSE_FIELD(y)
|
||||||
|
PARSE_FIELD(z)
|
||||||
|
PARSE_FIELD(status)PARSE_END()
|
||||||
|
|
||||||
|
// team_update_message_t
|
||||||
|
EMIT_START(team_update_message_t)
|
||||||
|
EMIT_FIELD(team_id)
|
||||||
|
EMIT_FIELD(points)
|
||||||
|
EMIT_FIELD(wins)
|
||||||
|
EMIT_END()
|
||||||
|
|
||||||
|
PARSE_START(team_update_message_t) PARSE_FIELD(team_id)
|
||||||
|
PARSE_FIELD(points)
|
||||||
|
PARSE_FIELD(wins)PARSE_END()
|
||||||
|
|
||||||
void Network::dispatch(enet_uint8 *data, size_t length) {
|
void Network::dispatch(enet_uint8 *data, size_t length) {
|
||||||
#if 0
|
std::istringstream istr;
|
||||||
message_t *msg = (message_t *) data;
|
istr.rdbuf()->pubsetbuf((char *) data, length);
|
||||||
switch (msg->msg_id) {
|
YAML::Parser parser;
|
||||||
|
parser.Load(istr);
|
||||||
|
YAML::Node doc;
|
||||||
|
parser.GetNextDocument(doc);
|
||||||
|
int msd_id;
|
||||||
|
doc["id"] >> msd_id;
|
||||||
|
switch (msd_id) {
|
||||||
case MESSAGE_PLAYER_SPAWN: {
|
case MESSAGE_PLAYER_SPAWN: {
|
||||||
player_spawn_message_t *sm = _message_cast<player_spawn_message_t> (
|
player_spawn_message_t m;
|
||||||
data, length);
|
doc >> m;
|
||||||
Team *team = game->getTeam(sm->team_id);
|
Team *team = game->getTeam(m.team_id);
|
||||||
player_t *player = game->spawnPlayerWithId(team, sm->player_id);
|
player_t *player = game->spawnPlayerWithId(team, m.player_id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_PLAYER_KILL: {
|
case MESSAGE_PLAYER_KILL: {
|
||||||
player_kill_message_t *sm = _message_cast<player_kill_message_t> (data,
|
player_kill_message_t m;
|
||||||
length);
|
doc >> m;
|
||||||
player_t *player = game->getPlayer(sm->player_id);
|
player_t *player = game->getPlayer(m.player_id);
|
||||||
player->status = 0;
|
player->status = 0;
|
||||||
player->team = 0;
|
player->team = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_ACCEPT: {
|
case MESSAGE_ACCEPT: {
|
||||||
accept_message_t *am = _message_cast<accept_message_t> (data, length);
|
accept_message_t m;
|
||||||
game->local_player = game->getPlayer(am->player_id);
|
doc >> m;
|
||||||
std::cout << "[Network] accpeted player " << am->player_id << std::endl;
|
game->local_player = game->getPlayer(m.player_id);
|
||||||
|
std::cout << "[Network] accpeted player " << m.player_id << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_PLAYER_UPDATE: {
|
case MESSAGE_PLAYER_UPDATE: {
|
||||||
player_update_message_t *um = _message_cast<player_update_message_t> (
|
player_update_message_t m;
|
||||||
data, length);
|
doc >> m;
|
||||||
player_t *player = game->getPlayer(um->player_id);
|
player_t *player = game->getPlayer(m.player_id);
|
||||||
#if 1
|
#if 1
|
||||||
btVector3 v = player->body->getLinearVelocity();
|
btVector3 v = player->body->getLinearVelocity();
|
||||||
btVector3 p = player->body->getWorldTransform().getOrigin();
|
btVector3 p = player->body->getWorldTransform().getOrigin();
|
||||||
btVector3 v1(um->vx, um->vy, um->vz);
|
btVector3 v1(m.vx, m.vy, m.vz);
|
||||||
btVector3 p1(um->x, um->y, um->z);
|
btVector3 p1(m.x, m.y, m.z);
|
||||||
player->body->activate(true);
|
player->body->activate(true);
|
||||||
player->body->setLinearVelocity(v1);
|
player->body->setLinearVelocity(v1);
|
||||||
player->body->getWorldTransform().setOrigin((2 * p + p1) / 3);
|
player->body->getWorldTransform().setOrigin((2 * p + p1) / 3);
|
||||||
@ -187,44 +331,43 @@ void Network::dispatch(enet_uint8 *data, size_t length) {
|
|||||||
player->vy = um->vy;
|
player->vy = um->vy;
|
||||||
player->vz = um->vz;
|
player->vz = um->vz;
|
||||||
#endif
|
#endif
|
||||||
std::cout << um->z << std::endl;
|
player->points = m.points;
|
||||||
player->points = um->points;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_POINT_UPDATE: {
|
case MESSAGE_POINT_UPDATE: {
|
||||||
point_update_mesage_t *msg = _message_cast<point_update_mesage_t> (
|
point_update_mesage_t m;
|
||||||
data, length);
|
doc >> m;
|
||||||
point_t *p = &game->point[msg->point_index];
|
point_t *p = &game->point[m.point_index];
|
||||||
p->status = msg->status;
|
p->status = m.status;
|
||||||
p->x = msg->x;
|
p->x = m.x;
|
||||||
p->y = msg->y;
|
p->y = m.y;
|
||||||
p->z = msg->z;
|
p->z = m.z;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_PLAYER_ACCELERATE: {
|
case MESSAGE_PLAYER_ACCELERATE: {
|
||||||
player_accelerate_message_t *um = _message_cast<
|
player_accelerate_message_t m;
|
||||||
player_accelerate_message_t> (data, length);
|
doc >> m;
|
||||||
player_t *player = game->getPlayer(um->player_id);
|
player_t *player = game->getPlayer(m.player_id);
|
||||||
player->vx += um->x;
|
player->vx += m.x;
|
||||||
player->vy += um->y;
|
player->vy += m.y;
|
||||||
player->vz += um->z;
|
player->vz += m.z;
|
||||||
player->body->activate(true);
|
player->body->activate(true);
|
||||||
player->body->applyCentralImpulse(btVector3(um->x, um->y, um->z));
|
player->body->applyCentralImpulse(btVector3(m.x, m.y, m.z));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_BOMB_DROP: {
|
case MESSAGE_BOMB_DROP: {
|
||||||
bomb_drop_meesage_t *m = _message_cast<bomb_drop_meesage_t> (data,
|
bomb_drop_meesage_t m;
|
||||||
length);
|
doc >> m;
|
||||||
bomb_t *bomb = game->spawn_bomb();
|
bomb_t *bomb = game->spawn_bomb();
|
||||||
if (bomb == NULL)
|
if (bomb == NULL)
|
||||||
return;
|
return;
|
||||||
bomb->x = m->x + m->vx * 0.0001;
|
bomb->x = m.x + m.vx * 0.0001;
|
||||||
bomb->y = m->y + m->vy * 0.0001;
|
bomb->y = m.y + m.vy * 0.0001;
|
||||||
bomb->z = m->z + m->vz * 0.0001;
|
bomb->z = m.z + m.vz * 0.0001;
|
||||||
bomb->vx = m->vx;
|
bomb->vx = m.vx;
|
||||||
bomb->vy = m->vy;
|
bomb->vy = m.vy;
|
||||||
bomb->vz = m->vz;
|
bomb->vz = m.vz;
|
||||||
bomb->ttl = m->ttl;
|
bomb->ttl = m.ttl;
|
||||||
if (client_peer == NULL) {
|
if (client_peer == NULL) {
|
||||||
ENetPacket * packet = enet_packet_create(data, length,
|
ENetPacket * packet = enet_packet_create(data, length,
|
||||||
ENET_PACKET_FLAG_RELIABLE);
|
ENET_PACKET_FLAG_RELIABLE);
|
||||||
@ -233,17 +376,16 @@ void Network::dispatch(enet_uint8 *data, size_t length) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGE_TEAM_UPDATE: {
|
case MESSAGE_TEAM_UPDATE: {
|
||||||
team_update_message_t *m = _message_cast<team_update_message_t> (data,
|
team_update_message_t m;
|
||||||
length);
|
doc >> m;
|
||||||
Team *team = game->getTeam(m->team_id);
|
Team *team = game->getTeam(m.team_id);
|
||||||
if (team == NULL)
|
if (team == NULL)
|
||||||
return;
|
return;
|
||||||
team->points = m->points;
|
team->points = m.points;
|
||||||
team->wins = m->wins;
|
team->wins = m.wins;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::service(uint32_t timeout) {
|
void Network::service(uint32_t timeout) {
|
||||||
@ -259,7 +401,6 @@ void Network::service(uint32_t timeout) {
|
|||||||
std::cout << "A new client connected from "
|
std::cout << "A new client connected from "
|
||||||
<< event.peer->address.host << " "
|
<< event.peer->address.host << " "
|
||||||
<< event.peer->address.port << std::endl;
|
<< event.peer->address.port << std::endl;
|
||||||
#if 0
|
|
||||||
// bring new client up to date
|
// bring new client up to date
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
for (i = 0; i < GAME_PLAYER_COUNT; i++) {
|
||||||
@ -267,11 +408,13 @@ void Network::service(uint32_t timeout) {
|
|||||||
continue;
|
continue;
|
||||||
// send player spawn message
|
// send player spawn message
|
||||||
player_spawn_message_t spwan_msg;
|
player_spawn_message_t spwan_msg;
|
||||||
spwan_msg.msg_id = MESSAGE_PLAYER_SPAWN;
|
|
||||||
spwan_msg.team_id = game->player[i].team->id;
|
spwan_msg.team_id = game->player[i].team->id;
|
||||||
spwan_msg.player_id = game->player[i].id;
|
spwan_msg.player_id = game->player[i].id;
|
||||||
ENetPacket * packet = enet_packet_create(&spwan_msg,
|
YAML::Emitter em;
|
||||||
sizeof(spwan_msg), ENET_PACKET_FLAG_RELIABLE);
|
em << spwan_msg;
|
||||||
|
ENetPacket * packet = enet_packet_create(
|
||||||
|
(uint8_t *) em.c_str(), em.size(),
|
||||||
|
ENET_PACKET_FLAG_RELIABLE);
|
||||||
enet_peer_send(event.peer, 0, packet);
|
enet_peer_send(event.peer, 0, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,13 +422,16 @@ void Network::service(uint32_t timeout) {
|
|||||||
if (game->point[i].status == 0)
|
if (game->point[i].status == 0)
|
||||||
continue;
|
continue;
|
||||||
point_update_mesage_t msg;
|
point_update_mesage_t msg;
|
||||||
msg.msg_id = MESSAGE_POINT_UPDATE;
|
|
||||||
msg.point_index = i;
|
msg.point_index = i;
|
||||||
msg.status = game->point[i].status;
|
msg.status = game->point[i].status;
|
||||||
msg.x = game->point[i].x;
|
msg.x = game->point[i].x;
|
||||||
msg.y = game->point[i].y;
|
msg.y = game->point[i].y;
|
||||||
msg.z = game->point[i].z;
|
msg.z = game->point[i].z;
|
||||||
ENetPacket * packet = enet_packet_create(&msg, sizeof(msg),
|
YAML::Emitter em;
|
||||||
|
em << msg;
|
||||||
|
|
||||||
|
ENetPacket * packet = enet_packet_create(
|
||||||
|
(uint8_t *) em.c_str(), em.size(),
|
||||||
ENET_PACKET_FLAG_RELIABLE);
|
ENET_PACKET_FLAG_RELIABLE);
|
||||||
enet_peer_send(event.peer, 0, packet);
|
enet_peer_send(event.peer, 0, packet);
|
||||||
}
|
}
|
||||||
@ -293,24 +439,31 @@ void Network::service(uint32_t timeout) {
|
|||||||
Team *team = game->team_with_least_players();
|
Team *team = game->team_with_least_players();
|
||||||
player_t *player = game->spawnPlayer(team);
|
player_t *player = game->spawnPlayer(team);
|
||||||
event.peer->data = player;
|
event.peer->data = player;
|
||||||
|
{
|
||||||
// send player spawn message
|
// send player spawn message
|
||||||
player_spawn_message_t spwan_msg;
|
player_spawn_message_t spwan_msg;
|
||||||
spwan_msg.msg_id = MESSAGE_PLAYER_SPAWN;
|
|
||||||
spwan_msg.team_id = team->id;
|
spwan_msg.team_id = team->id;
|
||||||
spwan_msg.player_id = player->id;
|
spwan_msg.player_id = player->id;
|
||||||
ENetPacket * packet = enet_packet_create(&spwan_msg,
|
YAML::Emitter em;
|
||||||
sizeof(spwan_msg), ENET_PACKET_FLAG_RELIABLE);
|
em << spwan_msg;
|
||||||
enet_host_broadcast(host, 0, packet);
|
|
||||||
|
|
||||||
|
ENetPacket * packet = enet_packet_create(
|
||||||
|
(uint8_t *) em.c_str(), em.size(),
|
||||||
|
ENET_PACKET_FLAG_RELIABLE);
|
||||||
|
enet_host_broadcast(host, 0, packet);
|
||||||
|
}
|
||||||
|
{
|
||||||
// send team and player
|
// send team and player
|
||||||
accept_message_t msg;
|
accept_message_t msg;
|
||||||
msg.msg_id = MESSAGE_ACCEPT;
|
|
||||||
msg.player_id = player->id;
|
msg.player_id = player->id;
|
||||||
packet = enet_packet_create(&msg, sizeof(msg),
|
YAML::Emitter em;
|
||||||
|
em << msg;
|
||||||
|
|
||||||
|
ENetPacket * packet = enet_packet_create(
|
||||||
|
(uint8_t *) em.c_str(), em.size(),
|
||||||
ENET_PACKET_FLAG_RELIABLE);
|
ENET_PACKET_FLAG_RELIABLE);
|
||||||
enet_peer_send(event.peer, 0, packet);
|
enet_peer_send(event.peer, 0, packet);
|
||||||
#endif
|
}
|
||||||
// send state
|
// send state
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -342,39 +495,6 @@ void Network::service(uint32_t timeout) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EMIT_START(msg) YAML::Emitter& operator <<(YAML::Emitter& out, const msg& m) { out << YAML::Key << "id" << YAML::Value << msg::id;
|
|
||||||
#define EMIT_FIELD(name) out << YAML::Key << #name << YAML::Value << m.name;
|
|
||||||
#define EMIT_END() out << YAML::EndMap;return out;}
|
|
||||||
|
|
||||||
EMIT_START(player_spawn_message_t)
|
|
||||||
EMIT_FIELD(team_id)
|
|
||||||
EMIT_FIELD(player_id)
|
|
||||||
EMIT_END()
|
|
||||||
|
|
||||||
EMIT_START(player_accelerate_message_t)
|
|
||||||
EMIT_FIELD(player_id)
|
|
||||||
EMIT_FIELD(x)
|
|
||||||
EMIT_FIELD(y)
|
|
||||||
EMIT_FIELD(z)
|
|
||||||
EMIT_END()
|
|
||||||
|
|
||||||
EMIT_START(bomb_drop_meesage_t)
|
|
||||||
EMIT_FIELD(x)
|
|
||||||
EMIT_FIELD(y)
|
|
||||||
EMIT_FIELD(z)
|
|
||||||
EMIT_FIELD(vx)
|
|
||||||
EMIT_FIELD(vy)
|
|
||||||
EMIT_FIELD(vz)
|
|
||||||
EMIT_FIELD(ttl)
|
|
||||||
EMIT_END()
|
|
||||||
|
|
||||||
#define PARSE_START(msg) void operator >>(const YAML::Node& node, msg& m) {
|
|
||||||
#define PARSE_FIELD(name) node[#name] >> m.name;
|
|
||||||
#define PARSE_END() }
|
|
||||||
|
|
||||||
PARSE_START(player_spawn_message_t) PARSE_FIELD(team_id)
|
|
||||||
PARSE_FIELD(player_id)PARSE_END()
|
|
||||||
|
|
||||||
//void Network::sendMessage(message_t &m) {
|
//void Network::sendMessage(message_t &m) {
|
||||||
// if (client_peer) {
|
// if (client_peer) {
|
||||||
// msgpack::sbuffer b;
|
// msgpack::sbuffer b;
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#define EMIT_DEFINE(msg) YAML::Emitter& operator <<(YAML::Emitter& out, const msg& m);
|
||||||
|
|
||||||
#define MESSAGE_PLAYER_SPAWN 0
|
#define MESSAGE_PLAYER_SPAWN 0
|
||||||
#define MESSAGE_PLAYER_KILL 1
|
#define MESSAGE_PLAYER_KILL 1
|
||||||
#define MESSAGE_ACCEPT 2
|
#define MESSAGE_ACCEPT 2
|
||||||
@ -33,6 +35,7 @@ struct player_spawn_message_t {
|
|||||||
size_t team_id;
|
size_t team_id;
|
||||||
size_t player_id;
|
size_t player_id;
|
||||||
};
|
};
|
||||||
|
EMIT_DEFINE(player_spawn_message_t)
|
||||||
|
|
||||||
struct player_kill_message_t {
|
struct player_kill_message_t {
|
||||||
enum {
|
enum {
|
||||||
@ -40,6 +43,7 @@ struct player_kill_message_t {
|
|||||||
};
|
};
|
||||||
uint16_t player_id;
|
uint16_t player_id;
|
||||||
};
|
};
|
||||||
|
EMIT_DEFINE(player_kill_message_t)
|
||||||
|
|
||||||
struct accept_message_t {
|
struct accept_message_t {
|
||||||
enum {
|
enum {
|
||||||
@ -47,6 +51,7 @@ struct accept_message_t {
|
|||||||
};
|
};
|
||||||
uint16_t player_id;
|
uint16_t player_id;
|
||||||
};
|
};
|
||||||
|
EMIT_DEFINE(accept_message_t)
|
||||||
|
|
||||||
struct player_update_message_t {
|
struct player_update_message_t {
|
||||||
enum {
|
enum {
|
||||||
@ -58,6 +63,7 @@ struct player_update_message_t {
|
|||||||
double vx, vy, vz;
|
double vx, vy, vz;
|
||||||
uint16_t points;
|
uint16_t points;
|
||||||
};
|
};
|
||||||
|
EMIT_DEFINE(player_update_message_t)
|
||||||
|
|
||||||
struct player_accelerate_message_t {
|
struct player_accelerate_message_t {
|
||||||
enum {
|
enum {
|
||||||
@ -66,6 +72,7 @@ struct player_accelerate_message_t {
|
|||||||
uint16_t player_id;
|
uint16_t player_id;
|
||||||
double x, y, z;
|
double x, y, z;
|
||||||
};
|
};
|
||||||
|
EMIT_DEFINE(player_accelerate_message_t)
|
||||||
|
|
||||||
struct bomb_drop_meesage_t {
|
struct bomb_drop_meesage_t {
|
||||||
enum {
|
enum {
|
||||||
@ -75,6 +82,7 @@ struct bomb_drop_meesage_t {
|
|||||||
double vx, vy, vz;
|
double vx, vy, vz;
|
||||||
double ttl;
|
double ttl;
|
||||||
};
|
};
|
||||||
|
EMIT_DEFINE(bomb_drop_meesage_t)
|
||||||
|
|
||||||
struct bomb_update_meesage_t {
|
struct bomb_update_meesage_t {
|
||||||
enum {
|
enum {
|
||||||
@ -85,6 +93,7 @@ struct bomb_update_meesage_t {
|
|||||||
double vx, vy, vz;
|
double vx, vy, vz;
|
||||||
double ttl;
|
double ttl;
|
||||||
};
|
};
|
||||||
|
EMIT_DEFINE(bomb_update_meesage_t)
|
||||||
|
|
||||||
struct point_update_mesage_t {
|
struct point_update_mesage_t {
|
||||||
enum {
|
enum {
|
||||||
@ -94,6 +103,7 @@ struct point_update_mesage_t {
|
|||||||
uint8_t status;
|
uint8_t status;
|
||||||
double x, y, z;
|
double x, y, z;
|
||||||
};
|
};
|
||||||
|
EMIT_DEFINE(point_update_mesage_t)
|
||||||
|
|
||||||
struct team_update_message_t {
|
struct team_update_message_t {
|
||||||
enum {
|
enum {
|
||||||
@ -103,12 +113,7 @@ struct team_update_message_t {
|
|||||||
uint16_t points;
|
uint16_t points;
|
||||||
uint16_t wins;
|
uint16_t wins;
|
||||||
};
|
};
|
||||||
|
EMIT_DEFINE(team_update_message_t)
|
||||||
#define EMIT_DEFINE(msg) YAML::Emitter& operator <<(YAML::Emitter& out, const msg& m);
|
|
||||||
|
|
||||||
EMIT_DEFINE(player_spawn_message_t)
|
|
||||||
EMIT_DEFINE(player_accelerate_message_t)
|
|
||||||
EMIT_DEFINE(bomb_drop_meesage_t)
|
|
||||||
|
|
||||||
class Network {
|
class Network {
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user