Main Page | Namespace List | Class List | File List | Class Members | File Members

main.cpp

Go to the documentation of this file.
00001 #include <ClanLib/core.h>
00002 #include <ClanLib/gui.h>
00003 #include <ClanLib/gl.h>
00004 #include <ClanLib/guistylesilver.h>
00005 #include <ClanLib/application.h>
00006 #include <ClanLib/display.h>
00007 #include <ClanLib/sound.h>
00008 
00009 #include <iostream>
00010 using namespace std;
00011 
00012 #include "gamestate.h"
00013 #include "gui.h"
00014 #include "scene.h"
00015 
00016 #define CL_MODULES( func )   \
00017     CL_SetupCore::func();    \
00018     CL_SetupSound::func();   \
00019     CL_SetupDisplay::func(); \
00020     CL_SetupGL::func();      \
00021     CL_SetupGUI::func()
00022 
00023 class AP : public CL_ClanApplication {
00024 public:
00025     virtual int main(int argc, char** argv)
00026     {
00027         // Create a console window for text-output if not available
00028         CL_ConsoleWindow console("Console", 80, 10000 );
00029         console.redirect_stdio();
00030 
00031         try {
00032             cout << "Initializing ClanLib..." << endl;
00033 
00034             CL_MODULES( init );
00035 
00036             CL_SoundOutput output( 44100 );
00037             output.set_global_volume( 100 );
00038 
00039             cout << "Creating GameState..." << endl;
00040 
00041             game_state = new GameState();
00042 
00043             cout << "Creating GUI..." << endl;
00044 
00045             gui = new GUI();
00046 
00047             cout << "Adding Resources..." << endl;
00048 
00049             if( gui->add_resources( "resources/gui/GUIStyleSilver/gui.xml" ) < 0 )
00050                 return -1;
00051 
00052             if( gui->add_resources( "resources/gui/gui.xml" ) < 0 )
00053                 return -1;
00054 
00055             cout << "Initializing GUI..." << endl;
00056 
00057             if( gui->initialize( game_state ) < 0 )
00058                 return -1;
00059 
00060             cout << "Registering GUI signals..." << endl;
00061 
00062             if( gui->register_signals() < 0 )
00063                 return -1;
00064 
00065             cout << "Creating SceneManager..." << endl;
00066 
00067             scene_manager = new SceneManager( gui->get_gc(), game_state );
00068 
00069             cout << "Registering SceneManager signals..." << endl;
00070 
00071             if( scene_manager->register_signals() < 0 )
00072                 return -1;
00073 
00074             cout << "Entering Game Loop..." << endl;
00075 
00076             last_tick = CL_System::get_time();
00077 
00078             while( !gui->quit() )
00079             {
00080                 cur_tick = CL_System::get_time();
00081 //                double t = double(cur_tick - last_tick) / 1000.0; 
00082 
00083                 game_state->tick( 0.01 );
00084 
00085                 scene_manager->tick( 0.01 );
00086 
00087                 last_tick = cur_tick;
00088 
00089                 scene_manager->render();
00090 
00091                 gui->render();
00092 
00093                 CL_Display::flip();
00094                 CL_System::keep_alive( 10 );
00095             }
00096 
00097             gui->finish();
00098 
00099             dCloseODE();
00100 
00101             CL_MODULES( deinit );
00102         }
00103         catch ( CL_Error e ) {
00104             cout << e.message << endl;
00105 
00106             // Display console close message and wait for a key
00107             console.display_close_message();
00108         }
00109 
00110         return 0;
00111     }
00112 
00113 private:
00114 
00115     GameState* game_state;
00116 
00117     GUI* gui;
00118 
00119     SceneManager* scene_manager;
00120 
00121     int last_tick, cur_tick;
00122 
00123 } app;

Generated on Sat Mar 13 14:58:32 2004 for Ars Physica by doxygen 1.3.5