Files
Bret Curtis 620581ca65 Report frame stats through a renderer-agnostic interface
Physics, Lua, world, mechanics and the navigator reported their per-frame numbers straight into osg::Stats and timed themselves with osg::Timer, so every one of them carried OSG in its headers only to fill the profiler. They now report through Misc::FrameStats, a two-method interface (collectStats, setAttribute) that engine.cpp adapts to the viewer's osg::Stats, and they time with std::chrono::steady_clock; the engine expresses the viewer start tick on that clock, so the reported times stay on the timeline the OSG profiler draws and the stats file records.
2026-10-19 13:11:42 +02:00

62 lines
1.7 KiB
C++

#ifndef OPENMW_MWLUA_WORKER_H
#define OPENMW_MWLUA_WORKER_H
#include <components/misc/framestats.hpp>
#include <condition_variable>
#include <mutex>
#include <optional>
#include <thread>
namespace MWLua
{
class LuaManager;
class Worker
{
public:
explicit Worker(LuaManager& manager);
~Worker();
void allowUpdate(Misc::FrameClock::time_point statsEpoch, unsigned int frameNumber, Misc::FrameStats& stats);
void finishUpdate(Misc::FrameClock::time_point statsEpoch, unsigned int frameNumber, Misc::FrameStats& stats);
// Starts incremental garbage collection on the Lua thread. Runs in small
// steps until finishGc() is called or a full collection cycle completes.
// Without a Lua thread, does the configured amount of GC synchronously
// instead.
void gc();
// Stops garbage collection, waiting only for the step in flight. Must be
// called before the main thread touches the Lua state again.
void finishGc();
void join();
private:
struct UpdateRequest
{
Misc::FrameClock::time_point mStatsEpoch;
unsigned mFrameNumber;
Misc::FrameStats* mStats;
};
void update(Misc::FrameClock::time_point statsEpoch, unsigned frameNumber, Misc::FrameStats& stats);
void run() noexcept;
LuaManager& mManager;
std::mutex mMutex;
std::condition_variable mCV;
std::optional<UpdateRequest> mUpdateRequest;
bool mGcRequest = false;
bool mGcInProgress = false;
bool mJoinRequest = false;
std::optional<std::thread> mThread;
};
}
#endif // OPENMW_MWLUA_LUAWORKER_H