2022-10-05 23:45:45 +00:00
|
|
|
#ifndef OPENMW_MWLUA_WORKER_H
|
|
|
|
#define OPENMW_MWLUA_WORKER_H
|
|
|
|
|
2024-04-24 09:09:13 +00:00
|
|
|
#include <osg/Timer>
|
|
|
|
#include <osg/ref_ptr>
|
|
|
|
|
2022-10-05 23:45:45 +00:00
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
|
|
|
#include <optional>
|
|
|
|
#include <thread>
|
|
|
|
|
2024-04-24 09:09:13 +00:00
|
|
|
namespace osg
|
2022-10-05 23:45:45 +00:00
|
|
|
{
|
2024-04-24 09:09:13 +00:00
|
|
|
class Stats;
|
2022-10-05 23:45:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWLua
|
|
|
|
{
|
|
|
|
class LuaManager;
|
|
|
|
|
|
|
|
class Worker
|
|
|
|
{
|
|
|
|
public:
|
2024-04-24 09:09:13 +00:00
|
|
|
explicit Worker(LuaManager& manager);
|
2022-10-05 23:45:45 +00:00
|
|
|
|
|
|
|
~Worker();
|
|
|
|
|
2024-04-24 09:09:13 +00:00
|
|
|
void allowUpdate(osg::Timer_t frameStart, unsigned int frameNumber, osg::Stats& stats);
|
2022-10-05 23:45:45 +00:00
|
|
|
|
2024-04-24 09:09:13 +00:00
|
|
|
void finishUpdate(osg::Timer_t frameStart, unsigned int frameNumber, osg::Stats& stats);
|
2022-10-05 23:45:45 +00:00
|
|
|
|
|
|
|
void join();
|
|
|
|
|
|
|
|
private:
|
2024-04-24 09:09:13 +00:00
|
|
|
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);
|
2022-10-05 23:45:45 +00:00
|
|
|
|
|
|
|
void run() noexcept;
|
|
|
|
|
|
|
|
LuaManager& mManager;
|
|
|
|
std::mutex mMutex;
|
|
|
|
std::condition_variable mCV;
|
2024-04-24 09:09:13 +00:00
|
|
|
std::optional<UpdateRequest> mUpdateRequest;
|
2022-10-05 23:45:45 +00:00
|
|
|
bool mJoinRequest = false;
|
|
|
|
std::optional<std::thread> mThread;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // OPENMW_MWLUA_LUAWORKER_H
|