/*! \file world.h \brief Holds and manages all game data */ #ifndef WORLD_H #define WORLD_H #include "stdincl.h" class Track; class WorldEntity; //! The game environment class World { public: World (); ~World (); template T* spawn(Location* loc, WorldEntity* owner); // template to be able to spawn any derivation of WorldEntity template T* spawn(Placement* plc, WorldEntity* owner); void time_slice (Uint32 deltaT); void collide (); void draw (); void update (); // maps Locations to Placements void calc_camera_pos (Location* loc, Placement* plc); void unload (); void load_debug_level (); private: List* entities; // base level data Track* track; Uint32 tracklen; Vector* pathnodes; }; /** \brief spawn a new WorldEntity at a Location \param loc: the Location where the Entity should be spawned \param owner: a pointer to the parent of the Entity \return a pointer to the new WorldEntity or NULL if there was an error You can use this function to spawn any derivation of WorldEntity you want, just specify the desired class within the template specification brackets. Do not attempt to spawn any classes that have NOT been derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn() works with both free and bound WorldEntities. */ template T* World::spawn(Location* loc = NULL, WorldEntity* owner = NULL) { Location zeroloc; T* entity = new T(); entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); if( loc == NULL) { zeroloc.dist = 0; zeroloc.part = 0; zeroloc.pos = Vector(); zeroloc.rot = Quaternion(); loc = &zeroloc; } entity->init (loc, owner); if (entity->bFree) { track[loc->part].map_coords( loc, entity->get_placement()); } entity->post_spawn (); return entity; } /** \brief spawn a new WorldEntity at a Placement \param lplc: the placement where the Entity should be spawned \param owner: a pointer to the parent of the Entity \return a pointer to the new WorldEntity or NULL if there was an error You can use this function to spawn any FREE derivation of WorldEntity you want, just specify the desired class within the template specification brackets. Do not attempt to spawn any classes that have NOT been derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn() works with free WorldEntities only, you will provoke an error message if you try to spawn a bound Entity with a Placement. */ template T* World::spawn(Placement* plc, WorldEntity* owner = NULL) { T* entity = new T(); entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); entity->init (plc, owner); if (!entity->bFree) { printf("Can't spawn unfree entity with placement\n"); entities->remove( (WorldEntity*)entity, LIST_FIND_FW); return NULL; } entity->post_spawn (); return entity; } #endif