Game Development Community

Persistence Questions

by Alex Poli · in Torque 2D Beginner · 09/08/2013 (5:28 pm) · 6 replies

Recently I have been working on a game that is designed to have a large open-world. I have only recently begun work on generating and persisting the game-world and I have run into a few problems.

Before I get into the issues I am experiencing I will describe my strategy for "streaming" this large game world. The idea behind my current strategy is to divide the world into chunks and then only load the chunks nearest to the player. To do this I first generate the map, and then go through and put all the objects contained within a chunk into a set that is then saved to a TAML file. I then clear the scene and load the chunks where the player is currently located. Then, as the player moves around I have an object tracking which chunks need to be loaded and unloaded/saved. Right now I have this pretty much working but I am having a few issues.

1. The first problem I ran into was the fact that all my sceneObjects were referenced by their id, rather than a name. I addressed this by setting their name to their class, followed by their original id. for example a stone might be named "stone1234". I did it this way so that I could still reference objects individually and keep track of relationships between objects (parents, children, etc.). The issue I am running into now is that when the objects are read from file and added to the scene I get the message:
"SimObject::assignName() - Attempted to set object to name 'Stone5826' but it is already assigned to another object.
Taml::parseElement() - Registered an instance of type 'Sprite' but a request to name it 'Stone5826' was rejected. This is typically because an object of that name already exists."

My question is, am I approaching the persistence of these objects correctly, and if so how do I address this warning?


2. My second issue is with performance. When a player walks from one chunk to another there is often a lag-spike that is especially noticeable when entering a chunk with a lot of objects. At first I thought this was because I was trying to load all the objects in the chunk at once and it would freeze while each object was added, but I re-wrote it so that the objects in the chunks are loaded one at a time, over a short amount of time. My other thought is that it might just be too slow to read in from file, and if this is the case I guess I need to look at another method of handling this large world. I was also thinking that it might be due, in part, to all the warning messages (above) that get thrown at me when I load chunks.

I guess my question is, why might I be getting these lag-spikes, and if it comes down to slow file-loading, what are some better techniques for dealing with large worlds?

If it would be helpful I can post my code, but right now it's a bit of a mess from trying to iron out all these issues.

#1
09/08/2013 (6:37 pm)
It could be that you aren't preloading the assets. Which might be a problem itself if you have a lot. It could be box2d or it could be slow reading from the engine like you said. It could be anything :O! You're going to have to dig deep into the source for this one.
#2
09/08/2013 (6:44 pm)
Yeah, that's what I was afraid of. I probably need to just focus on one possibility at a time and try to eliminate possible problems. I was mostly curious if I am on a path that can eventually result in a feasible system.
#3
09/09/2013 (2:59 am)
Sounds like loading chunks this way without threading it is bound to create some lag.
Try doing a profiling of your game (don't know about T2D but T3D has a profiler built in) to see what takes how much time.
#4
09/09/2013 (6:00 am)
Funny, I was also thinking of trying to have things loaded one piece at a time to avoid the laggy jump any time a new area is created. My prototype game generates chunks of world one big chunk at a time as the character travels around. I will be interested to hear how you handle it, as I'm currently tackling other problems with my own code :P
#5
09/09/2013 (6:31 am)
Oh, and my current plan is to leave a certain number of areas loaded in the memory, and having areas outside of that saved as a .taml file (indexed via an X Y type grid system for the area name) and then everything within them deleted. Getting that to work without lag will be the primary challenge, I think.
#6
09/09/2013 (5:15 pm)
Profiling would probably be very helpful in identifying the problems I am facing. Does anyone know how to do that in T2D?

At this point I am going to attempt to address the console warnings I am receiving and see if that helps the performance at all. I will also look at preloading assets, because I will probably need to do this in the future anyway as the world generation becomes more complex.

@Chase: That sounds pretty similar to what I am trying to do; hopefully I can work out the bugs and get it working. I will let you know how it goes :)