cooler chunk generation
This commit is contained in:
parent
fdbe207540
commit
001cbb9141
8 changed files with 44 additions and 20 deletions
BIN
res/image/sand.png
Normal file
BIN
res/image/sand.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
res/image/snow.png
Normal file
BIN
res/image/snow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5 KiB |
BIN
res/image/stone.png
Normal file
BIN
res/image/stone.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
res/image/water.png
Normal file
BIN
res/image/water.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 942 B |
|
@ -6,7 +6,7 @@ layout (location = 2) in flat int fragTex;
|
|||
|
||||
layout (location = 0) out vec4 outColor;
|
||||
|
||||
layout (binding = 1) uniform sampler2D texSampler[3];
|
||||
layout (binding = 1) uniform sampler2D texSampler[6];
|
||||
|
||||
void main() {
|
||||
outColor = texture(texSampler[fragTex], fragUv) + fragLight;
|
||||
|
|
|
@ -57,13 +57,12 @@ static std::map<uint8_t, Block> blocks{};
|
|||
static std::map<std::string, uint32_t> texturesIds{};
|
||||
static std::vector<xe::Image*> textures{};
|
||||
|
||||
void loadTexture(const std::string& filePath) {
|
||||
xe::Image* image = xe::Image::createImage(filePath, false);
|
||||
texturesIds[filePath] = static_cast<uint32_t>(textures.size());
|
||||
textures.push_back(image);
|
||||
}
|
||||
|
||||
uint32_t getTexture(const std::string& filePath) {
|
||||
if(!texturesIds.count(filePath)) {
|
||||
xe::Image* image = xe::Image::createImage(filePath, false);
|
||||
texturesIds[filePath] = static_cast<uint32_t>(textures.size());
|
||||
textures.push_back(image);
|
||||
}
|
||||
return texturesIds[filePath];
|
||||
}
|
||||
|
||||
|
@ -72,11 +71,13 @@ std::vector<xe::Image*>& Chunk::getTextures() {
|
|||
}
|
||||
|
||||
void Chunk::load() {
|
||||
loadTexture(DIRT_TEXTURE);
|
||||
loadTexture(GRASS_TEXTURE);
|
||||
loadTexture(GRASS_TOP_TEXTURE);
|
||||
blocks[DIRT] = {{getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(DIRT_TEXTURE)}};
|
||||
blocks[GRASS] = {{getTexture(GRASS_TEXTURE), getTexture(GRASS_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(DIRT_TEXTURE), getTexture(GRASS_TEXTURE), getTexture(GRASS_TEXTURE)}};
|
||||
blocks[GREEN] = {{getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE), getTexture(GRASS_TOP_TEXTURE)}};
|
||||
blocks[STONE] = {{getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE), getTexture(STONE_TEXTURE)}};
|
||||
blocks[SNOW] = {{getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE), getTexture(SNOW_TEXTURE)}};
|
||||
blocks[SAND] = {{getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE), getTexture(SAND_TEXTURE)}};
|
||||
blocks[WATER] = {{getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE), getTexture(WATER_TEXTURE)}};
|
||||
}
|
||||
|
||||
void Chunk::unload() {
|
||||
|
@ -177,14 +178,25 @@ void Chunk::generate(Chunk* c) {
|
|||
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
int height = perlin.octave2D_01((( x + c->gridX * 16) * 0.01), ((z + c->gridZ * 16) * 0.01), 4) * 20;
|
||||
for(int y = 0; y < 256; y++) {
|
||||
if(y == height){
|
||||
c->setBlock(x, y, z, GRASS);
|
||||
} else if(y < height)
|
||||
double noise = perlin.octave2D_01((( x + c->gridX * 16) * 0.01), ((z + c->gridZ * 16) * 0.01), 4);
|
||||
int height = noise * 40;
|
||||
for(int y = 0; y < std::max(height, WATER_LEVEL); y++) {
|
||||
int difference = y - WATER_LEVEL;
|
||||
if (difference < 0) {
|
||||
c->setBlock(x, y, z, WATER);
|
||||
} else if(difference < 3) {
|
||||
c->setBlock(x, y, z, SAND);
|
||||
} else if(difference < 5) {
|
||||
c->setBlock(x, y, z, DIRT);
|
||||
else
|
||||
c->setBlock(x, y, z, AIR);
|
||||
} else if(difference < 6) {
|
||||
c->setBlock(x, y, z, GRASS);
|
||||
} else if(difference < 10) {
|
||||
c->setBlock(x, y, z, GREEN);
|
||||
} else if(difference < 16) {
|
||||
c->setBlock(x, y, z, STONE);
|
||||
} else if(difference < 18) {
|
||||
c->setBlock(x, y, z, SNOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,15 +13,27 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
|
||||
#define INVALID -1
|
||||
#define AIR 0
|
||||
#define DIRT 1
|
||||
#define GRASS 2
|
||||
#define GREEN 3
|
||||
#define STONE 4
|
||||
#define SNOW 5
|
||||
#define SAND 6
|
||||
#define WATER 7
|
||||
|
||||
#define DIRT_TEXTURE "res/image/dirt.png"
|
||||
#define GRASS_TEXTURE "res/image/grass.png"
|
||||
#define GRASS_TOP_TEXTURE "res/image/grass_top.png"
|
||||
#define STONE_TEXTURE "res/image/stone.png"
|
||||
#define SNOW_TEXTURE "res/image/snow.png"
|
||||
#define SAND_TEXTURE "res/image/sand.png"
|
||||
#define WATER_TEXTURE "res/image/water.png"
|
||||
|
||||
static constexpr int WATER_LEVEL = 20;
|
||||
|
||||
namespace app {
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ void FirstApp::run() {
|
|||
|
||||
SimpleRenderer renderer{xeEngine, Chunk::getTextures()};
|
||||
|
||||
xe::Sound sound{"res/sound/when_the_world_ends.wav"};
|
||||
sound.setLooping(true);
|
||||
sound.play();
|
||||
// xe::Sound sound{"res/sound/when_the_world_ends.wav"};
|
||||
// sound.setLooping(true);
|
||||
// sound.play();
|
||||
|
||||
KeyboardMovementController cameraController{xeEngine.getInput(), viewerObject};
|
||||
|
||||
|
|
Loading…
Reference in a new issue