|
@@ -1,86 +1,21 @@
|
|
|
#include "Chunk.h"
|
|
#include "Chunk.h"
|
|
|
|
|
|
|
|
-#include <Shader.h>
|
|
|
|
|
-
|
|
|
|
|
-#include "ChunkFluidModel.h"
|
|
|
|
|
-#include "ChunkGroundModel.h"
|
|
|
|
|
#include "Constants.h"
|
|
#include "Constants.h"
|
|
|
-#include "CustomDX12API.h"
|
|
|
|
|
-#include "FactoryCraftModel.h"
|
|
|
|
|
|
|
+#include "DX12ChunkData.h"
|
|
|
#include "Globals.h"
|
|
#include "Globals.h"
|
|
|
-#include "TransparentChunkGroundModel.h"
|
|
|
|
|
|
|
|
|
|
Chunk::Chunk(Framework::Point location)
|
|
Chunk::Chunk(Framework::Point location)
|
|
|
: ReferenceCounter(),
|
|
: ReferenceCounter(),
|
|
|
location(location),
|
|
location(location),
|
|
|
isLoading(0),
|
|
isLoading(0),
|
|
|
lightChanged(0),
|
|
lightChanged(0),
|
|
|
- modelChanged(0),
|
|
|
|
|
bLock(),
|
|
bLock(),
|
|
|
vLock(),
|
|
vLock(),
|
|
|
- aLock()
|
|
|
|
|
|
|
+ aLock(),
|
|
|
|
|
+ dx12Data(new DX12ChunkData(location))
|
|
|
{
|
|
{
|
|
|
blocks = new Block*[CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT];
|
|
blocks = new Block*[CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT];
|
|
|
memset(blocks, 0, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT * sizeof(Block*));
|
|
memset(blocks, 0, CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT * sizeof(Block*));
|
|
|
- // FactoryCraftModel* ground = new FactoryCraftModel();
|
|
|
|
|
- // Model3DData* chunkModel
|
|
|
|
|
- // = uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(
|
|
|
|
|
- // Text("chunk_ground_") + location.x + location.y);
|
|
|
|
|
- // if (!chunkModel)
|
|
|
|
|
- // {
|
|
|
|
|
- // chunkModel
|
|
|
|
|
- // = uiFactory.initParam.bildschirm->zGraphicsApi()->createModel(
|
|
|
|
|
- // Text("chunk_ground_") + location.x + location.y);
|
|
|
|
|
- // }
|
|
|
|
|
- // chunkModel->setAmbientFactor(0.f);
|
|
|
|
|
- // chunkModel->setDiffusFactor(1.f);
|
|
|
|
|
- // chunkModel->setSpecularFactor(0.f);
|
|
|
|
|
- // chunkModel->setVertecies(0, 0);
|
|
|
|
|
- // ground->setModelData(chunkModel);
|
|
|
|
|
- // ground->setPosition(
|
|
|
|
|
- // (float)location.x, (float)location.y, (float)WORLD_HEIGHT / 2.f);
|
|
|
|
|
- // ground->tick(0);
|
|
|
|
|
- // ChunkModelBuilder* groundModel = new ChunkGroundModel(ground, this);
|
|
|
|
|
- // modelBuilders.add(groundModel);
|
|
|
|
|
- // FactoryCraftModel* transparentGround = new FactoryCraftModel();
|
|
|
|
|
- // chunkModel = uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(
|
|
|
|
|
- // Text("transparent_chunk_ground_") + location.x + location.y);
|
|
|
|
|
- // if (!chunkModel)
|
|
|
|
|
- //{
|
|
|
|
|
- // chunkModel
|
|
|
|
|
- // = uiFactory.initParam.bildschirm->zGraphicsApi()->createModel(
|
|
|
|
|
- // Text("transparent_chunk_ground_") + location.x + location.y);
|
|
|
|
|
- //}
|
|
|
|
|
- // chunkModel->setAmbientFactor(0.f);
|
|
|
|
|
- // chunkModel->setDiffusFactor(1.f);
|
|
|
|
|
- // chunkModel->setSpecularFactor(0.f);
|
|
|
|
|
- // chunkModel->setVertecies(0, 0);
|
|
|
|
|
- // transparentGround->setModelData(chunkModel);
|
|
|
|
|
- // transparentGround->setPosition(
|
|
|
|
|
- // (float)location.x, (float)location.y, (float)WORLD_HEIGHT / 2.f);
|
|
|
|
|
- // transparentGround->tick(0);
|
|
|
|
|
- // ChunkModelBuilder* transparentGroundModel
|
|
|
|
|
- // = new TransparentChunkGroundModel(transparentGround, this);
|
|
|
|
|
- // modelBuilders.add(transparentGroundModel);
|
|
|
|
|
- // FactoryCraftModel* fluids = new FactoryCraftModel();
|
|
|
|
|
- // chunkModel = uiFactory.initParam.bildschirm->zGraphicsApi()->getModel(
|
|
|
|
|
- // Text("chunk_fluids_") + location.x + location.y);
|
|
|
|
|
- // if (!chunkModel)
|
|
|
|
|
- //{
|
|
|
|
|
- // chunkModel
|
|
|
|
|
- // = uiFactory.initParam.bildschirm->zGraphicsApi()->createModel(
|
|
|
|
|
- // Text("chunk_fluids_") + location.x + location.y);
|
|
|
|
|
- //}
|
|
|
|
|
- // chunkModel->setAmbientFactor(0.f);
|
|
|
|
|
- // chunkModel->setDiffusFactor(1.f);
|
|
|
|
|
- // chunkModel->setSpecularFactor(0.f);
|
|
|
|
|
- // chunkModel->setVertecies(0, 0);
|
|
|
|
|
- // fluids->setModelData(chunkModel);
|
|
|
|
|
- // fluids->setPosition(
|
|
|
|
|
- // (float)location.x, (float)location.y, (float)WORLD_HEIGHT / 2.f);
|
|
|
|
|
- // fluids->tick(0);
|
|
|
|
|
- // ChunkModelBuilder* fluidModel = new ChunkFluidModel(fluids, this);
|
|
|
|
|
- // modelBuilders.add(fluidModel);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Chunk::Chunk(Framework::Point location, Framework::StreamReader* zReader)
|
|
Chunk::Chunk(Framework::Point location, Framework::StreamReader* zReader)
|
|
@@ -111,6 +46,7 @@ Chunk::~Chunk()
|
|
|
}
|
|
}
|
|
|
delete[] blocks;
|
|
delete[] blocks;
|
|
|
bLock.unlockWrite();
|
|
bLock.unlockWrite();
|
|
|
|
|
+ dx12Data->release();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Chunk::appendAnimation(
|
|
void Chunk::appendAnimation(
|
|
@@ -197,12 +133,13 @@ void Chunk::load(Framework::StreamReader* zReader)
|
|
|
bLock.unlockWrite();
|
|
bLock.unlockWrite();
|
|
|
if (b->isVisible())
|
|
if (b->isVisible())
|
|
|
{
|
|
{
|
|
|
- if (!blockTypes[id]->getModelInfo().getModelName().isEqual(
|
|
|
|
|
- "cube")
|
|
|
|
|
- && !blockTypes[id]->getModelInfo().getModelName().isEqual(
|
|
|
|
|
- "grass"))
|
|
|
|
|
|
|
+ if (blockTypes[id]->getModelInfo().getModelName().isEqual(
|
|
|
|
|
+ "cube"))
|
|
|
|
|
+ {
|
|
|
|
|
+ dx12Data->setBlock(index, b);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
{
|
|
{
|
|
|
- b->tick(0);
|
|
|
|
|
vLock.lockWrite();
|
|
vLock.lockWrite();
|
|
|
visibleBlocks.add(b);
|
|
visibleBlocks.add(b);
|
|
|
vLock.unlockWrite();
|
|
vLock.unlockWrite();
|
|
@@ -350,25 +287,8 @@ void Chunk::load(Framework::StreamReader* zReader)
|
|
|
isLoading = 0;
|
|
isLoading = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// void Chunk::buildModel(ChunkModelBuilder* builder)
|
|
|
|
|
-//{
|
|
|
|
|
-// modelChanged &= ~builder->getType();
|
|
|
|
|
-// lightChanged &= ~builder->getType();
|
|
|
|
|
-// builder->buildModel();
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// void Chunk::updateLight(ChunkModelBuilder* builder)
|
|
|
|
|
-//{
|
|
|
|
|
-// lightChanged &= ~builder->getType();
|
|
|
|
|
-// builder->updateLightning();
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
void Chunk::forAll(std::function<void(Model3D*)> f)
|
|
void Chunk::forAll(std::function<void(Model3D*)> f)
|
|
|
{
|
|
{
|
|
|
- // for (ChunkModelBuilder* builder : modelBuilders)
|
|
|
|
|
- //{
|
|
|
|
|
- // f(builder->zModel());
|
|
|
|
|
- // }
|
|
|
|
|
vLock.lockRead();
|
|
vLock.lockRead();
|
|
|
for (Block* b : visibleBlocks)
|
|
for (Block* b : visibleBlocks)
|
|
|
{
|
|
{
|
|
@@ -379,21 +299,7 @@ void Chunk::forAll(std::function<void(Model3D*)> f)
|
|
|
|
|
|
|
|
bool Chunk::tick(std::function<void(Model3D*)> f, double time)
|
|
bool Chunk::tick(std::function<void(Model3D*)> f, double time)
|
|
|
{
|
|
{
|
|
|
- // for (ChunkModelBuilder* builder : modelBuilders)
|
|
|
|
|
- //{
|
|
|
|
|
- // if ((modelChanged | builder->getType()) == modelChanged)
|
|
|
|
|
- // buildModel(builder);
|
|
|
|
|
- // }
|
|
|
|
|
- // for (ChunkModelBuilder* builder : modelBuilders)
|
|
|
|
|
- //{
|
|
|
|
|
- // if ((lightChanged | builder->getType()) == lightChanged)
|
|
|
|
|
- // updateLight(builder);
|
|
|
|
|
- // }
|
|
|
|
|
bool res = 0;
|
|
bool res = 0;
|
|
|
- // for (ChunkModelBuilder* builder : modelBuilders)
|
|
|
|
|
- //{
|
|
|
|
|
- // res |= builder->zModel()->tick(time);
|
|
|
|
|
- // }
|
|
|
|
|
aLock.lockRead();
|
|
aLock.lockRead();
|
|
|
auto iterator = animations.begin();
|
|
auto iterator = animations.begin();
|
|
|
while (iterator)
|
|
while (iterator)
|
|
@@ -419,22 +325,16 @@ bool Chunk::tick(std::function<void(Model3D*)> f, double time)
|
|
|
++iterator;
|
|
++iterator;
|
|
|
}
|
|
}
|
|
|
aLock.unlockRead();
|
|
aLock.unlockRead();
|
|
|
|
|
+ vLock.lockRead();
|
|
|
|
|
+ for (Block* b : visibleBlocks)
|
|
|
|
|
+ {
|
|
|
|
|
+ res |= b->tick(time);
|
|
|
|
|
+ }
|
|
|
|
|
+ vLock.unlockRead();
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void Chunk::destroy()
|
|
|
|
|
-{
|
|
|
|
|
- // for (ChunkModelBuilder* builder : modelBuilders)
|
|
|
|
|
- //{
|
|
|
|
|
- // Model3DData* chunkModel = builder->zModel()->zModelData();
|
|
|
|
|
- // // remove old model
|
|
|
|
|
- // while (chunkModel->getPolygonCount() > 0)
|
|
|
|
|
- // {
|
|
|
|
|
- // chunkModel->removePolygon(0);
|
|
|
|
|
- // }
|
|
|
|
|
- // chunkModel->setVertecies(0, 0);
|
|
|
|
|
- // }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+void Chunk::destroy() {}
|
|
|
|
|
|
|
|
void Chunk::api(char* message)
|
|
void Chunk::api(char* message)
|
|
|
{
|
|
{
|
|
@@ -534,83 +434,80 @@ void Chunk::setBlock(Block* block)
|
|
|
if (pos.x < 0) pos.x += CHUNK_SIZE;
|
|
if (pos.x < 0) pos.x += CHUNK_SIZE;
|
|
|
if (pos.y < 0) pos.y += CHUNK_SIZE;
|
|
if (pos.y < 0) pos.y += CHUNK_SIZE;
|
|
|
int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
|
|
int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
|
|
|
- int affectsGround = 0;
|
|
|
|
|
- int newAffectsGround = 0;
|
|
|
|
|
bLock.lockWrite();
|
|
bLock.lockWrite();
|
|
|
- // for (ChunkModelBuilder* builder : modelBuilders)
|
|
|
|
|
- //{
|
|
|
|
|
- // if (block && builder->isPartOfModel(block))
|
|
|
|
|
- // {
|
|
|
|
|
- // newAffectsGround |= builder->getType();
|
|
|
|
|
- // }
|
|
|
|
|
- // if (blocks[index] && builder->isPartOfModel(blocks[index]))
|
|
|
|
|
- // {
|
|
|
|
|
- // affectsGround |= builder->getType();
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
if (blocks[index])
|
|
if (blocks[index])
|
|
|
{
|
|
{
|
|
|
- vLock.lockWrite();
|
|
|
|
|
- for (Framework::ArrayIterator<Block*> vi = visibleBlocks.begin(); vi;
|
|
|
|
|
- vi++)
|
|
|
|
|
|
|
+ if (!blocks[index]->zBlockType()->getModelInfo().getModelName().isEqual(
|
|
|
|
|
+ "cube"))
|
|
|
{
|
|
{
|
|
|
- if (blocks[index] == (Block*)vi)
|
|
|
|
|
|
|
+ vLock.lockWrite();
|
|
|
|
|
+ for (Framework::ArrayIterator<Block*> vi = visibleBlocks.begin();
|
|
|
|
|
+ vi;
|
|
|
|
|
+ vi++)
|
|
|
{
|
|
{
|
|
|
- vi.remove();
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (blocks[index] == (Block*)vi)
|
|
|
|
|
+ {
|
|
|
|
|
+ vi.remove();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ vLock.unlockWrite();
|
|
|
}
|
|
}
|
|
|
- vLock.unlockWrite();
|
|
|
|
|
blocks[index]->copyLightTo(block);
|
|
blocks[index]->copyLightTo(block);
|
|
|
blocks[index]->release();
|
|
blocks[index]->release();
|
|
|
- blocks[index] = block;
|
|
|
|
|
- bLock.unlockWrite();
|
|
|
|
|
- modelChanged |= affectsGround | newAffectsGround;
|
|
|
|
|
- if (block && block->isVisible() && !newAffectsGround)
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ blocks[index] = block;
|
|
|
|
|
+ bLock.unlockWrite();
|
|
|
|
|
+ if (block && block->isVisible())
|
|
|
|
|
+ {
|
|
|
|
|
+ if (block->zBlockType()->getModelInfo().getModelName().isEqual("cube"))
|
|
|
|
|
+ {
|
|
|
|
|
+ dx12Data->setBlock(index, block);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
{
|
|
{
|
|
|
- block->tick(0);
|
|
|
|
|
|
|
+ dx12Data->setBlock(index, 0);
|
|
|
vLock.lockWrite();
|
|
vLock.lockWrite();
|
|
|
visibleBlocks.add(block);
|
|
visibleBlocks.add(block);
|
|
|
vLock.unlockWrite();
|
|
vLock.unlockWrite();
|
|
|
}
|
|
}
|
|
|
- return;
|
|
|
|
|
}
|
|
}
|
|
|
- blocks[index] = block;
|
|
|
|
|
- bLock.unlockWrite();
|
|
|
|
|
- modelChanged |= affectsGround | newAffectsGround;
|
|
|
|
|
- if (block && block->isVisible() && !newAffectsGround)
|
|
|
|
|
|
|
+ else
|
|
|
{
|
|
{
|
|
|
- block->tick(0);
|
|
|
|
|
- vLock.lockWrite();
|
|
|
|
|
- visibleBlocks.add(block);
|
|
|
|
|
- vLock.unlockWrite();
|
|
|
|
|
|
|
+ dx12Data->setBlock(index, 0);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Chunk::removeBlock(Block* zBlock)
|
|
void Chunk::removeBlock(Block* zBlock)
|
|
|
{
|
|
{
|
|
|
- vLock.lockWrite();
|
|
|
|
|
- for (Framework::ArrayIterator<Block*> iterator = visibleBlocks.begin();
|
|
|
|
|
- iterator;
|
|
|
|
|
- iterator++)
|
|
|
|
|
|
|
+ if (!zBlock->zBlockType()->getModelInfo().getModelName().isEqual("cube"))
|
|
|
{
|
|
{
|
|
|
- if (zBlock == (Block*)iterator)
|
|
|
|
|
|
|
+ vLock.lockWrite();
|
|
|
|
|
+ for (Framework::ArrayIterator<Block*> iterator = visibleBlocks.begin();
|
|
|
|
|
+ iterator;
|
|
|
|
|
+ iterator++)
|
|
|
{
|
|
{
|
|
|
- iterator.remove();
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if (zBlock == (Block*)iterator)
|
|
|
|
|
+ {
|
|
|
|
|
+ iterator.remove();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ vLock.unlockWrite();
|
|
|
}
|
|
}
|
|
|
- vLock.unlockWrite();
|
|
|
|
|
Vec3<int> pos = zBlock->getLocation();
|
|
Vec3<int> pos = zBlock->getLocation();
|
|
|
pos.x = pos.x % CHUNK_SIZE;
|
|
pos.x = pos.x % CHUNK_SIZE;
|
|
|
pos.y = pos.y % CHUNK_SIZE;
|
|
pos.y = pos.y % CHUNK_SIZE;
|
|
|
if (pos.x < 0) pos.x += CHUNK_SIZE;
|
|
if (pos.x < 0) pos.x += CHUNK_SIZE;
|
|
|
if (pos.y < 0) pos.y += CHUNK_SIZE;
|
|
if (pos.y < 0) pos.y += CHUNK_SIZE;
|
|
|
int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
|
|
int index = (pos.x * CHUNK_SIZE + pos.y) * WORLD_HEIGHT + pos.z;
|
|
|
|
|
+ if (zBlock->zBlockType()->getModelInfo().getModelName().isEqual("cube"))
|
|
|
|
|
+ {
|
|
|
|
|
+ dx12Data->setBlock(index, 0);
|
|
|
|
|
+ }
|
|
|
bLock.lockWrite();
|
|
bLock.lockWrite();
|
|
|
if (blocks[index])
|
|
if (blocks[index])
|
|
|
{
|
|
{
|
|
|
- modelChanged |= blocks[index]->getPartOfModels();
|
|
|
|
|
blocks[index]->release();
|
|
blocks[index]->release();
|
|
|
blocks[index] = 0;
|
|
blocks[index] = 0;
|
|
|
}
|
|
}
|
|
@@ -659,11 +556,6 @@ Framework::Vec3<int> Chunk::getMax() const
|
|
|
location.x + CHUNK_SIZE / 2, location.y + CHUNK_SIZE / 2, WORLD_HEIGHT};
|
|
location.x + CHUNK_SIZE / 2, location.y + CHUNK_SIZE / 2, WORLD_HEIGHT};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void Chunk::setModelChanged(int type)
|
|
|
|
|
-{
|
|
|
|
|
- modelChanged |= type;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
void Chunk::setLightChanged(int type)
|
|
void Chunk::setLightChanged(int type)
|
|
|
{
|
|
{
|
|
|
lightChanged |= type;
|
|
lightChanged |= type;
|
|
@@ -673,3 +565,8 @@ Lock& Chunk::getBlockReadLock() const
|
|
|
{
|
|
{
|
|
|
return bLock.getReadLock();
|
|
return bLock.getReadLock();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+DX12ChunkData* Chunk::zDX12Data() const
|
|
|
|
|
+{
|
|
|
|
|
+ return dx12Data;
|
|
|
|
|
+}
|