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 <cmd_line/parser.h>
10#include <context/context.hpp>
12#include <hpp/span.hpp>
13
14#include <dotnetpp/dotnetpp.h>
15
16namespace unravel
17{
18
20{
21 static void set_needs_recompile(const std::string& protocol, bool now = false);
22 static auto get_script_debug_mode() -> bool;
23 static void set_script_debug_mode(bool debug);
24 static auto get_lib_name(const std::string& protocol) -> std::string;
25 static auto get_lib_data_key(const std::string& protocol) -> std::string;
26 static auto get_lib_temp_compiled_key(const std::string& protocol) -> std::string;
27 static auto get_lib_compiled_key(const std::string& protocol) -> std::string;
28 static void copy_compiled_lib(const fs::path& from, const fs::path& to);
29 static auto is_debugger_attached() -> bool;
30 static void log_exception(const dotnet::exception& e,
31 const hpp::source_location& loc = hpp::source_location::current());
32 static auto find_dotnet_paths(const rtti::context& ctx) -> dotnet::compiler_paths;
33
35
36 auto init(rtti::context& ctx, const cmd_line::parser& parser) -> bool;
37 auto deinit(rtti::context& ctx) -> bool;
38
39 void set_debug_config(const std::string& address, uint32_t port, uint32_t loglevel);
40
41 auto load_engine_domain(rtti::context& ctx, bool recompile) -> bool;
43
44 auto load_app_domain(rtti::context& ctx, bool recompile) -> bool;
45 void unload_app_domain();
46
47 auto get_all_scriptable_components() const -> const std::vector<dotnet::type>&;
48 auto get_scriptable_component_base_type() const -> dotnet::type;
49 auto get_engine_assembly() const -> dotnet::assembly;
50 auto get_app_assembly() const -> dotnet::assembly;
51
55 {
56 dotnet::type update_manager_type;
57 dotnet::type script_system_type;
58 dotnet::type component_type;
61
62 // SystemManager frame hooks
63 dotnet::method update_method;
64 dotnet::method fixed_update_method;
65 dotnet::method late_update_method;
66
67 // Component / ScriptComponent lifecycle (resolved once per engine domain)
68 dotnet::method set_entity_method;
69 dotnet::method on_create_method;
70 dotnet::method on_enable_method;
71 dotnet::method on_disable_method;
72 dotnet::method on_start_method;
73 dotnet::method on_destroy_method;
74 dotnet::method on_sensor_enter_method;
75 dotnet::method on_sensor_exit_method;
78
79 // UIEventManager
81 };
82
83 auto get_cache() const -> const engine_script_cache&
84 {
85 return cache_;
86 }
87
88 auto get_type_by_fullname(const std::string& fullname) const -> dotnet::type;
89 auto get_type(const std::string& name_space, const std::string& name) const -> dotnet::type;
90
91 auto is_create_called() const -> bool;
92 auto is_update_called() const -> bool;
93 void wait_for_jobs_to_finish(rtti::context& ctx);
94 auto has_compilation_errors() const -> bool;
95
96 void on_sensor_enter(entt::handle sensor, entt::handle other, const std::vector<manifold_point>& manifolds);
97 void on_sensor_exit(entt::handle sensor, entt::handle other, const std::vector<manifold_point>& manifolds);
98
99 void on_collision_enter(entt::handle a, entt::handle b, const std::vector<manifold_point>& manifolds);
100 void on_collision_exit(entt::handle a, entt::handle b, const std::vector<manifold_point>& manifolds);
101
107 static void on_create_component(entt::registry& r, entt::entity e);
108 static void on_create_active_component(entt::registry& r, entt::entity e);
109
115 static void on_load_component(entt::registry& r, entt::entity e);
116
122 static void on_destroy_component(entt::registry& r, entt::entity e);
123 static void on_destroy_active_component(entt::registry& r, entt::entity e);
124
125
130 void on_play_begin(rtti::context& ctx);
131 void on_play_begin(hpp::span<const entt::handle> entities);
132 void on_play_begin(entt::registry& entities);
133
134private:
140 void on_frame_update(rtti::context& ctx, delta_t dt);
141 void on_frame_fixed_update(rtti::context& ctx, delta_t dt);
142 void on_frame_late_update(rtti::context& ctx, delta_t dt);
143
148 void on_play_end(rtti::context& ctx);
149
154 void on_pause(rtti::context& ctx);
155
160 void on_resume(rtti::context& ctx);
161
166 void on_skip_next_frame(rtti::context& ctx);
167
168 auto bind_internal_calls(rtti::context& ctx) -> bool;
169
170 void check_for_recompile(rtti::context& ctx, delta_t dt, bool emit_callback);
171
172 auto create_compilation_job(rtti::context& ctx, const std::string& protocol, bool debug) -> tpp::job_future<bool>;
173
175 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
176
177 delta_t time_since_last_check_{};
178
179 dotnet::debugging_config debug_config_;
180 std::unique_ptr<dotnet::domain> domain_;
181
182 engine_script_cache cache_;
183
184 std::unique_ptr<dotnet::domain> app_domain_;
185
186 struct app_script_cache
187 {
188 std::vector<dotnet::type> scriptable_component_types;
189
190 } app_cache_;
191
192 enum class call_progress
193 {
194 not_called,
195 started,
197 };
198
199 call_progress create_call_{call_progress::not_called};
200 bool is_updating_{};
201 std::vector<tpp::future<void>> compilation_jobs_;
202
203 bool has_compilation_errors_{};
204
205 delta_t elapsed_time_{};
206};
207} // namespace unravel
entt::handle b
entt::handle a
std::chrono::duration< float > delta_t
std::string name
Definition hub.cpp:33
@ finished
The action has finished.
Hash specialization for batch_key to enable use in std::unordered_map.
entt::handle entity
static auto is_debugger_attached() -> bool
static auto get_lib_name(const std::string &protocol) -> std::string
auto get_scriptable_component_base_type() const -> dotnet::type
static void on_load_component(entt::registry &r, entt::entity e)
Called when a script component is loaded.
auto is_create_called() const -> bool
auto get_type(const std::string &name_space, const std::string &name) const -> dotnet::type
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 find_dotnet_paths(const rtti::context &ctx) -> dotnet::compiler_paths
script_system(rtti::context &ctx, cmd_line::parser &parser)
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 has_compilation_errors() const -> bool
void on_collision_enter(entt::handle a, entt::handle b, const std::vector< manifold_point > &manifolds)
auto get_app_assembly() const -> dotnet::assembly
auto get_cache() const -> const engine_script_cache &
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
auto get_all_scriptable_components() const -> const std::vector< dotnet::type > &
static void on_create_active_component(entt::registry &r, entt::entity e)
auto get_type_by_fullname(const std::string &fullname) const -> dotnet::type
static void log_exception(const dotnet::exception &e, const hpp::source_location &loc=hpp::source_location::current())
void on_play_begin(rtti::context &ctx)
Called when playback begins.
auto deinit(rtti::context &ctx) -> bool
auto get_engine_assembly() const -> dotnet::assembly
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)
void on_sensor_enter(entt::handle sensor, entt::handle other, const std::vector< manifold_point > &manifolds)
void on_sensor_exit(entt::handle sensor, entt::handle other, const std::vector< manifold_point > &manifolds)
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when a physics component is destroyed.
auto init(rtti::context &ctx, const cmd_line::parser &parser) -> bool
gfx::uniform_handle handle
Definition uniform.cpp:9