forked from Jenova-Framework/Jenova-Runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_object.cpp
More file actions
322 lines (310 loc) · 11.2 KB
/
Copy pathscript_object.cpp
File metadata and controls
322 lines (310 loc) · 11.2 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*-------------------------------------------------------------+
| |
| _________ ______ _ _____ |
| / / ____/ | / / __ \ | / / | |
| __ / / __/ / |/ / / / / | / / /| | |
| / /_/ / /___/ /| / /_/ /| |/ / ___ | |
| \____/_____/_/ |_/\____/ |___/_/ |_| |
| |
| Jenova Runtime |
| Developed by Hamid.Memar |
| |
+-------------------------------------------------------------*/
// Jenova SDK
#include "Jenova.hpp"
// Code Templates
#include "CodeTemplates.h"
// Shared Values/Objects
static std::chrono::steady_clock::time_point lastScriptReloadTime = std::chrono::steady_clock::now();
// CPPScript Object Implementation
void CPPScript::_bind_methods()
{
ClassDB::bind_method(D_METHOD("GenerateScriptIdentity"), &CPPScript::GenerateScriptIdentity);
}
bool CPPScript::_editor_can_reload_from_file()
{
// Needs Investigation
// It Seems This is for Tracking Changes to Files When They Are Open?
return true;
}
void CPPScript::_placeholder_erased(void* p_placeholder)
{
}
bool CPPScript::_can_instantiate() const
{
return true;
}
Ref<Script> CPPScript::_get_base_script() const
{
return Ref<Script>();
}
StringName CPPScript::_get_global_name()
{
if (!this->HasValidScriptIdentity()) this->GenerateScriptIdentity();
globalName = StringName("JenovaScript_" + scriptObjectIdentity);
return globalName;
}
bool CPPScript::_inherits_script(const Ref<Script>& p_script) const
{
return false;
}
StringName CPPScript::_get_instance_base_type() const
{
return StringName(jenova::GlobalSettings::JenovaScriptType);
}
void* CPPScript::_instance_create(Object* p_for_object) const
{
godot::Node* parentNode = godot::Object::cast_to<godot::Node>(p_for_object);
jenova::VerboseByID(__LINE__, "Adding C++ Script (%s) Instance to (%s)", AS_C_STRING(this->get_path()), AS_C_STRING(parentNode->get_name()));
CPPScriptInstance* instance = memnew(CPPScriptInstance(p_for_object, Ref<CPPScript>(this)));
return CPPScriptInstance::create_native_instance(instance);
}
void* CPPScript::_placeholder_instance_create(Object* p_for_object) const
{
return nullptr; // Not Supported Yet
}
bool CPPScript::_instance_has(Object* p_object) const
{
return false;
}
bool CPPScript::_has_source_code() const
{
return !source_code.is_empty();
}
String CPPScript::_get_source_code() const
{
if (!this->get_path().is_empty()) jenova::VerboseByID(__LINE__, "Get C++ Script Source (%s) [%p]", AS_C_STRING(this->get_path()), this);
return source_code;
}
void CPPScript::_set_source_code(const String& p_code)
{
if (!this->get_path().is_empty()) jenova::VerboseByID(__LINE__, "Set C++ Script Source (%s) [%p]", AS_C_STRING(this->get_path()), this);
source_code = p_code;
// Detect Tool Macro
String cleanedSource = jenova::RemoveCommentsFromSource(p_code);
this->IsTool = jenova::ContainsExactString(cleanedSource, jenova::GlobalSettings::ScriptToolIdentifier);
}
Error CPPScript::_reload(bool p_keep_state)
{
jenova::VerboseByID(__LINE__, "Reloading C++ Script (%s)", AS_C_STRING(this->get_path()));
if (!jenova::UpdateGlobalStorageFromEditorSettings()) return Error::FAILED;
if (jenova::GlobalStorage::CurrentChangesTriggerMode == jenova::ChangesTriggerMode::TriggerOnScriptReload)
{
scriptMutex->lock();
auto now = std::chrono::steady_clock::now();
if (now - lastScriptReloadTime >= std::chrono::milliseconds(jenova::GlobalSettings::ScriptReloadCooldown))
{
lastScriptReloadTime = now;
if (jenova::QueueProjectBuild())
{
scriptMutex->unlock();
return Error::OK;
}
}
scriptMutex->unlock();
}
return Error::ERR_UNAVAILABLE;
}
TypedArray<Dictionary> CPPScript::_get_documentation() const
{
return TypedArray<Dictionary>(); // Not Supported Yet
}
String CPPScript::_get_class_icon_path() const
{
return String(); // Not Supported Yet
}
bool CPPScript::_has_method(const StringName& p_method) const
{
jenova::VerboseByID(__LINE__, "CPPScript::_has_method (%s)", AS_C_STRING(p_method));
return false; // Not Supported Yet
}
bool CPPScript::_has_static_method(const StringName& p_method) const
{
jenova::VerboseByID(__LINE__, "CPPScript::_has_static_method (%s)", AS_C_STRING(p_method));
return false; // Not Supported Yet
}
Dictionary CPPScript::_get_method_info(const StringName& p_method) const
{
jenova::VerboseByID(__LINE__, "CPPScript::_get_method_info (%s)", AS_C_STRING(p_method));
return Dictionary(); // Not Supported Yet
}
bool CPPScript::_is_tool() const
{
return IsTool;
}
bool CPPScript::_is_valid() const
{
// Ask From Interpreter
return true;
}
bool CPPScript::_is_abstract() const
{
return false;
}
ScriptLanguage* CPPScript::_get_language() const
{
return CPPScriptLanguage::get_singleton();
}
bool CPPScript::_has_script_signal(const StringName& p_signal) const
{
jenova::VerboseByID(__LINE__, "CPPScript::_has_script_signal (%s)", AS_C_STRING(p_signal));
return false; // Not Supported Yet
}
TypedArray<Dictionary> CPPScript::_get_script_signal_list() const
{
jenova::VerboseByID(__LINE__, "CPPScript::_get_script_signal_list");
return TypedArray<Dictionary>();
}
bool CPPScript::_has_property_default_value(const StringName& p_property) const
{
jenova::VerboseByID(__LINE__, "CPPScript::_has_property_default_value (%s)", AS_C_STRING(p_property));
// This will cause property change flag on assigned node!
return false;
}
Variant CPPScript::_get_property_default_value(const StringName& p_property) const
{
jenova::VerboseByID(__LINE__, "CPPScript::_get_property_default_value (%s)", AS_C_STRING(p_property));
return Variant(); // Not Supported Yet
}
void CPPScript::_update_exports()
{
jenova::VerboseByID(__LINE__, "CPPScript::_update_exports");
}
TypedArray<Dictionary> CPPScript::_get_script_method_list() const
{
jenova::VerboseByID(__LINE__, "CPPScript::_get_script_method_list");
return TypedArray<Dictionary>(); // Not Supported Yet
}
TypedArray<Dictionary> CPPScript::_get_script_property_list() const
{
jenova::VerboseByID(__LINE__, "CPPScript::_get_script_property_list");
TypedArray<Dictionary> properties;
return properties; // Not Supported Yet
}
int32_t CPPScript::_get_member_line(const StringName& p_member) const
{
jenova::VerboseByID(__LINE__, "CPPScript::_get_member_line (%s)", AS_C_STRING(p_member));
return 0; // Not Supported Yet
}
Dictionary CPPScript::_get_constants() const
{
jenova::VerboseByID(__LINE__, "CPPScript::_get_constants");
return Dictionary(); // Not Supported Yet
}
TypedArray<StringName> CPPScript::_get_members() const
{
jenova::VerboseByID(__LINE__, "CPPScript::_get_members");
return TypedArray<StringName>(); // Not Supported Yet
}
bool CPPScript::_is_placeholder_fallback_enabled() const
{
return false; // Not Supported Yet
}
Variant CPPScript::_get_rpc_config() const
{
jenova::VerboseByID(__LINE__, "CPPScript::_get_rpc_config");
return Variant(); // Not Supported Yet
}
// CPPScript Extended Implementation
void CPPScript::SetDefaultSourceCode()
{
// Set Default Source Code
source_code = CODE_TEMPLATE(CODE_TEMPLATE_DEFAULT);
}
jenova::ScriptIdentifier CPPScript::GenerateScriptIdentity()
{
scriptObjectIdentity = jenova::GenerateStandardUIDFromPath(this);
return scriptObjectIdentity;
}
jenova::ScriptIdentifier CPPScript::GetScriptIdentity()
{
return scriptObjectIdentity;
}
bool CPPScript::HasValidScriptIdentity() const
{
if (scriptObjectIdentity.is_empty()) return false;
return true;
}
bool CPPScript::SetScriptIdentity(jenova::ScriptIdentifier newIdentity)
{
scriptObjectIdentity = newIdentity;
return true;
}
void CPPScript::ReloadScriptSourceCode()
{
source_code = FileAccess::get_file_as_string(this->get_path());
}
// CPPScript Initializer/Destructor
CPPScript::CPPScript()
{
// Initialize Objects
scriptMutex.instantiate();
// Register Script Object to Manager
JenovaScriptManager::get_singleton()->add_script_object(this);
// Set Default Source Code
SetDefaultSourceCode();
}
CPPScript::~CPPScript()
{
// Release Objects
scriptMutex.unref();
// Unregister Script Object to Manager
JenovaScriptManager::get_singleton()->remove_script_object(this);
}
// CPPHeader Object Implementation
void CPPHeader::_bind_methods() { }
bool CPPHeader::_editor_can_reload_from_file() { return false; }
void CPPHeader::_placeholder_erased(void* p_placeholder) { }
bool CPPHeader::_can_instantiate() const { return false; }
Ref<Script> CPPHeader::_get_base_script() const { return Ref<Script>(); }
StringName CPPHeader::_get_global_name()
{
return StringName("Jenova C++ Header");
}
bool CPPHeader::_inherits_script(const Ref<Script>& p_script) const
{
return false;
}
StringName CPPHeader::_get_instance_base_type() const
{
return StringName(jenova::GlobalSettings::JenovaHeaderType);
}
void* CPPHeader::_instance_create(Object* p_for_object) const { return nullptr; }
void* CPPHeader::_placeholder_instance_create(Object* p_for_object) const { return nullptr; }
bool CPPHeader::_instance_has(Object* p_object) const { return false; }
bool CPPHeader::_has_source_code() const { return !source_code.is_empty(); }
String CPPHeader::_get_source_code() const { return this->source_code; }
void CPPHeader::_set_source_code(const String& p_code) { this->source_code = p_code; }
Error CPPHeader::_reload(bool p_keep_state) { return Error::ERR_UNAVAILABLE; }
TypedArray<Dictionary> CPPHeader::_get_documentation() const { return TypedArray<Dictionary>(); }
String CPPHeader::_get_class_icon_path() const { return String(); }
bool CPPHeader::_has_method(const StringName& p_method) const { return false; }
bool CPPHeader::_has_static_method(const StringName& p_method) const { return false; }
Dictionary CPPHeader::_get_method_info(const StringName& p_method) const { return Dictionary(); }
bool CPPHeader::_is_tool() const { return false; }
bool CPPHeader::_is_valid() const { return false; }
bool CPPHeader::_is_abstract() const { return true; }
ScriptLanguage* CPPHeader::_get_language() const
{
return CPPHeaderLanguage::get_singleton();
}
bool CPPHeader::_has_script_signal(const StringName& p_signal) const { return false; }
TypedArray<Dictionary> CPPHeader::_get_script_signal_list() const { return TypedArray<Dictionary>(); }
bool CPPHeader::_has_property_default_value(const StringName& p_property) const { return false; }
Variant CPPHeader::_get_property_default_value(const StringName& p_property) const { return false; }
void CPPHeader::_update_exports() { }
TypedArray<Dictionary> CPPHeader::_get_script_method_list() const { return TypedArray<Dictionary>(); }
TypedArray<Dictionary> CPPHeader::_get_script_property_list() const { return TypedArray<Dictionary>(); }
int32_t CPPHeader::_get_member_line(const StringName& p_member) const { return 0; }
Dictionary CPPHeader::_get_constants() const { return Dictionary(); }
TypedArray<StringName> CPPHeader::_get_members() const { return TypedArray<StringName>(); }
bool CPPHeader::_is_placeholder_fallback_enabled() const { return false; }
Variant CPPHeader::_get_rpc_config() const { return Variant(); }
void CPPHeader::ReloadHeaderSourceCode()
{
source_code = FileAccess::get_file_as_string(this->get_path());
}
CPPHeader::CPPHeader()
{
this->source_code = "#pragma once\n";
}