void sMap::InsertLayerFromMap(int where, const sMap& map, int layer) { const sLayer& old_l = map.GetLayer(layer); sLayer new_l(old_l.GetWidth(), old_l.GetHeight()); // merge the two tilesets, updating the indices in layer 'l' sTileset& dst_ts = m_Tileset; const sTileset& src_ts = map.GetTileset(); // add each tile to the tileset for (int i = src_ts.GetNumTiles() - 1; i >= 0; i--) { // if it's already in the old tileset, we don't need to add it bool duplication = false; for (int j = 0; j < dst_ts.GetNumTiles(); j++) { if (src_ts.GetTile(i) == dst_ts.GetTile(j)) { // put 'j' where 'i' was in old layer for (int iy = 0; iy < old_l.GetHeight(); iy++) { for (int ix = 0; ix < old_l.GetWidth(); ix++) { if (old_l.GetTile(ix, iy) == i) { new_l.SetTile(ix, iy, j); } } } duplication = true; break; } } // add tile to end of tileset if (!duplication) { dst_ts.AppendTiles(1); int j = dst_ts.GetNumTiles() - 1; dst_ts.GetTile(j) = src_ts.GetTile(i); // put 'j' where 'i' was in old layer for (int iy = 0; iy < old_l.GetHeight(); iy++) { for (int ix = 0; ix < old_l.GetWidth(); ix++) { if (old_l.GetTile(ix, iy) == i) { new_l.SetTile(ix, iy, j); } } } } } InsertLayer(where, new_l); }
void hsGMaterial::SetLayer(plLayerInterface* layer, int32_t which, bool insert, bool piggyBack) { if( insert ) { InsertLayer(layer, which, piggyBack); } else { hsTArray<plLayerInterface*>& layers = piggyBack ? fPiggyBacks : fLayers; if( which < 0 ) which = layers.GetCount(); hsAssert(which <= layers.GetCount(), "Material layers Exceeding test depth"); if( which < layers.GetCount() ) layers[which] = layer; else layers.Append(layer); } }
void sMap::DuplicateLayer(int layer) { sLayer l = m_Layers[layer]; InsertLayer(layer, l); }