]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/static.qh
Merge branch 'terencehill/eraseable_functions'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / static.qh
1 #pragma once
2
3 void __static_init() {}
4 #define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
5 void __static_init_late() {}
6 #define static_init_late() CALL_ACCUMULATED_FUNCTION(__static_init_late)
7 void __static_init_precache() {}
8 #define static_init_precache() CALL_ACCUMULATED_FUNCTION(__static_init_precache)
9 void __shutdown() {}
10 #define shutdownhooks() CALL_ACCUMULATED_FUNCTION(__shutdown)
11
12 #define GETTIME_REALTIME 1
13 #ifdef MENUQC
14 float(int tmr) _gettime = #67;
15 #else
16 float(int tmr) _gettime = #519;
17 #endif
18
19 [[eraseable]]
20 void profile(string s)
21 {
22         static float g_starttime;
23         float rt = _gettime(GETTIME_REALTIME);
24         if (!g_starttime) g_starttime = rt;
25         LOG_TRACEF("[%f] %s", rt - g_starttime, s);
26 }
27
28 #define _STATIC_INIT(where, func) \
29         [[accumulate]] void _static_##func() { profile(#func); } \
30         ACCUMULATE_FUNCTION(where, _static_##func) \
31         void _static_##func()
32
33 #define STATIC_INIT(func) _STATIC_INIT(__static_init,           func)
34 #define STATIC_INIT_LATE(func) _STATIC_INIT(__static_init_late, func##_late)
35 #define PRECACHE(func) _STATIC_INIT(__static_init_precache,     func##_precache)
36 #define SHUTDOWN(func) _STATIC_INIT(__shutdown,                         func##_shutdown)