Unravel Engine C++ Reference
Loading...
Searching...
No Matches
script_system.h
Go to the documentation of this file.
1#pragma once
2#include <engine/engine_export.h>
5
7
8#include <base/basetypes.hpp>
9#include <context/context.hpp>
11#include <hpp/span.hpp>
12
13#include <monopp/mono_exception.h>
14#include <monopp/mono_jit.h>
15#include <monort/monort.h>
16
17namespace unravel
18{
19
21{
22 static void set_needs_recompile(const std::string& protocol, bool now = false);
23 static auto get_script_debug_mode() -> bool;
24 static void set_script_debug_mode(bool debug);
25 static auto get_lib_name(const std::string& protocol) -> std::string;
26 static auto get_lib_data_key(const std::string& protocol) -> std::string;
27 static auto get_lib_temp_compiled_key(const std::string& protocol) -> std::string;
28 static auto get_lib_compiled_key(const std::string& protocol) -> std::string;
29 static void copy_compiled_lib(const fs::path& from, const fs::path& to);
30 static auto is_debugger_attached() -> bool;
31 static void log_exception(const mono::mono_exception& e,
32 const hpp::source_location& loc = hpp::source_location::current());
33 static auto find_mono(const rtti::context& ctx) -> mono::compiler_paths;
34
35 auto init(rtti::context& ctx) -> bool;
36 auto deinit(rtti::context& ctx) -> bool;
37
38 void set_debug_config(const std::string& address, uint32_t port, uint32_t loglevel);
39
40 auto load_engine_domain(rtti::context& ctx, bool recompile) -> bool;
42
43 auto load_app_domain(rtti::context& ctx, bool recompile) -> bool;
44 void unload_app_domain();
45
46 auto get_all_scriptable_components() const -> const std::vector<mono::mono_type>&;
47 auto get_engine_assembly() const -> mono::mono_assembly;
48 auto get_app_assembly() const -> mono::mono_assembly;
49
50 auto is_create_called() const -> bool;
51 auto is_update_called() const -> bool;
53 auto has_compilation_errors() const -> bool;
54
55 void on_sensor_enter(entt::handle sensor, entt::handle other);
56 void on_sensor_exit(entt::handle sensor, entt::handle other);
57
58 void on_collision_enter(entt::handle a, entt::handle b, const std::vector<manifold_point>& manifolds);
59 void on_collision_exit(entt::handle a, entt::handle b, const std::vector<manifold_point>& manifolds);
60
66 static void on_create_component(entt::registry& r, entt::entity e);
67 static void on_create_active_component(entt::registry& r, entt::entity e);
68
74 static void on_destroy_component(entt::registry& r, entt::entity e);
75 static void on_destroy_active_component(entt::registry& r, entt::entity e);
76
77
83 void on_play_begin(hpp::span<const entt::handle> entities);
84 void on_play_begin(entt::registry& entities);
85
86private:
92 void on_frame_update(rtti::context& ctx, delta_t dt);
93 void on_frame_fixed_update(rtti::context& ctx, delta_t dt);
94 void on_frame_late_update(rtti::context& ctx, delta_t dt);
95
100 void on_play_end(rtti::context& ctx);
101
106 void on_pause(rtti::context& ctx);
107
112 void on_resume(rtti::context& ctx);
113
118 void on_skip_next_frame(rtti::context& ctx);
119
120 auto bind_internal_calls(rtti::context& ctx) -> bool;
121
122 void check_for_recompile(rtti::context& ctx, delta_t dt, bool emit_callback);
123
124 auto create_compilation_job(rtti::context& ctx, const std::string& protocol, bool debug) -> tpp::job_future<bool>;
125
127 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
128
129 delta_t time_since_last_check_{};
130
131 mono::debugging_config debug_config_;
132 std::unique_ptr<mono::mono_domain> domain_;
133
134 struct mono_cache
135 {
136 mono::mono_type update_manager_type;
137 mono::mono_type script_system_type;
138 mono::mono_type native_component_type;
139 mono::mono_type script_component_type;
140 } cache_;
141
142 std::unique_ptr<mono::mono_domain> app_domain_;
143
144 struct mono_app_cache
145 {
146 std::vector<mono::mono_type> scriptable_component_types;
147
148 } app_cache_;
149
150 enum class call_progress
151 {
152 not_called,
153 started,
154 finished
155 };
156
157 call_progress create_call_{call_progress::not_called};
158 bool is_updating_{};
159 std::vector<tpp::future<void>> compilation_jobs_;
160
161 bool has_compilation_errors_{};
162};
163} // namespace unravel
entt::handle b
entt::handle a
std::chrono::duration< float > delta_t
static auto is_debugger_attached() -> bool
static auto get_lib_name(const std::string &protocol) -> std::string
auto is_create_called() const -> bool
static auto get_lib_data_key(const std::string &protocol) -> std::string
static auto get_script_debug_mode() -> bool
auto is_update_called() const -> bool
static auto get_lib_compiled_key(const std::string &protocol) -> std::string
static auto get_lib_temp_compiled_key(const std::string &protocol) -> std::string
static void set_script_debug_mode(bool debug)
auto load_engine_domain(rtti::context &ctx, bool recompile) -> bool
auto get_app_assembly() const -> mono::mono_assembly
auto has_compilation_errors() const -> bool
void on_collision_enter(entt::handle a, entt::handle b, const std::vector< manifold_point > &manifolds)
auto init(rtti::context &ctx) -> bool
static void on_create_component(entt::registry &r, entt::entity e)
Called when a physics component is created.
static void set_needs_recompile(const std::string &protocol, bool now=false)
void set_debug_config(const std::string &address, uint32_t port, uint32_t loglevel)
static void copy_compiled_lib(const fs::path &from, const fs::path &to)
static void on_destroy_active_component(entt::registry &r, entt::entity e)
auto load_app_domain(rtti::context &ctx, bool recompile) -> bool
static auto find_mono(const rtti::context &ctx) -> mono::compiler_paths
void on_sensor_exit(entt::handle sensor, entt::handle other)
void on_sensor_enter(entt::handle sensor, entt::handle other)
static void log_exception(const mono::mono_exception &e, const hpp::source_location &loc=hpp::source_location::current())
auto get_engine_assembly() const -> mono::mono_assembly
static void on_create_active_component(entt::registry &r, entt::entity e)
void on_play_begin(rtti::context &ctx)
Called when playback begins.
auto deinit(rtti::context &ctx) -> bool
auto get_all_scriptable_components() const -> const std::vector< mono::mono_type > &
void on_collision_exit(entt::handle a, entt::handle b, const std::vector< manifold_point > &manifolds)
void wait_for_jobs_to_finish(rtti::context &ctx)
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when a physics component is destroyed.