[1850] | 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 | This program is distributed in the hope that it will be useful, |
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | GNU General Public License for more details. |
---|
| 15 | |
---|
| 16 | You should have received a copy of the GNU General Public License |
---|
| 17 | along with this program; if not, write to the Free Software Foundation, |
---|
| 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 19 | |
---|
[1855] | 20 | |
---|
| 21 | ### File Specific: |
---|
| 22 | main-programmer: Patrick Boenzli |
---|
[2190] | 23 | co-programmer: Christian Meyer |
---|
[1850] | 24 | */ |
---|
| 25 | |
---|
[2190] | 26 | #include "orxonox.h" |
---|
[2036] | 27 | #include "world.h" |
---|
[2190] | 28 | #include "camera.h" |
---|
[2036] | 29 | #include "data_tank.h" |
---|
[2190] | 30 | #include "command_node.h" |
---|
[2636] | 31 | #include "game_loader.h" |
---|
[2190] | 32 | #include <string.h> |
---|
[2036] | 33 | |
---|
[1803] | 34 | using namespace std; |
---|
| 35 | |
---|
[2190] | 36 | /** |
---|
[2636] | 37 | \brief create a new Orxonox |
---|
[2190] | 38 | */ |
---|
| 39 | Orxonox::Orxonox () |
---|
[1872] | 40 | { |
---|
| 41 | pause = false; |
---|
| 42 | } |
---|
[1803] | 43 | |
---|
[2190] | 44 | /** |
---|
[2636] | 45 | \brief remove Orxonox from memory |
---|
[2190] | 46 | */ |
---|
[1875] | 47 | Orxonox::~Orxonox () |
---|
[2190] | 48 | { |
---|
[3226] | 49 | Orxonox::singletonRef = NULL; |
---|
[2636] | 50 | if( world != NULL) delete world; |
---|
| 51 | if( localinput != NULL) delete world; |
---|
| 52 | if( localcamera != NULL) delete localcamera; |
---|
| 53 | if( resources != NULL) delete resources; |
---|
[2190] | 54 | } |
---|
[1850] | 55 | |
---|
| 56 | |
---|
[2190] | 57 | /* this is a singleton class to prevent duplicates */ |
---|
[3226] | 58 | Orxonox* Orxonox::singletonRef = 0; |
---|
[1872] | 59 | |
---|
[1850] | 60 | Orxonox* Orxonox::getInstance (void) |
---|
[1803] | 61 | { |
---|
[3226] | 62 | if (singletonRef == NULL) |
---|
| 63 | singletonRef = new Orxonox(); |
---|
| 64 | return singletonRef; |
---|
[1850] | 65 | } |
---|
| 66 | |
---|
[2190] | 67 | /** |
---|
[2636] | 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 |
---|
[2190] | 73 | */ |
---|
[3226] | 74 | void Orxonox::getConfigFile (int argc, char** argv) |
---|
[1850] | 75 | { |
---|
[2636] | 76 | strcpy (configfilename, "orxonox.conf"); |
---|
[1803] | 77 | } |
---|
| 78 | |
---|
[2190] | 79 | /** |
---|
[2636] | 80 | \brief initialize Orxonox with command line |
---|
[2190] | 81 | */ |
---|
| 82 | int Orxonox::init (int argc, char** argv) |
---|
[1803] | 83 | { |
---|
[2636] | 84 | // parse command line |
---|
| 85 | // config file |
---|
| 86 | |
---|
[3226] | 87 | getConfigFile (argc, argv); |
---|
[3174] | 88 | SDL_Init (SDL_INIT_TIMER); |
---|
[2636] | 89 | // initialize everything |
---|
[3226] | 90 | if( initVideo() == -1) return -1; |
---|
| 91 | if( initSound() == -1) return -1; |
---|
[2190] | 92 | printf("> Initializing input\n"); |
---|
[3226] | 93 | if( initInput() == -1) return -1; |
---|
[2190] | 94 | printf("> Initializing networking\n"); |
---|
[3226] | 95 | if( initNetworking () == -1) return -1; |
---|
[2190] | 96 | printf("> Initializing resources\n"); |
---|
[3226] | 97 | if( initResources () == -1) return -1; |
---|
[2636] | 98 | //printf("> Initializing world\n"); |
---|
| 99 | //if( init_world () == -1) return -1; PB: world will be initialized when started |
---|
| 100 | |
---|
| 101 | return 0; |
---|
[1850] | 102 | } |
---|
[1849] | 103 | |
---|
[2190] | 104 | /** |
---|
[2636] | 105 | \brief initializes SDL and OpenGL |
---|
[2190] | 106 | */ |
---|
[3226] | 107 | int Orxonox::initVideo() |
---|
[2190] | 108 | { |
---|
[3174] | 109 | printf("> Initializing video\n"); |
---|
[3226] | 110 | if (SDL_Init(SDL_INIT_VIDEO) == -1) |
---|
[3174] | 111 | { |
---|
| 112 | printf ("could not initialize SDL Video\n"); |
---|
| 113 | return -1; |
---|
| 114 | } |
---|
[2190] | 115 | // Set video mode |
---|
| 116 | // TO DO: parse arguments for settings |
---|
[3338] | 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); |
---|
[2190] | 121 | |
---|
[3338] | 122 | |
---|
| 123 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
---|
| 124 | SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16); |
---|
| 125 | SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); |
---|
| 126 | SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0); |
---|
| 127 | SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0); |
---|
| 128 | SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0); |
---|
| 129 | SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0); |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | |
---|
[2190] | 133 | int bpp = 16; |
---|
| 134 | int width = 640; |
---|
| 135 | int height = 480; |
---|
[3336] | 136 | //Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER; /* \todo: SDL_OPENGL doen't permit to load images*/ |
---|
| 137 | //Uint32 flags = SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER; |
---|
| 138 | |
---|
| 139 | Uint32 videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE; |
---|
| 140 | |
---|
| 141 | /* query SDL for information about our video hardware */ |
---|
| 142 | const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo (); |
---|
[2190] | 143 | |
---|
[3336] | 144 | if( videoInfo == NULL) |
---|
| 145 | { |
---|
| 146 | printf ("Orxonox::initVideo() - Failed getting Video Info :%s\n", SDL_GetError()); |
---|
| 147 | SDL_Quit (); |
---|
| 148 | } |
---|
| 149 | if( videoInfo->hw_available) |
---|
| 150 | videoFlags |= SDL_HWSURFACE; |
---|
[3338] | 151 | else |
---|
[3336] | 152 | videoFlags |= SDL_SWSURFACE; |
---|
| 153 | /* |
---|
| 154 | if(VideoInfo -> blit_hw) |
---|
| 155 | VideoFlags |= SDL_HWACCEL; |
---|
| 156 | */ |
---|
| 157 | |
---|
| 158 | if((this->screen = SDL_SetVideoMode (width, height, bpp, videoFlags)) == NULL) |
---|
[2190] | 159 | { |
---|
[3336] | 160 | printf("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, videoFlags, SDL_GetError()); |
---|
[2190] | 161 | SDL_Quit(); |
---|
| 162 | return -1; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | // Set window labeling |
---|
[3338] | 166 | SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION); |
---|
[2190] | 167 | |
---|
| 168 | // TO DO: Create a cool icon and use it here |
---|
| 169 | // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); |
---|
[1850] | 170 | |
---|
[2190] | 171 | // OpenGL stuff |
---|
[3338] | 172 | glClearColor (0.0, 0.0, 0.0, 0.0); |
---|
| 173 | glEnable (GL_DEPTH_TEST); |
---|
[2817] | 174 | |
---|
| 175 | // LIGHTING |
---|
| 176 | GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0}; |
---|
| 177 | GLfloat whiteLight[] = {1.0, 1.0, 1.0,1.0}; |
---|
| 178 | GLfloat lightPosition[] = {10.0, 10, 19.0, 0.0}; |
---|
| 179 | |
---|
[3338] | 180 | glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight); |
---|
| 181 | glLightfv (GL_LIGHT0, GL_SPECULAR, whiteLight); |
---|
| 182 | glEnable (GL_LIGHTING); |
---|
| 183 | glEnable (GL_LIGHT0); |
---|
| 184 | glEnable (GL_DEPTH_TEST); |
---|
| 185 | glLightfv (GL_LIGHT0, GL_POSITION, lightPosition); |
---|
| 186 | glLightfv (GL_LIGHT0, GL_DIFFUSE, whiteLight); |
---|
[2817] | 187 | |
---|
[3338] | 188 | glEnable (GL_TEXTURE_2D); |
---|
[2792] | 189 | // glEnable(GL_COLOR); |
---|
| 190 | // glShadeModel(GL_SMOOTH); |
---|
[1899] | 191 | |
---|
[2190] | 192 | // create camera |
---|
[3213] | 193 | //localcamera = new Camera(world); /* \todo camera/input node not used anymore*/ |
---|
[2190] | 194 | |
---|
| 195 | return 0; |
---|
| 196 | } |
---|
[1850] | 197 | |
---|
[3214] | 198 | |
---|
[2190] | 199 | /** |
---|
[2636] | 200 | \brief initializes the sound engine |
---|
[2190] | 201 | */ |
---|
[3226] | 202 | int Orxonox::initSound() |
---|
[2190] | 203 | { |
---|
[3174] | 204 | printf("> Initializing sound\n"); |
---|
[3226] | 205 | // SDL_Init(SDL_INIT_AUDIO); |
---|
[2636] | 206 | printf("Not yet implemented\n"); |
---|
| 207 | return 0; |
---|
[2190] | 208 | } |
---|
[1900] | 209 | |
---|
[3214] | 210 | |
---|
[2190] | 211 | /** |
---|
[2636] | 212 | \brief initializes input functions |
---|
[2190] | 213 | */ |
---|
[3226] | 214 | int Orxonox::initInput() |
---|
[2190] | 215 | { |
---|
[2636] | 216 | // create localinput |
---|
| 217 | localinput = new CommandNode( configfilename); |
---|
| 218 | |
---|
| 219 | return 0; |
---|
[1803] | 220 | } |
---|
| 221 | |
---|
[3214] | 222 | |
---|
[2190] | 223 | /** |
---|
[2636] | 224 | \brief initializes network system |
---|
[2190] | 225 | */ |
---|
[3226] | 226 | int Orxonox::initNetworking() |
---|
[1897] | 227 | { |
---|
[2636] | 228 | printf("Not yet implemented\n"); |
---|
| 229 | return 0; |
---|
[1897] | 230 | } |
---|
| 231 | |
---|
[3214] | 232 | |
---|
[2190] | 233 | /** |
---|
[2636] | 234 | \brief initializes and loads resource files |
---|
[2190] | 235 | */ |
---|
[3226] | 236 | int Orxonox::initResources() |
---|
[1858] | 237 | { |
---|
[2636] | 238 | printf("Not yet implemented\n"); |
---|
| 239 | return 0; |
---|
[1858] | 240 | } |
---|
[1849] | 241 | |
---|
[3214] | 242 | |
---|
[2190] | 243 | /** |
---|
[2636] | 244 | \brief initializes the world |
---|
[2190] | 245 | */ |
---|
[3226] | 246 | int Orxonox::initWorld() |
---|
[1896] | 247 | { |
---|
[2636] | 248 | //world = new World(); |
---|
| 249 | |
---|
| 250 | // TO DO: replace this with a menu/intro |
---|
| 251 | //world->load_debug_level(); |
---|
| 252 | |
---|
| 253 | return 0; |
---|
[1896] | 254 | } |
---|
| 255 | |
---|
[2636] | 256 | |
---|
[2190] | 257 | /** |
---|
[2636] | 258 | \brief starts the orxonox game or menu |
---|
| 259 | |
---|
| 260 | here is the central orxonox state manager. There are currently two states |
---|
| 261 | - menu |
---|
| 262 | - game-play |
---|
| 263 | both states manage their states themselfs again. |
---|
[2190] | 264 | */ |
---|
[2636] | 265 | void Orxonox::start() |
---|
| 266 | { |
---|
| 267 | |
---|
| 268 | this->gameLoader = GameLoader::getInstance(); |
---|
| 269 | this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
---|
| 270 | this->gameLoader->init(); |
---|
| 271 | this->gameLoader->start(); |
---|
| 272 | } |
---|
| 273 | |
---|
[3214] | 274 | |
---|
[2636] | 275 | /** |
---|
| 276 | \brief exits Orxonox |
---|
| 277 | */ |
---|
[1875] | 278 | void Orxonox::quitGame() |
---|
| 279 | { |
---|
[2636] | 280 | bQuitOrxonox = true; |
---|
[1875] | 281 | } |
---|
| 282 | |
---|
| 283 | |
---|
[3214] | 284 | |
---|
[2190] | 285 | /** |
---|
[2636] | 286 | \brief handles sprecial events from localinput |
---|
| 287 | \param event: an event not handled by the CommandNode |
---|
[2190] | 288 | */ |
---|
[3226] | 289 | void Orxonox::eventHandler(SDL_Event* event) |
---|
[2190] | 290 | { |
---|
[2636] | 291 | // Handle special events such as reshape, quit, focus changes |
---|
[2190] | 292 | } |
---|
[3214] | 293 | |
---|
[1875] | 294 | |
---|
[2190] | 295 | /** |
---|
[2636] | 296 | \brief handle keyboard commands that are not meant for WorldEntities |
---|
| 297 | \param cmd: the command to handle |
---|
| 298 | \return true if the command was handled by the system or false if it may be passed to the WorldEntities |
---|
[2190] | 299 | */ |
---|
[3226] | 300 | bool Orxonox::systemCommand(Command* cmd) |
---|
[2190] | 301 | { |
---|
[3220] | 302 | /* |
---|
[2636] | 303 | if( !strcmp( cmd->cmd, "quit")) |
---|
| 304 | { |
---|
| 305 | if( !cmd->bUp) this->gameLoader->stop(); |
---|
| 306 | return true; |
---|
| 307 | } |
---|
| 308 | return false; |
---|
[3220] | 309 | */ |
---|
| 310 | return false; |
---|
[2190] | 311 | } |
---|
[1803] | 312 | |
---|
[1850] | 313 | |
---|
[2190] | 314 | /** |
---|
[2636] | 315 | \brief retrieve a pointer to the local Camera |
---|
| 316 | \return a pointer to localcamera |
---|
[2190] | 317 | */ |
---|
[3226] | 318 | Camera* Orxonox::getCamera() |
---|
[1872] | 319 | { |
---|
[2636] | 320 | return localcamera; |
---|
[1872] | 321 | } |
---|
[1850] | 322 | |
---|
[3214] | 323 | |
---|
[2190] | 324 | /** |
---|
[2636] | 325 | \brief retrieve a pointer to the local CommandNode |
---|
| 326 | \return a pointer to localinput |
---|
[2190] | 327 | */ |
---|
[3226] | 328 | CommandNode* Orxonox::getLocalInput() |
---|
[1850] | 329 | { |
---|
[2636] | 330 | return localinput; |
---|
[1803] | 331 | } |
---|
| 332 | |
---|
[3214] | 333 | |
---|
[2190] | 334 | /** |
---|
[2636] | 335 | \brief retrieve a pointer to the local World |
---|
| 336 | \return a pointer to world |
---|
[2190] | 337 | */ |
---|
[3226] | 338 | World* Orxonox::getWorld() |
---|
[1872] | 339 | { |
---|
[2636] | 340 | return world; |
---|
[1872] | 341 | } |
---|
[1850] | 342 | |
---|
[3214] | 343 | |
---|
[3336] | 344 | SDL_Surface* Orxonox::getScreen () |
---|
| 345 | { |
---|
| 346 | return this->screen; |
---|
| 347 | } |
---|
[3214] | 348 | |
---|
| 349 | |
---|
[3226] | 350 | int main(int argc, char** argv) |
---|
[1803] | 351 | { |
---|
[2636] | 352 | printf(">>> Starting Orxonox <<<\n"); |
---|
[1850] | 353 | Orxonox *orx = Orxonox::getInstance(); |
---|
[2190] | 354 | |
---|
[3226] | 355 | if((*orx).init(argc, argv) == -1) |
---|
[2636] | 356 | { |
---|
| 357 | printf("! Orxonox initialization failed\n"); |
---|
| 358 | return -1; |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | orx->start(); |
---|
| 362 | |
---|
[2190] | 363 | //delete orx; |
---|
| 364 | |
---|
[1803] | 365 | return 0; |
---|
| 366 | } |
---|