-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptengine.h
More file actions
91 lines (77 loc) · 2.69 KB
/
scriptengine.h
File metadata and controls
91 lines (77 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef CH_SCRIPT_ENGINE_H
#define CH_SCRIPT_ENGINE_H
#include "engine/core/base.h"
#include "scriptengine_services.h"
#include <Coral/Assembly.hpp>
#include <string>
#include <unordered_map>
namespace CHEngine
{
class Scene;
// Process-wide facade over the scripting host, type registry, and runtime scene handoff state.
// The singleton shape stays because CoreCLR and the editor/runtime layers expect one scripting service.
class ScriptEngine
{
public:
ScriptEngine();
~ScriptEngine();
static void Init();
static void Shutdown();
void InternalInit();
void InternalShutdown();
// Load (or reload) the game script DLL and refresh the type registry.
bool LoadAppAssembly(const std::string& filepath);
// Hot-reload: stops running scripts, unloads the old ALC, and loads the new DLL.
bool ReloadAssembly();
// UI-safe reload entry point with consistent guard/log behavior.
bool RequestAssemblyReload(const char* requestSource);
// Returns a pointer to the Coral::Type for the given short or full class name.
// Search is case-insensitive. Returns nullptr if not found.
Coral::Type* GetScriptClass(const std::string& name);
// All discovered script types keyed by lowercase full name.
const std::unordered_map<std::string, Coral::Type>& GetScriptClasses() const
{
return GetScriptTypeRegistry().GetScriptClasses();
}
bool IsInitialized() const
{
return GetScriptAssemblyHost().IsInitialized();
}
bool IsReloadInProgress() const
{
return m_RuntimeSession.IsReloadInProgress();
}
bool CanExecuteFrameScripts() const
{
return GetScriptAssemblyHost().IsInitialized() && !m_RuntimeSession.IsReloadInProgress();
}
Scene* GetActiveScene() const
{
return m_RuntimeSession.GetActiveScene();
}
void SetActiveScene(Scene* scene)
{
m_RuntimeSession.SetActiveScene(scene);
}
// Called from C# script glue - queue a scene to load next frame.
void RequestLoadScene(const std::string& path)
{
m_RuntimeSession.RequestLoadScene(path);
}
// Consumed by RuntimeLayer::OnUpdate each frame. Returns the path and clears it.
std::string ConsumeRequestedScene()
{
return m_RuntimeSession.ConsumeRequestedScene();
}
// Safely consumes pending scene requests for frame updates.
// Returns false if reload is in progress or there is no pending path.
bool TryConsumeRequestedScene(std::string& outPath)
{
return m_RuntimeSession.TryConsumeRequestedScene(outPath);
}
static ScriptEngine& Get();
private:
ScriptRuntimeSession m_RuntimeSession;
};
} // namespace CHEngine
#endif // CH_SCRIPT_ENGINE_H