Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/chris/src/orxonox.cc @ 2115

Last change on this file since 2115 was 2115, checked in by chris, 20 years ago

orxonox/branches/chris: Managed to apply all that rotating and translating so that you now actually see the debug player following the track. You can even steer the spaceship via the keys now… unfortunately the coordinate transformations are still a mess. Even though mapping from Locations to Placements seems to work in general, applying the finetuned position and rotation still messes up the whole damn thing…

File size: 5.9 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#include "world.h"
28#include "camera.h"
29#include "data_tank.h"
30#include "command_node.h"
31
32using namespace std;
33
34Orxonox::Orxonox () 
35{
36  pause = false;
37}
38
39
40
41Orxonox::~Orxonox () 
42{
43        Orxonox::singleton_ref = NULL;
44        if( world != NULL) delete world;
45        if( localinput != NULL) delete world;
46        if( localcamera != NULL) delete localcamera;
47        if( resources != NULL) delete resources;
48}
49
50
51/* this is a singleton class to prevent duplicates */
52Orxonox* Orxonox::singleton_ref = 0;
53
54Orxonox* Orxonox::getInstance (void)
55{
56  if (singleton_ref == NULL)
57    singleton_ref = new Orxonox();
58  return singleton_ref;
59}
60
61void Orxonox::get_config_file (int argc, char** argv)
62{
63/*      char* path;
64        #ifdef __WIN32__
65        path = getenv("");
66        #else
67        path = getenv("HOME");
68        #endif
69       
70        if( path != NULL) strcpy (configfilename, path);
71        else strcpy (configfilename, "./");
72        strcat (configfilename, "/.orxonox.conf");*/
73       
74        strcpy (configfilename, "orxonox.conf");
75}
76
77int Orxonox::init (int argc, char** argv)
78{
79                // parse command line
80                // config file
81               
82        get_config_file (argc, argv);
83       
84                // initialize SDL
85  printf("> Initializing SDL\n");
86  if( SDL_Init (SDL_INIT_EVERYTHING) == -1)
87  {
88    printf ("Could not SDL_Init(): %s\n", SDL_GetError());
89    return -1;
90  }
91 
92        // initialize everything
93  printf("> Initializing video\n");
94        if( init_video () == -1) return -1;
95  printf("> Initializing sound\n");
96        if( init_sound () == -1) return -1;
97  printf("> Initializing input\n");
98        if( init_input () == -1) return -1;
99  printf("> Initializing networking\n");
100        if( init_networking () == -1) return -1;
101  printf("> Initializing resources\n");
102        if( init_resources () == -1) return -1;
103  printf("> Initializing world\n");
104        if( init_world () == -1) return -1;
105       
106        return 0;
107}
108
109int Orxonox::init_video () 
110{
111  // Set video mode
112  // TO DO: parse arguments for settings
113  SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5);
114  SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5);
115  SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5);
116  SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
117 
118  int bpp = 16;
119  int width = 640;
120  int height = 480;
121  Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
122 
123  if( (screen = SDL_SetVideoMode (width, height, bpp, flags)) == NULL)
124  {
125    printf ("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, flags, SDL_GetError());
126    SDL_Quit();
127    return -1;
128  }
129 
130  // Set window labeling
131  // TO DO: Add version information to caption
132  SDL_WM_SetCaption( "Orxonox", "Orxonox");
133 
134  // TO DO: Create a cool icon and use it here
135  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); 
136
137  // OpenGL stuff
138  // (Is this all we initialize globally???)
139  glClearColor(0.0, 0.0, 0.0, 0.0);
140  glEnable(GL_DEPTH_TEST);
141  glEnable(GL_COLOR);
142  glShadeModel(GL_FLAT);
143 
144  // create camera
145  localcamera = new Camera();
146 
147  return 0;
148}
149
150int Orxonox::init_sound () 
151{
152        printf("Not yet implemented\n");
153        return 0;
154}
155
156int Orxonox::init_input () 
157{
158        // create localinput
159        localinput = new CommandNode( configfilename);
160       
161        return 0;
162}
163
164
165int Orxonox::init_networking () 
166{
167        printf("Not yet implemented\n");
168        return 0;
169}
170
171int Orxonox::init_resources () 
172{
173        printf("Not yet implemented\n");
174        return 0;
175}
176
177int Orxonox::init_world () 
178{
179        world = new World();
180       
181        // TO DO: replace this with a menu/intro
182        world->load_debug_level();
183       
184        return 0;
185}
186
187void Orxonox::quitGame() 
188{
189        bQuitOrxonox = true;
190}
191void Orxonox::mainLoop()
192{
193        lastframe = SDL_GetTicks();
194        bQuitOrxonox = false;
195  // This is where everything is run
196printf("Orxonox|Entering main loop\n");
197  while( !bQuitOrxonox)
198  {
199        // Network
200        synchronize();
201    // Process input
202    handle_input();
203    // Process time
204    time_slice();
205    // Process collision
206    collision();
207    // Draw
208    display();
209  }
210printf("Orxonox|Exiting the main loop\n");
211}
212
213void Orxonox::event_handler (SDL_Event* event)
214{
215        // Handle special events such as reshape, quit, focus changes
216}
217
218void Orxonox::synchronize ()
219{
220        // Get remote input
221        // Update synchronizables
222}
223
224void Orxonox::handle_input ()
225{
226        // localinput
227                localinput->process();
228        // remoteinput
229}
230
231void Orxonox::time_slice ()
232{
233        Uint32 curframe = SDL_GetTicks();
234        if( !pause)
235        {
236                world->time_slice (curframe - lastframe);
237                world->update ();
238                localcamera->time_slice (curframe - lastframe);
239        }
240        lastframe = curframe;
241}
242
243void Orxonox::collision ()
244{
245        world->collide ();
246}
247
248bool Orxonox::system_command (Command* cmd)
249{
250        if( !strcmp( cmd->cmd, "quit") && !cmd->bUp)
251        {
252                bQuitOrxonox = true;
253                return true;
254        }
255        return false;
256}
257
258void Orxonox::display ()
259{
260                // clear buffer
261        glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
262                // set camera
263        localcamera->apply ();
264                // draw world
265        world->draw ();
266                // draw HUD
267                // flip buffers
268        SDL_GL_SwapBuffers();
269}
270
271Camera* Orxonox::get_camera ()
272{
273        return localcamera;
274}
275
276CommandNode* Orxonox::get_localinput ()
277{
278        return localinput;
279}
280
281World* Orxonox::get_world ()
282{
283        return world;
284}
285
286int main (int argc, char** argv) 
287{ 
288        printf(">>> Starting Orxonox <<<\n");
289  Orxonox *orx = Orxonox::getInstance();
290 
291  if( (*orx).init(argc, argv) == -1)
292  {
293    printf("! Orxonox initialization failed\n");
294    return -1;
295  }
296       
297  (*orx).mainLoop();
298 
299  return 0;
300}
Note: See TracBrowser for help on using the repository browser.