This commit is contained in:
Crypto City 2019-08-13 14:58:06 +00:00
parent 65549199c6
commit d2f70a2fd4

View File

@ -253,7 +253,6 @@ void CityMeshSection::RebuildFlags(const C &flags, bool edit)
parent = blockNodes[flag->id] = blocksNode->CreateChild("blockNode");
else
parent = it->second;
parent->RemoveAllChildren();
for (uint32_t y = fy0; y <= fy1; ++y)
{
@ -261,6 +260,12 @@ void CityMeshSection::RebuildFlags(const C &flags, bool edit)
{
const uint16_t th = flag->get_tile_height(x, y);
const uint16_t prevth = nodes[y - vy0][x - vx0].blocks.size();
if (th < prevth)
{
for (uint32_t h = th; h < prevth; ++h)
if (nodes[y - vy0][x - vx0].blocks[h].node)
nodes[y - vy0][x - vx0].blocks[h].node->Remove();
}
nodes[y - vy0][x - vx0].blocks.resize(th);
for (uint32_t h = 0; h < th; ++h)
{
@ -276,20 +281,30 @@ void CityMeshSection::RebuildFlags(const C &flags, bool edit)
if (hidden)
{
++n_hidden;
if (nodes[y - vy0][x - vx0].blocks[h].node)
nodes[y - vy0][x - vx0].blocks[h].node->Remove();
nodes[y - vy0][x - vx0].blocks[h] = {NULL, type, false};
continue;
}
SharedPtr<StaticModel> blockObject;
if (!nodes[y - vy0][x - vx0].blocks[h].node)
{
SharedPtr<Node> blockNode(parent->CreateChild("block"));
blockNode->SetPosition(Vector3(U2F1(,x), h + 0.5f, U2F1(,y)));
blockNode->SetScale(1);
auto* blockObject = blockNode->CreateComponent<StaticModel>();
blockObject = blockNode->CreateComponent<StaticModel>();
blockObject->SetModel(resources.blockModel);
nodes[y - vy0][x - vx0].blocks[h].node = std::move(blockNode);
}
else
blockObject = nodes[y - vy0][x - vx0].blocks[h].node->GetComponent<StaticModel>();
const bool is_new = !edit && h >= prevth;
const MaterialVersion mv = is_new ? MVNew : MVNormal;
blockObject->SetMaterial(resources.materials[mv][type]);
nodes[y - vy0][x - vx0].blocks[h].type = type;
nodes[y - vy0][x - vx0].blocks[h].is_new = is_new;
//blockObject->SetCastShadows(true);
nodes[y - vy0][x - vx0].blocks[h] = {std::move(blockNode), type, is_new};
++ncubes;
}