Implement activity SFX and decouple camera orbit from movement facing

This commit is contained in:
Kelsi 2026-02-03 19:49:56 -08:00
parent dfc29cad10
commit 8bc50818a9
9 changed files with 592 additions and 12 deletions

View file

@ -0,0 +1,78 @@
#pragma once
#include "audio/footstep_manager.hpp"
#include <array>
#include <chrono>
#include <cstdint>
#include <random>
#include <string>
#include <vector>
namespace wowee {
namespace pipeline { class AssetManager; }
namespace audio {
class ActivitySoundManager {
public:
ActivitySoundManager();
~ActivitySoundManager();
bool initialize(pipeline::AssetManager* assets);
void shutdown();
void update(float deltaTime);
bool isInitialized() const { return initialized; }
void playJump();
void playLanding(FootstepSurface surface, bool hardLanding);
void setSwimmingState(bool swimming, bool moving);
void setCharacterVoiceProfile(const std::string& modelName);
void playWaterEnter();
void playWaterExit();
private:
struct Sample {
std::string path;
std::vector<uint8_t> data;
};
struct SurfaceLandingSet {
std::vector<Sample> clips;
};
bool initialized = false;
pipeline::AssetManager* assetManager = nullptr;
std::vector<Sample> jumpClips;
std::vector<Sample> splashEnterClips;
std::vector<Sample> splashExitClips;
std::vector<Sample> swimLoopClips;
std::vector<Sample> hardLandClips;
std::array<SurfaceLandingSet, 7> landingSets;
bool swimmingActive = false;
bool swimMoving = false;
pid_t swimLoopPid = -1;
pid_t oneShotPid = -1;
std::string loopTempPath = "/tmp/wowee_swim_loop.wav";
std::string oneShotTempPath = "/tmp/wowee_activity.wav";
std::mt19937 rng;
std::chrono::steady_clock::time_point lastJumpAt{};
std::chrono::steady_clock::time_point lastLandAt{};
std::chrono::steady_clock::time_point lastSplashAt{};
std::string voiceProfileKey;
void preloadCandidates(std::vector<Sample>& out, const std::vector<std::string>& candidates);
void preloadLandingSet(FootstepSurface surface, const std::string& material);
void rebuildJumpClipsForProfile(const std::string& raceFolder, const std::string& raceBase, bool male);
void rebuildSwimLoopClipsForProfile(const std::string& raceFolder, const std::string& raceBase, bool male);
void rebuildHardLandClipsForProfile(const std::string& raceFolder, const std::string& raceBase, bool male);
bool playOneShot(const std::vector<Sample>& clips, float volume, float pitchLo, float pitchHi);
void startSwimLoop();
void stopSwimLoop();
void stopOneShot();
void reapProcesses();
};
} // namespace audio
} // namespace wowee

View file

@ -37,6 +37,7 @@ public:
float getMovementSpeed() const { return movementSpeed; }
bool isMoving() const;
float getYaw() const { return yaw; }
float getFacingYaw() const { return facingYaw; }
bool isThirdPerson() const { return thirdPerson; }
bool isGrounded() const { return grounded; }
bool isJumping() const { return !grounded && verticalVelocity > 0.0f; }
@ -74,6 +75,7 @@ private:
// Stored rotation (avoids lossy forward-vector round-trip)
float yaw = 180.0f;
float pitch = -30.0f;
float facingYaw = 180.0f; // Character-facing yaw (can differ from camera yaw)
// Movement settings
float movementSpeed = 50.0f;

View file

@ -65,6 +65,7 @@ public:
void removeInstance(uint32_t instanceId);
bool getAnimationState(uint32_t instanceId, uint32_t& animationId, float& animationTimeMs, float& animationDurationMs) const;
bool hasAnimation(uint32_t instanceId, uint32_t animationId) const;
bool getInstanceModelName(uint32_t instanceId, std::string& modelName) const;
/** Attach a weapon model to a character instance at the given attachment point. */
bool attachWeapon(uint32_t charInstanceId, uint32_t attachmentId,

View file

@ -8,7 +8,7 @@
namespace wowee {
namespace core { class Window; }
namespace game { class World; class ZoneManager; }
namespace audio { class MusicManager; class FootstepManager; enum class FootstepSurface : uint8_t; }
namespace audio { class MusicManager; class FootstepManager; class ActivitySoundManager; enum class FootstepSurface : uint8_t; }
namespace pipeline { class AssetManager; }
namespace rendering {
@ -151,6 +151,7 @@ private:
std::unique_ptr<Minimap> minimap;
std::unique_ptr<audio::MusicManager> musicManager;
std::unique_ptr<audio::FootstepManager> footstepManager;
std::unique_ptr<audio::ActivitySoundManager> activitySoundManager;
std::unique_ptr<game::ZoneManager> zoneManager;
pipeline::AssetManager* cachedAssetManager = nullptr;
@ -182,6 +183,11 @@ private:
uint32_t footstepLastAnimationId = 0;
float footstepLastNormTime = 0.0f;
bool footstepNormInitialized = false;
bool sfxStateInitialized = false;
bool sfxPrevGrounded = true;
bool sfxPrevJumping = false;
bool sfxPrevFalling = false;
bool sfxPrevSwimming = false;
bool terrainEnabled = true;
bool terrainLoaded = false;