From 98cf9df93e7f845f376b67c8a9e4f4d4dd1aaa6c Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Wed, 29 Jul 2020 17:56:54 +0200 Subject: [PATCH] [Heightmap] Added and used in TerrainGenerator. Fixed #135. [README.md] Fixed typo. [EngineConfig] Increased pre-release version suffix. [mods/default] Fixed furnace texture. --- README.md | 2 +- external/gamekit | 2 +- mods/default/textures/gui/furnace.png | Bin 674 -> 2031 bytes source/common/core/EngineConfig.hpp | 2 +- source/common/world/Heightmap.cpp | 63 +++++++++++++++++++++++ source/common/world/Heightmap.hpp | 61 ++++++++++++++++++++++ source/server/lua/LuaMod.hpp | 2 +- source/server/world/ServerWorld.hpp | 3 +- source/server/world/TerrainGenerator.cpp | 11 +--- source/server/world/TerrainGenerator.hpp | 6 ++- texturepacks/minecraft/gui/furnace.png | Bin 1432 -> 2031 bytes 11 files changed, 137 insertions(+), 15 deletions(-) create mode 100644 source/common/world/Heightmap.cpp create mode 100644 source/common/world/Heightmap.hpp diff --git a/README.md b/README.md index 9fb3ca43..07df50e1 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/external/gamekit b/external/gamekit index f0285a38..c664d115 160000 --- a/external/gamekit +++ b/external/gamekit @@ -1 +1 @@ -Subproject commit f0285a38170f3f59963b56bbb3347a6321f7e064 +Subproject commit c664d1150ffd59f6899738e26b0cabb8af608254 diff --git a/mods/default/textures/gui/furnace.png b/mods/default/textures/gui/furnace.png index 9418bcba4704b86dfc8f3f6995ca7c0e947264c7..298c4fdc4b2d1847f4e1570c955b16b7aa46ca03 100644 GIT binary patch literal 2031 zcmds2YfzL`7=FJ+S_UZ2XoRDsbt(F`}PGC7Ujz_b|D>Ci?HVL8<*@CQ`p0oeRKmBT^&dlz9@4WB(ywCHz z-?!hE)Rcsvz>q*93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m3MVY8r)CI=j^z`xGK_a z<4%DOm6Cjik7vs!SnQm$%j<{U4E;~1o*Bz7_;4=zVQE8E>W;bzOsA9?=FfZmhQpzh z=fHK@eUqaaf_PUvX$WGL_%~PXB;!)44U-tw)#d(*4Bh^!xj>ce&Z_%u+J*{m7<3a< z*K&?w~`ZVe@QniW%*%H^^xm= z5YrvDgy?7;(*tpgF+vyM#7=x-EQWp#lIy=*;C{fGyJ;CxL0HUq?@%hO4z`n a&F{_a*L~lzFK_lokSU(7elF{r5}E-1;ucW= diff --git a/source/common/core/EngineConfig.hpp b/source/common/core/EngineConfig.hpp index 584cad7c..2d5bd555 100644 --- a/source/common/core/EngineConfig.hpp +++ b/source/common/core/EngineConfig.hpp @@ -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; diff --git a/source/common/world/Heightmap.cpp b/source/common/world/Heightmap.cpp new file mode 100644 index 00000000..c9823462 --- /dev/null +++ b/source/common/world/Heightmap.cpp @@ -0,0 +1,63 @@ +/* + * ===================================================================================== + * + * OpenMiner + * + * Copyright (C) 2018-2020 Unarelith, Quentin Bazin + * 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; +} + diff --git a/source/common/world/Heightmap.hpp b/source/common/world/Heightmap.hpp new file mode 100644 index 00000000..79dc512c --- /dev/null +++ b/source/common/world/Heightmap.hpp @@ -0,0 +1,61 @@ +/* + * ===================================================================================== + * + * OpenMiner + * + * Copyright (C) 2018-2020 Unarelith, Quentin Bazin + * 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 + +#include +#include + +#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 m_chunks; +}; + +#endif // HEIGHTMAP_HPP_ diff --git a/source/server/lua/LuaMod.hpp b/source/server/lua/LuaMod.hpp index 2de1faf4..a861e436 100644 --- a/source/server/lua/LuaMod.hpp +++ b/source/server/lua/LuaMod.hpp @@ -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_ diff --git a/source/server/world/ServerWorld.hpp b/source/server/world/ServerWorld.hpp index 4bef39e0..2fbe0c5a 100644 --- a/source/server/world/ServerWorld.hpp +++ b/source/server/world/ServerWorld.hpp @@ -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; diff --git a/source/server/world/TerrainGenerator.cpp b/source/server/world/TerrainGenerator.cpp index 852f041f..8e574bc9 100644 --- a/source/server/world/TerrainGenerator.cpp +++ b/source/server/world/TerrainGenerator.cpp @@ -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++) { diff --git a/source/server/world/TerrainGenerator.hpp b/source/server/world/TerrainGenerator.hpp index a4dfa144..6b5f2ca7 100644 --- a/source/server/world/TerrainGenerator.hpp +++ b/source/server/world/TerrainGenerator.hpp @@ -33,6 +33,7 @@ #include +#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_ diff --git a/texturepacks/minecraft/gui/furnace.png b/texturepacks/minecraft/gui/furnace.png index f40de39d67a762e7de0e190b776fa0f0a1ed8b0b..298c4fdc4b2d1847f4e1570c955b16b7aa46ca03 100644 GIT binary patch literal 2031 zcmds2YfzL`7=FJ+S_UZ2XoRDsbt(F`}PGC7Ujz_b|D>Ci?HVL8<*@CQ`p0oeRKmBT^&dlz9@4WB(ywCHz z-?!hE)Rcsvz>q*93Q9_hn@?om(jb2y{H(5Am`3D7sV}9)BP3!(oJbH!BBdk7h;d?q zm?Wljk~89*xF9ZxD_tuX2~I+gkR+6Dm5d}ODM(6^3P_|FDNag|lB5s-8_>W)Gpd!I zqYr0HFeVvOdMqN&85fL8#+7D)q~J^lCL|L|lR~ZJObR9?lL{Qs$`ofxFeRD7RImmZ zNP{J4A&0@h1~jnHth68<;|R_r=Su6tSVTf_A-PamE?6Kb1(%Xb1@$0>TCN0Fk}JrA zAE1eD*a7_@0fk@jlTCS2yfD zF*?7iWY660wzQhSi%BEyB)9x{tMg=+k@aO?an%>@t>G#4MsG#?n-zI2QMa3q&hGMY zj_tg=%8c-7FR?XW8saGKyjbXPFSc~lET3ojsySlH=9~+Ap0^Ko1{~_yFwmJ1SWGQ} ziG`k=T_dfQcg{^PT|bYg4mdaSUVTYS`J=@#6dpU&k^k25akfW(f5jPUVdP{F+xH}GuSm9h zST!ZU87|N4y0Ks%8+NC#xQOo6+zLNG%eS}TXr$TS*LuF- zz!eb4yn;-sL8lioidHsi$jOg#S z4WIj9mM%T!%Iu$g)BmY$)k7Xkn>&rOhgHwrF`uv2+3A6<%-qJ);}d*#+>HN7>G#&) z@p5cIu=4y9h4Pq8MmO%y*$E?PRyD4OX%hN0qe(~98a(9_jH>pHti?p)6QV( guyp*VFUtISeRD0gL)n!tglRXD;#1-d#M+Dg0%qTwX#fBK literal 1432 zcmcJOYfO_@7{{Ntw57bz**Z$QGGYtNNkFIOUXb1E#QU&hr*wTDm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