fix event loop timing issue

The event loop tries to run no faster than every 10ms. If it detects
that it goes faster, it would incorrectly calculate the difference, and
then wait (what I assume was) way too long or too short.
Either way, now it's fixed and it correctly works, even when introducing
new lua states.
This commit is contained in:
Lion Kortlepel
2022-07-20 14:31:32 +02:00
parent 6a94060970
commit fd7b11f436
14 changed files with 71 additions and 51 deletions

View File

@@ -187,7 +187,7 @@ private:
class StateThreadData : IThreaded {
public:
StateThreadData(const std::string& Name, std::atomic_bool& Shutdown, TLuaStateId StateId, TLuaEngine& Engine);
StateThreadData(const std::string& Name, TLuaStateId StateId, TLuaEngine& Engine);
StateThreadData(const StateThreadData&) = delete;
~StateThreadData() noexcept { beammp_debug("\"" + mStateId + "\" destroyed"); }
[[nodiscard]] std::shared_ptr<TLuaResult> EnqueueScript(const TLuaChunk& Script);
@@ -218,7 +218,6 @@ private:
sol::table Lua_FS_ListDirectories(const std::string& Path);
std::string mName;
std::atomic_bool& mShutdown;
TLuaStateId mStateId;
lua_State* mState;
std::thread mThread;
@@ -247,8 +246,7 @@ private:
TNetwork* mNetwork;
TServer* mServer;
std::atomic_bool mShutdown { false };
fs::path mResourceServerPath;
const fs::path mResourceServerPath;
std::vector<std::shared_ptr<TLuaPlugin>> mLuaPlugins;
std::unordered_map<TLuaStateId, std::unique_ptr<StateThreadData>> mLuaStates;
std::recursive_mutex mLuaStatesMutex;