Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2080 in orxonox.OLD for orxonox/branches/chris/src/world.cc


Ignore:
Timestamp:
Jul 6, 2004, 10:29:05 PM (21 years ago)
Author:
chris
Message:

orxonox/branches/chris: Implemented basic track and spawning functionality. Added a function to convert a Rotation into a glmatrix. Implemented operator* in Rotation. Refined World, made World friend class of world_entity. Implemented camera functionality (can now be bound to the worldentity it should focus on).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/chris/src/world.cc

    r2068 r2080  
    1818#include <stdlib.h>
    1919#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"
    2820
    2921#include "world.h"
     
    4638World::~World ()
    4739{
     40        unload ();
    4841        delete entities;
    4942}
    5043
    51 template<class T> T* World::spawn<T>(Location* loc, WorldEntity* owner)
    52 {
     44template<class T> T* World::spawn<T>(Location* loc = NULL, WorldEntity* owner = NULL)
     45{
     46        Location zeroloc;
    5347        T* entity = new T();
    5448        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
     66template<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 ();
    5578        return entity;
    5679}
     
    107130void World::update ()
    108131{
     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       
    109178}
    110179
     
    124193          l = l->get_next();
    125194        }
    126 }
     195       
     196        for( int i = 0; i < tracklen) track[i].tick (seconds);
     197}
     198
     199void World::unload()
     200{
     201        if( pathnodes) delete []pathnodes;
     202        if( track) delete []pathnodes;
     203}
     204
     205void 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.