1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00
OpenMW/apps/openmw/mwlua/worker.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.1 KiB
C++
Raw Normal View History

2022-10-05 23:45:45 +00:00
#ifndef OPENMW_MWLUA_WORKER_H
#define OPENMW_MWLUA_WORKER_H
#include <osg/Timer>
#include <osg/ref_ptr>
2022-10-05 23:45:45 +00:00
#include <condition_variable>
#include <mutex>
#include <optional>
#include <thread>
namespace osg
2022-10-05 23:45:45 +00:00
{
class Stats;
2022-10-05 23:45:45 +00:00
}
namespace MWLua
{
class LuaManager;
class Worker
{
public:
explicit Worker(LuaManager& manager);
2022-10-05 23:45:45 +00:00
~Worker();
void allowUpdate(osg::Timer_t frameStart, unsigned int frameNumber, osg::Stats& stats);
2022-10-05 23:45:45 +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:
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;
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