From c1b058929459a95a525deff9e0ebb76a513a7c22 Mon Sep 17 00:00:00 2001 From: TimePath Date: Thu, 27 Aug 2015 12:38:07 +1000 Subject: [PATCH] Extract more lib functions --- qcsrc/client/csqcmodel_hooks.qc | 2 - qcsrc/client/generator.qc | 10 -- qcsrc/client/hook.qc | 29 ---- qcsrc/client/hud.qc | 143 -------------------- qcsrc/client/main.qc | 1 - qcsrc/client/miscfunctions.qc | 10 -- qcsrc/client/miscfunctions.qh | 1 - qcsrc/client/noise.qh | 9 -- qcsrc/client/progs.src | 4 - qcsrc/client/scoreboard.qc | 1 - qcsrc/client/teamradar.qc | 15 -- qcsrc/client/teamradar.qh | 6 - qcsrc/client/tuba.qc | 1 - qcsrc/client/view.qc | 2 - qcsrc/common/command/rpn.qc | 1 - qcsrc/common/constants.qh | 4 - qcsrc/common/util.qc | 2 - qcsrc/common/weapons/all.qc | 2 - qcsrc/csqcmodellib/cl_player.qc | 1 - qcsrc/lib/Draw.qh | 133 ++++++++++++++++++ qcsrc/lib/Player.qh | 34 +++++ qcsrc/lib/String.qh | 38 ++++++ qcsrc/lib/Vector.qh | 34 +++++ qcsrc/lib/_all.inc | 9 ++ qcsrc/{client => lib}/noise.qc | 5 +- qcsrc/{common => lib}/p2mathlib.qc | 0 qcsrc/{common => lib}/p2mathlib.qh | 0 qcsrc/lib/prandom.qc | 2 - qcsrc/{client => lib}/sortlist.qc | 2 +- qcsrc/{client => lib}/sortlist.qh | 2 +- qcsrc/menu/progs.src | 1 - qcsrc/menu/xonotic/slider_decibels.qc | 2 - qcsrc/server/anticheat.qc | 1 - qcsrc/server/command/sv_cmd.qc | 1 - qcsrc/server/mutators/gamemode.qh | 1 - qcsrc/server/mutators/gamemode_ctf.qc | 1 - qcsrc/server/mutators/gamemode_onslaught.qc | 10 -- qcsrc/server/mutators/mutator.qh | 1 - qcsrc/server/mutators/mutators_include.qc | 1 - qcsrc/server/progs.src | 2 - qcsrc/server/t_plats.qc | 1 - 41 files changed, 252 insertions(+), 273 deletions(-) delete mode 100644 qcsrc/client/noise.qh create mode 100644 qcsrc/lib/Draw.qh create mode 100644 qcsrc/lib/Player.qh create mode 100644 qcsrc/lib/String.qh create mode 100644 qcsrc/lib/Vector.qh rename qcsrc/{client => lib}/noise.qc (94%) rename qcsrc/{common => lib}/p2mathlib.qc (100%) rename qcsrc/{common => lib}/p2mathlib.qh (100%) rename qcsrc/{client => lib}/sortlist.qc (98%) rename qcsrc/{client => lib}/sortlist.qh (90%) diff --git a/qcsrc/client/csqcmodel_hooks.qc b/qcsrc/client/csqcmodel_hooks.qc index 227341ae3..80b68a6e2 100644 --- a/qcsrc/client/csqcmodel_hooks.qc +++ b/qcsrc/client/csqcmodel_hooks.qc @@ -3,7 +3,6 @@ #include "gibs.qh" #include "player_skeleton.qh" -#include "sortlist.qh" #include "weapons/projectile.qh" @@ -18,7 +17,6 @@ #include "../csqcmodellib/cl_player.qh" #include "../csqcmodellib/interpolate.qh" -#include "../warpzonelib/mathlib.qh" .float death_time; .int modelflags; diff --git a/qcsrc/client/generator.qc b/qcsrc/client/generator.qc index ed4b35681..46872d817 100644 --- a/qcsrc/client/generator.qc +++ b/qcsrc/client/generator.qc @@ -4,16 +4,6 @@ bool generator_precached; .int count; .float max_health; -vector randompos(vector m1, vector m2) -{ - vector v; - m2 = m2 - m1; - v_x = m2_x * random() + m1_x; - v_y = m2_y * random() + m1_y; - v_z = m2_z * random() + m1_z; - return v; -} - void generator_precache() { if(generator_precached) diff --git a/qcsrc/client/hook.qc b/qcsrc/client/hook.qc index 3da79866d..ce6ca92b5 100644 --- a/qcsrc/client/hook.qc +++ b/qcsrc/client/hook.qc @@ -2,14 +2,12 @@ #include "_all.qh" #include "hud.qh" -#include "noise.qh" #include "../common/teams.qh" #include "../csqcmodellib/interpolate.qh" #include "../warpzonelib/common.qh" -#include "../warpzonelib/mathlib.qh" entityclass(Hook); class(Hook) .float HookType; // ENT_CLIENT_* @@ -18,33 +16,6 @@ class(Hook) .vector velocity; class(Hook) .float HookSilent; class(Hook) .float HookRange; -void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg) -{ - // I want to draw a quad... - // from and to are MIDPOINTS. - - vector axis, thickdir, A, B, C, D; - float length_tex; - - axis = normalize(to - from); - length_tex = aspect * vlen(to - from) / thickness; - - // direction is perpendicular to the view normal, and perpendicular to the axis - thickdir = normalize(cross(axis, vieworg - from)); - - A = from - thickdir * (thickness / 2); - B = from + thickdir * (thickness / 2); - C = to + thickdir * (thickness / 2); - D = to - thickdir * (thickness / 2); - - R_BeginPolygon(texture, drawflag); - R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, theAlpha); - R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha); - R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha); - R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha); - R_EndPolygon(); -} - string Draw_GrapplingHook_trace_callback_tex; float Draw_GrapplingHook_trace_callback_rnd; vector Draw_GrapplingHook_trace_callback_rgb; diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index f623e2706..32028ce42 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -4,7 +4,6 @@ #include "hud_config.qh" #include "mapvoting.qh" #include "scoreboard.qh" -#include "sortlist.qh" #include "teamradar.qh" #include "t_items.qh" @@ -23,7 +22,6 @@ #include "../csqcmodellib/cl_player.qh" -#include "../warpzonelib/mathlib.qh" /* ================== @@ -31,89 +29,6 @@ Misc HUD functions ================== */ -// a border picture is a texture containing nine parts: -// 1/4 width: left part -// 1/2 width: middle part (stretched) -// 1/4 width: right part -// divided into -// 1/4 height: top part -// 1/2 height: middle part (stretched) -// 1/4 height: bottom part -void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize) -{ - if (theBorderSize.x < 0 && theBorderSize.y < 0) // draw whole image as it is - { - drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0); - return; - } - if (theBorderSize.x == 0 && theBorderSize.y == 0) // no border - { - // draw only the central part - drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0); - return; - } - - vector dX, dY; - vector width, height; - vector bW, bH; - //pic = draw_UseSkinFor(pic); - width = eX * theSize.x; - height = eY * theSize.y; - if(theSize.x <= theBorderSize.x * 2) - { - // not wide enough... draw just left and right then - bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2)); - if(theSize.y <= theBorderSize.y * 2) - { - // not high enough... draw just corners - bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2)); - drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0); - drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0); - drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0); - drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0); - } - else - { - dY = theBorderSize.x * eY; - drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0); - drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0); - drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0); - drawsubpic(theOrigin + width * 0.5 + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0' + eX - bW, '0 0.5 0' + bW, theColor, theAlpha, 0); - drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0); - drawsubpic(theOrigin + width * 0.5 + height - dY, width * 0.5 + dY, pic, '0 0.75 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0); - } - } - else - { - if(theSize.y <= theBorderSize.y * 2) - { - // not high enough... draw just top and bottom then - bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2)); - dX = theBorderSize.x * eX; - drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0); - drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0); - drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0); - drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0); - drawsubpic(theOrigin + dX + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5 0 0' + bH, theColor, theAlpha, 0); - drawsubpic(theOrigin + width - dX + height * 0.5, dX + height * 0.5, pic, '0.75 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0); - } - else - { - dX = theBorderSize.x * eX; - dY = theBorderSize.x * eY; - drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0); - drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0); - drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0); - drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0); - drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0); - drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0); - drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0); - drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0); - drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0); - } - } -} - vector HUD_Get_Num_Color (float x, float maxvalue) { float blinkingamt; @@ -205,28 +120,6 @@ vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspe return eX * best_columns + eY * best_rows; } -float stringwidth_colors(string s, vector theSize) -{ - return stringwidth(s, true, theSize); -} - -float stringwidth_nocolors(string s, vector theSize) -{ - return stringwidth(s, false, theSize); -} - -void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag) -{ - position.x -= 2 / 3 * strlen(text) * theScale.x; - drawstring(position, text, theScale, rgb, theAlpha, flag); -} - -void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag) -{ - position.x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale.x); - drawstring(position, text, theScale, rgb, theAlpha, flag); -} - // return the string of the onscreen race timer string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname) { @@ -306,30 +199,6 @@ int race_CheckName(string net_name) return 0; } -int GetPlayerColorForce(int i) -{ - if(!teamplay) - return 0; - else - return stof(getplayerkeyvalue(i, "colors")) & 15; -} - -int GetPlayerColor(int i) -{ - if(!playerslots[i].gotscores) // unconnected - return NUM_SPECTATOR; - else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR) - return NUM_SPECTATOR; - else - return GetPlayerColorForce(i); -} - -string GetPlayerName(int i) -{ - return ColorTranslateRGB(getplayerkeyvalue(i, "name")); -} - - /* ================== HUD panels @@ -1947,18 +1816,6 @@ void HUD_Notify(void) notify_count = count; } -// Timer (#5) -// -// TODO: macro -string seconds_tostring(float sec) -{ - float minutes; - minutes = floor(sec / 60); - - sec -= minutes * 60; - return sprintf("%d:%02d", minutes, sec); -} - void HUD_Timer(void) { if(intermission == 2) return; diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 2309426ce..ed50dda37 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -16,7 +16,6 @@ #include "particles.qh" #include "scoreboard.qh" #include "shownames.qh" -#include "sortlist.qh" #include "tuba.qh" #include "t_items.qh" #include "wall.qh" diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index c9c599945..fbd98da95 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -2,7 +2,6 @@ #include "_all.qh" #include "hud.qh" -#include "sortlist.qh" #include "../common/command/generic.qh" @@ -11,7 +10,6 @@ #include "../csqcmodellib/cl_model.qh" -#include "../warpzonelib/mathlib.qh" void AuditLists() { @@ -168,14 +166,6 @@ vector rotate(vector v, float a) return w; } -string ColorTranslateRGB(string s) -{ - if(ColorTranslateMode & 1) - return strdecolorize(s); - else - return s; -} - // decolorizes and team colors the player name when needed string playername(string thename, float teamid) { diff --git a/qcsrc/client/miscfunctions.qh b/qcsrc/client/miscfunctions.qh index 0c2be7fc5..9ac46340d 100644 --- a/qcsrc/client/miscfunctions.qh +++ b/qcsrc/client/miscfunctions.qh @@ -34,7 +34,6 @@ float PreviewExists(string name); vector rotate(vector v, float a); -int ColorTranslateMode; string ColorTranslateRGB(string s); diff --git a/qcsrc/client/noise.qh b/qcsrc/client/noise.qh deleted file mode 100644 index 2b18adee5..000000000 --- a/qcsrc/client/noise.qh +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef NOISE_H -#define NOISE_H - -// noises "usually" start in the range -1..1 -float Noise_Brown(entity e, float dt); -float Noise_Pink(entity e, float dt); -float Noise_White(entity e, float dt); -float Noise_Burst(entity e, float dt, float p); // +1 or -1 -#endif diff --git a/qcsrc/client/progs.src b/qcsrc/client/progs.src index 6941d86da..506669602 100644 --- a/qcsrc/client/progs.src +++ b/qcsrc/client/progs.src @@ -22,13 +22,11 @@ mapvoting.qc miscfunctions.qc modeleffects.qc movelib.qc -noise.qc particles.qc player_skeleton.qc rubble.qc scoreboard.qc shownames.qc -sortlist.qc teamradar.qc tuba.qc t_items.qc @@ -49,7 +47,6 @@ weapons/projectile.qc // TODO ../common/notifications.qc ../common/physics.qc ../common/playerstats.qc -../common/p2mathlib.qc ../common/util.qc ../common/viewloc.qc @@ -77,7 +74,6 @@ weapons/projectile.qc // TODO ../warpzonelib/anglestransform.qc ../warpzonelib/client.qc ../warpzonelib/common.qc -../warpzonelib/mathlib.qc ../warpzonelib/util_server.qc ../../mod/client/progs.inc diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 1e2ef0baa..c635e9754 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -2,7 +2,6 @@ #include "_all.qh" #include "hud.qh" -#include "sortlist.qh" #include "../common/constants.qh" #include "../common/mapinfo.qh" diff --git a/qcsrc/client/teamradar.qc b/qcsrc/client/teamradar.qc index 874fec1f5..ab6129e78 100644 --- a/qcsrc/client/teamradar.qc +++ b/qcsrc/client/teamradar.qc @@ -7,21 +7,6 @@ #include "../csqcmodellib/interpolate.qh" -float vlen2d(vector v) -{ - return sqrt(v.x * v.x + v.y * v.y); -} - -float vlen_maxnorm2d(vector v) -{ - return max(v.x, v.y, -v.x, -v.y); -} - -float vlen_minnorm2d(vector v) -{ - return min(max(v.x, -v.x), max(v.y, -v.y)); -} - vector teamradar_3dcoord_to_texcoord(vector in) { vector out; diff --git a/qcsrc/client/teamradar.qh b/qcsrc/client/teamradar.qh index b2329cfb0..8aefc0fad 100644 --- a/qcsrc/client/teamradar.qh +++ b/qcsrc/client/teamradar.qh @@ -27,12 +27,6 @@ float hud_panel_radar_maximized_zoommode; float hud_panel_radar_maximized_rotation; -float vlen2d(vector v); - -float vlen_maxnorm2d(vector v); - -float vlen_minnorm2d(vector v); - vector teamradar_2dcoord_to_texcoord(vector in); vector teamradar_3dcoord_to_texcoord(vector in); diff --git a/qcsrc/client/tuba.qc b/qcsrc/client/tuba.qc index 0b300d3b2..2b9dcd0a8 100644 --- a/qcsrc/client/tuba.qc +++ b/qcsrc/client/tuba.qc @@ -4,7 +4,6 @@ #include "../common/constants.qh" #include "../common/util.qh" -#include "../warpzonelib/mathlib.qh" #define TUBA_STARTNOTE(i, n) W_Sound(strcat("tuba", (i ? ftos(i) : ""), "_loopnote", ftos(n))) diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 9b4eddd48..7720f58fb 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -5,7 +5,6 @@ #include "hud.qh" #include "hud_config.qh" #include "mapvoting.qh" -#include "noise.qh" #include "scoreboard.qh" #include "shownames.qh" @@ -25,7 +24,6 @@ #include "../warpzonelib/client.qh" #include "../warpzonelib/common.qh" -#include "../warpzonelib/mathlib.qh" entity porto; vector polyline[16]; diff --git a/qcsrc/common/command/rpn.qc b/qcsrc/common/command/rpn.qc index 700ceb46e..c975f98ea 100644 --- a/qcsrc/common/command/rpn.qc +++ b/qcsrc/common/command/rpn.qc @@ -1,7 +1,6 @@ #include "command.qh" #include "rpn.qh" -#include "../../warpzonelib/mathlib.qh" // ======================================== // RPN command code, written by divVerent diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index a85f09e1b..6d332d611 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -177,10 +177,6 @@ const int CTF_STATE_COMMANDER = 3; const int HUD_NORMAL = 0; const int HUD_BUMBLEBEE_GUN = 25; -const vector eX = '1 0 0'; -const vector eY = '0 1 0'; -const vector eZ = '0 0 1'; - // moved that here so the client knows the max. // # of maps, I'll use arrays for them :P const int MAPVOTE_COUNT = 30; diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 56d64f561..b6e2f348b 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -4,7 +4,6 @@ #include "../dpdefs/csprogsdefs.qh" #include "../client/defs.qh" #include "constants.qh" - #include "../warpzonelib/mathlib.qh" #include "../client/mutators/events.qh" #include "mapinfo.qh" #include "notifications.qh" @@ -13,7 +12,6 @@ #elif defined(SVQC) #include "../dpdefs/progsdefs.qh" #include "../dpdefs/dpextensions.qh" - #include "../warpzonelib/mathlib.qh" #include "constants.qh" #include "../server/autocvars.qh" #include "../server/defs.qh" diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 7d5ef31ee..046298a4c 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -9,7 +9,6 @@ #include "../constants.qh" #include "../stats.qh" #include "../../warpzonelib/anglestransform.qh" - #include "../../warpzonelib/mathlib.qh" #include "../../warpzonelib/common.qh" #include "../../warpzonelib/client.qh" #include "../util.qh" @@ -25,7 +24,6 @@ #include "../../dpdefs/progsdefs.qh" #include "../../dpdefs/dpextensions.qh" #include "../../warpzonelib/anglestransform.qh" - #include "../../warpzonelib/mathlib.qh" #include "../../warpzonelib/common.qh" #include "../../warpzonelib/util_server.qh" #include "../../warpzonelib/server.qh" diff --git a/qcsrc/csqcmodellib/cl_player.qc b/qcsrc/csqcmodellib/cl_player.qc index 30dab91f2..7cb3c2852 100644 --- a/qcsrc/csqcmodellib/cl_player.qc +++ b/qcsrc/csqcmodellib/cl_player.qc @@ -24,7 +24,6 @@ #include "../dpdefs/csprogsdefs.qh" #include "../client/defs.qh" #include "../common/constants.qh" - #include "../common/p2mathlib.qh" #include "../common/stats.qh" #include "../common/util.qh" #include "interpolate.qh" diff --git a/qcsrc/lib/Draw.qh b/qcsrc/lib/Draw.qh new file mode 100644 index 000000000..4ca536956 --- /dev/null +++ b/qcsrc/lib/Draw.qh @@ -0,0 +1,133 @@ +#ifdef CSQC +#ifndef DRAW_H +#define DRAW_H + +#include "I18N.qh" +#include "Vector.qh" + +#include "../client/defs.qh" + +void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, float shift, vector rgb, float theAlpha, float drawflag, vector vieworg) +{ + // I want to draw a quad... + // from and to are MIDPOINTS. + + vector axis, thickdir, A, B, C, D; + float length_tex; + + axis = normalize(to - from); + length_tex = aspect * vlen(to - from) / thickness; + + // direction is perpendicular to the view normal, and perpendicular to the axis + thickdir = normalize(cross(axis, vieworg - from)); + + A = from - thickdir * (thickness / 2); + B = from + thickdir * (thickness / 2); + C = to + thickdir * (thickness / 2); + D = to - thickdir * (thickness / 2); + + R_BeginPolygon(texture, drawflag); + R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, theAlpha); + R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha); + R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha); + R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha); + R_EndPolygon(); +} + +// a border picture is a texture containing nine parts: +// 1/4 width: left part +// 1/2 width: middle part (stretched) +// 1/4 width: right part +// divided into +// 1/4 height: top part +// 1/2 height: middle part (stretched) +// 1/4 height: bottom part +void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize) +{ + if (theBorderSize.x < 0 && theBorderSize.y < 0) // draw whole image as it is + { + drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0); + return; + } + if (theBorderSize.x == 0 && theBorderSize.y == 0) // no border + { + // draw only the central part + drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0); + return; + } + + vector dX, dY; + vector width, height; + vector bW, bH; + //pic = draw_UseSkinFor(pic); + width = eX * theSize.x; + height = eY * theSize.y; + if(theSize.x <= theBorderSize.x * 2) + { + // not wide enough... draw just left and right then + bW = eX * (0.25 * theSize.x / (theBorderSize.x * 2)); + if(theSize.y <= theBorderSize.y * 2) + { + // not high enough... draw just corners + bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2)); + drawsubpic(theOrigin, width * 0.5 + height * 0.5, pic, '0 0 0', bW + bH, theColor, theAlpha, 0); + drawsubpic(theOrigin + width * 0.5, width * 0.5 + height * 0.5, pic, eX - bW, bW + bH, theColor, theAlpha, 0); + drawsubpic(theOrigin + height * 0.5, width * 0.5 + height * 0.5, pic, eY - bH, bW + bH, theColor, theAlpha, 0); + drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0); + } + else + { + dY = theBorderSize.x * eY; + drawsubpic(theOrigin, width * 0.5 + dY, pic, '0 0 0', '0 0.25 0' + bW, theColor, theAlpha, 0); + drawsubpic(theOrigin + width * 0.5, width * 0.5 + dY, pic, '0 0 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0); + drawsubpic(theOrigin + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0', '0 0.5 0' + bW, theColor, theAlpha, 0); + drawsubpic(theOrigin + width * 0.5 + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0' + eX - bW, '0 0.5 0' + bW, theColor, theAlpha, 0); + drawsubpic(theOrigin + height - dY, width * 0.5 + dY, pic, '0 0.75 0', '0 0.25 0' + bW, theColor, theAlpha, 0); + drawsubpic(theOrigin + width * 0.5 + height - dY, width * 0.5 + dY, pic, '0 0.75 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0); + } + } + else + { + if(theSize.y <= theBorderSize.y * 2) + { + // not high enough... draw just top and bottom then + bH = eY * (0.25 * theSize.y / (theBorderSize.y * 2)); + dX = theBorderSize.x * eX; + drawsubpic(theOrigin, dX + height * 0.5, pic, '0 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0); + drawsubpic(theOrigin + dX, width - 2 * dX + height * 0.5, pic, '0.25 0 0', '0.5 0 0' + bH, theColor, theAlpha, 0); + drawsubpic(theOrigin + width - dX, dX + height * 0.5, pic, '0.75 0 0', '0.25 0 0' + bH, theColor, theAlpha, 0); + drawsubpic(theOrigin + height * 0.5, dX + height * 0.5, pic, '0 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0); + drawsubpic(theOrigin + dX + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5 0 0' + bH, theColor, theAlpha, 0); + drawsubpic(theOrigin + width - dX + height * 0.5, dX + height * 0.5, pic, '0.75 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0); + } + else + { + dX = theBorderSize.x * eX; + dY = theBorderSize.x * eY; + drawsubpic(theOrigin, dX + dY, pic, '0 0 0', '0.25 0.25 0', theColor, theAlpha, 0); + drawsubpic(theOrigin + dX, width - 2 * dX + dY, pic, '0.25 0 0', '0.5 0.25 0', theColor, theAlpha, 0); + drawsubpic(theOrigin + width - dX, dX + dY, pic, '0.75 0 0', '0.25 0.25 0', theColor, theAlpha, 0); + drawsubpic(theOrigin + dY, dX + height - 2 * dY, pic, '0 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0); + drawsubpic(theOrigin + dY + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0); + drawsubpic(theOrigin + dY + width - dX, dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5 0', theColor, theAlpha, 0); + drawsubpic(theOrigin + height - dY, dX + dY, pic, '0 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0); + drawsubpic(theOrigin + height - dY + dX, width - 2 * dX + dY, pic, '0.25 0.75 0', '0.5 0.25 0', theColor, theAlpha, 0); + drawsubpic(theOrigin + height - dY + width - dX, dX + dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0); + } + } +} + +void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag) +{ + position.x -= 2 / 3 * strlen(text) * theScale.x; + drawstring(position, text, theScale, rgb, theAlpha, flag); +} + +void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag) +{ + position.x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale.x); + drawstring(position, text, theScale, rgb, theAlpha, flag); +} + +#endif +#endif diff --git a/qcsrc/lib/Player.qh b/qcsrc/lib/Player.qh new file mode 100644 index 000000000..07034a066 --- /dev/null +++ b/qcsrc/lib/Player.qh @@ -0,0 +1,34 @@ +#ifdef CSQC +#ifndef PLAYER_H +#define PLAYER_H + +#include "String.qh" + +#include "../client/main.qh" +#include "../common/teams.qh" + +int GetPlayerColorForce(int i) +{ + if(!teamplay) + return 0; + else + return stof(getplayerkeyvalue(i, "colors")) & 15; +} + +int GetPlayerColor(int i) +{ + if(!playerslots[i].gotscores) // unconnected + return NUM_SPECTATOR; + else if(stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR) + return NUM_SPECTATOR; + else + return GetPlayerColorForce(i); +} + +string GetPlayerName(int i) +{ + return ColorTranslateRGB(getplayerkeyvalue(i, "name")); +} + +#endif +#endif diff --git a/qcsrc/lib/String.qh b/qcsrc/lib/String.qh new file mode 100644 index 000000000..faf81b29d --- /dev/null +++ b/qcsrc/lib/String.qh @@ -0,0 +1,38 @@ +#ifndef STRING_H +#define STRING_H + +#ifndef SVQC +float stringwidth_colors(string s, vector theSize) +{ + return stringwidth(s, true, theSize); +} + +float stringwidth_nocolors(string s, vector theSize) +{ + return stringwidth(s, false, theSize); +} +#endif + +// Timer (#5) +// +// TODO: macro +string seconds_tostring(float sec) +{ + float minutes; + minutes = floor(sec / 60); + + sec -= minutes * 60; + return sprintf("%d:%02d", minutes, sec); +} + +int ColorTranslateMode; + +string ColorTranslateRGB(string s) +{ + if(ColorTranslateMode & 1) + return strdecolorize(s); + else + return s; +} + +#endif diff --git a/qcsrc/lib/Vector.qh b/qcsrc/lib/Vector.qh new file mode 100644 index 000000000..d81a79571 --- /dev/null +++ b/qcsrc/lib/Vector.qh @@ -0,0 +1,34 @@ +#ifndef VECTOR_H +#define VECTOR_H + +const vector eX = '1 0 0'; +const vector eY = '0 1 0'; +const vector eZ = '0 0 1'; + +vector randompos(vector m1, vector m2) +{ + vector v; + m2 = m2 - m1; + v_x = m2_x * random() + m1_x; + v_y = m2_y * random() + m1_y; + v_z = m2_z * random() + m1_z; + return v; +} + +float vlen2d(vector v) +{ + return sqrt(v.x * v.x + v.y * v.y); +} + +float vlen_maxnorm2d(vector v) +{ + return max(v.x, v.y, -v.x, -v.y); +} + +float vlen_minnorm2d(vector v) +{ + return min(max(v.x, -v.x), max(v.y, -v.y)); +} + + +#endif diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 108790668..a3bcbcb5c 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -1,12 +1,21 @@ +#include "../warpzonelib/mathlib.qc" + #include "Accumulate.qh" #include "Counting.qh" #include "Cvar.qh" +#include "Draw.qh" #include "I18N.qh" #include "Lazy.qh" #include "Nil.qh" +#include "noise.qc" #include "OO.qh" +#include "p2mathlib.qc" +#include "Player.qh" #include "prandom.qc" #include "Progname.qh" #include "Registry.qh" +#include "sortlist.qc" +#include "String.qh" #include "test.qc" #include "urllib.qc" +#include "Vector.qh" diff --git a/qcsrc/client/noise.qc b/qcsrc/lib/noise.qc similarity index 94% rename from qcsrc/client/noise.qc rename to qcsrc/lib/noise.qc index 2047410a9..5bd6ad650 100644 --- a/qcsrc/client/noise.qc +++ b/qcsrc/lib/noise.qc @@ -1,6 +1,4 @@ -#include "noise.qh" -#include "_all.qh" - +// noises "usually" start in the range -1..1 entityclass(Noise); class(Noise) .float noise_baccum; class(Noise) .float noise_paccum; @@ -30,6 +28,7 @@ float Noise_White(entity e, float dt) { return random() * 2 - 1; } +/** +1 or -1 */ float Noise_Burst(entity e, float dt, float p) { if(random() > pow(p, dt)) diff --git a/qcsrc/common/p2mathlib.qc b/qcsrc/lib/p2mathlib.qc similarity index 100% rename from qcsrc/common/p2mathlib.qc rename to qcsrc/lib/p2mathlib.qc diff --git a/qcsrc/common/p2mathlib.qh b/qcsrc/lib/p2mathlib.qh similarity index 100% rename from qcsrc/common/p2mathlib.qh rename to qcsrc/lib/p2mathlib.qh diff --git a/qcsrc/lib/prandom.qc b/qcsrc/lib/prandom.qc index 8b1f8d938..975080a71 100644 --- a/qcsrc/lib/prandom.qc +++ b/qcsrc/lib/prandom.qc @@ -1,7 +1,5 @@ #include "prandom.qh" -#include "../warpzonelib/mathlib.qh" - // prandom - PREDICTABLE random number generator (not seeded yet) #ifdef USE_PRANDOM diff --git a/qcsrc/client/sortlist.qc b/qcsrc/lib/sortlist.qc similarity index 98% rename from qcsrc/client/sortlist.qc rename to qcsrc/lib/sortlist.qc index 4d05d2c5f..fcaf6be50 100644 --- a/qcsrc/client/sortlist.qc +++ b/qcsrc/lib/sortlist.qc @@ -4,7 +4,7 @@ entity Sort_Spawn() { entity sort; sort = spawn(); - sort.sort_next = world; + sort.sort_next = NULL; sort.chain = sort; return sort; } diff --git a/qcsrc/client/sortlist.qh b/qcsrc/lib/sortlist.qh similarity index 90% rename from qcsrc/client/sortlist.qh rename to qcsrc/lib/sortlist.qh index 298314810..d4a1f183e 100644 --- a/qcsrc/client/sortlist.qh +++ b/qcsrc/lib/sortlist.qh @@ -3,7 +3,7 @@ entityclass(Sort); //.float(entity,entity) sort_cmp; -class(Sort) .entity sort_next, sort_prev; +class(Sort) .entity chain, sort_next, sort_prev; entity Sort_Spawn(); diff --git a/qcsrc/menu/progs.src b/qcsrc/menu/progs.src index 600e326a3..92b10fa4c 100644 --- a/qcsrc/menu/progs.src +++ b/qcsrc/menu/progs.src @@ -28,6 +28,5 @@ xonotic/util.qc ../common/vehicles/all.qc ../common/weapons/all.qc -../warpzonelib/mathlib.qc ../../mod/menu/progs.inc diff --git a/qcsrc/menu/xonotic/slider_decibels.qc b/qcsrc/menu/xonotic/slider_decibels.qc index 3d8cf1da4..b40488ef4 100644 --- a/qcsrc/menu/xonotic/slider_decibels.qc +++ b/qcsrc/menu/xonotic/slider_decibels.qc @@ -1,5 +1,3 @@ -#include "../../warpzonelib/mathlib.qh" - #ifndef SLIDER_DECIBELS_H #define SLIDER_DECIBELS_H #include "slider.qc" diff --git a/qcsrc/server/anticheat.qc b/qcsrc/server/anticheat.qc index 1e6759684..d065cb59f 100644 --- a/qcsrc/server/anticheat.qc +++ b/qcsrc/server/anticheat.qc @@ -8,7 +8,6 @@ #include "../dpdefs/progsdefs.qh" #include "../dpdefs/dpextensions.qh" -#include "../warpzonelib/mathlib.qh" #include "command/common.qh" diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index 0bf2df320..29e75b63b 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -31,7 +31,6 @@ #include "../../common/monsters/sv_monsters.qh" -#include "../../warpzonelib/mathlib.qh" void PutObserverInServer (void); diff --git a/qcsrc/server/mutators/gamemode.qh b/qcsrc/server/mutators/gamemode.qh index d272af857..d2066b9ab 100644 --- a/qcsrc/server/mutators/gamemode.qh +++ b/qcsrc/server/mutators/gamemode.qh @@ -36,7 +36,6 @@ #include "../../common/stats.qh" #include "../../common/teams.qh" -#include "../../warpzonelib/mathlib.qh" #include "../../warpzonelib/server.qh" #include "../../warpzonelib/util_server.qh" diff --git a/qcsrc/server/mutators/gamemode_ctf.qc b/qcsrc/server/mutators/gamemode_ctf.qc index 6ebf651f2..d6859bee3 100644 --- a/qcsrc/server/mutators/gamemode_ctf.qc +++ b/qcsrc/server/mutators/gamemode_ctf.qc @@ -8,7 +8,6 @@ #endif #include "../../warpzonelib/common.qh" -#include "../../warpzonelib/mathlib.qh" void ctf_FakeTimeLimit(entity e, float t) { diff --git a/qcsrc/server/mutators/gamemode_onslaught.qc b/qcsrc/server/mutators/gamemode_onslaught.qc index 73c37997a..708683e67 100644 --- a/qcsrc/server/mutators/gamemode_onslaught.qc +++ b/qcsrc/server/mutators/gamemode_onslaught.qc @@ -4,16 +4,6 @@ #include "../controlpoint.qh" #include "../generator.qh" -vector randompos(vector m1, vector m2) -{ - vector v; - m2 = m2 - m1; - v_x = m2_x * random() + m1_x; - v_y = m2_y * random() + m1_y; - v_z = m2_z * random() + m1_z; - return v; -} - // ======================= // CaptureShield Functions // ======================= diff --git a/qcsrc/server/mutators/mutator.qh b/qcsrc/server/mutators/mutator.qh index fa4c9ec8f..39adb175c 100644 --- a/qcsrc/server/mutators/mutator.qh +++ b/qcsrc/server/mutators/mutator.qh @@ -39,7 +39,6 @@ #include "../../common/monsters/all.qh" #include "../../warpzonelib/anglestransform.qh" -#include "../../warpzonelib/mathlib.qh" #include "../../warpzonelib/server.qh" #include "../../warpzonelib/util_server.qh" diff --git a/qcsrc/server/mutators/mutators_include.qc b/qcsrc/server/mutators/mutators_include.qc index c5b1ce2ca..aaedcba8b 100644 --- a/qcsrc/server/mutators/mutators_include.qc +++ b/qcsrc/server/mutators/mutators_include.qc @@ -4,7 +4,6 @@ #include "../../dpdefs/progsdefs.qh" #include "../../dpdefs/dpextensions.qh" #include "../../warpzonelib/anglestransform.qh" - #include "../../warpzonelib/mathlib.qh" #include "../../warpzonelib/common.qh" #include "../../warpzonelib/util_server.qh" #include "../../warpzonelib/server.qh" diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src index 9dd0fae9b..22afdf411 100644 --- a/qcsrc/server/progs.src +++ b/qcsrc/server/progs.src @@ -97,7 +97,6 @@ weapons/weaponsystem.qc ../common/notifications.qc ../common/physics.qc ../common/playerstats.qc -../common/p2mathlib.qc ../common/viewloc.qc ../common/triggers/include.qc ../common/util.qc @@ -120,7 +119,6 @@ weapons/weaponsystem.qc ../warpzonelib/anglestransform.qc ../warpzonelib/common.qc -../warpzonelib/mathlib.qc ../warpzonelib/server.qc ../warpzonelib/util_server.qc diff --git a/qcsrc/server/t_plats.qc b/qcsrc/server/t_plats.qc index b93b1d577..41354bf8a 100644 --- a/qcsrc/server/t_plats.qc +++ b/qcsrc/server/t_plats.qc @@ -17,7 +17,6 @@ #include "../csqcmodellib/sv_model.qh" #include "../warpzonelib/common.qh" -#include "../warpzonelib/mathlib.qh" #include "../warpzonelib/util_server.qh" .float height; -- 2.39.2