|
@@ -62,7 +62,28 @@ void Chunk::api(char* message)
|
|
pos.y += this->location.y - CHUNK_SIZE / 2;
|
|
pos.y += this->location.y - CHUNK_SIZE / 2;
|
|
Block* zB = zBlockAt(pos);
|
|
Block* zB = zBlockAt(pos);
|
|
if (zB)
|
|
if (zB)
|
|
|
|
+ {
|
|
|
|
+ bool visible = zB->isVisible();
|
|
zB->setLightData(getOppositeDirection(getDirectionFromIndex(i)), (unsigned char*)(message + 5));
|
|
zB->setLightData(getOppositeDirection(getDirectionFromIndex(i)), (unsigned char*)(message + 5));
|
|
|
|
+ if (zB->isVisible() != visible)
|
|
|
|
+ {
|
|
|
|
+ vcs.lock();
|
|
|
|
+ if (zB->isVisible())
|
|
|
|
+ visibleBlocks.add(zB);
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ for (Framework::Iterator<Block*> iterator = visibleBlocks.begin(); iterator; iterator++)
|
|
|
|
+ {
|
|
|
|
+ if (zB == (Block*)iterator)
|
|
|
|
+ {
|
|
|
|
+ iterator.remove();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ vcs.unlock();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -70,7 +91,29 @@ void Chunk::api(char* message)
|
|
pos.y += this->location.y - CHUNK_SIZE / 2;
|
|
pos.y += this->location.y - CHUNK_SIZE / 2;
|
|
Block* zB = currentGame->zBlockAt(pos);
|
|
Block* zB = currentGame->zBlockAt(pos);
|
|
if (zB)
|
|
if (zB)
|
|
|
|
+ {
|
|
|
|
+ bool visible = zB->isVisible();
|
|
zB->setLightData(getOppositeDirection(getDirectionFromIndex(i)), (unsigned char*)(message + 5));
|
|
zB->setLightData(getOppositeDirection(getDirectionFromIndex(i)), (unsigned char*)(message + 5));
|
|
|
|
+ if (zB->isVisible() != visible)
|
|
|
|
+ {
|
|
|
|
+ Chunk* c = currentGame->zChunk(currentGame->getChunkCenter(pos.x, pos.y));
|
|
|
|
+ c->vcs.lock();
|
|
|
|
+ if (zB->isVisible())
|
|
|
|
+ c->visibleBlocks.add(zB);
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ for (Framework::Iterator<Block*> iterator = c->visibleBlocks.begin(); iterator; iterator++)
|
|
|
|
+ {
|
|
|
|
+ if (zB == (Block*)iterator)
|
|
|
|
+ {
|
|
|
|
+ iterator.remove();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ c->vcs.unlock();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -101,33 +144,46 @@ void Chunk::setBlock(Block* block)
|
|
{
|
|
{
|
|
if (pos == iterator->getLocation())
|
|
if (pos == iterator->getLocation())
|
|
{
|
|
{
|
|
|
|
+ vcs.lock();
|
|
|
|
+ for (Framework::Iterator<Block*> vi = visibleBlocks.begin(); vi; vi++)
|
|
|
|
+ {
|
|
|
|
+ if ((Block*)iterator == (Block*)vi)
|
|
|
|
+ {
|
|
|
|
+ iterator.remove();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ vcs.unlock();
|
|
iterator->release();
|
|
iterator->release();
|
|
iterator.set(block);
|
|
iterator.set(block);
|
|
- cs.unlock();
|
|
|
|
- return;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
blocks.add(block);
|
|
blocks.add(block);
|
|
cs.unlock();
|
|
cs.unlock();
|
|
- if (!isLoading)
|
|
|
|
- updateVisibility();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void Chunk::removeBlock(Block* zBlock)
|
|
void Chunk::removeBlock(Block* zBlock)
|
|
{
|
|
{
|
|
cs.lock();
|
|
cs.lock();
|
|
- int index = 0;
|
|
|
|
- for (Framework::Iterator<Block*> iterator = blocks.begin(); iterator; iterator++, index++)
|
|
|
|
|
|
+ for (Framework::Iterator<Block*> iterator = blocks.begin(); iterator; iterator++)
|
|
{
|
|
{
|
|
if (zBlock == (Block*)iterator)
|
|
if (zBlock == (Block*)iterator)
|
|
{
|
|
{
|
|
- blocks.remove(index);
|
|
|
|
- cs.unlock();
|
|
|
|
- if (!isLoading)
|
|
|
|
- updateVisibility();
|
|
|
|
- return;
|
|
|
|
|
|
+ iterator.remove();
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ vcs.lock();
|
|
|
|
+ for (Framework::Iterator<Block*> iterator = visibleBlocks.begin(); iterator; iterator++)
|
|
|
|
+ {
|
|
|
|
+ if (zBlock == (Block*)iterator)
|
|
|
|
+ {
|
|
|
|
+ iterator.remove();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ vcs.unlock();
|
|
cs.unlock();
|
|
cs.unlock();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -165,7 +221,12 @@ void Chunk::load(Framework::StreamReader* zReader)
|
|
pos.y += this->location.y - CHUNK_SIZE / 2;
|
|
pos.y += this->location.y - CHUNK_SIZE / 2;
|
|
Block* zB = zBlockAt(pos);
|
|
Block* zB = zBlockAt(pos);
|
|
if (zB)
|
|
if (zB)
|
|
|
|
+ {
|
|
|
|
+ bool visible = zB->isVisible();
|
|
zB->setLightData(getOppositeDirection(getDirectionFromIndex(i)), (unsigned char*)lightData);
|
|
zB->setLightData(getOppositeDirection(getDirectionFromIndex(i)), (unsigned char*)lightData);
|
|
|
|
+ if (zB->isVisible() && !visible)
|
|
|
|
+ visibleBlocks.add(zB);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -173,14 +234,23 @@ void Chunk::load(Framework::StreamReader* zReader)
|
|
pos.y += this->location.y - CHUNK_SIZE / 2;
|
|
pos.y += this->location.y - CHUNK_SIZE / 2;
|
|
Block* zB = currentGame->zBlockAt(pos);
|
|
Block* zB = currentGame->zBlockAt(pos);
|
|
if (zB)
|
|
if (zB)
|
|
|
|
+ {
|
|
|
|
+ bool visible = zB->isVisible();
|
|
zB->setLightData(getOppositeDirection(getDirectionFromIndex(i)), (unsigned char*)lightData);
|
|
zB->setLightData(getOppositeDirection(getDirectionFromIndex(i)), (unsigned char*)lightData);
|
|
|
|
+ if (zB->isVisible() && !visible)
|
|
|
|
+ {
|
|
|
|
+ Chunk* c = currentGame->zChunk(currentGame->getChunkCenter(pos.x, pos.y));
|
|
|
|
+ c->vcs.lock();
|
|
|
|
+ c->visibleBlocks.add(zB);
|
|
|
|
+ c->vcs.unlock();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
zReader->lese((char*)&index, 4);
|
|
zReader->lese((char*)&index, 4);
|
|
}
|
|
}
|
|
isLoading = 0;
|
|
isLoading = 0;
|
|
- updateVisibility();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
Framework::Punkt Chunk::getCenter() const
|
|
Framework::Punkt Chunk::getCenter() const
|
|
@@ -200,23 +270,8 @@ Framework::Vec3<int> Chunk::getMax() const
|
|
|
|
|
|
void Chunk::forAll(std::function<void(Model3D*)> f)
|
|
void Chunk::forAll(std::function<void(Model3D*)> f)
|
|
{
|
|
{
|
|
- cs.lock();
|
|
|
|
- for (Block* b : blocks)
|
|
|
|
|
|
+ vcs.lock();
|
|
|
|
+ for (Block* b : visibleBlocks)
|
|
f(b);
|
|
f(b);
|
|
- cs.unlock();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void Chunk::updateVisibility()
|
|
|
|
-{
|
|
|
|
- cs.lock();
|
|
|
|
- for (Block* b : blocks)
|
|
|
|
- {
|
|
|
|
- Framework::Vec3<int> pos = Framework::Vec3<int>((int)floor(b->getPos().x), (int)floor(b->getPos().y), (int)floor(b->getPos().z));
|
|
|
|
- for (int i = 0; i < 6; i++)
|
|
|
|
- {
|
|
|
|
- Block* c = zBlockAt(pos + getDirection(getDirectionFromIndex(i)));
|
|
|
|
- b->setSideVisible(getDirectionFromIndex(i), !c || c->isTransparent());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- cs.unlock();
|
|
|
|
|
|
+ vcs.unlock();
|
|
}
|
|
}
|