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