Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/old.dave/src/world.h @ 3291

Last change on this file since 3291 was 2860, checked in by dave, 20 years ago

orxonox/branches/dave: das level hat jetzt form angenommen, stand:nach der Convention vom Samstag….

File size: 3.9 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 
47  void setTrackLen(Uint32 tracklen);
48  int getTrackLen();
49  bool system_command (Command* cmd);
50  Camera* getCamera();
51
52  void spawn(WorldEntity* entity);
53  void spawn(WorldEntity* entity, Location* loc);
54  void spawn(WorldEntity* entity, Placement* plc);
55
56  tList<WorldEntity>* entities;
57 
58  // base level data
59  Track* track;
60  Uint32 tracklen;   // number of Tracks the World consist of
61  Vector* pathnodes;
62  Camera* localCamera; 
63
64 private:
65  Uint32 lastFrame; //!> last time of frame
66  bool bQuitOrxonox; //!> quit this application
67  bool bQuitCurrentGame; //!> quit only the current game and return to menu
68  bool bPause;
69
70  char* worldName;
71  int debugWorldNr;
72  GLuint objectList;
73
74  WorldEntity* localPlayer;
75 
76  void mainLoop();
77  void synchronize();
78  void handle_input();
79  void time_slice();
80  void collision();
81  void display();
82  void debug();
83};
84
85/**
86    \brief spawn a new WorldEntity at a Location
87    \param loc: the Location where the Entity should be spawned
88    \param owner: a pointer to the parent of the Entity
89    \return a pointer to the new WorldEntity or NULL if there was an error
90   
91    You can use this function to spawn any derivation of WorldEntity you want, just specify the desired
92    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
93    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
94    works with both free and bound WorldEntities.
95*/ 
96template<typename T> T* World::spawn(Location* loc = NULL, WorldEntity* owner = NULL)
97{
98  Location zeroloc;
99  T* entity = new T();
100  entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
101  if( loc == NULL)
102    {
103      zeroloc.dist = 0;
104      zeroloc.part = 0;
105      zeroloc.pos = Vector();
106      zeroloc.rot = Quaternion();
107      loc = &zeroloc;
108    }
109  entity->init (loc, owner);
110  if (entity->bFree)
111    {
112      track[loc->part].map_coords( loc, entity->get_placement());
113    }
114  entity->post_spawn ();
115  return entity;
116}
117
118/**
119    \brief spawn a new WorldEntity at a Placement
120    \param lplc: the placement where the Entity should be spawned
121    \param owner: a pointer to the parent of the Entity
122    \return a pointer to the new WorldEntity or NULL if there was an error
123   
124    You can use this function to spawn any FREE derivation of WorldEntity you want, just specify the desired
125    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
126    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
127    works with free WorldEntities only, you will provoke an error message if you try to spawn a bound Entity with
128    a Placement.
129*/ 
130template<typename T> T* World::spawn(Placement* plc, WorldEntity* owner = NULL)
131{
132  T* entity = new T();
133  entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
134  entity->init (plc, owner);
135  if (!entity->bFree)
136    {
137      printf("Can't spawn unfree entity with placement\n"); 
138      entities->remove( (WorldEntity*)entity, LIST_FIND_FW);
139      return NULL;
140    }
141  entity->post_spawn ();
142  return entity;
143}
144
145#endif
Note: See TracBrowser for help on using the repository browser.