CnC_Remastered_Collection

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

TIMER.CPP (10496B)


      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 : Temp timer for 32bit lib                 *
     21  *                                                                         *
     22  *                    File Name : TIMER.CPP                                *
     23  *                                                                         *
     24  *                   Programmer : Scott K. Bowen                           *
     25  *                                                                         *
     26  *                   Start Date : July 6, 1994                             *
     27  *                                                                         *
     28  *                  Last Update : May 3, 1995   [SKB]                      *
     29  *                                                                         *
     30  *-------------------------------------------------------------------------*
     31  * Functions:                                                              *
     32  *   TC::Time -- Return the time on the timer.                             *
     33  *   TC::TimerClass -- Construct a timer class object.                     *
     34  *   TC::Stop -- Stop the timer.                                           *
     35  *   TC::Start -- Start a timer.                                           *
     36  *   TC::Set -- Set the time of a timer.                                   *
     37  *   TC::Reset -- Clear the timer.                                         *
     38  *   TimerClass::Time -- Get the current time of timer.                    *
     39  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     40 
     41 #include <wwstd.h>
     42 #include "timer.H"
     43 #include <stdio.h>
     44 #include <stdlib.h>
     45 
     46 
     47 /////////////////////////////////////////////////////////////////////////////////
     48 /////////////////////////////////// Code ////////////////////////////////////////
     49 
     50 /***************************************************************************
     51  * TC::TIMERCLASS -- Construct a timer class object.                       *
     52  *                                                                         *
     53  *                                                                         *
     54  * INPUT:                                                                  *
     55  *                                                                         *
     56  * OUTPUT:                                                                 *
     57  *                                                                         *
     58  * WARNINGS:                                                               *
     59  *                                                                         *
     60  * HISTORY:                                                                *
     61  *   07/12/1994 SKB : Created.                                             *
     62  *=========================================================================*/
     63 TimerClass::TimerClass(BaseTimerEnum timer, BOOL on)
     64 {
     65 	Accumulated = 0;
     66 	Started = 0;
     67 
     68 	TickType=timer;
     69 
     70 	if (on && TimerSystemOn) Start();
     71 }
     72 
     73 
     74 
     75 
     76 /***********************************************************************************************
     77  * TC:Get_Ticks -- return the number of ticks on the system or user timers                     *
     78  *                                                                                             *
     79  *                                                                                             *
     80  *                                                                                             *
     81  * INPUT:    Nothing                                                                           *
     82  *                                                                                             *
     83  * OUTPUT:   tick count                                                                        *
     84  *                                                                                             *
     85  * WARNINGS: None                                                                              *
     86  *                                                                                             *
     87  * HISTORY:                                                                                    *
     88  *              10/5/95 4:17PM ST : Created                                                    *
     89  *=============================================================================================*/
     90 
     91 long TimerClass::Get_Ticks ( void )
     92 
     93 {
     94 	if ( WindowsTimer ){
     95 		switch ( TickType ){
     96 
     97 		 	case BT_SYSTEM :
     98 				return ( WindowsTimer->Get_System_Tick_Count() );
     99 
    100 		 	case BT_USER :
    101 				return ( WindowsTimer->Get_User_Tick_Count() );
    102 
    103 		}
    104 	}
    105 	return 0;
    106 }
    107 
    108 
    109 
    110 /***************************************************************************
    111  * TIMERCLASS::TIME -- Get the current time of timer.                      *
    112  *                                                                         *
    113  *                                                                         *
    114  *                                                                         *
    115  * INPUT:                                                                  *
    116  *                                                                         *
    117  * OUTPUT:                                                                 *
    118  *                                                                         *
    119  * WARNINGS:                                                               *
    120  *                                                                         *
    121  * HISTORY:                                                                *
    122  *   05/03/1995 SKB : Created.                                             *
    123  *=========================================================================*/
    124 long TimerClass::Time(void)
    125 {
    126 	if (Started) {
    127 		long ticks = Get_Ticks();
    128 		Accumulated += ticks - (Started-1);
    129 		Started = ticks+1;
    130 	}
    131 	return(Accumulated);
    132 }
    133 
    134 
    135 /***************************************************************************
    136  * TC::STOP -- Stop the timer.                                             *
    137  *                                                                         *
    138  *                                                                         *
    139  *                                                                         *
    140  * INPUT:                                                                  *
    141  *                                                                         *
    142  * OUTPUT:                                                                 *
    143  *                                                                         *
    144  * WARNINGS:                                                               *
    145  *                                                                         *
    146  * HISTORY:                                                                *
    147  *   07/12/1994 SKB : Created.                                             *
    148  *=========================================================================*/
    149 long TimerClass::Stop(void)
    150 {
    151 	long time = Time();
    152 	Started = 0;
    153 	return(time);
    154 }
    155 
    156 
    157 /***************************************************************************
    158  * TC::START -- Start a timer.                                             *
    159  *                                                                         *
    160  *                                                                         *
    161  * INPUT:                                                                  *
    162  *                                                                         *
    163  * OUTPUT:                                                                 *
    164  *                                                                         *
    165  * WARNINGS:                                                               *
    166  *                                                                         *
    167  * HISTORY:                                                                *
    168  *   07/12/1994 SKB : Created.                                             *
    169  *=========================================================================*/
    170 long TimerClass::Start(void)
    171 {
    172 	if (!Started) {
    173 		Started = Get_Ticks()+1;
    174 	}
    175 	return(Time());
    176 }
    177 
    178 
    179 /***************************************************************************
    180  * TC::SET -- Set the time of a timer.                                     *
    181  *                                                                         *
    182  *                                                                         *
    183  *                                                                         *
    184  * INPUT:  long value to set timer at.                                     *
    185  *                                                                         *
    186  * OUTPUT:                                                                 *
    187  *                                                                         *
    188  * WARNINGS:                                                               *
    189  *                                                                         *
    190  * HISTORY:                                                                *
    191  *   07/12/1994 SKB : Created.                                             *
    192  *   05/03/1995 SKB : If start return Start since it returns Time          *
    193  *=========================================================================*/
    194 long TimerClass::Set(long value, BOOL start)
    195 {
    196 	Started = 0;
    197 	Accumulated = value;
    198 	if (start) return (Start());
    199 	return(Time());
    200 }