本文整理汇总了C++中SerializeBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ SerializeBuffer类的具体用法?C++ SerializeBuffer怎么用?C++ SerializeBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SerializeBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: net_recv_player_actions
void net_recv_player_actions(SerializeBuffer& sb, int sender, PlayerData& pd) {
int frame, player_number;
sb.read_int(frame);
sb.read_int(player_number);
PlayerDataEntry& pde = pd.all_players().at(player_number);
ActionQueue actions;
sb.read_container(actions);
pde.action_queue.queue_actions_for_frame(actions, frame);
// printf("Receiving %d actions for player %d from %d \n", actions.size(),
// player_number, sender);
}
示例2: deserialize
void GameScreenSet::deserialize(GameState *gs, SerializeBuffer &serializer) {
serializer.read_int(current_screen);
simulation_map = read_gamemap(gs, serializer);
serializer.read_container(screens, [&](GameScreen& screen) {
screen.deserialize(gs, serializer);
});
GameSettings& settings = gs->game_settings();
int n_local_players = 0;
for (PlayerDataEntry &player: gs->player_data().all_players()) {
if (player.is_local_player) {
n_local_players++;
}
}
// Number of split-screens tiled together
int n_x = 1, n_y = 1;
if (n_local_players <= 2) {
n_x = n_local_players;
} else if (n_local_players <= 4) {
// More than 2, less than 4? Try 2x2 tiling
n_x = 2, n_y = 2;
} else if (n_local_players <= 6) {
n_x = 3, n_y = 2;
} else {
LANARTS_ASSERT(n_local_players <= 9);
// Last resort, Try 3x3 tiling
n_x = 3, n_y = 3;
}
const int WIDTH = settings.view_width / n_x;
const int HEIGHT = settings.view_height / n_y; // / N_PLAYERS;
std::vector<BBox> bounding_boxes;
for (GameScreen& screen : screens) {
const int x1 = (screen.index % n_x) * WIDTH, y1 = (screen.index / n_x) * HEIGHT;
bounding_boxes.push_back(BBox {x1, y1, x1 + WIDTH, y1 + HEIGHT});
}
if (bounding_boxes.size() == 3) {
bounding_boxes[1] = {WIDTH, 0, settings.view_width, settings.view_height};
}
for (GameScreen& screen : screens) {
BBox b = bounding_boxes[screen.index];
screen.window_region = b;
screen.hud = GameHud {
BBox(b.x2 - GAME_SIDEBAR_WIDTH, b.y1, b.x2, b.y2),
BBox(b.x1, b.y1, b.x2 - GAME_SIDEBAR_WIDTH, b.y2)
};
screen.view = GameView {0, 0, b.width() - GAME_SIDEBAR_WIDTH, b.height()};
}
}
示例3: extract_message
static bool extract_message(QueuedMessage& qm,
std::vector<QueuedMessage>& delayed_messages, int type) {
for (int i = 0; i < delayed_messages.size(); i++) {
qm = delayed_messages[i];
SerializeBuffer* msg = qm.message;
int msg_type;
msg->read_int(msg_type);
if (type == msg_type) {
delayed_messages.erase(delayed_messages.begin() + i);
return true;
}
msg->move_read_position(-(int)sizeof(int));
}
return false;
}
示例4: write_or_assert_hash
static void write_or_assert_hash(SerializeBuffer& sb, unsigned int hash,
bool is_writing) {
if (is_writing) {
sb.write_int(hash);
} else {
LANARTS_ASSERT(serializer_equals_read(sb, hash));
}
}
示例5: net_recv_sync_data
void net_recv_sync_data(SerializeBuffer& sb, GameState* gs) {
printf("Got sync on frame %d\n", gs->frame());
int mtwistseed;
sb.read_int(mtwistseed);
gs->rng().init_genrand(mtwistseed);
gs->deserialize(sb);
std::vector<PlayerDataEntry>& pdes = gs->player_data().all_players();
for (int i = 0; i < pdes.size(); i++) {
pdes[i].player()->set_local_player(pdes[i].is_local_player);
}
}
示例6: net_recv_game_init_data
void net_recv_game_init_data(SerializeBuffer& sb, int sender,
GameStateInitData& init_data, PlayerData& pd) {
//Write seed
sb.read_int(init_data.seed);
init_data.seed_set_by_network_message = true;
//Read player data
int localidx;
sb.read_int(localidx);
pd.set_local_player_idx(localidx);
int playern;
sb.read_int(playern);
LANARTS_ASSERT(pd.all_players().empty());
for (int i = 0; i < playern; i++) {
std::string name;
class_id classtype;
int net_id;
sb.read(name);
sb.read_int(classtype);
sb.read_int(net_id);
pd.register_player(name, NULL, classtype, net_id);
}
printf("Received init packet: seed = 0x%X, localid = %d, nplayers = %d\n",
init_data.seed, localidx, playern);
}
示例7: net_recv_game_init_data
void net_recv_game_init_data(SerializeBuffer& sb, int sender,
GameStateInitData& init_data, PlayerData& pd) {
//Write seed
sb.read(init_data);
init_data.received_init_data = true;
//Read player data
int localidx;
sb.read_int(localidx);
int playern;
sb.read_int(playern);
LANARTS_ASSERT(pd.all_players().empty());
for (int i = 0; i < playern; i++) {
std::string name;
std::string classtype;
int net_id;
sb.read(name);
sb.read(classtype);
sb.read_int(net_id);
pd.register_player(name, NULL, classtype, LuaValue(), (i == localidx), net_id);
}
printf(
"Received init packet: seed = 0x%X, localid = %d, nplayers = %d, "
"frame_action_repeat = %d, regen_level_on_death = %d, network_debug_mode = %d, time_per_step = %f\n",
init_data.seed, localidx, playern, init_data.frame_action_repeat,
(int) init_data.regen_on_death,
(int) init_data.network_debug_mode, init_data.time_per_step);
}
示例8: net_recv_sync_data
void net_recv_sync_data(SerializeBuffer& sb, GameState* gs) {
int mtwistseed;
sb.read_int(mtwistseed);
gs->rng().init_genrand(mtwistseed);
int nplayer = gs->player_data().get_local_player_idx();
gs->deserialize(sb);
std::vector<PlayerDataEntry>& pdes = gs->player_data().all_players();
for (int i = 0; i < pdes.size(); i++) {
pdes[i].player()->set_local_player(false);
}
gs->player_data().set_local_player_idx(nplayer);
gs->game_world().set_current_level(gs->local_player()->current_level);
}
示例9: serialize
void GameInstSet::serialize(GameState* gs, SerializeBuffer& serializer) {
serializer.write_int(grid_w);
serializer.write_int(grid_h);
serializer.write_int(size());
serializer.write_int(next_id);
DepthMap::const_iterator it = depthlist_map.end();
for (int ind = 0; it != depthlist_map.begin();) {
--it;
InstanceState* state = it->second.start_of_list;
while (state) {
GameInst* inst = state->inst;
serializer.write_int(get_inst_type(inst));
serializer.write_int(inst->id);
inst->serialize(gs, serializer);
serializer.write_int(inst->integrity_hash());
state = state->next_same_depth;
}
}
}
示例10: send_packet
void GameNetConnection::send_packet(SerializeBuffer& serializer, int receiver) {
_connection->send_message(serializer.data(), serializer.size(), receiver);
}
示例11: deserialize
void ChatMessage::deserialize(SerializeBuffer& serializer) {
serializer.read(sender);
serializer.read(message);
serializer.read(sender_colour);
serializer.read(message_colour);
}
示例12: serialize
void ChatMessage::serialize(SerializeBuffer& serializer) {
serializer.write(sender);
serializer.write(message);
serializer.write(sender_colour);
serializer.write(message_colour);
}
示例13: deserialize
void AnimatedInst::deserialize(GameState* gs, SerializeBuffer& serializer) {
GameInst::deserialize(gs, serializer);
DESERIALIZE_POD_REGION(serializer, this, textcol, animatetime);
serializer.read(text);
}
示例14: deserialize
void MonsterController::deserialize(SerializeBuffer& serializer) {
serializer.read_container(mids);
serializer.read(monsters_wandering_flag);
}
示例15: serialize
void MonsterController::serialize(SerializeBuffer& serializer) {
serializer.write_container(mids);
serializer.write(monsters_wandering_flag);
}