|
@@ -121,7 +121,9 @@ void Chunk::load(Framework::StreamReader* zReader)
|
|
|
if (b->isVisible())
|
|
|
{
|
|
|
if (!blockTypes[id]->getModelInfo().getModelName().istGleich(
|
|
|
- "cube"))
|
|
|
+ "cube")
|
|
|
+ && !blockTypes[id]->getModelInfo().getModelName().istGleich(
|
|
|
+ "grass"))
|
|
|
{
|
|
|
b->tick(0);
|
|
|
visibleBlocks.add(b);
|
|
@@ -255,6 +257,7 @@ void Chunk::load(Framework::StreamReader* zReader)
|
|
|
void Chunk::buildGroundModel()
|
|
|
{
|
|
|
vcs.lock();
|
|
|
+ visibleBlocks.leeren();
|
|
|
lightChanged = 0;
|
|
|
Model3DData* chunkModel = groundModel->zModelData();
|
|
|
// remove old model
|
|
@@ -271,18 +274,103 @@ void Chunk::buildGroundModel()
|
|
|
int groundVertexArraySize = 10000;
|
|
|
for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
|
|
|
{
|
|
|
- if (blocks[i]
|
|
|
- && blocks[i]->zBlockType()->getModelInfo().getModelName().istGleich(
|
|
|
- "cube"))
|
|
|
+ if (blocks[i])
|
|
|
{
|
|
|
- int index = 0;
|
|
|
- for (Text* textureName :
|
|
|
- *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
|
|
|
+ if (blocks[i]
|
|
|
+ ->zBlockType()
|
|
|
+ ->getModelInfo()
|
|
|
+ .getModelName()
|
|
|
+ .istGleich("cube"))
|
|
|
+ {
|
|
|
+ blocks[i]->setPartOfGround(1);
|
|
|
+ int index = 0;
|
|
|
+ for (Text* textureName :
|
|
|
+ *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
|
|
|
+ {
|
|
|
+ Framework::Vec3<int> location(
|
|
|
+ (i / WORLD_HEIGHT) / CHUNK_SIZE,
|
|
|
+ (i / WORLD_HEIGHT) % CHUNK_SIZE,
|
|
|
+ i % WORLD_HEIGHT);
|
|
|
+ if (isPartOfGroundModel(location, index))
|
|
|
+ {
|
|
|
+ if (!groundModelBuidler.get(
|
|
|
+ *textureName, textureName->getLength()))
|
|
|
+ {
|
|
|
+ GroundModelPart* part = new GroundModelPart();
|
|
|
+ part->indexList = new int[10000];
|
|
|
+ part->indexCount = 0;
|
|
|
+ part->indexArraySize = 10000;
|
|
|
+ part->name = *textureName;
|
|
|
+ groundModelBuidler.set(
|
|
|
+ *textureName, textureName->getLength(), part);
|
|
|
+ groundPartArray.add(part);
|
|
|
+ }
|
|
|
+ GroundModelPart* part = groundModelBuidler.get(
|
|
|
+ *textureName, textureName->getLength());
|
|
|
+ const Vertex3D* vBuffer
|
|
|
+ = blocks[i]->zModelData()->zVertexBuffer();
|
|
|
+ Polygon3D* polygon
|
|
|
+ = blocks[i]->zModelData()->getPolygon(index);
|
|
|
+ if (part->indexCount + polygon->indexAnz
|
|
|
+ > part->indexArraySize)
|
|
|
+ {
|
|
|
+ int* tmp = new int[part->indexArraySize + 10000];
|
|
|
+ memcpy(tmp, part->indexList, part->indexCount * 4);
|
|
|
+ delete[] part->indexList;
|
|
|
+ part->indexList = tmp;
|
|
|
+ part->indexArraySize += 10000;
|
|
|
+ }
|
|
|
+ if (groundVertexCount + polygon->indexAnz
|
|
|
+ > groundVertexArraySize)
|
|
|
+ {
|
|
|
+ Vertex3D* tmp
|
|
|
+ = new Vertex3D[groundVertexArraySize + 10000];
|
|
|
+ memcpy(tmp,
|
|
|
+ groundVerticies,
|
|
|
+ groundVertexCount * sizeof(Vertex3D));
|
|
|
+ delete[] groundVerticies;
|
|
|
+ groundVerticies = tmp;
|
|
|
+ groundVertexArraySize += 10000;
|
|
|
+ __int64* lTmp = new __int64[groundVertexArraySize];
|
|
|
+ memcpy(lTmp,
|
|
|
+ lightBuffer,
|
|
|
+ groundVertexCount * sizeof(__int64));
|
|
|
+ delete[] lightBuffer;
|
|
|
+ lightBuffer = lTmp;
|
|
|
+ }
|
|
|
+ for (int vi = 0; vi < polygon->indexAnz; vi++)
|
|
|
+ {
|
|
|
+ lightBuffer[groundVertexCount] = calculateLight(
|
|
|
+ vBuffer[polygon->indexList[vi]].pos,
|
|
|
+ location,
|
|
|
+ getDirectionFromIndex(index));
|
|
|
+ part->indexList[part->indexCount++]
|
|
|
+ = groundVertexCount;
|
|
|
+ groundVerticies[groundVertexCount++]
|
|
|
+ = vBuffer[polygon->indexList[vi]];
|
|
|
+ groundVerticies[groundVertexCount - 1].pos
|
|
|
+ += blocks[i]->getPos()
|
|
|
+ - Vec3<float>((float)this->location.x,
|
|
|
+ (float)this->location.y,
|
|
|
+ (float)WORLD_HEIGHT / 2.f);
|
|
|
+ groundVerticies[groundVertexCount - 1].id
|
|
|
+ = groundVertexCount - 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (blocks[i]
|
|
|
+ ->zBlockType()
|
|
|
+ ->getModelInfo()
|
|
|
+ .getModelName()
|
|
|
+ .istGleich("grass"))
|
|
|
{
|
|
|
- Framework::Vec3<int> location((i / WORLD_HEIGHT) / CHUNK_SIZE,
|
|
|
- (i / WORLD_HEIGHT) % CHUNK_SIZE,
|
|
|
- i % WORLD_HEIGHT);
|
|
|
- if (isPartOfGroundModel(location, index))
|
|
|
+ blocks[i]->setPartOfGround(1);
|
|
|
+ __int64 light = blocks[i]->getMaxLight();
|
|
|
+ int index = 0;
|
|
|
+ for (Text* textureName :
|
|
|
+ *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
|
|
|
{
|
|
|
if (!groundModelBuidler.get(
|
|
|
*textureName, textureName->getLength()))
|
|
@@ -331,10 +419,7 @@ void Chunk::buildGroundModel()
|
|
|
}
|
|
|
for (int vi = 0; vi < polygon->indexAnz; vi++)
|
|
|
{
|
|
|
- lightBuffer[groundVertexCount] = calculateLight(
|
|
|
- vBuffer[polygon->indexList[vi]].pos,
|
|
|
- location,
|
|
|
- getDirectionFromIndex(index));
|
|
|
+ lightBuffer[groundVertexCount] = light;
|
|
|
part->indexList[part->indexCount++] = groundVertexCount;
|
|
|
groundVerticies[groundVertexCount++]
|
|
|
= vBuffer[polygon->indexList[vi]];
|
|
@@ -346,8 +431,13 @@ void Chunk::buildGroundModel()
|
|
|
groundVerticies[groundVertexCount - 1].id
|
|
|
= groundVertexCount - 1;
|
|
|
}
|
|
|
+ index++;
|
|
|
}
|
|
|
- index++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ blocks[i]->setPartOfGround(0);
|
|
|
+ visibleBlocks.add(blocks[i]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -378,18 +468,49 @@ void Chunk::updateGroundLight()
|
|
|
int groundVertexCount = 0;
|
|
|
for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
|
|
|
{
|
|
|
- if (blocks[i]
|
|
|
- && blocks[i]->zBlockType()->getModelInfo().getModelName().istGleich(
|
|
|
- "cube"))
|
|
|
+ if (blocks[i])
|
|
|
{
|
|
|
- int index = 0;
|
|
|
- for (Text* textureName :
|
|
|
- *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
|
|
|
+ if (blocks[i]
|
|
|
+ ->zBlockType()
|
|
|
+ ->getModelInfo()
|
|
|
+ .getModelName()
|
|
|
+ .istGleich("cube"))
|
|
|
+ {
|
|
|
+ int index = 0;
|
|
|
+ for (Text* textureName :
|
|
|
+ *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
|
|
|
+ {
|
|
|
+ Framework::Vec3<int> location(
|
|
|
+ (i / WORLD_HEIGHT) / CHUNK_SIZE,
|
|
|
+ (i / WORLD_HEIGHT) % CHUNK_SIZE,
|
|
|
+ i % WORLD_HEIGHT);
|
|
|
+ if (isPartOfGroundModel(location, index))
|
|
|
+ {
|
|
|
+ const Vertex3D* vBuffer
|
|
|
+ = blocks[i]->zModelData()->zVertexBuffer();
|
|
|
+ Polygon3D* polygon
|
|
|
+ = blocks[i]->zModelData()->getPolygon(index);
|
|
|
+ for (int vi = 0; vi < polygon->indexAnz; vi++)
|
|
|
+ {
|
|
|
+ lightBuffer[groundVertexCount++] = calculateLight(
|
|
|
+ vBuffer[polygon->indexList[vi]].pos,
|
|
|
+ location,
|
|
|
+ getDirectionFromIndex(index));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (blocks[i]
|
|
|
+ ->zBlockType()
|
|
|
+ ->getModelInfo()
|
|
|
+ .getModelName()
|
|
|
+ .istGleich("grass"))
|
|
|
{
|
|
|
- Framework::Vec3<int> location((i / WORLD_HEIGHT) / CHUNK_SIZE,
|
|
|
- (i / WORLD_HEIGHT) % CHUNK_SIZE,
|
|
|
- i % WORLD_HEIGHT);
|
|
|
- if (isPartOfGroundModel(location, index))
|
|
|
+ __int64 light = blocks[i]->getMaxLight();
|
|
|
+ int index = 0;
|
|
|
+ for (Text* textureName :
|
|
|
+ *blocks[i]->zBlockType()->getModelInfo().getTexturNames())
|
|
|
{
|
|
|
const Vertex3D* vBuffer
|
|
|
= blocks[i]->zModelData()->zVertexBuffer();
|
|
@@ -397,13 +518,9 @@ void Chunk::updateGroundLight()
|
|
|
= blocks[i]->zModelData()->getPolygon(index);
|
|
|
for (int vi = 0; vi < polygon->indexAnz; vi++)
|
|
|
{
|
|
|
- lightBuffer[groundVertexCount++] = calculateLight(
|
|
|
- vBuffer[polygon->indexList[vi]].pos,
|
|
|
- location,
|
|
|
- getDirectionFromIndex(index));
|
|
|
+ lightBuffer[groundVertexCount++] = light;
|
|
|
}
|
|
|
}
|
|
|
- index++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -509,6 +626,68 @@ bool Chunk::isPartOfGroundModel(
|
|
|
return needed;
|
|
|
}
|
|
|
|
|
|
+void Chunk::renderSolid(std::function<void(Model3D*)> f)
|
|
|
+{
|
|
|
+ vcs.lock();
|
|
|
+ CustomDX11API* api
|
|
|
+ = (CustomDX11API*)uiFactory.initParam.bildschirm->zGraphicsApi();
|
|
|
+ api->setCullBack(false);
|
|
|
+ f(groundModel);
|
|
|
+ api->setCullBack(true);
|
|
|
+ float dist = 0.f;
|
|
|
+ if (api->isInFrustrum(groundModel->getPos(),
|
|
|
+ (CHUNK_SIZE / 2.f, CHUNK_SIZE / 2.f, WORLD_HEIGHT / 2.f),
|
|
|
+ &dist))
|
|
|
+ {
|
|
|
+ for (Block* b : visibleBlocks)
|
|
|
+ {
|
|
|
+ f(b);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vcs.unlock();
|
|
|
+}
|
|
|
+
|
|
|
+void Chunk::renderTransparent(std::function<void(Model3D*)> f) {}
|
|
|
+
|
|
|
+bool Chunk::tick(std::function<void(Model3D*)> f, double time)
|
|
|
+{
|
|
|
+ acs.lock();
|
|
|
+ vcs.lock(); // TODO: enshure no dead lock occures
|
|
|
+ if (modelChanged)
|
|
|
+ {
|
|
|
+ modelChanged = 0;
|
|
|
+ buildGroundModel();
|
|
|
+ }
|
|
|
+ if (lightChanged)
|
|
|
+ {
|
|
|
+ lightChanged = 0;
|
|
|
+ updateGroundLight();
|
|
|
+ }
|
|
|
+ bool res = groundModel->tick(time);
|
|
|
+ auto iterator = animations.begin();
|
|
|
+ while (iterator)
|
|
|
+ {
|
|
|
+ if (iterator->tick(time))
|
|
|
+ {
|
|
|
+ res |= iterator->zBlock()->tick(time);
|
|
|
+ if (iterator->isFinished())
|
|
|
+ {
|
|
|
+ iterator.remove();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ iterator.remove();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ++iterator;
|
|
|
+ }
|
|
|
+ vcs.unlock();
|
|
|
+ acs.unlock();
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
void Chunk::destroy()
|
|
|
{
|
|
|
Model3DData* chunkModel = groundModel->zModelData();
|
|
@@ -592,11 +771,18 @@ void Chunk::setBlock(Block* block)
|
|
|
int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
|
|
|
bool newAffectsGround
|
|
|
= block
|
|
|
- && block->zBlockType()->getModelInfo().getModelName().istGleich("cube");
|
|
|
+ && (block->zBlockType()->getModelInfo().getModelName().istGleich("cube")
|
|
|
+ || block->zBlockType()->getModelInfo().getModelName().istGleich(
|
|
|
+ "grass"));
|
|
|
bool affectsGround
|
|
|
= blocks[index]
|
|
|
- && blocks[index]->zBlockType()->getModelInfo().getModelName().istGleich(
|
|
|
- "cube");
|
|
|
+ && (blocks[index]->zBlockType()->getModelInfo().getModelName().istGleich(
|
|
|
+ "cube")
|
|
|
+ || blocks[index]
|
|
|
+ ->zBlockType()
|
|
|
+ ->getModelInfo()
|
|
|
+ .getModelName()
|
|
|
+ .istGleich("grass"));
|
|
|
if (blocks[index])
|
|
|
{
|
|
|
vcs.lock();
|
|
@@ -667,7 +853,12 @@ void Chunk::removeBlock(Block* zBlock)
|
|
|
->zBlockType()
|
|
|
->getModelInfo()
|
|
|
.getModelName()
|
|
|
- .istGleich("cube");
|
|
|
+ .istGleich("cube")
|
|
|
+ || blocks[index]
|
|
|
+ ->zBlockType()
|
|
|
+ ->getModelInfo()
|
|
|
+ .getModelName()
|
|
|
+ .istGleich("grass");
|
|
|
blocks[index]->release();
|
|
|
blocks[index] = 0;
|
|
|
if (affectsGround) modelChanged = 1;
|
|
@@ -715,70 +906,9 @@ Framework::Vec3<int> Chunk::getMax() const
|
|
|
location.x + CHUNK_SIZE / 2, location.y + CHUNK_SIZE / 2, WORLD_HEIGHT};
|
|
|
}
|
|
|
|
|
|
-void Chunk::forAll(std::function<void(Model3D*)> f)
|
|
|
-{
|
|
|
- vcs.lock();
|
|
|
- f(groundModel);
|
|
|
- float dist = 0.f;
|
|
|
- CustomDX11API* api
|
|
|
- = (CustomDX11API*)uiFactory.initParam.bildschirm->zGraphicsApi();
|
|
|
- if (api->isInFrustrum(groundModel->getPos(),
|
|
|
- (CHUNK_SIZE / 2.f, CHUNK_SIZE / 2.f, WORLD_HEIGHT / 2.f),
|
|
|
- &dist))
|
|
|
- {
|
|
|
- api->setCullBack(false);
|
|
|
- //int index = 0;
|
|
|
- //int filter = 1 + (int)(dist / 100.f);
|
|
|
- for (Block* b : visibleBlocks)
|
|
|
- {
|
|
|
- // if (index % filter == 0)
|
|
|
- // {
|
|
|
- f(b);
|
|
|
- // }
|
|
|
- // index++;
|
|
|
- }
|
|
|
- api->setCullBack(true);
|
|
|
- }
|
|
|
- vcs.unlock();
|
|
|
-}
|
|
|
-
|
|
|
-bool Chunk::tick(std::function<void(Model3D*)> f, double time)
|
|
|
+void Chunk::setGroundChanged()
|
|
|
{
|
|
|
- acs.lock();
|
|
|
- vcs.lock(); // TODO: enshure no dead lock occures
|
|
|
- if (modelChanged)
|
|
|
- {
|
|
|
- modelChanged = 0;
|
|
|
- buildGroundModel();
|
|
|
- }
|
|
|
- if (lightChanged)
|
|
|
- {
|
|
|
- lightChanged = 0;
|
|
|
- updateGroundLight();
|
|
|
- }
|
|
|
- bool res = groundModel->tick(time);
|
|
|
- auto iterator = animations.begin();
|
|
|
- while (iterator)
|
|
|
- {
|
|
|
- if (iterator->tick(time))
|
|
|
- {
|
|
|
- res |= iterator->zBlock()->tick(time);
|
|
|
- if (iterator->isFinished())
|
|
|
- {
|
|
|
- iterator.remove();
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- iterator.remove();
|
|
|
- continue;
|
|
|
- }
|
|
|
- ++iterator;
|
|
|
- }
|
|
|
- vcs.unlock();
|
|
|
- acs.unlock();
|
|
|
- return 1;
|
|
|
+ modelChanged = 1;
|
|
|
}
|
|
|
|
|
|
void Chunk::setLightChanged()
|