From 4e7de6bf2bdc06275b92f7988b08caafaa70fb99 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Sun, 26 Jul 2020 16:00:12 +0000 Subject: [PATCH] sv_ccmds: Partially rewrite ent_create command to be entirely serverside It will now use serverside functionality to generate the view matrix used to trace a line. Client involvement is no longer necessary. Also removed CL_TraceLine_FromViewOrigin git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12879 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_cmd.c | 24 ------------------------ cl_collision.c | 12 ------------ cl_collision.h | 1 - sbar.c | 2 +- sv_ccmds.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 5 files changed, 42 insertions(+), 43 deletions(-) diff --git a/cl_cmd.c b/cl_cmd.c index 01ba68a7..e8f90268 100644 --- a/cl_cmd.c +++ b/cl_cmd.c @@ -633,29 +633,6 @@ static void CL_PingPLReport_f(cmd_state_t *cmd) } } -static void CL_Ent_Create_f(cmd_state_t *cmd) -{ - trace_t trace; - char vabuf[MAX_INPUTLINE]; - - if(Cmd_Argc(cmd) < 1) - return; - - if(!strstr(Cmd_Args(cmd), "origin")) - { - // Get coordinates where the player is aiming. - trace = CL_TraceLine_FromViewOrigin(MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID, 0, 0, collision_extendmovelength.value, true, false, NULL, false, true); - dpsnprintf(vabuf, sizeof(vabuf), "ent_create %s origin \"%g %g %g\"", Cmd_Args(cmd), trace.endpos[0], trace.endpos[1], trace.endpos[2]); - } - else - { - // Unless we're setting origin manually. - dpsnprintf(vabuf, sizeof(vabuf), "ent_create %s", Cmd_Args(cmd)); - } - - CL_ForwardToServer(vabuf); -} - void CL_InitCommands(void) { dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\dp"); @@ -693,5 +670,4 @@ void CL_InitCommands(void) // commands that are only sent by server to client for execution Cmd_AddCommand(CMD_CLIENT_FROM_SERVER, "pingplreport", CL_PingPLReport_f, "command sent by server containing client ping and packet loss values for scoreboard, triggered by pings command from client (not used by QW servers)"); Cmd_AddCommand(CMD_CLIENT_FROM_SERVER, "fullserverinfo", CL_FullServerinfo_f, "internal use only, sent by server to client to update client's local copy of serverinfo string"); - Cmd_AddCommand(CMD_CLIENT, "ent_create", CL_Ent_Create_f, "Creates an entity at the specified coordinate, of the specified classname. If executed from a server, origin has to be specified manually."); } diff --git a/cl_collision.c b/cl_collision.c index 6c9b8c4c..924d017c 100644 --- a/cl_collision.c +++ b/cl_collision.c @@ -643,18 +643,6 @@ finished: return cliptrace; } -trace_t CL_TraceLine_FromViewOrigin(int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities, qboolean hitsurfaces) -{ - vec3_t org, temp, dest; - - Matrix4x4_OriginFromMatrix(&r_refdef.view.matrix, org); - VectorSet(temp, 65536, 0, 0); - Matrix4x4_Transform(&r_refdef.view.matrix, temp, dest); - - return CL_TraceLine(org, dest, type, passedict, hitsupercontentsmask, skipsupercontentsmask, skipmaterialflagsmask, extend, hitnetworkbrushmodels, hitnetworkplayers, hitnetworkentity, hitcsqcentities, hitsurfaces); - -} - /* ================== CL_Move diff --git a/cl_collision.h b/cl_collision.h index 4f0d32ad..20ce9f65 100644 --- a/cl_collision.h +++ b/cl_collision.h @@ -12,7 +12,6 @@ void CL_LinkEdict(prvm_edict_t *ent); int CL_GenericHitSuperContentsMask(const prvm_edict_t *edict); trace_t CL_TraceBox(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities); trace_t CL_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities, qboolean hitsurfaces); -trace_t CL_TraceLine_FromViewOrigin(int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities, qboolean hitsurfaces); trace_t CL_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, qboolean hitnetworkbrushmodels, qboolean hitnetworkplayers, int *hitnetworkentity, qboolean hitcsqcentities); trace_t CL_Cache_TraceLineSurfaces(const vec3_t start, const vec3_t end, int type, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); #define CL_PointSuperContents(point) (CL_TracePoint((point), sv_gameplayfix_swiminbmodels.integer ? MOVE_NOMONSTERS : MOVE_WORLDONLY, NULL, 0, 0, 0, true, false, NULL, false).startsupercontents) diff --git a/sbar.c b/sbar.c index b6903ba0..7c8df4b9 100644 --- a/sbar.c +++ b/sbar.c @@ -1217,7 +1217,7 @@ void Sbar_ShowFPS(void) vec3_t temp; trace_t svtrace, cltrace; int hitnetentity = -1; - // TODO: Use CL_TraceLine_FromViewOrigin + Matrix4x4_OriginFromMatrix(&r_refdef.view.matrix, org); VectorSet(temp, 65536, 0, 0); Matrix4x4_Transform(&r_refdef.view.matrix, temp, dest); diff --git a/sv_ccmds.c b/sv_ccmds.c index f15f2f4b..f57c20c7 100644 --- a/sv_ccmds.c +++ b/sv_ccmds.c @@ -1510,15 +1510,49 @@ static void SV_SendCvar_f(cmd_state_t *cmd) static void SV_Ent_Create_f(cmd_state_t *cmd) { prvm_prog_t *prog = SVVM_prog; + prvm_edict_t *ed; ddef_t *key; int i; - qboolean expectval = false, haveorigin = false; + qboolean haveorigin; + + qboolean expectval = false; void (*print)(const char *, ...) = (cmd->source == src_client ? SV_ClientPrintf : Con_Printf); - prvm_edict_t *ed = PRVM_ED_Alloc(SVVM_prog); + if(!Cmd_Argc(cmd)) + return; + + ed = PRVM_ED_Alloc(SVVM_prog); PRVM_ED_ParseEpair(prog, ed, PRVM_ED_FindField(prog, "classname"), Cmd_Argv(cmd, 1), false); + // Spawn where the player is aiming. We need a view matrix first. + if(cmd->source == src_client) + { + vec3_t org, temp, dest; + matrix4x4_t view; + trace_t trace; + char buf[128]; + + SV_GetEntityMatrix(prog, host_client->edict, &view, true); + + Matrix4x4_OriginFromMatrix(&view, org); + VectorSet(temp, 65536, 0, 0); + Matrix4x4_Transform(&view, temp, dest); + + trace = SV_TraceLine(org, dest, MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID, 0, 0, collision_extendmovelength.value); + + dpsnprintf(buf, sizeof(buf), "%g %g %g", trace.endpos[0], trace.endpos[1], trace.endpos[2]); + PRVM_ED_ParseEpair(prog, ed, PRVM_ED_FindField(prog, "origin"), buf, false); + + haveorigin = true; + } + // Or spawn at a specified origin. + else + { + print = Con_Printf; + haveorigin = false; + } + // Allow more than one key/value pair by cycling between expecting either one. for(i = 2; i < Cmd_Argc(cmd); i++) { @@ -1531,7 +1565,11 @@ static void SV_Ent_Create_f(cmd_state_t *cmd) return; } - if(!strcmp(Cmd_Argv(cmd, i), "origin") && !haveorigin) + /* + * This is mostly for dedicated server console, but if the + * player gave a custom origin, we can ignore the traceline. + */ + if(!strcmp(Cmd_Argv(cmd, i), "origin")) haveorigin = true; expectval = true; @@ -1546,8 +1584,6 @@ static void SV_Ent_Create_f(cmd_state_t *cmd) if(!haveorigin) { print("Missing origin\n"); - if(cmd->source == src_client) - print("This should never happen if you're a player. Please report this to a developer.\n"); PRVM_ED_Free(prog, ed); return; } -- 2.39.2