From 489fa7f930689dc9ff271138e613a8d68d88ee45 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 20 Sep 2024 20:17:32 +0100 Subject: Add basic environment object Will hold world time/date, weather, location etc --- game/environment.cpp | 18 ++++++++++++++++++ game/environment.h | 16 ++++++++++++++++ game/gamestate.cpp | 3 +++ game/gamestate.h | 2 ++ test/test-render.cpp | 8 ++++++++ ui/gameMainWindow.cpp | 8 ++++---- 6 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 game/environment.cpp create mode 100644 game/environment.h diff --git a/game/environment.cpp b/game/environment.cpp new file mode 100644 index 0000000..fd2bfd4 --- /dev/null +++ b/game/environment.cpp @@ -0,0 +1,18 @@ +#include "environment.h" +#include +#include + +Environment::Environment() : worldTime {"2024-01-01T12:00:00"_time_t} { } + +void +Environment::tick(TickDuration) +{ + worldTime += 1; +} + +void +Environment::render(const SceneRenderer & renderer, const SceneProvider & scene) const +{ + renderer.setAmbientLight({0.5F, 0.5F, 0.5F}); + renderer.setDirectionalLight({0.6F, 0.6F, 0.6F}, {-1, 1, -1}, scene); +} diff --git a/game/environment.h b/game/environment.h new file mode 100644 index 0000000..62eedb8 --- /dev/null +++ b/game/environment.h @@ -0,0 +1,16 @@ +#pragma once + +#include "worldobject.h" + +class SceneRenderer; +class SceneProvider; + +class Environment : public WorldObject { +public: + Environment(); + void tick(TickDuration elapsed) override; + void render(const SceneRenderer &, const SceneProvider &) const; + +private: + time_t worldTime; +}; diff --git a/game/gamestate.cpp b/game/gamestate.cpp index fcd4248..910e8a7 100644 --- a/game/gamestate.cpp +++ b/game/gamestate.cpp @@ -1,4 +1,5 @@ #include "gamestate.h" +#include "environment.h" #include GameState * gameState {nullptr}; @@ -7,6 +8,8 @@ GameState::GameState() { assert(!gameState); gameState = this; + + environment = world.create(); } GameState::~GameState() diff --git a/game/gamestate.h b/game/gamestate.h index f07f844..892aa69 100644 --- a/game/gamestate.h +++ b/game/gamestate.h @@ -7,6 +7,7 @@ class WorldObject; class GeoData; +class Environment; class GameState { public: @@ -17,6 +18,7 @@ public: Collection world; std::shared_ptr geoData; + std::shared_ptr environment; AssetFactory::Assets assets; }; diff --git a/test/test-render.cpp b/test/test-render.cpp index b9a809e..ea53708 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -1,3 +1,4 @@ +#include "game/environment.h" #define BOOST_TEST_MODULE test_render #include "testHelpers.h" @@ -33,6 +34,7 @@ class TestScene : public SceneProvider { std::shared_ptr plant1; RailLinks rail; std::shared_ptr gd = std::make_shared(GeoData::createFlat({0, 0}, {1000000, 1000000}, 1)); + std::shared_ptr env = std::make_shared(); Terrain terrain {gd}; Water water {gd}; @@ -68,6 +70,12 @@ public: { } + void + environment(const SceneShader &, const SceneRenderer & r) const override + { + env->render(r, *this); + } + void shadows(const ShadowMapper & shadowMapper) const override { diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index 6168504..c53300b 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -1,16 +1,17 @@ #include "gameMainWindow.h" #include "editNetwork.h" #include "gameMainSelector.h" -#include "gfx/camera_controller.h" #include "manualCameraController.h" #include "modeHelper.h" #include "toolbar.h" #include "window.h" #include #include +#include #include #include #include // IWYU pragma: keep +#include #include #include #include @@ -65,10 +66,9 @@ GameMainWindow::content(const SceneShader & shader) const } void -GameMainWindow::environment(const SceneShader & s, const SceneRenderer & r) const +GameMainWindow::environment(const SceneShader &, const SceneRenderer & r) const { - // default for now - SceneProvider::environment(s, r); + gameState->environment->render(r, *this); } void -- cgit v1.2.3