Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2636 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Oct 25, 2004, 12:48:39 AM (20 years ago)
Author:
patrick
Message:
  • Added a GameLoader to the game. This enables orxonox to load a campaign consisting of multimple worlds and cinematics etc. However, cinematics are not yet implemented.

In the game you can jump from one level to the other by pressing x. Currently there are only two very simple levels defined. (DEBUG_LEVEL_0, DEBUG_LEVEL_1).

  • Added Error Handling structs to signal the error source and code
Location:
orxonox/trunk/src
Files:
7 added
16 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.am

    r2589 r2636  
    66
    77bin_PROGRAMS=orxonox
    8 orxonox_SOURCES=orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc
     8orxonox_SOURCES=orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc game_loader.cc campaign.cc story_entity.cc
    99
    1010noinst_HEADERS=ability.h data_tank.h npc.h stdincl.h ai.h environment.h orxonox.h synchronisable.h base_entity.h error.h player.h track.h camera.h ini_parser.h power_up.h vector.h collision.h keynames.h proto_class.h world.h command_node.h list.h shoot_laser.h world_entity.h coordinates.h message_structures.h shoot_rocket.h
  • orxonox/trunk/src/Makefile.in

    r2589 r2636  
    117117#"-O3 -pedantic -fPIC -ffast-math -I/usr/X11R6/include"
    118118bin_PROGRAMS = orxonox
    119 orxonox_SOURCES = orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc
     119orxonox_SOURCES = orxonox.cc world.cc player.cc data_tank.cc world_entity.cc vector.cc camera.cc collision.cc command_node.cc ini_parser.cc keynames.cc track.cc base_entity.cc game_loader.cc campaign.cc story_entity.cc
    120120
    121121noinst_HEADERS = ability.h data_tank.h npc.h stdincl.h ai.h environment.h orxonox.h synchronisable.h base_entity.h error.h player.h track.h camera.h ini_parser.h power_up.h vector.h collision.h keynames.h proto_class.h world.h command_node.h list.h shoot_laser.h world_entity.h coordinates.h message_structures.h shoot_rocket.h
     
    132132        camera.$(OBJEXT) collision.$(OBJEXT) command_node.$(OBJEXT) \
    133133        ini_parser.$(OBJEXT) keynames.$(OBJEXT) track.$(OBJEXT) \
    134         base_entity.$(OBJEXT)
     134        base_entity.$(OBJEXT) game_loader.$(OBJEXT) campaign.$(OBJEXT) \
     135        story_entity.$(OBJEXT)
    135136orxonox_OBJECTS = $(am_orxonox_OBJECTS)
    136137orxonox_LDADD = $(LDADD)
     
    142143am__depfiles_maybe = depfiles
    143144@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/base_entity.Po ./$(DEPDIR)/camera.Po \
    144 @AMDEP_TRUE@    ./$(DEPDIR)/collision.Po \
     145@AMDEP_TRUE@    ./$(DEPDIR)/campaign.Po ./$(DEPDIR)/collision.Po \
    145146@AMDEP_TRUE@    ./$(DEPDIR)/command_node.Po \
    146 @AMDEP_TRUE@    ./$(DEPDIR)/data_tank.Po ./$(DEPDIR)/ini_parser.Po \
    147 @AMDEP_TRUE@    ./$(DEPDIR)/keynames.Po ./$(DEPDIR)/orxonox.Po \
    148 @AMDEP_TRUE@    ./$(DEPDIR)/player.Po ./$(DEPDIR)/track.Po \
     147@AMDEP_TRUE@    ./$(DEPDIR)/data_tank.Po ./$(DEPDIR)/game_loader.Po \
     148@AMDEP_TRUE@    ./$(DEPDIR)/ini_parser.Po ./$(DEPDIR)/keynames.Po \
     149@AMDEP_TRUE@    ./$(DEPDIR)/orxonox.Po ./$(DEPDIR)/player.Po \
     150@AMDEP_TRUE@    ./$(DEPDIR)/story_entity.Po ./$(DEPDIR)/track.Po \
    149151@AMDEP_TRUE@    ./$(DEPDIR)/vector.Po ./$(DEPDIR)/world.Po \
    150152@AMDEP_TRUE@    ./$(DEPDIR)/world_entity.Po
     
    157159HEADERS = $(noinst_HEADERS)
    158160
    159 DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.in INSTALL \
     161DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.in ChangeLog INSTALL \
    160162        Makefile.am
    161163SOURCES = $(orxonox_SOURCES)
     
    206208@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/base_entity.Po@am__quote@
    207209@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/camera.Po@am__quote@
     210@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/campaign.Po@am__quote@
    208211@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/collision.Po@am__quote@
    209212@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/command_node.Po@am__quote@
    210213@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/data_tank.Po@am__quote@
     214@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/game_loader.Po@am__quote@
    211215@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ini_parser.Po@am__quote@
    212216@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keynames.Po@am__quote@
    213217@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox.Po@am__quote@
    214218@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/player.Po@am__quote@
     219@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/story_entity.Po@am__quote@
    215220@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/track.Po@am__quote@
    216221@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@
  • orxonox/trunk/src/camera.cc

    r2551 r2636  
    2727   This standard constructor sets all parameters to zero
    2828*/
    29 Camera::Camera ()
    30 {
     29Camera::Camera (World* world)
     30{
     31  this->world = world;
    3132  bound = NULL;
    3233  /* give it some physical live */
     
    3637  fs = new Vector(0.0, 0.0, 0.0);
    3738  cameraMode = NORMAL;
    38 
    3939  deltaTime = 3000.0;
    4040  cameraOffset = 1.0;
     
    179179      /* the camera is handled like an entity and rolls on the track */
    180180    case NORMAL:
    181       Orxonox *orx = Orxonox::getInstance();
    182181      Location lookat; 
    183       if( bound != NULL)
     182      if( bound != NULL && world != NULL )
    184183        {
    185184          bound->get_lookat (&lookat);
    186           orx->get_world()->calc_camera_pos (&lookat, &desired_place);
     185          world->calc_camera_pos (&lookat, &desired_place);
    187186        }
    188187      else
     
    293292    }
    294293}
     294
     295
     296void Camera::setWorld(World* world)
     297{
     298  this->world = world;
     299}
  • orxonox/trunk/src/camera.h

    r2551 r2636  
    1010
    1111class WorldEntity;
     12class World;
    1213
    1314//! Camera
    1415/**
    15         This class controls the viewpoint from which the World is rendered. To use the
    16         Camera it has to be bound to a WorldEntity which serves as the reference focus
    17         point. The Camera itself calls the WorldEntity::get_lookat() and
    18         World::calc_camera_pos() functions to calculate the position it currently should
    19         be in.
     16   This class controls the viewpoint from which the World is rendered. To use the
     17   Camera it has to be bound to a WorldEntity which serves as the reference focus
     18   point. The Camera itself calls the WorldEntity::get_lookat() and
     19   World::calc_camera_pos() functions to calculate the position it currently should
     20   be in.
    2021*/
    2122
     
    2728  Placement actual_place;               //!< the Camera's current position
    2829  Placement desired_place;        //!< where the Camera should be according to calculations
     30  World* world;
    2931 
    3032  /* physical system - not needed yet */
     
    4951  Quaternion *res;
    5052 
     53 
     54  CAMERA_MODE cameraMode; //!< saves the camera mode: how the camera follows the entity
     55 
     56  void update_desired_place ();
     57 
     58 public:
     59  Camera (World* world);
     60  ~Camera ();
     61 
     62  void time_slice (Uint32 deltaT);
     63  void apply ();
     64  void bind (WorldEntity* entity);
     65  void jump (Placement* plc);
    5166
    52   CAMERA_MODE cameraMode; //!< saves the camera mode: how the camera follows the entity
    53 
    54         void update_desired_place ();
    55        
    56  public:
    57   Camera ();
    58   ~Camera ();
    59 
    60         void time_slice (Uint32 deltaT);
    61         void apply ();
    62         void bind (WorldEntity* entity);
    63         void jump (Placement* plc);
     67  void setWorld(World* world); 
    6468
    6569};
  • orxonox/trunk/src/command_node.cc

    r2551 r2636  
    1919#include "ini_parser.h"
    2020#include "world_entity.h"
     21#include "game_loader.h"
    2122
    2223#include <stdio.h>
     
    2728
    2829/**
    29         \brief constructs a CommandNode to handle remote input
    30         \param ID: unique denumerator to identify the node in the network
     30   \brief constructs a CommandNode to handle remote input
     31   \param ID: unique denumerator to identify the node in the network
    3132*/
    3233CommandNode::CommandNode (int ID)
    3334{
    34         bound = new List<WorldEntity>();
    35         aliases = NULL;
    36         netID = ID;
    37         bLocalInput = false;
    38 }
    39 
    40 /**
    41         \brief constructs a CommandNode to handle local input
    42         \param filename: The path and name of the file to load the key bindings from
     35  bound = new List<WorldEntity>();
     36  aliases = NULL;
     37  netID = ID;
     38  bLocalInput = false;
     39}
     40
     41/**
     42   \brief constructs a CommandNode to handle local input
     43   \param filename: The path and name of the file to load the key bindings from
    4344*/
    4445CommandNode::CommandNode (char* filename = DEFAULT_KEYBIND_FILE)
    4546{
    46         aliases = NULL;
    47         bLocalInput = true;
    48         netID = 0;
    49         bound = new List<WorldEntity>();
    50         load_bindings (filename);
    51 }
    52 
    53 /**
    54         \brief removes the CommandNode from memory
     47  aliases = NULL;
     48  bLocalInput = true;
     49  netID = 0;
     50  bound = new List<WorldEntity>();
     51  load_bindings (filename);
     52}
     53
     54/**
     55   \brief removes the CommandNode from memory
    5556*/
    5657CommandNode::~CommandNode ()
    5758{
    58         if( aliases != NULL) free (aliases);
    59         if( bound != NULL) delete bound;
    60 }
    61 
    62 /**
    63         \brief loads new key bindings from a file
    64         \param filename: The path and name of the file to load the bindings from
     59  if( aliases != NULL) free (aliases);
     60  if( bound != NULL) delete bound;
     61}
     62
     63/**
     64   \brief loads new key bindings from a file
     65   \param filename: The path and name of the file to load the bindings from
    6566*/
    6667void CommandNode::load_bindings (char* filename)
    6768{
    68         FILE* stream;
    69        
    70         printf("Loading key bindings from %s\n", filename);
    71        
    72         if( filename == NULL) filename = DEFAULT_KEYBIND_FILE;
    73        
    74                 // remove old bindings if present
    75         if( aliases != NULL)
     69  FILE* stream;
     70 
     71  printf("Loading key bindings from %s\n", filename);
     72 
     73  if( filename == NULL) filename = DEFAULT_KEYBIND_FILE;
     74 
     75  // remove old bindings if present
     76  if( aliases != NULL)
     77    {
     78      free (aliases);
     79      aliases = NULL;
     80    }
     81 
     82  // create parser
     83  IniParser parser (filename);
     84  if( parser.get_section ("Bindings") == -1)
     85    {
     86      printf("Could not find key bindings in %s\n", filename);
     87      return;
     88    }
     89  // allocate empty lookup table
     90  aliases = (KeyBindings*) calloc (1, sizeof (KeyBindings));
     91 
     92  char namebuf[256];
     93  char valuebuf[256];
     94  memset (namebuf, 0, 256);
     95  memset (valuebuf, 0, 256);
     96  int* index;
     97 
     98  while( parser.next_var (namebuf, valuebuf) != -1)
     99    {
     100      index = name_to_index (namebuf);
     101      switch( index[0])
    76102        {
    77                 free (aliases);
    78                 aliases = NULL;
     103        case 0:
     104          printf("Key binding %d(%s) set to %s\n", index[1], SDLK_to_keyname( index[1]), valuebuf);
     105          strcpy (aliases->keys[index[1]], valuebuf);
     106          break;
     107        case 1:
     108          printf("Button binding %d(%s) set to %s\n", index[1], SDLB_to_buttonname( index[1]), valuebuf);
     109          strcpy (aliases->buttons[index[1]], valuebuf);
     110          break;
     111        default:
     112          break;
    79113        }
    80                        
    81                 // create parser
    82         IniParser parser (filename);
    83         if( parser.get_section ("Bindings") == -1)
     114      memset (namebuf, 0, 256);
     115      memset (valuebuf, 0, 256);
     116    }
     117}
     118
     119/**
     120   \brief binds a WorldEntity to the CommandNode
     121   \param entity: Pointer to the entity to bind
     122*/
     123void CommandNode::bind (WorldEntity* entity)
     124{
     125  bound->add (entity, LIST_ADD_NEXT, true);
     126}
     127
     128/**
     129   \brief removes an entity from the list of the CommandNode
     130   \param entity: Pointer to the entity to relese
     131*/
     132void CommandNode::unbind (WorldEntity* entity)
     133{
     134  bound->remove (entity, LIST_FIND_FW);
     135}
     136
     137int* CommandNode::name_to_index (char* name)
     138{
     139  coord[0] = -1;
     140  coord[1] = -1;
     141  int c;
     142  if( (c = keyname_to_SDLK (name)) != -1)
     143    {
     144      coord[1] = c;
     145      coord[0] = 0;
     146    }
     147  if( (c = buttonname_to_SDLB (name)) != -1)
     148    {
     149      coord[1] = c;
     150      coord[0] = 1;
     151    }
     152  return coord;
     153}
     154
     155/**
     156   \brief tells the CommandNode to run through all pending events and relay them accordingly
     157*/
     158void CommandNode::process ()
     159{
     160  if( bLocalInput) process_local ();
     161  else process_network ();
     162}
     163
     164void CommandNode::process_local ()
     165{
     166  SDL_Event event;
     167  Command cmd;
     168 
     169  while( SDL_PollEvent (&event))
     170    {
     171      memset (cmd.cmd, 0, CMD_LENGHT);
     172      switch( event.type)
    84173        {
    85                 printf("Could not find key bindings in %s\n", filename);
    86                 return;
     174        case SDL_KEYDOWN:
     175          strcpy (cmd.cmd, aliases->keys[event.key.keysym.sym]);
     176          cmd.bUp = false;
     177          if( strlen (cmd.cmd) > 0) relay (&cmd);
     178          break;
     179        case SDL_KEYUP:
     180          strcpy( cmd.cmd, aliases->keys[event.key.keysym.sym]);
     181          cmd.bUp = true;
     182          if( strlen (cmd.cmd) > 0) relay (&cmd);
     183          break;
     184        case SDL_MOUSEMOTION:
     185          strcpy( cmd.cmd, "cursor");
     186          cmd.x = event.motion.x;
     187          cmd.y = event.motion.y;
     188          cmd.xrel = event.motion.xrel;
     189          cmd.yrel = event.motion.yrel;
     190          break;
     191        case SDL_MOUSEBUTTONUP:
     192          strcpy( cmd.cmd, aliases->buttons[event.button.button]);
     193          cmd.bUp = true;
     194          if( strlen (cmd.cmd) > 0) relay (&cmd);
     195          break;
     196        case SDL_MOUSEBUTTONDOWN:
     197          strcpy( cmd.cmd, aliases->buttons[event.button.button]);
     198          cmd.bUp = false;
     199          if( strlen (cmd.cmd) > 0) relay (&cmd);
     200          break;
     201        case SDL_JOYAXISMOTION:
     202        case SDL_JOYBALLMOTION:
     203        case SDL_JOYHATMOTION:
     204        case SDL_JOYBUTTONDOWN:
     205        case SDL_JOYBUTTONUP:
     206          break;
     207        default:
     208          Orxonox *orx = Orxonox::getInstance();
     209          orx->event_handler (&event);
     210         
     211          break;
    87212        }
    88                         // allocate empty lookup table
    89         aliases = (KeyBindings*) calloc (1, sizeof (KeyBindings));
    90        
    91         char namebuf[256];
    92         char valuebuf[256];
    93         memset (namebuf, 0, 256);
    94         memset (valuebuf, 0, 256);
    95         int* index;
    96 
    97         while( parser.next_var (namebuf, valuebuf) != -1)
    98         {
    99                 index = name_to_index (namebuf);
    100                 switch( index[0])
    101                 {
    102                         case 0:
    103                                 printf("Key binding %d(%s) set to %s\n", index[1], SDLK_to_keyname( index[1]), valuebuf);
    104                                 strcpy (aliases->keys[index[1]], valuebuf);
    105                                 break;
    106                         case 1:
    107                                 printf("Button binding %d(%s) set to %s\n", index[1], SDLB_to_buttonname( index[1]), valuebuf);
    108                                 strcpy (aliases->buttons[index[1]], valuebuf);
    109                                 break;
    110                         default:
    111                                 break;
    112                 }
    113                 memset (namebuf, 0, 256);
    114                 memset (valuebuf, 0, 256);
    115         }
    116 }
    117 
    118 /**
    119         \brief binds a WorldEntity to the CommandNode
    120         \param entity: Pointer to the entity to bind
    121 */
    122 void CommandNode::bind (WorldEntity* entity)
    123 {
    124         bound->add (entity, LIST_ADD_NEXT, true);
    125 }
    126 
    127 /**
    128         \brief removes an entity from the list of the CommandNode
    129         \param entity: Pointer to the entity to relese
    130 */
    131 void CommandNode::unbind (WorldEntity* entity)
    132 {
    133         bound->remove (entity, LIST_FIND_FW);
    134 }
    135 
    136 int* CommandNode::name_to_index (char* name)
    137 {
    138         coord[0] = -1;
    139         coord[1] = -1;
    140         int c;
    141         if( (c = keyname_to_SDLK (name)) != -1)
    142         {
    143                 coord[1] = c;
    144                 coord[0] = 0;
    145         }
    146         if( (c = buttonname_to_SDLB (name)) != -1)
    147         {
    148                 coord[1] = c;
    149                 coord[0] = 1;
    150         }
    151         return coord;
    152 }
    153 
    154 /**
    155         \brief tells the CommandNode to run through all pending events and relay them accordingly
    156 */
    157 void CommandNode::process ()
    158 {
    159         if( bLocalInput) process_local ();
    160         else process_network ();
    161 }
    162 
    163 void CommandNode::process_local ()
    164 {
    165         SDL_Event event;
    166         Command cmd;
    167        
    168         while( SDL_PollEvent (&event))
    169         {
    170                 memset (cmd.cmd, 0, CMD_LENGHT);
    171                 switch( event.type)
    172                 {
    173                         case SDL_KEYDOWN:
    174                                 strcpy (cmd.cmd, aliases->keys[event.key.keysym.sym]);
    175                                 cmd.bUp = false;
    176                                 if( strlen (cmd.cmd) > 0) relay (&cmd);
    177                                 break;
    178                         case SDL_KEYUP:
    179                                 strcpy( cmd.cmd, aliases->keys[event.key.keysym.sym]);
    180                                 cmd.bUp = true;
    181                                 if( strlen (cmd.cmd) > 0) relay (&cmd);
    182                                 break;
    183                         case SDL_MOUSEMOTION:
    184                                 strcpy( cmd.cmd, "cursor");
    185                                 cmd.x = event.motion.x;
    186                                 cmd.y = event.motion.y;
    187                                 cmd.xrel = event.motion.xrel;
    188                                 cmd.yrel = event.motion.yrel;
    189                                 break;
    190                         case SDL_MOUSEBUTTONUP:
    191                                 strcpy( cmd.cmd, aliases->buttons[event.button.button]);
    192                                 cmd.bUp = true;
    193                                 if( strlen (cmd.cmd) > 0) relay (&cmd);
    194                                 break;
    195                         case SDL_MOUSEBUTTONDOWN:
    196                                 strcpy( cmd.cmd, aliases->buttons[event.button.button]);
    197                                 cmd.bUp = false;
    198                                 if( strlen (cmd.cmd) > 0) relay (&cmd);
    199                                 break;
    200                         case SDL_JOYAXISMOTION:
    201                         case SDL_JOYBALLMOTION:
    202                         case SDL_JOYHATMOTION:
    203                         case SDL_JOYBUTTONDOWN:
    204                         case SDL_JOYBUTTONUP:
    205                                 break;
    206                         default:
    207                                 Orxonox *orx = Orxonox::getInstance();
    208                                 orx->event_handler (&event);
    209                                 break;
    210                 }
    211         }
     213    }
    212214}
    213215
     
    219221void CommandNode::relay (Command* cmd)
    220222{
    221 printf("CommandNode|relay()\n");
    222         List<WorldEntity>* plist = bound;
    223        
    224         Orxonox *orx = Orxonox::getInstance();
    225         if( orx->system_command (cmd)) return;
    226                
    227         if( bLocalInput) send_over_network (cmd);
    228        
    229         while( (plist = plist->get_next()) != NULL)
    230         {
    231                 plist->get_object()->command (cmd);
    232         }
    233 }
    234 
    235 /**
    236         \brief sets the network identifier of the CommandNode
    237         \param ID: the new ID to use
     223  //printf("CommandNode|relay()\n");
     224  List<WorldEntity>* plist = bound;
     225 
     226  Orxonox *orx = Orxonox::getInstance();
     227  if( orx->system_command (cmd)) return;
     228  GameLoader* gl = GameLoader::getInstance();
     229  if(gl->worldCommand(cmd)) return;
     230 
     231  if( bLocalInput) send_over_network (cmd);
     232 
     233  while( (plist = plist->get_next()) != NULL)
     234    {
     235      plist->get_object()->command (cmd);
     236    }
     237}
     238
     239/**
     240   \brief sets the network identifier of the CommandNode
     241   \param ID: the new ID to use
    238242*/
    239243void CommandNode::set_netID (int ID)
    240244{
    241         netID = ID;
     245  netID = ID;
    242246}
    243247
  • orxonox/trunk/src/error.h

    r2551 r2636  
    2222*/
    2323
    24 
     24// this are the two undefined error nr. Don't use them ...
    2525#define ERROR -1
    2626#define NO_ERROR 0
     27
     28/*!
     29    \brief Error Definitions:
     30
     31    Error Classes:
     32    0xx application framework codes
     33    1xx graphics codes
     34    2xx file/FS codes
     35    3xx network codes
     36    4xx general codes
     37
     38    Error Specifier 1:
     39    x0x action finsished as desired
     40    x1x initialisation error
     41    x2x execution error
     42    x3x uninitialisation error
     43
     44    Error Specifier 2:
     45    xx0 no further informations
     46    xx1 only a warning - feel free to ignore, the program will proceed
     47    xx2 this could lead unexpected behaviour
     48    xx3 this is a fatal error - you are invited to quit the program - panic!
     49*/
     50
     51typedef struct
     52{
     53  int code;
     54  char* message;
     55  char* location;
     56} Error;
  • orxonox/trunk/src/list.h

    r2077 r2636  
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
     3
     4   Copyright (C) 2004 orx
     5
     6   This program is free software; you can redistribute it and/or modify
     7   it under the terms of the GNU General Public License as published by
     8   the Free Software Foundation; either version 2, or (at your option)
     9   any later version.
     10
     11   ### File Specific:
     12   main-programmer: Christian Meyer
     13
     14   ADDONS/FIXES:
     15 
     16   Patrick Boenzli     :          Implemented getSize() function
     17*/
     18
     19
    120/*!
    221  \file list.h
     
    2140  List<T>* prev;
    2241  bool bReference;
     42  int size;
    2343 
    2444 public:
     
    3555  void set_prev (List<T>* ptr);
    3656  int remove (T* obj, FINDMODE mode);
     57  int getSize();
    3758};
    3859
     
    5273  prev = p;
    5374  bReference = bRef;
     75  if(obj != NULL)
     76    ++size;
    5477}
    5578
     
    127150      break;
    128151  }
     152  ++size;
    129153  return 0;
    130154}
     
    224248    }
    225249  }
     250  --size;
    226251  return 0;
    227252}
     
    262287
    263288
     289/**
     290  \brief Returns the current size of the List
     291  \return Size of List
     292*/
     293template<class T>
     294int List<T>::getSize()
     295{
     296  return this->size;
     297}
    264298
    265299#endif
  • orxonox/trunk/src/orxonox.cc

    r2551 r2636  
    2929#include "data_tank.h"
    3030#include "command_node.h"
     31#include "game_loader.h"
    3132#include <string.h>
    3233
     
    3435
    3536/**
    36         \brief create a new Orxonox
     37   \brief create a new Orxonox
    3738*/
    3839Orxonox::Orxonox ()
     
    4243
    4344/**
    44         \brief remove Orxonox from memory
     45   \brief remove Orxonox from memory
    4546*/
    4647Orxonox::~Orxonox ()
    4748{
    48         Orxonox::singleton_ref = NULL;
    49         if( world != NULL) delete world;
    50         if( localinput != NULL) delete world;
    51         if( localcamera != NULL) delete localcamera;
    52         if( resources != NULL) delete resources;
     49  Orxonox::singleton_ref = NULL;
     50  if( world != NULL) delete world;
     51  if( localinput != NULL) delete world;
     52  if( localcamera != NULL) delete localcamera;
     53  if( resources != NULL) delete resources;
    5354}
    5455
     
    6566
    6667/**
    67         \brief this finds the config file
    68        
    69         Since the config file varies from user to user and since one may want to specify different config files
    70         for certain occasions or platforms this function finds the right config file for every occasion and stores
    71         it's path and name into configfilename
     68   \brief this finds the config file
     69   
     70   Since the config file varies from user to user and since one may want to specify different config files
     71   for certain occasions or platforms this function finds the right config file for every occasion and stores
     72   it's path and name into configfilename
    7273*/
    7374void Orxonox::get_config_file (int argc, char** argv)
    7475{
    75 /*      char* path;
    76         #ifdef __WIN32__
    77         path = getenv("");
    78         #else
    79         path = getenv("HOME");
    80         #endif
    81        
    82         if( path != NULL) strcpy (configfilename, path);
    83         else strcpy (configfilename, "./");
    84         strcat (configfilename, "/.orxonox.conf");*/
    85        
    86         strcpy (configfilename, "orxonox.conf");
    87 }
    88 
    89 /**
    90         \brief initialize Orxonox with command line
     76  /*    char* path;
     77    #ifdef __WIN32__
     78    path = getenv("");
     79    #else
     80    path = getenv("HOME");
     81    #endif
     82   
     83    if( path != NULL) strcpy (configfilename, path);
     84    else strcpy (configfilename, "./");
     85    strcat (configfilename, "/.orxonox.conf");*/
     86 
     87  strcpy (configfilename, "orxonox.conf");
     88}
     89
     90/**
     91   \brief initialize Orxonox with command line
    9192*/
    9293int Orxonox::init (int argc, char** argv)
    9394{
    94                 // parse command line
    95                 // config file
    96                
    97         get_config_file (argc, argv);
    98        
    99                 // initialize SDL
     95  // parse command line
     96  // config file
     97 
     98  get_config_file (argc, argv);
     99 
     100  // initialize SDL
    100101  printf("> Initializing SDL\n");
    101102  if( SDL_Init (SDL_INIT_EVERYTHING) == -1)
    102   {
    103     printf ("Could not SDL_Init(): %s\n", SDL_GetError());
    104     return -1;
    105   }
    106  
    107         // initialize everything
     103    {
     104      printf ("Could not SDL_Init(): %s\n", SDL_GetError());
     105      return -1;
     106    }
     107 
     108  // initialize everything
    108109  printf("> Initializing video\n");
    109         if( init_video () == -1) return -1;
     110  if( init_video () == -1) return -1;
    110111  printf("> Initializing sound\n");
    111         if( init_sound () == -1) return -1;
     112  if( init_sound () == -1) return -1;
    112113  printf("> Initializing input\n");
    113         if( init_input () == -1) return -1;
     114  if( init_input () == -1) return -1;
    114115  printf("> Initializing networking\n");
    115         if( init_networking () == -1) return -1;
     116  if( init_networking () == -1) return -1;
    116117  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 
    124 /**
    125         \brief initializes SDL and OpenGL
     118  if( init_resources () == -1) return -1;
     119  //printf("> Initializing world\n");
     120  //if( init_world () == -1) return -1; PB: world will be initialized when started
     121 
     122  return 0;
     123}
     124
     125/**
     126   \brief initializes SDL and OpenGL
    126127*/
    127128int Orxonox::init_video ()
     
    161162 
    162163  // create camera
    163   localcamera = new Camera();
    164  
    165   return 0;
    166 }
    167 
    168 /**
    169         \brief initializes the sound engine
     164  localcamera = new Camera(world);
     165 
     166  return 0;
     167}
     168
     169/**
     170   \brief initializes the sound engine
    170171*/
    171172int Orxonox::init_sound ()
    172173{
    173         printf("Not yet implemented\n");
    174         return 0;
    175 }
    176 
    177 /**
    178         \brief initializes input functions
     174  printf("Not yet implemented\n");
     175  return 0;
     176}
     177
     178/**
     179   \brief initializes input functions
    179180*/
    180181int Orxonox::init_input ()
    181182{
    182         // create localinput
    183         localinput = new CommandNode( configfilename);
    184        
    185         return 0;
    186 }
    187 
    188 /**
    189         \brief initializes network system
     183  // create localinput
     184  localinput = new CommandNode( configfilename);
     185 
     186  return 0;
     187}
     188
     189/**
     190   \brief initializes network system
    190191*/
    191192int Orxonox::init_networking ()
    192193{
    193         printf("Not yet implemented\n");
    194         return 0;
    195 }
    196 
    197 /**
    198         \brief initializes and loads resource files
     194  printf("Not yet implemented\n");
     195  return 0;
     196}
     197
     198/**
     199   \brief initializes and loads resource files
    199200*/
    200201int Orxonox::init_resources ()
    201202{
    202         printf("Not yet implemented\n");
    203         return 0;
    204 }
    205 
    206 /**
    207         \brief initializes the world
     203  printf("Not yet implemented\n");
     204  return 0;
     205}
     206
     207/**
     208   \brief initializes the world
    208209*/
    209210int Orxonox::init_world ()
    210211{
    211         world = new World();
    212        
    213         // TO DO: replace this with a menu/intro
    214         world->load_debug_level();
    215        
    216         return 0;
    217 }
    218 
    219 /**
    220         \brief exits Orxonox
     212  //world = new World();
     213 
     214  // TO DO: replace this with a menu/intro
     215  //world->load_debug_level();
     216 
     217  return 0;
     218}
     219
     220
     221/**
     222   \brief starts the orxonox game or menu
     223
     224   here is the central orxonox state manager. There are currently two states
     225   - menu
     226   - game-play
     227   both states manage their states themselfs again.
     228*/
     229void Orxonox::start()
     230{
     231 
     232  this->gameLoader = GameLoader::getInstance();
     233  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
     234  this->gameLoader->init();
     235  this->gameLoader->start();
     236}
     237
     238/**
     239   \brief exits Orxonox
    221240*/
    222241void Orxonox::quitGame()
    223242{
    224         bQuitOrxonox = true;
    225 }
    226 
    227 /**
    228         \brief this runs all of Orxonox
     243  bQuitOrxonox = true;
     244}
     245
     246/**
     247   \brief this runs all of Orxonox
    229248*/
    230249void Orxonox::mainLoop()
     
    236255  while( !bQuitOrxonox)
    237256    {
    238       printf("<==");
    239 
    240257      // Network
    241258      synchronize();
     
    248265      // Draw
    249266      display();
    250 
    251       printf(">\n");
    252267    }
    253268  printf("Orxonox|Exiting the main loop\n");
     
    255270
    256271/**
    257         \brief handles sprecial events from localinput
    258         \param event: an event not handled by the CommandNode
     272   \brief handles sprecial events from localinput
     273   \param event: an event not handled by the CommandNode
    259274*/
    260275void Orxonox::event_handler (SDL_Event* event)
    261276{
    262         // Handle special events such as reshape, quit, focus changes
    263 }
    264 
    265 /**
    266         \brief synchronize local data with remote data
     277  // Handle special events such as reshape, quit, focus changes
     278}
     279
     280/**
     281   \brief synchronize local data with remote data
    267282*/
    268283void Orxonox::synchronize ()
    269284{
    270         // Get remote input
    271         // Update synchronizables
    272 }
    273 
    274 /**
    275         \brief run all input processing
     285  // Get remote input
     286  // Update synchronizables
     287}
     288
     289/**
     290   \brief run all input processing
    276291*/
    277292void Orxonox::handle_input ()
    278293{
    279         // localinput
    280                 localinput->process();
    281         // remoteinput
    282 }
    283 
    284 /**
    285         \brief advance the timeline
     294  // localinput
     295  localinput->process();
     296  // remoteinput
     297}
     298
     299/**
     300   \brief advance the timeline
    286301*/
    287302void Orxonox::time_slice ()
     
    295310        {
    296311          float fps = 1000/dt;
    297           printf("%f", fps);
     312          printf("fps = %f\n", fps);
    298313        }
    299314     
     
    306321
    307322/**
    308         \brief compute collision detection
     323   \brief compute collision detection
    309324*/
    310325void Orxonox::collision ()
    311326{
    312         world->collide ();
    313 }
    314 
    315 /**
    316         \brief handle keyboard commands that are not meant for WorldEntities
    317         \param cmd: the command to handle
    318         \return true if the command was handled by the system or false if it may be passed to the WorldEntities
     327  world->collide ();
     328}
     329
     330/**
     331   \brief handle keyboard commands that are not meant for WorldEntities
     332   \param cmd: the command to handle
     333   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
    319334*/
    320335bool Orxonox::system_command (Command* cmd)
    321336{
    322         if( !strcmp( cmd->cmd, "quit"))
    323         {
    324                 if( !cmd->bUp) bQuitOrxonox = true;
    325                 return true;
    326         }
    327         return false;
    328 }
    329 
    330 /**
    331         \brief render the current frame
     337  if( !strcmp( cmd->cmd, "quit"))
     338    {
     339      if( !cmd->bUp) this->gameLoader->stop();
     340      return true;
     341    }
     342  return false;
     343}
     344
     345/**
     346   \brief render the current frame
    332347*/
    333348void Orxonox::display ()
    334349{
    335                 // clear buffer
    336         glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    337                 // set camera
    338         localcamera->apply ();
    339                 // draw world
    340         world->draw ();
    341                 // draw HUD
    342                 // flip buffers
    343         SDL_GL_SwapBuffers();
    344 }
    345 
    346 /**
    347         \brief retrieve a pointer to the local Camera
    348         \return a pointer to localcamera
     350  // clear buffer
     351  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     352  // set camera
     353  localcamera->apply ();
     354  // draw world
     355  world->draw ();
     356  // draw HUD
     357  // flip buffers
     358  SDL_GL_SwapBuffers();
     359}
     360
     361/**
     362   \brief retrieve a pointer to the local Camera
     363   \return a pointer to localcamera
    349364*/
    350365Camera* Orxonox::get_camera ()
    351366{
    352         return localcamera;
    353 }
    354 
    355 /**
    356         \brief retrieve a pointer to the local CommandNode
    357         \return a pointer to localinput
     367  return localcamera;
     368}
     369
     370/**
     371   \brief retrieve a pointer to the local CommandNode
     372   \return a pointer to localinput
    358373*/
    359374CommandNode* Orxonox::get_localinput ()
    360375{
    361         return localinput;
    362 }
    363 
    364 /**
    365         \brief retrieve a pointer to the local World
    366         \return a pointer to world
     376  return localinput;
     377}
     378
     379/**
     380   \brief retrieve a pointer to the local World
     381   \return a pointer to world
    367382*/
    368383World* Orxonox::get_world ()
    369384{
    370         return world;
     385  return world;
    371386}
    372387
    373388int main (int argc, char** argv)
    374389
    375         printf(">>> Starting Orxonox <<<\n");
     390  printf(">>> Starting Orxonox <<<\n");
    376391  Orxonox *orx = Orxonox::getInstance();
    377392 
    378393  if( (*orx).init(argc, argv) == -1)
    379   {
    380     printf("! Orxonox initialization failed\n");
    381     return -1;
    382   }
    383        
    384   (*orx).mainLoop();
    385 
     394    {
     395      printf("! Orxonox initialization failed\n");
     396      return -1;
     397    }
     398 
     399  //(*orx).mainLoop();
     400
     401  orx->start();
     402 
    386403  //delete orx;
    387404 
  • orxonox/trunk/src/orxonox.conf

    r2190 r2636  
    66SPACE=fire
    77ESCAPE=quit
     8p=pause
    89q=quit
    910BUTTON_LEFT=fire
    1011BUTTON_RIGHT=altfire
    1112b=benscho
     13x=up_world
     14z=down_world
     15
  • orxonox/trunk/src/orxonox.h

    r2190 r2636  
    1616class World;
    1717class Camera;
     18class GameLoader;
    1819
    1920//! Orxonox core singleton class
     
    3334  Camera* localcamera;
    3435  SDL_Surface* screen;
     36  GameLoader* gameLoader;
    3537 
    3638  bool bQuitOrxonox;
    3739  bool pause;
    38         Uint32 lastframe;
    39 
    40         void get_config_file (int argc, char** argv);
    41        
    42                 // main loop functions
     40  Uint32 lastframe;
     41 
     42  void get_config_file (int argc, char** argv);
     43 
     44  // main loop functions
    4345  void synchronize ();
    4446  void handle_input ();
     
    5759 public:
    5860  static Orxonox* getInstance ();
     61  void start();
    5962  void quitGame();
    6063
     
    6366
    6467  int init (int argc, char** argv);
    65        
    66         CommandNode* get_localinput();
    67         Camera* get_camera();
    68         World* get_world();
    69        
     68 
     69  CommandNode* get_localinput();
     70  Camera* get_camera();
     71  World* get_world();
     72 
    7073  void mainLoop();
    7174};
  • orxonox/trunk/src/player.cc

    r2551 r2636  
    6262void Player::command (Command* cmd)
    6363{
    64         printf("Player|recieved command [%s]\n", cmd->cmd);
    65         if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
    66         else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
    67         else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
    68         else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
    69         else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
     64  //printf("Player|recieved command [%s]\n", cmd->cmd);
     65  if( !strcmp( cmd->cmd, "up")) bUp = !cmd->bUp;
     66  else if( !strcmp( cmd->cmd, "down")) bDown = !cmd->bUp;
     67  else if( !strcmp( cmd->cmd, "left")) bLeft = !cmd->bUp;
     68  else if( !strcmp( cmd->cmd, "right")) bRight = !cmd->bUp;
     69  else if( !strcmp( cmd->cmd, "fire")) bFire = !cmd->bUp;
    7070}
    7171
  • orxonox/trunk/src/stdincl.h

    r2551 r2636  
    1515#include "coordinates.h"
    1616#include "list.h"
     17#include "error.h"
    1718#include "message_structures.h"
    1819#include "orxonox.h"
  • orxonox/trunk/src/track.cc

    r2551 r2636  
    5252{
    5353}
     54
     55void Track::init()
     56{
     57 
     58}
     59
    5460
    5561/**
  • orxonox/trunk/src/track.h

    r2551 r2636  
    2727       
    2828 public:
    29         Track ();
     29  Track ();
    3030  Track (Uint32 number, Uint32 next, Vector* start, Vector* finish);
    3131  ~Track ();
    32        
    33         virtual void post_enter (WorldEntity* entity);  // handle coordinate transition in here !!! (when dist < 0 or dist > lasttracklenght)
    34         virtual void post_leave (WorldEntity* entity);
    35         virtual void tick (float deltaT);
    36         virtual void map_camera (Location* lookat, Placement* camplc);
    37         virtual bool map_coords (Location* loc, Placement* plc);        // this should return true if the entity left track boundaries
     32  virtual void init();
     33 
     34  virtual void post_enter (WorldEntity* entity);        // handle coordinate transition in here !!! (when dist < 0 or dist > lasttracklenght)
     35  virtual void post_leave (WorldEntity* entity);
     36  virtual void tick (float deltaT);
     37  virtual void map_camera (Location* lookat, Placement* camplc);
     38  virtual bool map_coords (Location* loc, Placement* plc);      // this should return true if the entity left track boundaries
    3839};
    3940
  • orxonox/trunk/src/world.cc

    r2551 r2636  
    3131    This creates a new empty world!
    3232*/
    33 World::World ()
    34 {
    35   entities = new List<WorldEntity>();
     33World::World (char* name)
     34{
     35  this->worldName = name;
     36  this->debugWorldNr = -1;
     37  this->entities = new List<WorldEntity>();
     38}
     39
     40World::World (int worldID)
     41{
     42  this->debugWorldNr = worldID;
     43  this->worldName = NULL;
     44  this->entities = new List<WorldEntity>();
    3645}
    3746
     
    4453  delete entities;
    4554}
     55
     56
     57/**
     58    \brief initialize the world before use.
     59*/
     60Error World::init()
     61{
     62  this->bPause = false;
     63}
     64
     65Error World::start()
     66{
     67  this->mainLoop();
     68}
     69
     70Error World::stop()
     71{
     72  this->bQuitCurrentGame = true;
     73  this->localCamera->setWorld(NULL);
     74}
     75
     76Error World::pause()
     77{
     78  this->isPaused = true;
     79}
     80
     81Error World::resume()
     82{
     83  this->isPaused = false;
     84}
     85
     86void World::load()
     87{
     88  if(this->debugWorldNr != -1)
     89    {
     90      switch(this->debugWorldNr)
     91        {
     92        case DEBUG_WORLD_0:
     93          {
     94            // create some path nodes
     95            this->pathnodes = new Vector[6];
     96            this->pathnodes[0] = Vector(0, 0, 0);
     97            this->pathnodes[1] = Vector(-100, 40, 0);
     98            this->pathnodes[2] = Vector(-100, 140, 0);
     99            this->pathnodes[3] = Vector(0, 180, 0);
     100            this->pathnodes[4] = Vector(100, 140, 0);
     101            this->pathnodes[5] = Vector(100, 40, 0);
     102           
     103            // create the tracks
     104            this->tracklen = 6;
     105            this->track = new Track[6];
     106            for( int i = 0; i < this->tracklen; i++)
     107              {
     108                this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]);
     109              }
     110           
     111            // create a player
     112            WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();
     113           
     114            // bind input
     115            Orxonox *orx = Orxonox::getInstance();
     116            orx->get_localinput()->bind (myPlayer);
     117           
     118            // bind camera
     119            this->localCamera = new Camera(this);
     120            this->getCamera()->bind (myPlayer);
     121            break;
     122          }
     123        case DEBUG_WORLD_1:
     124          {
     125            // create some path nodes
     126            this->pathnodes = new Vector[6];
     127            this->pathnodes[0] = Vector(0, 0, 0);
     128            this->pathnodes[1] = Vector(20, 10, 10);
     129            this->pathnodes[2] = Vector(40, 0, 10);
     130            this->pathnodes[3] = Vector(60, 10, 0);
     131            this->pathnodes[4] = Vector(80, 20, 10);
     132            this->pathnodes[5] = Vector(30, 50, 0);
     133           
     134            // create the tracks
     135            this->tracklen = 6;
     136            this->track = new Track[6];
     137            for( int i = 0; i < this->tracklen; i++)
     138              {
     139                this->track[i] = Track( i, (i+1)%this->tracklen, &this->pathnodes[i], &this->pathnodes[(i+1)%this->tracklen]);
     140              }
     141           
     142            // create a player
     143            WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();
     144           
     145            // bind input
     146            Orxonox *orx = Orxonox::getInstance();
     147            orx->get_localinput()->bind (myPlayer);
     148           
     149            // bind camera
     150            this->localCamera = new Camera(this);
     151            this->getCamera()->bind (myPlayer);
     152            break;
     153          }
     154        default:
     155          printf("World::load() - no world with ID %i found", this->debugWorldNr );
     156        }
     157    }
     158  else if(this->worldName != NULL)
     159    {
     160
     161    }
     162}
     163
    46164
    47165/**
     
    254372}
    255373
    256 /**
    257    \brief loads a simple level for testing purposes
    258 */
    259 void World::load_debug_level()
    260 {
    261   // create some path nodes
    262   pathnodes = new Vector[6];
    263   pathnodes[0] = Vector(0, 0, 0);
    264   pathnodes[1] = Vector(-100, 40, 0);
    265   pathnodes[2] = Vector(-100, 140, 0);
    266   pathnodes[3] = Vector(0, 180, 0);
    267   pathnodes[4] = Vector(100, 140, 0);
    268   pathnodes[5] = Vector(100, 40, 0);   
    269  
    270   // create the tracks
    271   tracklen = 6;
    272   track = new Track[6];
    273   for( int i = 0; i < tracklen; i++)
    274     {
    275       track[i] = Track( i, (i+1)%tracklen, &pathnodes[i], &pathnodes[(i+1)%tracklen]);
    276     }
    277  
    278   // create a player
    279   WorldEntity* myPlayer = (WorldEntity*) spawn<Player>();
    280  
    281   // bind input
    282   Orxonox *orx = Orxonox::getInstance();
    283   orx->get_localinput()->bind (myPlayer);
    284  
    285   // bind camera
    286   orx->get_camera()->bind (myPlayer);
    287 }
     374
    288375
    289376/**
     
    295382  track[loc->part].map_camera (loc, plc);
    296383}
     384
     385
     386void World::setTrackLen(Uint32 len)
     387{
     388  this->tracklen = len;
     389}
     390
     391int World::getTrackLen()
     392{
     393  return this->tracklen;
     394}
     395
     396
     397void World::mainLoop()
     398{
     399  this->lastFrame = SDL_GetTicks();
     400  this->bQuitOrxonox = false;
     401  this->bQuitCurrentGame = false;
     402  printf("World|Entering main loop\n");
     403  while(!this->bQuitOrxonox && !this->bQuitCurrentGame) /* pause pause pause ?!?!?*/
     404    {
     405      // Network
     406      synchronize();
     407      // Process input
     408      handle_input();
     409      // Process time
     410      time_slice();
     411      // Process collision
     412      collision();
     413      // Draw
     414      display();
     415    }
     416  printf("World|Exiting the main loop\n");
     417}
     418
     419/**
     420   \brief synchronize local data with remote data
     421*/
     422void World::synchronize ()
     423{
     424  // Get remote input
     425  // Update synchronizables
     426}
     427
     428/**
     429   \brief run all input processing
     430*/
     431void World::handle_input ()
     432{
     433  // localinput
     434  Orxonox::getInstance()->get_localinput()->process();
     435  // remoteinput
     436}
     437
     438/**
     439   \brief advance the timeline
     440*/
     441void World::time_slice ()
     442{
     443  Uint32 currentFrame = SDL_GetTicks();
     444  if(!this->bPause)
     445    {
     446      Uint32 dt = currentFrame - this->lastFrame;
     447      /*
     448      if(dt > 0)
     449        {
     450          float fps = 1000/dt;
     451          printf("fps = %f\n", fps);
     452        }
     453      else
     454        {
     455          printf("fps = 1000\n");
     456        }
     457      */
     458      this->time_slice (dt);
     459      this->update ();
     460      this->localCamera->time_slice (dt);
     461    }
     462  this->lastFrame = currentFrame;
     463}
     464
     465/**
     466   \brief compute collision detection
     467*/
     468void World::collision ()
     469{
     470  this->collide ();
     471}
     472
     473/**
     474   \brief handle keyboard commands that are not meant for WorldEntities
     475   \param cmd: the command to handle
     476   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
     477*/
     478bool World::system_command (Command* cmd)
     479{
     480  if( !strcmp( cmd->cmd, "quit"))
     481    {
     482      if( !cmd->bUp) this->bQuitOrxonox = true;
     483      return true;
     484    }
     485  return false;
     486}
     487
     488/**
     489        \brief render the current frame
     490*/
     491void World::display ()
     492{
     493  // clear buffer
     494  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     495  // set camera
     496  this->localCamera->apply ();
     497  // draw world
     498  this->draw();
     499  // draw HUD
     500  // flip buffers
     501  SDL_GL_SwapBuffers();
     502}
     503
     504Camera* World::getCamera()
     505{
     506  return this->localCamera;
     507}
  • orxonox/trunk/src/world.h

    r2551 r2636  
    88
    99#include "stdincl.h"
     10#include "story_entity.h"
     11
     12
    1013
    1114class Track;
    1215class WorldEntity;
     16class Camera;
    1317
    1418//! The game environment
    15 class World {
     19class World : public StoryEntity {
    1620
    1721 public:
    18   World ();
     22  World (char* name);
     23  World (int worldID);
    1924  ~World ();
    2025
    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);
     26  template<typename T>
     27    T* spawn(Location* loc, WorldEntity* owner);        // template to be able to spawn any derivation of WorldEntity
     28  template<typename T>
     29    T* spawn(Placement* plc, WorldEntity* owner);
     30 
     31  virtual Error init();
     32  virtual Error start();
     33  virtual Error stop();
     34  virtual Error pause();
     35  virtual Error resume();
    2536
    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);
     37  virtual void load();
     38
     39  void time_slice (Uint32 deltaT);
     40  void collide ();
     41  void draw ();
     42  void update ();       // maps Locations to Placements
     43  void calc_camera_pos (Location* loc, Placement* plc);
    3144       
    32         void unload ();
    33        
    34         void load_debug_level ();
    35        
     45  void unload ();
     46 
     47  void setTrackLen(Uint32 tracklen);
     48  int getTrackLen();
     49  bool system_command (Command* cmd);
     50  Camera* getCamera();
     51  //private:
     52 
     53  List<WorldEntity>* entities;
     54 
     55  // base level data
     56  Track* track;
     57  Uint32 tracklen;   // number of Tracks the World consist of
     58  Vector* pathnodes;
     59  Camera* localCamera; 
     60
    3661 private:
    37  
    38         List<WorldEntity>* entities;
    39        
    40                 // base level data
    41         Track* track;
    42         Uint32 tracklen;   // number of Tracks the World consist of
    43         Vector* pathnodes;
     62  Uint32 lastFrame; //!> last time of frame
     63  bool bQuitOrxonox; //!> quit this application
     64  bool bQuitCurrentGame; //!> quit only the current game and return to menu
     65  bool bPause;
    4466
     67  char* worldName;
     68  int debugWorldNr;
     69
     70  void mainLoop();
     71  void synchronize();
     72  void handle_input();
     73  void time_slice();
     74  void collision();
     75  void display();
    4576};
    4677
     
    6394        if( loc == NULL)
    6495        {
    65                 zeroloc.dist = 0;
    66                 zeroloc.part = 0;
     96          zeroloc.dist = 0;
     97          zeroloc.part = 0;
    6798                zeroloc.pos = Vector();
    6899                zeroloc.rot = Quaternion();
Note: See TracChangeset for help on using the changeset viewer.