Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/chris/src/world.h @ 2166

Last change on this file since 2166 was 2141, checked in by chris, 20 years ago

orxonox/branches/chris: added lots and lots of doxygen tags

File size: 2.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
11class Track;
12class WorldEntity;
13
14//! The game environment
15class World {
16
17 public:
18  World ();
19  ~World ();
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);
25
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       
36 private:
37 
38        List<WorldEntity>* entities;
39       
40                // base level data
41        Track* track;
42        Uint32 tracklen;
43        Vector* pathnodes;
44
45};
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*/ 
58template<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*/ 
92template<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
107#endif
Note: See TracBrowser for help on using the repository browser.