summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
Diffstat (limited to 'core/os')
-rw-r--r--core/os/dir_access.cpp134
-rw-r--r--core/os/dir_access.h2
-rw-r--r--core/os/file_access.cpp35
-rw-r--r--core/os/file_access.h9
-rw-r--r--core/os/input.cpp5
-rw-r--r--core/os/input.h6
-rw-r--r--core/os/main_loop.cpp10
-rw-r--r--core/os/main_loop.h2
-rw-r--r--core/os/memory.h9
-rw-r--r--core/os/os.cpp18
-rw-r--r--core/os/os.h7
11 files changed, 129 insertions, 108 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 9a7135913a..c2402183fd 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -143,118 +143,52 @@ Error DirAccess::make_dir_recursive(String p_dir) {
};
String full_dir;
- Globals* g = Globals::get_singleton();
- if (!p_dir.is_abs_path()) {
- //append current
+ if (p_dir.is_rel_path()) {
+ //append current
+ full_dir=get_current_dir().plus_file(p_dir);
- String cur = normalize_path(g->globalize_path(get_current_dir()));
- if (cur[cur.length()-1] != '/') {
- cur = cur + "/";
- };
-
- full_dir=(cur+"/"+p_dir).simplify_path();
} else {
- //validate and use given
- String dir = normalize_path(g->globalize_path(p_dir));
- if (dir.length() < 1) {
- return OK;
- };
- if (dir[dir.length()-1] != '/') {
- dir = dir + "/";
- };
- full_dir=dir;
+ full_dir=p_dir;
}
- //int slices = full_dir.get_slice_count("/");
-
- int pos = 0;
- while (pos < full_dir.length()) {
-
- int n = full_dir.find("/", pos);
- if (n < 0) {
- n = full_dir.length();
- };
- pos = n + 1;
-
- if (pos > 1) {
- String to_create = full_dir.substr(0, pos -1);
- //print_line("MKDIR: "+to_create);
- Error err = make_dir(to_create);
- if (err != OK && err != ERR_ALREADY_EXISTS) {
-
- ERR_FAIL_V(err);
- };
- };
- };
-
- return OK;
-};
-
-
-String DirAccess::normalize_path(const String &p_path) {
-
- static const int max_depth = 64;
- int pos_stack[max_depth];
- int curr = 0;
-
- int pos = 0;
- String cur_dir;
-
- do {
+ full_dir=full_dir.replace("\\","/");
- if (curr >= max_depth) {
-
- ERR_PRINT("Directory depth too deep.");
- return "";
- };
-
- int start = pos;
-
- int next = p_path.find("/", pos);
- if (next < 0) {
- next = p_path.length() - 1;
- };
-
- pos = next + 1;
+ //int slices = full_dir.get_slice_count("/");
- cur_dir = p_path.substr(start, next - start);
+ String base;
- if (cur_dir == "" || cur_dir == ".") {
- continue;
- };
- if (cur_dir == "..") {
+ if (full_dir.begins_with("res://"))
+ base="res://";
+ else if (full_dir.begins_with("user://"))
+ base="user://";
+ else if (full_dir.begins_with("/"))
+ base="/";
+ else if (full_dir.find(":/")!=-1) {
+ base=full_dir.substr(0,full_dir.find(":/")+2);
+ } else {
+ ERR_FAIL_V(ERR_INVALID_PARAMETER);
+ }
- if (curr > 0) { // pop a dir
- curr -= 2;
- };
- continue;
- };
+ full_dir=full_dir.replace_first(base,"").simplify_path();
- pos_stack[curr++] = start;
- pos_stack[curr++] = next;
+ Vector<String> subdirs=full_dir.split("/");
- } while (pos < p_path.length());
+ String curpath=base;
+ for(int i=0;i<subdirs.size();i++) {
- String path;
- if (p_path[0] == '/') {
- path = "/";
- };
+ curpath=curpath.plus_file(subdirs[i]);
+ Error err = make_dir(curpath);
+ if (err != OK && err != ERR_ALREADY_EXISTS) {
- int i=0;
- while (i < curr) {
-
- int start = pos_stack[i++];
+ ERR_FAIL_V(err);
+ }
+ }
- while ( ((i+1)<curr) && (pos_stack[i] == pos_stack[i+1]) ) {
+ return OK;
+}
- ++i;
- };
- path = path + p_path.substr(start, (pos_stack[i++] - start) + 1);
- };
- return path;
-};
String DirAccess::get_next(bool* p_is_dir) {
@@ -276,9 +210,9 @@ String DirAccess::fix_path(String p_path) const {
String resource_path = Globals::get_singleton()->get_resource_path();
if (resource_path != "") {
- return p_path.replace("res:/",resource_path);
+ return p_path.replace_first("res:/",resource_path);
};
- return p_path.replace("res://", "");
+ return p_path.replace_first("res://", "");
}
}
@@ -292,9 +226,9 @@ String DirAccess::fix_path(String p_path) const {
String data_dir=OS::get_singleton()->get_data_dir();
if (data_dir != "") {
- return p_path.replace("user:/",data_dir);
+ return p_path.replace_first("user:/",data_dir);
};
- return p_path.replace("user://", "");
+ return p_path.replace_first("user://", "");
}
} break;
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index 7a850ddc6d..83288b7c91 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -72,8 +72,6 @@ protected:
public:
- static String normalize_path(const String& p_path);
-
virtual bool list_dir_begin()=0; ///< This starts dir listing
virtual String get_next(bool* p_is_dir); // compatibility
virtual String get_next()=0;
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index a3ee9395de..2f1693c044 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -31,10 +31,13 @@
#include "os/os.h"
#include "core/io/marshalls.h"
#include "io/md5.h"
+#include "io/sha256.h"
#include "core/io/file_access_pack.h"
FileAccess::CreateFunc FileAccess::create_func[ACCESS_MAX]={0,0};
+FileAccess::FileCloseFailNotify FileAccess::close_fail_notify=NULL;
+
bool FileAccess::backup_save=false;
@@ -515,6 +518,38 @@ String FileAccess::get_md5(const String& p_file) {
}
+String FileAccess::get_sha256(const String& p_file) {
+
+ FileAccess *f=FileAccess::open(p_file,READ);
+ if (!f)
+ return String();
+
+ sha256_context sha256;
+ sha256_init(&sha256);
+
+ unsigned char step[32768];
+
+ while(true) {
+
+ int br = f->get_buffer(step,32768);
+ if (br>0) {
+
+ sha256_hash(&sha256,step,br);
+ }
+ if (br < 4096)
+ break;
+
+ }
+
+ unsigned char hash[32];
+
+ sha256_done(&sha256, hash);
+
+ memdelete(f);
+ return String::hex_encode_buffer(hash, 32);
+
+}
+
FileAccess::FileAccess() {
endian_swap=false;
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 2c894c94eb..5178c469bc 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -47,6 +47,8 @@ public:
ACCESS_MAX
};
+ typedef void (*FileCloseFailNotify)(const String&);
+
typedef FileAccess*(*CreateFunc)();
bool endian_swap;
bool real_is_double;
@@ -56,7 +58,7 @@ protected:
virtual Error _open(const String& p_path, int p_mode_flags)=0; ///< open a file
virtual uint64_t _get_modified_time(const String& p_file)=0;
-
+ static FileCloseFailNotify close_fail_notify;
private:
static bool backup_save;
@@ -69,8 +71,12 @@ private:
return memnew( T );
}
+
+
public:
+ static void set_file_close_fail_notify_callback(FileCloseFailNotify p_cbk) { close_fail_notify=p_cbk; }
+
virtual void _set_access_type(AccessType p_access);
enum ModeFlags {
@@ -147,6 +153,7 @@ public:
static bool is_backup_save_enabled() { return backup_save; };
static String get_md5(const String& p_file);
+ static String get_sha256(const String& p_file);
static Vector<uint8_t> get_file_as_array(const String& p_path);
diff --git a/core/os/input.cpp b/core/os/input.cpp
index 6e1e618d9a..005a248aac 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -59,7 +59,12 @@ void Input::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_joy_axis","device","axis"),&Input::get_joy_axis);
ObjectTypeDB::bind_method(_MD("get_joy_name","device"),&Input::get_joy_name);
ObjectTypeDB::bind_method(_MD("get_joy_guid","device"),&Input::get_joy_guid);
+ ObjectTypeDB::bind_method(_MD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength);
+ ObjectTypeDB::bind_method(_MD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration);
+ ObjectTypeDB::bind_method(_MD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration);
+ ObjectTypeDB::bind_method(_MD("stop_joy_vibration", "device"), &Input::stop_joy_vibration);
ObjectTypeDB::bind_method(_MD("get_accelerometer"),&Input::get_accelerometer);
+ ObjectTypeDB::bind_method(_MD("get_magnetometer"),&Input::get_magnetometer);
//ObjectTypeDB::bind_method(_MD("get_mouse_pos"),&Input::get_mouse_pos); - this is not the function you want
ObjectTypeDB::bind_method(_MD("get_mouse_speed"),&Input::get_mouse_speed);
ObjectTypeDB::bind_method(_MD("get_mouse_button_mask"),&Input::get_mouse_button_mask);
diff --git a/core/os/input.h b/core/os/input.h
index 535776f39c..6364d597b0 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -67,6 +67,11 @@ public:
virtual void remove_joy_mapping(String p_guid)=0;
virtual bool is_joy_known(int p_device)=0;
virtual String get_joy_guid(int p_device) const=0;
+ virtual Vector2 get_joy_vibration_strength(int p_device)=0;
+ virtual float get_joy_vibration_duration(int p_device)=0;
+ 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;
+ virtual void stop_joy_vibration(int p_device)=0;
virtual Point2 get_mouse_pos() const=0;
virtual Point2 get_mouse_speed() const=0;
@@ -75,6 +80,7 @@ public:
virtual void warp_mouse_pos(const Vector2& p_to)=0;
virtual Vector3 get_accelerometer()=0;
+ virtual Vector3 get_magnetometer()=0;
virtual void action_press(const StringName& p_action)=0;
virtual void action_release(const StringName& p_action)=0;
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index 310bbaa3b8..e5feebfbfc 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -43,6 +43,7 @@ void MainLoop::_bind_methods() {
BIND_VMETHOD( MethodInfo("_initialize") );
BIND_VMETHOD( MethodInfo("_iteration",PropertyInfo(Variant::REAL,"delta")) );
BIND_VMETHOD( MethodInfo("_idle",PropertyInfo(Variant::REAL,"delta")) );
+ BIND_VMETHOD( MethodInfo("_drop_files",PropertyInfo(Variant::STRING_ARRAY,"files"),PropertyInfo(Variant::INT,"screen")) );
BIND_VMETHOD( MethodInfo("_finalize") );
BIND_CONSTANT(NOTIFICATION_WM_MOUSE_ENTER);
@@ -108,6 +109,15 @@ bool MainLoop::idle(float p_time) {
return false;
}
+
+void MainLoop::drop_files(const Vector<String>& p_files,int p_from_screen) {
+
+
+ if (get_script_instance())
+ get_script_instance()->call("_drop_files",p_files,p_from_screen);
+
+}
+
void MainLoop::finish() {
if (get_script_instance()) {
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index a34014983e..57185d9d3d 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -64,6 +64,8 @@ public:
virtual bool idle(float p_time);
virtual void finish();
+ virtual void drop_files(const Vector<String>& p_files,int p_from_screen=0);
+
void set_init_script(const Ref<Script>& p_init_script);
MainLoop();
diff --git a/core/os/memory.h b/core/os/memory.h
index 8257e66851..5f4c6f929c 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -211,7 +211,7 @@ void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_de
#ifdef DEBUG_MEMORY_ENABLED
-#define memalloc(m_size) Memory::alloc_static(m_size, __FILE__":"__STR(__LINE__)", memalloc.")
+#define memalloc(m_size) Memory::alloc_static(m_size, __FILE__ ":" __STR(__LINE__) ", memalloc.")
#define memrealloc(m_mem,m_size) Memory::realloc_static(m_mem,m_size)
#define memfree(m_size) Memory::free_static(m_size)
@@ -224,8 +224,7 @@ void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_de
#endif
#ifdef DEBUG_MEMORY_ENABLED
-
-#define dynalloc(m_size) Memory::alloc_dynamic(m_size, __FILE__":"__STR(__LINE__)", type: DYNAMIC")
+#define dynalloc(m_size) Memory::alloc_dynamic(m_size, __FILE__ ":" __STR(__LINE__) ", type: DYNAMIC")
#define dynrealloc(m_mem,m_size) m_mem.resize(m_size)
#else
@@ -248,7 +247,7 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
#ifdef DEBUG_MEMORY_ENABLED
-#define memnew(m_class) _post_initialize(new(__FILE__":"__STR(__LINE__)", memnew type: "__STR(m_class)) m_class)
+#define memnew(m_class) _post_initialize(new(__FILE__ ":" __STR(__LINE__) ", memnew type: " __STR(m_class)) m_class)
#else
@@ -291,7 +290,7 @@ void memdelete_allocator(T *p_class) {
#define memdelete_notnull(m_v) { if (m_v) memdelete(m_v); }
#ifdef DEBUG_MEMORY_ENABLED
-#define memnew_arr( m_class, m_count ) memnew_arr_template<m_class>(m_count,__FILE__":"__STR(__LINE__)", memnew_arr type: "_STR(m_class))
+#define memnew_arr( m_class, m_count ) memnew_arr_template<m_class>(m_count,__FILE__ ":" __STR(__LINE__) ", memnew_arr type: " _STR(m_class))
#else
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 1aee6d9aa2..e501bc2eb5 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -306,6 +306,15 @@ String OS::get_system_dir(SystemDir p_dir) const {
return ".";
}
+String OS::get_safe_application_name() const {
+ String an = Globals::get_singleton()->get("application/name");
+ Vector<String> invalid_char = String("\\ / : * ? \" < > |").split(" ");
+ for (int i=0;i<invalid_char.size();i++) {
+ an = an.replace(invalid_char[i],"-");
+ }
+ return an;
+}
+
String OS::get_data_dir() const {
return ".";
@@ -530,6 +539,14 @@ String OS::get_joy_guid(int p_device) const {
void OS::set_context(int p_context) {
}
+void OS::set_use_vsync(bool p_enable) {
+
+}
+
+bool OS::is_vsnc_enabled() const{
+
+ return true;
+}
OS::OS() {
last_error=NULL;
@@ -548,6 +565,7 @@ OS::OS() {
_render_thread_mode=RENDER_THREAD_SAFE;
_time_scale=1.0;
_pixel_snap=false;
+ _allow_hidpi=true;
Math::seed(1234567);
}
diff --git a/core/os/os.h b/core/os/os.h
index 160c0495bb..c291d09250 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -60,6 +60,7 @@ class OS {
int _target_fps;
float _time_scale;
bool _pixel_snap;
+ bool _allow_hidpi;
char *last_error;
@@ -160,6 +161,7 @@ public:
virtual void set_current_screen(int p_screen) { }
virtual Point2 get_screen_position(int p_screen=0) const { return Point2(); }
virtual Size2 get_screen_size(int p_screen=0) const { return get_window_size(); }
+ virtual int get_screen_dpi(int p_screen=0) const { return 72; }
virtual Point2 get_window_position() const { return Vector2(); }
virtual void set_window_position(const Point2& p_position) {}
virtual Size2 get_window_size() const=0;
@@ -324,6 +326,7 @@ public:
virtual String get_locale() const;
+ String get_safe_application_name() const;
virtual String get_data_dir() const;
virtual String get_resource_dir() const;
@@ -417,6 +420,10 @@ public:
virtual void set_context(int p_context);
+ virtual void set_use_vsync(bool p_enable);
+ virtual bool is_vsnc_enabled() const;
+
+ bool is_hidpi_allowed() const { return _allow_hidpi; }
OS();
virtual ~OS();