diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/dir_access.cpp | 8 | ||||
-rw-r--r-- | core/os/dir_access.h | 17 | ||||
-rw-r--r-- | core/os/file_access.cpp | 8 | ||||
-rw-r--r-- | core/os/input.cpp | 1 | ||||
-rw-r--r-- | core/os/input.h | 1 | ||||
-rw-r--r-- | core/os/input_event.cpp | 4 | ||||
-rw-r--r-- | core/os/input_event.h | 4 | ||||
-rw-r--r-- | core/os/keyboard.h | 4 | ||||
-rw-r--r-- | core/os/main_loop.cpp | 8 | ||||
-rw-r--r-- | core/os/main_loop.h | 5 | ||||
-rw-r--r-- | core/os/memory.h | 4 | ||||
-rw-r--r-- | core/os/os.cpp | 13 | ||||
-rw-r--r-- | core/os/os.h | 10 | ||||
-rw-r--r-- | core/os/semaphore.h | 4 | ||||
-rw-r--r-- | core/os/thread.h | 4 |
15 files changed, 41 insertions, 54 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 0cdb5b41b7..b444f0ae1e 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -179,14 +179,6 @@ Error DirAccess::make_dir_recursive(String p_dir) { return OK; } -String DirAccess::get_next(bool *p_is_dir) { - - String next = get_next(); - if (p_is_dir) - *p_is_dir = current_is_dir(); - return next; -} - String DirAccess::fix_path(String p_path) const { switch (_access_type) { diff --git a/core/os/dir_access.h b/core/os/dir_access.h index bde19bd5ae..d3eb1e13f6 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -34,10 +34,6 @@ #include "core/typedefs.h" #include "core/ustring.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - //@ TODO, excellent candidate for THREAD_SAFE MACRO, should go through all these and add THREAD_SAFE where it applies class DirAccess { public: @@ -71,7 +67,6 @@ protected: public: virtual Error list_dir_begin() = 0; ///< This starts dir listing - virtual String get_next(bool *p_is_dir); // compatibility virtual String get_next() = 0; virtual bool current_is_dir() const = 0; virtual bool current_is_hidden() const = 0; @@ -98,6 +93,18 @@ public: virtual Error rename(String p_from, String p_to) = 0; virtual Error remove(String p_name) = 0; + // Meant for editor code when we want to quickly remove a file without custom + // handling (e.g. removing a cache file). + static void remove_file_or_error(String p_path) { + DirAccess *da = create(ACCESS_FILESYSTEM); + if (da->file_exists(p_path)) { + if (da->remove(p_path) != OK) { + ERR_FAIL_MSG("Cannot remove file or directory: " + p_path); + } + } + memdelete(da); + } + virtual String get_filesystem_type() const = 0; static String get_full_path(const String &p_path, AccessType p_access); static DirAccess *create_for_path(const String &p_path); diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 7509050b2b..9a8315a3bb 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -30,9 +30,9 @@ #include "file_access.h" +#include "core/crypto/crypto_core.h" #include "core/io/file_access_pack.h" #include "core/io/marshalls.h" -#include "core/math/crypto_core.h" #include "core/os/os.h" #include "core/project_settings.h" @@ -599,8 +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_EXPLAIN("Can't open file from path: " + String(p_path)); - ERR_FAIL_V(Vector<uint8_t>()); + 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()); @@ -620,8 +619,7 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) { if (r_error) { return String(); } - ERR_EXPLAIN("Can't get file as string from path: " + String(p_path)); - ERR_FAIL_V(String()); + ERR_FAIL_V_MSG(String(), "Can't get file as string from path: " + String(p_path) + "."); } String ret; diff --git a/core/os/input.cpp b/core/os/input.cpp index f04d4a1b3e..51cb41b184 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -80,6 +80,7 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string); ClassDB::bind_method(D_METHOD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0)); ClassDB::bind_method(D_METHOD("stop_joy_vibration", "device"), &Input::stop_joy_vibration); + ClassDB::bind_method(D_METHOD("vibrate_handheld", "duration_ms"), &Input::vibrate_handheld, DEFVAL(500)); ClassDB::bind_method(D_METHOD("get_gravity"), &Input::get_gravity); ClassDB::bind_method(D_METHOD("get_accelerometer"), &Input::get_accelerometer); ClassDB::bind_method(D_METHOD("get_magnetometer"), &Input::get_magnetometer); diff --git a/core/os/input.h b/core/os/input.h index de04f239e6..a12ded176b 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -100,6 +100,7 @@ public: virtual uint64_t get_joy_vibration_timestamp(int p_device) = 0; virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0) = 0; virtual void stop_joy_vibration(int p_device) = 0; + virtual void vibrate_handheld(int p_duration_ms = 500) = 0; virtual Point2 get_mouse_position() const = 0; virtual Point2 get_last_mouse_speed() const = 0; diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index a40a50cfce..30fca0c155 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -450,7 +450,7 @@ bool InputEventMouseButton::is_doubleclick() const { Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Vector2 g = p_xform.xform(get_global_position()); + Vector2 g = get_global_position(); Vector2 l = p_xform.xform(get_position() + p_local_ofs); Ref<InputEventMouseButton> mb; @@ -577,7 +577,7 @@ Vector2 InputEventMouseMotion::get_speed() const { Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - Vector2 g = p_xform.xform(get_global_position()); + Vector2 g = get_global_position(); Vector2 l = p_xform.xform(get_position() + p_local_ofs); Vector2 r = p_xform.basis_xform(get_relative()); Vector2 s = p_xform.basis_xform(get_speed()); diff --git a/core/os/input_event.h b/core/os/input_event.h index 4f5762e756..28658e3865 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -38,10 +38,6 @@ #include "core/ustring.h" /** - @author Juan Linietsky <reduzio@gmail.com> -*/ - -/** * Input Event classes. These are used in the main loop. * The events are pretty obvious. */ diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 58a0807579..5c8a2e90e9 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -33,10 +33,6 @@ #include "core/ustring.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - /* Special Key: diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 9946ced2f3..eca3b2a7f4 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -49,6 +49,8 @@ void MainLoop::_bind_methods() { BIND_VMETHOD(MethodInfo("_drop_files", PropertyInfo(Variant::POOL_STRING_ARRAY, "files"), PropertyInfo(Variant::INT, "from_screen"))); BIND_VMETHOD(MethodInfo("_finalize")); + BIND_VMETHOD(MethodInfo("_global_menu_action", PropertyInfo(Variant::NIL, "id"), PropertyInfo(Variant::NIL, "meta"))); + BIND_CONSTANT(NOTIFICATION_WM_MOUSE_ENTER); BIND_CONSTANT(NOTIFICATION_WM_MOUSE_EXIT); BIND_CONSTANT(NOTIFICATION_WM_FOCUS_IN); @@ -115,6 +117,12 @@ void MainLoop::drop_files(const Vector<String> &p_files, int p_from_screen) { get_script_instance()->call("_drop_files", p_files, p_from_screen); } +void MainLoop::global_menu_action(const Variant &p_id, const Variant &p_meta) { + + if (get_script_instance()) + get_script_instance()->call("_global_menu_action", p_id, p_meta); +} + void MainLoop::finish() { if (get_script_instance()) { diff --git a/core/os/main_loop.h b/core/os/main_loop.h index ad734d3fc8..54e61fd2fa 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -35,10 +35,6 @@ #include "core/reference.h" #include "core/script_language.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class MainLoop : public Object { GDCLASS(MainLoop, Object); @@ -75,6 +71,7 @@ public: virtual void finish(); virtual void drop_files(const Vector<String> &p_files, int p_from_screen = 0); + virtual void global_menu_action(const Variant &p_id, const Variant &p_meta); void set_init_script(const Ref<Script> &p_init_script); diff --git a/core/os/memory.h b/core/os/memory.h index e073b11e76..8778cb63ad 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -35,10 +35,6 @@ #include <stddef.h> -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - #ifndef PAD_ALIGN #define PAD_ALIGN 16 //must always be greater than this at much #endif diff --git a/core/os/os.cpp b/core/os/os.cpp index 925154af7d..7531900480 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -186,6 +186,11 @@ int OS::get_process_id() const { return -1; }; +void OS::vibrate_handheld(int p_duration_ms) { + + WARN_PRINTS("vibrate_handheld() only works with Android and iOS"); +} + bool OS::is_stdout_verbose() const { return _verbose_stdout; @@ -268,8 +273,7 @@ void OS::print_all_resources(String p_to_file) { _OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err); if (err != OK) { _OSPRF = NULL; - ERR_EXPLAIN("Can't print all resources to file: " + String(p_to_file)); - ERR_FAIL(); + ERR_FAIL_MSG("Can't print all resources to file: " + String(p_to_file) + "."); } } @@ -487,10 +491,7 @@ void OS::_ensure_user_data_dir() { da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); Error err = da->make_dir_recursive(dd); - if (err != OK) { - ERR_EXPLAIN("Error attempting to create data dir: " + dd); - } - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Error attempting to create data dir: " + dd + "."); memdelete(da); } diff --git a/core/os/os.h b/core/os/os.h index 2224d3b006..9b46b43081 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -41,10 +41,6 @@ #include <stdarg.h> -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class Mutex; class OS { @@ -147,6 +143,11 @@ public: static OS *get_singleton(); + virtual void global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta){}; + virtual void global_menu_add_separator(const String &p_menu){}; + virtual void global_menu_remove_item(const String &p_menu, int p_idx){}; + virtual void global_menu_clear(const String &p_menu){}; + void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, Logger::ErrorType p_type = Logger::ERR_ERROR); void print(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3; void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3; @@ -269,6 +270,7 @@ public: virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false, Mutex *p_pipe_mutex = NULL) = 0; virtual Error kill(const ProcessID &p_pid) = 0; virtual int get_process_id() const; + virtual void vibrate_handheld(int p_duration_ms = 500); virtual Error shell_open(String p_uri); virtual Error set_cwd(const String &p_cwd); diff --git a/core/os/semaphore.h b/core/os/semaphore.h index ccbba0dacd..a0862dce84 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -33,10 +33,6 @@ #include "core/error_list.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class Semaphore { protected: static Semaphore *(*create_func)(); diff --git a/core/os/thread.h b/core/os/thread.h index e7a6e8cb1f..169280a208 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -34,10 +34,6 @@ #include "core/typedefs.h" #include "core/ustring.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - typedef void (*ThreadCreateCallback)(void *p_userdata); class Thread { |