game_client.cpp

Go to the documentation of this file.
00001 /* MAINTAINER: Bernard CURRENT_EDITOR: Bernard */
00002 
00003 // #define WANT_TRACE
00004 
00005 #include "log.h"
00006 
00007 #include "tasksound.h"
00008 #include "taskrender.h"
00009 #include "tasksimulation.h"
00010 #include "taskapplyserverchanges.h"
00011 
00012 #include "game_client.h"
00013 
00014 #include "application_client.h"
00015 #include "font_manager.h"
00016 #include "thread.h"
00017 
00018 GameClient::GameClient(void):
00019         mActualCamera(0)
00020 {
00021         TIN
00022 }
00023  
00024 GameClient::~GameClient(void)
00025 {
00026         TIN
00027 }
00028 
00029 GameClient::GameClient(GameClient &copy)
00030 {
00031         TIN
00032         
00033         LOGE << "It is forbidden to make copy of GameClient." << endl;
00034         DIE();
00035 }
00036 
00037 /*
00038 Camera* GameClient::getCamera()
00039 { 
00040         TIN
00041 
00042         return *mActualCamera; 
00043 }
00044 */
00045 
00046 GameGUI& GameClient::getGUI()
00047 {
00048         return mGUI;
00049 }
00050 
00051 
00052 void GameClient::run()
00053 {
00054         TIN;
00055         
00056         recreateWorld();
00057         getWorld().getLandscape().getTerrain().initClient();
00058         
00059         // Everybody wants to have some fun.
00060         mEndFun = false;
00061         
00062         // Prepare tasks
00063         TaskSound               sound;
00064         TaskRender              render;
00065         TaskSimulation          simulation;
00066         TaskApplyServerChanges  applyServerChanges;
00067         
00068 
00069         mTaskManager.add(applyServerChanges);
00070         mTaskManager.add(simulation);
00071         mTaskManager.add(render);
00072         mTaskManager.add(sound);
00073                 
00074         mTaskManager.initTasks();
00075 
00076         // We also add font manager because font need clearing cache
00077         mTaskManager.add(getAppClient().getTaskManager());
00078 
00079         TPOINTS("Tasks Inicialized");
00080 
00081         // This is the main loop for client engine. How do you like it :-)
00082         InputManager &input = getAppClient().getInputManager();
00083         while (!mEndFun)
00084         {
00085                 mTaskManager.update();
00086 
00087                 // this may be in a different thread
00088                 input.checkSDLEvents();
00089                 input.processKeys();
00090 
00091                 //TODO: this could be as task in task manager
00092                 getAppClient().getCommander().processAllCommands(); 
00093 
00094                 // This is here for better multithread performance
00095                 Thread::reshedule();
00096         }
00097         
00098         mTaskManager.remove(getAppClient().getTaskManager());
00099         
00100         mTaskManager.cleanTasks();
00101 }
00102 
00103 void GameClient::init()
00104 {
00105         mGUI.init();
00106 }
00107 
00108 void GameClient::clean()
00109 {
00110         mGUI.clean();
00111 
00112         Game::clean();
00113 }
00114 
00115 Player * GameClient::getClientPlayer()
00116 {
00117         return 0;
00118 }
00119 
00120 Camera* GameClient::getCamera()
00121 {
00122         // temporary camera, until I don't get instance of Player's tank (to mTracer work correctly)
00123         // and until camera-switching system isn't implemented.
00124         static Camera tmp_camera(GLVector3d(128,128,100), GLVector3d(768, 768, 0), GLVector3d(0,0,1));
00125         static bool flag = false;
00126 
00127         if (!flag){
00128                 double 
00129                         w = getAppClient().getGFX().getWidth(),
00130                         h = getAppClient().getGFX().getHeight();
00131                 tmp_camera.setPerspective(60, w/h, 1, 2024);
00132                 flag = true;
00133         }
00134 
00135         return mActualCamera = &tmp_camera;
00136 }

Generated on Wed Apr 12 13:55:28 2006 for bjs by  doxygen 1.4.5