Changeset 3238 in orxonox.OLD for orxonox/branches/sound/src/orxonox.cc
- Timestamp:
- Dec 20, 2004, 2:42:54 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/sound/src/orxonox.cc
r2636 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 … … 158 142 glClearColor(0.0, 0.0, 0.0, 0.0); 159 143 glEnable(GL_DEPTH_TEST); 160 glEnable(GL_COLOR); 161 glShadeModel(GL_FLAT); 144 145 // LIGHTING 146 GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0}; 147 GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0}; 148 GLfloat lightPosition[] = {10.0, 10, 19.0, 0.0}; 149 150 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); 151 glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight); 152 glEnable(GL_LIGHTING); 153 glEnable(GL_LIGHT0); 154 glEnable(GL_DEPTH_TEST); 155 glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); 156 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); 157 158 // glEnable(GL_COLOR); 159 // glShadeModel(GL_SMOOTH); 162 160 163 161 // create camera 164 localcamera = new Camera(world); 165 166 return 0; 167 } 162 //localcamera = new Camera(world); /* \todo camera/input node not used anymore*/ 163 164 return 0; 165 } 166 168 167 169 168 /** 170 169 \brief initializes the sound engine 171 170 */ 172 int Orxonox::init_sound () 173 { 171 int Orxonox::initSound() 172 { 173 printf("> Initializing sound\n"); 174 // SDL_Init(SDL_INIT_AUDIO); 174 175 printf("Not yet implemented\n"); 175 176 return 0; 176 177 } 177 178 179 178 180 /** 179 181 \brief initializes input functions 180 182 */ 181 int Orxonox::init _input()183 int Orxonox::initInput() 182 184 { 183 185 // create localinput … … 187 189 } 188 190 191 189 192 /** 190 193 \brief initializes network system 191 194 */ 192 int Orxonox::init _networking()195 int Orxonox::initNetworking() 193 196 { 194 197 printf("Not yet implemented\n"); … … 196 199 } 197 200 201 198 202 /** 199 203 \brief initializes and loads resource files 200 204 */ 201 int Orxonox::init _resources()205 int Orxonox::initResources() 202 206 { 203 207 printf("Not yet implemented\n"); … … 205 209 } 206 210 211 207 212 /** 208 213 \brief initializes the world 209 214 */ 210 int Orxonox::init _world()215 int Orxonox::initWorld() 211 216 { 212 217 //world = new World(); … … 236 241 } 237 242 243 238 244 /** 239 245 \brief exits Orxonox … … 244 250 } 245 251 246 /** 247 \brief this runs all of Orxonox 248 */ 249 void Orxonox::mainLoop() 250 { 251 lastframe = SDL_GetTicks(); 252 bQuitOrxonox = false; 253 // This is where everything is run 254 printf("Orxonox|Entering main loop\n"); 255 while( !bQuitOrxonox) 256 { 257 // Network 258 synchronize(); 259 // Process input 260 handle_input(); 261 // Process time 262 time_slice(); 263 // Process collision 264 collision(); 265 // Draw 266 display(); 267 } 268 printf("Orxonox|Exiting the main loop\n"); 269 } 252 270 253 271 254 /** … … 273 256 \param event: an event not handled by the CommandNode 274 257 */ 275 void Orxonox::event _handler(SDL_Event* event)258 void Orxonox::eventHandler(SDL_Event* event) 276 259 { 277 260 // Handle special events such as reshape, quit, focus changes 278 261 } 279 280 /** 281 \brief synchronize local data with remote data 282 */ 283 void Orxonox::synchronize () 284 { 285 // Get remote input 286 // Update synchronizables 287 } 288 289 /** 290 \brief run all input processing 291 */ 292 void Orxonox::handle_input () 293 { 294 // localinput 295 localinput->process(); 296 // remoteinput 297 } 298 299 /** 300 \brief advance the timeline 301 */ 302 void Orxonox::time_slice () 303 { 304 Uint32 curframe = SDL_GetTicks(); 305 if( !pause) 306 { 307 Uint32 dt = curframe - lastframe; 308 309 if(dt > 0) 310 { 311 float fps = 1000/dt; 312 printf("fps = %f\n", fps); 313 } 314 315 world->time_slice (dt); 316 world->update (); 317 localcamera->time_slice (dt); 318 } 319 lastframe = curframe; 320 } 321 322 /** 323 \brief compute collision detection 324 */ 325 void Orxonox::collision () 326 { 327 world->collide (); 328 } 262 329 263 330 264 /** … … 333 267 \return true if the command was handled by the system or false if it may be passed to the WorldEntities 334 268 */ 335 bool Orxonox::system_command (Command* cmd) 336 { 269 bool Orxonox::systemCommand(Command* cmd) 270 { 271 /* 337 272 if( !strcmp( cmd->cmd, "quit")) 338 273 { … … 341 276 } 342 277 return false; 343 } 344 345 /** 346 \brief render the current frame 347 */ 348 void Orxonox::display () 349 { 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 } 278 */ 279 return false; 280 } 281 360 282 361 283 /** … … 363 285 \return a pointer to localcamera 364 286 */ 365 Camera* Orxonox::get _camera()287 Camera* Orxonox::getCamera() 366 288 { 367 289 return localcamera; 368 290 } 291 369 292 370 293 /** … … 372 295 \return a pointer to localinput 373 296 */ 374 CommandNode* Orxonox::get _localinput()297 CommandNode* Orxonox::getLocalInput() 375 298 { 376 299 return localinput; 377 300 } 301 378 302 379 303 /** … … 381 305 \return a pointer to world 382 306 */ 383 World* Orxonox::get _world()307 World* Orxonox::getWorld() 384 308 { 385 309 return world; 386 310 } 387 311 388 int main (int argc, char** argv) 312 313 314 315 int main(int argc, char** argv) 389 316 { 390 317 printf(">>> Starting Orxonox <<<\n"); 391 318 Orxonox *orx = Orxonox::getInstance(); 392 319 393 if( 320 if((*orx).init(argc, argv) == -1) 394 321 { 395 322 printf("! Orxonox initialization failed\n"); … … 397 324 } 398 325 399 //(*orx).mainLoop();400 401 326 orx->start(); 402 327
Note: See TracChangeset
for help on using the changeset viewer.