From e9815ad279dc61506e5e65c34348fa7dcc570b9e Mon Sep 17 00:00:00 2001 From: TimePath Date: Tue, 22 Mar 2016 15:57:23 +1100 Subject: [PATCH] Client: Type check --- qcsrc/client/commands/cl_cmd.qc | 9 +++++++++ qcsrc/client/csqcmodel_hooks.qc | 1 + qcsrc/client/hud/hud.qc | 8 ++++++++ qcsrc/client/hud/hud_config.qc | 3 +-- qcsrc/client/hud/panel/ammo.qc | 1 + qcsrc/client/hud/panel/centerprint.qc | 7 ++++--- qcsrc/client/hud/panel/modicons.qc | 2 ++ qcsrc/client/hud/panel/powerups.qc | 1 + qcsrc/client/hud/panel/radar.qc | 4 +++- qcsrc/client/hud/panel/weapons.qc | 2 ++ qcsrc/client/main.qc | 4 +++- qcsrc/client/mapvoting.qc | 23 ++++++++++++++++++++--- qcsrc/client/miscfunctions.qc | 5 ++++- qcsrc/client/player_skeleton.qc | 6 ++++-- qcsrc/client/quickmenu.qc | 20 ++++++++++++++------ qcsrc/client/scoreboard.qc | 11 ++++++++--- qcsrc/client/teamradar.qc | 1 + qcsrc/client/view.qc | 1 + qcsrc/client/weapons/projectile.qc | 1 + qcsrc/common/mutators/base.qh | 2 +- qcsrc/lib/_all.inc | 14 +++++++++----- qcsrc/server/_all.qh | 2 +- 22 files changed, 99 insertions(+), 29 deletions(-) diff --git a/qcsrc/client/commands/cl_cmd.qc b/qcsrc/client/commands/cl_cmd.qc index 5a1350f02..fdc7dae70 100644 --- a/qcsrc/client/commands/cl_cmd.qc +++ b/qcsrc/client/commands/cl_cmd.qc @@ -41,6 +41,7 @@ void DrawDebugModel(entity this) void LocalCommand_blurtest(int request) { + TC(int, request); // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now... // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command. @@ -76,6 +77,7 @@ void LocalCommand_blurtest(int request) void LocalCommand_boxparticles(int request, int argc) { + TC(int, request); TC(int, argc); switch (request) { case CMD_REQUEST_COMMAND: @@ -129,6 +131,7 @@ void LocalCommand_boxparticles(int request, int argc) void LocalCommand_create_scrshot_ent(int request) { + TC(int, request); switch (request) { case CMD_REQUEST_COMMAND: @@ -167,6 +170,7 @@ void LocalCommand_create_scrshot_ent(int request) void LocalCommand_debugmodel(int request, int argc) { + TC(int, request); TC(int, argc); switch (request) { case CMD_REQUEST_COMMAND: @@ -195,6 +199,7 @@ void LocalCommand_debugmodel(int request, int argc) void LocalCommand_handlevote(int request, int argc) { + TC(int, request); TC(int, argc); switch (request) { case CMD_REQUEST_COMMAND: @@ -254,6 +259,7 @@ void HUD_Radar_Show_Maximized(bool doshow, bool clickable); void LocalCommand_hud(int request, int argc) { + TC(int, request); TC(int, argc); switch (request) { case CMD_REQUEST_COMMAND: @@ -346,6 +352,7 @@ void LocalCommand_hud(int request, int argc) void LocalCommand_localprint(int request, int argc) { + TC(int, request); TC(int, argc); switch (request) { case CMD_REQUEST_COMMAND: @@ -372,6 +379,7 @@ void LocalCommand_localprint(int request, int argc) void LocalCommand_mv_download(int request, int argc) { + TC(int, request); TC(int, argc); switch (request) { case CMD_REQUEST_COMMAND: @@ -398,6 +406,7 @@ void LocalCommand_mv_download(int request, int argc) void LocalCommand_sendcvar(int request, int argc) { + TC(int, request); TC(int, argc); switch (request) { case CMD_REQUEST_COMMAND: diff --git a/qcsrc/client/csqcmodel_hooks.qc b/qcsrc/client/csqcmodel_hooks.qc index d0910e374..35f28bdca 100644 --- a/qcsrc/client/csqcmodel_hooks.qc +++ b/qcsrc/client/csqcmodel_hooks.qc @@ -353,6 +353,7 @@ void CSQCPlayer_AnimDecide_PostUpdate(entity this, bool isnew) } int CSQCPlayer_FallbackFrame(entity this, int f) { + TC(int, f); if(frameduration(this.modelindex, f) > 0) return f; // goooooood if(frameduration(this.modelindex, 1) <= 0) diff --git a/qcsrc/client/hud/hud.qc b/qcsrc/client/hud/hud.qc index a4e831835..f62b8992e 100644 --- a/qcsrc/client/hud/hud.qc +++ b/qcsrc/client/hud/hud.qc @@ -68,12 +68,14 @@ vector HUD_Get_Num_Color (float x, float maxvalue) float HUD_GetRowCount(int item_count, vector size, float item_aspect) { + TC(int, item_count); float aspect = size_y / size_x; return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count); } vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect) { + TC(int, item_count); float columns, rows; float ratio, best_ratio = 0; float best_columns = 1, best_rows = 1; @@ -115,6 +117,7 @@ vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspe // return the string of the onscreen race timer string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname) { + TC(int, cp); string col; string timestr; string cpname; @@ -200,6 +203,7 @@ HUD panels //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag) { + TC(bool, vertical); TC(int, drawflag); if(!length_ratio || !theAlpha) return; if(length_ratio > 1) @@ -303,6 +307,7 @@ void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, flo void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag) { + TC(int, drawflag); if(!theAlpha) return; @@ -320,6 +325,7 @@ void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theA void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha, float fadelerp) { + TC(bool, vertical); TC(bool, icon_right_align); vector newPos = '0 0 0', newSize = '0 0 0'; vector picpos, numpos; @@ -399,6 +405,7 @@ void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bo void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha) { + TC(bool, vertical); TC(bool, icon_right_align); DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0); } @@ -427,6 +434,7 @@ void HUD_Vehicle() bool HUD_Panel_CheckFlags(int showflags) { + TC(int, showflags); if ( HUD_Minigame_Showpanels() ) return showflags & PANEL_SHOW_MINIGAME; if(intermission == 2) diff --git a/qcsrc/client/hud/hud_config.qc b/qcsrc/client/hud/hud_config.qc index 2ba78f798..8e69a2dec 100644 --- a/qcsrc/client/hud/hud_config.qc +++ b/qcsrc/client/hud/hud_config.qc @@ -641,8 +641,7 @@ float tab_backward; void HUD_Panel_FirstInDrawQ(float id); void reset_tab_panels() { - int i; - for(i = 0; i < hud_panels_COUNT; ++i) + for (int i = 0; i < hud_panels_COUNT; ++i) tab_panels[i] = world; } float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary) diff --git a/qcsrc/client/hud/panel/ammo.qc b/qcsrc/client/hud/panel/ammo.qc index 0ccdbf2f0..fda7887b1 100644 --- a/qcsrc/client/hud/panel/ammo.qc +++ b/qcsrc/client/hud/panel/ammo.qc @@ -18,6 +18,7 @@ void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expan void DrawAmmoItem(vector myPos, vector mySize, .int ammoType, bool isCurrent, bool isInfinite) { + TC(bool, isCurrent); TC(bool, isInfinite); if(ammoType == ammo_none) return; diff --git a/qcsrc/client/hud/panel/centerprint.qc b/qcsrc/client/hud/panel/centerprint.qc index cde2b501c..99e8baaa6 100644 --- a/qcsrc/client/hud/panel/centerprint.qc +++ b/qcsrc/client/hud/panel/centerprint.qc @@ -17,6 +17,7 @@ bool centerprint_showing; void centerprint_generic(int new_id, string strMessage, float duration, int countdown_num) { + TC(int, new_id); TC(int, countdown_num); //printf("centerprint_generic(%d, '%s^7', %d, %d);\n", new_id, strMessage, duration, countdown_num); int i, j; @@ -91,8 +92,9 @@ void centerprint_generic(int new_id, string strMessage, float duration, int coun centerprint_countdown_num[j] = countdown_num; } -void centerprint_kill(float id) +void centerprint_kill(int id) { + TC(int, id); centerprint_generic(id, "", 0, 0); } @@ -103,8 +105,7 @@ void centerprint_hud(string strMessage) void reset_centerprint_messages() { - int i; - for (i=0; i 0); } -void HUD_Quickmenu_PlayerListEntries(string cmd, int teamplayers, float without_me); -bool HUD_Quickmenu_PlayerListEntries_Create(string cmd, int teamplayers, float without_me) +void HUD_Quickmenu_PlayerListEntries(string cmd, int teamplayers, bool without_me); +bool HUD_Quickmenu_PlayerListEntries_Create(string cmd, int teamplayers, bool without_me) { + TC(int, teamplayers); TC(bool, without_me); int i; for(i = 0; i < QUICKMENU_MAXLINES; ++i) QuickMenu_Page_ClearEntry(i); @@ -253,8 +256,9 @@ bool HUD_Quickmenu_PlayerListEntries_Create(string cmd, int teamplayers, float w // new_page 0 means page 0, new_page != 0 means next page int QuickMenu_Buffer_Index_Prev; -bool QuickMenu_Page_Load(string target_submenu, int new_page) +bool QuickMenu_Page_Load(string target_submenu, bool new_page) { + TC(bool, new_page); string s = string_null, cmd = string_null, z_submenu; if (new_page == 0) @@ -363,6 +367,7 @@ bool QuickMenu_Page_Load(string target_submenu, int new_page) bool QuickMenu_ActionForNumber(int num) { + TC(int, num); if (!QuickMenu_IsLastPage) { if (num < 0 || num >= QUICKMENU_MAXLINES) @@ -388,8 +393,9 @@ bool QuickMenu_ActionForNumber(int num) return false; } -void QuickMenu_Page_ActiveEntry(float entry_num) +void QuickMenu_Page_ActiveEntry(int entry_num) { + TC(int, entry_num); QuickMenu_Page_ActivatedEntry = entry_num; QuickMenu_Page_ActivatedEntry_Time = time + 0.1; if(QuickMenu_Page_Command[QuickMenu_Page_ActivatedEntry]) @@ -405,8 +411,9 @@ void QuickMenu_Page_ActiveEntry(float entry_num) QuickMenu_Page_ActivatedEntry_Close = (!(hudShiftState & S_CTRL)); } -bool QuickMenu_InputEvent(float bInputType, float nPrimary, float nSecondary) +bool QuickMenu_InputEvent(int bInputType, float nPrimary, float nSecondary) { + TC(int, bInputType); // we only care for keyboard events if(bInputType == 2) return false; @@ -744,8 +751,9 @@ void HUD_QuickMenu() QUICKMENU_ENTRY(strcat("(", prvm_language, ")", title), sprintf(command, translated_text)) \ } -void HUD_Quickmenu_PlayerListEntries(string cmd, float teamplayers, float without_me) +void HUD_Quickmenu_PlayerListEntries(string cmd, int teamplayers, bool without_me) { + TC(int, teamplayers); TC(bool, without_me); entity pl; if(teamplayers && !team_count) return; diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index a99db0360..cf25209c7 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -128,8 +128,9 @@ void HUD_UpdatePlayerTeams() */ } -int HUD_CompareScore(float vl, float vr, int f) +int HUD_CompareScore(int vl, int vr, int f) { + TC(int, vl); TC(int, vr); TC(int, f); if(f & SFL_ZERO_IS_WORST) { if(vl == 0 && vr != 0) @@ -313,8 +314,9 @@ void Cmd_HUD_Help() "+as/objectives +nb/faults +nb/goals +ka/pickups +ka/bckills +ka/bctime +ft/revivals " \ "-lms,rc,nb/score" -void Cmd_HUD_SetFields(float argc) +void Cmd_HUD_SetFields(int argc) { + TC(int, argc); int i, j, slash; string str, pattern; float have_name = 0, have_primary = 0, have_secondary = 0, have_separator = 0; @@ -516,6 +518,7 @@ float hud_field_icon1_alpha; float hud_field_icon2_alpha; string HUD_GetField(entity pl, int field) { + TC(int, field); float tmp, num, denom; int f; string str; @@ -640,6 +643,7 @@ float hud_fixscoreboardcolumnwidth_marginlen; string HUD_FixScoreboardColumnWidth(int i, string str) { + TC(int, i); float field, f; vector sz; field = hud_field[i]; @@ -704,8 +708,9 @@ string HUD_FixScoreboardColumnWidth(int i, string str) return str; } -void HUD_PrintScoreboardItem(vector pos, vector item_size, entity pl, float is_self, int pl_number) +void HUD_PrintScoreboardItem(vector pos, vector item_size, entity pl, bool is_self, int pl_number) { + TC(bool, is_self); TC(int, pl_number); vector tmp, rgb; rgb = Team_ColorRGB(pl.team); string str; diff --git a/qcsrc/client/teamradar.qc b/qcsrc/client/teamradar.qc index 96fd5ee97..01388fdd2 100644 --- a/qcsrc/client/teamradar.qc +++ b/qcsrc/client/teamradar.qc @@ -148,6 +148,7 @@ void draw_teamradar_icon(vector coord, entity icon, entity pingdata, vector rgb, void draw_teamradar_link(vector start, vector end, int colors) { + TC(int, colors); vector c0, c1, norm; start = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(start)); diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index a52794ec5..6e8487b96 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -1352,6 +1352,7 @@ float vh_notice_time; void WaypointSprite_Load(); void CSQC_UpdateView(float w, float h) {SELFPARAM(); + TC(int, w); TC(int, h); entity e; float fov; float f; diff --git a/qcsrc/client/weapons/projectile.qc b/qcsrc/client/weapons/projectile.qc index c8e246a06..ea2f5f3d6 100644 --- a/qcsrc/client/weapons/projectile.qc +++ b/qcsrc/client/weapons/projectile.qc @@ -171,6 +171,7 @@ void Projectile_Draw(entity this) void loopsound(entity e, int ch, string samp, float vol, float attn) { + TC(int, ch); if (e.silent) return; diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh index 79cba7f92..3bca32452 100644 --- a/qcsrc/common/mutators/base.qh +++ b/qcsrc/common/mutators/base.qh @@ -112,7 +112,7 @@ ENDCLASS(CallbackChain) #define _MUTATOR_HANDLE_NOP(type, id) #define _MUTATOR_HANDLE_PARAMS(type, id) , type in_##id #define _MUTATOR_HANDLE_PREPARE(type, id) id = in_##id; -#define _MUTATOR_HANDLE_PUSHTMP(type, id) type tmp_##id = id; +#define _MUTATOR_HANDLE_PUSHTMP(type, id) TC(type, id); type tmp_##id = id; #define _MUTATOR_HANDLE_PUSHOUT(type, id) type out_##id = id; #define _MUTATOR_HANDLE_POPTMP(type, id) id = tmp_##id; #define _MUTATOR_HANDLE_POPOUT(type, id) id = out_##id; diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 212ba4a5d..97d560b5c 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -30,16 +30,20 @@ #include "macro.qh" -#ifndef NDEBUG +#if NDEBUG + #define TC(T, sym) MACRO_BEGIN MACRO_END +#else #define TC(T, sym) MACRO_BEGIN \ if (!is_##T(sym)) LOG_WARNINGF("Type check failed: " #sym " :: " #T); \ MACRO_END -#else - #define TC(T, sym) MACRO_BEGIN MACRO_END #endif -bool is_int(float f) { return f == f | 0; } -bool is_bool(float f) { return f == true || f == false; } +bool is_float (float this) { return true; } +bool is_vector(vector this) { return true; } +bool is_string(string this) { return true; } +bool is_entity(entity this) { return true; } +bool is_int (float this) { return this == floor(this); } +bool is_bool (float this) { return this == true || this == false; } #include "warpzone/mathlib.qc" diff --git a/qcsrc/server/_all.qh b/qcsrc/server/_all.qh index f12a715aa..686b47d86 100644 --- a/qcsrc/server/_all.qh +++ b/qcsrc/server/_all.qh @@ -11,7 +11,7 @@ const string STR_OBSERVER = "observer"; #define IS_OBSERVER(v) ((v).classname == STR_OBSERVER) #define IS_CLIENT(v) (v.flags & FL_CLIENT) -#define is_client IS_CLIENT +#define is_Client IS_CLIENT #define IS_BOT_CLIENT(v) (clienttype(v) == CLIENTTYPE_BOT) #define IS_REAL_CLIENT(v) (clienttype(v) == CLIENTTYPE_REAL) #define IS_NOT_A_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT) -- 2.39.2