newspeoplefor developersdocumentationdownloads

app.h

Go to the documentation of this file.
00001 #ifndef APPLICATION_APP_H
00002 #define APPLICATION_APP_H
00003 //------------------------------------------------------------------------------
00018 #include "foundation/refcounted.h"
00019 #include "foundation/ptr.h"
00020 #include "gfx2/ndisplaymode2.h"
00021 #include "foundation/server.h"
00022 #include "message/server.h"
00023 #include "graphics/server.h"
00024 #include "audio/server.h"
00025 #include "physics/server.h"
00026 #include "input/server.h"
00027 #include "loader/server.h"
00028 #include "navigation/server.h"
00029 #include "game/server.h"
00030 #include "vfx/server.h"
00031 #include "db/server.h"
00032 #include "ui/server.h"
00033 #include "ceui/server.h"
00034 #include "script/server.h"
00035 #include "tools/ncmdlineargs.h"
00036 #include "util/nstartupchecker.h"
00037 
00038 #define MANGALORE_USE_CEGUI
00039 
00040 //------------------------------------------------------------------------------
00041 namespace Application
00042 {
00043 class StateHandler;
00044 
00045 class App
00046 {
00047 public:
00049     App();
00051     virtual ~App();
00053     static App* Instance();
00054 
00056     void SetCmdLineArgs(const nCmdLineArgs& args);
00058     const nCmdLineArgs& GetCmdLineArgs() const;
00060     virtual bool Open();
00062     virtual void Close();
00064     bool IsOpen() const;
00066     virtual void Run();
00067 
00069     virtual nString GetAppName() const;
00071     virtual nString GetAppVersion() const;
00073     virtual nString GetVendorName() const;
00075     virtual bool GetForceFullscreen() const;
00076 
00078     const nString& GetProjectDirectory() const;
00080     const nDisplayMode2& GetDisplayMode() const;
00082     const nString& GetStartupLevel() const;
00083     // get startup save game
00084     const nString& GetStartupSavegame() const;
00086     const nString& GetFeatureSet() const;
00088     const nString& GetRenderPath() const;
00089 
00091     void AddStateHandler(StateHandler* state);
00093     StateHandler* FindStateHandlerByName(const nString& stateName) const;
00095     StateHandler* FindStateHandlerByRtti(const Foundation::Rtti& rtti) const;
00097     StateHandler* GetCurrentStateHandler() const;
00099     const nString& GetCurrentState() const;
00101     int GetNumStates() const;
00103     StateHandler* GetStateHandlerAt(int index) const;
00105     void RequestState(const nString& stateName);
00106 
00108     nTime GetTime() const;
00110     nTime GetFrameTime() const;
00112     nTime GetStateTime() const;
00114     void SetTimeFactor(float f);
00116     float GetTimeFactor() const;
00118     virtual void SetPaused(bool b);
00120     bool IsPaused() const;
00121 
00123     void StartFrameCapture();
00125     void StopFrameCapture();
00127     bool IsCapturing() const;
00128 
00129 protected:
00131     virtual void OnFrame();
00133     virtual bool DoStartupCheck();
00135     virtual void SetupFromDefaults();
00137     virtual void SetupFromCmdLineArgs();
00139     virtual void SetupFromProfile();
00141     virtual void SetupGameSubsystem();
00143     virtual void CleanupGameSubsystem();
00145     virtual void SetupSubsystems();
00147     virtual void CleanupSubsystems();
00149     virtual void SetupStateHandlers();
00151     virtual void CleanupStateHandlers();
00153     virtual void DoStateTransition();
00155     void SetState(const nString& s);
00157     void UpdateTimes();
00159     void SetProjectDirectory(const nString& dir);
00161     void SetDisplayMode(const nDisplayMode2& mode);
00163     void SetStartupLevel(const nString& path);
00164     // set startup save game
00165     void SetStartupSavegame(const nString& savegame);
00167     void SetFeatureSet(const nString& s);
00169     void SetRenderPath(const nString& s);
00170 
00171     static App* Singleton;
00172 
00173     Foundation::Server* foundationServer;
00174     Ptr<Game::Server> gameServer;
00175     Ptr<Graphics::Server> graphicsServer;
00176     Ptr<Physics::Server> physicsServer;
00177     Ptr<Input::Server> inputServer;
00178     Ptr<Loader::Server> loaderServer;
00179     Ptr<Message::Server> messageServer;
00180     Ptr<Audio::Server> audioServer;
00181     Ptr<Navigation::Server> navigationServer;
00182     Ptr<VFX::Server> vfxServer;
00183     Ptr<Db::Server> dbServer;
00184     Ptr<UI::Server> uiServer;
00185 #ifdef MANGALORE_USE_CEGUI
00186     Ptr<CEUI::Server> ceuiServer;
00187 #endif
00188     Ptr<Script::Server> scriptServer;
00189 
00190     nStartupChecker startupChecker;
00191     nCmdLineArgs cmdLineArgs;
00192     nString projDir;
00193     nString startupLevel;
00194     nString startupSavegame;
00195     nString featureSet;
00196     nString renderPath;
00197     nDisplayMode2 displayMode;
00198     bool isOpen;
00199     bool isRunning;
00200     bool isPaused;
00201 
00202     nTime time;                         // current time
00203     nTime stateTime;                    // time since in state
00204     nTime frameTime;                    // current frame time
00205     nTime pauseTime;                    // time stamp when pause has started
00206     nTime stateTransitionTimeStamp;     // time stamp of last state transition
00207     nTime lastRealTime;                 // last realtime stamp
00208 
00209     float timeFactor;                   // the time factor, to slow down or speed up gametime
00210 
00211     nString requestedState;
00212     nString curState;
00213     nString nextState;
00214     nArray<Ptr<StateHandler> > stateHandlers;
00215 };
00216 
00217 //------------------------------------------------------------------------------
00220 inline
00221 App*
00222 App::Instance()
00223 {
00224     n_assert(0 != App::Singleton);
00225     return App::Singleton;
00226 }
00227 
00228 //------------------------------------------------------------------------------
00231 inline
00232 bool
00233 App::IsPaused() const
00234 {
00235     return this->isPaused;
00236 }
00237 
00238 //------------------------------------------------------------------------------
00241 inline
00242 int
00243 App::GetNumStates() const
00244 {
00245     return this->stateHandlers.Size();
00246 }
00247 
00248 //------------------------------------------------------------------------------
00251 inline
00252 StateHandler*
00253 App::GetStateHandlerAt(int index) const
00254 {
00255     return this->stateHandlers[index];
00256 }
00257 
00258 //------------------------------------------------------------------------------
00263 inline
00264 const nString&
00265 App::GetCurrentState() const
00266 {
00267     return this->curState;
00268 }
00269 
00270 //------------------------------------------------------------------------------
00273 inline
00274 void
00275 App::SetProjectDirectory(const nString& dir)
00276 {
00277     this->projDir = dir;
00278 }
00279 
00280 //------------------------------------------------------------------------------
00283 inline
00284 const nString&
00285 App::GetProjectDirectory() const
00286 {
00287     return this->projDir;
00288 }
00289 
00290 //------------------------------------------------------------------------------
00293 inline
00294 void
00295 App::SetDisplayMode(const nDisplayMode2& mode)
00296 {
00297     this->displayMode = mode;
00298 }
00299 
00300 //------------------------------------------------------------------------------
00303 inline
00304 const nDisplayMode2&
00305 App::GetDisplayMode() const
00306 {
00307     return this->displayMode;
00308 }
00309 
00310 //------------------------------------------------------------------------------
00313 inline
00314 void
00315 App::SetStartupLevel(const nString& l)
00316 {
00317     this->startupLevel = l;
00318 }
00319 
00320 //------------------------------------------------------------------------------
00323 inline
00324 const nString&
00325 App::GetStartupLevel() const
00326 {
00327     return this->startupLevel;
00328 }
00329 
00330 //------------------------------------------------------------------------------
00333 inline
00334 nTime
00335 App::GetTime() const
00336 {
00337     return this->time;
00338 }
00339 
00340 //------------------------------------------------------------------------------
00343 inline
00344 nTime
00345 App::GetFrameTime() const
00346 {
00347     return this->frameTime;
00348 }
00349 
00350 //------------------------------------------------------------------------------
00353 inline
00354 nTime
00355 App::GetStateTime() const
00356 {
00357     return this->stateTime;
00358 }
00359 
00360 //------------------------------------------------------------------------------
00363 inline
00364 float
00365 App::GetTimeFactor() const
00366 {
00367     return this->timeFactor;
00368 }
00369 
00370 //------------------------------------------------------------------------------
00373 inline
00374 void
00375 App::SetTimeFactor(float f)
00376 {
00377     if (f < 0.125f) f = 0.125f; // 1/8
00378     else if (f > 4.0f) f = 4.0f;
00379     this->timeFactor = f;
00380 }
00381 
00382 //------------------------------------------------------------------------------
00385 inline
00386 void
00387 App::SetFeatureSet(const nString& s)
00388 {
00389     this->featureSet = s;
00390 }
00391 
00392 //------------------------------------------------------------------------------
00395 inline
00396 const nString&
00397 App::GetFeatureSet() const
00398 {
00399     return this->featureSet;
00400 }
00401 
00402 //------------------------------------------------------------------------------
00405 inline
00406 void
00407 App::SetRenderPath(const nString& s)
00408 {
00409     this->renderPath = s;
00410 }
00411 
00412 //------------------------------------------------------------------------------
00415 inline
00416 const nString&
00417 App::GetRenderPath() const
00418 {
00419     return this->renderPath;
00420 }
00421 
00422 //------------------------------------------------------------------------------
00425 inline
00426 void
00427 App::SetStartupSavegame(const nString& n)
00428 {
00429     this->startupSavegame = n;
00430 }
00431 
00432 //------------------------------------------------------------------------------
00435 inline
00436 const nString&
00437 App::GetStartupSavegame() const
00438 {
00439     return this->startupSavegame;
00440 }
00441 
00442 //------------------------------------------------------------------------------
00445 inline
00446 bool
00447 App::IsOpen() const
00448 {
00449     return this->isOpen;
00450 }
00451 
00452 //------------------------------------------------------------------------------
00455 inline
00456 void
00457 App::SetCmdLineArgs(const nCmdLineArgs& args)
00458 {
00459     this->cmdLineArgs = args;
00460 }
00461 
00462 //------------------------------------------------------------------------------
00465 inline
00466 const nCmdLineArgs&
00467 App::GetCmdLineArgs() const
00468 {
00469     return this->cmdLineArgs;
00470 }
00471 
00472 };
00473 //------------------------------------------------------------------------------
00474 #endif

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.