Merge pull request #819 from MihailRis/new-generator-parameters

add new generator parameters
This commit is contained in:
MihailRis 2026-03-19 21:03:29 +03:00 • committed by GitHub
commit 4adf3e2456
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 39 additions and 9 deletions

View file

@ -54,6 +54,9 @@ The main properties described in the configuration file:
- **heights-bpd** - number of blocks per point of the height map. Default: 4. - **heights-bpd** - number of blocks per point of the height map. Default: 4.
- **wide-structs-chunks-radius** - maximum radius for placing 'wide' structures, measured in chunks. - **wide-structs-chunks-radius** - maximum radius for placing 'wide' structures, measured in chunks.
- **heightmap-inputs** - an array of parameter map numbers that will be passed by the inputs table to the height map generation function. - **heightmap-inputs** - an array of parameter map numbers that will be passed by the inputs table to the height map generation function.
- **player-spawn-radius** - radius of the player spawn zone.
- **player-min-spawn-height**, **player-max-spawn-height** - specifying the **preferred** vertical spawn zone.
Specifying a minimum height allows you to minimize the chance of spawning in underground voids, just as specifying a maximum allows you to minimize the chance of spawning on suspiciously dense cloud.
## Global variables ## Global variables

View file

@ -54,6 +54,9 @@
- **heights-bpd** - количество блоков на точку карты высот. По-умолчанию: 4. - **heights-bpd** - количество блоков на точку карты высот. По-умолчанию: 4.
- **wide-structs-chunks-radius** - масимальный радиус размещения 'широких' структур, измеряемый в чанках. - **wide-structs-chunks-radius** - масимальный радиус размещения 'широких' структур, измеряемый в чанках.
- **heightmap-inputs** - массив номеров карт параметров, которые будут переданы таблицей inputs в функцию генерации карты высот. - **heightmap-inputs** - массив номеров карт параметров, которые будут переданы таблицей inputs в функцию генерации карты высот.
- **player-spawn-radius** - радиус зоны спавна игроков.
- **player-min-spawn-height**, **player-max-spawn-height** - указание **предпочтительной** вертикальной зоны спавна.
Указание минимальной высоты позволяет минимизировать шанс спавна в подземных пустотах, как и указание максимальной - шанс спавна на подозрительно плотном облаке.
## Глобальные переменные ## Глобальные переменные

View file

@ -46,6 +46,9 @@ inline constexpr float CHUNKS_MAP_MAX_LOAD_FACTOR = 0.1f;
/// @brief chunk volume (count of voxels per Chunk) /// @brief chunk volume (count of voxels per Chunk)
inline constexpr int CHUNK_VOL = (CHUNK_W * CHUNK_H * CHUNK_D); inline constexpr int CHUNK_VOL = (CHUNK_W * CHUNK_H * CHUNK_D);
/// @brief default player spawn radius (see GeneratorDef::playerSpawnRadius)
inline constexpr float DEFAULT_PLAYER_SPAWN_RADIUS = 100.0f;
/// @brief block id used to mark non-existing voxel (voxel of missing chunk) /// @brief block id used to mark non-existing voxel (voxel of missing chunk)
inline constexpr blockid_t BLOCK_VOID = std::numeric_limits<blockid_t>::max(); inline constexpr blockid_t BLOCK_VOID = std::numeric_limits<blockid_t>::max();
/// @brief item id used to mark non-existing item (error) /// @brief item id used to mark non-existing item (error)

View file

@ -6,6 +6,7 @@
#include "../ContentPack.hpp" #include "../ContentPack.hpp"
#include "io/io.hpp" #include "io/io.hpp"
#include "data/dv_util.hpp"
#include "engine/EnginePaths.hpp" #include "engine/EnginePaths.hpp"
#include "logic/scripting/scripting.hpp" #include "logic/scripting/scripting.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"
@ -217,6 +218,9 @@ void ContentLoader::loadGenerator(
map.at("sea-level").get(def.seaLevel); map.at("sea-level").get(def.seaLevel);
map.at("wide-structs-chunks-radius").get(def.wideStructsChunksRadius); map.at("wide-structs-chunks-radius").get(def.wideStructsChunksRadius);
map.at("player-spawn-radius").get(def.playerSpawnRadius);
map.at("player-min-spawn-height").get(def.playerMinSpawnHeight);
map.at("player-max-spawn-height").get(def.playerMaxSpawnHeight);
if (map.has("heightmap-inputs")) { if (map.has("heightmap-inputs")) {
for (const auto& element : map["heightmap-inputs"]) { for (const auto& element : map["heightmap-inputs"]) {
int index = element.asInteger(); int index = element.asInteger();

View file

@ -16,6 +16,8 @@
#include "voxels/Chunks.hpp" #include "voxels/Chunks.hpp"
#include "window/Camera.hpp" #include "window/Camera.hpp"
#include "world/Level.hpp" #include "world/Level.hpp"
#include "world/World.hpp"
#include "world/generator/GeneratorDef.hpp"
#include "data/dv_util.hpp" #include "data/dv_util.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
@ -50,6 +52,7 @@ Player::Player(
fpCamera->setFov(glm::radians(90.0f)); fpCamera->setFov(glm::radians(90.0f));
spCamera->setFov(glm::radians(90.0f)); spCamera->setFov(glm::radians(90.0f));
tpCamera->setFov(glm::radians(90.0f)); tpCamera->setFov(glm::radians(90.0f));
random.setSeed((id << 8) ^ 34076213);
} }
Player::~Player() = default; Player::~Player() = default;
@ -106,7 +109,7 @@ void Player::postUpdate() {
flight = false; flight = false;
} }
for (int i = 0; i < SPAWN_ATTEMPTS_PER_UPDATE && std::isnan(spawnpoint.x); i++) { for (int i = 0; i < SPAWN_ATTEMPTS_PER_UPDATE && std::isnan(spawnpoint.x); i++) {
attemptToFindSpawnpoint(); attemptToChooseSpawnpoint();
} }
} }
@ -120,12 +123,19 @@ void Player::teleport(glm::vec3 position) {
} }
} }
void Player::attemptToFindSpawnpoint() { void Player::attemptToChooseSpawnpoint() {
glm::vec3 newpos( // looks bad to be here tbh
position.x + (rand() % 200 - 100), const auto& generatorDef =
rand() % 80 + 100, level.content.generators.require(level.getWorld()->getGenerator());
position.z + (rand() % 200 - 100)
); int minHeight = generatorDef.playerMinSpawnHeight;
int maxHeight = generatorDef.playerMaxSpawnHeight;
glm::vec3 newpos {0.0f, random.randFloat() * (maxHeight - minHeight + 1) + minHeight, 0.0f};
double angle = random.randDouble() * glm::two_pi<double>();
double radius = glm::sqrt(random.randDouble());
newpos.x += glm::cos(angle) * generatorDef.playerSpawnRadius * radius;
newpos.z += glm::sin(angle) * generatorDef.playerSpawnRadius * radius;
while (newpos.y > 0 && while (newpos.y > 0 &&
!chunks->isObstacleBlock(newpos.x, newpos.y - 2, newpos.z)) { !chunks->isObstacleBlock(newpos.x, newpos.y - 2, newpos.z)) {
newpos.y--; newpos.y--;

View file

@ -7,6 +7,7 @@
#include "settings.hpp" #include "settings.hpp"
#include "voxels/voxel.hpp" #include "voxels/voxel.hpp"
#include "util/Interpolation.hpp" #include "util/Interpolation.hpp"
#include "maths/util.hpp"
class Chunks; class Chunks;
class Camera; class Camera;
@ -63,6 +64,9 @@ class Player : public Serializable {
entityid_t selectedEid = 0; entityid_t selectedEid = 0;
glm::vec3 rotation {}; glm::vec3 rotation {};
util::PseudoRandom random;
void attemptToChooseSpawnpoint();
public: public:
util::VecInterpolation<3, float, true> rotationInterpolation {true}; util::VecInterpolation<3, float, true> rotationInterpolation {true};
@ -88,8 +92,6 @@ public:
void updateSelectedEntity(); void updateSelectedEntity();
void postUpdate(); void postUpdate();
void attemptToFindSpawnpoint();
void setChosenSlot(int index); void setChosenSlot(int index);
int getChosenSlot() const; int getChosenSlot() const;

View file

@ -7,6 +7,7 @@
#include <unordered_map> #include <unordered_map>
#include "typedefs.hpp" #include "typedefs.hpp"
#include "constants.hpp"
#include "maths/Heightmap.hpp" #include "maths/Heightmap.hpp"
#include "StructurePlacement.hpp" #include "StructurePlacement.hpp"
@ -212,6 +213,10 @@ struct GeneratorDef {
/// @brief Heightmap blocks per dot /// @brief Heightmap blocks per dot
uint heightsBPD = 4; uint heightsBPD = 4;
float playerSpawnRadius = DEFAULT_PLAYER_SPAWN_RADIUS;
int playerMinSpawnHeight = CHUNK_H / 4;
int playerMaxSpawnHeight = CHUNK_H;
/// @brief Biome parameter maps interpolation method /// @brief Biome parameter maps interpolation method
InterpolationType biomesInterpolation = InterpolationType::LINEAR; InterpolationType biomesInterpolation = InterpolationType::LINEAR;