Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: first definition of the Grahpics-class. more to follow, (and to read about)

File size: 5.7 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}
59
60/** \brief this is a singleton class to prevent duplicates */
61Orxonox* Orxonox::singletonRef = 0;
62
63/**
64   \returns reference or new Object of Orxonox if not existent.
65*/
66Orxonox* Orxonox::getInstance (void)
67{
68  if (singletonRef == NULL)
69    singletonRef = new Orxonox();
70  return singletonRef;
71}
72
73/**
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
79*/
80void Orxonox::getConfigFile (int argc, char** argv)
81{
82  strcpy (configfilename, "orxonox.conf");
83}
84
85/**
86   \brief initialize Orxonox with command line
87*/
88int Orxonox::init (int argc, char** argv)
89{
90  // parse command line
91  // config file
92 
93  getConfigFile (argc, argv);
94  SDL_Init (SDL_INIT_TIMER);
95  // initialize everything
96  if( initVideo() == -1) return -1;
97  if( initSound() == -1) return -1;
98  printf("> Initializing input\n");
99  if( initInput() == -1) return -1;
100  printf("> Initializing networking\n");
101  if( initNetworking () == -1) return -1;
102  printf("> Initializing resources\n");
103  if( initResources () == -1) return -1;
104  //printf("> Initializing world\n");
105  //if( init_world () == -1) return -1; PB: world will be initialized when started
106 
107  return 0;
108}
109
110/**
111   \brief initializes SDL and OpenGL
112*/
113int Orxonox::initVideo() 
114{
115  printf("> Initializing video\n");
116 
117  GraphicsEngine::getInstance();
118 
119  return 0;
120}
121
122
123/**
124   \brief initializes the sound engine
125*/
126int Orxonox::initSound() 
127{
128  printf("> Initializing sound\n");
129  // SDL_Init(SDL_INIT_AUDIO);
130  printf("Not yet implemented\n");
131  return 0;
132}
133
134
135/**
136   \brief initializes input functions
137*/
138int Orxonox::initInput() 
139{
140  // create localinput
141  localinput = new CommandNode( configfilename);
142 
143  return 0;
144}
145
146
147/**
148   \brief initializes network system
149*/
150int Orxonox::initNetworking() 
151{
152  printf("Not yet implemented\n");
153  return 0;
154}
155
156
157/**
158   \brief initializes and loads resource files
159*/
160int Orxonox::initResources() 
161{
162  printf("Not yet implemented\n");
163  return 0;
164}
165
166
167/**
168   \brief initializes the world
169*/
170int Orxonox::initWorld() 
171{
172  //world = new World();
173 
174  // TO DO: replace this with a menu/intro
175  //world->load_debug_level();
176 
177  return 0;
178}
179
180
181/**
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.
188*/
189void 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
198
199/**
200   \brief exits Orxonox
201*/
202void Orxonox::quitGame() 
203{
204  bQuitOrxonox = true;
205}
206
207
208
209/**
210   \brief handles sprecial events from localinput
211   \param event: an event not handled by the CommandNode
212*/
213void Orxonox::eventHandler(SDL_Event* event)
214{
215  // Handle special events such as reshape, quit, focus changes
216}
217 
218
219/**
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
223*/
224bool Orxonox::systemCommand(Command* cmd)
225{
226  /*
227  if( !strcmp( cmd->cmd, "quit"))
228    {
229      if( !cmd->bUp) this->gameLoader->stop();
230      return true;
231    }
232  return false;
233  */
234  return false;
235}
236
237
238/**
239   \brief retrieve a pointer to the local Camera
240   \return a pointer to localcamera
241*/
242Camera* Orxonox::getCamera()
243{
244  return localcamera;
245}
246
247
248/**
249   \brief retrieve a pointer to the local CommandNode
250   \return a pointer to localinput
251*/
252CommandNode* Orxonox::getLocalInput()
253{
254  return localinput;
255}
256
257
258/**
259   \brief retrieve a pointer to the local World
260   \return a pointer to world
261*/
262World* Orxonox::getWorld()
263{
264  return world;
265}
266
267/**
268   \return The reference of the SDL-screen of orxonox
269*/
270SDL_Surface* Orxonox::getScreen ()
271{
272  return this->screen;
273}
274
275/**
276   \brief main function
277
278   here the journey begins
279*/
280int main(int argc, char** argv) 
281{ 
282  printf(">>> Starting Orxonox <<<\n");
283  Orxonox *orx = Orxonox::getInstance();
284 
285  if((*orx).init(argc, argv) == -1)
286    {
287      printf("! Orxonox initialization failed\n");
288      return -1;
289    }
290 
291  orx->start();
292 
293  //delete orx;
294 
295  return 0;
296}
Note: See TracBrowser for help on using the repository browser.