Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/chris: Implemented basic track and spawning functionality. Added a function to convert a Rotation into a glmatrix. Implemented operator* in Rotation. Refined World, made World friend class of world_entity. Implemented camera functionality (can now be bound to the worldentity it should focus on).

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