|Hosting by Solid Eight Studios,PhotoTangler Collage Maker|
Level Storage & Element Relationships
Question submitted by (10 November 1999)
|Return to The Archives|
|I hope this isn't more of a C++ question then a game question, but, using objects, how is a game scene or level stored in memory with the objects relationships? For instance, if I have a class called orc and one called human, how would they be stored in level knowing the specifics about each other? Is it using a hash table or something more dynamic?|
Here's an example situation...
Consider your world (CWorld). It's the space in which you play the game (a level, for example.) It maintains the geometry and other high-level information for the environment. Derived from that, you'll have your scene (CScene). A scene differs from a world because the scene is the stuff that changes with time. When the player starts the level, the scene is full of keys and enemies. At the end of the level, the scene is stripped of its keys and all the enemies are dead. A scene might be populated with keys & enemies via some form of script or binary file created from an editor. Inside the scene are all the actors (CActors - one of which is the player.) Each actor keeps track of its own inventory, weapons, health, etc. One of the weapons (CWeapon) might keep track of its own ammo.
Break that down and you have class ownership/hierarchy: A scene is derived from a world. A scene owns an actor. An actor owns a weapon. A weapon owns ammo.
Each has their own special properties. For the actor class, you might have a CHuman derived from CActor, or a COrc derived from CActor. Yet all the scene knows about are CActors. That keeps the interface simple for the scene to deal with each actor, yet each actor can act differently based on its specific derivation from CActor.
Response provided by Paul Nettle
This article was originally an entry in flipCode's Fountain of Knowledge, an open Question and Answer column that no longer exists.