-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw_timer.cpp
78 lines (65 loc) · 2.1 KB
/
w_timer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// ****************************************************************
// * PCP *
// * Copyright (C)1999 Dark Nova Software (DNS) *
// * All Rights Reserved. *
// * *
// * File: win_timer.cpp *
// * Author: zeromus, vecna *
// * Portability: Win32 only *
// * Description: Win32 Timer code *
// ****************************************************************
#define TIMER_H
#include "pcp.h"
void CALLBACK TimeProc(UINT uID,UINT uMsg,DWORD dwUser,DWORD dw1,DWORD dw2);
// ***************************** Code *****************************
vTimer::vTimer(int hz, LPTIMECALLBACK TimeProc)
{
if (currtimer) timeKillEvent(currtimer);
currtimer = timeSetEvent(1000/hz,0,(LPTIMECALLBACK)TimeProc,0,TIME_PERIODIC);
}
vTimer::~vTimer()
{
timeKillEvent(currtimer);
currtimer=0;
}
// ***************************** Data *****************************
int key_timer, key_repeater, repeatedkey;
int systemtime, timer, timer2, hooktimer=0;
vTimer *mainTimeEvent;
byte an=0,tickctr=0,sec=0,min=0,hr=0;
// ****************************************************************
void CALLBACK TimeProc(UINT uID,UINT uMsg,DWORD dwUser,DWORD dw1,DWORD dw2)
{
timer++;
timer2++;
systemtime++;
if (repeatedkey)
if (key_timer + 20 < systemtime)
{
key_repeater++;
if (key_repeater > 8)
{
last_pressed = repeatedkey;
key[last_pressed] = 1;
key_repeater = 0;
}
}
UpdateSound();
if (an) check_tileanimation();
if (hooktimer) ExecuteHookedScript(hooktimer);
tickctr++;
if (tickctr == 100) { tickctr=0; sec++; }
if (sec == 60) { min++; sec=0; }
if (min == 60) { hr++; min=0; }
}
void ShutdownTimer(void)
{
delete mainTimeEvent;
}
void InitTimer(int hz)
{
systemtime = 0;
timer = 0;
mainTimeEvent = new vTimer(hz, TimeProc);
atexit(ShutdownTimer); //, "Timer subsystem");
}