mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Previously we did sq_pushroottable() and a subsequent sq_call() after compiling the text buffer, but this didn't work for code that was threaded, or using Get/SetNetVar* functions. The second issue was that the callback for the "script" command was ran in the main thread. Server script should always run in the server frame thread, the Set/GetNetVar* functions check thread id to retrieve the correct VM context, so running server script from the main thread ended up with Set/GetNetVar* functions retrieving the client VM context rather than server's, causing undefined behavior. Script commands are now queued to the server frame thread, ultimately fixing this bug. Also fixed a small bug with function 'sq_compilebuffer()'; it takes an extra argument but this wasn't taken into account in the SDK.
33 lines
1.1 KiB
C++
33 lines
1.1 KiB
C++
#ifndef TIER0_FRAMETASK_H
|
|
#define TIER0_FRAMETASK_H
|
|
|
|
#include "public/iframetask.h"
|
|
|
|
//=============================================================================//
|
|
// This class is set up to run before each frame, committed tasks are scheduled
|
|
// to execute after 'i' frames.
|
|
// ----------------------------------------------------------------------------
|
|
// A use case for scheduling tasks in the main thread would be (for example)
|
|
// performing a web request in a separate thread, and apply the results (such as
|
|
// server lists in the browser) onto the imgui panels which are created/drawn in
|
|
// the main thread
|
|
//=============================================================================//
|
|
class CFrameTask : public IFrameTask
|
|
{
|
|
public:
|
|
virtual ~CFrameTask() {}
|
|
virtual void RunFrame();
|
|
virtual bool IsFinished() const;
|
|
|
|
void Dispatch(std::function<void()> functor, unsigned int frames);
|
|
|
|
private:
|
|
mutable std::mutex m_Mutex;
|
|
std::list<QueuedTasks_s> m_QueuedTasks;
|
|
};
|
|
|
|
extern std::list<IFrameTask*> g_TaskQueueList;
|
|
extern CFrameTask g_TaskQueue;
|
|
|
|
#endif // TIER0_FRAMETASK_H
|