Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2068 in orxonox.OLD


Ignore:
Timestamp:
Jul 5, 2004, 10:43:49 AM (20 years ago)
Author:
chris
Message:

orxonox/branches/chris: First snippet of the totally revamped base system… perhaps a bit confusing at the moment, but when finished theoretically you only have to subclass the worldentity and track classes to create the game content (even the menu will be a WorldEntity I suppose)

Location:
orxonox/branches/chris/src
Files:
4 added
2 deleted
11 edited

Legend:

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

    r2066 r2068  
    157157                                break;
    158158                        default:
    159                                         // TO DO: Send other events to orxonox sysevent handler
     159                                Orxonox *orx = Orxonox::getInstance();
     160                                orx->event_handler (&event);
    160161                                break;
    161162                }
  • orxonox/branches/chris/src/data_tank.cc

    r1982 r2068  
    1919using namespace std;
    2020
    21 float DataTank::xOffset = 0;
    22 float DataTank::yOffset = 0;
    23 float DataTank::zOffset = 0;
    24 
    2521DataTank::DataTank () {}
    2622DataTank::~DataTank () {}
  • orxonox/branches/chris/src/data_tank.h

    r1982 r2068  
    1010  ~DataTank ();
    1111
    12   static float xOffset;
    13   static float yOffset;
    14   static float zOffset;
    15 
    1612};
    1713
  • orxonox/branches/chris/src/orxonox.cc

    r2058 r2068  
    2121   ### File Specific:
    2222   main-programmer: Patrick Boenzli
    23    co-programmer:
     23   co-programmer: Christian Meyer
    2424*/
     25
     26#ifdef __WIN32__
     27#include <windows.h>
     28#endif
    2529
    2630#include <iostream>
     
    5155
    5256Orxonox::~Orxonox ()
    53 {}
    54 
    55 
    56 /* this is a singleton class to prevent dublicates */
     57{
     58        Orxonox::singleton_ref = NULL;
     59        if( world != NULL) delete world;
     60        if( localinput != NULL) delete world;
     61        if( localcamera != NULL) delete camera;
     62        if( resources != NULL) delete resources;
     63}
     64
     65
     66/* this is a singleton class to prevent duplicates */
    5767Orxonox* Orxonox::singleton_ref = 0;
    5868World* Orxonox::world = 0;
    59 InputOutput* Orxonox::io = 0;
    60 Player* Orxonox::localPlayer = 0;
    6169bool Orxonox::pause = false;
    62 bool Orxonox::inputEnabled = false;
    63 bool Orxonox::upWeGo = false;
    64 bool Orxonox::downWeGo = false;
    65 bool Orxonox::rightWeGo = false;
    66 bool Orxonox::leftWeGo = false;
    67 bool Orxonox::shoot1 = false;
    68 int Orxonox::fps = 0;
    69 int Orxonox::alpha = 0;
    70 int Orxonox::beta = 0;
    71 //int Orxonox::offsetX = 0;
    72 //int Orxonox::offsetY = 0;
    7370
    7471
     
    8077}
    8178
    82 
    83 int Orxonox::globalInit (int argc, char** argv)
    84 {
     79void Orxonox::get_config_file (int argc, char** argv)
     80{
     81        char* path;
     82        #ifdef __WIN32__
     83        path = getenv("");
     84        #else
     85        path = getenv("HOME");
     86        #endif
     87       
     88        if( path != NULL) strcpy (configfilename, path);
     89        strcat (configfilename, "/.orxonox.conf");
     90}
     91
     92int Orxonox::init (int argc, char** argv)
     93{
     94                // parse command line
     95                // config file
     96               
     97        get_config_file (argc, argv);
     98       
     99                // initialize SDL
     100  printf("> Initializing SDL\n");
    85101  if( SDL_Init (SDL_INIT_EVERYTHING) == -1)
    86102  {
     
    89105  }
    90106 
     107        // initialize everything
     108  printf("> Initializing video\n");
     109        if( init_video () == -1) return -1;
     110  printf("> Initializing sound\n");
     111        if( init_sound () == -1) return -1;
     112  printf("> Initializing input\n");
     113        if( init_input () == -1) return -1;
     114  printf("> Initializing networking\n");
     115        if( init_networking () == -1) return -1;
     116  printf("> Initializing resources\n");
     117        if( init_resources () == -1) return -1;
     118  printf("> Initializing world\n");
     119        if( init_world () == -1) return -1;
     120       
     121        return 0;
     122}
     123
     124int Orxonox::init_video ()
     125{
    91126  // Set video mode
    92127  // TO DO: parse arguments for settings
     
    117152  // OpenGL stuff
    118153  // (Is this all we initialize globally???)
     154  glClearColor(0.0, 0.0, 0.0, 0.0);
    119155  glEnable(GL_DEPTH_TEST);
    120156  glShadeModel(GL_FLAT);
    121157 
    122 //  glutInit(&argc, argv);
    123 //  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    124 //  glutInitWindowSize(500, 500);
    125 //  //glutFullScreen();
    126 //  glutInitWindowPosition(100, 100);
    127 //  glutCreateWindow("OrxonoX");
    128 //  /* window event dispatchers */
    129 //  glutDisplayFunc(display);
    130 //  glutReshapeFunc(reshape);
    131 //  glutKeyboardFunc(keyboard);
    132 //  glutKeyboardUpFunc(upKeyboard);
    133 //
    134 //  glutTimerFunc(1000, timeSlice, 0);
    135 //  cout << "measuring performance...";
    136 
    137 }
    138 
    139 
    140 int Orxonox::menuInit (void)
    141 {
    142   glClearColor(0.0, 0.0, 0.0, 0.0);
    143 }
    144 
    145 
    146 int Orxonox::gameInit (void)
    147 {
    148   glClearColor(0.0, 0.0, 0.0, 0.0);
    149  
    150   /* world init, shouldnt be done here later */
    151   world = new World;
    152   (*world).initEnvironement();
    153   localPlayer = new Player;
    154   localPlayer->setPosition(0.0, -10.0, 3.0);
    155   localPlayer->setCollisionRadius(2.0);
    156   io = new InputOutput(world, localPlayer);
    157   (*world).addPlayer(localPlayer);
    158   Environment *env = new Environment;
    159   (*world).addEnv(env);
    160   NPC* npc = new NPC;
    161   npc->setPosition(3.0, 0.0, 3.0);
    162   npc->setCollisionRadius(1.0);
    163   world->addNPC(npc);
    164 
    165   NPC* npc2 = new NPC;
    166   npc2->setPosition(-2.0, 10.0, 3.0);
    167   npc2->setCollisionRadius(1.0);
    168   world->addNPC(npc2);
    169 
    170   glutSpecialFunc(specFunc);
    171   glutSpecialUpFunc(releaseKey);
    172 
    173   glutIdleFunc(continousRedraw);
    174   //cout << "Orxonox::gameInit" << endl;
    175 }
    176 
    177 
    178 /* this is the time triggered function. heart beat*/
    179 
    180 void Orxonox::timeSlice(int value)
    181 {
    182   cout << "got " << fps << " fps" << endl;
    183   /* this is very very unsafe: io could be uninit */
    184   io->setPlayerStep(19.2/fps); /* set player to propper speed */
    185   localPlayer->shootLaser->setShootStep(20.0/fps); /* set shoot speed */
    186   world->setWorldStep(7.0/fps); /* set the speed of the terrain moving away */
    187   fps = 0;
    188   inputEnabled = true;
    189   glutTimerFunc(1000, timeSlice, 0);
    190 }
    191 
    192 
    193 
    194 void Orxonox::keyboard(unsigned char key, int x, int y)
    195 {
    196   switch(key) {
    197 
    198     /* perspectiv control */
    199   case 'w':
    200     beta -= 1;
    201     break;
    202   case 's':
    203     beta += 1;
    204     break;
    205   case 'a':
    206     alpha -= 1;
    207     break;
    208   case 'd':
    209     alpha += 1;
    210     break;
    211 
    212     /* game controls */
    213   case 'p':
    214     if (pause)
    215       {
    216         cout << "unset pause" << endl;
    217         glutIdleFunc(continousRedraw);
    218         pause = false;
    219       }
    220     else
    221       {
    222         cout << "set pause" << endl;
    223         glutIdleFunc(NULL);
    224         pause = true;
    225       }
    226     break;
    227   case 32:
    228     shoot1 = true;
    229     break;
    230   case 27:
    231   case 'q':
    232     quitGame();
    233     break;
    234   }
    235 }
    236 
    237 
    238 void Orxonox::upKeyboard(unsigned char key, int x, int y)
    239 {
    240   switch(key) {
    241   case 32:
    242     shoot1 = false;
    243     break;
    244   }
    245 }
    246 
     158  // create camera
     159  localcamera = new Camera();
     160 
     161  return 0;
     162}
     163
     164int Orxonox::init_sound ()
     165{
     166        printf("Not yet implemented\n");
     167        return 0;
     168}
     169
     170int Orxonox::init_input ()
     171{
     172        // create localinput
     173        localinput = new CommandNode( configfilename);
     174       
     175        return 0;
     176}
     177
     178
     179int Orxonox::init_networking ()
     180{
     181        printf("Not yet implemented\n");
     182        return 0;
     183}
     184
     185int Orxonox::init_resources ()
     186{
     187        printf("Not yet implemented\n");
     188        return 0;
     189}
     190
     191int Orxonox::init_world ()
     192{
     193        printf("Not yet implemented\n");
     194        return 0;
     195}
    247196
    248197void Orxonox::quitGame()
    249198{
     199        bQuitOrxonox = true;
    250200  //cout << "finished garbage colletion, quitting..." << endl;
    251   exit(0);
    252 }
    253 
    254 
    255 void Orxonox::releaseKey(int key, int x, int y)
    256 
    257   switch(key) {
    258   case GLUT_KEY_UP:
    259     upWeGo = false;
    260     break;
    261   case GLUT_KEY_DOWN:
    262     downWeGo = false;
    263     break;
    264   case GLUT_KEY_RIGHT:
    265     rightWeGo = false;
    266     break;
    267   case GLUT_KEY_LEFT:
    268     leftWeGo = false;
    269     break;
    270   }
    271 }
    272 
    273 
    274 /**
    275    \brief special keys function. called by glut
    276    
    277    Here are all special key function defined.
    278 */
    279 void Orxonox::specFunc(int key, int x, int y)
    280 {
    281   switch(key) {
    282     /* spacecraft controls */
    283   case GLUT_KEY_UP:
    284     upWeGo = true;
    285     break;
    286   case GLUT_KEY_DOWN:
    287     downWeGo = true;
    288     break;
    289   case GLUT_KEY_RIGHT:
    290     rightWeGo = true;
    291     break;
    292   case GLUT_KEY_LEFT:
    293     leftWeGo = true;
    294     break;
    295   }
    296 }
    297 
    298 
    299 void Orxonox::display()
    300 {
    301   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    302 
    303   glColor3f(0.0, 0.5, 0.6);
    304   glLoadIdentity();
    305   gluLookAt(0.0, -14.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    306   (*world).drawWorld();
    307 
    308   SDL_Flip( screen);
    309 }
    310 
    311 
    312 void Orxonox::continousRedraw()
    313 {
    314   /* increment the frames-per-second counter*/
    315   fps++;
    316   /* check for collisions */
    317   world->detectCollision();
    318 
    319   /* check for input to pass it over */
    320   if ( !pause && inputEnabled &&
    321        (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1))
    322     {
    323       if (upWeGo)
    324         (*io).goUp();
    325       if (downWeGo)
    326       (*io).goDown();
    327       if (rightWeGo)
    328         (*io).goRight();
    329       if (leftWeGo)
    330       (*io).goLeft();
    331       if (shoot1)
    332         (*io).shoot();
    333     }
    334   /* request repaint */
    335   glutPostRedisplay();
    336   //cout << "Orxonox::continousRedraw" << endl;
    337 }
    338 
    339 
    340 void Orxonox::reshape (int w, int h)
    341 {
    342   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
    343   glMatrixMode(GL_PROJECTION);
    344   glLoadIdentity();
    345   glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 200.0);
    346   glMatrixMode(GL_MODELVIEW);
    347   glLoadIdentity(); //pb why a second time?
    348 }
    349 
    350 
    351 void Orxonox::testTheShit()
    352 {
    353   //Player* pl = new Player;
    354   //(*pl).setPosition(1, 1, 1);
    355   //(*world).addPlayer(pl);
    356  
    357   //NPC* nl = new NPC;
    358   //(*world).addNPC(nl);
    359   //(*world).addNPC(nl);
    360   //(*world).addNPC(nl);
    361   //(*world).addNPC(nl);
    362   //(*world).addNPC(nl);
    363   //(*world).addNPC(nl);
    364   //(*world).testThaTest();
    365 }
    366 
     201}
    367202void Orxonox::mainLoop()
    368203{
     
    370205  while( !bQuitOrxonox)
    371206  {
     207        // Network
     208        synchronize();
    372209    // Process input
     210    handle_input();
    373211    // Process time
     212    time_slice();
    374213    // Process collision
     214    collision();
    375215    // Draw
    376216    display();
    377217  }
     218}
     219
     220void Orxonox::event_handler (SDL_Event* event)
     221{
     222        // Handle special events such as reshape, quit, focus changes
     223}
     224
     225void Orxonox::synchronize ()
     226{
     227        // Get remote input
     228        // Update synchronizables
     229}
     230
     231void Orxonox::handle_input ()
     232{
     233        // localinput
     234                localinput.process();
     235        // remoteinput
     236}
     237
     238void Orxonox::time_slice ()
     239{
     240        Uint32 curframe = SDL_GetTicks();
     241        if( !pause)
     242        {
     243                world->time_slice (curframe - lastframe);
     244                world->update ();
     245                localcamera->time_slice (curframe - lastframe);
     246        }
     247        lastframe = curframe;
     248}
     249
     250void Orxonox::collision ()
     251{
     252        world->collide ();
     253}
     254
     255void Orxonox::display ()
     256{
     257                // clear buffer
     258        glClear( GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT);
     259                // set camera
     260        localcamera->apply ();
     261                // draw world
     262        world->draw ();
     263                // draw HUD
     264                // flip buffers
     265        SDL_Flip( screen);
     266}
     267
     268Camera* Orxonox::get_camera ()
     269{
     270        return localcamera;
     271}
     272
     273Camera* Orxonox::get_world ()
     274{
     275        return world;
    378276}
    379277
     
    381279
    382280  Orxonox *orx = Orxonox::getInstance();
    383   if( (*orx).globalInit(argc, argv) == -1)
    384   {
    385     printf("! Global initialization failed\n");
     281 
     282  if( (*orx).init(argc, argv) == -1)
     283  {
     284    printf("! Orxonox initialization failed\n");
    386285    return -1;
    387286  }
    388  
    389   //(*orx).menuInit(); pb: directly jump to the game, no menu
    390  
    391   if( (*orx).gameInit() == -1)
    392   {
    393     printf("! Game initialization failed\n");
    394     return -1;
    395   }
    396 
     287
     288        lastframe = SDL_GetTicks();
     289       
    397290  (*orx).mainLoop();
    398291 
    399292  return 0;
    400293}
    401 
  • orxonox/branches/chris/src/orxonox.h

    r2058 r2068  
    66
    77class World;
    8 class InputOutput;
    9 class Player;
    10 
    118
    129class Orxonox {
     
    1613  Orxonox ();
    1714  ~Orxonox ();
     15 
     16  static char configfilename[256];
    1817  static World* world;
    19   static InputOutput* io;
    20   static Player* localPlayer;
     18  static DataTank* resources;
     19  static CommandNode* localinput;
     20  static Camera* localcamera;
     21  static SDL_Surface* screen;
     22 
    2123  static bool bQuitOrxonox;
    2224  static bool pause;
    23   static bool inputEnabled;
    24   static bool upWeGo;
    25   static bool downWeGo;
    26   static bool rightWeGo;
    27   static bool leftWeGo;
    28   static bool shoot1;
    29   static int fps;
     25        static Uint32 lastframe;
    3026
    31   static int alpha;
    32   static int beta;
    33   static int offsetX;
    34   static int offsetY;
     27        static void get_config_file (int argc, char** argv);
     28       
     29                // main loop functions
     30  static void synchronize ();
     31  static void handle_input ();
     32  static void time_slice ();
     33  static void collision ();
     34  static void display ();
     35 
     36        // subsystem initialization
     37  int init_video ();
     38  int init_sound ();
     39  int init_input ();
     40  int init_networking ();
     41  int init_resources ();
     42  int init_world ();
    3543
    36   static void timeSlice(int value);
    37 
    38   static SDL_Surface* screen;
     44  static void event_handler (SDL_Event* event);
    3945 
    4046 public:
    41   static Orxonox* getInstance (void);
     47  static Orxonox* getInstance ();
     48  static void quitGame();
    4249
    43   int globalInit (int argc, char** argv);
    44   int menuInit (void);
    45   int gameInit (void);
    46  
     50  int init (int argc, char** argv);
     51       
     52        Camera* get_camera();
     53        World* get_world();
     54       
    4755  void mainLoop();
    48 
    49   void testTheShit(void);
    50   static void display (void);
    51   static void continousRedraw(void);
    52   static void reshape (int w, int h);
    53   static void keyboard(unsigned char key, int x, int y);
    54   static void upKeyboard(unsigned char key, int x, int y);
    55   static void releaseKey(int key, int x, int y);
    56   static void specFunc(int key, int x, int y);
    57   static void quitGame(void);
    5856};
    5957
  • orxonox/branches/chris/src/vector.cc

    r1982 r2068  
    266266
    267267/**
     268   \brief fills the specified buffer with a 4x4 glmatrix
     269   \param buffer: Pointer to an array of 16 floats
     270   
     271   Use this to get the rotation in a gl-compatible format
     272*/
     273void Rotation::glmatrix (float* buffer)
     274{
     275        buffer[0] = m[0];
     276        buffer[1] = m[3];
     277        buffer[2] = m[6];
     278        buffer[3] = m[0];
     279        buffer[4] = m[1];
     280        buffer[5] = m[4];
     281        buffer[6] = m[7];
     282        buffer[7] = m[0];
     283        buffer[8] = m[2];
     284        buffer[9] = m[5];
     285        buffer[10] = m[8];
     286        buffer[11] = m[0];
     287        buffer[12] = m[0];
     288        buffer[13] = m[0];
     289        buffer[14] = m[0];
     290        buffer[15] = m[1];
     291}
     292
     293
     294/**
    268295   \brief rotates the vector by the given rotation
    269296   \param v: a vector
  • orxonox/branches/chris/src/vector.h

    r2014 r2068  
    5858  ~Rotation () {}
    5959 
     60  glmatrix (float* buffer);
    6061};
    6162
  • orxonox/branches/chris/src/world.cc

    r2058 r2068  
    1212   ### File Specific:
    1313   main-programmer: Patrick Boenzli
    14    co-programmer:
     14   co-programmer: Christian Meyer
    1515*/
    1616
     
    1818#include <stdlib.h>
    1919#include <cmath>
    20 #include <GL/glut.h>
    2120
    2221#include "npc.h"
     
    3938   This creates a new empty world!
    4039*/
    41 World::World () {
    42   lastPlayer = null;
    43   lastNPC = null;
    44   lastEnv = null;
    45   primitiveMove = 0;
    46   step = 0;
     40World::World ()
     41{
     42        entities = new List<WorldEntitites>();
    4743}
    4844
    4945
    50 World::~World () {}
    51 
    52 
    53 /**
    54    \brief Add Player
    55    \param player A reference to the new player object
    56    
    57    Add a new Player to the game. Player has to be initialised previously
    58 */
    59 bool World::addPlayer(Player* player)
     46World::~World ()
    6047{
    61   playerList* listMember = new playerList;
    62   listMember->player = player;
    63   if ( lastPlayer != null )
    64     {
    65       listMember->number = lastPlayer->number + 1;
    66       listMember->next = lastPlayer;
    67     }
    68   else
    69     {
    70       listMember->number = 0;
    71       listMember->next = null;
    72     }
    73   lastPlayer = listMember;
     48        delete entities;
    7449}
    7550
    76 
    77 /**
    78    \brief Remove Player
    79    \param player A reference to the new npc object
    80    
    81    Remove a new Player to the game.
    82 */
    83 bool World::removePlayer(Player* player) {
    84   cout << "World::removeNPC not implemented yet" << endl;
     51template<class T> T* World::spawn<T>(Location* loc, WorldEntity* owner)
     52{
     53        T* entity = new T();
     54        entities->add ((WorldEntity*)entity, LIST_ADD_NEXT);
     55        return entity;
    8556}
    8657
    87 Player* World::getLocalPlayer()
     58World::collide ()
    8859{
    89   return localPlayer;
     60        List<WorldEntity> *a, *b;
     61        WorldEntity *aobj, *bobj;
     62       
     63        a = entities->get_next();
     64       
     65        while( a != NULL)
     66        {
     67                aobj = a->get_object();
     68                if( aobj->bCollide && aobj->collisioncluster != NULL)
     69                {
     70                        b = a->get_next();
     71                        while( b != NULL)
     72                        {
     73                                bobj = b->get_object();
     74                                if( bobj->bCollide && bobj->collisioncluster != NULL)
     75                                {
     76                                        Uint32 ahitflg, bhitflg;
     77                                        if check_collision ( aobj->place, aobj->collisioncluster, &ahitflg, bobj->place, bobj->collisioncluster, &bhitflg);
     78                                        {
     79                                                aobj->collide (bobj, ahitflg, bhitflg);
     80                                                bobj->collide (aobj, bhitflg, ahitflg);
     81                                        }
     82                                }
     83                                b = b->get_next();
     84                        }
     85                }
     86                a = a->get_next();
     87        }
    9088}
    9189
    92 
    93 /**
    94    \brief Add Non-Player-Character
    95    \param player A reference to the new npc object
    96    
    97    Add a new Non-Player-Character to the game. Player has to be initialised previously
    98 */
    99 bool World::addNPC(NPC* npc)
     90void World::draw ()
    10091{
    101   npcList* listMember = new npcList;
    102   listMember->npc = npc;
    103   if ( lastNPC != null )
    104     {
    105       listMember->number = lastNPC->number + 1;
    106       listMember->next = lastNPC;
    107     }
    108   else
    109     {
    110       listMember->number = 0;
    111       listMember->next = null;
    112     }
    113   lastNPC = listMember;
     92        // draw geometry
     93       
     94        // draw entities
     95        List<WorldEntity> *l;
     96        WorldEntity* entity;
     97       
     98        l = entities->get_next(); 
     99        while( l != NULL)
     100        {
     101                entity = l->get_object();
     102                if(     entity->bDraw) entity->draw();
     103          l = l->get_next();
     104        }
    114105}
    115106
    116 
    117 /**
    118    \brief Remove Non-Player Character
    119    \param player A reference to the new npc object
    120    
    121    Remove a new Non-Player-Character to the game.
    122 */
    123 bool World::removeNPC(NPC* npc) {
    124 
    125   npcList* npcRef = lastNPC;
    126   npcList* lastRef = lastNPC;
    127   while ( npcRef != null )
    128     {
    129       if ( npcRef->npc == npc ) {
    130         cout << "found" << endl;
    131         if ( npcRef == lastRef ) {
    132           lastNPC = lastNPC->next;
    133           delete npcRef;
    134           npcRef = lastNPC;
    135           lastRef = lastNPC;
    136         }
    137         else {
    138           lastRef->next = npcRef->next;
    139           delete npcRef;
    140           npcRef = lastRef->next;
    141         }
    142         cout << "killed ..." << endl;
    143       }
    144       else {
    145         lastRef = npcRef;
    146         npcRef = npcRef->next;
    147       }
    148     }
    149   cout << "npc left" << endl;
     107void World::update ()
     108{
    150109}
    151110
    152 
    153 
    154 /**
    155    \brief Add environmental object
    156    \param player A reference to the new env object
    157    
    158    Add a new Environment to the world. Env has to be initialised before.
    159 */
    160 bool World::addEnv(Environment* env)
     111void World::time_slice (Uint32 deltaT)
    161112{
    162   envList* listMember = new envList;
    163   listMember->env = env;
    164   if ( lastEnv != null )
    165     {
    166       listMember->number = lastEnv->number + 1;
    167       listMember->next = lastEnv;
    168     }
    169   else
    170     {
    171       listMember->number = 0;
    172       listMember->next = null;
    173     }
    174   lastEnv = listMember;
     113        List<WorldEntity> *l;
     114        WorldEntity* entity;
     115        float seconds = deltaT;
     116       
     117        seconds /= 1000;
     118       
     119        l = entities->get_next(); 
     120        while( l != NULL)
     121        {
     122                entity = l->get_object();
     123                entity->tick (seconds);
     124          l = l->get_next();
     125        }
    175126}
    176 
    177 
    178 
    179 
    180 /**
    181    \brief Draws the World and all Objects contained
    182    
    183    Calls the draw function of all: Objects, Players, Environement. This is the core of all graphics here.
    184 */
    185 void World::drawWorld(void)
    186 {
    187 
    188   glLoadIdentity();
    189   gluLookAt(0.0, -14.0 + DataTank::yOffset, 15.0, 0.0, 0.0 + DataTank::yOffset, 0.0, 0.0, 1.0, 0.0);
    190   /* first draw all players */
    191   playerList* tmpPlayer = lastPlayer;
    192   Player* player = tmpPlayer->player;
    193   while( tmpPlayer != null )
    194     {
    195       tmpPlayer->player->paint();
    196       tmpPlayer = tmpPlayer->next;
    197     }
    198   /* second draw all npcs */
    199   npcList* tmpNPC = lastNPC;
    200   while( tmpNPC != null )
    201     {
    202       (*tmpNPC->npc).paint();
    203       tmpNPC = tmpNPC->next;
    204     }
    205 
    206   /* now draw the rest of the world: environement */
    207   envList* tmpEnv = lastEnv;
    208   while( tmpEnv != null )
    209     {
    210       (*tmpEnv->env).drawEnvironment();
    211       tmpEnv = tmpEnv->next;
    212     }
    213  
    214   /* draw the ground grid  */
    215   glColor3f(0.0, 1.0, 0.0);
    216   glBegin(GL_LINES);
    217   /* for the moment, we've got only pseudo moving ground */
    218   for (int y = 0; y < 60; y += 2)
    219     {
    220       for (int x = 0; x < 60; x += 2)
    221         {
    222           glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
    223           glVertex3f((float)(x - 28), (float)(y - 30), surface[x+2][y]);
    224         }
    225     }
    226   glEnd();
    227  
    228   glBegin(GL_LINES);
    229   for (int x = 0; x < 60; x += 2)
    230     {
    231       for (int y = 0; y < 60; y += 2)
    232         {
    233           glVertex3f((float)(x - 30), (float)(y - 30), surface[x][y]);
    234           glVertex3f((float)(x - 30), (float)(y - 28), surface[x][y+2]);
    235         }
    236     }
    237   glEnd();
    238 
    239   //primitiveMove+=0.07;
    240   DataTank::yOffset += step;
    241 
    242   tmpPlayer = lastPlayer;
    243   while( tmpPlayer != null )
    244     {
    245       tmpPlayer->player->yCor += step;
    246       tmpPlayer = tmpPlayer->next;
    247     }
    248 
    249 
    250 }
    251 
    252 
    253 void World::initEnvironement()
    254 {
    255 
    256  for (int x = 0; x < 60; x += 2)
    257     {
    258       for (int y = 0; y < 60; y += 2)
    259         {
    260           surface[x][y] = 0;
    261         }
    262     }
    263 }
    264 
    265 
    266 void World::setWorldStep(float step)
    267 {
    268   //cout << "World::setWorldStep(" << step << ");" << endl;
    269   this->step = step;
    270   //cout << "setting speed to " << step << endl;
    271 }
    272 
    273 
    274 
    275 /**
    276    \brief Updates the world and all its objects
    277    
    278    Calculates the new state of the world. User-input and AI of
    279    the enemies are accounted for.
    280 */
    281 void World::updateWorld(void)
    282 {
    283  
    284 
    285 }
    286 
    287 
    288 /* collision detection */
    289 /* fix: bad efficency: stupid brute force */
    290 
    291 void World::detectCollision()
    292 {
    293   //cout << "World::detectCollision" << endl;
    294   float xOff, yOff, zOff, radius;
    295   npcList* tmpNPC, *tmpRef;
    296 
    297   //cout << "World::detectCollsions" << endl;
    298   /* first: check if any player's shoots trigger a collision */
    299   playerList* tmpPlayer = lastPlayer;
    300   Player* player = tmpPlayer->player;
    301   int state;
    302   while( tmpPlayer != null )
    303     {
    304       tmpNPC = lastNPC;
    305       while( tmpNPC != null )
    306         {
    307           //cout << "npc != null" << endl;
    308           radius = tmpNPC->npc->collisionRadius;
    309           //cout << "worki" << endl;
    310           ShootLaser::shoot* shoota = tmpPlayer->player->shootLaser->lastShoot;
    311           while( shoota != null )
    312             {
    313               xOff = shoota->xCor - tmpNPC->npc->xCor;
    314               yOff = shoota->yCor - tmpNPC->npc->yCor;
    315               zOff = shoota->zCor - tmpNPC->npc->zCor;
    316               if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius )
    317                 {
    318                   //cout << "COLLISION " << endl;
    319                   int state = tmpNPC->npc->hit();
    320                   /* state is a value that marks if the ship dies or not */
    321                   /* if state == 0 the ship dies and we have to remove it */
    322                   /*
    323                   if ( state == 0 ) {
    324                     tmpRef = tmpNPC;
    325                     tmpNPC = tmpNPC->next;
    326                     removeNPC(tmpRef->npc);
    327                     break;
    328                   }
    329                   */
    330                 }
    331               shoota = shoota->next;
    332             }
    333           //cout << "changing npc..." << endl;
    334           tmpNPC = tmpNPC->next;
    335           //cout << "..changing npc done" << endl;
    336         }
    337       //cout << "changing play..." << endl;
    338       tmpPlayer = tmpPlayer->next;
    339       //cout << "changing play done" << endl;
    340     }
    341 
    342   //cout << "World::detectCollisions middle" << endl;
    343 
    344   /* second: check if any player hits an enemy */
    345   tmpPlayer = lastPlayer;
    346   while( tmpPlayer != null )
    347     {
    348       tmpNPC = lastNPC;
    349       while( tmpNPC != null )
    350         {
    351           radius = tmpNPC->npc->collisionRadius + tmpPlayer->player->collisionRadius;
    352           xOff = tmpPlayer->player->xCor - tmpNPC->npc->xCor;
    353           yOff = tmpPlayer->player->yCor - tmpNPC->npc->yCor;
    354           zOff = tmpPlayer->player->zCor - tmpNPC->npc->zCor;
    355           if ( sqrt(xOff*xOff + yOff*yOff + zOff*zOff) < radius ) {
    356             //cout << "COLLISION " << endl;
    357             tmpNPC->npc->hit();
    358           }
    359          
    360           tmpNPC = tmpNPC->next;
    361         }
    362      
    363       tmpPlayer = tmpPlayer->next;
    364     }
    365  
    366  
    367 
    368   /* third: check if any enemy shoots a player */
    369 
    370   //cout << "World::detectCollisions end" << endl;
    371 }
    372 
    373 
    374 
    375 /**
    376    \brief Routine for testing purposes.
    377    
    378    testing, testing, testing...
    379 */
    380 void World::testThaTest(void)
    381 {
    382   cout << "World::testThaTest() called" << endl;
    383   /* test addPlayer */
    384   cout << "addPlayer test..." << endl;
    385   playerList* pl = lastPlayer;
    386   while ( pl != null )
    387     {
    388       cout << "player " << pl->number << " was found" << endl;
    389       pl = pl->next;
    390     }
    391 
    392   /* test addNPC */
    393   cout << "addNPC test..." << endl;
    394   npcList* nl = lastNPC;
    395   while ( nl != null )
    396     {
    397       cout << "npc " << nl->number << " was found" << endl;
    398       nl = nl->next;
    399     }
    400 
    401 
    402   /* test addEnv */
    403   cout << "addEnv test..." << endl;
    404   envList* en = lastEnv;
    405   while ( en != null )
    406     {
    407       cout << "env " << en->number << " was found" << endl;
    408       en = en->next;
    409     }
    410 
    411   /* test drawWorld() */
    412 }
  • orxonox/branches/chris/src/world.h

    r2058 r2068  
    22#ifndef WORLD_H
    33#define WORLD_H
    4 
    5 class Player;
    6 class NPC;
    7 class Environment;
    8 
    94
    105class World {
     
    149  ~World ();
    1510
    16   float primitiveMove;
     11        template<class T> T* spawn<T>(Location* loc, WorldEntity* owner);       // template to be able to spawn any derivation of WorldEntity
    1712
    18   /* for easier use: map the first two player here */
    19   Player *localPlayer;
    20   Player *player1;
    21   Player *player2;
    22 
    23   /* a list of all players */
    24   struct playerList {
    25     playerList* next;
    26     Player* player;
    27     int number;
    28   };
    29   playerList* lastPlayer;
    30 
    31   /* a list of all non-player-characters */
    32   struct npcList {
    33     npcList* next;
    34     NPC* npc;
    35     int number;
    36   };
    37   npcList* lastNPC;
    38 
    39   /* a list of all environmental objects */
    40   struct envList {
    41     envList* next;
    42     Environment* env;
    43     int number;
    44   };
    45   envList* lastEnv;
    46 
    47 
    48 
    49 
    50   bool addPlayer(Player* player);
    51   bool removePlayer(Player* player);
    52   Player* getLocalPlayer();
    53   bool addNPC(NPC* npc);
    54   bool removeNPC(NPC* npc);
    55   bool addEnv(Environment* env);
    56 
    57   void drawWorld(void);
    58   void initEnvironement(void);
    59   void setWorldStep(float step);
    60   void updateWorld(void);
    61   void detectCollision(void);
    62   void testThaTest(void);
    63 
     13        void time_slice (Uint32 deltaT);
     14        void collide ();
     15        void draw ();
     16        void update (); // maps Locations to Placements
     17        void calc_camera_pos (Location* loc, Placement* plc);
     18       
    6419 private:
    65   float surface[120][120];
    66   float step;
    67 
     20 
     21        List<WorldEntity>* entities;
     22       
     23                // base level data
     24        Track* track;
     25        Uint32 tracklen;
     26        Vector* pathnodes;
    6827
    6928};
  • orxonox/branches/chris/src/world_entity.cc

    r2058 r2068  
    1313   ### File Specific:
    1414   main-programmer: Patrick Boenzli
    15    co-programmer: ...
     15   co-programmer: Christian Meyer
    1616*/
    1717
     
    120120   This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn.
    121121*/
    122 void WorldEntity::paint()
     122void WorldEntity::draw()
    123123{
    124   cout << "WorldEntity::paint()" << endl;
     124  cout << "WorldEntity::draw()" << endl;
    125125}
    126126
     
    131131   \param loc: place where the collision happens
    132132*/
    133 void WorldEntity::collide(WorldEntity* we, Vector loc) {}
     133void WorldEntity::collide(WorldEntity* other, Uint32 ownhitflags, Uint32 otherhitflags) {}
    134134
    135135/**
  • orxonox/branches/chris/src/world_entity.h

    r2066 r2068  
    2929  void removeAbility(Ability* ability);
    3030
    31   virtual void tick(float time);
    32   virtual void paint();
    33   /* virtual void actionEvent(Event* event); */
    34   virtual void collide(WorldEntity* we, Vector loc);
    35   virtual void hit(WorldEntity* weapon, Vector loc);
    36   virtual void destroy();
     31  virtual void tick (float time);
     32  virtual void draw ();
     33  virtual void collide (WorldEntity* other,  Uint32 ownhitflags, Uint32 otherhitflags);
     34  virtual void hit (WorldEntity* weapon, Vector loc);
     35  virtual void destroy ();
    3736  virtual void command (Command* cmd);
     37  virtual void get_lookat (Location* locbuf);
    3838
    3939  virtual void entityPreEnter();
     
    4242  virtual void entityPostQuit();
    4343
    44  
     44  bool bCollide;
     45  bool bDraw;
    4546
    4647 private:
    47   Vector* position;
    48   Vector* orientation;
     48        WorldEntity* owner;
     49        CollisionCluster* collisioncluster;
     50        Placement place;
     51        Location loc;
    4952  /* List of abilities */
    5053  float health;
Note: See TracChangeset for help on using the changeset viewer.