}
-void PartCache::clear()
+void PartCache::begin_rebuild()
{
- parts.clear();
+ next = parts.begin();
+ current = parts.end();
}
void PartCache::insert_special(const Part &part)
if(part.get_name().empty())
throw invalid_argument("PartCache::insert_special");
- parts.push_back(CachedPart());
- parts.back().part = ∂
+ for(current=next; current!=parts.end(); ++current)
+ if(current->part==&part)
+ {
+ parts.erase(next, current);
+ break;
+ }
+
+ if(current==parts.end())
+ current = parts.insert(next, CachedPart());
+ else
+ *current = CachedPart();
+ current->part = ∂
+
+ next = current;
+ ++next;
}
GL::Mesh &PartCache::create_mesh(const Part &part, const GL::Texture2D &tex)
{
- if(!parts.empty() && parts.back().texture==&tex)
- return *parts.back().mesh;
-
- parts.push_back(CachedPart());
- CachedPart &cpart = parts.back();
- cpart.part = ∂
- cpart.texture = &tex;
- cpart.mesh = new GL::Mesh((GL::TEXCOORD2, GL::COLOR4_UBYTE, GL::VERTEX2));
- return *cpart.mesh;
+ if(current!=parts.end() && current->texture==&tex)
+ return *current->mesh;
+
+ for(current=next; current!=parts.end(); ++current)
+ if(current->texture==&tex)
+ {
+ parts.erase(next, current);
+ break;
+ }
+
+ if(current==parts.end())
+ {
+ current = parts.insert(next, CachedPart());
+ current->texture = &tex;
+ current->mesh = new GL::Mesh((GL::TEXCOORD2, GL::COLOR4_UBYTE, GL::VERTEX2));
+ }
+ else
+ current->mesh->clear();
+ current->part = ∂
+
+ next = current;
+ ++next;
+
+ return *current->mesh;
+}
+
+void PartCache::end_rebuild()
+{
+ parts.erase(next, parts.end());
}
} // namespace GLtk