system.h

Go to the documentation of this file.
00001 
00002 //            Copyright (C) 2004-2007 by The Allacrost Project
00003 //                         All Rights Reserved
00004 //
00005 // This code is licensed under the GNU GPL version 2. It is free software
00006 // and you may modify it and/or redistribute it under the terms of this license.
00007 // See http://www.gnu.org/copyleft/gpl.html for details.
00009 
00023 #ifndef __SYSTEM_HEADER__
00024 #define __SYSTEM_HEADER__
00025 
00026 // #include "gettext.h"
00027 
00028 #include <set>
00029 
00030 #include "utils.h"
00031 #include "defs.h"
00032 
00033 #include "mode_manager.h"
00034 
00036 namespace hoa_system {
00037 
00043 const uint32 SYSTEM_INFINITE_TIME = 4294967295UL;
00044 
00049 const int32 SYSTEM_LOOP_INFINITE = -1;
00050 
00052 enum SYSTEM_TIMER_STATE {
00053   SYSTEM_TIMER_INVALID  = -1,
00054   SYSTEM_TIMER_INITIAL  =  0,
00055   SYSTEM_TIMER_RUNNING  =  1,
00056   SYSTEM_TIMER_PAUSED   =  2,
00057   SYSTEM_TIMER_FINISHED =  3,
00058   SYSTEM_TIMER_TOTAL    =  4
00059 };
00060 
00062 extern GameSystem* SystemManager;
00063 
00065 extern bool SYSTEM_DEBUG;
00066 
00068 namespace private_system {
00069 
00070 } // namespace private_system
00071 
00098 class SystemTimer {
00099   friend class GameSystem;
00100 
00101 public:
00102   SystemTimer();
00103 
00105   SystemTimer(uint32 duration, int32 number_loops = 0, hoa_mode_manager::GameMode* mode_owner = NULL) :
00106     _state(SYSTEM_TIMER_INITIAL) { Initialize(duration, number_loops, mode_owner); }
00107   
00108   ~SystemTimer();
00109 
00118   void Initialize(uint32 duration, int32 number_loops = 0, hoa_mode_manager::GameMode* mode_owner = NULL);
00119 
00121   void Reset()
00122     { if (_state != SYSTEM_TIMER_INVALID) { _state = SYSTEM_TIMER_INITIAL; _time_expired = 0; _times_completed = 0; } }
00123 
00125   void Run()
00126     { if (IsInitial() || IsPaused()) _state = SYSTEM_TIMER_RUNNING; }
00127 
00129   void Pause()
00130     { if (IsRunning()) _state = SYSTEM_TIMER_PAUSED; }
00131 
00133 
00134   bool IsInitial() const
00135     { return (_state == SYSTEM_TIMER_INITIAL); }
00136 
00137   bool IsRunning() const
00138     { return (_state == SYSTEM_TIMER_RUNNING); }
00139 
00140   bool IsPaused() const
00141     { return (_state == SYSTEM_TIMER_PAUSED); }
00142 
00143   bool IsFinished() const
00144     { return (_state == SYSTEM_TIMER_FINISHED); }
00146 
00152   void SetDuration(uint32 duration);
00153 
00154   void SetNumberLoops(int32 number_loops);
00155 
00156   void SetModeOwner(hoa_mode_manager::GameMode* mode_owner);
00158 
00160 
00161   SYSTEM_TIMER_STATE GetState() const
00162     { return _state; }
00163 
00164   uint32 GetDuration() const
00165     { return _duration; }
00166 
00167   int32 GetNumberLoops() const
00168     { return _number_loops; }
00169 
00170   hoa_mode_manager::GameMode* GetModeOwner() const
00171     { return _mode_owner; }
00172 
00173   uint32 GetTimeExpired() const
00174     { return _time_expired; }
00175 
00177   uint32 GetTimeLeft() const
00178     { return (_duration - _time_expired); }
00179 
00180   uint32 GetTimesCompleted() const
00181     { return _times_completed; }
00182 
00186   uint32 GetCurrentLoop() const
00187     { return _times_completed; }
00189 
00190 private:
00192   SYSTEM_TIMER_STATE _state;
00193 
00195   uint32 _duration;
00196 
00198   int32 _number_loops;
00199 
00201   hoa_mode_manager::GameMode* _mode_owner;
00202 
00204   uint32 _time_expired;
00205 
00207   uint32 _times_completed;
00208 
00213   void _UpdateTimer();
00214 }; // class SystemTimer
00215 
00216 
00226 class GameSystem : public hoa_utils::Singleton<GameSystem> {
00227   friend class hoa_utils::Singleton<GameSystem>;
00228   friend class SystemTimer;
00229 
00230 public:
00231   ~GameSystem();
00232 
00233   bool SingletonInitialize();
00234 
00239   void InitializeTimers();
00240 
00247   void UpdateTimers();
00248 
00254   void ExamineSystemTimers();
00255 
00265   uint32 GetUpdateTime() const
00266     { return _update_time; }
00267 
00275   void SetPlayTime(const uint8 h, const uint8 m, const uint8 s)
00276     { _hours_played = h; _minutes_played = m; _seconds_played = s; _milliseconds_played = 0; }
00277 
00282   uint8 GetPlayHours() const
00283     { return _hours_played; }
00284 
00285   uint8 GetPlayMinutes() const
00286     { return _minutes_played; }
00287 
00288   uint8 GetPlaySeconds() const
00289     { return _seconds_played; }
00291 
00295   std::string GetLanguage() const
00296     { return _language; }
00297 
00301   void SetLanguage(std::string lang);
00302 
00306   bool NotDone() const
00307     { return _not_done; }
00308 
00312   void ExitGame()
00313     { _not_done = false; }
00314 
00315 private:
00316   GameSystem();
00317 
00319   uint32 _last_update;
00321   uint32 _update_time;
00322 
00328   uint8 _hours_played;
00329   uint8 _minutes_played;
00330   uint8 _seconds_played;
00332   uint16 _milliseconds_played;
00334 
00336   bool _not_done;
00337 
00341   std::string _language;
00342 
00348   std::set<SystemTimer*> _system_timers;
00349 }; // class GameSystem : public hoa_utils::Singleton<GameSystem>
00350 
00351 } // namepsace hoa_system
00352 
00353 #endif

Generated on Fri Jul 6 23:11:24 2007 for Hero of Allacrost by  doxygen 1.5.1