aboutsummaryrefslogtreecommitdiffstats
path: root/src/world/map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/world/map.cpp')
-rw-r--r--src/world/map.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/world/map.cpp b/src/world/map.cpp
new file mode 100644
index 0000000..48701d8
--- /dev/null
+++ b/src/world/map.cpp
@@ -0,0 +1,91 @@
+#include "world/map.h"
+#include "world/tectonicphase.h"
+
+#include "boxii/input.h"
+
+WorldMap::WorldMap(int w, int h, int seed) :
+ m_width(w), m_height(h), m_seed(seed),
+ m_random(seed)
+{
+ m_landElevation = new float[w * h];
+ m_waterElevation = new float[w * h];
+ m_vegetation = new float[w * h];
+}
+
+WorldMap::~WorldMap()
+{
+ delete[] m_landElevation;
+ delete[] m_waterElevation;
+ delete[] m_vegetation;
+}
+
+void
+WorldMap::begin(std::shared_ptr<WorldMap> self)
+{
+ std::shared_ptr<GenerationPhase> phase1 = std::make_shared<TectonicPhase>(nullptr, self);
+}
+
+void
+WorldMap::draw(std::shared_ptr<Boxii::Window> window, int zoom)
+{
+ //TODO: Zoom
+ (void)zoom;
+
+ int cx, cy;
+ int sx, sy;
+
+ window->getCenter(cx, cy);
+ sx = cx - (m_width / 2);
+ sy = cy - (m_height / 2);
+
+ for(int y = 0; y < m_height; y++)
+ for(int x = 0; x < m_width; x++)
+ {
+ int index = x + (y * m_width);
+
+ unsigned int r = 256;
+ unsigned int g = 256;
+ unsigned int b = 256;
+ unsigned int color;
+
+ float landElevation = m_landElevation[index];
+ float waterElevation = m_waterElevation[index];
+
+ float landScale = std::clamp(landElevation / 1024.f, 0.f, 1.f);
+ float waterScale = std::clamp(waterElevation / 6.f, 0.f, 1.f);
+
+ r *= 1.f - waterScale;
+ g *= 1.f - waterScale;
+
+ r *= landScale;
+ g *= landScale;
+ b *= landScale;
+
+ color = ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF);
+ //window->plot(sx + x, sy + y, ' ', color, color);
+ window->plot(x, y, ' ', color, color);
+ }
+}
+
+void
+WorldMap::getProperties(int x, int y, float &le, float &we, float &v)
+{
+ int index = x + (y * m_width);
+ if(index >= m_width * m_height) return;
+
+ le = m_landElevation[index];
+ we = m_waterElevation[index];
+ v = m_vegetation[index];
+}
+
+void
+WorldMap::setProperties(int x, int y, float le, float we, float v)
+{
+ int index = x + (y * m_width);
+ if(index >= m_width * m_height)
+ return;
+
+ m_landElevation[index] = le;
+ m_waterElevation[index] = we;
+ m_vegetation[index] = v;
+}