Skip to content

Commit

Permalink
FTR: Camera Tilt when Hitting Ground
Browse files Browse the repository at this point in the history
  • Loading branch information
proof88 committed Feb 6, 2025
1 parent 524768b commit 13da761
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 35 deletions.
4 changes: 1 addition & 3 deletions PRooFPS-dd/InputHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ bool proofps_dd::InputHandling::serverHandleUserCmdMoveFromClient(
if (!pTargetWpn->isAvailable())
{
getConsole().EOLn("InputHandling::%s(): weapon not available: %s!", __func__, itTargetWpn->second.c_str());
assert(false); // in debug mode, must abort because CLIENT should had not sent weapon switch request if they don't have this wpn!
return true; // in release mode, dont terminate the server, just silently ignore!
// TODO: I might disconnect this client!
return true; // just silently ignore, maybe it was a message sent from client earlier when that weapon was still available!
}

if (pTargetWpn != player.getWeaponManager().getCurrentWeapon())
Expand Down
5 changes: 3 additions & 2 deletions PRooFPS-dd/PRooFPS-dd-PGE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ bool proofps_dd::PRooFPSddPGE::onPacketReceived(const pge_network::PgePacket& pk
case proofps_dd::MsgPlayerEventFromServer::id:
bRet = handlePlayerEventFromServer(
pge_network::PgePacket::getServerSideConnectionHandle(pkt),
pge_network::PgePacket::getMsgAppDataFromPkt<proofps_dd::MsgPlayerEventFromServer>(pkt));
pge_network::PgePacket::getMsgAppDataFromPkt<proofps_dd::MsgPlayerEventFromServer>(pkt),
cameraGetShakeForce());
break;
case proofps_dd::MsgUserInGameMenuCmd::id:
bRet = serverHandleUserInGameMenuCmd(
Expand Down Expand Up @@ -737,7 +738,7 @@ void proofps_dd::PRooFPSddPGE::mainLoopConnectedServerOnlyOneTick(
{
const std::chrono::time_point<std::chrono::steady_clock> timeStart = std::chrono::steady_clock::now();
serverGravity(*m_gui.getXHair(), m_config.getPhysicsRate(), *GameMode::getGameMode());
serverPlayerCollisionWithWalls(m_config.getPhysicsRate(), *m_gui.getXHair(), *GameMode::getGameMode());
serverPlayerCollisionWithWalls(m_config.getPhysicsRate(), *m_gui.getXHair(), *GameMode::getGameMode(), cameraGetShakeForce());
m_durations.m_nGravityCollisionDurationUSecs += std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - timeStart).count();
}
serverUpdateBullets(*GameMode::getGameMode(), *m_gui.getXHair(), m_config.getPhysicsRate(), cameraGetShakeForce());
Expand Down
14 changes: 9 additions & 5 deletions PRooFPS-dd/Physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ void proofps_dd::Physics::serverGravity(
void proofps_dd::Physics::serverPlayerCollisionWithWalls(
const unsigned int& nPhysicsRate,
XHair& xhair,
proofps_dd::GameMode& gameMode /* TODO: get rid of GameMode, Physics should not have it */)
proofps_dd::GameMode& gameMode /* TODO: get rid of GameMode, Physics should not have it */,
PureVector& vecCamShakeForce)
{
const float GAME_PLAYER_SPEED_WALK = Player::fBaseSpeedWalk / nPhysicsRate;
const float GAME_PLAYER_SPEED_RUN = Player::fBaseSpeedRun / nPhysicsRate;
Expand Down Expand Up @@ -451,7 +452,8 @@ void proofps_dd::Physics::serverPlayerCollisionWithWalls(
fPlayerPos1YPlusHalf,
fBlockSizeXhalf,
fBlockSizeYhalf,
xhair);
xhair,
vecCamShakeForce);

if (bCollided)
{
Expand Down Expand Up @@ -483,7 +485,8 @@ void proofps_dd::Physics::serverPlayerCollisionWithWalls(
fPlayerPos1YPlusHalf,
fBlockSizeXhalf,
fBlockSizeYhalf,
xhair);
xhair,
vecCamShakeForce);
} // end for i

if (!bCollided && player.isFalling() && (std::as_const(player).getHealth() > 0))
Expand Down Expand Up @@ -772,7 +775,8 @@ bool proofps_dd::Physics::serverPlayerCollisionWithWalls_LoopKernelVertical(
const float& fPlayerPos1YPlusHalf,
const float& fBlockSizeXhalf,
const float& fBlockSizeYhalf,
XHair& xhair
XHair& xhair,
PureVector& vecCamShakeForce
)
{
assert(obj);
Expand Down Expand Up @@ -833,7 +837,7 @@ bool proofps_dd::Physics::serverPlayerCollisionWithWalls_LoopKernelVertical(
if (bOriginalFalling)
{
// now handleLanded() has both the server- and client-side logic, this design should be the future design for most game logic
player.handleLanded(fFallHeight, nDamage > 0, std::as_const(player).getHealth() == 0);
player.handleLanded(fFallHeight, nDamage > 0, std::as_const(player).getHealth() == 0, vecCamShakeForce, isMyConnection(player.getServerSideConnectionHandle()));
}
player.setCanFall(false);

Expand Down
6 changes: 4 additions & 2 deletions PRooFPS-dd/Physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ namespace proofps_dd
void serverPlayerCollisionWithWalls(
const unsigned int& nPhysicsRate,
XHair& xhair,
proofps_dd::GameMode& gameMode /* TODO: get rid of GameMode, Physics should not have it */);
proofps_dd::GameMode& gameMode /* TODO: get rid of GameMode, Physics should not have it */,
PureVector& vecCamShakeForce);

bool serverPlayerCollisionWithWalls_LoopKernelVertical(
Player& player,
Expand All @@ -101,7 +102,8 @@ namespace proofps_dd
const float& fPlayerPos1YPlusHalf,
const float& fBlockSizeXhalf,
const float& fBlockSizeYhalf,
XHair& xhair);
XHair& xhair,
PureVector& vecCamShakeForce);

private:

Expand Down
17 changes: 11 additions & 6 deletions PRooFPS-dd/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,12 @@ void proofps_dd::Player::handleFallingFromHigh(int iServerScream /* valid only i
m_network.getServer().sendToAllClientsExcept(pktPlayerEvent);
}

void proofps_dd::Player::handleLanded(const float& fFallHeight, bool bDamageTaken, bool bDied)
void proofps_dd::Player::handleLanded(
const float& fFallHeight,
bool bDamageTaken,
bool bDied,
PureVector& vecCamShakeForce,
const bool& bMe)
{
// both server and client execute this function, so be careful with conditions here

Expand Down Expand Up @@ -1722,6 +1727,11 @@ void proofps_dd::Player::handleLanded(const float& fFallHeight, bool bDamageTake
// __func__,
// playerPos.getX(), playerPos.getY(), playerPos.getZ(),
// m_gfx.getCamera().getPosVec().getX(), m_gfx.getCamera().getPosVec().getY(), m_gfx.getCamera().getPosVec().getZ());

if (bMe)
{
vecCamShakeForce.SetY(vecCamShakeForce.getY() + 4 * fFallHeight);
}
}
else
{
Expand Down Expand Up @@ -1902,11 +1912,6 @@ void proofps_dd::Player::handleTeamIdChanged(const unsigned int& iTeamId)

getTeamId() = iTeamId;

if (!m_network.isServer() || (getServerSideConnectionHandle() == pge_network::ServerConnHandle))
{
// TODO: add xy joined team n to a new eventlister!
}

if (!m_network.isServer())
{
return;
Expand Down
7 changes: 6 additions & 1 deletion PRooFPS-dd/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,12 @@ namespace proofps_dd
Weapon* getWeaponInstanceByMapItemType(const MapItemType& mapItemType);

void handleFallingFromHigh(int iServerScream);
void handleLanded(const float& fFallHeight, bool bDamageTaken, bool bDied);
void handleLanded(
const float& fFallHeight,
bool bDamageTaken,
bool bDied,
PureVector& vecCamShakeForce,
const bool& bMe);
void handleActuallyRunningOnGround();
void handleTakeNonWeaponItem(const proofps_dd::MapItemType& eMapItemType);
void handleTakeWeaponItem(
Expand Down
7 changes: 5 additions & 2 deletions PRooFPS-dd/PlayerHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,10 @@ bool proofps_dd::PlayerHandling::handleDeathNotificationFromServer(pge_network::
return true;
}

bool proofps_dd::PlayerHandling::handlePlayerEventFromServer(pge_network::PgeNetworkConnectionHandle connHandleServerSide, const proofps_dd::MsgPlayerEventFromServer& msg)
bool proofps_dd::PlayerHandling::handlePlayerEventFromServer(
pge_network::PgeNetworkConnectionHandle connHandleServerSide,
const proofps_dd::MsgPlayerEventFromServer& msg,
PureVector& vecCamShakeForce)
{
//getConsole().EOLn("PlayerHandling::%s(): received event id: %u about player with connHandleServerSide: %u!", __func__, msg.m_iPlayerEventId, connHandleServerSide);

Expand Down Expand Up @@ -1134,7 +1137,7 @@ bool proofps_dd::PlayerHandling::handlePlayerEventFromServer(pge_network::PgeNet
player.handleFallingFromHigh(msg.m_optData1.m_nValue);
break;
case PlayerEventId::Landed:
player.handleLanded(msg.m_optData1.m_fValue, msg.m_optData2.m_bValue, msg.m_optData3.m_bValue);
player.handleLanded(msg.m_optData1.m_fValue, msg.m_optData2.m_bValue, msg.m_optData3.m_bValue, vecCamShakeForce, bCurrentClient);
break;
case PlayerEventId::ItemTake:
assert(bCurrentClient);
Expand Down
3 changes: 2 additions & 1 deletion PRooFPS-dd/PlayerHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ namespace proofps_dd
pge_network::PgeNetworkConnectionHandle nDeadConnHandleServerSide, const proofps_dd::MsgDeathNotificationFromServer& msg);
bool handlePlayerEventFromServer(
pge_network::PgeNetworkConnectionHandle connHandleServerSide,
const proofps_dd::MsgPlayerEventFromServer& msg
const proofps_dd::MsgPlayerEventFromServer& msg,
PureVector& vecCamShakeForce
);
bool serverHandleUserInGameMenuCmd(
pge_network::PgeNetworkConnectionHandle connHandleServerSide,
Expand Down
16 changes: 8 additions & 8 deletions PRooFPS-dd/Tests/PRooFPS-dd-Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ int WINAPI WinMain(const _In_ HINSTANCE /*hInstance*/, const _In_opt_ HINSTANCE
std::vector<std::unique_ptr<Test>> regTests;

// unit tests
//unitTests.push_back(std::unique_ptr<Test>(new EventListerTest()));
//unitTests.push_back(std::unique_ptr<Test>(new GameModeTest(cfgProfiles)));
//unitTests.push_back(std::unique_ptr<Test>(new MapItemTest(cfgProfiles)));
//unitTests.push_back(std::unique_ptr<Test>(new MapsTest(cfgProfiles)));
//unitTests.push_back(std::unique_ptr<Test>(new MapcycleTest()));
unitTests.push_back(std::unique_ptr<Test>(new EventListerTest()));
unitTests.push_back(std::unique_ptr<Test>(new GameModeTest(cfgProfiles)));
unitTests.push_back(std::unique_ptr<Test>(new MapItemTest(cfgProfiles)));
unitTests.push_back(std::unique_ptr<Test>(new MapsTest(cfgProfiles)));
unitTests.push_back(std::unique_ptr<Test>(new MapcycleTest()));
unitTests.push_back(std::unique_ptr<Test>(new PlayerTest(cfgProfiles)));

// performance tests (benchmarks)
//perfTests.push_back(std::unique_ptr<Test>(new EventListerPerfTest()));

// regression tests
//const proofps_dd::GameModeType gamemode = proofps_dd::GameModeType::DeathMatch;
for (auto gamemode = proofps_dd::GameModeType::DeathMatch; gamemode != proofps_dd::GameModeType::Max; ++gamemode)
const proofps_dd::GameModeType gamemode = proofps_dd::GameModeType::DeathMatch;
//for (auto gamemode = proofps_dd::GameModeType::DeathMatch; gamemode != proofps_dd::GameModeType::Max; ++gamemode)
{
//regTests.push_back(std::unique_ptr<Test>(new RegTestBasicServerClient2Players(60, 60, 60, gamemode)));
regTests.push_back(std::unique_ptr<Test>(new RegTestBasicServerClient2Players(60, 60, 60, gamemode)));
//regTests.push_back(std::unique_ptr<Test>(new RegTestBasicServerClient2Players(60, 20, 60, gamemode)));
//regTests.push_back(std::unique_ptr<Test>(new RegTestBasicServerClient2Players(20, 20, 60, gamemode)));
//
Expand Down
10 changes: 6 additions & 4 deletions PRooFPS-dd/Tests/PlayerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -2463,14 +2463,15 @@ class PlayerTest :
const pge_network::PgeNetworkConnectionHandle connHandleClient = static_cast<pge_network::PgeNetworkConnectionHandle>(12345);
proofps_dd::Player playerServer(m_audio, m_cfgProfiles, m_bullets, m_itemPickupEvents, m_ammoChangeEvents, *m_engine, m_network, connHandleServer, "192.168.1.11");
proofps_dd::Player playerClient(m_audio, m_cfgProfiles, m_bullets, m_itemPickupEvents, m_ammoChangeEvents, *m_engine, m_network, connHandleClient, "192.168.1.12");
PureVector vecCamShakeForce;

bool b = true;
// (I cannot check sound now, need stubs for that)
playerServer.handleLanded(1.f, false, false);
playerServer.handleLanded(1.f, false, false, vecCamShakeForce, true);
b &= assertEquals(1u, m_network.getServer().getTxPacketCount(), "tx pkt count 1");

// (I cannot check sound now, need stubs for that)
playerClient.handleLanded(1.f, false, false);
playerClient.handleLanded(1.f, false, false, vecCamShakeForce, true);
b &= assertEquals(2u, m_network.getServer().getTxPacketCount(), "tx pkt count 2");
try
{
Expand All @@ -2485,7 +2486,7 @@ class PlayerTest :
}

// same actions as above, no protective flag is in place that needs to be cleared first
playerClient.handleLanded(1.f, false, false);
playerClient.handleLanded(1.f, false, false, vecCamShakeForce, true);
b &= assertEquals(3u, m_network.getServer().getTxPacketCount(), "tx pkt count 3");
try
{
Expand Down Expand Up @@ -2516,9 +2517,10 @@ class PlayerTest :

proofps_dd::Player playerClient(m_audio, m_cfgProfiles, m_bullets, m_itemPickupEvents, m_ammoChangeEvents, *m_engine, m_network, connHandleClient, "192.168.1.12");
bool b = true;
PureVector vecCamShakeForce;

// client never sends pkt from this function, and always plays sound (I cannot check sound now, need stubs for that)
playerClient.handleLanded(1.f, false, false);
playerClient.handleLanded(1.f, false, false, vecCamShakeForce, true);
b &= assertEquals(0u, m_network.getServer().getTxPacketCount(), "tx pkt count 1");

return b;
Expand Down
2 changes: 1 addition & 1 deletion PRooFPS-dd/gamedata/profiles/default/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#############

# True: game instance will start up as listen-server, false: start up as a client.
net_server = true
net_server = false
# Clients try to connect to the server at address specified in cl_server_ip.


Expand Down

0 comments on commit 13da761

Please sign in to comment.