I have been getting very good results using boost::multi_index, like this:
struct DrawOrder {};
struct UpdateOrder {};
typedef multi_index_container<
shared_ptr<WorldObject>,
indexed_by<
ordered_non_unique<tag<DrawOrder>,member<WorldObject,double,&WorldObject::drawPriority> >,
ordered_non_unique<tag<UpdateOrder>,member<WorldObject,double,&WorldObject::updatePriority> >
>
> WorldObjectGroup;
typedef WorldObjectGroup::index<DrawOrder>::type ObjectsByDrawOrder;
typedef WorldObjectGroup::index<UpdateOrder>::type ObjectsByUpdateOrder;
WorldObjectGroup objects; // our object list
///////////////////////////////////////////////////////////////////////////////
// Update all objects:
void World::Update(Duration deltaTime) {
ObjectsByUpdateOrder &updateList = objects.get<UpdateOrder>();
ObjectsByUpdateOrder::iterator iter, obj;
for(iter=updateList.begin(); iter!=updateList.end(); ) {
obj=iter;
iter++;
if(not (*obj)->Update(deltaTime)) {
updateList.erase(obj);
}
}
}
///////////////////////////////////////////////////////////////////////////////
// Draw all objects:
void World::Render() {
ObjectsByDrawOrder &renderList = objects.get<DrawOrder>();
GameWindow.SetView(camera.view);
sf::View view;
for(auto obj : renderList) {
view=camera.view;
sf::Transformable xform = obj->transform;
if(obj->parallax != 1.0f) {
view.SetCenter(view.GetCenter() * obj->parallax);
GameWindow.SetView(view);
//xform.SetPosition(camera.view.GetCenter() * obj->parallax);
}
obj->Render(GameWindow, sf::Transform());
}
}
Sorry for the mess of code, it's just a copy-paste from the current project I'm working on.
So I get my objects sorted not only according to z-order, but by update order as well! Also, if you're developing a top-down RPG like Zelda or whatnot you could always add an index using the Y coordinate of your object, so you could have characters going behind buildings, etc.
Hope this helps!