mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Compile it as static object & renamed to more correct names. Also made the integral type for frame delay an unsigned int instead
59 lines
1.9 KiB
C++
59 lines
1.9 KiB
C++
//=============================================================================//
|
|
//
|
|
// Purpose:
|
|
//
|
|
//-----------------------------------------------------------------------------
|
|
//
|
|
//=============================================================================//
|
|
#include "tier0/frametask.h"
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: run frame task and process queued calls
|
|
//-----------------------------------------------------------------------------
|
|
void CFrameTask::RunFrame()
|
|
{
|
|
std::lock_guard<std::mutex> l(m_Mutex);
|
|
|
|
for (QueuedTasks_s& delay : m_QueuedTasks)
|
|
{
|
|
if (delay.m_nDelayedFrames == 0)
|
|
{
|
|
delay.m_rFunctor();
|
|
}
|
|
|
|
--delay.m_nDelayedFrames;
|
|
}
|
|
|
|
const auto newEnd = std::remove_if(m_QueuedTasks.begin(), m_QueuedTasks.end(),
|
|
[](const QueuedTasks_s& delay)
|
|
{
|
|
return delay.m_nDelayedFrames == 0;
|
|
});
|
|
|
|
m_QueuedTasks.erase(newEnd, m_QueuedTasks.end());
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: is the task finished
|
|
// Output : true if finished, false otherwise
|
|
//-----------------------------------------------------------------------------
|
|
bool CFrameTask::IsFinished() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: adds function to list, to be called after 'i' frames.
|
|
// Input : functor -
|
|
// frames -
|
|
//-----------------------------------------------------------------------------
|
|
void CFrameTask::Dispatch(std::function<void()> functor, unsigned int frames)
|
|
{
|
|
std::lock_guard<std::mutex> l(m_Mutex);
|
|
m_QueuedTasks.emplace_back(frames, functor);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
std::list<IFrameTask*> g_TaskQueueList;
|
|
CFrameTask g_TaskQueue;
|