00001 // 00002 // Copyright (c) 2000 by Tech Soft 3D, LLC. 00003 // The information contained herein is confidential and proprietary to 00004 // Tech Soft 3D, LLC., and considered a trade secret as defined under 00005 // civil and criminal statutes. Tech Soft 3D shall pursue its civil 00006 // and criminal remedies in the event of unauthorized use or misappropriation 00007 // of its trade secrets. Use of this information by anyone other than 00008 // authorized employees of Tech Soft 3D, LLC. is granted only under a 00009 // written non-disclosure agreement, expressly prescribing the scope and 00010 // manner of such use. 00011 // 00012 // $Id$ 00013 // 00014 00019 #ifndef _H_HT_MANAGER_H 00020 #define _H_HT_MANAGER_H 00021 00022 #ifdef H_PACK_8 00023 #pragma pack(push) 00024 #pragma pack(8) 00025 #endif 00026 00027 00028 #include "HTools.h" 00029 00030 class HTClient; 00031 class HTDriver; 00032 00055 class MVO_API HTManager 00056 { 00057 public: 00061 HTManager( int output_hz = 100 ); 00062 virtual ~HTManager(); 00063 00067 virtual void Tick( float time ); 00071 void RegisterClient( HTClient *c ); 00075 void UnRegisterClient( HTClient *c ); 00077 static HTManager *GetCurrentHTManager(); 00078 00079 protected: 00080 double m_interval; 00081 double m_request_time; 00082 double m_actual_time; 00083 int m_output_hz; 00084 struct vlist_s **m_buckets; 00085 int m_current_bucket; 00086 struct vlist_s *m_spillover; 00087 struct vhash_s *m_active_clients; 00088 struct vlist_s *m_recently_deleted_expirations; 00089 struct vlist_s *m_recently_deleted_clients; 00090 00095 void Init( float start_time ); 00101 void ScheduleNextTick( HTClient *c, float time ); 00102 }; 00103 00107 enum HTCStyle { 00108 HTCS_Invalid, 00109 HTCS_Once, 00110 HTCS_Periodic, 00111 HTCS_PeriodicSkip 00112 }; 00113 00115 typedef bool(*HTClientTickFunction)(float request_time, float actual_time, void * user_data); 00116 00162 class MVO_API HTClient 00163 { 00164 public: 00173 HTClient( float interval = 0.1f, 00174 HTCStyle style = HTCS_Invalid, 00175 HTClientTickFunction tick_function = 0, 00176 void* user_data = 0 ) { 00177 mt_interval = interval; 00178 mt_style = style; 00179 mt_next_request = 0; 00180 mt_priority = 0; 00181 mt_tick_function = tick_function; 00182 mt_user_data = user_data; 00183 } 00184 virtual ~HTClient(); 00185 00191 virtual bool Tick( float request_time, float actual_time ){ 00192 if( mt_tick_function ) 00193 return mt_tick_function(request_time, actual_time, mt_user_data); 00194 else 00195 return true; 00196 }; 00197 00200 void SetInterval( float interval ) { mt_interval = interval; }; 00201 00203 float GetInterval() const { return mt_interval; }; 00204 00209 void SetStyle( HTCStyle style ) { mt_style = style; }; 00210 00212 HTCStyle GetStyle() const { return mt_style; }; 00213 00217 void SetNextRequest( float nr ) { mt_next_request = nr; }; 00218 00220 float GetNextRequest() const { return mt_next_request; }; 00221 00225 int GetPriority() const { return mt_priority; }; 00226 00230 void SetPriorityLowest() { mt_priority = -1; }; 00231 00235 void SetUserData( void* user_data ) { mt_user_data = user_data; }; 00236 00238 void* GetUserData() const { return mt_user_data; }; 00239 00243 void SetTickFunction( HTClientTickFunction tick_function) { mt_tick_function = tick_function; }; 00244 00246 HTClientTickFunction GetTickFunction() const { return mt_tick_function; }; 00247 00248 protected: 00250 HTCStyle mt_style; 00251 00255 float mt_interval; 00256 00258 float mt_next_request; 00259 00263 int mt_priority; 00264 00266 void* mt_user_data; 00267 00270 HTClientTickFunction mt_tick_function; 00271 }; 00272 00273 00274 00275 #ifdef H_PACK_8 00276 #pragma pack(pop) 00277 #endif 00278 00279 #endif 00280 00281 00282 00283