Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2068 was 2068, checked in by chris, 21 years ago

orxonox/branches/chris: First snippet of the totally revamped base system… perhaps a bit confusing at the moment, but when finished theoretically you only have to subclass the worldentity and track classes to create the game content (even the menu will be a WorldEntity I suppose)

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#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        strcat (configfilename, "/.orxonox.conf");
90}
91
92int Orxonox::init (int argc, char** argv)
93{
94                // parse command line
95                // config file
96               
97        get_config_file (argc, argv);
98       
99                // initialize SDL
100  printf("> Initializing SDL\n");
101  if( SDL_Init (SDL_INIT_EVERYTHING) == -1)
102  {
103    printf ("Could not SDL_Init(): %s\n", SDL_GetError());
104    return -1;
105  }
106 
107        // initialize everything
108  printf("> Initializing video\n");
109        if( init_video () == -1) return -1;
110  printf("> Initializing sound\n");
111        if( init_sound () == -1) return -1;
112  printf("> Initializing input\n");
113        if( init_input () == -1) return -1;
114  printf("> Initializing networking\n");
115        if( init_networking () == -1) return -1;
116  printf("> Initializing resources\n");
117        if( init_resources () == -1) return -1;
118  printf("> Initializing world\n");
119        if( init_world () == -1) return -1;
120       
121        return 0;
122}
123
124int Orxonox::init_video () 
125{
126  // Set video mode
127  // TO DO: parse arguments for settings
128  SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 5);
129  SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 5);
130  SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 5);
131  SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
132 
133  int bpp = 16;
134  int width = 640;
135  int height = 480;
136  Uint32 flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
137 
138  if( (screen = SDL_SetVideoMode (width, height, bpp, flags)) == NULL)
139  {
140    printf ("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", width, height, bpp, flags, SDL_GetError());
141    SDL_Quit();
142    return -1;
143  }
144 
145  // Set window labeling
146  // TO DO: Add version information to caption
147  SDL_WM_SetCaption( "Orxonox", "Orxonox");
148 
149  // TO DO: Create a cool icon and use it here
150  // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); 
151
152  // OpenGL stuff
153  // (Is this all we initialize globally???)
154  glClearColor(0.0, 0.0, 0.0, 0.0);
155  glEnable(GL_DEPTH_TEST);
156  glShadeModel(GL_FLAT);
157 
158  // create camera
159  localcamera = new Camera();
160 
161  return 0;
162}
163
164int Orxonox::init_sound () 
165{
166        printf("Not yet implemented\n");
167        return 0;
168}
169
170int Orxonox::init_input () 
171{
172        // create localinput
173        localinput = new CommandNode( configfilename);
174       
175        return 0;
176}
177
178
179int Orxonox::init_networking () 
180{
181        printf("Not yet implemented\n");
182        return 0;
183}
184
185int Orxonox::init_resources () 
186{
187        printf("Not yet implemented\n");
188        return 0;
189}
190
191int Orxonox::init_world () 
192{
193        printf("Not yet implemented\n");
194        return 0;
195}
196
197void Orxonox::quitGame() 
198{
199        bQuitOrxonox = true;
200  //cout << "finished garbage colletion, quitting..." << endl;
201}
202void Orxonox::mainLoop()
203{
204  // This is where everything is run
205  while( !bQuitOrxonox)
206  {
207        // Network
208        synchronize();
209    // Process input
210    handle_input();
211    // Process time
212    time_slice();
213    // Process collision
214    collision();
215    // Draw
216    display();
217  }
218}
219
220void Orxonox::event_handler (SDL_Event* event)
221{
222        // Handle special events such as reshape, quit, focus changes
223}
224
225void Orxonox::synchronize ()
226{
227        // Get remote input
228        // Update synchronizables
229}
230
231void Orxonox::handle_input ()
232{
233        // localinput
234                localinput.process();
235        // remoteinput
236}
237
238void Orxonox::time_slice ()
239{
240        Uint32 curframe = SDL_GetTicks();
241        if( !pause)
242        {
243                world->time_slice (curframe - lastframe);
244                world->update ();
245                localcamera->time_slice (curframe - lastframe);
246        }
247        lastframe = curframe;
248}
249
250void Orxonox::collision ()
251{
252        world->collide ();
253}
254
255void Orxonox::display ()
256{
257                // clear buffer
258        glClear( GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT);
259                // set camera
260        localcamera->apply ();
261                // draw world
262        world->draw ();
263                // draw HUD
264                // flip buffers
265        SDL_Flip( screen);
266}
267
268Camera* Orxonox::get_camera ()
269{
270        return localcamera;
271}
272
273Camera* Orxonox::get_world ()
274{
275        return world;
276}
277
278int main (int argc, char** argv) 
279{ 
280  Orxonox *orx = Orxonox::getInstance();
281 
282  if( (*orx).init(argc, argv) == -1)
283  {
284    printf("! Orxonox initialization failed\n");
285    return -1;
286  }
287
288        lastframe = SDL_GetTicks();
289       
290  (*orx).mainLoop();
291 
292  return 0;
293}
Note: See TracBrowser for help on using the repository browser.