Sign in to follow this  

interface

This topic is 4356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

// 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.


1. how to use for(int i...) instead of iterator(it need know SM::entityType) 2. are there any solution else? [Edited by - luasitdown on January 12, 2006 5:10:54 AM]

Share this post


Link to post
Share on other sites

// 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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this