summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2019-02-23 15:37:53 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2019-02-23 15:37:53 -0500
commit4c73347244a51bdd3f25e751afe641664e56ca3f (patch)
tree471cd6445db94258c484d988a23b3013e2ba04fd /src
parent3504fd5080dbcfd0172299c5c6d13895e53ad163 (diff)
downloaddispatcher-4c73347244a51bdd3f25e751afe641664e56ca3f.tar.gz
dispatcher-4c73347244a51bdd3f25e751afe641664e56ca3f.tar.bz2
dispatcher-4c73347244a51bdd3f25e751afe641664e56ca3f.zip
Entities to be rendered are sorted by render layer
Partially just for fun.
Diffstat (limited to 'src')
-rw-r--r--src/renderer.cpp32
-rw-r--r--src/simulation.cpp77
2 files changed, 58 insertions, 51 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
6Renderer::Renderer() 7Renderer::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());
diff --git a/src/simulation.cpp b/src/simulation.cpp index 27ac6ab..98687b6 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp
@@ -8,7 +8,44 @@ Simulation::Simulation(
8 const Level& level) : 8 const Level& level) :
9 level_(level) 9 level_(level)
10{ 10{
11 id_type trainId = emplaceEntity();
12 Entity& train = getEntity(trainId);
13 train.size = TILE_SIZE;
14 train.speed = schedule_.getBPS() * 2.0;
15 train.colliderType = ColliderType::train;
16 train.scheduled = true;
17 train.colorVal = 90;
18 train.gridPos = vec2s { 6, 1 };
19 train.moveDir = Direction::left;
11 20
21 id_type playerId = emplaceEntity();
22 Entity& player = getEntity(playerId);
23 player.size = TILE_SIZE;
24 player.speed = 3.0;
25 player.controllable = true;
26 player.colliderType = ColliderType::player;
27 player.colorVal = 180;
28 player.gridPos = vec2s { 1, 5 };
29
30 id_type crateId = emplaceEntity();
31 Entity& crate = getEntity(crateId);
32 crate.size = TILE_SIZE;
33 crate.speed = schedule_.getBPS() * 2.0;
34 crate.colliderType = ColliderType::crate;
35 crate.canBePushedBy.insert(ColliderType::player);
36 crate.canBePushedBy.insert(ColliderType::crate);
37 crate.canBePushedBy.insert(ColliderType::train);
38 crate.gridPos = vec2s { 4, 5 };
39
40 id_type crateId2 = emplaceEntity();
41 Entity& crate2 = getEntity(crateId2);
42 crate2.size = TILE_SIZE;
43 crate2.speed = schedule_.getBPS() * 2.0;
44 crate2.colliderType = ColliderType::crate;
45 crate2.canBePushedBy.insert(ColliderType::player);
46 crate2.canBePushedBy.insert(ColliderType::crate);
47 crate2.canBePushedBy.insert(ColliderType::train);
48 crate2.gridPos = vec2s { 6, 7 };
12 49
13 id_type trackId = emplaceEntity(); 50 id_type trackId = emplaceEntity();
14 Entity& track = getEntity(trackId); 51 Entity& track = getEntity(trackId);
@@ -49,46 +86,6 @@ Simulation::Simulation(
49 track4.trackDir2 = Direction::down; 86 track4.trackDir2 = Direction::down;
50 track4.colorVal = 130; 87 track4.colorVal = 130;
51 track4.gridPos = vec2s { 7, 1 }; 88 track4.gridPos = vec2s { 7, 1 };
52
53
54 id_type trainId = emplaceEntity();
55 Entity& train = getEntity(trainId);
56 train.size = TILE_SIZE;
57 train.speed = schedule_.getBPS() * 2.0;
58 train.colliderType = ColliderType::train;
59 train.scheduled = true;
60 train.colorVal = 90;
61 train.gridPos = vec2s { 6, 1 };
62 train.moveDir = Direction::left;
63
64 id_type playerId = emplaceEntity();
65 Entity& player = getEntity(playerId);
66 player.size = TILE_SIZE;
67 player.speed = 3.0;
68 player.controllable = true;
69 player.colliderType = ColliderType::player;
70 player.colorVal = 180;
71 player.gridPos = vec2s { 1, 5 };
72
73 id_type crateId = emplaceEntity();
74 Entity& crate = getEntity(crateId);
75 crate.size = TILE_SIZE;
76 crate.speed = schedule_.getBPS() * 2.0;
77 crate.colliderType = ColliderType::crate;
78 crate.canBePushedBy.insert(ColliderType::player);
79 crate.canBePushedBy.insert(ColliderType::crate);
80 crate.canBePushedBy.insert(ColliderType::train);
81 crate.gridPos = vec2s { 4, 5 };
82
83 id_type crateId2 = emplaceEntity();
84 Entity& crate2 = getEntity(crateId2);
85 crate2.size = TILE_SIZE;
86 crate2.speed = schedule_.getBPS() * 2.0;
87 crate2.colliderType = ColliderType::crate;
88 crate2.canBePushedBy.insert(ColliderType::player);
89 crate2.canBePushedBy.insert(ColliderType::crate);
90 crate2.canBePushedBy.insert(ColliderType::train);
91 crate2.gridPos = vec2s { 6, 7 };
92} 89}
93 90
94void Simulation::tick( 91void Simulation::tick(