| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "eu/runner/entity.h" |
| 2 |
|
|
|
| 3 |
|
|
#include <algorithm> |
| 4 |
|
|
|
| 5 |
|
|
#include "dear_imgui/imgui.h" |
| 6 |
|
|
#include "eu/imgui/debug.h" |
| 7 |
|
|
#include "eu/imgui/ui.h" |
| 8 |
|
|
|
| 9 |
|
|
namespace eu::runner |
| 10 |
|
|
{ |
| 11 |
|
|
|
| 12 |
|
|
// ------------------------------------------------------------------------ |
| 13 |
|
|
// UpdateStageAndPrio |
| 14 |
|
|
|
| 15 |
|
|
// ------------------------------------------------------------------------ |
| 16 |
|
|
// SystemWithPrio |
| 17 |
|
|
|
| 18 |
|
|
// ------------------------------------------------------------------------ |
| 19 |
|
|
// UpdateHandler |
| 20 |
|
|
|
| 21 |
|
|
// ------------------------------------------------------------------------ |
| 22 |
|
|
// Entity |
| 23 |
|
|
|
| 24 |
|
✗ |
Entity::Entity(const std::string& n, std::set<Hsh>&& t) |
| 25 |
|
✗ |
: name(n) |
| 26 |
|
✗ |
, tags(std::move(t)) |
| 27 |
|
|
{ |
| 28 |
|
✗ |
} |
| 29 |
|
|
|
| 30 |
|
✗ |
void Entity::add_component(std::unique_ptr<Component> c) |
| 31 |
|
|
{ |
| 32 |
|
✗ |
components.emplace_back(std::move(c)); |
| 33 |
|
✗ |
Component* nc = components.back().get(); |
| 34 |
0/2
✗ Branch 22 → 9 not taken.
✗ Branch 22 → 23 not taken.
|
✗ |
for(auto& sys: systems) |
| 35 |
|
|
{ |
| 36 |
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 26 not taken.
|
✗ |
sys->add_component(nc); |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
0/2
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
|
✗ |
if (world) |
| 40 |
|
|
{ |
| 41 |
|
✗ |
world->on_add_component(this, nc); |
| 42 |
|
|
} |
| 43 |
|
✗ |
} |
| 44 |
|
✗ |
void Entity::add_system(std::unique_ptr<EntitySystem> system) |
| 45 |
|
|
{ |
| 46 |
|
✗ |
systems.emplace_back(std::move(system)); |
| 47 |
|
✗ |
EntitySystem* ne = systems.back().get(); |
| 48 |
|
✗ |
updates.add(ne); |
| 49 |
0/2
✗ Branch 23 → 10 not taken.
✗ Branch 23 → 24 not taken.
|
✗ |
for (auto& c: components) |
| 50 |
|
|
{ |
| 51 |
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 27 not taken.
|
✗ |
ne->add_component(c.get()); |
| 52 |
|
|
} |
| 53 |
0/2
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
|
✗ |
if (root) |
| 54 |
|
|
{ |
| 55 |
|
✗ |
ne->on_root_changed(root); |
| 56 |
|
|
} |
| 57 |
|
✗ |
} |
| 58 |
|
|
|
| 59 |
|
✗ |
bool Entity::has_tag(const Hsh& h) const |
| 60 |
|
|
{ |
| 61 |
|
✗ |
return tags.contains(h); |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
✗ |
SpatialComponent* Entity::get_root() const |
| 65 |
|
|
{ |
| 66 |
|
✗ |
return root; |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
|
✗ |
void Entity::set_root(SpatialComponent* c) |
| 70 |
|
|
{ |
| 71 |
|
✗ |
root = c; |
| 72 |
|
|
|
| 73 |
0/2
✗ Branch 17 → 4 not taken.
✗ Branch 17 → 18 not taken.
|
✗ |
for (auto& sys : systems) |
| 74 |
|
|
{ |
| 75 |
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 21 not taken.
|
✗ |
sys->on_root_changed(c); |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
|
✗ |
if (world) |
| 79 |
|
|
{ |
| 80 |
|
✗ |
world->on_root_changed(this, c); |
| 81 |
|
|
} |
| 82 |
|
✗ |
} |
| 83 |
|
|
|
| 84 |
|
✗ |
void Entity::imgui() |
| 85 |
|
|
{ |
| 86 |
0/2
✗ Branch 12 → 4 not taken.
✗ Branch 12 → 13 not taken.
|
✗ |
for (const auto& tag: tags) |
| 87 |
|
|
{ |
| 88 |
0/2
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 70 not taken.
|
✗ |
const auto f = fmt::format("{}", tag.text); |
| 89 |
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 71 not taken.
|
✗ |
ImGui::Bullet(); |
| 90 |
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 71 not taken.
|
✗ |
ImGui::TextUnformatted(f.c_str()); |
| 91 |
|
✗ |
} |
| 92 |
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 41 not taken.
|
✗ |
if (ImGui::TreeNodeEx("Components")) |
| 93 |
|
|
{ |
| 94 |
0/2
✗ Branch 39 → 17 not taken.
✗ Branch 39 → 40 not taken.
|
✗ |
for (auto& comp : components) |
| 95 |
|
|
{ |
| 96 |
0/6
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 78 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 78 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 30 not taken.
|
✗ |
if (imgui::header(comp->display())) |
| 97 |
|
|
{ |
| 98 |
0/4
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 77 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 28 not taken.
|
✗ |
if (const auto prop = imgui::PropTable::begin()) |
| 99 |
|
|
{ |
| 100 |
0/2
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 75 not taken.
|
✗ |
comp->imgui(prop); |
| 101 |
|
✗ |
} |
| 102 |
|
|
} |
| 103 |
|
|
} |
| 104 |
|
✗ |
ImGui::TreePop(); |
| 105 |
|
|
} |
| 106 |
|
|
|
| 107 |
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 69 not taken.
|
✗ |
if (ImGui::TreeNodeEx("Systems")) |
| 108 |
|
|
{ |
| 109 |
0/2
✗ Branch 67 → 45 not taken.
✗ Branch 67 → 68 not taken.
|
✗ |
for (auto& sys : systems) |
| 110 |
|
|
{ |
| 111 |
0/6
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 82 not taken.
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 82 not taken.
✗ Branch 50 → 51 not taken.
✗ Branch 50 → 58 not taken.
|
✗ |
if (imgui::header(sys->display())) |
| 112 |
|
|
{ |
| 113 |
0/4
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 81 not taken.
✗ Branch 53 → 54 not taken.
✗ Branch 53 → 56 not taken.
|
✗ |
if (const auto prop = imgui::PropTable::begin()) |
| 114 |
|
|
{ |
| 115 |
0/2
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 79 not taken.
|
✗ |
sys->imgui(prop); |
| 116 |
|
✗ |
} |
| 117 |
|
|
} |
| 118 |
|
|
} |
| 119 |
|
✗ |
ImGui::TreePop(); |
| 120 |
|
|
} |
| 121 |
|
✗ |
} |
| 122 |
|
|
|
| 123 |
|
|
// ------------------------------------------------------------------------ |
| 124 |
|
|
// Component |
| 125 |
|
✗ |
const HshSt& Component::type() |
| 126 |
|
|
{ |
| 127 |
0/6
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 10 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 10 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
|
✗ |
static const auto r = HshSt{ .data = {}, .primary = "<Component>"sv}; |
| 128 |
|
✗ |
return r; |
| 129 |
|
|
} |
| 130 |
|
|
|
| 131 |
|
✗ |
const HshSt& Component::get_type() |
| 132 |
|
|
{ |
| 133 |
|
✗ |
return type(); |
| 134 |
|
|
} |
| 135 |
|
|
|
| 136 |
|
|
// ------------------------------------------------------------------------ |
| 137 |
|
|
// SpatialComponent |
| 138 |
|
|
|
| 139 |
0/12
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 12 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 12 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 16 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 14 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 14 not taken.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
|
✗ |
EU_IMP_COMPONENT_TYPE(SpatialComponent, Component) |
| 140 |
|
|
|
| 141 |
|
✗ |
void SpatialComponent::set_transform(const m4& t) |
| 142 |
|
|
{ |
| 143 |
|
✗ |
transform = t; |
| 144 |
|
✗ |
} |
| 145 |
|
✗ |
const m4& SpatialComponent::get_transform() const |
| 146 |
|
|
{ |
| 147 |
|
✗ |
return transform; |
| 148 |
|
|
} |
| 149 |
|
|
|
| 150 |
|
✗ |
void SpatialComponent::imgui(const imgui::PropTable& prop) |
| 151 |
|
|
{ |
| 152 |
|
|
// todo(Gustav): use setter when there is a hierarchy |
| 153 |
|
✗ |
prop.transform(&transform); |
| 154 |
|
✗ |
} |
| 155 |
|
|
|
| 156 |
|
|
// ------------------------------------------------------------------------ |
| 157 |
|
|
// EntitySystem |
| 158 |
|
|
|
| 159 |
|
|
|
| 160 |
|
|
// ------------------------------------------------------------------------ |
| 161 |
|
|
// EntitySystemUpdateStageList |
| 162 |
|
|
|
| 163 |
|
|
// --------------------------------------------------- |
| 164 |
|
|
// World |
| 165 |
|
|
|
| 166 |
|
✗ |
Entity* World::add_entity(const std::string& name, std::set<Hsh>&& tags) |
| 167 |
|
|
{ |
| 168 |
0/4
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 13 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 11 not taken.
|
✗ |
entities.emplace_back(std::make_unique<Entity>(name, std::move(tags))); |
| 169 |
|
✗ |
Entity* ent = entities.back().get(); |
| 170 |
|
✗ |
ent->world = this; |
| 171 |
|
✗ |
return ent; |
| 172 |
|
|
} |
| 173 |
|
|
|
| 174 |
|
✗ |
void World::on_add_component(Entity* entity, Component* component) |
| 175 |
|
|
{ |
| 176 |
0/2
✗ Branch 17 → 4 not taken.
✗ Branch 17 → 18 not taken.
|
✗ |
for (auto& sys: systems) |
| 177 |
|
|
{ |
| 178 |
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 19 not taken.
|
✗ |
sys->add_component(entity, component); |
| 179 |
|
|
} |
| 180 |
|
✗ |
} |
| 181 |
|
|
|
| 182 |
|
✗ |
void World::on_root_changed(Entity* entity, SpatialComponent* component) |
| 183 |
|
|
{ |
| 184 |
0/2
✗ Branch 17 → 4 not taken.
✗ Branch 17 → 18 not taken.
|
✗ |
for (auto& sys : systems) |
| 185 |
|
|
{ |
| 186 |
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 19 not taken.
|
✗ |
sys->on_root_changed(entity, component); |
| 187 |
|
|
} |
| 188 |
|
✗ |
} |
| 189 |
|
|
|
| 190 |
|
✗ |
void World::add_system(std::unique_ptr<WorldSystem> system) |
| 191 |
|
|
{ |
| 192 |
|
✗ |
systems.emplace_back(std::move(system)); |
| 193 |
|
✗ |
WorldSystem* sys = systems.back().get(); |
| 194 |
|
|
|
| 195 |
|
✗ |
updates.add(sys); |
| 196 |
0/2
✗ Branch 46 → 10 not taken.
✗ Branch 46 → 47 not taken.
|
✗ |
for (auto& ent: entities) |
| 197 |
|
|
{ |
| 198 |
0/2
✗ Branch 29 → 15 not taken.
✗ Branch 29 → 30 not taken.
|
✗ |
for (auto& comp: ent->components) { |
| 199 |
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 48 not taken.
|
✗ |
sys->add_component(ent.get(), comp.get()); |
| 200 |
|
|
} |
| 201 |
0/2
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 37 not taken.
|
✗ |
if (ent->get_root()) |
| 202 |
|
|
{ |
| 203 |
0/2
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 49 not taken.
|
✗ |
sys->on_root_changed(ent.get(), ent->get_root()); |
| 204 |
|
|
} |
| 205 |
|
|
} |
| 206 |
|
✗ |
} |
| 207 |
|
|
|
| 208 |
|
✗ |
void World::update(UpdateStage stage, float dt) |
| 209 |
|
|
{ |
| 210 |
0/2
✗ Branch 17 → 4 not taken.
✗ Branch 17 → 18 not taken.
|
✗ |
for (auto& ent: entities) |
| 211 |
|
|
{ |
| 212 |
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 20 not taken.
|
✗ |
ent->updates.update(stage, dt); |
| 213 |
|
|
} |
| 214 |
|
|
|
| 215 |
|
✗ |
updates.update(stage, dt); |
| 216 |
|
✗ |
} |
| 217 |
|
|
|
| 218 |
|
✗ |
void World::gui() |
| 219 |
|
|
{ |
| 220 |
0/2
✗ Branch 25 → 4 not taken.
✗ Branch 25 → 26 not taken.
|
✗ |
for (auto& ent: entities) |
| 221 |
|
|
{ |
| 222 |
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 55 not taken.
|
✗ |
ImGui::PushID(ent.get()); |
| 223 |
0/4
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 55 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 15 not taken.
|
✗ |
if (ImGui::TreeNodeEx(ent->name.c_str())) |
| 224 |
|
|
{ |
| 225 |
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 55 not taken.
|
✗ |
ent->imgui(); |
| 226 |
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 55 not taken.
|
✗ |
ImGui::TreePop(); |
| 227 |
|
|
} |
| 228 |
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 55 not taken.
|
✗ |
ImGui::PopID(); |
| 229 |
|
|
} |
| 230 |
|
|
|
| 231 |
0/2
✗ Branch 53 → 28 not taken.
✗ Branch 53 → 54 not taken.
|
✗ |
for (auto& sys : systems) |
| 232 |
|
|
{ |
| 233 |
0/6
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 59 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 59 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 44 not taken.
|
✗ |
if (ImGui::TreeNodeEx(sys->display())) |
| 234 |
|
|
{ |
| 235 |
0/2
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 59 not taken.
|
✗ |
ImGui::PushID(sys.get()); |
| 236 |
0/4
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 58 not taken.
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 41 not taken.
|
✗ |
if (const auto prop = imgui::PropTable::begin()) |
| 237 |
|
|
{ |
| 238 |
0/2
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 56 not taken.
|
✗ |
sys->imgui(prop); |
| 239 |
|
✗ |
} |
| 240 |
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 59 not taken.
|
✗ |
ImGui::PopID(); |
| 241 |
0/2
✗ Branch 43 → 44 not taken.
✗ Branch 43 → 59 not taken.
|
✗ |
ImGui::TreePop(); |
| 242 |
|
|
} |
| 243 |
|
|
} |
| 244 |
|
✗ |
} |
| 245 |
|
|
} |
| 246 |
|
|
|