Xonotic
base.qh File Reference
#include "events.qh"
+ Include dependency graph for base.qh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Callback
 Callbacks may be added to zero or more callback chains. More...
 
class  CallbackChain
 Callback chains contain zero or more callbacks. More...
 
class  CallbackChain::CallbackNode
 
class  Mutator
 

Macros

#define _MUTATOR_CALLBACK(name, func)
 
#define _MUTATOR_CALLHOOK(id, ...)   APPLY(__Mutator_Send_##id, 0 P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))
 
#define _MUTATOR_HANDLE_NOP(type, id)
 
#define _MUTATOR_HANDLE_PARAMS(type, id)   , type in_##id
 
#define _MUTATOR_HANDLE_POPOUT(type, id)   id = out_##id;
 
#define _MUTATOR_HANDLE_POPTMP(type, id)   id = tmp_##id;
 
#define _MUTATOR_HANDLE_PREPARE(type, id)   id = in_##id;
 
#define _MUTATOR_HANDLE_PUSHOUT(type, id)   type out_##id = id;
 
#define _MUTATOR_HANDLE_PUSHTMP(type, id)   TC(type, id); type tmp_##id = id;
 
#define _MUTATOR_HOOKABLE(id, params)
 
#define _MUTATOR_IS_ENABLED(this)   this.mutatorcheck()
 
#define EVAL_MUTATOR_HOOKFUNCTION(...)   __VA_ARGS__
 
#define MUTATOR_ADD(name)   Mutator_Add(MUTATOR_##name)
 
#define MUTATOR_CALLHOOK(id, ...)   _MUTATOR_CALLHOOK(id, __VA_ARGS__)
 
#define MUTATOR_HOOK(cb, func, order)
 
#define MUTATOR_HOOKABLE(id, params)   _MUTATOR_HOOKABLE(id, params)
 
#define MUTATOR_HOOKFUNCTION(...)   EVAL_MUTATOR_HOOKFUNCTION(OVERLOAD(MUTATOR_HOOKFUNCTION, __VA_ARGS__))
 
#define MUTATOR_HOOKFUNCTION_2(mut, cb)   MUTATOR_HOOKFUNCTION_3(mut, cb, CBC_ORDER_ANY)
 
#define MUTATOR_HOOKFUNCTION_3(mut, cb, order)
 
#define MUTATOR_IS_ENABLED(this)   _MUTATOR_IS_ENABLED(MUTATOR_##this)
 
#define MUTATOR_ONADD   if (mode == MUTATOR_ADDING)
 
#define MUTATOR_ONREMOVE   if (mode == MUTATOR_REMOVING)
 
#define MUTATOR_ONROLLBACK_OR_REMOVE   if (mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
 
#define MUTATOR_REMOVE(name)   Mutator_Remove(MUTATOR_##name)
 
#define MUTATOR_RETURNVALUE   CallbackChain_ReturnValue
 
#define MUTATOR_STATIC()
 
#define REGISTER_MUTATOR(id, dependence)
 

Typedefs

using mutatorfunc_t = bool(int)
 

Enumerations

enum  { MUTATOR_REMOVING, MUTATOR_ADDING, MUTATOR_ROLLING_BACK }
 

Functions

void _mutPrintFail (string cb, string func)
 
bool Mutator_Add (Mutator mut)
 
void Mutator_Remove (Mutator mut)
 
void RegisterCallbacks ()
 
void RegisterHooks ()
 
 STATIC_INIT (Mutators)
 
 STATIC_INIT_LATE (Mutators)
 

Variables

bool CallbackChain_ReturnValue
 
const int CBC_ORDER_ANY = 4
 
const int CBC_ORDER_EXCLUSIVE = 3
 
const int CBC_ORDER_FIRST = 1
 
const int CBC_ORDER_LAST = 2
 
bool m_added
 
bool mutator_log = false
 

Macro Definition Documentation

◆ _MUTATOR_CALLBACK

#define _MUTATOR_CALLBACK (   name,
  func 
)
Value:
Callback CB_##name; \
bool func(); \
ACCUMULATE void RegisterCallbacks() { CB_##name = NEW(Callback, func); }
Callbacks may be added to zero or more callback chains.
Definition: base.qh:17
#define NEW(cname,...)
Definition: oo.qh:105
void RegisterCallbacks()
Definition: base.qh:124

Definition at line 305 of file base.qh.

◆ _MUTATOR_CALLHOOK

#define _MUTATOR_CALLHOOK (   id,
  ... 
)    APPLY(__Mutator_Send_##id, 0 P99_IF_EMPTY(__VA_ARGS__)()(, __VA_ARGS__))

Definition at line 142 of file base.qh.

◆ _MUTATOR_HANDLE_NOP

#define _MUTATOR_HANDLE_NOP (   type,
  id 
)

Definition at line 115 of file base.qh.

◆ _MUTATOR_HANDLE_PARAMS

#define _MUTATOR_HANDLE_PARAMS (   type,
  id 
)    , type in_##id

Definition at line 116 of file base.qh.

◆ _MUTATOR_HANDLE_POPOUT

#define _MUTATOR_HANDLE_POPOUT (   type,
  id 
)    id = out_##id;

Definition at line 121 of file base.qh.

◆ _MUTATOR_HANDLE_POPTMP

#define _MUTATOR_HANDLE_POPTMP (   type,
  id 
)    id = tmp_##id;

Definition at line 120 of file base.qh.

◆ _MUTATOR_HANDLE_PREPARE

#define _MUTATOR_HANDLE_PREPARE (   type,
  id 
)    id = in_##id;

Definition at line 117 of file base.qh.

◆ _MUTATOR_HANDLE_PUSHOUT

#define _MUTATOR_HANDLE_PUSHOUT (   type,
  id 
)    type out_##id = id;

Definition at line 119 of file base.qh.

◆ _MUTATOR_HANDLE_PUSHTMP

#define _MUTATOR_HANDLE_PUSHTMP (   type,
  id 
)    TC(type, id); type tmp_##id = id;

Definition at line 118 of file base.qh.

◆ _MUTATOR_HOOKABLE

#define _MUTATOR_HOOKABLE (   id,
  params 
)
Value:
CallbackChain HOOK_##id; \
bool __Mutator_Send_##id(int params(_MUTATOR_HANDLE_PARAMS, _MUTATOR_HANDLE_NOP)) { \
bool ret = CallbackChain_Call(HOOK_##id); \
return ret; \
} \
ACCUMULATE void RegisterHooks() { HOOK_##id = NEW(CallbackChain, #id); }
#define NEW(cname,...)
Definition: oo.qh:105
Callback chains contain zero or more callbacks.
Definition: base.qh:36
#define _MUTATOR_HANDLE_PUSHTMP(type, id)
Definition: base.qh:118
#define _MUTATOR_HANDLE_PUSHOUT(type, id)
Definition: base.qh:119
#define _MUTATOR_HANDLE_NOP(type, id)
Definition: base.qh:115
#define _MUTATOR_HANDLE_POPOUT(type, id)
Definition: base.qh:121
#define _MUTATOR_HANDLE_PREPARE(type, id)
Definition: base.qh:117
#define _MUTATOR_HANDLE_PARAMS(type, id)
Definition: base.qh:116
#define _MUTATOR_HANDLE_POPTMP(type, id)
Definition: base.qh:120
void RegisterHooks()
Definition: base.qh:123

Definition at line 127 of file base.qh.

◆ _MUTATOR_IS_ENABLED

#define _MUTATOR_IS_ENABLED (   this)    this.mutatorcheck()

Definition at line 175 of file base.qh.

Referenced by STATIC_INIT_LATE().

◆ EVAL_MUTATOR_HOOKFUNCTION

#define EVAL_MUTATOR_HOOKFUNCTION (   ...)    __VA_ARGS__

Definition at line 312 of file base.qh.

◆ MUTATOR_ADD

#define MUTATOR_ADD (   name)    Mutator_Add(MUTATOR_##name)

Definition at line 301 of file base.qh.

◆ MUTATOR_CALLHOOK

#define MUTATOR_CALLHOOK (   id,
  ... 
)    _MUTATOR_CALLHOOK(id, __VA_ARGS__)

Definition at line 140 of file base.qh.

Referenced by _StartItem(), accuracy_isgooddamage(), AnnouncerOption(), AppendItemcodes(), bot_fixcount(), bot_shouldattack(), buff_Touch(), buffs_BuffModel_Customize(), calculate_player_respawn_time(), CheatImpulse(), CheckRules_World(), ClientCommand_spectate(), ClientConnect(), ClientDisconnect(), ClientInit_SendEntity(), ClientKill_Now(), ClientKill_TeamChange(), CommonCommand_editmob(), CopyBody(), CSQCModel_AutoTagIndex_Apply(), CSQCPlayer_ModelAppearance_Apply(), Damage(), DecodeLevelParms(), Draw_ShowNames(), DrawReticle(), Drop_Special_Items(), fireBullet_antilag(), FixClientCvars(), FixPlayermodel(), formatmessage(), frag_centermessage_override(), Freeze(), GameCommand(), get_model_parameters(), GetCvars(), GetPlayerLimit(), GetPressedKeys(), getrecords(), GetResourceLimit(), getwelcomemessage(), GiveFrags(), GiveResource(), GiveResourceWithLimit(), GrapplingHookThink(), havocbot_aim(), havocbot_chooserole(), HUD_Contents(), HUD_Crosshair(), HUD_Draw(), HUD_Physics(), HUD_Powerups(), HUD_RaceTimer(), HUD_Radar(), HUD_Score(), HUD_StrafeHUD(), HUD_Vote(), IMPULSE(), Item_IsDefinitionAllowed(), Item_Model(), Item_RespawnCountdown(), Item_ScheduleRespawnIn(), Item_Sound(), Item_Touch(), joinAllowed(), KillPlayerForTeamChange(), LocalCommand_hud(), M_Model(), MainWindow_configureMainWindow(), Monster_Damage(), monster_dropitem(), Monster_FindTarget(), Monster_Miniboss_Check(), Monster_Move(), Monster_Remove(), Monster_Respawn_Check(), Monster_Spawn_Setup(), Monster_ValidTarget(), MUTATOR_HOOKFUNCTION(), NET_HANDLE(), NextLevel(), Obituary(), player_powerups(), player_regen(), Player_SetTeamIndex(), PlayerDamage(), PlayerJump(), PlayerPreThink(), PlayerScore_Add(), PlayerScore_Clear(), PlayerUseKey(), PM_ClientMovement_UpdateStatus(), Portal_TeleportPlayer(), PRECACHE(), PutClientInServer(), PutObserverInServer(), PutPlayerInServer(), race_SendTime(), RandomItems_GetRandomItemClassName(), readlevelcvars(), readplayerstartcvars(), ReadyRestart(), reset_map(), Say(), Scoreboard_AccuracyStats_WouldDraw(), Scoreboard_ItemStats_WouldDraw(), Scoreboard_WouldDraw(), SetChangeParms(), SetDefaultAlpha(), SetNewParms(), SetResource(), skeleton_loadinfo(), Spawn_Score(), spawnfunc(), Spectate(), SpectateCopy(), SpectateNext(), SpectatePrev(), StartFrame(), SV_OnEntityPreSpawnFunction(), SV_ParseClientCommand(), sys_phys_update(), TakeResource(), TakeResourceWithLimit(), TeamBalance_CheckAllowedTeams(), TeamBalance_FindBestTeams(), TeamBalance_GetPlayerForTeamSwitch(), TeamBalance_GetTeamCounts(), Unfreeze(), URI_Get_Callback(), vehicle_initialize(), vehicles_enter(), vehicles_exit(), vehicles_touch(), View_EventChase(), viewmodel_draw(), VoteCommand_parse(), W_DecreaseAmmo(), W_IsWeaponThrowable(), W_Model(), W_PlayStrengthSound(), W_PrepareExplosionByDamage(), W_Reload(), W_Sound(), W_ThrowWeapon(), W_WeaponRateFactor(), W_WeaponSpeedFactor(), want_weapon(), WantEventchase(), weapon_defaultspawnfunc(), weaponLocked(), weaponUseForbidden(), and WinningCondition_Scores().

◆ MUTATOR_HOOK

#define MUTATOR_HOOK (   cb,
  func,
  order 
)
Value:
MACRO_BEGIN \
MUTATOR_ONADD { \
if (!CallbackChain_Add(HOOK_##cb, CB_##func, order)) { \
_mutPrintFail(#cb, #func); \
return true; \
} \
} \
MUTATOR_ONROLLBACK_OR_REMOVE { \
CallbackChain_Remove(HOOK_##cb, CB_##func); \
} \
MACRO_END

Definition at line 329 of file base.qh.

◆ MUTATOR_HOOKABLE

#define MUTATOR_HOOKABLE (   id,
  params 
)    _MUTATOR_HOOKABLE(id, params)

Definition at line 126 of file base.qh.

◆ MUTATOR_HOOKFUNCTION

#define MUTATOR_HOOKFUNCTION (   ...)    EVAL_MUTATOR_HOOKFUNCTION(OVERLOAD(MUTATOR_HOOKFUNCTION, __VA_ARGS__))

Definition at line 310 of file base.qh.

Referenced by GENERIC_COMMAND(), and Item_ItemsTime_Allow().

◆ MUTATOR_HOOKFUNCTION_2

#define MUTATOR_HOOKFUNCTION_2 (   mut,
  cb 
)    MUTATOR_HOOKFUNCTION_3(mut, cb, CBC_ORDER_ANY)

Definition at line 314 of file base.qh.

◆ MUTATOR_HOOKFUNCTION_3

#define MUTATOR_HOOKFUNCTION_3 (   mut,
  cb,
  order 
)
Value:
_MUTATOR_CALLBACK(mut##_##cb, mut##_##cb) \
ACCUMULATE bool MUTATORFUNC_##mut##_hooks(int mode) { MUTATOR_HOOK(cb, mut##_##cb, order); } \
bool mut##_##cb() { return = false; } \
ACCUMULATE bool mut##_##cb()
#define MUTATOR_HOOK(cb, func, order)
Definition: base.qh:329
#define _MUTATOR_CALLBACK(name, func)
Definition: base.qh:305

Definition at line 317 of file base.qh.

◆ MUTATOR_IS_ENABLED

#define MUTATOR_IS_ENABLED (   this)    _MUTATOR_IS_ENABLED(MUTATOR_##this)

◆ MUTATOR_ONADD

#define MUTATOR_ONADD   if (mode == MUTATOR_ADDING)

Definition at line 284 of file base.qh.

Referenced by REGISTER_MUTATOR().

◆ MUTATOR_ONREMOVE

#define MUTATOR_ONREMOVE   if (mode == MUTATOR_REMOVING)

Definition at line 285 of file base.qh.

Referenced by REGISTER_MUTATOR().

◆ MUTATOR_ONROLLBACK_OR_REMOVE

#define MUTATOR_ONROLLBACK_OR_REMOVE   if (mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)

Definition at line 286 of file base.qh.

Referenced by REGISTER_MUTATOR().

◆ MUTATOR_REMOVE

#define MUTATOR_REMOVE (   name)    Mutator_Remove(MUTATOR_##name)

Definition at line 302 of file base.qh.

◆ MUTATOR_RETURNVALUE

#define MUTATOR_RETURNVALUE   CallbackChain_ReturnValue

Definition at line 303 of file base.qh.

Referenced by MUTATOR_HOOKFUNCTION().

◆ MUTATOR_STATIC

#define MUTATOR_STATIC ( )
Value:
MACRO_BEGIN \
MUTATOR_ONADD { \
/* game loads at time 1 */ \
if (time > 1) { \
error("This is a game type and it cannot be added at runtime."); \
} \
} \
MUTATOR_ONREMOVE { \
LOG_INFO("This is a game type and it cannot be removed at runtime."); \
return -1; \
} \
MACRO_END
float time
Definition: csprogsdefs.qc:16

Definition at line 288 of file base.qh.

Referenced by REGISTER_MUTATOR().

◆ REGISTER_MUTATOR

#define REGISTER_MUTATOR (   id,
  dependence 
)
Value:
bool MUTATORFUNC_##id##_hooks(int mode) { return = false; } \
bool MUTATORFUNC_##id(int mode) { \
return = false; \
bool ret = MUTATORFUNC_##id##_hooks(mode); if (ret) return ret; \
} \
bool MUTATOR_##id##_check() { return dependence; } \
REGISTER(Mutators, MUTATOR, id, m_id, NEW(Mutator, #id, MUTATORFUNC_##id)) \
{ this.mutatorcheck = MUTATOR_##id##_check; } \
ACCUMULATE bool MUTATORFUNC_##id(int mode)
#define NEW(cname,...)
Definition: oo.qh:105
Definition: base.qh:155
int m_id
Definition: effect.qh:19

Definition at line 263 of file base.qh.

Referenced by GENERIC_COMMAND().

Typedef Documentation

◆ mutatorfunc_t

Definition at line 153 of file base.qh.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MUTATOR_REMOVING 
MUTATOR_ADDING 
MUTATOR_ROLLING_BACK 

Definition at line 147 of file base.qh.

Function Documentation

◆ _mutPrintFail()

void _mutPrintFail ( string  cb,
string  func 
)

Definition at line 323 of file base.qh.

References LOG_INFO.

324 {
325  // this is inside a function to avoid expanding it on compilation everytime
326  LOG_INFO("HOOK FAILED: ", cb, ":", func);
327 }
#define LOG_INFO(...)
Definition: log.qh:70

◆ Mutator_Add()

bool Mutator_Add ( Mutator  mut)

Definition at line 220 of file base.qh.

References backtrace, error(), LOG_TRACEF, MUTATOR_ADDING, and MUTATOR_ROLLING_BACK.

Referenced by Mutator::Mutator ::Mutator(), and STATIC_INIT_LATE().

221 {
222  if(mut.m_added)
223  return true; // already added
224 
225  mut.m_added = true;
226  mutatorfunc_t func = mut.mutatorfunc;
227  if (!func(MUTATOR_ADDING)) {
228  // good
229  if (mutator_log) LOG_TRACEF("Mutator: added %s", mut.m_name);
230 #ifdef SVQC
231  Net_LinkEntity(mut, false, 0, Mutator_SendEntity);
232 #endif
233  return true;
234  }
235  backtrace("WARNING: when adding mutator: adding failed, rolling back\n");
236  if (func(MUTATOR_ROLLING_BACK)) {
237  // baaaaad
238  error("WARNING: when adding mutator: rolling back failed");
239  }
240  return false;
241 }
#define backtrace(msg)
Definition: log.qh:105
#define LOG_TRACEF(...)
Definition: log.qh:82
bool(int) mutatorfunc_t
Definition: base.qh:153
bool mutator_log
Definition: base.qh:172
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Mutator_Remove()

void Mutator_Remove ( Mutator  mut)

Definition at line 243 of file base.qh.

References backtrace, error(), LOG_TRACEF, and MUTATOR_REMOVING.

Referenced by Mutator::Mutator ::Mutator().

244 {
245  if(!mut.m_added)
246  {
247  backtrace("WARNING: removing not-added mutator\n");
248  return;
249  }
250 
251  mut.m_added = false;
252  mutatorfunc_t func = mut.mutatorfunc;
253  if (func(MUTATOR_REMOVING)) {
254  // baaaaad
255  error("Mutator_Remove: removing mutator failed");
256  }
257  if (mutator_log) LOG_TRACEF("Mutator: removed %s", mut.m_name);
258 #ifdef SVQC
259  Net_UnlinkEntity(mut);
260 #endif
261 }
#define backtrace(msg)
Definition: log.qh:105
#define LOG_TRACEF(...)
Definition: log.qh:82
bool(int) mutatorfunc_t
Definition: base.qh:153
bool mutator_log
Definition: base.qh:172
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RegisterCallbacks()

void RegisterCallbacks ( )

Definition at line 124 of file base.qh.

Referenced by STATIC_INIT().

124 {};
+ Here is the caller graph for this function:

◆ RegisterHooks()

void RegisterHooks ( )

Definition at line 123 of file base.qh.

Referenced by STATIC_INIT().

123 {};
+ Here is the caller graph for this function:

◆ STATIC_INIT()

STATIC_INIT ( Mutators  )

Definition at line 274 of file base.qh.

References RegisterCallbacks(), and RegisterHooks().

274  {
275  RegisterHooks();
277  RegisterMutators();
278 }
void RegisterCallbacks()
Definition: base.qh:124
void RegisterHooks()
Definition: base.qh:123
+ Here is the call graph for this function:

◆ STATIC_INIT_LATE()

STATIC_INIT_LATE ( Mutators  )

Definition at line 280 of file base.qh.

References _MUTATOR_IS_ENABLED, FOREACH, and Mutator_Add().

280  {
281  FOREACH(Mutators, _MUTATOR_IS_ENABLED(it), Mutator_Add(it));
282 }
#define _MUTATOR_IS_ENABLED(this)
Definition: base.qh:175
bool Mutator_Add(Mutator mut)
Definition: base.qh:220
#define FOREACH(list, cond, body)
Definition: iter.qh:19
+ Here is the call graph for this function:

Variable Documentation

◆ CallbackChain_ReturnValue

bool CallbackChain_ReturnValue

Definition at line 12 of file base.qh.

Referenced by CallbackChain::CallbackChain_Call().

◆ CBC_ORDER_ANY

const int CBC_ORDER_ANY = 4

◆ CBC_ORDER_EXCLUSIVE

const int CBC_ORDER_EXCLUSIVE = 3

Definition at line 9 of file base.qh.

◆ CBC_ORDER_FIRST

const int CBC_ORDER_FIRST = 1

Definition at line 7 of file base.qh.

Referenced by CallbackChain::CallbackChain_Add().

◆ CBC_ORDER_LAST

const int CBC_ORDER_LAST = 2

Definition at line 8 of file base.qh.

Referenced by CallbackChain::CallbackChain_Add(), and Item_ItemsTime_Allow().

◆ m_added

bool m_added

Definition at line 173 of file base.qh.

◆ mutator_log

bool mutator_log = false

Definition at line 172 of file base.qh.