2014-08-04 12:36:20 +04:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
2004-01-31 23:56:22 +03:00
|
|
|
|
|
|
|
#ifndef CTASK_H
|
|
|
|
#define CTASK_H
|
|
|
|
|
|
|
|
class CTaskMngr
|
|
|
|
{
|
2006-01-06 08:10:17 +03:00
|
|
|
private:
|
2004-07-18 22:48:20 +04:00
|
|
|
/*** class CTask ***/
|
2004-01-31 23:56:22 +03:00
|
|
|
class CTask
|
|
|
|
{
|
2006-01-06 08:10:17 +03:00
|
|
|
// task settings
|
|
|
|
|
2004-07-18 22:48:20 +04:00
|
|
|
CPluginMngr::CPlugin *m_pPlugin;
|
2005-10-19 01:05:52 +04:00
|
|
|
cell m_iId;
|
2004-07-18 22:48:20 +04:00
|
|
|
int m_iFunc;
|
|
|
|
int m_iRepeat;
|
2006-01-06 08:10:17 +03:00
|
|
|
|
2006-05-17 01:08:19 +04:00
|
|
|
bool m_bInExecute;
|
2006-01-06 08:10:17 +03:00
|
|
|
bool m_bLoop;
|
|
|
|
bool m_bAfterStart;
|
|
|
|
bool m_bBeforeEnd;
|
|
|
|
float m_fBase; // for normal tasks, stores the interval, for the others, stores the amount of time before start / after end
|
2004-07-18 22:48:20 +04:00
|
|
|
int m_iParamLen;
|
2006-01-06 08:10:17 +03:00
|
|
|
|
2004-07-18 22:48:20 +04:00
|
|
|
cell *m_pParams;
|
2006-01-06 08:10:17 +03:00
|
|
|
bool m_bFree;
|
|
|
|
|
|
|
|
// execution
|
2004-07-18 22:48:20 +04:00
|
|
|
float m_fNextExecTime;
|
2004-01-31 23:56:22 +03:00
|
|
|
public:
|
2005-10-19 01:05:52 +04:00
|
|
|
void set(CPluginMngr::CPlugin *pPlugin, int iFunc, int iFlags, cell iId, float fBase, int iParamsLen, const cell *pParams, int iRepeat, float fCurrentTime);
|
2005-09-10 04:38:42 +04:00
|
|
|
void clear();
|
|
|
|
bool isFree() const;
|
2006-01-06 08:10:17 +03:00
|
|
|
|
2006-05-17 01:08:19 +04:00
|
|
|
inline CPluginMngr::CPlugin *getPlugin() const { return m_pPlugin; }
|
|
|
|
inline AMX *getAMX() const { return m_pPlugin->getAMX(); }
|
|
|
|
inline int getTaskId() const { return m_iId; }
|
2006-01-06 08:10:17 +03:00
|
|
|
|
|
|
|
void executeIfRequired(float fCurrentTime, float fTimeLimit, float fTimeLeft); // also removes the task if needed
|
|
|
|
|
2005-09-10 04:38:42 +04:00
|
|
|
void changeBase(float fNewBase);
|
|
|
|
void resetNextExecTime(float fCurrentTime);
|
2006-05-17 01:08:19 +04:00
|
|
|
inline bool inExecute() const { return m_bInExecute; }
|
2006-01-06 08:10:17 +03:00
|
|
|
|
2005-09-10 04:38:42 +04:00
|
|
|
bool shouldRepeat();
|
2006-01-06 08:10:17 +03:00
|
|
|
|
2004-07-18 22:48:20 +04:00
|
|
|
CTask();
|
|
|
|
~CTask();
|
|
|
|
};
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2006-01-06 08:10:17 +03:00
|
|
|
class CTaskDescriptor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cell m_iId;
|
|
|
|
AMX *m_pAmx;
|
|
|
|
bool m_bFree;
|
|
|
|
|
|
|
|
CTaskDescriptor(int iId, AMX *pAmx, bool bFree = false)
|
|
|
|
{
|
|
|
|
m_iId = iId;
|
|
|
|
m_pAmx = pAmx;
|
|
|
|
m_bFree = bFree;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator == (const CTask &left, const CTaskDescriptor &right)
|
|
|
|
{
|
|
|
|
if (right.m_bFree)
|
2006-05-17 01:08:19 +04:00
|
|
|
return (left.isFree() && !left.inExecute());
|
2006-01-06 08:10:17 +03:00
|
|
|
|
2006-05-17 01:08:19 +04:00
|
|
|
return (!left.isFree()) &&
|
|
|
|
(right.m_pAmx ? left.getAMX() == right.m_pAmx : true) &&
|
|
|
|
(left.getTaskId() == right.m_iId);
|
2006-01-06 08:10:17 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-07-18 22:48:20 +04:00
|
|
|
/*** CTaskMngr priv members ***/
|
2006-01-06 08:10:17 +03:00
|
|
|
typedef CList<CTask, CTaskDescriptor> TaskList;
|
|
|
|
typedef TaskList::iterator TaskListIter;
|
|
|
|
|
|
|
|
TaskList m_Tasks;
|
|
|
|
|
2004-07-18 22:48:20 +04:00
|
|
|
float *m_pTmr_CurrentTime;
|
|
|
|
float *m_pTmr_TimeLimit;
|
|
|
|
float *m_pTmr_TimeLeft;
|
|
|
|
public:
|
|
|
|
CTaskMngr();
|
2005-07-25 23:09:49 +04:00
|
|
|
~CTaskMngr();
|
2004-07-18 22:48:20 +04:00
|
|
|
|
|
|
|
void registerTimers(float *pCurrentTime, float *pTimeLimit, float *pTimeLeft); // The timers will always point to the right value
|
2005-10-19 01:05:52 +04:00
|
|
|
void registerTask(CPluginMngr::CPlugin *pPlugin, int iFunc, int iFlags, cell iId, float fBase, int iParamsLen, const cell *pParams, int iRepeat);
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2005-09-10 04:38:42 +04:00
|
|
|
int removeTasks(int iId, AMX *pAmx); // remove all tasks that match the id and amx
|
|
|
|
int changeTasks(int iId, AMX *pAmx, float fNewBase); // change all tasks that match the id and amx
|
2004-07-18 22:48:20 +04:00
|
|
|
bool taskExists(int iId, AMX *pAmx);
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2004-07-18 22:48:20 +04:00
|
|
|
void startFrame();
|
|
|
|
void clear();
|
2004-01-31 23:56:22 +03:00
|
|
|
};
|
|
|
|
|
2005-09-10 04:38:42 +04:00
|
|
|
#endif //CTASK_H
|