• Advertisement
Sign in to follow this  

Spacial Partitioning and Game Logic

This topic is 2358 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

When writing my game I figured it would be a good idea to separate the scene's spacial partitioning from the logic entirely. This has worked fine for a while. A game object has a scene node which is stored in the scene which internally subdivides nodes in an octree or quadtree. This way the game object does not depend on the way the scene subdivides the nodes for visibility and the scene does not care what a game object is.

However, I have realized that the logic really needs to query the scene to retrieve logic-dependent values. For example, finding the nearest enemy or tracing a bullet ray.

Can anyone share how they have tackled this problem? Here are my initial ideas but they both seem flawed:

Separate spacial structure for game objects. The scene nodes that the game objects control are still managed by the scene for culling, but the game objects themselves are subdivided in another structure.

Scene nodes contain a pointer to the game object they belong to. Self explanatory. I really don't like this idea though.

Thanks

Share this post


Link to post
Share on other sites
Advertisement
If your GOs have a pointer to the BV that contain it, I would have your game logic query the scene for nearest object, etc.

This way your game logic is ontop of your GO system which sits ontop of the spatial partitioning/rendering/physics/ etc.

EDIT: on second thought this would require something close to your second proposal. I'd suggest looking into Entity/Component systems.

Share this post


Link to post
Share on other sites
The typical approach to this is to store a custom pointer/handle/ID/etc. in the spatial partition structure, which links back to the game data. Make it an opaque handle of some type preferably; that way you don't have the spatial partition code depending on the game logic, etc. You can do this with IDs, or proxy objects, or void pointers, or whatever else makes sense in your language of choice.

Share this post


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

  • Advertisement