diff options
author | Matthew Kosarek <matthew@matthewkosarek.xyz> | 2023-09-27 16:52:17 -0400 |
---|---|---|
committer | Matthew Kosarek <matthew@matthewkosarek.xyz> | 2023-09-27 16:52:17 -0400 |
commit | 9262b5c798e1921c759addb492b592f3ccf64980 (patch) | |
tree | 47c22d423f49678c8e50b365350777cc05ed17ac /themes/src | |
parent | 1da356d8a64c45c99871aca156ee9fdd3e10ec15 (diff) |
Moving renderer construction out to the individual themes instead of main.cpp
Diffstat (limited to 'themes/src')
-rw-r--r-- | themes/src/autumn/AutumnTheme.cpp | 31 | ||||
-rw-r--r-- | themes/src/autumn/AutumnTheme.hpp | 8 | ||||
-rw-r--r-- | themes/src/main.cpp | 16 | ||||
-rw-r--r-- | themes/src/summer/SummerTheme.cpp | 20 | ||||
-rw-r--r-- | themes/src/summer/SummerTheme.h | 6 | ||||
-rw-r--r-- | themes/src/winter/WinterTheme.cpp | 16 | ||||
-rw-r--r-- | themes/src/winter/WinterTheme.hpp | 9 |
7 files changed, 49 insertions, 57 deletions
diff --git a/themes/src/autumn/AutumnTheme.cpp b/themes/src/autumn/AutumnTheme.cpp index c6431a1..4b7a2e2 100644 --- a/themes/src/autumn/AutumnTheme.cpp +++ b/themes/src/autumn/AutumnTheme.cpp @@ -1,5 +1,4 @@ #include "AutumnTheme.hpp" -#include "../Renderer2d.h" #include "../shapes_2d.h" #include <memory> @@ -8,10 +7,10 @@ namespace const int NUM_HILLS = 3; } -AutumnTheme::AutumnTheme(Renderer2d* renderer) - : renderer{renderer} +AutumnTheme::AutumnTheme(WebglContext* context) { - load(renderer); + renderer.load(context); + load(); } AutumnTheme::~AutumnTheme() @@ -19,21 +18,21 @@ AutumnTheme::~AutumnTheme() unload(); } -void AutumnTheme::load(Renderer2d* renderer) { - renderer->clearColor = Vector4(252, 210, 153, 255).toNormalizedColor(); - auto lr = tree.load(renderer); - leafParticles.load(renderer, &lr); +void AutumnTheme::load() { + renderer.clearColor = Vector4(252, 210, 153, 255).toNormalizedColor(); + auto lr = tree.load(&renderer); + leafParticles.load(&renderer, &lr); background = new RectangularGradient( - *renderer, + renderer, Vector4{135, 206, 235, 255}.toNormalizedColor(), Vector4(252, 210, 153, 255).toNormalizedColor(), - renderer->get_width(), - renderer->get_height(), + renderer.get_width(), + renderer.get_height(), {0, 0}); background_hill = new Circleish( - *renderer, + renderer, 1000, Vector4(137, 129, 33, 255).toNormalizedColor(), 100, @@ -42,7 +41,7 @@ void AutumnTheme::load(Renderer2d* renderer) { background_hill->mesh.model = background_hill->mesh.model.translateByVec2({1200, -700}); tree_hill = new Circleish( - *renderer, + renderer, 500, Vector4{ 76, 75, 22, 255 }.toNormalizedColor(), 100, @@ -57,12 +56,12 @@ void AutumnTheme::update(f32 dtSeconds) { } void AutumnTheme::render() { - renderer->render(); + renderer.render(); background->render(); background_hill->render(); - tree.render(renderer); + tree.render(&renderer); tree_hill->render(); - leafParticles.render(renderer); + leafParticles.render(&renderer); } void AutumnTheme::unload() { diff --git a/themes/src/autumn/AutumnTheme.hpp b/themes/src/autumn/AutumnTheme.hpp index 41df04c..e3f5748 100644 --- a/themes/src/autumn/AutumnTheme.hpp +++ b/themes/src/autumn/AutumnTheme.hpp @@ -5,16 +5,16 @@ #include "LeafParticleRender.h" #include "../types.h" #include "../theme.h" +#include "../Renderer2d.h" #include <memory> #include <vector> -struct Renderer2d; class RectangularGradient; class Circleish; class AutumnTheme : public Theme { public: - AutumnTheme(Renderer2d* renderer); + AutumnTheme(WebglContext*); ~AutumnTheme(); TreeShape tree; LeafParticleRender leafParticles; @@ -22,12 +22,12 @@ public: Circleish* tree_hill; Circleish* background_hill; - void load(Renderer2d* renderer); + void load(); void update(f32 dtSeconds); void render(); void unload(); private: - Renderer2d* renderer; + Renderer2d renderer; }; #endif diff --git a/themes/src/main.cpp b/themes/src/main.cpp index 384174b..14227c9 100644 --- a/themes/src/main.cpp +++ b/themes/src/main.cpp @@ -11,7 +11,7 @@ #include <cstdio> #include <emscripten/fetch.h> -void load(Theme theme); +void load(ThemeType theme); void unload(); void update(f32 dtSeconds, void* userData); EM_BOOL selectNone(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); @@ -21,14 +21,9 @@ EM_BOOL selectSpring(int eventType, const EmscriptenMouseEvent* mouseEvent, void EM_BOOL selectSummer(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); WebglContext context; -Renderer2d renderer2d; MainLoop mainLoop; ThemeType type; Theme* active_theme; -AutumnTheme* autumnTheme; -WinterTheme* winterTheme; -SpringTheme* springTheme; -SummerTheme* summerTheme; int main() { context.init("#theme_canvas"); @@ -55,18 +50,16 @@ void load(ThemeType theme) { switch (type) { case ThemeType::Autumn: - renderer2d.load(&context); - active_theme = new AutumnTheme(&renderer2d); + active_theme = new AutumnTheme(&context); break; case ThemeType::Winter: - renderer2d.load(&context); - active_theme = new WinterTheme(&renderer2d); + active_theme = new WinterTheme(&context); break; case ThemeType::Spring: active_theme = new SpringTheme(&context); break; case ThemeType::Summer: - active_theme = new SummerTheme(&renderer2d, &context); + active_theme = new SummerTheme(&context); break; default: break; @@ -84,7 +77,6 @@ void unload() { type = ThemeType::Default; if (mainLoop.isRunning) { mainLoop.stop(); - renderer2d.unload(); } } diff --git a/themes/src/summer/SummerTheme.cpp b/themes/src/summer/SummerTheme.cpp index 522b44c..1f76b56 100644 --- a/themes/src/summer/SummerTheme.cpp +++ b/themes/src/summer/SummerTheme.cpp @@ -6,10 +6,10 @@ #include "../shaders/sun_vert.h" #include <vector> -SummerTheme::SummerTheme(Renderer2d* renderer, WebglContext* context) - : renderer{renderer} +SummerTheme::SummerTheme(WebglContext* context) { - load(renderer, context); + renderer.load(context); + load(context); } SummerTheme::~SummerTheme() @@ -17,12 +17,12 @@ SummerTheme::~SummerTheme() unload(); } -void SummerTheme::load(Renderer2d* renderer, WebglContext* context) { - renderer->load(context, shader_sun_vert, shader_sun_frag); - renderer->clearColor = Vector4(0, 181, 286, 255.f).toNormalizedColor(); +void SummerTheme::load(WebglContext* context) { + renderer.load(context, shader_sun_vert, shader_sun_frag); + renderer.clearColor = Vector4(0, 181, 286, 255.f).toNormalizedColor(); sun.sectors = 180; - sun.radius = renderer->context->width / 4.f; - sun.load(renderer); + sun.radius = renderer.context->width / 4.f; + sun.load(&renderer); } void SummerTheme::update(f32 dtSeconds) { @@ -30,8 +30,8 @@ void SummerTheme::update(f32 dtSeconds) { } void SummerTheme::render() { - renderer->render(); - sun.render(renderer); + renderer.render(); + sun.render(&renderer); } void SummerTheme::unload() { diff --git a/themes/src/summer/SummerTheme.h b/themes/src/summer/SummerTheme.h index 030f20a..2ce6b7f 100644 --- a/themes/src/summer/SummerTheme.h +++ b/themes/src/summer/SummerTheme.h @@ -17,13 +17,13 @@ struct Sun { class SummerTheme : public Theme { public: - SummerTheme(Renderer2d*, WebglContext*); + SummerTheme(WebglContext*); ~SummerTheme(); Sun sun; - void load(Renderer2d*, WebglContext*); + void load(WebglContext*); void update(f32 dtSeconds); void render(); void unload(); private: - Renderer2d* renderer; + Renderer2d renderer; }; diff --git a/themes/src/winter/WinterTheme.cpp b/themes/src/winter/WinterTheme.cpp index 69e7e69..052670e 100644 --- a/themes/src/winter/WinterTheme.cpp +++ b/themes/src/winter/WinterTheme.cpp @@ -1,10 +1,10 @@ #include "WinterTheme.hpp" #include "../Renderer2d.h" -WinterTheme::WinterTheme(Renderer2d* renderer) - : renderer{renderer} +WinterTheme::WinterTheme(WebglContext* context) { - load(renderer); + renderer.load(context); + load(); } WinterTheme::~WinterTheme() @@ -12,10 +12,10 @@ WinterTheme::~WinterTheme() unload(); } -void WinterTheme::load(Renderer2d* renderer) { - renderer->clearColor = Vector4(200, 229, 239, 255).toNormalizedColor(); +void WinterTheme::load() { + renderer.clearColor = Vector4(200, 229, 239, 255).toNormalizedColor(); SnowflakeLoadParameters lp; - spr.load(lp, renderer); + spr.load(lp, &renderer); } void WinterTheme::update(f32 dtSeconds) { @@ -23,8 +23,8 @@ void WinterTheme::update(f32 dtSeconds) { } void WinterTheme::render() { - renderer->render(); - spr.render(renderer); + renderer.render(); + spr.render(&renderer); } void WinterTheme::unload() { diff --git a/themes/src/winter/WinterTheme.hpp b/themes/src/winter/WinterTheme.hpp index 7e5f2ef..5ba6d94 100644 --- a/themes/src/winter/WinterTheme.hpp +++ b/themes/src/winter/WinterTheme.hpp @@ -4,21 +4,22 @@ #include "Snowflake.h" #include "../types.h" #include "../theme.h" +#include "../Renderer2d.h" -struct Renderer2d; +struct WebglContext; struct WinterTheme : public Theme { public: - WinterTheme(Renderer2d* renderer); + WinterTheme(WebglContext*); ~WinterTheme(); SnowflakeParticleRenderer spr; - void load(Renderer2d* renderer); + void load(); void update(f32 dtSeconds); void render(); void unload(); private: - Renderer2d* renderer; + Renderer2d renderer; }; #endif |