2022-08-19 21:33:31 +02:00
|
|
|
#ifndef TIER0_FRAMETASK_H
|
|
|
|
#define TIER0_FRAMETASK_H
|
|
|
|
|
|
|
|
#include "public/iframetask.h"
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
//=============================================================================//
|
|
|
|
// This class is set up to run before each frame (main thread).
|
2022-09-09 19:47:31 +02:00
|
|
|
// Committed tasks are scheduled to execute after 'i' frames.
|
2022-08-27 18:57:56 +02:00
|
|
|
// ----------------------------------------------------------------------------
|
2022-09-09 19:47:31 +02:00
|
|
|
// A use case for scheduling tasks in the main thread would be (for example)
|
2022-08-27 18:57:56 +02:00
|
|
|
// calling 'KeyValues::ParsePlaylists(...)' from the render thread.
|
|
|
|
//=============================================================================//
|
2022-08-19 21:33:31 +02:00
|
|
|
class CFrameTask : public IFrameTask
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~CFrameTask() {}
|
|
|
|
virtual void RunFrame();
|
|
|
|
virtual bool IsFinished() const;
|
|
|
|
|
2022-08-27 18:57:56 +02:00
|
|
|
void Dispatch(std::function<void()> functor, int frames);
|
2022-08-19 21:33:31 +02:00
|
|
|
|
|
|
|
private:
|
2022-08-27 18:57:56 +02:00
|
|
|
mutable std::mutex m_Mutex;
|
2022-09-09 02:28:03 +02:00
|
|
|
std::list<ScheduledTasks_s> m_ScheduledTasks;
|
2022-08-19 21:33:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern std::list<IFrameTask*> g_FrameTasks;
|
2022-08-27 18:57:56 +02:00
|
|
|
extern CFrameTask* g_TaskScheduler;
|
2022-08-19 21:33:31 +02:00
|
|
|
|
|
|
|
#endif // TIER0_FRAMETASK_H
|