summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/math/random_pcg.cpp3
-rw-r--r--core/math/random_pcg.h2
-rw-r--r--core/project_settings.cpp3
-rw-r--r--doc/classes/ProjectSettings.xml4
-rw-r--r--modules/mono/csharp_script.cpp74
-rw-r--r--modules/mono/csharp_script.h20
-rw-r--r--modules/mono/glue/Managed/Files/DebuggingUtils.cs6
-rw-r--r--modules/mono/glue/Managed/Files/GodotTraceListener.cs37
-rw-r--r--modules/mono/glue/Managed/Files/Mathf.cs4
-rw-r--r--modules/mono/glue/Managed/Files/MathfEx.cs5
-rw-r--r--modules/mono/mono_gd/gd_mono.cpp21
-rw-r--r--modules/mono/mono_gd/gd_mono.h2
-rw-r--r--platform/android/java_glue.cpp11
-rw-r--r--scene/2d/animated_sprite.cpp2
-rw-r--r--scene/2d/sprite.cpp2
15 files changed, 162 insertions, 34 deletions
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp
index 8c324414e6..45467b32b2 100644
--- a/core/math/random_pcg.cpp
+++ b/core/math/random_pcg.cpp
@@ -33,7 +33,8 @@
#include "core/os/os.h"
RandomPCG::RandomPCG(uint64_t p_seed, uint64_t p_inc) :
- pcg() {
+ pcg(),
+ current_seed(DEFAULT_SEED) {
pcg.inc = p_inc;
seed(p_seed);
}
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h
index f6cc3db595..230eb9a11b 100644
--- a/core/math/random_pcg.h
+++ b/core/math/random_pcg.h
@@ -37,7 +37,7 @@
class RandomPCG {
pcg32_random_t pcg;
- uint64_t current_seed = DEFAULT_SEED; // seed with this to get the same state
+ uint64_t current_seed; // seed with this to get the same state
public:
static const uint64_t DEFAULT_SEED = 12047754176567800795U;
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 6b4895d688..02c7c9e029 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -1185,6 +1185,9 @@ ProjectSettings::ProjectSettings() {
Compression::gzip_level = GLOBAL_DEF("compression/formats/gzip/compression_level", Z_DEFAULT_COMPRESSION);
custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
+ // Would ideally be defined in an Android-specific file, but then it doesn't appear in the docs
+ GLOBAL_DEF("android/modules", "");
+
using_datapack = false;
}
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 1fec737642..74762df15e 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -163,7 +163,11 @@
</method>
</methods>
<members>
+ <member name="android/modules" type="String" setter="" getter="">
+ Comma-separated list of custom Android modules (which must have been built in the Android export templates) using their Java package path, e.g. [code]org/godotengine/org/GodotPaymentV3,org/godotengine/godot/MyCustomSingleton"[/code].
+ </member>
<member name="application/boot_splash/bg_color" type="Color" setter="" getter="">
+ Background color for the boot splash.
</member>
<member name="application/boot_splash/fullsize" type="bool" setter="" getter="">
Scale the boot splash image to the full window length when engine starts (will leave it as default pixel size otherwise).
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 47be3a9959..04405e0c1d 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -499,6 +499,47 @@ String CSharpLanguage::_get_indentation() const {
return "\t";
}
+String CSharpLanguage::debug_get_error() const {
+
+ return _debug_error;
+}
+
+int CSharpLanguage::debug_get_stack_level_count() const {
+
+ if (_debug_parse_err_line >= 0)
+ return 1;
+
+ // TODO: StackTrace
+ return 1;
+}
+
+int CSharpLanguage::debug_get_stack_level_line(int p_level) const {
+
+ if (_debug_parse_err_line >= 0)
+ return _debug_parse_err_line;
+
+ // TODO: StackTrace
+ return 1;
+}
+
+String CSharpLanguage::debug_get_stack_level_function(int p_level) const {
+
+ if (_debug_parse_err_line >= 0)
+ return String();
+
+ // TODO: StackTrace
+ return String();
+}
+
+String CSharpLanguage::debug_get_stack_level_source(int p_level) const {
+
+ if (_debug_parse_err_line >= 0)
+ return _debug_parse_err_file;
+
+ // TODO: StackTrace
+ return String();
+}
+
Vector<ScriptLanguage::StackInfo> CSharpLanguage::debug_get_current_stack_info() {
#ifdef DEBUG_ENABLED
@@ -958,12 +999,11 @@ void CSharpLanguage::thread_exit() {
bool CSharpLanguage::debug_break_parse(const String &p_file, int p_line, const String &p_error) {
- // Break because of parse error
+ // Not a parser error in our case, but it's still used for other type of errors
if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) {
- // TODO
- //_debug_parse_err_line = p_line;
- //_debug_parse_err_file = p_file;
- //_debug_error = p_error;
+ _debug_parse_err_line = p_line;
+ _debug_parse_err_file = p_file;
+ _debug_error = p_error;
ScriptDebugger::get_singleton()->debug(this, false);
return true;
} else {
@@ -974,10 +1014,9 @@ bool CSharpLanguage::debug_break_parse(const String &p_file, int p_line, const S
bool CSharpLanguage::debug_break(const String &p_error, bool p_allow_continue) {
if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) {
- // TODO
- //_debug_parse_err_line = -1;
- //_debug_parse_err_file = "";
- //_debug_error = p_error;
+ _debug_parse_err_line = -1;
+ _debug_parse_err_file = "";
+ _debug_error = p_error;
ScriptDebugger::get_singleton()->debug(this, p_allow_continue);
return true;
} else {
@@ -985,6 +1024,13 @@ bool CSharpLanguage::debug_break(const String &p_error, bool p_allow_continue) {
}
}
+void CSharpLanguage::_uninitialize_script_bindings() {
+ for (Map<Object *, CSharpScriptBinding>::Element *E = script_bindings.front(); E; E = E->next()) {
+ CSharpScriptBinding &script_binding = E->value();
+ script_binding.inited = false;
+ }
+}
+
void CSharpLanguage::set_language_index(int p_idx) {
ERR_FAIL_COND(lang_idx != -1);
@@ -1269,14 +1315,14 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) {
GDMonoClass *top = script->script_class;
while (top && top != script->native) {
- GDMonoField *field = script->script_class->get_field(p_name);
+ GDMonoField *field = top->get_field(p_name);
if (field) {
field->set_value_from_variant(mono_object, p_value);
return true;
}
- GDMonoProperty *property = script->script_class->get_property(p_name);
+ GDMonoProperty *property = top->get_property(p_name);
if (property) {
property->set_value(mono_object, GDMonoMarshal::variant_to_mono_object(p_value, property->get_type()));
@@ -2203,8 +2249,11 @@ bool CSharpScript::_get_member_export(GDMonoClass *p_class, IMonoClassMember *p_
hint_string = name_only_hint_string;
}
} else if (variant_type == Variant::OBJECT && CACHED_CLASS(GodotReference)->is_assignable_from(type.type_class)) {
+ GDMonoClass *field_native_class = GDMonoUtils::get_class_native_base(type.type_class);
+ CRASH_COND(field_native_class == NULL);
+
hint = PROPERTY_HINT_RESOURCE_TYPE;
- hint_string = NATIVE_GDMONOCLASS_NAME(type.type_class);
+ hint_string = NATIVE_GDMONOCLASS_NAME(field_native_class);
} else {
hint = PropertyHint(CACHED_FIELD(ExportAttribute, hint)->get_int_value(attr));
hint_string = CACHED_FIELD(ExportAttribute, hintString)->get_string_value(attr);
@@ -2699,6 +2748,7 @@ Error CSharpScript::reload(bool p_keep_state) {
}
load_script_signals(script_class, native);
+ _update_exports();
}
return OK;
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index 8b1a4b5f7e..99877a4379 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -162,7 +162,7 @@ public:
virtual bool has_script_signal(const StringName &p_signal) const;
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const;
- /* TODO */ virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
+ virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const;
virtual void update_exports();
@@ -309,6 +309,14 @@ class CSharpLanguage : public ScriptLanguage {
Dictionary scripts_metadata;
+ // For debug_break and debug_break_parse
+ int _debug_parse_err_line;
+ String _debug_parse_err_file;
+ String _debug_error;
+
+ friend class GDMono;
+ void _uninitialize_script_bindings();
+
public:
StringNameCache string_names;
@@ -365,11 +373,11 @@ public:
/* TODO */ virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) {}
/* DEBUGGER FUNCTIONS */
- /* TODO */ virtual String debug_get_error() const { return ""; }
- /* TODO */ virtual int debug_get_stack_level_count() const { return 1; }
- /* TODO */ virtual int debug_get_stack_level_line(int p_level) const { return 1; }
- /* TODO */ virtual String debug_get_stack_level_function(int p_level) const { return ""; }
- /* TODO */ virtual String debug_get_stack_level_source(int p_level) const { return ""; }
+ virtual String debug_get_error() const;
+ virtual int debug_get_stack_level_count() const;
+ virtual int debug_get_stack_level_line(int p_level) const;
+ virtual String debug_get_stack_level_function(int p_level) const;
+ virtual String debug_get_stack_level_source(int p_level) const;
/* TODO */ virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {}
/* TODO */ virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {}
/* TODO */ virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {}
diff --git a/modules/mono/glue/Managed/Files/DebuggingUtils.cs b/modules/mono/glue/Managed/Files/DebuggingUtils.cs
index b27816084e..edfe3464ec 100644
--- a/modules/mono/glue/Managed/Files/DebuggingUtils.cs
+++ b/modules/mono/glue/Managed/Files/DebuggingUtils.cs
@@ -19,6 +19,12 @@ namespace Godot
sb.Append(" ");
}
+ public static void InstallTraceListener()
+ {
+ Trace.Listeners.Clear();
+ Trace.Listeners.Add(new GodotTraceListener());
+ }
+
public static void GetStackFrameInfo(StackFrame frame, out string fileName, out int fileLineNumber, out string methodDecl)
{
fileName = frame.GetFileName();
diff --git a/modules/mono/glue/Managed/Files/GodotTraceListener.cs b/modules/mono/glue/Managed/Files/GodotTraceListener.cs
new file mode 100644
index 0000000000..f1a00ae0fa
--- /dev/null
+++ b/modules/mono/glue/Managed/Files/GodotTraceListener.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Diagnostics;
+
+namespace Godot
+{
+ internal class GodotTraceListener : TraceListener
+ {
+ public override void Write(string message)
+ {
+ GD.PrintRaw(message);
+ }
+
+ public override void WriteLine(string message)
+ {
+ GD.Print(message);
+ }
+
+ public override void Fail(string message, string detailMessage)
+ {
+ GD.PrintErr("Assertion failed: ", message);
+ if (detailMessage != null)
+ {
+ GD.PrintErr(" Details: ", detailMessage);
+ }
+
+ try
+ {
+ var stackTrace = new StackTrace(true).ToString();
+ GD.PrintErr(stackTrace);
+ }
+ catch
+ {
+ // ignored
+ }
+ }
+ }
+}
diff --git a/modules/mono/glue/Managed/Files/Mathf.cs b/modules/mono/glue/Managed/Files/Mathf.cs
index dcab3c1ffc..5f5de12959 100644
--- a/modules/mono/glue/Managed/Files/Mathf.cs
+++ b/modules/mono/glue/Managed/Files/Mathf.cs
@@ -289,13 +289,13 @@ namespace Godot
public static int Wrap(int value, int min, int max)
{
int rng = max - min;
- return min + ((value - min) % rng + rng) % rng;
+ return rng != 0 ? min + ((value - min) % rng + rng) % rng : min;
}
public static real_t Wrap(real_t value, real_t min, real_t max)
{
real_t rng = max - min;
- return min + ((value - min) % rng + rng) % rng;
+ return !IsEqualApprox(rng, default(real_t)) ? min + ((value - min) % rng + rng) % rng : min;
}
}
}
diff --git a/modules/mono/glue/Managed/Files/MathfEx.cs b/modules/mono/glue/Managed/Files/MathfEx.cs
index 2ef02cc288..414762f7b1 100644
--- a/modules/mono/glue/Managed/Files/MathfEx.cs
+++ b/modules/mono/glue/Managed/Files/MathfEx.cs
@@ -35,5 +35,10 @@ namespace Godot
{
return (int)Math.Round(s);
}
+
+ public static bool IsEqualApprox(real_t a, real_t b, real_t ratio = Mathf.Epsilon)
+ {
+ return Abs(a - b) < ratio;
+ }
}
} \ No newline at end of file
diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp
index acd8a3b73b..94aaff30c2 100644
--- a/modules/mono/mono_gd/gd_mono.cpp
+++ b/modules/mono/mono_gd/gd_mono.cpp
@@ -587,6 +587,8 @@ bool GDMono::_load_core_api_assembly() {
CS_GLUE_VERSION != api_assembly_ver.cs_glue_version;
if (!core_api_assembly_out_of_sync) {
GDMonoUtils::update_godot_api_cache();
+
+ _install_trace_listener();
}
#else
GDMonoUtils::update_godot_api_cache();
@@ -690,6 +692,23 @@ bool GDMono::_load_api_assemblies() {
return true;
}
+void GDMono::_install_trace_listener() {
+
+#ifdef DEBUG_ENABLED
+ // Install the trace listener now before the project assembly is loaded
+ typedef void (*DebuggingUtils_InstallTraceListener)(MonoObject **);
+ MonoException *exc = NULL;
+ GDMonoClass *debug_utils = core_api_assembly->get_class(BINDINGS_NAMESPACE, "DebuggingUtils");
+ DebuggingUtils_InstallTraceListener install_func =
+ (DebuggingUtils_InstallTraceListener)debug_utils->get_method_thunk("InstallTraceListener");
+ install_func((MonoObject **)&exc);
+ if (exc) {
+ ERR_PRINT("Failed to install System.Diagnostics.Trace listener");
+ GDMonoUtils::debug_print_unhandled_exception(exc);
+ }
+#endif
+}
+
#ifdef TOOLS_ENABLED
String GDMono::_get_api_assembly_metadata_path() {
@@ -848,6 +867,8 @@ Error GDMono::reload_scripts_domain() {
}
}
+ CSharpLanguage::get_singleton()->_uninitialize_script_bindings();
+
Error err = _load_scripts_domain();
if (err != OK) {
ERR_PRINT("Mono: Failed to load scripts domain");
diff --git a/modules/mono/mono_gd/gd_mono.h b/modules/mono/mono_gd/gd_mono.h
index 785b65ce13..216c96a612 100644
--- a/modules/mono/mono_gd/gd_mono.h
+++ b/modules/mono/mono_gd/gd_mono.h
@@ -125,6 +125,8 @@ class GDMono {
String _get_api_assembly_metadata_path();
#endif
+ void _install_trace_listener();
+
void _register_internal_calls();
Error _load_scripts_domain();
diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp
index 7adfec0ebb..dd60e96923 100644
--- a/platform/android/java_glue.cpp
+++ b/platform/android/java_glue.cpp
@@ -833,7 +833,6 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *en
static void _initialize_java_modules() {
if (!ProjectSettings::get_singleton()->has_setting("android/modules")) {
- print_line("Android modules: Nothing to load, aborting");
return;
}
@@ -853,19 +852,16 @@ static void _initialize_java_modules() {
jmethodID getClassLoader = env->GetMethodID(activityClass, "getClassLoader", "()Ljava/lang/ClassLoader;");
jobject cls = env->CallObjectMethod(_godot_instance, getClassLoader);
- //cls=env->NewGlobalRef(cls);
jclass classLoader = env->FindClass("java/lang/ClassLoader");
- //classLoader=(jclass)env->NewGlobalRef(classLoader);
jmethodID findClass = env->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
for (int i = 0; i < mods.size(); i++) {
String m = mods[i];
- //jclass singletonClass = env->FindClass(m.utf8().get_data());
- print_line("Loading module: " + m);
+ print_line("Loading Android module: " + m);
jstring strClassName = env->NewStringUTF(m.utf8().get_data());
jclass singletonClass = (jclass)env->CallObjectMethod(cls, findClass, strClassName);
@@ -874,7 +870,6 @@ static void _initialize_java_modules() {
ERR_EXPLAIN("Couldn't find singleton for class: " + m);
ERR_CONTINUE(!singletonClass);
}
- //singletonClass=(jclass)env->NewGlobalRef(singletonClass);
jmethodID initialize = env->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lorg/godotengine/godot/Godot$SingletonBase;");
@@ -1577,7 +1572,3 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *
// something
env->PopLocalFrame(NULL);
}
-
-//Main::cleanup();
-
-//return os.get_exit_code();
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp
index 3d7ff5f1fd..f8384bd1e4 100644
--- a/scene/2d/animated_sprite.cpp
+++ b/scene/2d/animated_sprite.cpp
@@ -93,7 +93,7 @@ Rect2 AnimatedSprite::_get_rect() const {
Point2 ofs = offset;
if (centered)
- ofs -= s / 2;
+ ofs -= Size2(s) / 2;
if (s == Size2(0, 0))
s = Size2(1, 1);
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp
index ba103a8bf0..a8c7622828 100644
--- a/scene/2d/sprite.cpp
+++ b/scene/2d/sprite.cpp
@@ -363,7 +363,7 @@ Rect2 Sprite::get_rect() const {
Point2 ofs = offset;
if (centered)
- ofs -= s / 2;
+ ofs -= Size2(s) / 2;
if (s == Size2(0, 0))
s = Size2(1, 1);