diff options
Diffstat (limited to 'src/renderer.cpp')
-rw-r--r-- | src/renderer.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/renderer.cpp b/src/renderer.cpp index 0feee50..5580073 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -2,6 +2,7 @@ | |||
2 | #include "simulation.h" | 2 | #include "simulation.h" |
3 | #include "consts.h" | 3 | #include "consts.h" |
4 | #include "level.h" | 4 | #include "level.h" |
5 | #include "views.h" | ||
5 | 6 | ||
6 | Renderer::Renderer() | 7 | Renderer::Renderer() |
7 | { | 8 | { |
@@ -76,19 +77,28 @@ void Renderer::render(const Simulation& sim) | |||
76 | } | 77 | } |
77 | } | 78 | } |
78 | 79 | ||
79 | for (const Entity& entity : sim.getActive() | sim.entityView()) | 80 | constexpr Layer renderOrder[] = { Layer::track, Layer::object }; |
80 | { | ||
81 | SDL_SetRenderDrawColor(ren_.get(), entity.colorVal, entity.colorVal, 65, 255); | ||
82 | 81 | ||
83 | SDL_Rect rect { | 82 | ranges::for_each( |
84 | static_cast<int>(entity.pos.x()), | 83 | ranges::view::for_each( |
85 | static_cast<int>(entity.pos.y()), | 84 | renderOrder, |
86 | static_cast<int>(entity.size.w()), | 85 | [&] (Layer layer) { |
87 | static_cast<int>(entity.size.h()) | 86 | return sim.getActive() | |
88 | }; | 87 | sim.entityView() | |
88 | views::isOnLayer(layer); | ||
89 | }), | ||
90 | [&] (const Entity& entity) { | ||
91 | SDL_SetRenderDrawColor(ren_.get(), entity.colorVal, entity.colorVal, 65, 255); | ||
89 | 92 | ||
90 | SDL_RenderFillRect(ren_.get(), &rect); | 93 | SDL_Rect rect { |
91 | } | 94 | static_cast<int>(entity.pos.x()), |
95 | static_cast<int>(entity.pos.y()), | ||
96 | static_cast<int>(entity.size.w()), | ||
97 | static_cast<int>(entity.size.h()) | ||
98 | }; | ||
99 | |||
100 | SDL_RenderFillRect(ren_.get(), &rect); | ||
101 | }); | ||
92 | 102 | ||
93 | //SDL_RenderCopy(ren_.get(), canvas.get(), nullptr, nullptr); | 103 | //SDL_RenderCopy(ren_.get(), canvas.get(), nullptr, nullptr); |
94 | SDL_RenderPresent(ren_.get()); | 104 | SDL_RenderPresent(ren_.get()); |