Changeset 2190 in orxonox.OLD for orxonox/trunk/src/world.h
- Timestamp:
- Jul 17, 2004, 12:11:20 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world.h
r2077 r2190 1 /** 2 Class representating the game-world 3 4 It contains a list of players (if multiplayer game), a list of Non-Player-Characters (nps), a list of Environment Entities. All this things together are building the orxonox-world. This class also handels the story-line (track), the world start/stop, init/uninit abilities. It is the middle point of every orxonox world. 5 */ 1 /*! 2 \file world.h 3 \brief Holds and manages all game data 4 */ 6 5 7 6 #ifndef WORLD_H 8 7 #define WORLD_H 9 8 10 class Player; 11 class NPC; 12 class Environment;9 #include "stdincl.h" 10 11 class Track; 13 12 class WorldEntity; 14 13 15 template<class T> class List; 16 17 18 19 //! World Class 20 /** 21 Class for World representation 22 23 It contains a list of players (if multiplayer game), a list of Non-Player-Characters (nps), a list of Environment Entities. All this things together are building the orxonox-world. This class also handels the story-line (track), the world start/stop, init/uninit abilities. It is the middle point of every orxonox world. 24 */ 14 //! The game environment 25 15 class World { 26 16 … … 29 19 ~World (); 30 20 21 template<typename T> 22 T* spawn(Location* loc, WorldEntity* owner); // template to be able to spawn any derivation of WorldEntity 23 template<typename T> 24 T* spawn(Placement* plc, WorldEntity* owner); 31 25 32 33 float primitiveMove; //!< deprecated, do not use 34 35 Player *localPlayer; //!< a pointer to the local player object 36 Player *player1; //!< a pointer to the second player object 37 Player *player2; //!< a pointer to the third player object 38 39 /* 40 struct playerList { 41 playerList* next; 42 Player* player; 43 int number; 44 }; 45 playerList* lastPlayer; 46 47 struct npcList { 48 npcList* next; 49 NPC* npc; 50 int number; 51 }; 52 npcList* lastNPC; 53 54 struct envList { 55 envList* next; 56 Environment* env; 57 int number; 58 }; 59 envList* lastEnv; 60 */ 61 62 63 void loadWorld(); 64 void unloadWorld(); 65 void pauseWorld(); 66 void saveGameState(char* filename); 67 68 69 bool addPlayer(Player* player); 70 bool removePlayer(Player* player); 71 Player* getLocalPlayer(); 72 bool addNPC(NPC* npc); 73 bool removeNPC(NPC* npc); 74 bool addEnv(Environment* env); 75 bool removeEnv(Environment* env); 76 77 78 void drawWorld(void); 79 void initEnvironement(void); 80 void setWorldStep(float step); 81 void updateWorld(void); 82 void detectCollision(void); 83 void testThaTest(void); 84 26 void time_slice (Uint32 deltaT); 27 void collide (); 28 void draw (); 29 void update (); // maps Locations to Placements 30 void calc_camera_pos (Location* loc, Placement* plc); 31 32 void unload (); 33 34 void load_debug_level (); 35 85 36 private: 86 float surface[120][120]; //!< deprecated: used to build a surface87 float step; //!< this is the step 88 89 List<WorldEntity*> *playerList; //!< the list of players, usualy very short 90 List<WorldEntity*> *npcList; //!< list of non player characters (npc) 91 List<WorldEntity*> *envList; //!< list of environment objects 92 37 38 List<WorldEntity>* entities; 39 40 // base level data 41 Track* track; 42 Uint32 tracklen; 43 Vector* pathnodes; 93 44 94 45 }; 95 46 47 /** 48 \brief spawn a new WorldEntity at a Location 49 \param loc: the Location where the Entity should be spawned 50 \param owner: a pointer to the parent of the Entity 51 \return a pointer to the new WorldEntity or NULL if there was an error 52 53 You can use this function to spawn any derivation of WorldEntity you want, just specify the desired 54 class within the template specification brackets. Do not attempt to spawn any classes that have NOT been 55 derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn() 56 works with both free and bound WorldEntities. 57 */ 58 template<typename T> T* World::spawn(Location* loc = NULL, WorldEntity* owner = NULL) 59 { 60 Location zeroloc; 61 T* entity = new T(); 62 entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); 63 if( loc == NULL) 64 { 65 zeroloc.dist = 0; 66 zeroloc.part = 0; 67 zeroloc.pos = Vector(); 68 zeroloc.rot = Quaternion(); 69 loc = &zeroloc; 70 } 71 entity->init (loc, owner); 72 if (entity->bFree) 73 { 74 track[loc->part].map_coords( loc, entity->get_placement()); 75 } 76 entity->post_spawn (); 77 return entity; 78 } 79 80 /** 81 \brief spawn a new WorldEntity at a Placement 82 \param lplc: the placement where the Entity should be spawned 83 \param owner: a pointer to the parent of the Entity 84 \return a pointer to the new WorldEntity or NULL if there was an error 85 86 You can use this function to spawn any FREE derivation of WorldEntity you want, just specify the desired 87 class within the template specification brackets. Do not attempt to spawn any classes that have NOT been 88 derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn() 89 works with free WorldEntities only, you will provoke an error message if you try to spawn a bound Entity with 90 a Placement. 91 */ 92 template<typename T> T* World::spawn(Placement* plc, WorldEntity* owner = NULL) 93 { 94 T* entity = new T(); 95 entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); 96 entity->init (plc, owner); 97 if (!entity->bFree) 98 { 99 printf("Can't spawn unfree entity with placement\n"); 100 entities->remove( (WorldEntity*)entity, LIST_FIND_FW); 101 return NULL; 102 } 103 entity->post_spawn (); 104 return entity; 105 } 106 96 107 #endif
Note: See TracChangeset
for help on using the changeset viewer.