Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2640 was 2640, checked in by patrick, 20 years ago

orxonox/trunk/src - BUGFIX: input node now redirected to the right story_entity. This should fix the display player visibility problem, encountered on some systems

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