X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Flib%2Fstatic.qh;h=e0ec96b8ec0c43872992e12523329c0be74e8f5d;hb=55a4614bcbabe7335c9a7c25bbb6458400b3a424;hp=d51a8717532677a9e55b54d9119096fd4b90a1d2;hpb=c17854ba3d21dc82455ada46c42ecef6f02acdd1;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/static.qh b/qcsrc/lib/static.qh index d51a87175..e0ec96b8e 100644 --- a/qcsrc/lib/static.qh +++ b/qcsrc/lib/static.qh @@ -1,17 +1,51 @@ -#ifndef STATIC_H -#define STATIC_H +#pragma once -void __static_init_early() { } -void __static_init() { CALL_ACCUMULATED_FUNCTION(__static_init_early); } -#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init) -#define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init_early, func) +#define GETTIME_REALTIME 1 +#ifdef MENUQC +float(int tmr) _gettime = #67; +#else +float(int tmr) _gettime = #519; +#endif -#define _STATIC_INIT(where, func) \ - void _static_##func(); \ - ACCUMULATE_FUNCTION(where, _static_##func) \ - void _static_##func() +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(func) _STATIC_INIT(__static_init_early, func##_early) -#define STATIC_INIT_LATE(func) _STATIC_INIT(__static_init, func) +#define _STATIC_INIT(func, where) \ + ACCUMULATE void _static_##func##profile() { profile(#func); } \ + ACCUMULATE_FUNCTION(where, _static_##func##profile) \ + ACCUMULATE void _static_##func(); \ + ACCUMULATE_FUNCTION(where, _static_##func) \ + void _static_##func() -#endif +/** 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() {}