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