[ChunkLightmap|TerrainGenerator] Optimized chunk sending.
This commit is contained in:
parent
6f933ab34f
commit
f5c9054e81
2
.gitignore
vendored
2
.gitignore
vendored
@ -16,6 +16,8 @@ a.out
|
||||
vgcore.*
|
||||
.gdb_history
|
||||
.valgrind_suppressions
|
||||
gmon.out
|
||||
gprof.txt
|
||||
|
||||
# CMake temporary files
|
||||
CMakeFiles
|
||||
|
@ -1,12 +1,3 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# CMakeLists.txt
|
||||
#------------------------------------------------------------------------------
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(openminer)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Get source files
|
||||
#------------------------------------------------------------------------------
|
||||
@ -42,6 +33,8 @@ target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -DSOL_CHECK_ARGUMENTS
|
||||
|
||||
target_compile_features(${CMAKE_PROJECT_NAME} PRIVATE cxx_std_17)
|
||||
|
||||
# target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -pg)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Link options
|
||||
#------------------------------------------------------------------------------
|
||||
|
@ -69,7 +69,7 @@ void ClientWorld::receiveChunkData(sf::Packet &packet) {
|
||||
|
||||
packet >> block >> light;
|
||||
|
||||
chunk->setBlock(x, y, z, block & 0xffff);
|
||||
chunk->setBlockRaw(x, y, z, block & 0xffff);
|
||||
// chunk->setData(x, y, z, block >> 16);
|
||||
chunk->lightmap().setLightData(x, y, z, light);
|
||||
}
|
||||
|
@ -1,12 +1,3 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# CMakeLists.txt
|
||||
#------------------------------------------------------------------------------
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(openminer)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Get source files
|
||||
#------------------------------------------------------------------------------
|
||||
@ -26,7 +17,7 @@ add_library(${CMAKE_PROJECT_NAME}_common STATIC ${SOURCE_FILES})
|
||||
#------------------------------------------------------------------------------
|
||||
# Compiler flags
|
||||
#------------------------------------------------------------------------------
|
||||
target_compile_options(${CMAKE_PROJECT_NAME}_common PRIVATE -O3 -ffast-math)
|
||||
# target_compile_options(${CMAKE_PROJECT_NAME}_common PRIVATE -O3 -ffast-math)
|
||||
target_compile_options(${CMAKE_PROJECT_NAME}_common PRIVATE -g -Wall -Wextra -Wfatal-errors -Wno-variadic-macros)
|
||||
target_compile_options(${CMAKE_PROJECT_NAME}_common PRIVATE -DDEBUG_ENABLED)
|
||||
target_compile_options(${CMAKE_PROJECT_NAME}_common PRIVATE -DSOL_CHECK_ARGUMENTS
|
||||
|
@ -49,6 +49,8 @@ class Chunk : public gk::NonCopyable {
|
||||
void setBlock(int x, int y, int z, u16 type);
|
||||
void setData(int x, int y, int z, u16 data);
|
||||
|
||||
void setBlockRaw(int x, int y, int z, u16 block);
|
||||
|
||||
// BlockData *getBlockData(int x, int y, int z);
|
||||
|
||||
s32 x() const { return m_x; }
|
||||
|
@ -50,15 +50,15 @@ class ChunkLightmap {
|
||||
void updateTorchlight();
|
||||
void updateSunlight();
|
||||
|
||||
u8 getLightData(int x, int y, int z) const { return m_lightMap[x][y][z]; }
|
||||
u8 getSunlight(int x, int y, int z) const;
|
||||
u8 getTorchlight(int x, int y, int z) const;
|
||||
|
||||
u8 getLightData(int x, int y, int z) const;
|
||||
void setLightData(int x, int y, int z, u8 val);
|
||||
void setSunlight(int x, int y, int z, u8 val);
|
||||
|
||||
private:
|
||||
void setTorchlight(int x, int y, int z, u8 val);
|
||||
void setSunlight(int x, int y, int z, u8 val);
|
||||
|
||||
void updateSurroundingChunks(int x, int y, int z);
|
||||
|
||||
|
@ -120,6 +120,19 @@ void Chunk::setData(int x, int y, int z, u16 data) {
|
||||
m_hasChanged = true;
|
||||
}
|
||||
|
||||
void Chunk::setBlockRaw(int x, int y, int z, u16 type) {
|
||||
if(x < 0) { if(m_surroundingChunks[0]) m_surroundingChunks[0]->setBlockRaw(x + Chunk::width, y, z, type); return; }
|
||||
if(x >= Chunk::width) { if(m_surroundingChunks[1]) m_surroundingChunks[1]->setBlockRaw(x - Chunk::width, y, z, type); return; }
|
||||
if(y < 0) { if(m_surroundingChunks[4]) m_surroundingChunks[4]->setBlockRaw(x, y + Chunk::height, z, type); return; }
|
||||
if(y >= Chunk::height) { if(m_surroundingChunks[5]) m_surroundingChunks[5]->setBlockRaw(x, y - Chunk::height, z, type); return; }
|
||||
if(z < 0) { if(m_surroundingChunks[2]) m_surroundingChunks[2]->setBlockRaw(x, y, z + Chunk::depth, type); return; }
|
||||
if(z >= Chunk::depth) { if(m_surroundingChunks[3]) m_surroundingChunks[3]->setBlockRaw(x, y, z - Chunk::depth, type); return; }
|
||||
|
||||
m_data[x][y][z] = type;
|
||||
|
||||
m_hasChanged = true;
|
||||
}
|
||||
|
||||
// FIXME
|
||||
// BlockData *Chunk::getBlockData(int x, int y, int z) {
|
||||
// if(x < 0) return m_surroundingChunks[0] ? m_surroundingChunks[0]->getBlockData(x + CHUNK_WIDTH, y, z) : 0;
|
||||
|
@ -173,10 +173,6 @@ u8 ChunkLightmap::getTorchlight(int x, int y, int z) const {
|
||||
return m_lightMap[x][y][z] & 0xf;
|
||||
}
|
||||
|
||||
u8 ChunkLightmap::getLightData(int x, int y, int z) const {
|
||||
return m_lightMap[x][y][z];
|
||||
}
|
||||
|
||||
void ChunkLightmap::setLightData(int x, int y, int z, u8 val) {
|
||||
m_lightMap[x][y][z] = val;
|
||||
|
||||
|
@ -1,12 +1,3 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# CMakeLists.txt
|
||||
#------------------------------------------------------------------------------
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(openminer)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Get source files
|
||||
#------------------------------------------------------------------------------
|
||||
@ -42,6 +33,8 @@ target_compile_options(${CMAKE_PROJECT_NAME}_server PRIVATE -DSOL_CHECK_ARGUMENT
|
||||
|
||||
target_compile_features(${CMAKE_PROJECT_NAME}_server PRIVATE cxx_std_17)
|
||||
|
||||
# target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -pg)
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Link options
|
||||
#------------------------------------------------------------------------------
|
||||
|
@ -31,9 +31,9 @@ void TerrainGenerator::basicGeneration(ServerChunk &chunk) const {
|
||||
|
||||
for(u8 y = 0 ; y < CHUNK_HEIGHT ; y++) {
|
||||
if(y + chunk.y() * CHUNK_HEIGHT < h) {
|
||||
chunk.setBlock(x, y, z, 1);
|
||||
chunk.setBlockRaw(x, y, z, 1);
|
||||
} else {
|
||||
chunk.setBlock(x, y, z, 0);
|
||||
chunk.setBlockRaw(x, y, z, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,7 +52,7 @@ void TerrainGenerator::testCraftGeneration(ServerChunk &chunk) const {
|
||||
for(int y = 0 ; y < CHUNK_HEIGHT ; y++) {
|
||||
// Wood planks layer
|
||||
// if (y == 0 && chunk.y() == 0) {
|
||||
// chunk.setBlock(x, y, z, 16);
|
||||
// chunk.setBlockRaw(x, y, z, 16);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
@ -60,7 +60,7 @@ void TerrainGenerator::testCraftGeneration(ServerChunk &chunk) const {
|
||||
if(y + chunk.y() * CHUNK_HEIGHT >= h) {
|
||||
// if we are not yet up to sea level, fill with water blocks
|
||||
if(y + chunk.y() * CHUNK_HEIGHT < SEALEVEL) {
|
||||
chunk.setBlock(x, y, z, BlockType::Water);
|
||||
chunk.setBlockRaw(x, y, z, BlockType::Water);
|
||||
continue;
|
||||
// Otherwise we are in the air
|
||||
} else {
|
||||
@ -69,7 +69,8 @@ void TerrainGenerator::testCraftGeneration(ServerChunk &chunk) const {
|
||||
// Trunk
|
||||
h = (rand() & 0x3) + 3;
|
||||
for(int i = 0 ; i < h ; i++) {
|
||||
chunk.setBlock(x, y + i, z, BlockType::Wood);
|
||||
chunk.setBlockRaw(x, y + i, z, BlockType::Wood);
|
||||
|
||||
chunk.lightmap().addSunlight(x, y + i, z, 15);
|
||||
}
|
||||
|
||||
@ -78,9 +79,8 @@ void TerrainGenerator::testCraftGeneration(ServerChunk &chunk) const {
|
||||
for(int iy = -3 ; iy <= 3 ; iy++) {
|
||||
for(int iz = -3 ; iz <= 3 ; iz++) {
|
||||
if(ix * ix + iy * iy + iz * iz < 8 + (rand() & 1) && !chunk.getBlock(x + ix, y + h + iy, z + iz)) {
|
||||
chunk.setBlock(x + ix, y + h + iy, z + iz, BlockType::Leaves);
|
||||
chunk.setBlockRaw(x + ix, y + h + iy, z + iz, BlockType::Leaves);
|
||||
|
||||
// if (iy == 2)
|
||||
chunk.lightmap().addSunlight(x + ix, y + h + iy, z + iz, 15);
|
||||
}
|
||||
}
|
||||
@ -88,12 +88,10 @@ void TerrainGenerator::testCraftGeneration(ServerChunk &chunk) const {
|
||||
}
|
||||
}
|
||||
else if(chunk.getBlock(x, y - 1, z) == BlockType::Grass && (rand() & 0xff) == 0) {
|
||||
chunk.setBlock(x, y, z, BlockType::Flower);
|
||||
chunk.setBlockRaw(x, y, z, BlockType::Flower);
|
||||
chunk.lightmap().addSunlight(x, y, z, 15);
|
||||
}
|
||||
else {
|
||||
chunk.lightmap().addSunlight(x, y - 1, z, 15);
|
||||
|
||||
// FIXME: Temporary fix for air blocks light level
|
||||
chunk.lightmap().addSunlight(x, y, z, 15);
|
||||
}
|
||||
break;
|
||||
@ -105,22 +103,24 @@ void TerrainGenerator::testCraftGeneration(ServerChunk &chunk) const {
|
||||
|
||||
// Sand layer
|
||||
if(n + r * 5 < 4) {
|
||||
chunk.setBlock(x, y, z, BlockType::Sand);
|
||||
chunk.setBlockRaw(x, y, z, BlockType::Sand);
|
||||
}
|
||||
// Dirt layer, but use grass blocks for the top
|
||||
else if(n + r * 5 < 8) {
|
||||
chunk.setBlock(x, y, z, (h < SEALEVEL || y + chunk.y() * CHUNK_HEIGHT < h - 1) ? BlockType::Dirt : BlockType::Grass);
|
||||
chunk.setBlockRaw(x, y, z, (h < SEALEVEL || y + chunk.y() * CHUNK_HEIGHT < h - 1) ? BlockType::Dirt : BlockType::Grass);
|
||||
}
|
||||
// Rock layer
|
||||
else if(r < 1.25) {
|
||||
chunk.setBlock(x, y, z, BlockType::Stone);
|
||||
chunk.setBlockRaw(x, y, z, BlockType::Stone);
|
||||
// Sometimes, ores!
|
||||
} else {
|
||||
chunk.setBlock(x, y, z, BlockType::CoalOre);
|
||||
chunk.setBlockRaw(x, y, z, BlockType::CoalOre);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
chunk.lightmap().updateLights();
|
||||
}
|
||||
|
||||
float TerrainGenerator::noise2d(float x, float y, int octaves, float persistence) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user