Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world.h @ 3216

Last change on this file since 3216 was 3216, checked in by patrick, 19 years ago

orxonox/trunk: a first redesign of the CommandNode and its cmd passing system - others will follow.

File size: 4.0 KB
Line 
1/*!
2    \file world.h
3    \brief Holds and manages all game data
4*/ 
5
6#ifndef WORLD_H
7#define WORLD_H
8
9#include "stdincl.h"
10#include "story_entity.h"
11
12
13
14class Track;
15class WorldEntity;
16class Camera;
17
18//! The game environment
19class World : public StoryEntity {
20
21 public:
22  World (char* name);
23  World (int worldID);
24  ~World ();
25
26  template<typename T> 
27    T* spawn(Location* loc, WorldEntity* owner);        // template to be able to spawn any derivation of WorldEntity
28  template<typename T> 
29    T* spawn(Placement* plc, WorldEntity* owner);
30 
31  virtual Error init();
32  virtual Error start();
33  virtual Error stop();
34  virtual Error pause();
35  virtual Error resume();
36
37  virtual void load();
38
39  void time_slice (Uint32 deltaT);
40  void collide ();
41  void draw ();
42  void update ();       // maps Locations to Placements
43  void calc_camera_pos (Location* loc, Placement* plc);
44       
45  void unload ();
46  bool command(Command* cmd);
47 
48  void setTrackLen(Uint32 tracklen);
49  int getTrackLen();
50  //bool system_command (Command* cmd);
51  Camera* getCamera();
52
53  void spawn(WorldEntity* entity);
54  void spawn(WorldEntity* entity, Location* loc);
55  void spawn(WorldEntity* entity, Placement* plc);
56
57  tList<WorldEntity>* entities;
58 
59  // base level data
60  Track* track;
61  Uint32 tracklen;   // number of Tracks the World consist of
62  Vector* pathnodes;
63  Camera* localCamera; 
64
65 private:
66  Uint32 lastFrame; //!> last time of frame
67  bool bQuitOrxonox; //!> quit this application
68  bool bQuitCurrentGame; //!> quit only the current game and return to menu
69  bool bPause;
70
71  char* worldName;
72  int debugWorldNr;
73  GLuint objectList;
74
75  WorldEntity* localPlayer;
76 
77  void mainLoop();
78  void synchronize();
79  void handle_input();
80  void time_slice();
81  void collision();
82  void display();
83  void debug();
84};
85
86/**
87    \brief spawn a new WorldEntity at a Location
88    \param loc: the Location where the Entity should be spawned
89    \param owner: a pointer to the parent of the Entity
90    \return a pointer to the new WorldEntity or NULL if there was an error
91   
92    You can use this function to spawn any derivation of WorldEntity you want, just specify the desired
93    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
94    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
95    works with both free and bound WorldEntities.
96*/ 
97template<typename T> T* World::spawn(Location* loc = NULL, WorldEntity* owner = NULL)
98{
99  Location zeroloc;
100  T* entity = new T();
101  entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
102  if( loc == NULL)
103    {
104      zeroloc.dist = 0;
105      zeroloc.part = 0;
106      zeroloc.pos = Vector();
107      zeroloc.rot = Quaternion();
108      loc = &zeroloc;
109    }
110  entity->init (loc, owner);
111  if (entity->bFree)
112    {
113      track[loc->part].map_coords( loc, entity->get_placement());
114    }
115  entity->post_spawn ();
116  return entity;
117}
118
119/**
120    \brief spawn a new WorldEntity at a Placement
121    \param lplc: the placement where the Entity should be spawned
122    \param owner: a pointer to the parent of the Entity
123    \return a pointer to the new WorldEntity or NULL if there was an error
124   
125    You can use this function to spawn any FREE derivation of WorldEntity you want, just specify the desired
126    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
127    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
128    works with free WorldEntities only, you will provoke an error message if you try to spawn a bound Entity with
129    a Placement.
130*/ 
131template<typename T> T* World::spawn(Placement* plc, WorldEntity* owner = NULL)
132{
133  T* entity = new T();
134  entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
135  entity->init (plc, owner);
136  if (!entity->bFree)
137    {
138      printf("Can't spawn unfree entity with placement\n"); 
139      entities->remove( (WorldEntity*)entity, LIST_FIND_FW);
140      return NULL;
141    }
142  entity->post_spawn ();
143  return entity;
144}
145
146#endif
Note: See TracBrowser for help on using the repository browser.