]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/static.qh
Merge branch 'martin-t/nottarg' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / static.qh
index e1cfeb8721ce54f6b29a9f440e410d2c29bf5626..6f511fcecfa1c9c1f2ef842ad5fe47ac44fbd7ef 100644 (file)
@@ -1,20 +1,49 @@
 #pragma once
 
-void __static_init() {}
-#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
-void __static_init_late() {}
-#define static_init_late() CALL_ACCUMULATED_FUNCTION(__static_init_late)
-void __static_init_precache() {}
-#define static_init_precache() CALL_ACCUMULATED_FUNCTION(__static_init_precache)
-void __shutdown() {}
-#define shutdownhooks() CALL_ACCUMULATED_FUNCTION(__shutdown)
+#define GETTIME_REALTIME 1
+#ifdef MENUQC
+float(int tmr) _gettime = #67;
+#else
+float(int tmr) _gettime = #519;
+#endif
+
+ERASEABLE
+void profile(string s)
+{
+       static float g_starttime;
+       float rt = _gettime(GETTIME_REALTIME);
+       if (!g_starttime) g_starttime = rt;
+       LOG_TRACEF("[%f] %s", rt - g_starttime, s);
+}
 
-#define _STATIC_INIT(where, func) \
-       void _static_##func(); \
+#define _STATIC_INIT(func, where) \
+       [[accumulate]] void _static_##func() { profile(#func); } \
        ACCUMULATE_FUNCTION(where, _static_##func) \
        void _static_##func()
 
-#define STATIC_INIT(func) _STATIC_INIT(__static_init,           func)
-#define STATIC_INIT_LATE(func) _STATIC_INIT(__static_init_late, func##_late)
-#define PRECACHE(func) _STATIC_INIT(__static_init_precache,     func##_precache)
-#define SHUTDOWN(func) _STATIC_INIT(__shutdown,                        func##_shutdown)
+/** before worldspawn */
+#define STATIC_INIT_EARLY(func) _STATIC_INIT(func##_0,    __static_init_0)
+#define static_init_early()     CALL_ACCUMULATED_FUNCTION(__static_init_0)
+void __static_init_0() {}
+
+/** during worldspawn */
+#define STATIC_INIT(func)       _STATIC_INIT(func##_1,    __static_init_1)
+#define static_init()           CALL_ACCUMULATED_FUNCTION(__static_init_1)
+void __static_init_1() {}
+
+/** directly after STATIC_INIT */
+#define STATIC_INIT_LATE(func)  _STATIC_INIT(func##_2,    __static_init_2)
+#define static_init_late()      CALL_ACCUMULATED_FUNCTION(__static_init_2)
+void __static_init_2() {}
+
+/** directly after STATIC_INIT_LATE */
+#define PRECACHE(func)          _STATIC_INIT(func##_3,    __static_init_3)
+#define static_init_precache()  CALL_ACCUMULATED_FUNCTION(__static_init_3)
+void __static_init_3() {}
+
+/* other map entities spawn now */
+
+/** before shutdown */
+#define SHUTDOWN(func)          _STATIC_INIT(func##_shutdown, __shutdown)
+#define shutdownhooks()         CALL_ACCUMULATED_FUNCTION(    __shutdown)
+void __shutdown() {}