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