i'm writing small mmo, using boost library, i want to make it non-target game, but when i came to part where i need to save previous game states i became confused. How to implement game world, npcs, players states? Now i just copy all my my npcs, players and map in main game cycle, but it consume too many CPU, about 60-80%. Obviously it too much. Example of code in my save game method:
void GameHistory::saveGame(game* g)
{
if (player_history.size() == 64) {
player_history.erase(player_history.begin());
}
if (map_history.size() == 64) {
map_history.erase(map_history.begin());
}
if (npc_history.size() == 64) {
npc_history.erase(npc_history.begin());
}
long long t = lib::GET_SERVER_TIME();
players_obj_hash players;
game::players_hash::iterator itp = g->__players_by_id__.begin();
game::players_hash::iterator endp = g->__players_by_id__.end();
for (; itp != endp; itp++) {
players[itp->second->getId()] = (*itp->second);
}
player_history[t] = players;
map_history[t] = g->map;
npcs_obj_hash npcs;
game::npc_hash::iterator it = g->npcs_by_id.begin();
game::npc_hash::iterator end = g->npcs_by_id.end();
for (; it != end; it++) {
npcs[it->second->getId()] = (*it->second);
}
npc_history[t] = npcs;
}
Im using map as grid, where every npc or player "register" on which cell it stay for fast lookup of nearest entities. Maybe there is another more light approach to gamestate save? Thanks for answers.