When the map is relatively small, it takes a few milliseconds to save it, so it's generally ok. But with other, much much bigger maps, it could take several seconds, which is both annoying and hangs the game's networking, and overall leads to many problems.

Threading kind of is the answer, but it creates another problem — while map is being saved, all changes user makes are also being saved, after the save button was pressed (so if the user decides to blow up the map right after pressing Save button, he might be unaware of that it might be saved). So this either calls for user-map interaction block until map saves, or something else entirely.

  • 3
    \$\begingroup\$ Copying big RAM areas should be way faster than writing big files. So first copy your data structures, then save. This of course requires that your data is at one central point. \$\endgroup\$ – API-Beast Jul 29 '12 at 8:40
  • 2
    \$\begingroup\$ You hardly ever want to save to whole map during a game, because most of it is static, it does not change. What you want to save is the dynamic game-state, like current player checkpoint, the inventory or enemy positions and evolution in an RTS and so on, but not the actual map. \$\endgroup\$ – Maik Semder Jul 29 '12 at 8:44
  • \$\begingroup\$ @MaikSemder in this case map changes, and very often. \$\endgroup\$ – user1306322 Jul 29 '12 at 9:21
  • \$\begingroup\$ @Mr.Beast How did I not think if it! This is the solution. \$\endgroup\$ – user1306322 Jul 29 '12 at 9:24
  • \$\begingroup\$ @user1306322 what exactly changes? \$\endgroup\$ – Maik Semder Jul 29 '12 at 9:49

When it takes a lot of time to save a map, and it can't be divided into chunks, one way to do it is to copy the map into a new instance of map class and save that instead of the live map.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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