View Single Post
Re: Show off your finest piece of code!
Old
  (#10)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: Show off your finest piece of code! - 30-12-2004

about the A* Taskmanager ... I extended this idea a bit and made it more comfortable to work with ... here are the definitions : ( the actual code is nothing special, just some assignments and a simple algorithm for managing which task to execute, such stuff can be looked up in every operating system book )

Code:
class AStarBase;
class CBaseBot;
class CBehaviour;
class CCallback_onPathCreation;
// these classes handle astar task, so that you don't have any lags when paths are created. Each process is 
// executed only for some time ( based on the iteration count of A* ) and then next frame calculation is
// continued based on priority and time of last execution
class AStarTask{
	friend class AStarTaskManager;
public:
AStarTask();
AStarTask(AStarBase *p,int iPriority,CBaseBot *pBot,CCallback_onPathCreation *pPC=0,long lTime=0)
:m_pAStar(p),m_iPriority(iPriority),m_pBot(pBot),m_pCB_onPathCreation(pPC),m_lExecution(lTime),m_lExecuted(0),m_lAdded(lTime){}
virtual ~AStarTask();
protected:
AStarBase *m_pAStar;
CCallback_onPathCreation *m_pCB_onPathCreation;
CBaseBot *m_pBot;
int m_iPriority; // priority of task - 0 is lowest, 5 is default
long m_lExecution; // last execution cycle
long m_lAdded;	// when was this task added ?
long m_lExecuted; // how many slices are already executed ?
};
class AStarTaskManager {
public:
AStarTaskManager();
virtual ~AStarTaskManager();
void addTask(AStarBase *,int,CBaseBot *,CCallback_onPathCreation *pPC=0);
void run(void);
int deleteTasksFrom(CCallback_onPathCreation*); // delete tasks with this callback
long getTotalTasks(void){return m_lCTasksTotal;}
unsigned long getCurrentTotalTasks(void){return (unsigned long)m_LTasks.size();}
int getSlicesCPFrame(void){return m_iSlicesNow;}
protected:
int m_iSlicespF;	// Slices per frame
long m_lCounter;	// couting up each iteration
long m_lCTasksTotal; // Total Tasks added since start of manager
int m_iSlicesNow;	// how many slices have been calculated ?
list <AStarTask> m_LTasks; // list of tasks
};



Last edited by @$3.1415rin; 30-12-2004 at 16:46..
  
Reply With Quote