// psesudo code
class SM
{
typedef map<TYPE> entityType
map<TYPE> getentityMap() {return ...}
map<TYPE> entityMap;
}
void update()
{
SM::entityType temp getentityMap();
SM::entityType::Iterator iter;
for(iter=temp.begin();iter!=temp.end();iter++)
iter->second->update();
}
//it seem to complex.
//I see a engine do this way:
void update()
{
for(int i=0;i<something.size();i++)
{
getentity(i).update();
}
}
//it look simple.
interface
Put the update function in the SM class itself.
You probably want to return & manipulate a map reference, not a value.
You probably want to return & manipulate a map reference, not a value.
// update level & level objects {dev::Profile pr( "update.level" ); m_level->update( dt );} if ( m_wasActiveCutScene && !m_level->isActiveCutScene() ) focusLost(); m_wasActiveCutScene = m_level->isActiveCutScene(); for ( int i = 0; i < m_level->characters(); ++i ) m_level->getCharacter(i)->update( dt, updatesInThisFrame==0 ); {dev::Profile pr( "update.weapons" ); for ( int i = 0; i < m_level->weapons(); ++i ) m_level->getWeapon(i)->update( dt );} {dev::Profile pr( "update.triggers" ); for ( int i = 0; i < m_level->triggers(); ++i ) m_level->getTrigger(i)->update( dt );} {dev::Profile pr( "update.dynamicObjects" ); for ( int i = 0; i < m_level->dynamicObjects(); ++i ) m_level->getDynamicObject(i)->update( dt );} {dev::Profile pr( "update.noises" ); m_noiseMgr->update( totalDt );} // update camera {dev::Profile pr( "update.camera" ); if ( m_activeCamera && !m_cfg->getBoolean("Game.FlyCamera") && !m_arcBallCameraEnabled ) m_activeCamera->update( dt );} // update projectiles {dev::Profile pr( "update.projectiles" ); m_projectileMgr->update( dt );}
look how to update() in a engine. is it a good structure?
Iterators are not more complicated than using the size(). You should use iterators because it allows you to you things from algorithm (sort, for_each, etc) and other parts of the stl such as erase(itt.begin(), itt.end())
You can use the counter version for any STL object that has size() and operator[] defined.
You can use the counter version for any STL object that has size() and operator[] defined.
Quote:Original post by luasitdown
*** Source Snippet Removed ***
look how to update() in a engine. is it a good structure?
It really doesnt matter, as long as it works, its such a simple piece of code it will be unlikely to affect performance.
Quote:Original post by dave_
Iterators are not more complicated than using the size(). You should use iterators because it allows you to you things from algorithm (sort, for_each, etc) and other parts of the stl such as erase(itt.begin(), itt.end())
You can use the counter version for any STL object that has size() and operator[] defined.
the map object has no [] .
Entity* SM::entity(int index)
{
EntityMap::iterator iter;
iter = m_entityMap.begin();
return (iter+index)->second;
}
I do this way, but iter+index is error. why?
Quote:Original post by luasitdown
I do this way, but iter+index is error. why?
Because a map iterator is a bidirectional iterator, not a random access iterator. You can only step it one element at a time. Your indexing scheme cannot work efficiently.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement