Changeset 3238 in orxonox.OLD for orxonox/branches/nico/src/orxonox.cc
- Timestamp:
- Dec 20, 2004, 2:42:54 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/nico/src/orxonox.cc
r2817 r3238 47 47 Orxonox::~Orxonox () 48 48 { 49 Orxonox::singleton _ref = NULL;49 Orxonox::singletonRef = NULL; 50 50 if( world != NULL) delete world; 51 51 if( localinput != NULL) delete world; … … 56 56 57 57 /* this is a singleton class to prevent duplicates */ 58 Orxonox* Orxonox::singleton _ref = 0;58 Orxonox* Orxonox::singletonRef = 0; 59 59 60 60 Orxonox* Orxonox::getInstance (void) 61 61 { 62 if (singleton _ref == NULL)63 singleton _ref = new Orxonox();64 return singleton _ref;62 if (singletonRef == NULL) 63 singletonRef = new Orxonox(); 64 return singletonRef; 65 65 } 66 66 … … 72 72 it's path and name into configfilename 73 73 */ 74 void Orxonox::get_config_file (int argc, char** argv) 75 { 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 74 void Orxonox::getConfigFile (int argc, char** argv) 75 { 87 76 strcpy (configfilename, "orxonox.conf"); 88 77 } … … 96 85 // config file 97 86 98 get_config_file (argc, argv); 99 100 // initialize SDL 101 printf("> Initializing SDL\n"); 102 if( SDL_Init (SDL_INIT_EVERYTHING) == -1) 87 getConfigFile (argc, argv); 88 SDL_Init (SDL_INIT_TIMER); 89 // initialize everything 90 if( initVideo() == -1) return -1; 91 if( initSound() == -1) return -1; 92 printf("> Initializing input\n"); 93 if( initInput() == -1) return -1; 94 printf("> Initializing networking\n"); 95 if( initNetworking () == -1) return -1; 96 printf("> Initializing resources\n"); 97 if( initResources () == -1) return -1; 98 //printf("> Initializing world\n"); 99 //if( init_world () == -1) return -1; PB: world will be initialized when started 100 101 return 0; 102 } 103 104 /** 105 \brief initializes SDL and OpenGL 106 */ 107 int Orxonox::initVideo() 108 { 109 printf("> Initializing video\n"); 110 if (SDL_Init(SDL_INIT_VIDEO) == -1) 103 111 { 104 printf (" Could not SDL_Init(): %s\n", SDL_GetError());112 printf ("could not initialize SDL Video\n"); 105 113 return -1; 106 114 } 107 108 // initialize everything109 printf("> Initializing video\n");110 if( init_video () == -1) return -1;111 printf("> Initializing sound\n");112 if( init_sound () == -1) return -1;113 printf("> Initializing input\n");114 if( init_input () == -1) return -1;115 printf("> Initializing networking\n");116 if( init_networking () == -1) return -1;117 printf("> Initializing resources\n");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 started121 122 return 0;123 }124 125 /**126 \brief initializes SDL and OpenGL127 */128 int Orxonox::init_video ()129 {130 115 // Set video mode 131 116 // TO DO: parse arguments for settings 132 SDL_GL_SetAttribute 133 SDL_GL_SetAttribute 134 SDL_GL_SetAttribute 135 SDL_GL_SetAttribute 117 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); 118 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); 119 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); 120 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); 136 121 137 122 int bpp = 16; … … 140 125 Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER; 141 126 142 if( 127 if((screen = SDL_SetVideoMode (width, height, bpp, flags)) == NULL) 143 128 { 144 printf 129 printf("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, flags, SDL_GetError()); 145 130 SDL_Quit(); 146 131 return -1; … … 148 133 149 134 // Set window labeling 150 // TO DO: Add version information to caption 151 SDL_WM_SetCaption( "Orxonox", "Orxonox"); 135 SDL_WM_SetCaption("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION); 152 136 153 137 // TO DO: Create a cool icon and use it here … … 176 160 177 161 // create camera 178 localcamera = new Camera(world); 179 180 return 0; 181 } 162 //localcamera = new Camera(world); /* \todo camera/input node not used anymore*/ 163 164 return 0; 165 } 166 182 167 183 168 /** 184 169 \brief initializes the sound engine 185 170 */ 186 int Orxonox::init_sound () 187 { 171 int Orxonox::initSound() 172 { 173 printf("> Initializing sound\n"); 174 // SDL_Init(SDL_INIT_AUDIO); 188 175 printf("Not yet implemented\n"); 189 176 return 0; 190 177 } 191 178 179 192 180 /** 193 181 \brief initializes input functions 194 182 */ 195 int Orxonox::init _input()183 int Orxonox::initInput() 196 184 { 197 185 // create localinput … … 201 189 } 202 190 191 203 192 /** 204 193 \brief initializes network system 205 194 */ 206 int Orxonox::init _networking()195 int Orxonox::initNetworking() 207 196 { 208 197 printf("Not yet implemented\n"); … … 210 199 } 211 200 201 212 202 /** 213 203 \brief initializes and loads resource files 214 204 */ 215 int Orxonox::init _resources()205 int Orxonox::initResources() 216 206 { 217 207 printf("Not yet implemented\n"); … … 219 209 } 220 210 211 221 212 /** 222 213 \brief initializes the world 223 214 */ 224 int Orxonox::init _world()215 int Orxonox::initWorld() 225 216 { 226 217 //world = new World(); … … 250 241 } 251 242 243 252 244 /** 253 245 \brief exits Orxonox … … 258 250 } 259 251 260 /** 261 \brief this runs all of Orxonox 262 */ 263 void Orxonox::mainLoop() 264 { 265 lastframe = SDL_GetTicks(); 266 bQuitOrxonox = false; 267 // This is where everything is run 268 printf("Orxonox|Entering main loop\n"); 269 while( !bQuitOrxonox) 270 { 271 // Network 272 synchronize(); 273 // Process input 274 handle_input(); 275 // Process time 276 time_slice(); 277 // Process collision 278 collision(); 279 // Draw 280 display(); 281 } 282 printf("Orxonox|Exiting the main loop\n"); 283 } 252 284 253 285 254 /** … … 287 256 \param event: an event not handled by the CommandNode 288 257 */ 289 void Orxonox::event _handler(SDL_Event* event)258 void Orxonox::eventHandler(SDL_Event* event) 290 259 { 291 260 // Handle special events such as reshape, quit, focus changes 292 261 } 293 294 /** 295 \brief synchronize local data with remote data 296 */ 297 void Orxonox::synchronize () 298 { 299 // Get remote input 300 // Update synchronizables 301 } 302 303 /** 304 \brief run all input processing 305 */ 306 void Orxonox::handle_input () 307 { 308 // localinput 309 localinput->process(); 310 // remoteinput 311 } 312 313 /** 314 \brief advance the timeline 315 */ 316 void Orxonox::time_slice () 317 { 318 Uint32 curframe = SDL_GetTicks(); 319 if( !pause) 320 { 321 Uint32 dt = curframe - lastframe; 322 323 if(dt > 0) 324 { 325 float fps = 1000/dt; 326 printf("fps = %f\n", fps); 327 } 328 329 world->time_slice (dt); 330 world->update (); 331 localcamera->time_slice (dt); 332 } 333 lastframe = curframe; 334 } 335 336 /** 337 \brief compute collision detection 338 */ 339 void Orxonox::collision () 340 { 341 world->collide (); 342 } 262 343 263 344 264 /** … … 347 267 \return true if the command was handled by the system or false if it may be passed to the WorldEntities 348 268 */ 349 bool Orxonox::system_command (Command* cmd) 350 { 269 bool Orxonox::systemCommand(Command* cmd) 270 { 271 /* 351 272 if( !strcmp( cmd->cmd, "quit")) 352 273 { … … 355 276 } 356 277 return false; 357 } 358 359 /** 360 \brief render the current frame 361 */ 362 void Orxonox::display () 363 { 364 // clear buffer 365 glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 366 // set camera 367 localcamera->apply (); 368 // draw world 369 world->draw (); 370 // draw HUD 371 // flip buffers 372 SDL_GL_SwapBuffers(); 373 } 278 */ 279 return false; 280 } 281 374 282 375 283 /** … … 377 285 \return a pointer to localcamera 378 286 */ 379 Camera* Orxonox::get _camera()287 Camera* Orxonox::getCamera() 380 288 { 381 289 return localcamera; 382 290 } 291 383 292 384 293 /** … … 386 295 \return a pointer to localinput 387 296 */ 388 CommandNode* Orxonox::get _localinput()297 CommandNode* Orxonox::getLocalInput() 389 298 { 390 299 return localinput; 391 300 } 301 392 302 393 303 /** … … 395 305 \return a pointer to world 396 306 */ 397 World* Orxonox::get _world()307 World* Orxonox::getWorld() 398 308 { 399 309 return world; 400 310 } 401 311 402 int main (int argc, char** argv) 312 313 314 315 int main(int argc, char** argv) 403 316 { 404 317 printf(">>> Starting Orxonox <<<\n"); 405 318 Orxonox *orx = Orxonox::getInstance(); 406 319 407 if( 320 if((*orx).init(argc, argv) == -1) 408 321 { 409 322 printf("! Orxonox initialization failed\n"); … … 411 324 } 412 325 413 //(*orx).mainLoop();414 415 326 orx->start(); 416 327
Note: See TracChangeset
for help on using the changeset viewer.