Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3500 was 2192, checked in by chris, 20 years ago

orxonox/branches/chris: it's now possible to add derivations of Track to the World; hit function declaration finalized; implemented splash damage function (World::explosion())

File size: 3.1 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 explosion (Location* loc, Damage* dmg, float r, WorldEntity* instigator);
33        void explosion (Placement* plc, Damage* dmg, float r, WorldEntity* instigator);
34       
35        void unload ();
36       
37        void load_debug_level ();
38       
39 private:
40 
41        List<WorldEntity>* entities;
42       
43                // base level data
44        Track** track;
45        Uint32 tracklen;
46        Vector* pathnodes;
47
48};
49
50/**
51    \brief spawn a new WorldEntity at a Location
52    \param loc: the Location where the Entity should be spawned
53    \param owner: a pointer to the parent of the Entity
54    \return a pointer to the new WorldEntity or NULL if there was an error
55   
56    You can use this function to spawn any derivation of WorldEntity you want, just specify the desired
57    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
58    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
59    works with both free and bound WorldEntities.
60*/ 
61template<typename T> T* World::spawn(Location* loc = NULL, WorldEntity* owner = NULL)
62{
63        Location zeroloc;
64        T* entity = new T();
65        entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
66        if( loc == NULL)
67        {
68                zeroloc.dist = 0;
69                zeroloc.part = 0;
70                zeroloc.pos = Vector();
71                zeroloc.rot = Quaternion();
72                loc = &zeroloc;
73        }
74        entity->init (loc, owner);
75        if (entity->bFree)
76        {
77                track[loc->part]->map_coords( loc, entity->get_placement());
78        }
79        entity->post_spawn ();
80        return entity;
81}
82
83/**
84    \brief spawn a new WorldEntity at a Placement
85    \param lplc: the placement where the Entity should be spawned
86    \param owner: a pointer to the parent of the Entity
87    \return a pointer to the new WorldEntity or NULL if there was an error
88   
89    You can use this function to spawn any FREE derivation of WorldEntity you want, just specify the desired
90    class within the template specification brackets. Do not attempt to spawn any classes that have NOT been
91    derived from WorldEntity, you won't even be able to compile the code. Note that this version of spawn()
92    works with free WorldEntities only, you will provoke an error message if you try to spawn a bound Entity with
93    a Placement.
94*/ 
95template<typename T> T* World::spawn(Placement* plc, WorldEntity* owner = NULL)
96{
97        T* entity = new T();
98        entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
99        entity->init (plc, owner);
100        if (!entity->bFree)
101        {
102                printf("Can't spawn unfree entity with placement\n"); 
103                entities->remove( (WorldEntity*)entity, LIST_FIND_FW);
104                return NULL;
105        }
106        entity->post_spawn ();
107        return entity;
108}
109
110#endif
Note: See TracBrowser for help on using the repository browser.