Hi folks, it is sane to make a class to create 'Tasks' in a metamod plugin using this:
.cpp
Code:
#include "Task.h"
cTask gTask;
cTask::cTask()
{
this->m_Data.clear();
}
void cTask::SetTask(int iIndex,float fTime,bool bLoop)
{
if(!this->TaskExists(iIndex))
{
pTaskInfo pInfo =
{
iIndex,
fTime,
gpGlobals->time + fTime,
bLoop
};
this->m_Data.insert(std::pair<int, pTaskInfo>(iIndex, pInfo));
}
}
bool cTask::TaskExists(int iIndex)
{
return (this->m_Data.find(iIndex) != this->m_Data.end());
}
void cTask::Run() // StartFrame_Post
{
for(auto it = this->m_Data.begin();it != this->m_Data.end();it++)
{
if(gpGlobals->time >= it->second.fEndTime)
{
////////////////////////////
// Run Function an function
////////////////////////////
if(it->second.bLoop)
{
it->second.fEndTime += it->second.fTime;
}
else
{
it = this->m_Data.erase(it);
}
}
else
{
it++;
}
}
}
.h
Code:
#pragma once
typedef struct
{
int iIndex;
float fTime;
float fEndTime;
bool bLoop;
} pTaskInfo, *lpTaskInfo;
class cTask
{
public:
cTask();
void SetTask(int iIndex,float fTime,bool bLoop);
bool TaskExists(int iIndex);
void Run();
private:
std::map<int, pTaskInfo> m_Data;
};
extern cTask gTask;
Ps.
I'm using StartFrame_Post to run the ::Run of tasks.
If is a sane thing, how i pass a function as parameter to SetTask or something like else?
__________________