mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-04 02:41:19 +00:00
b4976354a5
When a loading screen appears during the frame processing, the frame number returned by the viewer is incremented and the stats reporting goes into the wrong frame. Pass frame number and stats object from the main thread to avoid this.
56 lines
1.1 KiB
C++
56 lines
1.1 KiB
C++
#ifndef OPENMW_MWLUA_WORKER_H
|
|
#define OPENMW_MWLUA_WORKER_H
|
|
|
|
#include <osg/Timer>
|
|
#include <osg/ref_ptr>
|
|
|
|
#include <condition_variable>
|
|
#include <mutex>
|
|
#include <optional>
|
|
#include <thread>
|
|
|
|
namespace osg
|
|
{
|
|
class Stats;
|
|
}
|
|
|
|
namespace MWLua
|
|
{
|
|
class LuaManager;
|
|
|
|
class Worker
|
|
{
|
|
public:
|
|
explicit Worker(LuaManager& manager);
|
|
|
|
~Worker();
|
|
|
|
void allowUpdate(osg::Timer_t frameStart, unsigned int frameNumber, osg::Stats& stats);
|
|
|
|
void finishUpdate(osg::Timer_t frameStart, unsigned int frameNumber, osg::Stats& stats);
|
|
|
|
void join();
|
|
|
|
private:
|
|
struct UpdateRequest
|
|
{
|
|
osg::Timer_t mFrameStart;
|
|
unsigned mFrameNumber;
|
|
osg::ref_ptr<osg::Stats> mStats;
|
|
};
|
|
|
|
void update(osg::Timer_t frameStart, unsigned frameNumber, osg::Stats& stats);
|
|
|
|
void run() noexcept;
|
|
|
|
LuaManager& mManager;
|
|
std::mutex mMutex;
|
|
std::condition_variable mCV;
|
|
std::optional<UpdateRequest> mUpdateRequest;
|
|
bool mJoinRequest = false;
|
|
std::optional<std::thread> mThread;
|
|
};
|
|
}
|
|
|
|
#endif // OPENMW_MWLUA_LUAWORKER_H
|