]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/static.qh
6f511fcecfa1c9c1f2ef842ad5fe47ac44fbd7ef
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / static.qh
1 #pragma once
2
3 #define GETTIME_REALTIME 1
4 #ifdef MENUQC
5 float(int tmr) _gettime = #67;
6 #else
7 float(int tmr) _gettime = #519;
8 #endif
9
10 ERASEABLE
11 void profile(string s)
12 {
13         static float g_starttime;
14         float rt = _gettime(GETTIME_REALTIME);
15         if (!g_starttime) g_starttime = rt;
16         LOG_TRACEF("[%f] %s", rt - g_starttime, s);
17 }
18
19 #define _STATIC_INIT(func, where) \
20         [[accumulate]] void _static_##func() { profile(#func); } \
21         ACCUMULATE_FUNCTION(where, _static_##func) \
22         void _static_##func()
23
24 /** before worldspawn */
25 #define STATIC_INIT_EARLY(func) _STATIC_INIT(func##_0,    __static_init_0)
26 #define static_init_early()     CALL_ACCUMULATED_FUNCTION(__static_init_0)
27 void __static_init_0() {}
28
29 /** during worldspawn */
30 #define STATIC_INIT(func)       _STATIC_INIT(func##_1,    __static_init_1)
31 #define static_init()           CALL_ACCUMULATED_FUNCTION(__static_init_1)
32 void __static_init_1() {}
33
34 /** directly after STATIC_INIT */
35 #define STATIC_INIT_LATE(func)  _STATIC_INIT(func##_2,    __static_init_2)
36 #define static_init_late()      CALL_ACCUMULATED_FUNCTION(__static_init_2)
37 void __static_init_2() {}
38
39 /** directly after STATIC_INIT_LATE */
40 #define PRECACHE(func)          _STATIC_INIT(func##_3,    __static_init_3)
41 #define static_init_precache()  CALL_ACCUMULATED_FUNCTION(__static_init_3)
42 void __static_init_3() {}
43
44 /* other map entities spawn now */
45
46 /** before shutdown */
47 #define SHUTDOWN(func)          _STATIC_INIT(func##_shutdown, __shutdown)
48 #define shutdownhooks()         CALL_ACCUMULATED_FUNCTION(    __shutdown)
49 void __shutdown() {}