View Single Post
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 11-14-2019 , 01:47   Re: Make tasks inside ServerFrame loop
Reply With Quote #4

If the looping is what you are worried about, then it is totally safe, as both SM and AMXx does it that one.

Also,
Code:
void cTask::Run() // StartFrame_Post
{
	for(auto it = this->m_Data.begin();it != this->m_Data.end();it++)
	{
		if(gpGlobals->time >= it->second.EndTime)
		{
			((void(*)(int))it->second.FunctionCallback)(it->second.Param);

			if(it->second.Loop)
			{
				it->second.EndTime += it->second.Time;
			}
			else
			{
				it = this->m_Data.erase(it);
			}
		}
		else
		{
			it++;
		}
	}
}
I don't uderstand why are you incrementing it here if the task time is yet to come? in some cases it may even increment it twice because the loop does it already:

Code:
void cTask::Run() // StartFrame_Post
{
	for(auto it = this->m_Data.begin();it != this->m_Data.end();it++)
	{
		if(gpGlobals->time >= it->second.EndTime)
		{
			((void(*)(int))it->second.FunctionCallback)(it->second.Param);

			if(it->second.Loop)
			{
				it->second.EndTime += it->second.Time;
			}
			else
			{
				it = this->m_Data.erase(it);
			}
		}		
	}
}
This should suffice.
TheDS1337 is offline