summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
Diffstat (limited to 'core/os')
-rw-r--r--core/os/dir_access.cpp21
-rw-r--r--core/os/file_access.cpp10
-rw-r--r--core/os/input_event.cpp40
-rw-r--r--core/os/input_event.h11
-rw-r--r--core/os/main_loop.cpp4
-rw-r--r--core/os/main_loop.h2
-rw-r--r--core/os/memory.cpp9
-rw-r--r--core/os/memory.h1
-rw-r--r--core/os/os.cpp36
-rw-r--r--core/os/os.h8
10 files changed, 74 insertions, 68 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index b444f0ae1e..e7496055ec 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -244,7 +244,7 @@ DirAccess *DirAccess::open(const String &p_path, Error *r_error) {
DirAccess *da = create_for_path(p_path);
- ERR_FAIL_COND_V(!da, NULL);
+ ERR_FAIL_COND_V_MSG(!da, NULL, "Cannot create DirAccess for path '" + p_path + "'.");
Error err = da->change_dir(p_path);
if (r_error)
*r_error = err;
@@ -384,39 +384,36 @@ Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flag
String target_dir = p_to + rel_path;
if (!p_target_da->dir_exists(target_dir)) {
Error err = p_target_da->make_dir(target_dir);
- ERR_FAIL_COND_V(err, err);
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot create directory '" + target_dir + "'.");
}
Error err = change_dir(E->get());
- ERR_FAIL_COND_V(err, err);
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot change current directory to '" + E->get() + "'.");
+
err = _copy_dir(p_target_da, p_to + rel_path + "/", p_chmod_flags);
if (err) {
change_dir("..");
- ERR_PRINT("Failed to copy recursively");
- return err;
+ ERR_FAIL_V_MSG(err, "Failed to copy recursively.");
}
err = change_dir("..");
- if (err) {
- ERR_PRINT("Failed to go back");
- return err;
- }
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to go back.");
}
return OK;
}
Error DirAccess::copy_dir(String p_from, String p_to, int p_chmod_flags) {
- ERR_FAIL_COND_V(!dir_exists(p_from), ERR_FILE_NOT_FOUND);
+ ERR_FAIL_COND_V_MSG(!dir_exists(p_from), ERR_FILE_NOT_FOUND, "Source directory doesn't exist.");
DirAccess *target_da = DirAccess::create_for_path(p_to);
- ERR_FAIL_COND_V(!target_da, ERR_CANT_CREATE);
+ ERR_FAIL_COND_V_MSG(!target_da, ERR_CANT_CREATE, "Cannot create DirAccess for path '" + p_to + "'.");
if (!target_da->dir_exists(p_to)) {
Error err = target_da->make_dir_recursive(p_to);
if (err) {
memdelete(target_da);
}
- ERR_FAIL_COND_V(err, err);
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot create directory '" + p_to + "'.");
}
if (!p_to.ends_with("/")) {
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 9a8315a3bb..738e597730 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -498,7 +498,7 @@ uint64_t FileAccess::get_modified_time(const String &p_file) {
return 0;
FileAccess *fa = create_for_path(p_file);
- ERR_FAIL_COND_V(!fa, 0);
+ ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'.");
uint64_t mt = fa->_get_modified_time(p_file);
memdelete(fa);
@@ -511,7 +511,7 @@ uint32_t FileAccess::get_unix_permissions(const String &p_file) {
return 0;
FileAccess *fa = create_for_path(p_file);
- ERR_FAIL_COND_V(!fa, 0);
+ ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'.");
uint32_t mt = fa->_get_unix_permissions(p_file);
memdelete(fa);
@@ -521,7 +521,7 @@ uint32_t FileAccess::get_unix_permissions(const String &p_file) {
Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissions) {
FileAccess *fa = create_for_path(p_file);
- ERR_FAIL_COND_V(!fa, ERR_CANT_CREATE);
+ ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create FileAccess for path '" + p_file + "'.");
Error err = fa->_set_unix_permissions(p_file, p_permissions);
memdelete(fa);
@@ -599,7 +599,7 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_err
if (r_error) { // if error requested, do not throw error
return Vector<uint8_t>();
}
- ERR_FAIL_V_MSG(Vector<uint8_t>(), "Can't open file from path: " + String(p_path) + ".");
+ ERR_FAIL_V_MSG(Vector<uint8_t>(), "Can't open file from path '" + String(p_path) + "'.");
}
Vector<uint8_t> data;
data.resize(f->get_len());
@@ -619,7 +619,7 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) {
if (r_error) {
return String();
}
- ERR_FAIL_V_MSG(String(), "Can't get file as string from path: " + String(p_path) + ".");
+ ERR_FAIL_V_MSG(String(), "Can't get file as string from path '" + String(p_path) + "'.");
}
String ret;
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 30fca0c155..f09a904953 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -49,11 +49,11 @@ bool InputEvent::is_action(const StringName &p_action) const {
return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action);
}
-bool InputEvent::is_action_pressed(const StringName &p_action) const {
+bool InputEvent::is_action_pressed(const StringName &p_action, bool p_allow_echo) const {
bool pressed;
bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed);
- return valid && pressed && !is_echo();
+ return valid && pressed && (p_allow_echo || !is_echo());
}
bool InputEvent::is_action_released(const StringName &p_action) const {
@@ -112,7 +112,7 @@ void InputEvent::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
ClassDB::bind_method(D_METHOD("is_action", "action"), &InputEvent::is_action);
- ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &InputEvent::is_action_pressed);
+ ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "allow_echo"), &InputEvent::is_action_pressed, DEFVAL(false));
ClassDB::bind_method(D_METHOD("is_action_released", "action"), &InputEvent::is_action_released);
ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &InputEvent::get_action_strength);
@@ -557,10 +557,31 @@ InputEventMouseButton::InputEventMouseButton() {
////////////////////////////////////////////
+void InputEventMouseMotion::set_tilt(const Vector2 &p_tilt) {
+
+ tilt = p_tilt;
+}
+
+Vector2 InputEventMouseMotion::get_tilt() const {
+
+ return tilt;
+}
+
+void InputEventMouseMotion::set_pressure(float p_pressure) {
+
+ pressure = p_pressure;
+}
+
+float InputEventMouseMotion::get_pressure() const {
+
+ return pressure;
+}
+
void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
relative = p_relative;
}
+
Vector2 InputEventMouseMotion::get_relative() const {
return relative;
@@ -570,6 +591,7 @@ void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
speed = p_speed;
}
+
Vector2 InputEventMouseMotion::get_speed() const {
return speed;
@@ -590,6 +612,8 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co
mm->set_modifiers_from_event(this);
mm->set_position(l);
+ mm->set_pressure(get_pressure());
+ mm->set_tilt(get_tilt());
mm->set_global_position(g);
mm->set_button_mask(get_button_mask());
@@ -665,17 +689,27 @@ bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
void InputEventMouseMotion::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventMouseMotion::set_tilt);
+ ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventMouseMotion::get_tilt);
+
+ ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMouseMotion::set_pressure);
+ ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMouseMotion::get_pressure);
+
ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
}
InputEventMouseMotion::InputEventMouseMotion() {
+
+ pressure = 0;
}
////////////////////////////////////////
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 28658e3865..a4db618bfe 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -184,7 +184,7 @@ public:
int get_device() const;
bool is_action(const StringName &p_action) const;
- bool is_action_pressed(const StringName &p_action) const;
+ bool is_action_pressed(const StringName &p_action, bool p_allow_echo = false) const;
bool is_action_released(const StringName &p_action) const;
float get_action_strength(const StringName &p_action) const;
@@ -351,6 +351,9 @@ public:
class InputEventMouseMotion : public InputEventMouse {
GDCLASS(InputEventMouseMotion, InputEventMouse);
+
+ Vector2 tilt;
+ float pressure;
Vector2 relative;
Vector2 speed;
@@ -358,6 +361,12 @@ protected:
static void _bind_methods();
public:
+ void set_tilt(const Vector2 &p_tilt);
+ Vector2 get_tilt() const;
+
+ void set_pressure(float p_pressure);
+ float get_pressure() const;
+
void set_relative(const Vector2 &p_relative);
Vector2 get_relative() const;
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index eca3b2a7f4..146a301995 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -63,6 +63,10 @@ void MainLoop::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_WM_ABOUT);
BIND_CONSTANT(NOTIFICATION_CRASH);
BIND_CONSTANT(NOTIFICATION_OS_IME_UPDATE);
+ BIND_CONSTANT(NOTIFICATION_APP_RESUMED);
+ BIND_CONSTANT(NOTIFICATION_APP_PAUSED);
+
+ ADD_SIGNAL(MethodInfo("on_request_permissions_result", PropertyInfo(Variant::STRING, "permission"), PropertyInfo(Variant::BOOL, "granted")));
};
void MainLoop::set_init_script(const Ref<Script> &p_init_script) {
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index 54e61fd2fa..aca920efcb 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -60,6 +60,8 @@ public:
NOTIFICATION_WM_ABOUT = 1011,
NOTIFICATION_CRASH = 1012,
NOTIFICATION_OS_IME_UPDATE = 1013,
+ NOTIFICATION_APP_RESUMED = 1014,
+ NOTIFICATION_APP_PAUSED = 1015,
};
virtual void input_event(const Ref<InputEvent> &p_event);
diff --git a/core/os/memory.cpp b/core/os/memory.cpp
index d1de51f3db..f4ed1d6e27 100644
--- a/core/os/memory.cpp
+++ b/core/os/memory.cpp
@@ -50,20 +50,17 @@ void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) {
#ifdef _MSC_VER
void operator delete(void *p_mem, const char *p_description) {
- ERR_EXPLAINC("Call to placement delete should not happen.");
- CRASH_NOW();
+ CRASH_NOW_MSG("Call to placement delete should not happen.");
}
void operator delete(void *p_mem, void *(*p_allocfunc)(size_t p_size)) {
- ERR_EXPLAINC("Call to placement delete should not happen.");
- CRASH_NOW();
+ CRASH_NOW_MSG("Call to placement delete should not happen.");
}
void operator delete(void *p_mem, void *p_pointer, size_t check, const char *p_description) {
- ERR_EXPLAINC("Call to placement delete should not happen.");
- CRASH_NOW();
+ CRASH_NOW_MSG("Call to placement delete should not happen.");
}
#endif
diff --git a/core/os/memory.h b/core/os/memory.h
index 8778cb63ad..a68a359546 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -31,6 +31,7 @@
#ifndef MEMORY_H
#define MEMORY_H
+#include "core/error_macros.h"
#include "core/safe_refcount.h"
#include <stddef.h>
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 7531900480..25889de1b3 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -196,29 +196,6 @@ bool OS::is_stdout_verbose() const {
return _verbose_stdout;
}
-void OS::set_last_error(const char *p_error) {
-
- GLOBAL_LOCK_FUNCTION
- if (p_error == NULL)
- p_error = "Unknown Error";
-
- if (last_error)
- memfree(last_error);
- last_error = NULL;
- int len = 0;
- while (p_error[len++])
- ;
-
- last_error = (char *)memalloc(len);
- for (int i = 0; i < len; i++)
- last_error[i] = p_error[i];
-}
-
-const char *OS::get_last_error() const {
- GLOBAL_LOCK_FUNCTION
- return last_error ? last_error : "";
-}
-
void OS::dump_memory_to_file(const char *p_file) {
//Memory::dump_static_mem_to_file(p_file);
@@ -297,14 +274,6 @@ void OS::dump_resources_to_file(const char *p_file) {
ResourceCache::dump(p_file);
}
-void OS::clear_last_error() {
-
- GLOBAL_LOCK_FUNCTION
- if (last_error)
- memfree(last_error);
- last_error = NULL;
-}
-
void OS::set_no_window_mode(bool p_enable) {
_no_window = p_enable;
@@ -722,7 +691,7 @@ int OS::get_audio_driver_count() const {
const char *OS::get_audio_driver_name(int p_driver) const {
AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
- ERR_FAIL_COND_V(!driver, "");
+ ERR_FAIL_COND_V_MSG(!driver, "", "Cannot get audio driver at index '" + itos(p_driver) + "'.");
return AudioDriverManager::get_driver(p_driver)->get_name();
}
@@ -764,7 +733,6 @@ OS::OS() {
void *volatile stack_bottom;
restart_on_exit = false;
- last_error = NULL;
singleton = this;
_keep_screen_on = true; // set default value to true, because this had been true before godot 2.0.
low_processor_usage_mode = false;
@@ -790,8 +758,6 @@ OS::OS() {
}
OS::~OS() {
- if (last_error)
- memfree(last_error);
memdelete(_logger);
singleton = NULL;
}
diff --git a/core/os/os.h b/core/os/os.h
index 9b46b43081..687ccaaba5 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -61,8 +61,6 @@ class OS {
bool _allow_layered;
bool _use_vsync;
- char *last_error;
-
void *_stack_bottom;
CompositeLogger *_logger;
@@ -155,10 +153,6 @@ public:
virtual void alert(const String &p_alert, const String &p_title = "ALERT!") = 0;
virtual String get_stdin_string(bool p_block = true) = 0;
- virtual void set_last_error(const char *p_error);
- virtual const char *get_last_error() const;
- virtual void clear_last_error();
-
enum MouseMode {
MOUSE_MODE_VISIBLE,
MOUSE_MODE_HIDDEN,
@@ -530,6 +524,8 @@ public:
List<String> get_restart_on_exit_arguments() const;
virtual bool request_permission(const String &p_name) { return true; }
+ virtual bool request_permissions() { return true; }
+ virtual Vector<String> get_granted_permissions() const { return Vector<String>(); }
virtual void process_and_drop_events() {}
OS();