I was thinking something more like this:
class Branch {
Branch*[] children; // Could be a 3D array, or could use a spatial hash or something else to organize them.
Object3D*[] objects; // Just like with children, it might be better to use a tree or a HashMap.
Branch* parent; // Each branch must have exactly one parent.
}
class Object3D {
// Properties go here, such as geometry, mass, texture, other identifiers, etc.
Branch*[] parents; // An object could conceivably be on the border of several branches. There's probably a better solution that preserves the tree structure.
// Connectors to other objects can go here?
}
The purpose of organizing them into a tree is efficiency. If your world is better described by objects than tiles, then you don't want to keep the objects in a single array; you'd want to organize them so that the most common object-object interactions are faster than less common interactions.
However, I don't remember if Panda3D's built-in approach favors tiles or scene graph type structures.
(You might want to look up Scene Graphs. The principal sounds reasonable, but they still confuse me. They're supposed to be excellent for worlds with vast amounts of space, or wide variety in scale (for example, if you need to simulate both very tiny and very large objects, or you need buildings or towns separated by vast wilderness, or islands and ocean, etc.)
Java3D basically takes this idea and drives it off a cliff (turning absolutely everything into its own class, usually with long and overly technical names). Most audio games go in the opposite direction, and sacrifice ram and detail for simplicity (
if(tiles[x+dx][y+dy].solid) walk=false;
). Mainstream games were more tile-based as late as the mid 1990s, but that stopped being practical when 3D became easier, so object-based models and priority-based structures became more common.
The tricky part to a tree structure based on location is that moving objects might need to switch from one branch to another, but you don't want to constantly do a boundary check. I'm not sure how to handle this, but I probably shouldn't focus too much on this without better understanding what model Panda3D favors.
看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
George... Don't do that.