From 6e27fadc1895c26850fae2ef49261677599c37b7 Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 5 May 2009 07:55:47 +0000 Subject: [PATCH] CPMA-style cl_movement physics settings possible! Variables for it: sv_aircontrol sv_maxairstrafespeed sv_airstrafeaccel sv_airstopaccel git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8944 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_input.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- client.h | 4 ++++ quakedef.h | 4 ++++ server.h | 4 ++++ sv_main.c | 12 ++++++++++++ 5 files changed, 78 insertions(+), 2 deletions(-) diff --git a/cl_input.c b/cl_input.c index 6edee3ef..a9da42cc 100644 --- a/cl_input.c +++ b/cl_input.c @@ -964,6 +964,30 @@ void CL_ClientMovement_Physics_Swim(cl_clientmovement_state_t *s) CL_ClientMovement_Move(s); } +void CL_ClientMovement_Physics_CPM_PM_Aircontrol(cl_clientmovement_state_t *s, vec3_t wishdir, vec_t wishspeed) +{ + vec_t zspeed, speed, dot, k; + + if(s->cmd.forwardmove == 0 || s->cmd.sidemove != 0) + return; + + zspeed = s->velocity[2]; + s->velocity[2] = 0; + speed = VectorNormalizeLength(s->velocity); + + dot = DotProduct(s->velocity, wishdir); + k = 32; + k *= cl.movevars_aircontrol*dot*dot*s->cmd.frametime; + + if(dot > 0) { // we can't change direction while slowing down + VectorMAM(speed, s->velocity, k, wishdir, s->velocity); + VectorNormalize(s->velocity); + } + + VectorScale(s->velocity, speed, s->velocity); + s->velocity[2] = zspeed; +} + void CL_ClientMovement_Physics_Walk(cl_clientmovement_state_t *s) { vec_t friction; @@ -1057,9 +1081,26 @@ void CL_ClientMovement_Physics_Walk(cl_clientmovement_state_t *s) vec_t vel_straight; vec_t vel_z; vec3_t vel_perpend; + float wishspeed2, accel; // apply air speed limit wishspeed = min(wishspeed, cl.movevars_maxairspeed); + accel = cl.movevars_airaccelerate; + + // CPM: air control + wishspeed2 = wishspeed; + if(cl.movevars_airstopaccelerate != 0) + if(DotProduct(s->velocity, wishdir) < 0) + accel = cl.movevars_airstopaccelerate; + if(s->cmd.forwardmove == 0 && s->cmd.sidemove != 0) + { + if(cl.movevars_maxairstrafespeed) + if(wishspeed > cl.movevars_maxairstrafespeed) + wishspeed = cl.movevars_maxairstrafespeed; + if(cl.movevars_airstrafeaccelerate) + accel = cl.movevars_airstrafeaccelerate; + } + // !CPM /* addspeed = wishspeed - DotProduct(s->velocity, wishdir); @@ -1077,14 +1118,17 @@ void CL_ClientMovement_Physics_Walk(cl_clientmovement_state_t *s) f = wishspeed - vel_straight; if(f > 0) - vel_straight += min(f, cl.movevars_airaccelerate * s->cmd.frametime * wishspeed) * cl.movevars_airaccel_qw; + vel_straight += min(f, accel * s->cmd.frametime * wishspeed) * cl.movevars_airaccel_qw; if(wishspeed > 0) - vel_straight += min(wishspeed, cl.movevars_airaccelerate * s->cmd.frametime * wishspeed) * (1 - cl.movevars_airaccel_qw); + vel_straight += min(wishspeed, accel * s->cmd.frametime * wishspeed) * (1 - cl.movevars_airaccel_qw); VectorM(1 - (s->cmd.frametime * (wishspeed / cl.movevars_maxairspeed) * cl.movevars_airaccel_sideways_friction), vel_perpend, vel_perpend); VectorMA(vel_perpend, vel_straight, wishdir, s->velocity); s->velocity[2] += vel_z; + + if(cl.movevars_aircontrol) + CL_ClientMovement_Physics_CPM_PM_Aircontrol(s, wishdir, wishspeed2); } s->velocity[2] -= cl.movevars_gravity * cl.movevars_entgravity * s->cmd.frametime; CL_ClientMovement_Move(s); @@ -1130,6 +1174,10 @@ void CL_UpdateMoveVars(void) cl.movevars_friction = cl.statsf[STAT_MOVEVARS_FRICTION]; cl.movevars_wallfriction = cl.statsf[STAT_MOVEVARS_WALLFRICTION]; cl.movevars_waterfriction = cl.statsf[STAT_MOVEVARS_WATERFRICTION]; + cl.movevars_airstopaccelerate = cl.statsf[STAT_MOVEVARS_AIRSTOPACCELERATE]; + cl.movevars_airstrafeaccelerate = cl.statsf[STAT_MOVEVARS_AIRSTRAFEACCELERATE]; + cl.movevars_maxairstrafespeed = cl.statsf[STAT_MOVEVARS_MAXAIRSTRAFESPEED]; + cl.movevars_aircontrol = cl.statsf[STAT_MOVEVARS_AIRCONTROL]; } else { @@ -1151,6 +1199,10 @@ void CL_UpdateMoveVars(void) cl.movevars_stepheight = cl_movement_stepheight.value; cl.movevars_airaccel_qw = cl_movement_airaccel_qw.value; cl.movevars_airaccel_sideways_friction = cl_movement_airaccel_sideways_friction.value; + cl.movevars_airstopaccelerate = 0; + cl.movevars_airstrafeaccelerate = 0; + cl.movevars_maxairstrafespeed = 0; + cl.movevars_aircontrol = 0; } } diff --git a/client.h b/client.h index 16427924..e470b9a5 100644 --- a/client.h +++ b/client.h @@ -1058,6 +1058,10 @@ typedef struct client_state_s float movevars_stepheight; float movevars_airaccel_qw; float movevars_airaccel_sideways_friction; + float movevars_airstopaccelerate; + float movevars_airstrafeaccelerate; + float movevars_maxairstrafespeed; + float movevars_aircontrol; // models used by qw protocol int qw_modelindex_spike; diff --git a/quakedef.h b/quakedef.h index 6dc94ef1..74ccc6d8 100644 --- a/quakedef.h +++ b/quakedef.h @@ -103,6 +103,10 @@ extern char engineversion[128]; //#define STAT_TIME 17 // FTE //#define STAT_VIEW2 20 // FTE #define STAT_VIEWZOOM 21 // DP +#define STAT_MOVEVARS_AIRSTOPACCELERATE 231 // DP +#define STAT_MOVEVARS_AIRSTRAFEACCELERATE 232 // DP +#define STAT_MOVEVARS_MAXAIRSTRAFESPEED 233 // DP +#define STAT_MOVEVARS_AIRCONTROL 234 // DP #define STAT_FRAGLIMIT 235 // DP #define STAT_TIMELIMIT 236 // DP #define STAT_MOVEVARS_WALLFRICTION 237 // DP diff --git a/server.h b/server.h index 86e07a76..03d92650 100644 --- a/server.h +++ b/server.h @@ -371,6 +371,10 @@ extern cvar_t sv_aim; extern cvar_t sv_airaccel_qw; extern cvar_t sv_airaccel_sideways_friction; extern cvar_t sv_airaccelerate; +extern cvar_t sv_airstopaccelerate; +extern cvar_t sv_airstrafeaccelerate; +extern cvar_t sv_maxairstrafespeed; +extern cvar_t sv_aircontrol; extern cvar_t sv_allowdownloads; extern cvar_t sv_allowdownloads_archive; extern cvar_t sv_allowdownloads_config; diff --git a/sv_main.c b/sv_main.c index 6e47d014..1bff0932 100644 --- a/sv_main.c +++ b/sv_main.c @@ -50,6 +50,10 @@ cvar_t sv_aim = {CVAR_SAVE, "sv_aim", "2", "maximum cosine angle for quake's ver cvar_t sv_airaccel_qw = {0, "sv_airaccel_qw", "1", "ratio of QW-style air control as opposed to simple acceleration"}; cvar_t sv_airaccel_sideways_friction = {0, "sv_airaccel_sideways_friction", "", "anti-sideways movement stabilization (reduces speed gain when zigzagging)"}; cvar_t sv_airaccelerate = {0, "sv_airaccelerate", "-1", "rate at which a player accelerates to sv_maxairspeed while in the air, if less than 0 the sv_accelerate variable is used instead"}; +cvar_t sv_airstopaccelerate = {0, "sv_airstopaccelerate", "0", "when set, replacement for sv_airaccelerate when moving backwards"}; +cvar_t sv_airstrafeaccelerate = {0, "sv_airstrafeaccelerate", "0", "when set, replacement for sv_airaccelerate when just strafing"}; +cvar_t sv_maxairstrafespeed = {0, "sv_maxairstrafespeed", "0", "when set, replacement for sv_maxairspeed when just strafing"}; +cvar_t sv_aircontrol = {0, "sv_aircontrol", "0", "CPMA-style air control"}; cvar_t sv_allowdownloads = {0, "sv_allowdownloads", "1", "whether to allow clients to download files from the server (does not affect http downloads)"}; cvar_t sv_allowdownloads_archive = {0, "sv_allowdownloads_archive", "0", "whether to allow downloads of archives (pak/pk3)"}; cvar_t sv_allowdownloads_config = {0, "sv_allowdownloads_config", "0", "whether to allow downloads of config files (cfg)"}; @@ -329,6 +333,10 @@ void SV_Init (void) Cvar_RegisterVariable (&sv_airaccel_qw); Cvar_RegisterVariable (&sv_airaccel_sideways_friction); Cvar_RegisterVariable (&sv_airaccelerate); + Cvar_RegisterVariable (&sv_airstopaccelerate); + Cvar_RegisterVariable (&sv_airstrafeaccelerate); + Cvar_RegisterVariable (&sv_maxairstrafespeed); + Cvar_RegisterVariable (&sv_aircontrol); Cvar_RegisterVariable (&sv_allowdownloads); Cvar_RegisterVariable (&sv_allowdownloads_archive); Cvar_RegisterVariable (&sv_allowdownloads_config); @@ -1656,6 +1664,10 @@ void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t statsf[STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION] = sv_airaccel_sideways_friction.value; statsf[STAT_MOVEVARS_FRICTION] = sv_friction.value; statsf[STAT_MOVEVARS_WATERFRICTION] = sv_waterfriction.value >= 0 ? sv_waterfriction.value : sv_friction.value; + statsf[STAT_MOVEVARS_AIRSTOPACCELERATE] = sv_airstopaccelerate.value; + statsf[STAT_MOVEVARS_AIRSTRAFEACCELERATE] = sv_airstrafeaccelerate.value; + statsf[STAT_MOVEVARS_MAXAIRSTRAFESPEED] = sv_maxairstrafespeed.value; + statsf[STAT_MOVEVARS_AIRCONTROL] = sv_aircontrol.value; statsf[STAT_FRAGLIMIT] = fraglimit.value; statsf[STAT_TIMELIMIT] = timelimit.value; -- 2.39.2