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