[Heightmap] Added and used in TerrainGenerator. Fixed #135.

[README.md] Fixed typo.
[EngineConfig] Increased pre-release version suffix.
[mods/default] Fixed furnace texture.
master
Quentin Bazin 2020-07-29 17:56:54 +02:00
parent 180123c0b7
commit 98cf9df93e
11 changed files with 137 additions and 15 deletions

View File

@ -77,7 +77,7 @@ The long-term goal of this project is to provide a viable alternative to Minecra
## Project status
This list is non complete.
This list is not complete.
See also the roadmap for 1.0.0 [here](https://github.com/Unarelith/OpenMiner/wiki/Roadmap).

2
external/gamekit vendored

@ -1 +1 @@
Subproject commit f0285a38170f3f59963b56bbb3347a6321f7e064
Subproject commit c664d1150ffd59f6899738e26b0cabb8af608254

Binary file not shown.

Before

Width:  |  Height:  |  Size: 674 B

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -36,7 +36,7 @@ namespace {
constexpr unsigned char VERSION_MAJOR = 0;
constexpr unsigned char VERSION_MINOR = 0;
constexpr unsigned char VERSION_PATCH = 10;
constexpr const char *VERSION_SUFFIX = "pre5";
constexpr const char *VERSION_SUFFIX = "pre6";
constexpr float DIST_NEAR = 0.1f;
constexpr float DIST_FAR = 1000.0f;

View File

@ -0,0 +1,63 @@
/*
* =====================================================================================
*
* OpenMiner
*
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
*
* This file is part of OpenMiner.
*
* OpenMiner is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* OpenMiner is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* =====================================================================================
*/
#include "FastNoise.hpp"
#include "Heightmap.hpp"
void HeightmapChunk::generate() {
FastNoise noise;
noise.SetNoiseType(FastNoise::NoiseType::SimplexFractal);
noise.SetFrequency(1 / 256.0f);
noise.SetFractalOctaves(4);
for(int y = 0 ; y < CHUNK_DEPTH ; y++) {
for(int x = 0 ; x < CHUNK_WIDTH ; x++) {
double n = noise.GetNoise(-x - m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
m_map[y][x] = 10 + n * 20;
}
}
}
s32 HeightmapChunk::landHeightAt(s8 x, s8 y) const {
return m_map[y][x];
}
HeightmapChunk &Heightmap::getOrCreateChunk(s32 x, s32 y) {
HeightmapChunk *chunk = nullptr;
auto it = m_chunks.find({x, y});
if (it == m_chunks.end()) {
m_chunks.emplace(gk::Vector2i{x, y}, HeightmapChunk{x, y});
chunk = &m_chunks.at({x, y});
chunk->generate();
}
else
chunk = &it->second;
return *chunk;
}

View File

@ -0,0 +1,61 @@
/*
* =====================================================================================
*
* OpenMiner
*
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
*
* This file is part of OpenMiner.
*
* OpenMiner is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* OpenMiner is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* =====================================================================================
*/
#ifndef HEIGHTMAP_HPP_
#define HEIGHTMAP_HPP_
#include <unordered_map>
#include <gk/core/IntTypes.hpp>
#include <gk/core/Vector2.hpp>
#include "EngineConfig.hpp"
class HeightmapChunk {
public:
HeightmapChunk(s32 x, s32 y)
: m_x(x), m_y(y) {}
void generate();
s32 landHeightAt(s8 x, s8 y) const;
private:
s32 m_x = 0;
s32 m_y = 0;
s32 m_map[CHUNK_DEPTH][CHUNK_WIDTH];
};
class Heightmap {
public:
HeightmapChunk &getOrCreateChunk(s32 x, s32 y);
private:
std::unordered_map<gk::Vector2i, HeightmapChunk> m_chunks;
};
#endif // HEIGHTMAP_HPP_

View File

@ -97,8 +97,8 @@ class LuaMod {
LuaSkyLoader m_skyLoader{*this};
LuaBiomeLoader m_biomeLoader{*this};
LuaDimensionLoader m_dimensionLoader{*this};
LuaEntityLoader m_entityLoader{*this, m_worldController};
LuaKeyLoader m_keyLoader{*this};
LuaEntityLoader m_entityLoader{*this, m_worldController};
};
#endif // LUAMOD_HPP_

View File

@ -49,7 +49,7 @@ class ServerWorld : public World {
public:
ServerWorld(PlayerList &players, const Dimension &dimension, gk::GameClock &clock)
: m_players(players), m_dimension(dimension), m_terrainGenerator(dimension), m_clock(clock), m_scene(players) {}
: m_players(players), m_dimension(dimension), m_terrainGenerator(m_heightmap, dimension), m_clock(clock), m_scene(players) {}
void update(bool doTick);
@ -80,6 +80,7 @@ class ServerWorld : public World {
ChunkMap m_chunks;
Heightmap m_heightmap;
TerrainGenerator m_terrainGenerator;
ServerCommandHandler *m_server = nullptr;

View File

@ -38,10 +38,7 @@ void TerrainGenerator::generate(ServerChunk &chunk) const {
}
void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) const {
FastNoise noise;
noise.SetNoiseType(FastNoise::NoiseType::SimplexFractal);
noise.SetFrequency(1 / 256.0f);
noise.SetFractalOctaves(4);
HeightmapChunk &heightmap = m_heightmap.getOrCreateChunk(chunk.x(), chunk.y());
Random_t rand;
rand.seed(chunk.x() + chunk.y() * CHUNK_WIDTH + chunk.z() * CHUNK_WIDTH * CHUNK_HEIGHT + 1337);
@ -53,11 +50,7 @@ void TerrainGenerator::fastNoiseGeneration(ServerChunk &chunk) const {
const Biome &biome = Registry::getInstance().getBiome(biomeIndex);
// Land height
double n = noise.GetNoise(-x - chunk.x() * CHUNK_WIDTH, y + chunk.y() * CHUNK_DEPTH);
double h = 10 + n * 20;
// double n = noise2d((x + chunk.x() * CHUNK_WIDTH) / 256.0, (y + chunk.y() * CHUNK_DEPTH) / 256.0, 4, 0.5) * 4;
// double h = 10 + n * 2;
double h = heightmap.landHeightAt(x, y);
// Land blocks
for(int z = 0 ; z < CHUNK_HEIGHT ; z++) {

View File

@ -33,6 +33,7 @@
#include <sol/sol.hpp>
#include "Heightmap.hpp"
#include "TerrainBiomeSampler.hpp"
using Random_t = effolkronium::random_local;
@ -43,7 +44,8 @@ class ServerChunk;
class TerrainGenerator {
public:
TerrainGenerator(const Dimension &dimension) : m_biomeSampler(dimension) {}
TerrainGenerator(Heightmap &heightmap, const Dimension &dimension)
: m_biomeSampler(dimension), m_heightmap(heightmap) {}
void generate(ServerChunk &chunk) const;
@ -64,6 +66,8 @@ class TerrainGenerator {
static float noise3d_abs(double x, double y, double z, int octaves, float persistence);
TerrainBiomeSampler m_biomeSampler;
Heightmap &m_heightmap;
};
#endif // TERRAINGENERATOR_HPP_

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB