Unravel Engine C++ Reference
Loading...
Searching...
No Matches
script_glue_common.h
Go to the documentation of this file.
1#pragma once
2
3#include <engine/ecs/ecs.h>
4#include <engine/engine.h>
5#include <dotnetpp/dotnetpp.h>
6#include <logging/logging.h>
7#include <hpp/type_name.hpp>
8
9namespace unravel
10{
11
12inline auto get_entity_from_id(entt::entity id) -> entt::handle
13{
14 if(id == entt::entity(0))
15 {
16 return {};
17 }
18 auto& ctx = engine::context();
19 auto& ec = ctx.get_cached<ecs>();
20 return ec.get_scene().create_handle(id);
21}
22
24{
25 dotnet::raise_exception("System", "Exception", "Entity is invalid.");
26}
27
28template<typename T>
30{
31 dotnet::raise_exception("System",
32 "Exception",
33 fmt::format("Entity does not have component of type {}.", hpp::type_name_str<T>()));
34}
35
36template<typename T>
37inline auto safe_get_component(entt::entity id) -> T*
38{
39 auto e = get_entity_from_id(id);
40 if(!e)
41 {
43 return nullptr;
44 }
45 auto* comp = e.try_get<T>();
46 if(!comp)
47 {
49 return nullptr;
50 }
51 return comp;
52}
53
54} // namespace unravel
void raise_missing_component_exception()
void raise_invalid_entity_exception()
auto get_entity_from_id(entt::entity id) -> entt::handle
auto safe_get_component(entt::entity id) -> T *
Manages the entity-component-system (ECS) operations for the ACE framework.
Definition ecs.h:12
auto get_scene() -> scene &
Gets the current scene.
Definition ecs.cpp:30
static auto context() -> rtti::context &
Definition engine.cpp:111