diff --git a/src/client/camera.qc b/src/client/camera.qc new file mode 100644 index 0000000..a0fac19 --- /dev/null +++ b/src/client/camera.qc @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016-2021 Marco Hladik + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +// FILE COPIED FROM FREEHL. +// Not ideal, but better than needing hack-ins to Nuclide files for now. + + +//TAGGG - BobNEW. Unused now. +/* +struct +{ + float m_flSpeed; + float m_flFracSin; + float m_flTime; + float m_flMove; + float m_flDelta; + int m_iCycle; +} g_camBobVars[4], *pCamBob; +*/ + + +/* tilts the camera for a head-bob like effect when moving */ +//TAGGG - BobNEW. REPLACED. +// There are some major differences between the Vavle file and this one: +// * TS does not adjust the camera angles for bob, it moves it up and down a little. +// This method does not alter camera_angle. It sets the model VF_ORIGIN, which +// may conflict a bit with Nuclide but it seems to work for now. +// * This depends on vCameraBobOriginOffset set by Viewmodel_CalcBob, which has +// already been called ahead of time. CameraBob does not have its own persistent vars +// like the g_camBobVars/pCamBob struct above. +// +// This method only runs when the player movetype is WALK. Doubt that is a problem. +void +Camera_RunBob(__inout vector camera_angle) +{ + + //TAGGG - NEW. TS viewbob also shifts the player camera up/down a tiny bit. + // We'll do that here, why not. + // AND IMPORTANT - used to refer to vPlayerOrigin here, + // now using vPlayerOrigin. + // See if anywhere else called here neds to do that! + // namely View_DetermineBobOffset. + + //setproperty(VF_ORIGIN, pSeat->vPlayerOrigin + pl.view_ofs + pViewBob->m_vCam); + + player pl = (player)pSeat->m_ePlayer; + + makevectors(view_angles); + + vector vCameraOriginFinal; + vCameraOriginFinal = + pSeat->m_vecPredictedOrigin + pl.view_ofs + + v_forward * (pViewBob->m_vCam[0]) + + v_right * (pViewBob->m_vCam[1]) + + v_up * (pViewBob->m_vCam[2]); + + setproperty(VF_ORIGIN, vCameraOriginFinal); +} + +/* applies a tilt to the camera for when we're strafing left to right */ +//TAGGG - BobNEW. Dummied. Don't think anything like this was in TS. +void +Camera_StrafeRoll(__inout vector camera_angle) +{ + +} diff --git a/src/client/cmds.qc b/src/client/cmds.qc index 602ea56..d151f99 100644 --- a/src/client/cmds.qc +++ b/src/client/cmds.qc @@ -94,8 +94,6 @@ ClientGame_ConsoleCommand(void) //If we're in spectator mode we can do this // no-screen check, not necessary probably: pSeatLocal->fVGUI_Display == VGUI_SCREEN::NONE && - - printfline("WOO HOO YEA BOY %s", getplayerkeyvalue( player_localnum, "*spec" )); if(getplayerkeyvalue( player_localnum, "*spec" ) != "0"){ //we can show it! VGUI_ChangeScreen(VGUI_SCREEN::BUYSIDEMENU); diff --git a/src/client/hud.qc b/src/client/hud.qc index 18325b3..af5b838 100644 --- a/src/client/hud.qc +++ b/src/client/hud.qc @@ -68,7 +68,6 @@ HUD_Draw(void) Obituary_Draw(); Textmenu_Draw(); - //TAGGG - NEw ////////////////////////////////////////////////////////////// //View_HandleZoom(); @@ -115,9 +114,7 @@ HUD_Draw(void) }else{ - // Fake spectator really. - - //printfline("I AM FAKE"); + // Fake spectator, or the temporary forced third-person on death (not yet implemented). drawfont = FONT_20; // TAGGG - could have some message from server-to-client on changing from player to spectator diff --git a/src/client/progs.src b/src/client/progs.src index 1342bf2..8de1734 100644 --- a/src/client/progs.src +++ b/src/client/progs.src @@ -77,8 +77,17 @@ clientinfo.qc entities.qc cmds.qc game_event.qc -../../../valve/src/client/camera.qc -../../../valve/src/client/viewmodel.qc + + +//TAGGG - ViewBobNEW. +// Include these instead of using clones here in TS if that turns out to be do-able. +//../../../valve/src/client/camera.qc +//../../../valve/src/client/viewmodel.qc +//------------ +camera.qc +viewmodel.qc + + view.qc obituary.qc hud.qc diff --git a/src/client/seatlocal.h b/src/client/seatlocal.h index d59b279..fab52f9 100644 --- a/src/client/seatlocal.h +++ b/src/client/seatlocal.h @@ -43,6 +43,18 @@ struct } g_seatslocal[4], *pSeatLocal; - - void pSeatLocal_init(void); + + +//TAGGG - BobNEW. ViewBob struct array/var moved here +struct +{ + float m_flBobTime; + float m_flBob; + float m_flBobCycle; + float m_flSpeed; + // NEW + vector m_vCam; +} g_viewBobVars[4], *pViewBob; + + diff --git a/src/client/viewmodel.qc b/src/client/viewmodel.qc new file mode 100644 index 0000000..47de57c --- /dev/null +++ b/src/client/viewmodel.qc @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2016-2021 Marco Hladik + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +// FILE COPIED FROM FREEHL. +// Not ideal, but better than needing hack-ins to Nuclide files for now. + +var float autocvar_v_bob = 0.01; +var float autocvar_v_bobcycle = 0.8; +var float autocvar_v_bobup = 0.5; + +//TAGGG - BobNEW. ViewBob struct array/var moved to seatlocal.h for better +// visibility. Remove from there on using the Valve file instead. + + +/* 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 + * the math too many times */ +//TAGGG - BobNEW. REPLACED. +// Also, a major difference between the Valve file and this version: +// This involves the previous frame's value of pViewBob->m_flBob, unlike Valve. +// pViewBob->m_flBobCycle involves its previous value still. +void +Viewmodel_CalcBob(void) +{ + vector vecVel; + float flBob; + int s = (float)getproperty(VF_ACTIVESEAT); + pViewBob = &g_viewBobVars[s]; + + float var_bob; + float var_cycle; + float var_up; + + // Multiples on these for new defaults for the same default CVar values: + // v_bob: 0.01 -> 0.01 (unchanged) + // v_bobcycle: 0.8 -> 1.05 + // v_bobup: 0.5 -> 0.525 + var_bob = autocvar_v_bob * 1; + var_cycle = autocvar_v_bobcycle * 1.3125; + var_up = autocvar_v_bobup * 1 * 1.05; + + + + player pl = (player)pSeat->m_ePlayer; //clientside can do this + + int inputLen = vlen(input_movevalues); + + // do we care about "self.maxspeed" ?? + + // Instead of some new bTouchingGround, using the presence of flag FL_ONGROUND. + // If the player waterlevel >= 2, the "FL_ONGROUND" flag never occurs, + // regardless of touching the floor in the area. + // In original TS, being on the floor underwater DOES still do the camera/viewbob. + // No idea how to get around this, beyond traces against the ground like pmove + // does. + + BOOL bOnGround = FALSE; + + if(pl.waterlevel < 2){ + // Easy, trsy pl.flags having FL_ONGROUND. + bOnGround = ((pl.flags & FL_ONGROUND) != 0); + }else{ + // Underwater enough? Need to do a re-trace, FL_ONGROUND is forced off by + // pmove. + // Open for better ideas, or maybe this is a massive "who cares" situation. + + tracebox(pl.origin, pl.mins, pl.maxs, pl.origin - [0,0,0.25], FALSE, pl); + + if (!trace_startsolid) { + if ((trace_fraction < 1) && (trace_plane_normal[2] > 0.7)) { + bOnGround = TRUE; + } else { + + } + } + } + + + + + + + if(!bOnGround){ + float timeTol; + vector vSource = pl.origin; + + traceline ( vSource, vSource + ( '0 0 -1' * 5 ), TRUE, pl ); + //entity ef = findradius(trace_endpos, 40); + + if(trace_fraction < 1.0 || pl.velocity[2] > 50){ + //more distance from the ground? + timeTol = 0.07; + }else{ + timeTol = 0.17; + } + + + if((time-pl.flRecentGroundTime) > timeTol*(1/autocvar_movemodmulti) ){ + + float reducerMulti; + + //if(inputLen <= 0.1){ + // reducerMulti = pow(0.95, autocvar_movemodmulti); + //}else{ + reducerMulti = pow(0.91, autocvar_movemodmulti); + //} + + if(pViewBob->m_flBob > 0.02){ + pViewBob->m_flBob *= reducerMulti; + }else{ + pViewBob->m_flBob = 0; + } + return; + } + }else{ + pl.flRecentGroundTime = time; + } + + + float var_cycle_adj = var_cycle * (1/autocvar_movemodmulti); + + pViewBob->m_flBobTime += clframetime; + pViewBob->m_flBobCycle = pViewBob->m_flBobTime - (int)(pViewBob->m_flBobTime / var_cycle_adj) * var_cycle_adj; + pViewBob->m_flBobCycle /= var_cycle_adj; + + 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; + + // Most major differences start after here. + // This involves the previous value of m_flBob for some smoothness when changed. + pViewBob->m_flBob += (flBob - pViewBob->m_flBob) * 0.09 * autocvar_movemodmulti; + + // bounds from Valve, does it make sense here? + //pViewBob->m_flBob = bound(-7, flBob, 4); + + // And the r_viewmodelscale from Valve. I think this is safe. + pViewBob->m_flBob *= autocvar_r_viewmodelscale; + + ////////////// + pViewBob->m_vCam[0] = 0; + pViewBob->m_vCam[1] = 0; + pViewBob->m_vCam[2] = pViewBob->m_flBob * 1.2 * sin(pViewBob->m_flBobCycle*2 + MATH_PI/2 ); +} + +//TAGGG - BobNEW. REPLACED. +void +Viewmodel_ApplyBob(entity gun) +{ + player pl = (player)pSeat->m_ePlayer; + gun.origin = pSeat->m_vecPredictedOrigin + pl.view_ofs; + gun.origin += [0,0,-1]; + gun.origin += v_forward * (0.75 + autocvar_v_gunofs[0] + pViewBob->m_flBob * (-0.68 + -0.112 * fabs(sin(pViewBob->m_flBobCycle)) ) + 0.98 * pViewBob->m_vCam[0] ); + gun.origin += v_right * (autocvar_v_gunofs[1] + (pViewBob->m_flBob * (-0.2 + 0.308 * sin(pViewBob->m_flBobCycle)) ) + 0.98 * pViewBob->m_vCam[1] ); + gun.origin += v_up * (0.5 + autocvar_v_gunofs[2] + (pViewBob->m_flBob * (-0.48 + 0.196 * fabs(sin(pViewBob->m_flBobCycle)) )) + 0.98 * pViewBob->m_vCam[2] ); + +} diff --git a/src/server/gamerules_multiplayer.qc b/src/server/gamerules_multiplayer.qc index c049fb9..3ebca5e 100644 --- a/src/server/gamerules_multiplayer.qc +++ b/src/server/gamerules_multiplayer.qc @@ -320,7 +320,6 @@ TSMultiplayerRules::PlayerDeath(base_player pp) TS_resetViewModel(pl); pl.setInventoryEquippedIndex(-1); - printfline("How many weapons do you have, dead player? %i", pl.ary_myWeapons_softMax); for(int i = pl.ary_myWeapons_softMax-1; i >= 0; i--){ pl.dropWeapon(i, TRUE); } @@ -995,7 +994,6 @@ TSMultiplayerRules::PlayerMakePlayable(base_player pp) } pl.iState = PLAYER_STATE::SPAWNED; - printfline("HERE I AM MAKING IT SPAWNED!!!"); // Nope! //MakePlayable(pp); @@ -1033,8 +1031,6 @@ TSMultiplayerRules::PlayerMakeSpectator(base_player pp) //MakeSpectator(pl); pl.iState = PLAYER_STATE::NOCLIP; - printfline("WELL??? %d", pl.iState), - // And do the rest of the lines to finish that // (copied from the Nuclide spectator's constructor) // Lines already handled by MakePlayerInvisible not here. @@ -1065,10 +1061,8 @@ TSMultiplayerRules::PlayerMakeSpectatorDelayed(base_player pp) // happening. Redirect to the normal version player pl = (player)pp; - printfline("SO WHAT %d", pl.iState), PlayerMakeSpectator(pp); - /* player pl = (player)pp; @@ -1119,7 +1113,6 @@ TSMultiplayerRules::PlayerSpawn(base_player pp) // What this means is, no need for spawnfunc_player here. - // should "Frags" be an infokey to be better preserved through player/spectator changes? // No clue. And setting these only that way further down by forceinfokey too. //pl.frags = 0; diff --git a/src/shared/player.h b/src/shared/player.h index 46f3554..1865ebc 100644 --- a/src/shared/player.h +++ b/src/shared/player.h @@ -93,20 +93,10 @@ class player:base_player float flZoomLerp; float flZoomLevel; - BOOLEAN fBobOnGroundMem; - vector flBobStart; - vector flBobTarget; - float flBobLerp; - vector vBob; //the actual bob offset to be applied. A full vector. - // For telling how long it's been since I've been on the ground. // Don't oscillate the view model bob on going down short steps. float flRecentGroundTime; - BOOLEAN bTouchingGround; - - float flBobTime; - BOOL recentLaserHitPosSet; vector recentLaserHitPos; vector recentLaserHitPos2; @@ -119,8 +109,6 @@ class player:base_player // is equipped. Not that it could ever change while not equipped anyway. int prev_forceBodygroup1Submodel; - vector vCameraBobOriginOffset; - // WEAPON KICKBACK STUFF. // Way it works is a little different from the average (Half-Life and Counterstrike). diff --git a/src/shared/player.qc b/src/shared/player.qc index 1668e5f..0a9520d 100644 --- a/src/shared/player.qc +++ b/src/shared/player.qc @@ -83,7 +83,7 @@ player::ReceiveEntity(float new, float fl) // do we need to do this here, I: forget, I don't think so /* - int s = (int)getproperty(VF_ACTIVESEAT); + int s = (float)getproperty(VF_ACTIVESEAT); pSeat = &g_seats[s]; */ /* @@ -777,7 +777,7 @@ player::reset(BOOLEAN resetInventory){ // properly before the call to here, (whatever event-method in base files leads // to here most likely), this is not necessary. // Also, no need for pSeatLocal yet, but add in if that changes. - int s = (int)getproperty(VF_ACTIVESEAT); + int s = (float)getproperty(VF_ACTIVESEAT); pSeat = &g_seats[s]; pSeat->m_flHUDWeaponSelectTime = -1; // we don't want damage related to the death / between spawns carrying over @@ -794,16 +794,18 @@ player::reset(BOOLEAN resetInventory){ flCurrentZoom = 1; flZoomLevel = 1; - fBobOnGroundMem = FALSE; - flBobStart = '0 0 0'; - flBobTarget = '0 0 0'; - flBobLerp = 1; //jump straight to the target at first. - vBob = '0 0 0'; flRecentGroundTime = 0; - bTouchingGround = FALSE; - flBobTime = 0; + //TAGGG - BobNEW. + // Reset the vars here? Or only on an inventory wipe? + pViewBob = &g_viewBobVars[s]; + pViewBob->m_flBobTime = 0; + pViewBob->m_flBob = 0; + pViewBob->m_flBobCycle = 0; + pViewBob->m_flSpeed = 0; + pViewBob->m_vCam = [0,0,0]; + ///////////////////////////////////////////////////// flViewShake = 0; @@ -814,7 +816,6 @@ player::reset(BOOLEAN resetInventory){ forceViewModelUpdate = FALSE; prev_forceBodygroup1Submodel = 0; - vCameraBobOriginOffset = [0,0,0]; #endif #ifdef SSQC @@ -956,9 +957,7 @@ player::View_approachAngleOffsetTarget(vector vecInputAngles) // do we have an offset at all? if( vlen(vViewAngleOffsetTarget) != 0){ - //shift our view to get closer to looking in the direction suggested by it. - //Math_Lerp(flBobStart[0], flBobTarget[0], flBobLerp) - + //shift our view to get closer to looking in the direction suggested by it. vector vecToMove; vecToMove = vViewAngleOffsetTarget * 0.22;