Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/orxonox.cc @ 3613

Last change on this file since 3613 was 3613, checked in by bensch, 19 years ago

orxonox/trunk: taken camera out of orxonox.cc/h because, it just does not belong there

File size: 5.6 KB
Line 
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>
35int verbose = 4;
36
37using namespace std;
38
39/**
40   \brief create a new Orxonox
41*/
42Orxonox::Orxonox ()
43{
44  pause = false;
45}
46
47/**
48   \brief remove Orxonox from memory
49*/
50Orxonox::~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 */
60Orxonox* Orxonox::singletonRef = 0;
61
62/**
63   \returns reference or new Object of Orxonox if not existent.
64*/
65Orxonox* 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*/
79void Orxonox::getConfigFile (int argc, char** argv)
80{
81  strcpy (configfilename, "orxonox.conf");
82}
83
84/**
85   \brief initialize Orxonox with command line
86*/
87int 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*/
112int 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*/
125int 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*/
137int 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*/
149int Orxonox::initNetworking() 
150{
151  printf("Not yet implemented\n");
152  return 0;
153}
154
155
156/**
157   \brief initializes and loads resource files
158*/
159int Orxonox::initResources() 
160{
161  printf("Not yet implemented\n");
162  return 0;
163}
164
165
166/**
167   \brief initializes the world
168*/
169int 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*/
188void 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*/
201void 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*/
212void Orxonox::eventHandler(SDL_Event* event)
213{
214  // Handle special events such as reshape, quit, focus changes
215}
216 
217
218/**
219   \brief handle keyboard commands that are not meant for WorldEntities
220   \param cmd: the command to handle
221   \return true if the command was handled by the system or false if it may be passed to the WorldEntities
222*/
223bool Orxonox::systemCommand(Command* cmd)
224{
225  /*
226  if( !strcmp( cmd->cmd, "quit"))
227    {
228      if( !cmd->bUp) this->gameLoader->stop();
229      return true;
230    }
231  return false;
232  */
233  return false;
234}
235
236/**
237   \brief retrieve a pointer to the local CommandNode
238   \return a pointer to localinput
239*/
240CommandNode* Orxonox::getLocalInput()
241{
242  return localinput;
243}
244
245
246/**
247   \brief retrieve a pointer to the local World
248   \return a pointer to world
249*/
250World* Orxonox::getWorld()
251{
252  return world;
253}
254
255/**
256   \return The reference of the SDL-screen of orxonox
257*/
258SDL_Surface* Orxonox::getScreen ()
259{
260  return this->screen;
261}
262
263/**
264   \brief main function
265
266   here the journey begins
267*/
268int main(int argc, char** argv) 
269{ 
270  printf(">>> Starting Orxonox <<<\n");
271  Orxonox *orx = Orxonox::getInstance();
272 
273  if((*orx).init(argc, argv) == -1)
274    {
275      printf("! Orxonox initialization failed\n");
276      return -1;
277    }
278 
279  orx->start();
280 
281  //delete orx;
282 
283  return 0;
284}
Note: See TracBrowser for help on using the repository browser.