7 years
edited 7 years
Game Clock
It allows you format the time and get the elapsed time.
1 //! zinc2 library GameClock { /* v1.0.0.7
3 *************************************************************************************4 *5 * Game Clock6 * by nel7 *8 * It allows you format the time and get the elapsed time.9 *10 ************************************************************************************11 *12 * SETTING13 *14 */15 private constant string DELIMITER = " : "; /* It used to seperate the hour,
16 minute, and second */17 /*18 ************************************************************************************19 *20 * struct GameClock extends array21 *22 * static method FormatTime takes real seconds return string23 * - It returns time as hh/mm/ss format.24 *25 * static method operator ElapsedTime takes nothing returns real26 * - It returns elapsed time.27 *28 * static method operator ElapsedTimeEx takes nothing returns string29 * - It returns elapsed time as hh/mm/ss format.30 *31 * static method operator Delimiter takes nothing returns string32 * - It returns GameClock's delimiter.33 *34 *************************************************************************************35 *36 * Issue:37 *38 * This library will not give you an exact current elapsed time.39 *40 ************************************************************************************/41 42 //! textmacro GAMECLOCK_TIMEFORMAT takes Time, delimiter43 if( $Time$ < 10 ) {
44 format = format + "0" + I2S( $Time$ ) $delimiter$;
45 } else {46 format = format + I2S( $Time$ ) $delimiter$;
47 }
48 //! endtextmacro49 50 private constant timer TIMER = CreateTimer();
51 52 public { struct GameClock [] {
53 public {54 static method FormatTime( real seconds ) -> string {
55 integer s = R2I( ModuloReal( seconds, 60 ) );
56 integer m = R2I( ModuloReal( seconds, 3600 ) / 60 );
57 integer h = R2I( seconds / 3600 );
58 string format = "";
59 60 //! runtextmacro GAMECLOCK_TIMEFORMAT( "h", "+ DELIMITER" )61 //! runtextmacro GAMECLOCK_TIMEFORMAT( "m", "+ DELIMITER" )62 //! runtextmacro GAMECLOCK_TIMEFORMAT( "s", "" )63 64 return format;65 }
66 67 static method operator ElapsedTime() -> real {
68 return TimerGetElapsed( TIMER );
69 }
70 71 static method operator ElapsedTimeEx() -> string {
72 return thistype.FormatTime( TimerGetElapsed(TIMER) );
73 }
74 75 static method operator Delimiter() -> string {
76 return DELIMITER;77 }
78 }
79 80 private static method onInit() {
81 TimerStart( TIMER, 100000000, true, null );
82 }
83 }}
84 }
85 //! endzinc
