-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.cpp
124 lines (103 loc) · 1.89 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Filename: main.c
* Description: 라이브러리 초기화/삭제 등
*
* Author: 비엽 aka. Cronan
*/
#define __LIBTHECORE__
#include "stdafx.h"
#include "memory.h"
extern void GOST_Init();
LPHEART thecore_heart = NULL;
volatile int shutdowned = FALSE;
volatile int tics = 0;
unsigned int thecore_profiler[NUM_PF];
static int pid_init(void)
{
#ifdef _WIN32
return true;
#else
FILE* fp;
if ((fp = fopen("pid", "w")))
{
fprintf(fp, "%d", getpid());
fclose(fp);
sys_err("\nStart of pid: %d\n", getpid());
}
else
{
printf("pid_init(): could not open file for writing. (filename: ./pid)");
sys_err("\nError writing pid file\n");
return false;
}
return true;
#endif
}
static void pid_deinit(void)
{
#ifdef _WIN32
return;
#else
remove("./pid");
sys_err("\nEnd of pid\n");
#endif
}
int thecore_init(int fps, HEARTFUNC heartbeat_func)
{
#ifdef _WIN32
srand(time(0));
#else
srandom(time(0) + getpid() + getuid());
srandomdev();
#endif
signal_setup();
if (!log_init() || !pid_init())
return false;
GOST_Init();
thecore_heart = heart_new(1000000 / fps, heartbeat_func);
return true;
}
void thecore_shutdown()
{
shutdowned = TRUE;
}
int thecore_idle(void)
{
thecore_tick();
if (shutdowned)
return 0;
int pulses;
DWORD t = get_dword_time();
if (!(pulses = heart_idle(thecore_heart)))
{
thecore_profiler[PF_IDLE] += (get_dword_time() - t);
return 0;
}
thecore_profiler[PF_IDLE] += (get_dword_time() - t);
return pulses;
}
void thecore_destroy(void)
{
pid_deinit();
log_destroy();
}
int thecore_pulse(void)
{
return (thecore_heart->pulse);
}
float thecore_pulse_per_second(void)
{
return ((float) thecore_heart->passes_per_sec);
}
float thecore_time(void)
{
return ((float) thecore_heart->pulse / (float) thecore_heart->passes_per_sec);
}
int thecore_is_shutdowned(void)
{
return shutdowned;
}
void thecore_tick(void)
{
++tics;
}