I am, of course, looking to optimize speed and memory usage. There is no actual overlap between the images I am putting together, but the order that I am drawing them might be non-linear, i.e. I might draw one in the top left and the bottom right, then a different one in the middle.
Here is my code as I have it now. "tiles" is a STL list of a class I wrote, sorted by each tile's id. "out" is the destination image. "ts" is a list of Drawables.
Code: Select all
prev_id = -1;
tl = NULL;
for (tiles_it = tiles.begin(); tiles_it != tiles.end(); tiles_it++) {
//if we've come upon a new id, draw out whatever we currently have
if ((*tiles_it).id() != prev_id) {
if (ts.empty() == false) {
out.draw(ts);
ts.clear();
}
prev_id = (*tiles_it).id();
//clean up the old image
if (tl != NULL)
tl->remove_image(base_size);
//get the new image
tl = &(*tiles_it);
}
//push back a new drawable for every tile we have
ts.push_back(DrawableCompositeImage((*tiles_it).x() * base_size, (*tiles_it).y() * base_size, tl->get_image(base_size)));
}