For an isometric game I am using circular collision and distance checks, which seem to perform well and are usually more realistic shapes in regards of the ground an entity covers (some entities use rectangles, but the mix works fine so far). Since I work myself towards a procedural worldcreation, I am building a virtual cell grid for that purpose anyways. Therefore I can use the same grid to restrict distance checks to objects in my cell, and neighbouring cells. So I figured I might use that grid to simplify logic for objects that are outside of the camera bounds (e.g. simplify pathfinding).
Each cell is a Structure of Arrays, that get created dynamically and saves a unique ID of the object, which the object itself knows too. (Pictures are just for visualization. I only create the root Variable Grid and ObjectData, everything else is created dynamically.)
Then I can use that ID (IDs are unique to each objectType) to lookup any data I need for my collision in an object Array of Structures.:
ObjectData[ObjectType][ID].radius/xc/yc
As a nice side effect I have put that in my extensions sceneVar, so this way I can lookup/use objects that are not passed as object parameters to my custom objects. (I could expand this with more variables, to read any object state from anywhere)
Now I have had the realization, that I might not need Objects at all anymore, but when they are in the viewport of the camera. That means, of course, that I need to build all object based extensions myself (Pathfinding etc.), but with circular pathfinding its something I am willing to do (for the learning…).
But before I start this journey, I would like to know:
Am I creating anything useful at all with going this direction?
Am I neglecting object lists of the engine by building my own and am I gaining anything in terms of performance, when objects are only created in the viewport, while otherwise just being inside a variablecontainer?
If I create objects anyways and only show/hide them, as we are supposed to do, am I just building a parallel system, which doubles data? (my goal is kinda to not have objects in the scene that are super far away, but still need to exist in terms of variable manipulation)
…not really having a specific question, just asking for your opinion, if this could be worth it or more of a fruitless endevour.
I have for example a resourceNode reproduction algorithm: a tree in a forest will occasionally spawn samplings around its center. Its an easy calculation: just needs to be a matured tree and the reproduction cycle timer needs to be >= reproductionTime. Then I check if the randomly chosen location (point) is already covered by an object. To reduce the amount of checks I use only collider objects in the current grid-cell and the 3 closest neighbour grid-cells (for the corner case).
If the player is now having their viewport like 10 cells away, using the object directly felt unnecessary. So I went for the array, to still account for this. That meant the Array needs to hold the StateVar and TimerVar as well. At that point I was doubling my Data in my Array (whichw as previously inside my Object)… and asked myself, if I am creating a duplicated system
Grid[x;y][objectType][0…n].ID is a number you assign; something you control
In ObjectData[ObjectType][ID], ID is the index, which is something you have no control over
If an entry removed from ObjectData[ObjectType], then all the entries after it get renumbered, to maintain an index that is sequential from 0 to #ObjectData[ObjectType],childcount-1, with no breaks/gaps.
This means you’d need to renumber all affected Grid[x;y][objectType][0…n].ID values.
You’d be better off making ObjectData[ObjectType] a structure, with the ID value as the key.
If it’s for object that get added and removed infrequently, then this isn’t really necessary as the performance improvement will be negligable. But if you have objects that are removed and spawned frequently (say bullets in a bullet hell game for example), then it is advisable to use this method
Other notes - you could derive xc and yc of an object based on its position on the scene.
And if you are doing a distance check for a specific object, then it’d involve a test with every other object in the scene. It may be more efficient to create a sprite with a collision mask that’s roughly circular. Then place that on the scene with the first object and check which objects are in collision with the sprite.
Hi - I’ve been working on something similar but doing it a slightly different way. its for a game with a fluid world with culling where the objects only exist when they’re local but can move from cell to cell - similar to what you’re describing. and i also want to do it so that events are executed for elements in the world that have not been created yet too.
I was trying to think of ways of doing this in my game - its not a procedurally generated world and so i was thinking of a system of connected points in a array of arrays and using objects on the editor - repeat for each to log connections and then delete them.
this was causing bloating of the tongue and involuntary dribbling and twitching and so I’ve taken a break from it for a bit to work on something else but ill come back to it soon.