mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Replace POSIX-specific socket and process APIs with portable abstractions so the project builds on both Windows and Linux. - Add include/network/net_platform.hpp: Winsock2/POSIX socket abstraction (socket types, non-blocking, error handling, WSAStartup lifecycle) - Add include/platform/process.hpp: CreateProcess/fork+exec abstraction for spawning ffplay subprocesses - Update network module (tcp_socket, world_socket) to use portable socket helpers instead of raw POSIX calls - Update audio module (music_manager, footstep_manager, activity_sound_manager) to use portable process helpers instead of fork/exec/kill/waitpid - Replace hardcoded /tmp/ paths with std::filesystem::temp_directory_path() - Link ws2_32 and SDL2main on Windows in CMakeLists.txt
67 lines
1.5 KiB
C++
67 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "platform/process.hpp"
|
|
#include <cstdint>
|
|
#include <random>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <chrono>
|
|
|
|
namespace wowee {
|
|
namespace pipeline { class AssetManager; }
|
|
|
|
namespace audio {
|
|
|
|
enum class FootstepSurface : uint8_t {
|
|
STONE = 0,
|
|
DIRT,
|
|
GRASS,
|
|
WOOD,
|
|
METAL,
|
|
WATER,
|
|
SNOW
|
|
};
|
|
|
|
class FootstepManager {
|
|
public:
|
|
FootstepManager();
|
|
~FootstepManager();
|
|
|
|
bool initialize(pipeline::AssetManager* assets);
|
|
void shutdown();
|
|
|
|
void update(float deltaTime);
|
|
void playFootstep(FootstepSurface surface, bool sprinting);
|
|
|
|
bool isInitialized() const { return assetManager != nullptr; }
|
|
bool hasAnySamples() const { return sampleCount > 0; }
|
|
|
|
private:
|
|
struct Sample {
|
|
std::string path;
|
|
std::vector<uint8_t> data;
|
|
};
|
|
|
|
struct SurfaceSamples {
|
|
std::vector<Sample> clips;
|
|
};
|
|
|
|
void preloadSurface(FootstepSurface surface, const std::vector<std::string>& candidates);
|
|
void stopCurrentProcess();
|
|
void reapFinishedProcess();
|
|
bool playRandomStep(FootstepSurface surface, bool sprinting);
|
|
static const char* surfaceName(FootstepSurface surface);
|
|
|
|
pipeline::AssetManager* assetManager = nullptr;
|
|
SurfaceSamples surfaces[7];
|
|
size_t sampleCount = 0;
|
|
|
|
std::string tempFilePath = platform::getTempFilePath("wowee_footstep.wav");
|
|
ProcessHandle playerPid = INVALID_PROCESS;
|
|
std::chrono::steady_clock::time_point lastPlayTime = std::chrono::steady_clock::time_point{};
|
|
|
|
std::mt19937 rng;
|
|
};
|
|
|
|
} // namespace audio
|
|
} // namespace wowee
|