// Base class for all resources
virtual void Load(const std::string & sourcePath);
virtual void Unload();
// Resource manager
std::map< std::string, Resource * > m_Resources;
template< class T >
T * GetResource(const std::string & sourcePath)
if(m_Resources[sourcePath] != 0)
return dynamic_cast< T * >(m_Resources[sourcePath]);
T * newT = new T();
m_Resources[sourcePath] = newT;
So what happens is when you use the resource manager to get a resource.
It will first check to see if we have already loaded the resource and try to return that one.
If we havent loaded it, load it and store it so we later on can get it.
So the point of this function would be to set a tick priority.
Essentially saying, the further away an ai is from the player, the less frequently it will receive tick calls.
This however can and will create some other problems depending on how you would like things to be and act.
Just to keep it simple, if a spider is really far away and gets the low priority. It would move really slow and wont cover as much land as someone close to the player would.
void World::tick(float deltaTime)
// update all world units
for(int i=0; i<units.size(); ++i)
// always tick
return tickCount > 10;
return tickCount > 20;
Just to reiterate, its a very simple optimization.
It has it share of flaws depending on how you want ais who are far off screen to act.
But its easy to implement and its dynamic and will work for all ais who inherit from the same base class.
Im sure if you where to dig deeper into entity management and updating world entites you could find all sorts of interesting techniques and methods to handle large amount ais and what not.
But what i have presented here is a simple method to gain some performance (if the performance loss lies with to many units are getting updated that is),