From fa458d3c9e00e232a7fead820c0032b309a39236 Mon Sep 17 00:00:00 2001 From: TimePath Date: Wed, 27 Jul 2016 22:04:38 +1000 Subject: [PATCH] Move objerror to qc --- qcsrc/dpdefs/post.qh | 1 + qcsrc/dpdefs/pre.qh | 1 + qcsrc/lib/_all.inc | 16 ++++++++++++++++ qcsrc/lib/log.qh | 8 +------- qcsrc/lib/oo.qh | 8 ++++++-- qcsrc/lib/self.qh | 6 ------ qcsrc/server/g_world.qc | 4 ++-- qcsrc/server/miscfunctions.qc | 4 ++-- qcsrc/server/sv_main.qc | 2 +- qcsrc/server/sys-post.qh | 2 +- qcsrc/server/sys-pre.qh | 1 - 11 files changed, 31 insertions(+), 22 deletions(-) diff --git a/qcsrc/dpdefs/post.qh b/qcsrc/dpdefs/post.qh index db8752d2b..9419dceea 100644 --- a/qcsrc/dpdefs/post.qh +++ b/qcsrc/dpdefs/post.qh @@ -6,6 +6,7 @@ #undef error #undef movetogoal #undef objerror +#undef remove #undef walkmove #ifdef MENUQC diff --git a/qcsrc/dpdefs/pre.qh b/qcsrc/dpdefs/pre.qh index b24d0120a..801b8731b 100644 --- a/qcsrc/dpdefs/pre.qh +++ b/qcsrc/dpdefs/pre.qh @@ -6,4 +6,5 @@ #define error builtin_error #define movetogoal builtin_movetogoal #define objerror builtin_objerror +#define remove builtin_remove #define walkmove builtin_walkmove diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 37093d27d..b0c9ec901 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -112,6 +112,22 @@ void isnt_bool(float this) { print(ftos(this)); } #include "matrix/_mod.inc" +#ifndef SVQC +#define objerror_safe(e) +#else +void make_safe_for_remove(entity this); + #define objerror_safe(e) make_safe_for_remove(e) +#endif + +#define objerror(this, msg) MACRO_BEGIN { \ + LOG_WARNING("======OBJECT ERROR======"); \ + entity _e = (this); \ + eprint(_e); \ + objerror_safe(_e); \ + delete(_e); \ + LOG_WARNINGF("%s OBJECT ERROR in %s:\n%s\nTip: read above for entity information", PROGNAME, __FUNC__, msg); \ +} MACRO_END + #ifdef MENUQC void _m_init(); void m_init() { if (_m_init) _m_init(); } diff --git a/qcsrc/lib/log.qh b/qcsrc/lib/log.qh index 370d96be5..a8874adbd 100644 --- a/qcsrc/lib/log.qh +++ b/qcsrc/lib/log.qh @@ -82,13 +82,7 @@ string(string...) strcat0n = #115; } MACRO_END // TODO: this sucks, lets find a better way to do backtraces? -#ifdef SVQC - void builtin_remove(entity); - #define _backtrace() builtin_remove(NULL) -#else - void remove(entity); - #define _backtrace() remove(NULL) -#endif +#define _backtrace() builtin_remove(NULL) noref int autocvar_developer; noref bool autocvar_prvm_backtraceforwarnings; diff --git a/qcsrc/lib/oo.qh b/qcsrc/lib/oo.qh index f47e558a8..e3206dcf3 100644 --- a/qcsrc/lib/oo.qh +++ b/qcsrc/lib/oo.qh @@ -73,11 +73,15 @@ entity __spawn(string _classname, string _sourceLoc, bool pure) [[accumulate]] void ONREMOVE(entity this) {} +#ifndef SVQC + #define delete_fn builtin_remove +#endif + #define delete(this) MACRO_BEGIN { \ entity _this = (this); \ void(entity) _dtor = _this.dtor; \ ONREMOVE(this); \ - if (_dtor) _dtor(_this); else remove(_this); \ + if (_dtor) _dtor(_this); else delete_fn(_this); \ /* this = NULL; */ \ } MACRO_END @@ -274,7 +278,7 @@ STATIC_INIT(RegisterClasses) #define spawn_1(this) #define _vtbl NULL CLASS(Object, ); - DESTRUCTOR(Object) { remove(this); } + DESTRUCTOR(Object) { builtin_remove(this); } #define remove(this) delete(this) METHOD(Object, describe, string(Object this)) { diff --git a/qcsrc/lib/self.qh b/qcsrc/lib/self.qh index 5d42bdccd..bc545b0d0 100644 --- a/qcsrc/lib/self.qh +++ b/qcsrc/lib/self.qh @@ -102,12 +102,6 @@ SELFWRAP(SendEntity, bool, (entity to, int sendflags), (entity this, entity to, #endif #define error(...) (__self = (NULL), builtin_error(__VA_ARGS__)) #define movetogoal(e, ...) (__self = (e), builtin_movetogoal(__VA_ARGS__)) -#ifndef SVQC - #define objerror(e, ...) (__self = (e), builtin_objerror(__VA_ARGS__)) -#else - void make_safe_for_remove(entity this); - #define objerror(e, ...) (__self = (e), make_safe_for_remove(__self), builtin_objerror(__VA_ARGS__)) -#endif #define walkmove(e, ...) (__self = (e), builtin_walkmove(__VA_ARGS__)) #ifndef MENUQC diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 064a69e47..2eff929b8 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -540,7 +540,7 @@ spawnfunc(__init_dedicated_server) cvar_string = cvar_string_normal; cvar_set = cvar_set_normal; - remove = remove_unsafely; + delete_fn = remove_unsafely; entity e = spawn(); setthink(e, GotoFirstMap); @@ -657,7 +657,7 @@ spawnfunc(worldspawn) error("world already spawned - you may have EXACTLY ONE worldspawn!"); world_already_spawned = true; - remove = remove_safely; // during spawning, watch what you remove! + delete_fn = remove_safely; // during spawning, watch what you remove! cvar_changes_init(); // do this very early now so it REALLY matches the server config diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 2686e0553..0abfef456 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -881,7 +881,7 @@ void InitializeEntitiesRun() { entity startoflist = initialize_entity_first; initialize_entity_first = NULL; - remove = remove_except_protected; + delete_fn = remove_except_protected; for (entity e = startoflist; e; e = e.initialize_entity_next) { e.remove_except_protected_forbidden = 1; @@ -912,7 +912,7 @@ void InitializeEntitiesRun() } e = next; } - remove = remove_unsafely; + delete_fn = remove_unsafely; } .float(entity) isEliminated; diff --git a/qcsrc/server/sv_main.qc b/qcsrc/server/sv_main.qc index bf24e09b7..105e2a943 100644 --- a/qcsrc/server/sv_main.qc +++ b/qcsrc/server/sv_main.qc @@ -165,7 +165,7 @@ void StartFrame() execute_next_frame(); if (autocvar_sv_autopause && !server_is_dedicated) Pause_TryPause(true); - remove = remove_unsafely; // not during spawning! + delete_fn = remove_unsafely; // not during spawning! serverprevtime = servertime; servertime = time; serverframetime = frametime; diff --git a/qcsrc/server/sys-post.qh b/qcsrc/server/sys-post.qh index e24a790a1..32024aec5 100644 --- a/qcsrc/server/sys-post.qh +++ b/qcsrc/server/sys-post.qh @@ -10,7 +10,7 @@ var float(string name) cvar; var string(string name) cvar_string; var void(string name, string value) cvar_set; -var void remove(entity e); +var void delete_fn(entity e); #undef IT_SHOTGUN #undef IT_SUPER_SHOTGUN diff --git a/qcsrc/server/sys-pre.qh b/qcsrc/server/sys-pre.qh index 7ab3f7b9f..9799a087e 100644 --- a/qcsrc/server/sys-pre.qh +++ b/qcsrc/server/sys-pre.qh @@ -1,7 +1,6 @@ #pragma once #define droptofloor builtin_droptofloor -#define remove builtin_remove #define cvar_set builtin_cvar_set #define cvar_string builtin_cvar_string #define cvar builtin_cvar -- 2.39.2