Decouple Camera/Viewmodel effects from src/ into base/src/

This commit is contained in:
Marco Cawthorne 2021-08-01 08:53:21 +02:00
parent 3ef55c5e48
commit 1ec3cf2e8e
7 changed files with 96 additions and 107 deletions

View File

@ -28,7 +28,7 @@ struct
void
Camera_RunBob(__inout vector camera_angle)
{
if (!autocvar(v_cambob, 0, "Enables bobbing effect for the first-person camera"))
if (!autocvar(v_cambob, 1, "Enables bobbing effect for the first-person camera"))
return;
int s = (float)getproperty(VF_ACTIVESEAT);
@ -66,7 +66,7 @@ Camera_RunBob(__inout vector camera_angle)
void
Camera_StrafeRoll(__inout vector camera_angle)
{
if (!autocvar(v_camroll, 1, "Enables strafe-roll for the first-person camera"))
if (!autocvar(v_camroll, 0, "Enables strafe-roll for the first-person camera"))
return;
float roll;

View File

@ -30,6 +30,8 @@ player.qc
entities.qc
cmds.qc
game_event.qc
camera.qc
viewmodel.qc
view.qc
hud.qc
hud_weaponselect.qc

View File

@ -14,96 +14,21 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
var float autocvar_v_bob = 0.01;
var float autocvar_v_bobcycle = 0.8;
var float autocvar_v_bobup = 0.5;
var int autocvar_v_bobstyle = 1;
enum
{
BOB_NONE,
BOB_CLASSIC,
BOB_VISIONS
};
var float autocvar_v_bob = 0.01f;
var float autocvar_v_bobcycle = 1.0f;
var float autocvar_v_bobup = 0.5f;
struct
{
float m_flBobTime;
float m_flBobTime2;
float m_flBob;
float m_flBob2;
float m_flBobCycle;
float m_flBobCycle2;
float m_flSpeed;
} g_viewBobVars[4], *pViewBob;
/* classic bob, similar to Q1 and HL */
void
Viewmodel_ClassicBobCalc(void)
{
vector vel;
pViewBob->m_flBobTime += clframetime;
pViewBob->m_flBobCycle = pViewBob->m_flBobTime - (int)(pViewBob->m_flBobTime / autocvar_v_bobcycle) * autocvar_v_bobcycle;
pViewBob->m_flBobCycle /= autocvar_v_bobcycle;
if (pViewBob->m_flBobCycle < autocvar_v_bobup) {
pViewBob->m_flBobCycle = MATH_PI * pViewBob->m_flBobCycle / autocvar_v_bobup;
} else {
pViewBob->m_flBobCycle = MATH_PI + MATH_PI * (pViewBob->m_flBobCycle - autocvar_v_bobup)/(1.0 - autocvar_v_bobup);
}
vel = pSeat->m_vecPredictedVelocity;
vel[2] = 0;
pViewBob->m_flSpeed = vlen(vel);
float flBob = pViewBob->m_flSpeed * autocvar_v_bob;
flBob = flBob * 0.3 + flBob * 0.7 * sin(pViewBob->m_flBobCycle);
pViewBob->m_flBob = bound(-7, flBob, 4);
}
void
Viewmodel_ClassicBobRun(entity gun)
{
// Give the gun a tilt effect like in old HL/CS versions
if (autocvar(v_bobclassic, 1, "Viewmodel bob classic tilt switch") == 1) {
gun.angles[2] = -pViewBob->m_flBob;
}
gun.origin += [0,0,-1] + (v_forward * (pViewBob->m_flBob * 0.4))
+ (v_forward * autocvar_v_gunofs[0])
+ (v_right * autocvar_v_gunofs[1])
+ (v_up * autocvar_v_gunofs[2]);
}
/* Vera Visions signature bob */
void
Viewmodel_VisionsBobCalc(void)
{
/* same for now */
Viewmodel_ClassicBobCalc();
}
void
Viewmodel_VisionsBobRun(entity gun)
{
float sintime;
float strength;
gun.angles[2] = -pViewBob->m_flBob;
vector angmod;
angmod[0] += pViewBob->m_flBob * 0.5f;
angmod[1] += pViewBob->m_flBob;
angmod[2] += pViewBob->m_flBob * 2.5f;
gun.angles += angmod * 1.5f;
/* sway with speed */
sintime = sin(time);
strength = pViewBob->m_flSpeed * 0.01f;
gun.angles[0] += strength * sintime;
gun.angles[1] += strength * sintime;
gun.angles[2] += strength * sintime;
gun.origin += [0,0,-1];
}
/* bob vars are calculated separately from application, so that if there's
* more than one viewmodel we won't affect the speed of the bob by running
@ -114,18 +39,50 @@ Viewmodel_CalcBob(void)
int s = (float)getproperty(VF_ACTIVESEAT);
pViewBob = &g_viewBobVars[s];
switch (autocvar_v_bobstyle)
{
case BOB_CLASSIC:
Viewmodel_ClassicBobCalc();
break;
case BOB_VISIONS:
Viewmodel_VisionsBobCalc();
break;
default:
break;
vector vecVel;
float flBob;
float var_bob;
float var_cycle;
float var_up;
var_bob = autocvar_v_bob;
var_cycle = autocvar_v_bobcycle;
var_up = autocvar_v_bobup;
pViewBob->m_flBobTime += clframetime;
pViewBob->m_flBobTime2 += clframetime;
pViewBob->m_flBobCycle = pViewBob->m_flBobTime - (int)(pViewBob->m_flBobTime / var_cycle) * var_cycle;
pViewBob->m_flBobCycle /= var_cycle;
if (pViewBob->m_flBobCycle < var_up) {
pViewBob->m_flBobCycle = MATH_PI * pViewBob->m_flBobCycle / var_up;
} else {
pViewBob->m_flBobCycle = MATH_PI + MATH_PI * (pViewBob->m_flBobCycle - var_up)/(1.0 - var_up);
}
vecVel = pSeat->m_vecPredictedVelocity;
vecVel[2] = 0;
pViewBob->m_flSpeed = vlen(vecVel);
flBob = pViewBob->m_flSpeed * var_bob;
flBob = flBob * 0.3 + flBob * 0.7 * sin(pViewBob->m_flBobCycle);
pViewBob->m_flBob = bound(-7, flBob, 4);
/* BOB2, which is half the cycle of bob1 */
pViewBob->m_flBobCycle2 = pViewBob->m_flBobTime2 - (int)(pViewBob->m_flBobTime2 / (var_cycle * 0.5f)) * (var_cycle * 0.5f);
pViewBob->m_flBobCycle2 /= (var_cycle * 0.5f);
if (pViewBob->m_flBobCycle2 < var_up) {
pViewBob->m_flBobCycle2 = MATH_PI * pViewBob->m_flBobCycle2 / var_up;
} else {
pViewBob->m_flBobCycle2 = MATH_PI + MATH_PI * (pViewBob->m_flBobCycle2 - var_up)/(1.0 - var_up);
}
flBob = pViewBob->m_flSpeed * var_bob;
flBob = flBob * 0.3 + flBob * 0.7 * sin(pViewBob->m_flBobCycle2);
pViewBob->m_flBob2 = bound(-7, flBob, 4);
/* make sure it's adjusted for scale */
pViewBob->m_flBob *= autocvar_r_viewmodelscale;
}
@ -136,15 +93,28 @@ Viewmodel_ApplyBob(entity gun)
int s = (float)getproperty(VF_ACTIVESEAT);
pViewBob = &g_viewBobVars[s];
switch (autocvar_v_bobstyle)
{
case BOB_CLASSIC:
Viewmodel_ClassicBobRun(gun);
break;
case BOB_VISIONS:
Viewmodel_VisionsBobRun(gun);
break;
default:
break;
}
float sintime;
float strength;
gun.angles[2] = -pViewBob->m_flBob;
vector angmod;
angmod[0] -= pViewBob->m_flBob2 * 0.5f;
angmod[1] += pViewBob->m_flBob * 2.5f;
angmod[2] += pViewBob->m_flBob * 3.0f;
gun.angles += angmod * 1.5f;
/* sway with speed */
sintime = sin(time);
strength = pViewBob->m_flSpeed;
if (strength > 240)
strength = 240;
strength = 240 - strength;
strength *= 0.005f;
gun.angles[0] += strength * sintime;
gun.angles[1] += strength * sintime;
gun.angles[2] += strength * sintime;
gun.origin += [0,0,-1];
}

View File

@ -43,4 +43,4 @@ FX_Spark(vector pos, vector ang)
pointparticles(PARTICLE_SPARK, pos, ang, 1);
Sound_PlayAt(pos, "env_spark.sfx");
#endif
}
}

View File

@ -150,6 +150,10 @@ CSQC_RenderScene(void)
renderscene();
}
void(float, float, float, float) gp_rumble = #0;
void(float devid, float amp_low, float amp_high, float duration) gp_rumbletriggers = #0;
void(float devid, vector color) gp_setledcolor = #0;
float g_deviceid;
void
CSQC_UpdateView(float w, float h, float focus)
{
@ -179,6 +183,9 @@ CSQC_UpdateView(float w, float h, float focus)
Sky_Update(FALSE);
cvar_set("_background", serverkey("background"));
vector color = getlight(getproperty(VF_ORIGIN)) / 255.0f;
gp_setledcolor(g_deviceid, color);
if (serverkeyfloat("background") == 1) {
setpause(FALSE);
}
@ -445,8 +452,16 @@ CSQC_InputEvent(float fEventType, float fKey, float fCharacter, float fDeviceID)
pSeat = &g_seats[s];
pSeatLocal = &g_seatslocal[s];
g_deviceid = fDeviceID;
switch (fEventType) {
case IE_KEYDOWN:
gp_rumble(fDeviceID, 0xFFFF, 0xFFFF, 100);
//gp_rumble(fDeviceID, 0xFFFF, 0xFFFF, 100);
if (random() < 0.5)
gp_rumbletriggers(fDeviceID, 0xFFFF, 0xFFFF, 100);
else
gp_rumbletriggers(fDeviceID, 0xFFFF, 0xFFFF, 100);
break;
case IE_KEYUP:
break;

View File

@ -15,8 +15,6 @@ predict.qc
npc.qc
entities.qc
modelevent.qc
camera.qc
viewmodel.qc
view.qc
damage.qc
chat.qc

View File

@ -93,6 +93,10 @@ trigger_push::touch(void)
return;
}
/* trigger_push is not supposed to work underwater */
if (other.waterlevel > 1)
return;
if (other.solid != SOLID_NOT && other.solid != SOLID_BSP) {
vector vecPush;
vecPush = (m_flSpeed * m_vecMoveDir);