Skip to content
Snippets Groups Projects
Commit be357a1a authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

clean up heighmap APIs

parent aa716b19
No related branches found
No related tags found
No related merge requests found
......@@ -65,18 +65,18 @@ static void process_camera(fggl::ecs3::World& ecs, const fggl::input::Input& inp
fggl::input::process_edgescroll( ecs, input, cam );
}
static void setupCamera(fggl::ecs3::World& world, fggl::ecs3::TypeRegistry& types) {
static void setupCamera(fggl::ecs3::World& world) {
auto prototype = world.create(false);
world.add(prototype, types.find(fggl::math::Transform::name));
world.add(prototype, types.find(fggl::gfx::Camera::name));
world.add(prototype, types.find(fggl::input::FreeCamKeys::name));
auto camTf = world.get<fggl::math::Transform>(prototype);
if ( camTf != nullptr) {
camTf->origin(glm::vec3(10.0f, 3.0f, 10.0f));
// setup camera position/transform
auto* transform = world.add<fggl::math::Transform>(prototype);
if ( transform != nullptr) {
transform->origin(glm::vec3(10.0f, 3.0f, 10.0f));
}
auto cameraKeys = world.get<fggl::input::FreeCamKeys>(prototype);
// setup camera components
world.add<fggl::gfx::Camera>(prototype);
auto* cameraKeys = world.add<fggl::input::FreeCamKeys>(prototype);
if ( cameraKeys != nullptr ) {
cameraKeys->forward = glfwGetKeyScancode(GLFW_KEY_W);
cameraKeys->backward = glfwGetKeyScancode(GLFW_KEY_S);
......@@ -87,26 +87,25 @@ static void setupCamera(fggl::ecs3::World& world, fggl::ecs3::TypeRegistry& type
}
}
static fggl::ecs3::entity_t setupTerrain(fggl::ecs3::World& world, fggl::ecs3::TypeRegistry& types) {
static fggl::ecs3::entity_t setupTerrain(fggl::ecs3::World& world) {
fggl::ecs3::entity_t terrain;
{
terrain = world.create(false);
world.add(terrain, types.find(fggl::math::Transform::name));
auto camTf = world.get<fggl::math::Transform>(terrain);
auto* camTf = world.add<fggl::math::Transform>(terrain);
camTf->origin( glm::vec3(-128.0f, 0.0f, 128.0f) );
//auto terrainData = m_world.get<fggl::data::HeightMap>(terrain);
fggl::data::HeightMap terrainData{};
terrainData.clear();
const siv::PerlinNoise::seed_type seed = 123456u;
const siv::PerlinNoise::seed_type seed = 123456U;
const siv::PerlinNoise perlin{ seed };
for (int y = 0; y < 255; ++y) {
for (int x = 0; x < 255; ++x) {
const double noise = perlin.octave2D_11( (x * 0.01), (y * 0.01) , 4) * 10.f;
terrainData.heightValues[x * 255 +y] = (float)noise;
for (int z = 0; z < fggl::data::heightMaxZ; ++z) {
for (int x = 0; x < fggl::data::heightMaxX; ++x) {
const double noise = perlin.octave2D_11( (x * 0.01), (z * 0.01) , 4) * 10.f;
terrainData.setValue(x, z, (float)noise);
}
}
world.set<fggl::data::HeightMap>(terrain, &terrainData);
......@@ -116,8 +115,8 @@ static fggl::ecs3::entity_t setupTerrain(fggl::ecs3::World& world, fggl::ecs3::T
static fggl::ecs3::entity_t setupEnvironment(fggl::ecs3::World& world) {
auto& types = world.types();
setupCamera(world, types);
return setupTerrain(world, types);
setupCamera(world);
return setupTerrain(world);
}
static fggl::ecs3::entity_t setupBunkerPrototype(fggl::ecs3::World& world) {
......
......@@ -6,6 +6,8 @@
#define FGGL_HEIGHTMAP_H
#include <cstdint>
#include <array>
#include "fggl/data/model.hpp"
namespace fggl::data {
......@@ -16,7 +18,7 @@ namespace fggl::data {
struct HeightMap {
constexpr static const char name[] = "Heightmap";
float heightValues[heightMaxX * heightMaxZ];
std::array<float, heightMaxX * heightMaxZ> heightValues;
void clear() {
for (float &heightValue : heightValues) {
......@@ -26,11 +28,11 @@ namespace fggl::data {
[[nodiscard]]
inline float getValue(std::size_t x, std::size_t z) const {
return heightValues[x * heightMaxZ + z];
return heightValues.at(x * heightMaxZ + z);
}
inline void setValue(std::size_t x, std::size_t z, float value) {
heightValues[x * heightMaxZ + z] = value;
heightValues.at(x * heightMaxZ + z) = value;
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment