View Single Post
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 09-12-2023 , 05:32   Re: [TUT] Tasks are Healthy, go for it
Reply With Quote #5

@Bugsy maybe back in the days it was somehow expensive, but i am not so sure. This looks fine to me

Code:
static cell AMX_NATIVE_CALL set_task(AMX *amx, cell *params) /* 2 param */
{

	CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx);

	int a, iFunc;

	char* stemp = get_amxstring(amx, params[2], 1, a);

	if (params[5])
	{
		iFunc = registerSPForwardByName(amx, stemp, FP_ARRAY, FP_CELL, FP_DONE);
	} else {
		iFunc = registerSPForwardByName(amx, stemp, FP_CELL, FP_DONE);
	}

	if (iFunc == -1)
	{
		LogError(amx, AMX_ERR_NATIVE, "Function is not present (function \"%s\") (plugin \"%s\")", stemp, plugin->getName());
		return 0;
	}

	float base = amx_ctof(params[1]);

	if (base < 0.1f)
		base = 0.1f;

	char* temp = get_amxstring(amx, params[6], 0, a);

	g_tasksMngr.registerTask(plugin, iFunc, UTIL_ReadFlags(temp), params[3], base, params[5], get_amxaddr(amx, params[4]), params[7]);

	return 1;
}
Code:
void CTaskMngr::registerTask(CPluginMngr::CPlugin *pPlugin, int iFunc, int iFlags, cell iId, float fBase, int iParamsLen, const cell *pParams, int iRepeat)
{
	// first, search for free tasks
	for (auto &task : m_Tasks)
	{
		if (task->isFree() && !task->inExecute())
		{
			// found: reuse it
			task->set(pPlugin, iFunc, iFlags, iId, fBase, iParamsLen, pParams, iRepeat, *m_pTmr_CurrentTime);
			return;
		}
	}
	// not found: make a new one
	auto task = ke::AutoPtr<CTask>(new CTask);
		
	if (!task)
		return;
		
	task->set(pPlugin, iFunc, iFlags, iId, fBase, iParamsLen, pParams, iRepeat, *m_pTmr_CurrentTime);
	m_Tasks.append(ke::Move(task));
}
But back in 2005 maybe it was an expensive operation. My first computer was a laptop, i am not sure what year it was but it was around 2005-2008 and it had finger print scan in order to login. Computers were not so bad back then, but who knows. Personally i believe this was a missconception, amxx was too fresh, it's normal to get some stuff wrong.
__________________
Jhob94 is offline