2004-03-05 21:03:14 +00:00
|
|
|
/* AMX Mod X
|
|
|
|
*
|
|
|
|
* by the AMX Mod X Development Team
|
|
|
|
* originally developed by OLO
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of this program with the Half-Life Game Engine ("HL
|
|
|
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL Engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
|
|
|
*/
|
2004-01-31 20:56:22 +00:00
|
|
|
|
|
|
|
#ifndef CTASK_H
|
|
|
|
#define CTASK_H
|
|
|
|
|
2005-11-29 00:52:35 +00:00
|
|
|
#define AVL_LEFT 0
|
|
|
|
#define AVL_RIGHT 1
|
|
|
|
#define AVL_PARENT -1
|
|
|
|
|
2005-11-22 04:14:07 +00:00
|
|
|
#include "sh_list.h"
|
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
class CTaskMngr
|
|
|
|
{
|
2005-10-25 20:38:00 +00:00
|
|
|
public:
|
2005-11-29 00:52:35 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
Task_Nothing = 0,
|
|
|
|
Task_Done,
|
|
|
|
Task_Rel
|
|
|
|
};
|
2004-07-18 18:48:20 +00:00
|
|
|
/*** class CTask ***/
|
2004-01-31 20:56:22 +00:00
|
|
|
class CTask
|
|
|
|
{
|
2005-11-29 00:52:35 +00:00
|
|
|
friend class CTaskMngr;
|
|
|
|
//plugin
|
2004-07-18 18:48:20 +00:00
|
|
|
CPluginMngr::CPlugin *m_pPlugin;
|
2005-11-29 00:52:35 +00:00
|
|
|
//task ID
|
2005-10-18 21:05:52 +00:00
|
|
|
cell m_iId;
|
2005-11-29 00:52:35 +00:00
|
|
|
//registered forward
|
2004-07-18 18:48:20 +00:00
|
|
|
int m_iFunc;
|
2005-11-29 00:52:35 +00:00
|
|
|
//number of times to repeat
|
2004-07-18 18:48:20 +00:00
|
|
|
int m_iRepeat;
|
2005-11-29 00:52:35 +00:00
|
|
|
//type of task (a|b, c, d)
|
2005-11-22 04:14:07 +00:00
|
|
|
int type;
|
2005-11-29 00:52:35 +00:00
|
|
|
// for normal tasks, stores the interval, for the others, stores the amount of time before start / after end
|
|
|
|
float m_fBase;
|
|
|
|
//Number of parameters
|
2004-07-18 18:48:20 +00:00
|
|
|
int m_iParamLen;
|
2005-11-29 00:52:35 +00:00
|
|
|
//Parameter array
|
2004-07-18 18:48:20 +00:00
|
|
|
cell *m_pParams;
|
2005-11-29 00:52:35 +00:00
|
|
|
//Size of parameter array
|
2005-10-25 20:38:00 +00:00
|
|
|
cell m_ParamSize;
|
2005-11-29 00:52:35 +00:00
|
|
|
//next execution
|
2004-07-18 18:48:20 +00:00
|
|
|
float m_fNextExecTime;
|
2005-11-29 00:52:35 +00:00
|
|
|
//will we repeat?
|
2005-11-22 04:14:07 +00:00
|
|
|
bool m_bLoop;
|
2005-11-29 00:52:35 +00:00
|
|
|
private:
|
|
|
|
//Tasks are both a binary tree and a doubly-linked list...
|
|
|
|
//The path of execution is stored in the linked list.
|
|
|
|
//The search tree is for fast insertion.
|
|
|
|
CTask *next;
|
|
|
|
CTask *prev;
|
|
|
|
CTask *child[2];
|
|
|
|
CTask *parent;
|
|
|
|
//balance factor for AVL trees
|
|
|
|
char balance;
|
|
|
|
int dir;
|
2004-01-31 20:56:22 +00:00
|
|
|
public:
|
2005-10-18 21:05:52 +00: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 00:38:42 +00:00
|
|
|
void clear();
|
|
|
|
bool isFree() const;
|
|
|
|
CPluginMngr::CPlugin *getPlugin() const;
|
|
|
|
int getTaskId() const;
|
2005-11-29 00:52:35 +00:00
|
|
|
int executeIfRequired(float fCurrentTime, float fTimeLimit, float fTimeLeft);
|
2005-09-10 00:38:42 +00:00
|
|
|
void changeBase(float fNewBase);
|
|
|
|
void resetNextExecTime(float fCurrentTime);
|
|
|
|
bool shouldRepeat();
|
2005-11-29 00:52:35 +00:00
|
|
|
float nextThink();
|
2004-07-18 18:48:20 +00:00
|
|
|
CTask();
|
|
|
|
~CTask();
|
|
|
|
};
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2004-07-18 18:48:20 +00:00
|
|
|
/*** CTaskMngr priv members ***/
|
2005-11-29 00:52:35 +00:00
|
|
|
CTask *root;
|
|
|
|
CTask *first;
|
2004-07-18 18:48:20 +00:00
|
|
|
float *m_pTmr_CurrentTime;
|
|
|
|
float *m_pTmr_TimeLimit;
|
|
|
|
float *m_pTmr_TimeLeft;
|
|
|
|
public:
|
|
|
|
CTaskMngr();
|
2005-07-25 19:09:49 +00:00
|
|
|
~CTaskMngr();
|
2004-07-18 18:48:20 +00:00
|
|
|
|
2005-11-29 00:52:35 +00:00
|
|
|
inline float CurrentTime() { return *m_pTmr_CurrentTime; }
|
|
|
|
inline float TimeLimit() { return *m_pTmr_TimeLimit; }
|
|
|
|
inline float TimeLeft() { return *m_pTmr_TimeLeft; }
|
2004-07-18 18:48:20 +00:00
|
|
|
void registerTimers(float *pCurrentTime, float *pTimeLimit, float *pTimeLeft); // The timers will always point to the right value
|
2005-10-18 21:05:52 +00:00
|
|
|
void registerTask(CPluginMngr::CPlugin *pPlugin, int iFunc, int iFlags, cell iId, float fBase, int iParamsLen, const cell *pParams, int iRepeat);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2005-11-29 00:52:35 +00:00
|
|
|
void insertTask(CTask *pTask);
|
|
|
|
void removeTask(CTask *pTask);
|
2005-09-10 00:38:42 +00: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 18:48:20 +00:00
|
|
|
bool taskExists(int iId, AMX *pAmx);
|
2005-09-16 23:48:51 +00:00
|
|
|
|
2004-07-18 18:48:20 +00:00
|
|
|
void startFrame();
|
|
|
|
void clear();
|
2005-11-29 00:52:35 +00:00
|
|
|
private:
|
|
|
|
void insertTask(CTask *pTask, float time, CTask *pRoot);
|
2004-01-31 20:56:22 +00:00
|
|
|
};
|
|
|
|
|
2005-09-10 00:38:42 +00:00
|
|
|
#endif //CTASK_H
|