Files
EVEngine/src/modules/timer/Timer.h
T
西风逍遥游 548dc34087 feat(common): capability-registered filesystem/network/timer service interfaces + mocks
Add eve::service::{IFileSystem, INetwork, ITimer} in common/ServiceInterfaces.h.
The real modules register themselves via cap::provide at construction:
- filesystem: readFile/writeFile/fileExists (PhysFS-backed, failure returns false)
- network: synchronous httpRequest polling the existing worker completions
- timer: elapsedSeconds from the SDL performance counter

test/service_mocks.cpp provides deterministic doubles (missing files, read/write
failures, HTTP 404/transport errors, scripted clock) so consumers can exercise
error paths offline; also verifies Timer registers the real provider.
2026-08-22 08:31:37 +08:00

41 lines
1.0 KiB
C++

#pragma once
#include "common/Capability.h"
#include "common/Module.h"
#include "common/ServiceInterfaces.h"
#include <cstdint>
namespace eve::timer {
/**
* @brief High-resolution frame/elapsed timer backed by SDL_GetPerformanceCounter().
* Script: `timer <- eve.Timer();`
*/
class Timer : public Module, public eve::service::ITimer {
public:
Module_REG(Timer);
Timer();
~Timer() override = default;
/**
* @brief Seconds since the Timer was created (0 if the timer is unavailable).
* Returns float (not double): SimpleSquirrel only pushes double when SQUSEDOUBLE is defined.
*/
float getTime() const;
/** @brief Seconds between the last two step() calls (0 until the first step). */
float getDelta() const;
/** @brief Advances the frame clock and returns the new delta in seconds. */
float step();
double elapsedSeconds() override { return getTime(); }
private:
uint64_t freq_ = 0;
uint64_t start_ = 0;
uint64_t prev_ = 0;
float delta_ = 0.f;
};
} // namespace eve::timer