Jump to content
  • Advertisement
Sign in to follow this  
ProgrammerGuy123

Updating Entities in a Chunk Based System

This topic is 1906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need help on how I should go about updating entities in my game with a chunk based approach. It's a 2D tile based side scroller. This is about updating the entity logic not drawing tiles.

 

My game is going to have different entities like monsters and projectiles. I don't wan't to update all the hundreds of entities in the map at the same time so I need some sort of chunk system, where I split the map up into chunks and only update the chunks that are visible.

 

With this in mind I thought about giving each chunk a list of entities that belong to it. Then I could update each visible chunk, which would cycle through the chunk's list and update each individual entity. If an entity like a monster moves from one chunk to another I could remove it from the previous chunk's list and add it two the new chunk's list.

 

However, say I shoot a projectile off my screen, then the entity would not get updated until the chunk is able to update which means making that chunk visible. I guess I would just have to force update the chunks the projectile is in then.

 

It seems like that could work, but there are probably more efficient ways to handle cutting down hundreds of entity updates to tens of entity updates, which is why I'm asking. This is a very fundamental concept to any large tile based game, so I want to here what your method is. How do you handle updating entities in a efficient matter?

 

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

Projectiles are short lived and should be isolated to active regions, so I would probably update them globally rather than have projectiles be subdivided into the chunks.

 

Chunking the world as you describe is a fun learning experience, but unless you plan to have a huge environment or many thousands of monsters, doing it just to save processing time is probably not worth the trouble. In theory all the entities that would normally need updated, like monsters and such are sitting in their idle state at their spawn point, so updating them should be extremely fast. Rather than making every monster do a perception check(distance to player, etc), perform that logic from the players perspective instead. Do a spatial query on the player in order to elevate monsters update level(aggro, etc) when the player gets close to them.

 

You could set it up so that you have all the monsters in your world in your spatial structure(quad tree, kd tree, etc) for spatial queries, and not until they are within a distance from the player do they get added to a global update list where they are effectively treated as player-aware and aggro versus the player. Maybe there are some conditions you could hibernate them again off the update list but back into the spatial structure for future aggroing(like if the player outruns them beyond some distance). I would probably set it up like this, because it allows you to keep them out of the processing pool until they have been 'tripped' by the player, but from your systems perspective it is still a monolithic entity update loop that doesn't deal with world partitioning. The details of your game could change the opinion but in a general sense thats how I would approach it.

Share this post


Link to post
Share on other sites

a similar way to organize it would be to separate the simulation data (which monsters start where) from the world map (the level map).

 

have a list (tree whatever) of all monsters, and a second list of active monsters which gets updated.

 

by storing the list of monsters (all targets in the simulation) separate from the level (the world map), you can reuse a level and have different monsters appearing in it, without having to create two copies of the same level with different monsters.

Share this post


Link to post
Share on other sites

You will want to look into windowing mechanisms to order adjacent chunks by distance and classify effects of action by whether they penetrate certain numbers or distances thru concentric sets of chinks. 

 

You may need to also have a 'realized' versus 'abstract'  execution of effects that cross chunk boundries  to avoid processing things the player wont be able to see or to simplify the processing into a simpler more generalized operation.

 

Significant vs Trivial (ones which can be dropped) effects likewise.

 

The whole behavior of objects in distant chunks may be abstracted as well to hold down the behavoir processing needed so that more resources can be available for the players immediate vicinity.

Share this post


Link to post
Share on other sites

If your "side scroller" has only scrolling in one direction, then you can just create monsters as they come close to the player. Everything can be stored in a single "active list", and you don't need to create the mobs at all until they come close by.

 

Likewise, once an object goes too far off the left-hand side (if you scroll to the right), you can just permanently destroy it (rather than add it to a chunk-based passive list or something).

 

That way you don't need any chunks at all.

Share this post


Link to post
Share on other sites

If its linear (even both directions)  then you can have a rote prestaging  list  to keep things cached/pre-warmed   well before they are needed  (faster the player can move the wider your prep window would be).

 

The List data can be preprocessed for a game with outside tools  (so no complex on-the-fly  calculations/delays/wasted resources)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!