Changeset 2636 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Oct 25, 2004, 12:48:39 AM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 7 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/Makefile.am
r2589 r2636 6 6 7 7 bin_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 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 game_loader.cc campaign.cc story_entity.cc 9 9 10 10 noinst_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 117 117 #"-O3 -pedantic -fPIC -ffast-math -I/usr/X11R6/include" 118 118 bin_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 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 game_loader.cc campaign.cc story_entity.cc 120 120 121 121 noinst_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 … … 132 132 camera.$(OBJEXT) collision.$(OBJEXT) command_node.$(OBJEXT) \ 133 133 ini_parser.$(OBJEXT) keynames.$(OBJEXT) track.$(OBJEXT) \ 134 base_entity.$(OBJEXT) 134 base_entity.$(OBJEXT) game_loader.$(OBJEXT) campaign.$(OBJEXT) \ 135 story_entity.$(OBJEXT) 135 136 orxonox_OBJECTS = $(am_orxonox_OBJECTS) 136 137 orxonox_LDADD = $(LDADD) … … 142 143 am__depfiles_maybe = depfiles 143 144 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/base_entity.Po ./$(DEPDIR)/camera.Po \ 144 @AMDEP_TRUE@ ./$(DEPDIR)/c ollision.Po \145 @AMDEP_TRUE@ ./$(DEPDIR)/campaign.Po ./$(DEPDIR)/collision.Po \ 145 146 @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 \ 149 151 @AMDEP_TRUE@ ./$(DEPDIR)/vector.Po ./$(DEPDIR)/world.Po \ 150 152 @AMDEP_TRUE@ ./$(DEPDIR)/world_entity.Po … … 157 159 HEADERS = $(noinst_HEADERS) 158 160 159 DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.in INSTALL \161 DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.in ChangeLog INSTALL \ 160 162 Makefile.am 161 163 SOURCES = $(orxonox_SOURCES) … … 206 208 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/base_entity.Po@am__quote@ 207 209 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/camera.Po@am__quote@ 210 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/campaign.Po@am__quote@ 208 211 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/collision.Po@am__quote@ 209 212 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/command_node.Po@am__quote@ 210 213 @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@ 211 215 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ini_parser.Po@am__quote@ 212 216 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keynames.Po@am__quote@ 213 217 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox.Po@am__quote@ 214 218 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/player.Po@am__quote@ 219 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/story_entity.Po@am__quote@ 215 220 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/track.Po@am__quote@ 216 221 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@ -
orxonox/trunk/src/camera.cc
r2551 r2636 27 27 This standard constructor sets all parameters to zero 28 28 */ 29 Camera::Camera () 30 { 29 Camera::Camera (World* world) 30 { 31 this->world = world; 31 32 bound = NULL; 32 33 /* give it some physical live */ … … 36 37 fs = new Vector(0.0, 0.0, 0.0); 37 38 cameraMode = NORMAL; 38 39 39 deltaTime = 3000.0; 40 40 cameraOffset = 1.0; … … 179 179 /* the camera is handled like an entity and rolls on the track */ 180 180 case NORMAL: 181 Orxonox *orx = Orxonox::getInstance();182 181 Location lookat; 183 if( bound != NULL )182 if( bound != NULL && world != NULL ) 184 183 { 185 184 bound->get_lookat (&lookat); 186 orx->get_world()->calc_camera_pos (&lookat, &desired_place);185 world->calc_camera_pos (&lookat, &desired_place); 187 186 } 188 187 else … … 293 292 } 294 293 } 294 295 296 void Camera::setWorld(World* world) 297 { 298 this->world = world; 299 } -
orxonox/trunk/src/camera.h
r2551 r2636 10 10 11 11 class WorldEntity; 12 class World; 12 13 13 14 //! Camera 14 15 /** 15 16 17 18 19 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. 20 21 */ 21 22 … … 27 28 Placement actual_place; //!< the Camera's current position 28 29 Placement desired_place; //!< where the Camera should be according to calculations 30 World* world; 29 31 30 32 /* physical system - not needed yet */ … … 49 51 Quaternion *res; 50 52 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); 51 66 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); 64 68 65 69 }; -
orxonox/trunk/src/command_node.cc
r2551 r2636 19 19 #include "ini_parser.h" 20 20 #include "world_entity.h" 21 #include "game_loader.h" 21 22 22 23 #include <stdio.h> … … 27 28 28 29 /** 29 30 30 \brief constructs a CommandNode to handle remote input 31 \param ID: unique denumerator to identify the node in the network 31 32 */ 32 33 CommandNode::CommandNode (int ID) 33 34 { 34 35 36 37 38 } 39 40 /** 41 42 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 43 44 */ 44 45 CommandNode::CommandNode (char* filename = DEFAULT_KEYBIND_FILE) 45 46 { 46 47 48 49 50 51 } 52 53 /** 54 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 55 56 */ 56 57 CommandNode::~CommandNode () 57 58 { 58 59 60 } 61 62 /** 63 64 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 65 66 */ 66 67 void CommandNode::load_bindings (char* filename) 67 68 { 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]) 76 102 { 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; 79 113 } 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 */ 123 void 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 */ 132 void CommandNode::unbind (WorldEntity* entity) 133 { 134 bound->remove (entity, LIST_FIND_FW); 135 } 136 137 int* 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 */ 158 void CommandNode::process () 159 { 160 if( bLocalInput) process_local (); 161 else process_network (); 162 } 163 164 void 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) 84 173 { 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; 87 212 } 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 } 212 214 } 213 215 … … 219 221 void CommandNode::relay (Command* cmd) 220 222 { 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 238 242 */ 239 243 void CommandNode::set_netID (int ID) 240 244 { 241 245 netID = ID; 242 246 } 243 247 -
orxonox/trunk/src/error.h
r2551 r2636 22 22 */ 23 23 24 24 // this are the two undefined error nr. Don't use them ... 25 25 #define ERROR -1 26 26 #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 51 typedef 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 1 20 /*! 2 21 \file list.h … … 21 40 List<T>* prev; 22 41 bool bReference; 42 int size; 23 43 24 44 public: … … 35 55 void set_prev (List<T>* ptr); 36 56 int remove (T* obj, FINDMODE mode); 57 int getSize(); 37 58 }; 38 59 … … 52 73 prev = p; 53 74 bReference = bRef; 75 if(obj != NULL) 76 ++size; 54 77 } 55 78 … … 127 150 break; 128 151 } 152 ++size; 129 153 return 0; 130 154 } … … 224 248 } 225 249 } 250 --size; 226 251 return 0; 227 252 } … … 262 287 263 288 289 /** 290 \brief Returns the current size of the List 291 \return Size of List 292 */ 293 template<class T> 294 int List<T>::getSize() 295 { 296 return this->size; 297 } 264 298 265 299 #endif -
orxonox/trunk/src/orxonox.cc
r2551 r2636 29 29 #include "data_tank.h" 30 30 #include "command_node.h" 31 #include "game_loader.h" 31 32 #include <string.h> 32 33 … … 34 35 35 36 /** 36 37 \brief create a new Orxonox 37 38 */ 38 39 Orxonox::Orxonox () … … 42 43 43 44 /** 44 45 \brief remove Orxonox from memory 45 46 */ 46 47 Orxonox::~Orxonox () 47 48 { 48 49 50 51 52 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; 53 54 } 54 55 … … 65 66 66 67 /** 67 68 69 70 71 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 72 73 */ 73 74 void Orxonox::get_config_file (int argc, char** argv) 74 75 { 75 /* char* path;76 77 78 79 80 81 82 83 84 85 86 87 } 88 89 /** 90 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 91 92 */ 92 93 int Orxonox::init (int argc, char** argv) 93 94 { 94 95 96 97 98 99 95 // parse command line 96 // config file 97 98 get_config_file (argc, argv); 99 100 // initialize SDL 100 101 printf("> Initializing SDL\n"); 101 102 if( SDL_Init (SDL_INIT_EVERYTHING) == -1) 102 {103 printf ("Could not SDL_Init(): %s\n", SDL_GetError());104 return -1;105 }106 107 103 { 104 printf ("Could not SDL_Init(): %s\n", SDL_GetError()); 105 return -1; 106 } 107 108 // initialize everything 108 109 printf("> Initializing video\n"); 109 110 if( init_video () == -1) return -1; 110 111 printf("> Initializing sound\n"); 111 112 if( init_sound () == -1) return -1; 112 113 printf("> Initializing input\n"); 113 114 if( init_input () == -1) return -1; 114 115 printf("> Initializing networking\n"); 115 116 if( init_networking () == -1) return -1; 116 117 printf("> Initializing resources\n"); 117 118 printf("> Initializing world\n");119 if( init_world () == -1) return -1; 120 121 122 } 123 124 /** 125 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 126 127 */ 127 128 int Orxonox::init_video () … … 161 162 162 163 // create camera 163 localcamera = new Camera( );164 165 return 0; 166 } 167 168 /** 169 164 localcamera = new Camera(world); 165 166 return 0; 167 } 168 169 /** 170 \brief initializes the sound engine 170 171 */ 171 172 int Orxonox::init_sound () 172 173 { 173 174 175 } 176 177 /** 178 174 printf("Not yet implemented\n"); 175 return 0; 176 } 177 178 /** 179 \brief initializes input functions 179 180 */ 180 181 int Orxonox::init_input () 181 182 { 182 183 184 185 186 } 187 188 /** 189 183 // create localinput 184 localinput = new CommandNode( configfilename); 185 186 return 0; 187 } 188 189 /** 190 \brief initializes network system 190 191 */ 191 192 int Orxonox::init_networking () 192 193 { 193 194 195 } 196 197 /** 198 194 printf("Not yet implemented\n"); 195 return 0; 196 } 197 198 /** 199 \brief initializes and loads resource files 199 200 */ 200 201 int Orxonox::init_resources () 201 202 { 202 203 204 } 205 206 /** 207 203 printf("Not yet implemented\n"); 204 return 0; 205 } 206 207 /** 208 \brief initializes the world 208 209 */ 209 210 int Orxonox::init_world () 210 211 { 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 */ 229 void 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 221 240 */ 222 241 void Orxonox::quitGame() 223 242 { 224 225 } 226 227 /** 228 243 bQuitOrxonox = true; 244 } 245 246 /** 247 \brief this runs all of Orxonox 229 248 */ 230 249 void Orxonox::mainLoop() … … 236 255 while( !bQuitOrxonox) 237 256 { 238 printf("<==");239 240 257 // Network 241 258 synchronize(); … … 248 265 // Draw 249 266 display(); 250 251 printf(">\n");252 267 } 253 268 printf("Orxonox|Exiting the main loop\n"); … … 255 270 256 271 /** 257 258 272 \brief handles sprecial events from localinput 273 \param event: an event not handled by the CommandNode 259 274 */ 260 275 void Orxonox::event_handler (SDL_Event* event) 261 276 { 262 263 } 264 265 /** 266 277 // Handle special events such as reshape, quit, focus changes 278 } 279 280 /** 281 \brief synchronize local data with remote data 267 282 */ 268 283 void Orxonox::synchronize () 269 284 { 270 271 272 } 273 274 /** 275 285 // Get remote input 286 // Update synchronizables 287 } 288 289 /** 290 \brief run all input processing 276 291 */ 277 292 void Orxonox::handle_input () 278 293 { 279 280 281 282 } 283 284 /** 285 294 // localinput 295 localinput->process(); 296 // remoteinput 297 } 298 299 /** 300 \brief advance the timeline 286 301 */ 287 302 void Orxonox::time_slice () … … 295 310 { 296 311 float fps = 1000/dt; 297 printf(" %f", fps);312 printf("fps = %f\n", fps); 298 313 } 299 314 … … 306 321 307 322 /** 308 323 \brief compute collision detection 309 324 */ 310 325 void Orxonox::collision () 311 326 { 312 313 } 314 315 /** 316 317 318 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 319 334 */ 320 335 bool Orxonox::system_command (Command* cmd) 321 336 { 322 323 324 if( !cmd->bUp) bQuitOrxonox = true;325 326 327 328 } 329 330 /** 331 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 332 347 */ 333 348 void Orxonox::display () 334 349 { 335 336 337 338 339 340 341 342 343 344 } 345 346 /** 347 348 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 349 364 */ 350 365 Camera* Orxonox::get_camera () 351 366 { 352 353 } 354 355 /** 356 357 367 return localcamera; 368 } 369 370 /** 371 \brief retrieve a pointer to the local CommandNode 372 \return a pointer to localinput 358 373 */ 359 374 CommandNode* Orxonox::get_localinput () 360 375 { 361 362 } 363 364 /** 365 366 376 return localinput; 377 } 378 379 /** 380 \brief retrieve a pointer to the local World 381 \return a pointer to world 367 382 */ 368 383 World* Orxonox::get_world () 369 384 { 370 385 return world; 371 386 } 372 387 373 388 int main (int argc, char** argv) 374 389 { 375 390 printf(">>> Starting Orxonox <<<\n"); 376 391 Orxonox *orx = Orxonox::getInstance(); 377 392 378 393 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 386 403 //delete orx; 387 404 -
orxonox/trunk/src/orxonox.conf
r2190 r2636 6 6 SPACE=fire 7 7 ESCAPE=quit 8 p=pause 8 9 q=quit 9 10 BUTTON_LEFT=fire 10 11 BUTTON_RIGHT=altfire 11 12 b=benscho 13 x=up_world 14 z=down_world 15 -
orxonox/trunk/src/orxonox.h
r2190 r2636 16 16 class World; 17 17 class Camera; 18 class GameLoader; 18 19 19 20 //! Orxonox core singleton class … … 33 34 Camera* localcamera; 34 35 SDL_Surface* screen; 36 GameLoader* gameLoader; 35 37 36 38 bool bQuitOrxonox; 37 39 bool pause; 38 39 40 41 42 40 Uint32 lastframe; 41 42 void get_config_file (int argc, char** argv); 43 44 // main loop functions 43 45 void synchronize (); 44 46 void handle_input (); … … 57 59 public: 58 60 static Orxonox* getInstance (); 61 void start(); 59 62 void quitGame(); 60 63 … … 63 66 64 67 int init (int argc, char** argv); 65 66 67 68 69 68 69 CommandNode* get_localinput(); 70 Camera* get_camera(); 71 World* get_world(); 72 70 73 void mainLoop(); 71 74 }; -
orxonox/trunk/src/player.cc
r2551 r2636 62 62 void Player::command (Command* cmd) 63 63 { 64 65 66 67 68 69 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; 70 70 } 71 71 -
orxonox/trunk/src/stdincl.h
r2551 r2636 15 15 #include "coordinates.h" 16 16 #include "list.h" 17 #include "error.h" 17 18 #include "message_structures.h" 18 19 #include "orxonox.h" -
orxonox/trunk/src/track.cc
r2551 r2636 52 52 { 53 53 } 54 55 void Track::init() 56 { 57 58 } 59 54 60 55 61 /** -
orxonox/trunk/src/track.h
r2551 r2636 27 27 28 28 public: 29 29 Track (); 30 30 Track (Uint32 number, Uint32 next, Vector* start, Vector* finish); 31 31 ~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 38 39 }; 39 40 -
orxonox/trunk/src/world.cc
r2551 r2636 31 31 This creates a new empty world! 32 32 */ 33 World::World () 34 { 35 entities = new List<WorldEntity>(); 33 World::World (char* name) 34 { 35 this->worldName = name; 36 this->debugWorldNr = -1; 37 this->entities = new List<WorldEntity>(); 38 } 39 40 World::World (int worldID) 41 { 42 this->debugWorldNr = worldID; 43 this->worldName = NULL; 44 this->entities = new List<WorldEntity>(); 36 45 } 37 46 … … 44 53 delete entities; 45 54 } 55 56 57 /** 58 \brief initialize the world before use. 59 */ 60 Error World::init() 61 { 62 this->bPause = false; 63 } 64 65 Error World::start() 66 { 67 this->mainLoop(); 68 } 69 70 Error World::stop() 71 { 72 this->bQuitCurrentGame = true; 73 this->localCamera->setWorld(NULL); 74 } 75 76 Error World::pause() 77 { 78 this->isPaused = true; 79 } 80 81 Error World::resume() 82 { 83 this->isPaused = false; 84 } 85 86 void 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 46 164 47 165 /** … … 254 372 } 255 373 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 288 375 289 376 /** … … 295 382 track[loc->part].map_camera (loc, plc); 296 383 } 384 385 386 void World::setTrackLen(Uint32 len) 387 { 388 this->tracklen = len; 389 } 390 391 int World::getTrackLen() 392 { 393 return this->tracklen; 394 } 395 396 397 void 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 */ 422 void World::synchronize () 423 { 424 // Get remote input 425 // Update synchronizables 426 } 427 428 /** 429 \brief run all input processing 430 */ 431 void World::handle_input () 432 { 433 // localinput 434 Orxonox::getInstance()->get_localinput()->process(); 435 // remoteinput 436 } 437 438 /** 439 \brief advance the timeline 440 */ 441 void 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 */ 468 void 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 */ 478 bool 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 */ 491 void 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 504 Camera* World::getCamera() 505 { 506 return this->localCamera; 507 } -
orxonox/trunk/src/world.h
r2551 r2636 8 8 9 9 #include "stdincl.h" 10 #include "story_entity.h" 11 12 10 13 11 14 class Track; 12 15 class WorldEntity; 16 class Camera; 13 17 14 18 //! The game environment 15 class World {19 class World : public StoryEntity { 16 20 17 21 public: 18 World (); 22 World (char* name); 23 World (int worldID); 19 24 ~World (); 20 25 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(); 25 36 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); 31 44 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 36 61 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; 44 66 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(); 45 76 }; 46 77 … … 63 94 if( loc == NULL) 64 95 { 65 66 96 zeroloc.dist = 0; 97 zeroloc.part = 0; 67 98 zeroloc.pos = Vector(); 68 99 zeroloc.rot = Quaternion();
Note: See TracChangeset
for help on using the changeset viewer.