| 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 | |
|---|
| 28 | #include "world.h" |
|---|
| 29 | #include "data_tank.h" |
|---|
| 30 | #include "command_node.h" |
|---|
| 31 | #include "game_loader.h" |
|---|
| 32 | #include "graphics_engine.h" |
|---|
| 33 | |
|---|
| 34 | #include <string.h> |
|---|
| 35 | int verbose = 4; |
|---|
| 36 | |
|---|
| 37 | using namespace std; |
|---|
| 38 | |
|---|
| 39 | /** |
|---|
| 40 | \brief create a new Orxonox |
|---|
| 41 | */ |
|---|
| 42 | Orxonox::Orxonox () |
|---|
| 43 | { |
|---|
| 44 | pause = false; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | \brief remove Orxonox from memory |
|---|
| 49 | */ |
|---|
| 50 | Orxonox::~Orxonox () |
|---|
| 51 | { |
|---|
| 52 | Orxonox::singletonRef = NULL; |
|---|
| 53 | if( world != NULL) delete world; |
|---|
| 54 | if( localinput != NULL) delete world; |
|---|
| 55 | if( resources != NULL) delete resources; |
|---|
| 56 | delete GraphicsEngine::getInstance(); // deleting the Graphics |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | /** \brief this is a singleton class to prevent duplicates */ |
|---|
| 60 | Orxonox* Orxonox::singletonRef = 0; |
|---|
| 61 | |
|---|
| 62 | /** |
|---|
| 63 | \returns reference or new Object of Orxonox if not existent. |
|---|
| 64 | */ |
|---|
| 65 | Orxonox* Orxonox::getInstance (void) |
|---|
| 66 | { |
|---|
| 67 | if (singletonRef == NULL) |
|---|
| 68 | singletonRef = new Orxonox(); |
|---|
| 69 | return singletonRef; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | /** |
|---|
| 73 | \brief this finds the config file |
|---|
| 74 | |
|---|
| 75 | Since the config file varies from user to user and since one may want to specify different config files |
|---|
| 76 | for certain occasions or platforms this function finds the right config file for every occasion and stores |
|---|
| 77 | it's path and name into configfilename |
|---|
| 78 | */ |
|---|
| 79 | void Orxonox::getConfigFile (int argc, char** argv) |
|---|
| 80 | { |
|---|
| 81 | strcpy (configfilename, "orxonox.conf"); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | \brief initialize Orxonox with command line |
|---|
| 86 | */ |
|---|
| 87 | int Orxonox::init (int argc, char** argv) |
|---|
| 88 | { |
|---|
| 89 | // parse command line |
|---|
| 90 | // config file |
|---|
| 91 | |
|---|
| 92 | getConfigFile (argc, argv); |
|---|
| 93 | SDL_Init (SDL_INIT_TIMER); |
|---|
| 94 | // initialize everything |
|---|
| 95 | if( initVideo() == -1) return -1; |
|---|
| 96 | if( initSound() == -1) return -1; |
|---|
| 97 | printf("> Initializing input\n"); |
|---|
| 98 | if( initInput() == -1) return -1; |
|---|
| 99 | printf("> Initializing networking\n"); |
|---|
| 100 | if( initNetworking () == -1) return -1; |
|---|
| 101 | printf("> Initializing resources\n"); |
|---|
| 102 | if( initResources () == -1) return -1; |
|---|
| 103 | //printf("> Initializing world\n"); |
|---|
| 104 | //if( init_world () == -1) return -1; PB: world will be initialized when started |
|---|
| 105 | |
|---|
| 106 | return 0; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | \brief initializes SDL and OpenGL |
|---|
| 111 | */ |
|---|
| 112 | int Orxonox::initVideo() |
|---|
| 113 | { |
|---|
| 114 | PRINTF(3)("> Initializing video\n"); |
|---|
| 115 | |
|---|
| 116 | GraphicsEngine::getInstance(); |
|---|
| 117 | |
|---|
| 118 | return 0; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | /** |
|---|
| 123 | \brief initializes the sound engine |
|---|
| 124 | */ |
|---|
| 125 | int Orxonox::initSound() |
|---|
| 126 | { |
|---|
| 127 | printf("> Initializing sound\n"); |
|---|
| 128 | // SDL_Init(SDL_INIT_AUDIO); |
|---|
| 129 | printf("Not yet implemented\n"); |
|---|
| 130 | return 0; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | /** |
|---|
| 135 | \brief initializes input functions |
|---|
| 136 | */ |
|---|
| 137 | int Orxonox::initInput() |
|---|
| 138 | { |
|---|
| 139 | // create localinput |
|---|
| 140 | localinput = new CommandNode( configfilename); |
|---|
| 141 | |
|---|
| 142 | return 0; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | /** |
|---|
| 147 | \brief initializes network system |
|---|
| 148 | */ |
|---|
| 149 | int Orxonox::initNetworking() |
|---|
| 150 | { |
|---|
| 151 | printf("Not yet implemented\n"); |
|---|
| 152 | return 0; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | /** |
|---|
| 157 | \brief initializes and loads resource files |
|---|
| 158 | */ |
|---|
| 159 | int Orxonox::initResources() |
|---|
| 160 | { |
|---|
| 161 | printf("Not yet implemented\n"); |
|---|
| 162 | return 0; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | /** |
|---|
| 167 | \brief initializes the world |
|---|
| 168 | */ |
|---|
| 169 | int Orxonox::initWorld() |
|---|
| 170 | { |
|---|
| 171 | //world = new World(); |
|---|
| 172 | |
|---|
| 173 | // TO DO: replace this with a menu/intro |
|---|
| 174 | //world->load_debug_level(); |
|---|
| 175 | |
|---|
| 176 | return 0; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | /** |
|---|
| 181 | \brief starts the orxonox game or menu |
|---|
| 182 | |
|---|
| 183 | here is the central orxonox state manager. There are currently two states |
|---|
| 184 | - menu |
|---|
| 185 | - game-play |
|---|
| 186 | both states manage their states themselfs again. |
|---|
| 187 | */ |
|---|
| 188 | void Orxonox::start() |
|---|
| 189 | { |
|---|
| 190 | |
|---|
| 191 | this->gameLoader = GameLoader::getInstance(); |
|---|
| 192 | this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0); |
|---|
| 193 | this->gameLoader->init(); |
|---|
| 194 | this->gameLoader->start(); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | /** |
|---|
| 199 | \brief exits Orxonox |
|---|
| 200 | */ |
|---|
| 201 | void Orxonox::quitGame() |
|---|
| 202 | { |
|---|
| 203 | bQuitOrxonox = true; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | /** |
|---|
| 209 | \brief handles sprecial events from localinput |
|---|
| 210 | \param event: an event not handled by the CommandNode |
|---|
| 211 | */ |
|---|
| 212 | void Orxonox::eventHandler(SDL_Event* event) |
|---|
| 213 | { |
|---|
| 214 | // Handle special events such as reshape, quit, focus changes |
|---|
| 215 | switch (event->type) |
|---|
| 216 | { |
|---|
| 217 | case SDL_VIDEORESIZE: |
|---|
| 218 | GraphicsEngine* tmpGEngine = GraphicsEngine::getInstance(); |
|---|
| 219 | tmpGEngine->resolutionChanged(&event->resize); |
|---|
| 220 | break; |
|---|
| 221 | } |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | /** |
|---|
| 226 | \brief handle keyboard commands that are not meant for WorldEntities |
|---|
| 227 | \param cmd: the command to handle |
|---|
| 228 | \return true if the command was handled by the system or false if it may be passed to the WorldEntities |
|---|
| 229 | */ |
|---|
| 230 | bool Orxonox::systemCommand(Command* cmd) |
|---|
| 231 | { |
|---|
| 232 | /* |
|---|
| 233 | if( !strcmp( cmd->cmd, "quit")) |
|---|
| 234 | { |
|---|
| 235 | if( !cmd->bUp) this->gameLoader->stop(); |
|---|
| 236 | return true; |
|---|
| 237 | } |
|---|
| 238 | return false; |
|---|
| 239 | */ |
|---|
| 240 | return false; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | /** |
|---|
| 244 | \brief retrieve a pointer to the local CommandNode |
|---|
| 245 | \return a pointer to localinput |
|---|
| 246 | */ |
|---|
| 247 | CommandNode* Orxonox::getLocalInput() |
|---|
| 248 | { |
|---|
| 249 | return localinput; |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | /** |
|---|
| 254 | \brief retrieve a pointer to the local World |
|---|
| 255 | \return a pointer to world |
|---|
| 256 | */ |
|---|
| 257 | World* Orxonox::getWorld() |
|---|
| 258 | { |
|---|
| 259 | return world; |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | /** |
|---|
| 263 | \return The reference of the SDL-screen of orxonox |
|---|
| 264 | */ |
|---|
| 265 | SDL_Surface* Orxonox::getScreen () |
|---|
| 266 | { |
|---|
| 267 | return this->screen; |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | /** |
|---|
| 271 | \brief main function |
|---|
| 272 | |
|---|
| 273 | here the journey begins |
|---|
| 274 | */ |
|---|
| 275 | int main(int argc, char** argv) |
|---|
| 276 | { |
|---|
| 277 | printf(">>> Starting Orxonox <<<\n"); |
|---|
| 278 | Orxonox *orx = Orxonox::getInstance(); |
|---|
| 279 | |
|---|
| 280 | if((*orx).init(argc, argv) == -1) |
|---|
| 281 | { |
|---|
| 282 | printf("! Orxonox initialization failed\n"); |
|---|
| 283 | return -1; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | orx->start(); |
|---|
| 287 | |
|---|
| 288 | //delete orx; |
|---|
| 289 | |
|---|
| 290 | return 0; |
|---|
| 291 | } |
|---|