diff --git a/core/logic/thread/BaseWorker.cpp b/core/logic/thread/BaseWorker.cpp index ef126e64..019af377 100644 --- a/core/logic/thread/BaseWorker.cpp +++ b/core/logic/thread/BaseWorker.cpp @@ -124,11 +124,6 @@ void BaseWorker::AddThreadToQueue(SWThreadHandle *pHandle) m_ThreadQueue.push_back(pHandle); } -unsigned int BaseWorker::GetMaxThreadsPerFrame() -{ - return m_perFrame; -} - WorkerState BaseWorker::GetStatus(unsigned int *threads) { if (threads) @@ -140,7 +135,7 @@ WorkerState BaseWorker::GetStatus(unsigned int *threads) unsigned int BaseWorker::RunFrame() { unsigned int done = 0; - unsigned int max = GetMaxThreadsPerFrame(); + unsigned int max = m_perFrame; SWThreadHandle *swt = NULL; IThread *pThread = NULL; diff --git a/core/logic/thread/BaseWorker.h b/core/logic/thread/BaseWorker.h index 38deaac9..0feceb5f 100644 --- a/core/logic/thread/BaseWorker.h +++ b/core/logic/thread/BaseWorker.h @@ -84,6 +84,8 @@ public: //IWorker virtual unsigned int Flush(bool flush_cancel); //returns status and number of threads in queue virtual WorkerState GetStatus(unsigned int *numThreads); + virtual void SetMaxThreadsPerFrame(unsigned int threads); + virtual void SetThinkTimePerFrame(unsigned int thinktime) {} public: //IThreadCreator virtual void MakeThread(IThread *pThread); virtual IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags); @@ -92,8 +94,6 @@ public: //IThreadCreator public: //BaseWorker virtual void AddThreadToQueue(SWThreadHandle *pHandle); virtual SWThreadHandle *PopThreadFromQueue(); - virtual void SetMaxThreadsPerFrame(unsigned int threads); - virtual unsigned int GetMaxThreadsPerFrame(); protected: SourceHook::List m_ThreadQueue; unsigned int m_perFrame; diff --git a/core/logic/thread/ThreadWorker.cpp b/core/logic/thread/ThreadWorker.cpp index 5f4c969e..91b1bff6 100644 --- a/core/logic/thread/ThreadWorker.cpp +++ b/core/logic/thread/ThreadWorker.cpp @@ -209,6 +209,11 @@ WorkerState ThreadWorker::GetStatus(unsigned int *threads) return state; } +void ThreadWorker::SetThinkTimePerFrame(unsigned int thinktime) +{ + m_think_time = thinktime; +} + bool ThreadWorker::Start() { if (m_state == Worker_Invalid) diff --git a/core/logic/thread/ThreadWorker.h b/core/logic/thread/ThreadWorker.h index 1699e244..ef653350 100644 --- a/core/logic/thread/ThreadWorker.h +++ b/core/logic/thread/ThreadWorker.h @@ -53,6 +53,8 @@ public: //IWorker virtual bool Stop(bool flush_cancel); //returns status and number of threads in queue virtual WorkerState GetStatus(unsigned int *numThreads); + //virtual void SetMaxThreadsPerFrame(unsigned int threads); + virtual void SetThinkTimePerFrame(unsigned int thinktime); public: //BaseWorker virtual void AddThreadToQueue(SWThreadHandle *pHandle); virtual SWThreadHandle *PopThreadFromQueue(); diff --git a/public/IThreader.h b/public/IThreader.h index 69821c69..9205b033 100644 --- a/public/IThreader.h +++ b/public/IThreader.h @@ -40,7 +40,7 @@ #include #define SMINTERFACE_THREADER_NAME "IThreader" -#define SMINTERFACE_THREADER_VERSION 2 +#define SMINTERFACE_THREADER_VERSION 3 namespace SourceMod { @@ -362,6 +362,23 @@ namespace SourceMod * @return State of the worker. */ virtual WorkerState GetStatus(unsigned int *numThreads) =0; + + /** + * @brief Sets the number of threads to run per frame. + * Default value is 1 thread per frame. + * + * @param threads Number of threads to run per frame. + */ + virtual void SetMaxThreadsPerFrame(unsigned int threads) =0; + + /** + * @brief For threaded workers, the think time of a frame. + * Has no effect for non-threaded workers. + * Default value is 50ms. + * + * @param thinktime Number of ms to sleep between frame execution. + */ + virtual void SetThinkTimePerFrame(unsigned int thinktime) =0; }; /**