mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add 'player-spawn-radius' generator parameter
This commit is contained in:
parent
4271f537a3
commit
2600dd7ed9
5 changed files with 27 additions and 9 deletions
|
|
@ -46,6 +46,9 @@ inline constexpr float CHUNKS_MAP_MAX_LOAD_FACTOR = 0.1f;
|
|||
/// @brief chunk volume (count of voxels per Chunk)
|
||||
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)
|
||||
inline constexpr blockid_t BLOCK_VOID = std::numeric_limits<blockid_t>::max();
|
||||
/// @brief item id used to mark non-existing item (error)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "../ContentPack.hpp"
|
||||
|
||||
#include "io/io.hpp"
|
||||
#include "data/dv_util.hpp"
|
||||
#include "engine/EnginePaths.hpp"
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
|
|
@ -217,6 +218,7 @@ void ContentLoader::loadGenerator(
|
|||
|
||||
map.at("sea-level").get(def.seaLevel);
|
||||
map.at("wide-structs-chunks-radius").get(def.wideStructsChunksRadius);
|
||||
map.at("player-spawn-radius").get(def.playerSpawnRadius);
|
||||
if (map.has("heightmap-inputs")) {
|
||||
for (const auto& element : map["heightmap-inputs"]) {
|
||||
int index = element.asInteger();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
#include "voxels/Chunks.hpp"
|
||||
#include "window/Camera.hpp"
|
||||
#include "world/Level.hpp"
|
||||
#include "world/World.hpp"
|
||||
#include "world/generator/GeneratorDef.hpp"
|
||||
#include "data/dv_util.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
|
||||
|
|
@ -50,6 +52,7 @@ Player::Player(
|
|||
fpCamera->setFov(glm::radians(90.0f));
|
||||
spCamera->setFov(glm::radians(90.0f));
|
||||
tpCamera->setFov(glm::radians(90.0f));
|
||||
random.setSeed((id << 8) ^ 34076213);
|
||||
}
|
||||
|
||||
Player::~Player() = default;
|
||||
|
|
@ -106,7 +109,7 @@ void Player::postUpdate() {
|
|||
flight = false;
|
||||
}
|
||||
for (int i = 0; i < SPAWN_ATTEMPTS_PER_UPDATE && std::isnan(spawnpoint.x); i++) {
|
||||
attemptToFindSpawnpoint();
|
||||
attemptToChooseSpawnpoint();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,12 +123,17 @@ void Player::teleport(glm::vec3 position) {
|
|||
}
|
||||
}
|
||||
|
||||
void Player::attemptToFindSpawnpoint() {
|
||||
glm::vec3 newpos(
|
||||
position.x + (rand() % 200 - 100),
|
||||
rand() % 80 + 100,
|
||||
position.z + (rand() % 200 - 100)
|
||||
);
|
||||
void Player::attemptToChooseSpawnpoint() {
|
||||
// looks bad to be here tbh
|
||||
const auto& generatorDef =
|
||||
level.content.generators.require(level.getWorld()->getGenerator());
|
||||
|
||||
glm::vec3 newpos {0.0f, random.randFloat() * 100 + 100, 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 &&
|
||||
!chunks->isObstacleBlock(newpos.x, newpos.y - 2, newpos.z)) {
|
||||
newpos.y--;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "settings.hpp"
|
||||
#include "voxels/voxel.hpp"
|
||||
#include "util/Interpolation.hpp"
|
||||
#include "maths/util.hpp"
|
||||
|
||||
class Chunks;
|
||||
class Camera;
|
||||
|
|
@ -63,6 +64,9 @@ class Player : public Serializable {
|
|||
entityid_t selectedEid = 0;
|
||||
|
||||
glm::vec3 rotation {};
|
||||
util::PseudoRandom random;
|
||||
|
||||
void attemptToChooseSpawnpoint();
|
||||
public:
|
||||
util::VecInterpolation<3, float, true> rotationInterpolation {true};
|
||||
|
||||
|
|
@ -88,8 +92,6 @@ public:
|
|||
void updateSelectedEntity();
|
||||
void postUpdate();
|
||||
|
||||
void attemptToFindSpawnpoint();
|
||||
|
||||
void setChosenSlot(int index);
|
||||
|
||||
int getChosenSlot() const;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <unordered_map>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "maths/Heightmap.hpp"
|
||||
#include "StructurePlacement.hpp"
|
||||
|
||||
|
|
@ -212,6 +213,8 @@ struct GeneratorDef {
|
|||
/// @brief Heightmap blocks per dot
|
||||
uint heightsBPD = 4;
|
||||
|
||||
float playerSpawnRadius = DEFAULT_PLAYER_SPAWN_RADIUS;
|
||||
|
||||
/// @brief Biome parameter maps interpolation method
|
||||
InterpolationType biomesInterpolation = InterpolationType::LINEAR;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue