Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
GroupOpacityLookup.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#pragma once
4
5#include "Registry.hpp"
8
9#include <algorithm>
10
11namespace esengine::ecs {
12
20public:
21 explicit GroupOpacityLookup(Registry& registry) : registry_(registry) {
22 auto groups = registry.view<GroupOpacity>();
23 active_ = groups.begin() != groups.end();
24 }
25
26 bool active() const { return active_; }
27
29 f32 of(Entity entity) const {
30 if (!active_) return 1.0f;
31 f32 opacity = 1.0f;
32 for (Entity current = entity; current != INVALID_ENTITY;) {
33 if (const auto* group = registry_.tryGet<GroupOpacity>(current); group && group->enabled) {
34 opacity *= std::clamp(group->opacity, 0.0f, 1.0f);
35 }
36 const auto* parent = registry_.tryGet<Parent>(current);
37 current = parent ? parent->entity : INVALID_ENTITY;
38 }
39 return opacity;
40 }
41
42private:
43 Registry& registry_;
44 bool active_ = false;
45};
46
47} // namespace esengine::ecs
Hierarchy components for parent-child relationships.
Central ECS registry for entity and component management.
f32 of(Entity entity) const
1 when no enabled group encloses entity (itself included).
Central container for all entities and components.
Definition Registry.hpp:73
View< Components... > view()
Creates a view for iterating entities with specific components.
Definition Registry.hpp:761
constexpr Entity INVALID_ENTITY
Invalid entity sentinel value.
Definition Types.hpp:174
float f32
32-bit floating point
Definition Types.hpp:59
Entity identifier with packed index + generation.
Definition Types.hpp:135
Fades an entity and everything under it, the way UINode.opacity fades a UI subtree.
Parent reference component.
Definition Hierarchy.hpp:46
Entity entity
Parent entity ID.
Definition Hierarchy.hpp:49