summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/unix/os_unix.cpp45
-rw-r--r--drivers/unix/os_unix.h2
-rw-r--r--editor/script_editor_debugger.cpp29
-rw-r--r--scene/gui/text_edit.cpp4
4 files changed, 52 insertions, 28 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 9936c95cf9..7d3e6b412c 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -45,6 +45,7 @@
#ifdef __APPLE__
#include <mach-o/dyld.h>
+#include <mach/mach_time.h>
#endif
#if defined(__FreeBSD__) || defined(__OpenBSD__)
@@ -64,6 +65,32 @@
#include <sys/wait.h>
#include <unistd.h>
+/// Clock Setup function (used by get_ticks_usec)
+static uint64_t _clock_start = 0;
+#if defined(__APPLE__)
+static double _clock_scale = 0;
+static void _setup_clock() {
+ mach_timebase_info_data_t info;
+ kern_return_t ret = mach_timebase_info(&info);
+ ERR_EXPLAIN("OS CLOCK IS NOT WORKING!");
+ ERR_FAIL_COND(ret != 0);
+ _clock_scale = (double)info.numer / (double)info.denom;
+ _clock_start = mach_absolute_time() * _clock_scale;
+}
+#else
+#if defined(CLOCK_MONOTONIC_RAW) && !defined(JAVASCRIPT_ENABLED) // This is a better clock on Linux.
+#define GODOT_CLOCK CLOCK_MONOTONIC_RAW
+#else
+#define GODOT_CLOCK CLOCK_MONOTONIC
+#endif
+static void _setup_clock() {
+ struct timespec tv_now = { 0, 0 };
+ ERR_EXPLAIN("OS CLOCK IS NOT WORKING!");
+ ERR_FAIL_COND(clock_gettime(GODOT_CLOCK, &tv_now) != 0);
+ _clock_start = ((uint64_t)tv_now.tv_nsec / 1000L) + (uint64_t)tv_now.tv_sec * 1000000L;
+}
+#endif
+
void OS_Unix::debug_break() {
assert(false);
@@ -126,8 +153,7 @@ void OS_Unix::initialize_core() {
IP_Unix::make_default();
#endif
- ticks_start = 0;
- ticks_start = get_ticks_usec();
+ _setup_clock();
struct sigaction sa;
sa.sa_handler = &handle_sigchld;
@@ -246,11 +272,16 @@ void OS_Unix::delay_usec(uint32_t p_usec) const {
}
uint64_t OS_Unix::get_ticks_usec() const {
- struct timeval tv_now;
- gettimeofday(&tv_now, NULL);
-
- uint64_t longtime = (uint64_t)tv_now.tv_usec + (uint64_t)tv_now.tv_sec * 1000000L;
- longtime -= ticks_start;
+#if defined(__APPLE__)
+ uint64_t longtime = mach_absolute_time() * _clock_scale;
+#else
+ // Unchecked return. Static analyzers might complain.
+ // If _setup_clock() succeded, we assume clock_gettime() works.
+ struct timespec tv_now = { 0, 0 };
+ clock_gettime(GODOT_CLOCK, &tv_now);
+ uint64_t longtime = ((uint64_t)tv_now.tv_nsec / 1000L) + (uint64_t)tv_now.tv_sec * 1000000L;
+#endif
+ longtime -= _clock_start;
return longtime;
}
diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h
index f4abfa2dd4..b702454603 100644
--- a/drivers/unix/os_unix.h
+++ b/drivers/unix/os_unix.h
@@ -42,8 +42,6 @@
class OS_Unix : public OS {
- uint64_t ticks_start;
-
protected:
// UNIX only handles the core functions.
// inheriting platforms under unix (eg. X11) should handle the rest
diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp
index f13d3f5287..f18c43b0d0 100644
--- a/editor/script_editor_debugger.cpp
+++ b/editor/script_editor_debugger.cpp
@@ -502,8 +502,12 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
String str = var;
var = str.substr(4, str.length());
- if (str.begins_with("PATH"))
- var = ResourceLoader::load(var);
+ if (str.begins_with("PATH")) {
+ if (String(var).empty())
+ var = RES();
+ else
+ var = ResourceLoader::load(var);
+ }
}
debugObj->prop_values[pinfo.name] = var;
@@ -577,12 +581,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
String hs = String();
if (v.get_type() == Variant::OBJECT) {
+ v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
h = PROPERTY_HINT_OBJECT_ID;
- v = ObjectDB::get_instance(Object::cast_to<EncodedObjectAsID>(v)->get_object_id());
- String s = v;
- s = s.replace("[", "");
- hs = s.get_slice(":", 0);
- v = s.get_slice(":", 1).to_int();
+ hs = "Object";
}
variables->add_property("Locals/" + n, v, h, hs);
@@ -599,12 +600,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
String hs = String();
if (v.get_type() == Variant::OBJECT) {
+ v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
h = PROPERTY_HINT_OBJECT_ID;
- v = ObjectDB::get_instance(Object::cast_to<EncodedObjectAsID>(v)->get_object_id());
- String s = v;
- s = s.replace("[", "");
- hs = s.get_slice(":", 0);
- v = s.get_slice(":", 1).to_int();
+ hs = "Object";
}
variables->add_property("Members/" + n, v, h, hs);
@@ -621,12 +619,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
String hs = String();
if (v.get_type() == Variant::OBJECT) {
+ v = Object::cast_to<EncodedObjectAsID>(v)->get_object_id();
h = PROPERTY_HINT_OBJECT_ID;
- v = ObjectDB::get_instance(Object::cast_to<EncodedObjectAsID>(v)->get_object_id());
- String s = v;
- s = s.replace("[", "");
- hs = s.get_slice(":", 0);
- v = s.get_slice(":", 1).to_int();
+ hs = "Object";
}
variables->add_property("Globals/" + n, v, h, hs);
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 632a686256..9fe306c236 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -5150,7 +5150,7 @@ bool TextEdit::can_fold(int p_line) const {
return false;
if (p_line + 1 >= text.size())
return false;
- if (text[p_line].size() == 0)
+ if (text[p_line].strip_edges().size() == 0)
return false;
if (is_folded(p_line))
return false;
@@ -5162,7 +5162,7 @@ bool TextEdit::can_fold(int p_line) const {
int start_indent = get_indent_level(p_line);
for (int i = p_line + 1; i < text.size(); i++) {
- if (text[i].size() == 0)
+ if (text[i].strip_edges().size() == 0)
continue;
int next_indent = get_indent_level(i);
if (is_line_comment(i)) {