Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: one step further with the gragpicsEngine

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