Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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) {
    if (map_history.size() == 64) {
    if (npc_history.size() == 64) {
    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.

share|improve this question
MMOs usually don't have lag compensation - MMO players are usually familiar with lag issues: likely because Blizzard do nothing for it in WoW. Are you sure you are not solving a non-problem? –  Jonathan Dickinson Feb 21 '12 at 12:15
I have though about it, but my game is more like action MMO game, players will cast non target spells, and fight by casting many projectiles (bullets, mini spells etc.) Is it ok that it will be no lag compensation? Wow is target-based game and it can use no lag compensation at all. –  Denis Ermolin Feb 21 '12 at 12:27
@DenisErmolin: so you would be doing something like spiral-knights or magicka? –  o0'. Feb 21 '12 at 12:42
Yeah more like magicka, more action without focusing target spells –  Denis Ermolin Feb 21 '12 at 12:48
@JonathanDickinson - Why do you say MMOs don't usually use lag compensation? WoW obviously has at least some position interpolation (haven't you ever seen someone "lag out" and everyone else sees them running in circles?), and so have all three commercial MMO codebases I've worked on/with. –  justinian Feb 21 '12 at 18:59

1 Answer 1

up vote 4 down vote accepted

Instead of making full copies of every entity in the world, just save the entities and attributes that are relevant to what you want to lag compensate.

For example, in a first person shooter, often the only thing to lag compensate are the bullet shots. To calculate whether a bullet hit, you only need to know, (a) the positions of other players and, (b) their hit boxes. That's all you should store in the history buffer. When you need to lag compensate, update the positions and hit boxes of the players, without touching anything else.

Additionally, you can be intelligent about which entities you choose to lag compensate. If you know your skill has a maximum range of x and players can move at a maximum speed of y then don't bother lag compensating any entities farther than x+y*dt distance away, since you know that they won't be hit by the skill.

P.S. I'm also working on an MMO that uses lag compensation. Just because it's not expected by MMO players doesn't mean we should deny them a good experience! WoW is over 7 years old now.

share|improve this answer
Thanks for your answer! It really helpfull –  Denis Ermolin Feb 21 '12 at 13:49
But what about world map? Now entity finding implemented as tile grid where every npc and player check-in. Currently major CPU load is copying map grid. –  Denis Ermolin Feb 21 '12 at 14:01
You shouldn't have to copy the entire grid. Just update each player in the grid as you lag compensate them. A uniform grid will have an O(1) update operation since you only need to divide the player's position by the grid cell size. –  Kai Feb 21 '12 at 14:06
Oh, i didnt think about it, yeah sure i'll just update grid. Thanks u really helped me) –  Denis Ermolin Feb 21 '12 at 14:17
@DenisErmolin have a look at how Valve do it. They explain their compensation really nicely. –  Jonathan Dickinson Feb 21 '12 at 16:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.