CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

TIMER.H (6795B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /***************************************************************************
     17  **     C O N F I D E N T I A L --- W E S T W O O D   S T U D I O S       **
     18  ***************************************************************************
     19  *                                                                         *
     20  *                 Project Name : Timer Class Functions                    *
     21  *                                                                         *
     22  *                    File Name : TIMER.H                                  *
     23  *                                                                         *
     24  *                   Programmer : Scott K. Bowen                           *
     25  *                                                                         *
     26  *                   Start Date : July 6, 1994                             *
     27  *                                                                         *
     28  *                  Last Update : July 12, 1994   [SKB]                    *
     29  *                                                                         *
     30  *-------------------------------------------------------------------------*
     31  * Functions:                                                              *
     32  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     33 
     34 #ifndef TIMER_H
     35 #define TIMER_H
     36 
     37 
     38 #ifndef WIN32
     39 #define WIN32 1
     40 #ifndef _WIN32 // Denzil 6/2/98 Watcom 11.0 complains without this check
     41 #define _WIN32
     42 #endif // _WIN32
     43 #endif
     44 #include <windows.h>
     45 #include <windowsx.h>
     46 
     47 /*=========================================================================*/
     48 /* The following prototypes are for the file: TIMERA.ASM							*/
     49 /*=========================================================================*/
     50 
     51 //////////////////////////////////////////////////////////////////////////////////////////////
     52 //////////////////////////////////////// Externs /////////////////////////////////////////////
     53 extern BOOL 		TimerSystemOn;
     54 extern	HANDLE	TimerThreadHandle;		//Handle of timer thread
     55 extern	int		InTimerCallback;			//true if we are currently in a callback
     56 
     57 
     58 /*=========================================================================*/
     59 typedef enum BaseTimerEnum {
     60 	BT_SYSTEM,			// System timer (60 / second).
     61 	BT_USER				// User controllable timer (? / second).
     62 } BaseTimerEnum;
     63 
     64 class TimerClass {
     65  	public:
     66 		// Constructor.  Timers set before low level init has been done will not
     67 		// be able to be 'Started' or 'on' until timer system is in place.
     68 		TimerClass(BaseTimerEnum timer=BT_SYSTEM, BOOL start=FALSE);
     69 
     70 		// No destructor.
     71 		~TimerClass(void){}
     72 
     73 		//
     74 		long Set(long value, BOOL start=TRUE);	// Set initial timer value.
     75 		long Stop(void);				// Pause timer.
     76 		long Start(void);				// Resume timer.
     77 		long Reset(BOOL start=TRUE);	// Reset timer to zero.
     78 		long Time(void);				// Fetch current timer value.
     79 
     80 	protected:
     81 		long Started;					// Time last started (0 == not paused).
     82 		long Accumulated;				//	Total accumulated ticks.
     83 
     84 	private:
     85 //		long (*Get_Ticks)(void);	// System timer fetch.
     86 		BaseTimerEnum	TickType;
     87 		long Get_Ticks (void);
     88 };
     89 
     90 
     91 inline long TimerClass::Reset(BOOL start)
     92 {
     93 	return(Set(0, start));
     94 }
     95 
     96 
     97 class CountDownTimerClass : private TimerClass {
     98 	public:
     99 		// Constructor.  Timers set before low level init has been done will not
    100 		// be able to be 'Started' or 'on' until timer system is in place.
    101 		CountDownTimerClass(BaseTimerEnum timer, long set, int on=FALSE);
    102 		CountDownTimerClass(BaseTimerEnum timer=BT_SYSTEM, int on=FALSE);
    103 
    104 		// No destructor.
    105 		~CountDownTimerClass(void){}
    106 
    107 		// Public functions
    108 		long Set(long set, BOOL start=TRUE);	// Set count down value.
    109 		long Reset(BOOL start=TRUE);	// Reset timer to zero.
    110 		long Stop(void);			// Pause timer.
    111 		long Start(void);			// Resume timer.
    112 		long Time(void);			// Fetch current count down value.
    113 
    114 	protected:
    115 		long DelayTime;			// Ticks remaining before countdown timer expires.
    116 };
    117 
    118 inline long CountDownTimerClass::Stop(void)
    119 {
    120 	TimerClass::Stop();
    121 	return(Time());
    122 }
    123 
    124 inline long CountDownTimerClass::Start(void)
    125 {
    126 	TimerClass::Start();
    127 	return(Time());
    128 }
    129 
    130 inline long CountDownTimerClass::Reset(BOOL start)
    131 {
    132 	return (TimerClass::Reset(start));
    133 }
    134 
    135 
    136 
    137 
    138 class WinTimerClass {
    139 
    140 	public:
    141 		WinTimerClass ( UINT freq=60 , BOOL partial=0 );
    142 		~WinTimerClass();
    143 
    144 		void 		Update_Tick_Count ( void );
    145 		unsigned	Get_System_Tick_Count ( void );
    146 		unsigned	Get_User_Tick_Count ( void );
    147 
    148 	private:
    149 
    150 		unsigned		TimerHandle;	//Handle for windows timer event
    151 		unsigned		Frequency;		//Frequency of our windows timer in ticks per second
    152 
    153 		unsigned		TrueRate;		//True rate of clock. (only use word)
    154 		unsigned		SysTicks;		//Tick count of timer.
    155 		unsigned		UserTicks;		//Tick count of timer.
    156 		unsigned		UserRate;		//Desired rate of timer.
    157 
    158 
    159 };
    160 
    161 
    162 extern	WinTimerClass	*WindowsTimer;
    163 
    164 
    165 
    166 
    167 
    168 
    169 
    170 
    171 //////////////////////////////////////////////////////////////////////////////////////////////
    172 //////////////////////////////////////// externs  //////////////////////////////////////////
    173 #ifndef FUNCTION_H
    174 extern TimerClass					TickCount;
    175 #endif
    176 extern CountDownTimerClass		CountDown;
    177 
    178 //////////////////////////////////////////////////////////////////////////////////////////////
    179 //////////////////////////////////////// Prototypes //////////////////////////////////////////
    180 
    181 extern "C" {
    182 	long __cdecl Get_System_Tick_Count(void);
    183 	long __cdecl Get_User_Tick_Count(void);
    184 	void far __cdecl Timer_Interrupt_Func(void);
    185 //	long Get_Num_Interrupts(unsigned int realmode);
    186 	void __cdecl Disable_Timer_Interrupt(void);
    187 	void __cdecl Enable_Timer_Interrupt(void);
    188 }
    189 
    190 /*=========================================================================*/
    191 /* The following prototypes are for the file: TIMER.CPP							*/
    192 /*=========================================================================*/
    193 BOOL __cdecl Init_Timer_System(unsigned int freq, int partial = FALSE);
    194 BOOL __cdecl Remove_Timer_System(VOID);
    195 
    196 
    197 #endif // TIMER_H
    198