Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3109 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
RevLine 
[2190]1/*!
2    \file world.h
3    \brief Holds and manages all game data
4*/ 
[1853]5
6#ifndef WORLD_H
7#define WORLD_H
8
[2190]9#include "stdincl.h"
[2636]10#include "story_entity.h"
[2190]11
[2636]12
13
[2190]14class Track;
[2077]15class WorldEntity;
[2636]16class Camera;
[1883]17
[2190]18//! The game environment
[2636]19class World : public StoryEntity {
[1853]20
21 public:
[2636]22  World (char* name);
23  World (int worldID);
[1853]24  ~World ();
25
[2636]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();
[1917]36
[2636]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);
[2190]44       
[2636]45  void unload ();
46 
47  void setTrackLen(Uint32 tracklen);
48  int getTrackLen();
49  bool system_command (Command* cmd);
50  Camera* getCamera();
[2644]51
52  void spawn(WorldEntity* entity);
[2860]53  void spawn(WorldEntity* entity, Location* loc);
54  void spawn(WorldEntity* entity, Placement* plc);
[2644]55
[2860]56  tList<WorldEntity>* entities;
[2636]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
[1883]64 private:
[2636]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;
[1855]69
[2636]70  char* worldName;
71  int debugWorldNr;
[2731]72  GLuint objectList;
[2636]73
[2640]74  WorldEntity* localPlayer;
75 
[2636]76  void mainLoop();
77  void synchronize();
78  void handle_input();
79  void time_slice();
80  void collision();
81  void display();
[2640]82  void debug();
[2190]83};
[1883]84
[2190]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{
[2640]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;
[2190]116}
[2077]117
[2190]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{
[2640]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;
[2190]143}
[1853]144
145#endif
Note: See TracBrowser for help on using the repository browser.