From 997d514f45060cee4a4243a30b1138876e74f6f5 Mon Sep 17 00:00:00 2001 From: Josef Spjut Date: Tue, 5 Dec 2023 10:41:34 -0500 Subject: [PATCH] Only strafe ever N calls to slideMove --- source/FPSciApp.cpp | 2 ++ source/FpsConfig.cpp | 6 +++++- source/FpsConfig.h | 1 + source/GuiElements.cpp | 4 ++++ source/PlayerEntity.cpp | 19 ++++++++++++++++--- source/PlayerEntity.h | 2 ++ 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/source/FPSciApp.cpp b/source/FPSciApp.cpp index 990f9321..19f0eccf 100644 --- a/source/FPSciApp.cpp +++ b/source/FPSciApp.cpp @@ -619,6 +619,8 @@ void FPSciApp::initPlayer(const shared_ptr config, const bool respawn player->height = &config->player.height; player->crouchHeight = &config->player.crouchHeight; + player->strafeDivider = &config->render.strafeDivider; + // Respawn player if (respawn) player->respawn(); updateMouseSensitivity(); diff --git a/source/FpsConfig.cpp b/source/FpsConfig.cpp index 176b5ecb..17bdc7cf 100644 --- a/source/FpsConfig.cpp +++ b/source/FpsConfig.cpp @@ -100,6 +100,8 @@ void RenderConfig::load(FPSciAnyTableReader reader, int settingsVersion) { reader.getIfPresent("frameDelay", frameDelay); reader.getIfPresent("frameTimeArray", frameTimeArray); reader.getIfPresent("frameTimeRandomize", frameTimeRandomize); + + reader.getIfPresent("strafeDivider", strafeDivider); reader.getIfPresent("frameTimeMode", frameTimeMode); frameTimeMode = toLower(frameTimeMode); // Convert to lower case @@ -169,7 +171,9 @@ Any RenderConfig::addToAny(Any a, bool forceAll) const { if (forceAll || def.samplerPrecomposite != samplerPrecomposite) a["samplerPrecomposite"] = samplerPrecomposite; if (forceAll || def.samplerComposite != samplerComposite) a["samplerComposite"] = samplerComposite; if (forceAll || def.samplerFinal != samplerFinal) a["samplerFinal"] = samplerFinal; - + + if (forceAll || def.strafeDivider != strafeDivider) a["strafeDivider"] = strafeDivider; + return a; } diff --git a/source/FpsConfig.h b/source/FpsConfig.h index cd660722..03bcca47 100644 --- a/source/FpsConfig.h +++ b/source/FpsConfig.h @@ -29,6 +29,7 @@ class RenderConfig { // Rendering parameters float frameRate = 1000.0f; ///< Target (goal) frame rate (in Hz) int frameDelay = 0; ///< Integer frame delay (in frames) + int strafeDivider = 1; ///< Integer number of frames between move updates Array frameTimeArray = { }; ///< Array of target frame times (in seconds) bool frameTimeRandomize = false; ///< Whether to choose a sequential or random item from frameTimeArray String frameTimeMode = "always"; ///< Mode to use for frame time selection (can be "always", "taskOnly", or "restartWithTask", case insensitive) diff --git a/source/GuiElements.cpp b/source/GuiElements.cpp index 07afa8df..96317570 100644 --- a/source/GuiElements.cpp +++ b/source/GuiElements.cpp @@ -228,6 +228,10 @@ RenderControls::RenderControls(FPSciApp* app, FpsConfig& config, bool& drawFps, auto c = framePane->addNumberBox("Framerate", &(config.render.frameRate), "fps", GuiTheme::LINEAR_SLIDER, minFrameRate, maxFrameRate, 1.0f); c->setWidth(width*0.95f); } framePane->endRow(); + framePane->beginRow(); { + auto c = framePane->addNumberBox("Strafe every", &(config.render.strafeDivider), "frames", GuiTheme::LINEAR_SLIDER, 1, 360, 1); + c->setWidth(width * 0.95f); + } framePane->endRow(); framePane->beginRow(); { auto c = framePane->addNumberBox("Display Lag", &(config.render.frameDelay), "f", GuiTheme::LINEAR_SLIDER, 0, maxFrameDelay); c->setWidth(width*0.95f); diff --git a/source/PlayerEntity.cpp b/source/PlayerEntity.cpp index 7579a181..ca06410c 100644 --- a/source/PlayerEntity.cpp +++ b/source/PlayerEntity.cpp @@ -128,7 +128,13 @@ void PlayerEntity::onSimulation(SimTime absoluteTime, SimTime deltaTime) { } simulatePose(absoluteTime, deltaTime); + static G3D::SimTime slideDeltaTime = 0.; + static int callCount = 1; + if (!isNaN(deltaTime)) { + // Accumulate for occasional slide only + slideDeltaTime += deltaTime; + // Apply rotation first m_yawRadians += m_desiredYawDelta; // Integrate the yaw change into heading m_yawRadians = mod1((m_yawRadians) / (2 * pif())) * 2 * pif(); // Keep the user's heading value in the [0,2pi) range @@ -138,9 +144,16 @@ void PlayerEntity::onSimulation(SimTime absoluteTime, SimTime deltaTime) { // Set player frame rotation based on the heading and tilt m_frame.rotation = Matrix3::fromAxisAngle(Vector3::unitY(), -m_yawRadians) * Matrix3::fromAxisAngle(Vector3::unitX(), m_pitchRadians); - // Translation update - in direction after rotating - if (m_motionEnable) { - m_inContact = slideMove(deltaTime); + if (strafeDivider && callCount >= *strafeDivider) { + // Translation update - in direction after rotating + if (m_motionEnable) { + m_inContact = slideMove(slideDeltaTime); + } + slideDeltaTime = 0.; + callCount = 1; + } + else { + callCount += 1; } // Check for "off map" condition and reset position here... diff --git a/source/PlayerEntity.h b/source/PlayerEntity.h index 2a36c4ed..b5970a73 100644 --- a/source/PlayerEntity.h +++ b/source/PlayerEntity.h @@ -46,6 +46,8 @@ class PlayerEntity : public VisibleEntity { float m_cameraRadiansPerMouseDot; ///< Player mouse sensitivity Vector2 turnScale; ///< Player asymmetric mouse scaler - typically near 1:1 + int* strafeDivider; ///< Integer how many frames to count between updating strafing + float* moveRate = nullptr; ///< Player movement rate (m/s) Vector2* moveScale = nullptr; ///< Player X/Y movement scale vector (interpreted as unit vector) Array* axisLock = nullptr; ///< World-space axis lock