Changeset 2080 in orxonox.OLD for orxonox/branches/chris/src/world.cc
- Timestamp:
- Jul 6, 2004, 10:29:05 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/chris/src/world.cc
r2068 r2080 18 18 #include <stdlib.h> 19 19 #include <cmath> 20 21 #include "npc.h"22 #include "player.h"23 #include "environment.h"24 #include "shoot_laser.h"25 #include "shoot_rocket.h"26 #include "stdincl.h"27 #include "data_tank.h"28 20 29 21 #include "world.h" … … 46 38 World::~World () 47 39 { 40 unload (); 48 41 delete entities; 49 42 } 50 43 51 template<class T> T* World::spawn<T>(Location* loc, WorldEntity* owner) 52 { 44 template<class T> T* World::spawn<T>(Location* loc = NULL, WorldEntity* owner = NULL) 45 { 46 Location zeroloc; 53 47 T* entity = new T(); 54 48 entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); 49 if( loc == NULL) 50 { 51 zeroloc.dist = 0; 52 zeroloc.part = 0; 53 zeroloc.pos = Vector(); 54 zeroloc.rot = Rotation(); 55 loc = &zeroloc; 56 } 57 entity->init (loc, owner); 58 if (entity->bFree) 59 { 60 track[loc->part].map_coords( loc, entity->get_placement()) 61 } 62 entity->post_spawn (); 63 return entity; 64 } 65 66 template<class T> T* World::spawn<T>(Placement* plc, WorldEntity* owner = NULL) 67 { 68 T* entity = new T(); 69 entities->add ((WorldEntity*)entity, LIST_ADD_NEXT); 70 entity->init (plc, owner); 71 if (!entity->bFree) 72 { 73 printf("Can't spawn unfree entity with placement\n"); 74 entities->remove( (WorldEntity*)entity, LIST_FIND_FW); 75 return NULL; 76 } 77 entity->post_spawn (); 55 78 return entity; 56 79 } … … 107 130 void World::update () 108 131 { 132 List<WorldEntity> *l; 133 WorldEntity* entity; 134 Location* loc; 135 Placement* plc; 136 Uint32 t; 137 138 l = entities->get_next(); 139 while( l != NULL) 140 { 141 entity = l->get_object(); 142 143 if( entity != bFree) 144 { 145 loc = entity->get_location(); 146 plc = entity->get_placement(); 147 t = loc->part; 148 149 if( t >= tracklen) 150 { 151 printf("An entity is out of the game area\n"); 152 entity->left_world (); 153 } 154 else 155 { 156 while( track[t].map_coords( loc, plc)) 157 { 158 track[t]->post_leave (entity); 159 if( loc->part >= tracklen) 160 { 161 printf("An entity has left the game area\n"); 162 entity->left_world (); 163 break; 164 } 165 track[loc->part]->post_enter (entity); 166 } 167 } 168 } 169 else 170 { 171 // TO DO: implement check whether this particular free entity is out of the game area 172 // TO DO: call function to notify the entity that it left the game area 173 } 174 175 l = l->get_next(); 176 } 177 109 178 } 110 179 … … 124 193 l = l->get_next(); 125 194 } 126 } 195 196 for( int i = 0; i < tracklen) track[i].tick (seconds); 197 } 198 199 void World::unload() 200 { 201 if( pathnodes) delete []pathnodes; 202 if( track) delete []pathnodes; 203 } 204 205 void World::load_debug_level() 206 { 207 // create some path nodes 208 pathnodes = new Vector[6]; 209 pathnodes[0] = Vector(0, 0, 0); 210 pathnodes[1] = Vector(-100, 40, 0); 211 pathnodes[2] = Vector(-100, 140, 0); 212 pathnodes[3] = Vector(0, 180, 0); 213 pathnodes[4] = Vector(100, 140, 0); 214 pathnodes[5] = Vector(100, 40, 0); 215 216 // create the tracks 217 tracklen = 6; 218 track = new Track[6]; 219 for( int i = 0; i < tracklen; i++) 220 { 221 track[i] = Track( i, (i+1)%tracklen, &pathnodes[i], &pathnodes[(i+1)%tracklen]); 222 } 223 224 // create a player 225 226 // bind input 227 // bind camera 228 }
Note: See TracChangeset
for help on using the changeset viewer.