diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /core/os | |
parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) |
A Whole New World (clang-format edition)
I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?
I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon
A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format
A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
Diffstat (limited to 'core/os')
32 files changed, 1349 insertions, 1487 deletions
diff --git a/core/os/copymem.h b/core/os/copymem.h index 0452b1a36c..9b13d6c731 100644 --- a/core/os/copymem.h +++ b/core/os/copymem.h @@ -39,7 +39,7 @@ #include <string.h> -#define copymem(to,from,count) memcpy(to,from,count) +#define copymem(to, from, count) memcpy(to, from, count) #define zeromem(to, count) memset(to, 0, count) #define movemem(to, from, count) memmove(to, from, count) diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 974225a3e8..6f7255372f 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -27,15 +27,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "dir_access.h" +#include "global_config.h" #include "os/file_access.h" #include "os/memory.h" #include "os/os.h" -#include "global_config.h" - String DirAccess::_get_root_path() const { - switch(_access_type) { + switch (_access_type) { case ACCESS_RESOURCES: return GlobalConfig::get_singleton()->get_resource_path(); case ACCESS_USERDATA: return OS::get_singleton()->get_data_dir(); @@ -46,7 +45,7 @@ String DirAccess::_get_root_path() const { } String DirAccess::_get_root_string() const { - switch(_access_type) { + switch (_access_type) { case ACCESS_RESOURCES: return "res://"; case ACCESS_USERDATA: return "user://"; @@ -59,7 +58,7 @@ String DirAccess::_get_root_string() const { int DirAccess::get_current_drive() { String path = get_current_dir().to_lower(); - for(int i=0;i<get_drive_count();i++) { + for (int i = 0; i < get_drive_count(); i++) { String d = get_drive(i).to_lower(); if (path.begins_with(d)) return i; @@ -75,9 +74,9 @@ static Error _erase_recursive(DirAccess *da) { da->list_dir_begin(); String n = da->get_next(); - while(n!=String()) { + while (n != String()) { - if (n!="." && n!="..") { + if (n != "." && n != "..") { if (da->current_is_dir()) dirs.push_back(n); @@ -85,43 +84,43 @@ static Error _erase_recursive(DirAccess *da) { files.push_back(n); } - n=da->get_next(); + n = da->get_next(); } da->list_dir_end(); - for(List<String>::Element *E=dirs.front();E;E=E->next()) { + for (List<String>::Element *E = dirs.front(); E; E = E->next()) { Error err = da->change_dir(E->get()); - if (err==OK) { + if (err == OK) { err = _erase_recursive(da); if (err) { - print_line("err recurso "+E->get()); + print_line("err recurso " + E->get()); return err; } err = da->change_dir(".."); if (err) { - print_line("no go back "+E->get()); + print_line("no go back " + E->get()); return err; } err = da->remove(da->get_current_dir().plus_file(E->get())); if (err) { - print_line("no remove dir"+E->get()); + print_line("no remove dir" + E->get()); return err; } } else { - print_line("no change to "+E->get()); + print_line("no change to " + E->get()); return err; } } - for(List<String>::Element *E=files.front();E;E=E->next()) { + for (List<String>::Element *E = files.front(); E; E = E->next()) { Error err = da->remove(da->get_current_dir().plus_file(E->get())); if (err) { - print_line("no remove file"+E->get()); + print_line("no remove file" + E->get()); return err; } } @@ -129,13 +128,11 @@ static Error _erase_recursive(DirAccess *da) { return OK; } - Error DirAccess::erase_contents_recursive() { return _erase_recursive(this); } - Error DirAccess::make_dir_recursive(String p_dir) { if (p_dir.length() < 1) { @@ -145,39 +142,39 @@ Error DirAccess::make_dir_recursive(String p_dir) { String full_dir; if (p_dir.is_rel_path()) { - //append current - full_dir=get_current_dir().plus_file(p_dir); + //append current + full_dir = get_current_dir().plus_file(p_dir); } else { - full_dir=p_dir; + full_dir = p_dir; } - full_dir=full_dir.replace("\\","/"); + full_dir = full_dir.replace("\\", "/"); //int slices = full_dir.get_slice_count("/"); String base; if (full_dir.begins_with("res://")) - base="res://"; + base = "res://"; else if (full_dir.begins_with("user://")) - base="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); + base = "/"; + else if (full_dir.find(":/") != -1) { + base = full_dir.substr(0, full_dir.find(":/") + 2); } else { ERR_FAIL_V(ERR_INVALID_PARAMETER); } - full_dir=full_dir.replace_first(base,"").simplify_path(); + full_dir = full_dir.replace_first(base, "").simplify_path(); - Vector<String> subdirs=full_dir.split("/"); + Vector<String> subdirs = full_dir.split("/"); - String curpath=base; - for(int i=0;i<subdirs.size();i++) { + String curpath = base; + for (int i = 0; i < subdirs.size(); i++) { - curpath=curpath.plus_file(subdirs[i]); + curpath = curpath.plus_file(subdirs[i]); Error err = make_dir(curpath); if (err != OK && err != ERR_ALREADY_EXISTS) { @@ -188,19 +185,17 @@ Error DirAccess::make_dir_recursive(String p_dir) { return OK; } +String DirAccess::get_next(bool *p_is_dir) { - -String DirAccess::get_next(bool* p_is_dir) { - - String next=get_next(); + String next = get_next(); if (p_is_dir) - *p_is_dir=current_is_dir(); + *p_is_dir = current_is_dir(); return next; } String DirAccess::fix_path(String p_path) const { - switch(_access_type) { + switch (_access_type) { case ACCESS_RESOURCES: { @@ -210,23 +205,21 @@ String DirAccess::fix_path(String p_path) const { String resource_path = GlobalConfig::get_singleton()->get_resource_path(); if (resource_path != "") { - return p_path.replace_first("res:/",resource_path); + return p_path.replace_first("res:/", resource_path); }; return p_path.replace_first("res://", ""); } } - } break; case ACCESS_USERDATA: { - if (p_path.begins_with("user://")) { - String data_dir=OS::get_singleton()->get_data_dir(); + String data_dir = OS::get_singleton()->get_data_dir(); if (data_dir != "") { - return p_path.replace_first("user:/",data_dir); + return p_path.replace_first("user:/", data_dir); }; return p_path.replace_first("user://", ""); } @@ -241,35 +234,34 @@ String DirAccess::fix_path(String p_path) const { return p_path; } +DirAccess::CreateFunc DirAccess::create_func[ACCESS_MAX] = { 0, 0, 0 }; -DirAccess::CreateFunc DirAccess::create_func[ACCESS_MAX]={0,0,0}; +DirAccess *DirAccess::create_for_path(const String &p_path) { -DirAccess *DirAccess::create_for_path(const String& p_path) { - - DirAccess *da=NULL; + DirAccess *da = NULL; if (p_path.begins_with("res://")) { - da=create(ACCESS_RESOURCES); + da = create(ACCESS_RESOURCES); } else if (p_path.begins_with("user://")) { - da=create(ACCESS_USERDATA); + da = create(ACCESS_USERDATA); } else { - da=create(ACCESS_FILESYSTEM); + da = create(ACCESS_FILESYSTEM); } return da; } -DirAccess *DirAccess::open(const String& p_path,Error *r_error) { +DirAccess *DirAccess::open(const String &p_path, Error *r_error) { - DirAccess *da=create_for_path(p_path); + DirAccess *da = create_for_path(p_path); - ERR_FAIL_COND_V(!da,NULL); + ERR_FAIL_COND_V(!da, NULL); Error err = da->change_dir(p_path); if (r_error) - *r_error=err; - if (err!=OK) { + *r_error = err; + if (err != OK) { memdelete(da); return NULL; } @@ -279,63 +271,61 @@ DirAccess *DirAccess::open(const String& p_path,Error *r_error) { DirAccess *DirAccess::create(AccessType p_access) { - DirAccess * da = create_func[p_access]?create_func[p_access]():NULL; + DirAccess *da = create_func[p_access] ? create_func[p_access]() : NULL; if (da) { - da->_access_type=p_access; + da->_access_type = p_access; } return da; }; +String DirAccess::get_full_path(const String &p_path, AccessType p_access) { -String DirAccess::get_full_path(const String& p_path,AccessType p_access) { - - DirAccess *d=DirAccess::create(p_access); + DirAccess *d = DirAccess::create(p_access); if (!d) return p_path; d->change_dir(p_path); - String full=d->get_current_dir(); + String full = d->get_current_dir(); memdelete(d); return full; } -Error DirAccess::copy(String p_from,String p_to) { +Error DirAccess::copy(String p_from, String p_to) { //printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data()); Error err; - FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ,&err); + FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ, &err); if (err) { - ERR_FAIL_COND_V( err, err ); + ERR_FAIL_COND_V(err, err); } - - FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE,&err ); + FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE, &err); if (err) { fsrc->close(); - memdelete( fsrc ); - ERR_FAIL_COND_V( err, err ); + memdelete(fsrc); + ERR_FAIL_COND_V(err, err); } fsrc->seek_end(0); int size = fsrc->get_pos(); fsrc->seek(0); err = OK; - while(size--) { + while (size--) { - if (fsrc->get_error()!=OK) { - err= fsrc->get_error(); + if (fsrc->get_error() != OK) { + err = fsrc->get_error(); break; } - if (fdst->get_error()!=OK) { - err= fdst->get_error(); + if (fdst->get_error() != OK) { + err = fdst->get_error(); break; } - fdst->store_8( fsrc->get_8() ); + fdst->store_8(fsrc->get_8()); } memdelete(fsrc); @@ -346,21 +336,16 @@ Error DirAccess::copy(String p_from,String p_to) { bool DirAccess::exists(String p_dir) { - DirAccess* da = DirAccess::create_for_path(p_dir); - bool valid = da->change_dir(p_dir)==OK; + DirAccess *da = DirAccess::create_for_path(p_dir); + bool valid = da->change_dir(p_dir) == OK; memdelete(da); return valid; - } -DirAccess::DirAccess(){ +DirAccess::DirAccess() { - _access_type=ACCESS_FILESYSTEM; + _access_type = ACCESS_FILESYSTEM; } - DirAccess::~DirAccess() { - } - - diff --git a/core/os/dir_access.h b/core/os/dir_access.h index 7c173fc780..1ac2d0e03a 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -29,7 +29,6 @@ #ifndef DIR_ACCESS_H #define DIR_ACCESS_H - #include "typedefs.h" #include "ustring.h" @@ -40,7 +39,6 @@ //@ TOOD, excellent candidate for THREAD_SAFE MACRO, should go through all these and add THREAD_SAFE where it applies class DirAccess { public: - enum AccessType { ACCESS_RESOURCES, ACCESS_USERDATA, @@ -48,13 +46,9 @@ public: ACCESS_MAX }; - - - typedef DirAccess*(*CreateFunc)(); + typedef DirAccess *(*CreateFunc)(); private: - - AccessType _access_type; static CreateFunc create_func[ACCESS_MAX]; ///< set this to instance a filesystem object protected: @@ -64,45 +58,44 @@ protected: String fix_path(String p_path) const; bool next_is_dir; - template<class T> - static DirAccess* _create_builtin() { + template <class T> + static DirAccess *_create_builtin() { - return memnew( T ); + return memnew(T); } 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; - 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; - - virtual void list_dir_end()=0; ///< + virtual void list_dir_end() = 0; ///< - virtual int get_drive_count()=0; - virtual String get_drive(int p_drive)=0; + virtual int get_drive_count() = 0; + virtual String get_drive(int p_drive) = 0; virtual int get_current_drive(); - virtual Error change_dir(String p_dir)=0; ///< can be relative or absolute, return false on success - virtual String get_current_dir()=0; ///< return current dir location - virtual Error make_dir(String p_dir)=0; + virtual Error change_dir(String p_dir) = 0; ///< can be relative or absolute, return false on success + virtual String get_current_dir() = 0; ///< return current dir location + virtual Error make_dir(String p_dir) = 0; virtual Error make_dir_recursive(String p_dir); virtual Error erase_contents_recursive(); //super dangerous, use with care! - virtual bool file_exists(String p_file)=0; - virtual bool dir_exists(String p_dir)=0; + virtual bool file_exists(String p_file) = 0; + virtual bool dir_exists(String p_dir) = 0; static bool exists(String p_dir); - virtual size_t get_space_left()=0; + virtual size_t get_space_left() = 0; - virtual Error copy(String p_from,String p_to); - virtual Error rename(String p_from, String p_to)=0; - virtual Error remove(String p_name)=0; + virtual Error copy(String p_from, String p_to); + virtual Error rename(String p_from, String p_to) = 0; + virtual Error remove(String p_name) = 0; - static String get_full_path(const String& p_path,AccessType p_access); - static DirAccess *create_for_path(const String& p_path); + static String get_full_path(const String &p_path, AccessType p_access); + static DirAccess *create_for_path(const String &p_path); -/* + /* enum DirType { FILE_TYPE_INVALID, @@ -114,30 +107,31 @@ public: */ static DirAccess *create(AccessType p_access); - template<class T> + template <class T> static void make_default(AccessType p_access) { - create_func[p_access]=_create_builtin<T>; + create_func[p_access] = _create_builtin<T>; } - static DirAccess *open(const String& p_path,Error *r_error=NULL); + static DirAccess *open(const String &p_path, Error *r_error = NULL); DirAccess(); virtual ~DirAccess(); - }; struct DirAccessRef { - _FORCE_INLINE_ DirAccess* operator->() { + _FORCE_INLINE_ DirAccess *operator->() { return f; } - operator bool() const { return f!=NULL; } + operator bool() const { return f != NULL; } DirAccess *f; DirAccessRef(DirAccess *fa) { f = fa; } - ~DirAccessRef() { if (f) memdelete(f); } + ~DirAccessRef() { + if (f) memdelete(f); + } }; #endif diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index ae592720e8..3aac1f6f21 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -27,42 +27,39 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "file_access.h" -#include "global_config.h" -#include "os/os.h" +#include "core/io/file_access_pack.h" #include "core/io/marshalls.h" +#include "global_config.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}; +#include "os/os.h" -FileAccess::FileCloseFailNotify FileAccess::close_fail_notify=NULL; +FileAccess::CreateFunc FileAccess::create_func[ACCESS_MAX] = { 0, 0 }; +FileAccess::FileCloseFailNotify FileAccess::close_fail_notify = NULL; -bool FileAccess::backup_save=false; +bool FileAccess::backup_save = false; -FileAccess *FileAccess::create(AccessType p_access){ +FileAccess *FileAccess::create(AccessType p_access) { - ERR_FAIL_COND_V( !create_func, 0 ); - ERR_FAIL_INDEX_V( p_access,ACCESS_MAX, 0 ); + ERR_FAIL_COND_V(!create_func, 0); + ERR_FAIL_INDEX_V(p_access, ACCESS_MAX, 0); FileAccess *ret = create_func[p_access](); ret->_set_access_type(p_access); return ret; } -bool FileAccess::exists(const String& p_name) { +bool FileAccess::exists(const String &p_name) { if (PackedData::get_singleton()->has_path(p_name)) return true; - FileAccess *f=open(p_name,READ); + FileAccess *f = open(p_name, READ); if (!f) return false; memdelete(f); return true; - - } void FileAccess::_set_access_type(AccessType p_access) { @@ -70,9 +67,9 @@ void FileAccess::_set_access_type(AccessType p_access) { _access_type = p_access; }; -FileAccess *FileAccess::create_for_path(const String& p_path) { +FileAccess *FileAccess::create_for_path(const String &p_path) { - FileAccess *ret=NULL; + FileAccess *ret = NULL; if (p_path.begins_with("res://")) { ret = create(ACCESS_RESOURCES); @@ -86,56 +83,52 @@ FileAccess *FileAccess::create_for_path(const String& p_path) { } return ret; - - } -Error FileAccess::reopen(const String& p_path, int p_mode_flags) { +Error FileAccess::reopen(const String &p_path, int p_mode_flags) { return _open(p_path, p_mode_flags); }; - -FileAccess *FileAccess::open(const String& p_path, int p_mode_flags, Error *r_error) { +FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_error) { //try packed data first - FileAccess *ret=NULL; - if (!(p_mode_flags&WRITE) && PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled()) { + FileAccess *ret = NULL; + if (!(p_mode_flags & WRITE) && PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled()) { ret = PackedData::get_singleton()->try_open_path(p_path); if (ret) { if (r_error) - *r_error=OK; + *r_error = OK; return ret; } } - ret=create_for_path(p_path); - Error err = ret->_open(p_path,p_mode_flags); + ret = create_for_path(p_path); + Error err = ret->_open(p_path, p_mode_flags); if (r_error) - *r_error=err; - if (err!=OK) { + *r_error = err; + if (err != OK) { memdelete(ret); - ret=NULL; + ret = NULL; } return ret; } - FileAccess::CreateFunc FileAccess::get_create_func(AccessType p_access) { return create_func[p_access]; }; -String FileAccess::fix_path(const String& p_path) const { +String FileAccess::fix_path(const String &p_path) const { //helper used by file accesses that use a single filesystem String r_path = p_path.replace("\\", "/"); - switch(_access_type) { + switch (_access_type) { case ACCESS_RESOURCES: { @@ -145,23 +138,21 @@ String FileAccess::fix_path(const String& p_path) const { String resource_path = GlobalConfig::get_singleton()->get_resource_path(); if (resource_path != "") { - return r_path.replace("res:/",resource_path); + return r_path.replace("res:/", resource_path); }; return r_path.replace("res://", ""); } } - } break; case ACCESS_USERDATA: { - if (r_path.begins_with("user://")) { - String data_dir=OS::get_singleton()->get_data_dir(); + String data_dir = OS::get_singleton()->get_data_dir(); if (data_dir != "") { - return r_path.replace("user:/",data_dir); + return r_path.replace("user:/", data_dir); }; return r_path.replace("user://", ""); } @@ -178,63 +169,62 @@ String FileAccess::fix_path(const String& p_path) const { /* these are all implemented for ease of porting, then can later be optimized */ -uint16_t FileAccess::get_16()const { +uint16_t FileAccess::get_16() const { uint16_t res; - uint8_t a,b; + uint8_t a, b; - a=get_8(); - b=get_8(); + a = get_8(); + b = get_8(); if (endian_swap) { - SWAP( a,b ); + SWAP(a, b); } - res=b; - res<<=8; - res|=a; + res = b; + res <<= 8; + res |= a; return res; } -uint32_t FileAccess::get_32() const{ +uint32_t FileAccess::get_32() const { uint32_t res; - uint16_t a,b; + uint16_t a, b; - a=get_16(); - b=get_16(); + a = get_16(); + b = get_16(); if (endian_swap) { - SWAP( a,b ); + SWAP(a, b); } - res=b; - res<<=16; - res|=a; + res = b; + res <<= 16; + res |= a; return res; } -uint64_t FileAccess::get_64()const { +uint64_t FileAccess::get_64() const { uint64_t res; - uint32_t a,b; + uint32_t a, b; - a=get_32(); - b=get_32(); + a = get_32(); + b = get_32(); if (endian_swap) { - SWAP( a,b ); + SWAP(a, b); } - res=b; - res<<=32; - res|=a; + res = b; + res <<= 32; + res |= a; return res; - } float FileAccess::get_float() const { @@ -250,7 +240,6 @@ real_t FileAccess::get_real() const { return get_double(); else return get_float(); - } double FileAccess::get_double() const { @@ -264,17 +253,17 @@ String FileAccess::get_line() const { CharString line; - CharType c=get_8(); + CharType c = get_8(); - while(!eof_reached()) { + while (!eof_reached()) { - if (c=='\n' || c=='\0') { + if (c == '\n' || c == '\0') { line.push_back(0); return String::utf8(line.get_data()); - } else if (c!='\r') + } else if (c != '\r') line.push_back(c); - c=get_8(); + c = get_8(); } line.push_back(0); return String::utf8(line.get_data()); @@ -282,51 +271,48 @@ String FileAccess::get_line() const { Vector<String> FileAccess::get_csv_line(String delim) const { - ERR_FAIL_COND_V(delim.length()!=1,Vector<String>()); + ERR_FAIL_COND_V(delim.length() != 1, Vector<String>()); String l; - int qc=0; + int qc = 0; do { - l+=get_line()+"\n"; - qc=0; - for(int i=0;i<l.length();i++) { + l += get_line() + "\n"; + qc = 0; + for (int i = 0; i < l.length(); i++) { - if (l[i]=='"') + if (l[i] == '"') qc++; } + } while (qc % 2); - } while (qc%2); - - l=l.substr(0, l.length()-1); + l = l.substr(0, l.length() - 1); Vector<String> strings; - bool in_quote=false; + bool in_quote = false; String current; - for(int i=0;i<l.length();i++) { + for (int i = 0; i < l.length(); i++) { CharType c = l[i]; - CharType s[2]={0,0}; - + CharType s[2] = { 0, 0 }; - if (!in_quote && c==delim[0]) { + if (!in_quote && c == delim[0]) { strings.push_back(current); - current=String(); - } else if (c=='"') { - if (l[i+1]=='"') { - s[0]='"'; - current+=s; + current = String(); + } else if (c == '"') { + if (l[i + 1] == '"') { + s[0] = '"'; + current += s; i++; } else { - in_quote=!in_quote; + in_quote = !in_quote; } } else { - s[0]=c; - current+=s; + s[0] = c; + current += s; } - } strings.push_back(current); @@ -334,73 +320,67 @@ Vector<String> FileAccess::get_csv_line(String delim) const { return strings; } +int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const { -int FileAccess::get_buffer(uint8_t *p_dst,int p_length) const{ - - int i=0; - for (i=0; i<p_length && !eof_reached(); i++) - p_dst[i]=get_8(); + int i = 0; + for (i = 0; i < p_length && !eof_reached(); i++) + p_dst[i] = get_8(); return i; } void FileAccess::store_16(uint16_t p_dest) { - uint8_t a,b; + uint8_t a, b; - a=p_dest&0xFF; - b=p_dest>>8; + a = p_dest & 0xFF; + b = p_dest >> 8; if (endian_swap) { - SWAP( a,b ); + SWAP(a, b); } store_8(a); store_8(b); - } void FileAccess::store_32(uint32_t p_dest) { + uint16_t a, b; - uint16_t a,b; - - a=p_dest&0xFFFF; - b=p_dest>>16; + a = p_dest & 0xFFFF; + b = p_dest >> 16; if (endian_swap) { - SWAP( a,b ); + SWAP(a, b); } store_16(a); store_16(b); - } void FileAccess::store_64(uint64_t p_dest) { - uint32_t a,b; + uint32_t a, b; - a=p_dest&0xFFFFFFFF; - b=p_dest>>32; + a = p_dest & 0xFFFFFFFF; + b = p_dest >> 32; if (endian_swap) { - SWAP( a,b ); + SWAP(a, b); } store_32(a); store_32(b); - } void FileAccess::store_real(real_t p_real) { - if (sizeof(real_t)==4) + if (sizeof(real_t) == 4) store_float(p_real); else store_double(p_real); - } void FileAccess::store_float(float p_dest) { @@ -417,40 +397,39 @@ void FileAccess::store_double(double p_dest) { store_64(m.l); }; -uint64_t FileAccess::get_modified_time(const String& p_file) { +uint64_t FileAccess::get_modified_time(const String &p_file) { FileAccess *fa = create_for_path(p_file); - ERR_FAIL_COND_V(!fa,0); + ERR_FAIL_COND_V(!fa, 0); uint64_t mt = fa->_get_modified_time(p_file); memdelete(fa); return mt; } -void FileAccess::store_string(const String& p_string) { +void FileAccess::store_string(const String &p_string) { - if (p_string.length()==0) + if (p_string.length() == 0) return; - CharString cs=p_string.utf8(); - store_buffer((uint8_t*)&cs[0],cs.length()); - + CharString cs = p_string.utf8(); + store_buffer((uint8_t *)&cs[0], cs.length()); } -void FileAccess::store_pascal_string(const String& p_string) { +void FileAccess::store_pascal_string(const String &p_string) { CharString cs = p_string.utf8(); store_32(cs.length()); - store_buffer((uint8_t*)&cs[0], cs.length()); + store_buffer((uint8_t *)&cs[0], cs.length()); }; String FileAccess::get_pascal_string() { uint32_t sl = get_32(); CharString cs; - cs.resize(sl+1); - get_buffer((uint8_t*)cs.ptr(),sl); - cs[sl]=0; + cs.resize(sl + 1); + get_buffer((uint8_t *)cs.ptr(), sl); + cs[sl] = 0; String ret; ret.parse_utf8(cs.ptr()); @@ -458,35 +437,32 @@ String FileAccess::get_pascal_string() { return ret; }; - -void FileAccess::store_line(const String& p_line) { +void FileAccess::store_line(const String &p_line) { store_string(p_line); store_8('\n'); } -void FileAccess::store_buffer(const uint8_t *p_src,int p_length) { +void FileAccess::store_buffer(const uint8_t *p_src, int p_length) { - for (int i=0;i<p_length;i++) + for (int i = 0; i < p_length; i++) store_8(p_src[i]); } -Vector<uint8_t> FileAccess::get_file_as_array(const String& p_file) { +Vector<uint8_t> FileAccess::get_file_as_array(const String &p_file) { - FileAccess *f=FileAccess::open(p_file,READ); - ERR_FAIL_COND_V(!f,Vector<uint8_t>()); + FileAccess *f = FileAccess::open(p_file, READ); + ERR_FAIL_COND_V(!f, Vector<uint8_t>()); Vector<uint8_t> data; data.resize(f->get_len()); - f->get_buffer(data.ptr(),data.size()); + f->get_buffer(data.ptr(), data.size()); memdelete(f); return data; - - } -String FileAccess::get_md5(const String& p_file) { +String FileAccess::get_md5(const String &p_file) { - FileAccess *f=FileAccess::open(p_file,READ); + FileAccess *f = FileAccess::open(p_file, READ); if (!f) return String(); @@ -495,32 +471,28 @@ String FileAccess::get_md5(const String& p_file) { unsigned char step[32768]; - while(true) { + while (true) { - int br = f->get_buffer(step,32768); - if (br>0) { + int br = f->get_buffer(step, 32768); + if (br > 0) { - MD5Update(&md5,step,br); + MD5Update(&md5, step, br); } if (br < 4096) break; - } MD5Final(&md5); String ret = String::md5(md5.digest); - - memdelete(f); return ret; - } -String FileAccess::get_sha256(const String& p_file) { +String FileAccess::get_sha256(const String &p_file) { - FileAccess *f=FileAccess::open(p_file,READ); + FileAccess *f = FileAccess::open(p_file, READ); if (!f) return String(); @@ -529,16 +501,15 @@ String FileAccess::get_sha256(const String& p_file) { unsigned char step[32768]; - while(true) { + while (true) { - int br = f->get_buffer(step,32768); - if (br>0) { + int br = f->get_buffer(step, 32768); + if (br > 0) { - sha256_hash(&sha256,step,br); + sha256_hash(&sha256, step, br); } if (br < 4096) break; - } unsigned char hash[32]; @@ -547,12 +518,11 @@ String FileAccess::get_sha256(const String& p_file) { memdelete(f); return String::hex_encode_buffer(hash, 32); - } FileAccess::FileAccess() { - endian_swap=false; - real_is_double=false; - _access_type=ACCESS_FILESYSTEM; + endian_swap = false; + real_is_double = false; + _access_type = ACCESS_FILESYSTEM; }; diff --git a/core/os/file_access.h b/core/os/file_access.h index 7d61099bc2..10d3ffebbb 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -29,10 +29,10 @@ #ifndef FILE_ACCESS_H #define FILE_ACCESS_H +#include "math_defs.h" +#include "os/memory.h" #include "typedefs.h" #include "ustring.h" -#include "os/memory.h" -#include "math_defs.h" /** * Multi-Platform abstraction for accessing to files. */ @@ -47,57 +47,54 @@ public: ACCESS_MAX }; - typedef void (*FileCloseFailNotify)(const String&); + typedef void (*FileCloseFailNotify)(const String &); - typedef FileAccess*(*CreateFunc)(); + typedef FileAccess *(*CreateFunc)(); bool endian_swap; bool real_is_double; -protected: - String fix_path(const String& p_path) const; - 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; +protected: + String fix_path(const String &p_path) const; + 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: +private: static bool backup_save; AccessType _access_type; static CreateFunc create_func[ACCESS_MAX]; /** default file access creation function for a platform */ - template<class T> - static FileAccess* _create_builtin() { + template <class T> + static FileAccess *_create_builtin() { - return memnew( T ); + return memnew(T); } - - public: - - static void set_file_close_fail_notify_callback(FileCloseFailNotify p_cbk) { close_fail_notify=p_cbk; } + 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 { + enum ModeFlags { - READ=1, - WRITE=2, - READ_WRITE=3, - WRITE_READ=7, + READ = 1, + WRITE = 2, + READ_WRITE = 3, + WRITE_READ = 7, }; - virtual void close()=0; ///< close a file - virtual bool is_open() const=0; ///< true when file is open + virtual void close() = 0; ///< close a file + virtual bool is_open() const = 0; ///< true when file is open - virtual void seek(size_t p_position)=0; ///< seek to a given position - virtual void seek_end(int64_t p_position=0)=0; ///< seek from the end of file - virtual size_t get_pos() const=0; ///< get position in the file - virtual size_t get_len() const=0; ///< get size of the file + virtual void seek(size_t p_position) = 0; ///< seek to a given position + virtual void seek_end(int64_t p_position = 0) = 0; ///< seek from the end of file + virtual size_t get_pos() const = 0; ///< get position in the file + virtual size_t get_len() const = 0; ///< get size of the file - virtual bool eof_reached() const=0; ///< reading passed EOF + virtual bool eof_reached() const = 0; ///< reading passed EOF - virtual uint8_t get_8() const=0; ///< get a byte + virtual uint8_t get_8() const = 0; ///< get a byte virtual uint16_t get_16() const; ///< get 16 bits uint virtual uint32_t get_32() const; ///< get 32 bits uint virtual uint64_t get_64() const; ///< get 64 bits uint @@ -106,21 +103,21 @@ public: virtual double get_double() const; virtual real_t get_real() const; - virtual int get_buffer(uint8_t *p_dst,int p_length) const; ///< get an array of bytes + virtual int get_buffer(uint8_t *p_dst, int p_length) const; ///< get an array of bytes virtual String get_line() const; - virtual Vector<String> get_csv_line(String delim=",") const; + virtual Vector<String> get_csv_line(String delim = ",") const; /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) * It's not about the current CPU type but file formats. * this flags get reset to false (little endian) on each open */ - virtual void set_endian_swap(bool p_swap) { endian_swap=p_swap; } + virtual void set_endian_swap(bool p_swap) { endian_swap = p_swap; } inline bool get_endian_swap() const { return endian_swap; } - virtual Error get_error() const=0; ///< get last error + virtual Error get_error() const = 0; ///< get last error - virtual void store_8(uint8_t p_dest)=0; ///< store a byte + virtual void store_8(uint8_t p_dest) = 0; ///< store a byte virtual void store_16(uint16_t p_dest); ///< store 16 bits uint virtual void store_32(uint32_t p_dest); ///< store 32 bits uint virtual void store_64(uint64_t p_dest); ///< store 64 bits uint @@ -129,58 +126,56 @@ public: virtual void store_double(double p_dest); virtual void store_real(real_t p_real); - virtual void store_string(const String& p_string); - virtual void store_line(const String& p_string); + virtual void store_string(const String &p_string); + virtual void store_line(const String &p_string); - virtual void store_pascal_string(const String& p_string); + virtual void store_pascal_string(const String &p_string); virtual String get_pascal_string(); - virtual void store_buffer(const uint8_t *p_src,int p_length); ///< store an array of bytes + virtual void store_buffer(const uint8_t *p_src, int p_length); ///< store an array of bytes - virtual bool file_exists(const String& p_name)=0; ///< return true if a file exists + virtual bool file_exists(const String &p_name) = 0; ///< return true if a file exists - virtual Error reopen(const String& p_path, int p_mode_flags); ///< does not change the AccessType + virtual Error reopen(const String &p_path, int p_mode_flags); ///< does not change the AccessType static FileAccess *create(AccessType p_access); /// Create a file access (for the current platform) this is the only portable way of accessing files. - static FileAccess *create_for_path(const String& p_path); - static FileAccess *open(const String& p_path, int p_mode_flags, Error *r_error=NULL); /// Create a file access (for the current platform) this is the only portable way of accessing files. + static FileAccess *create_for_path(const String &p_path); + static FileAccess *open(const String &p_path, int p_mode_flags, Error *r_error = NULL); /// Create a file access (for the current platform) this is the only portable way of accessing files. static CreateFunc get_create_func(AccessType p_access); - static bool exists(const String& p_name); ///< return true if a file exists - static uint64_t get_modified_time(const String& p_file); - + static bool exists(const String &p_name); ///< return true if a file exists + static uint64_t get_modified_time(const String &p_file); - static void set_backup_save(bool p_enable) { backup_save=p_enable; }; + static void set_backup_save(bool p_enable) { backup_save = p_enable; }; 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 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); + static Vector<uint8_t> get_file_as_array(const String &p_path); - - template<class T> + template <class T> static void make_default(AccessType p_access) { - create_func[p_access]=_create_builtin<T>; + create_func[p_access] = _create_builtin<T>; } FileAccess(); - virtual ~FileAccess(){} - + virtual ~FileAccess() {} }; - struct FileAccessRef { - _FORCE_INLINE_ FileAccess* operator->() { + _FORCE_INLINE_ FileAccess *operator->() { return f; } - operator bool() const { return f!=NULL; } + operator bool() const { return f != NULL; } FileAccess *f; FileAccessRef(FileAccess *fa) { f = fa; } - ~FileAccessRef() { if (f) memdelete(f); } + ~FileAccessRef() { + if (f) memdelete(f); + } }; #endif diff --git a/core/os/input.cpp b/core/os/input.cpp index 34883e63ba..63efbe4d11 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -27,10 +27,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "input.h" +#include "global_config.h" #include "input_map.h" #include "os/os.h" -#include "global_config.h" -Input *Input::singleton=NULL; +Input *Input::singleton = NULL; Input *Input::get_singleton() { @@ -38,7 +38,7 @@ Input *Input::get_singleton() { } void Input::set_mouse_mode(MouseMode p_mode) { - ERR_FAIL_INDEX(p_mode,4); + ERR_FAIL_INDEX(p_mode, 4); OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode); } @@ -49,19 +49,19 @@ Input::MouseMode Input::get_mouse_mode() const { void Input::_bind_methods() { - ClassDB::bind_method(D_METHOD("is_key_pressed","scancode"),&Input::is_key_pressed); - ClassDB::bind_method(D_METHOD("is_mouse_button_pressed","button"),&Input::is_mouse_button_pressed); - ClassDB::bind_method(D_METHOD("is_joy_button_pressed","device","button"),&Input::is_joy_button_pressed); - ClassDB::bind_method(D_METHOD("is_action_pressed","action"),&Input::is_action_pressed); - ClassDB::bind_method(D_METHOD("is_action_just_pressed","action"),&Input::is_action_just_pressed); - ClassDB::bind_method(D_METHOD("is_action_just_released","action"),&Input::is_action_just_released); - ClassDB::bind_method(D_METHOD("add_joy_mapping","mapping", "update_existing"),&Input::add_joy_mapping, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("remove_joy_mapping","guid"),&Input::remove_joy_mapping); - ClassDB::bind_method(D_METHOD("is_joy_known","device"),&Input::is_joy_known); - ClassDB::bind_method(D_METHOD("get_joy_axis","device","axis"),&Input::get_joy_axis); - ClassDB::bind_method(D_METHOD("get_joy_name","device"),&Input::get_joy_name); - ClassDB::bind_method(D_METHOD("get_joy_guid","device"),&Input::get_joy_guid); - ClassDB::bind_method(D_METHOD("get_connected_joypads"),&Input::get_connected_joypads); + ClassDB::bind_method(D_METHOD("is_key_pressed", "scancode"), &Input::is_key_pressed); + ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed); + ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed); + ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &Input::is_action_pressed); + ClassDB::bind_method(D_METHOD("is_action_just_pressed", "action"), &Input::is_action_just_pressed); + ClassDB::bind_method(D_METHOD("is_action_just_released", "action"), &Input::is_action_just_released); + ClassDB::bind_method(D_METHOD("add_joy_mapping", "mapping", "update_existing"), &Input::add_joy_mapping, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("remove_joy_mapping", "guid"), &Input::remove_joy_mapping); + ClassDB::bind_method(D_METHOD("is_joy_known", "device"), &Input::is_joy_known); + ClassDB::bind_method(D_METHOD("get_joy_axis", "device", "axis"), &Input::get_joy_axis); + ClassDB::bind_method(D_METHOD("get_joy_name", "device"), &Input::get_joy_name); + ClassDB::bind_method(D_METHOD("get_joy_guid", "device"), &Input::get_joy_guid); + ClassDB::bind_method(D_METHOD("get_connected_joypads"), &Input::get_connected_joypads); ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength); ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration); ClassDB::bind_method(D_METHOD("get_joy_button_string", "button_index"), &Input::get_joy_button_string); @@ -70,57 +70,53 @@ 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("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); - ClassDB::bind_method(D_METHOD("get_gyroscope"),&Input::get_gyroscope); + 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); + ClassDB::bind_method(D_METHOD("get_gyroscope"), &Input::get_gyroscope); //ClassDB::bind_method(D_METHOD("get_mouse_pos"),&Input::get_mouse_pos); - this is not the function you want - ClassDB::bind_method(D_METHOD("get_last_mouse_speed"),&Input::get_last_mouse_speed); - ClassDB::bind_method(D_METHOD("get_mouse_button_mask"),&Input::get_mouse_button_mask); - ClassDB::bind_method(D_METHOD("set_mouse_mode","mode"),&Input::set_mouse_mode); - ClassDB::bind_method(D_METHOD("get_mouse_mode"),&Input::get_mouse_mode); - ClassDB::bind_method(D_METHOD("warp_mouse_pos","to"),&Input::warp_mouse_pos); - ClassDB::bind_method(D_METHOD("action_press","action"),&Input::action_press); - ClassDB::bind_method(D_METHOD("action_release","action"),&Input::action_release); - ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor","image:Texture","hotspot"),&Input::set_custom_mouse_cursor,DEFVAL(Vector2())); - - BIND_CONSTANT( MOUSE_MODE_VISIBLE ); - BIND_CONSTANT( MOUSE_MODE_HIDDEN ); - BIND_CONSTANT( MOUSE_MODE_CAPTURED ); - BIND_CONSTANT( MOUSE_MODE_CONFINED ); - - ADD_SIGNAL( MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "connected")) ); + ClassDB::bind_method(D_METHOD("get_last_mouse_speed"), &Input::get_last_mouse_speed); + ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask); + ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &Input::set_mouse_mode); + ClassDB::bind_method(D_METHOD("get_mouse_mode"), &Input::get_mouse_mode); + ClassDB::bind_method(D_METHOD("warp_mouse_pos", "to"), &Input::warp_mouse_pos); + ClassDB::bind_method(D_METHOD("action_press", "action"), &Input::action_press); + ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release); + ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image:Texture", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(Vector2())); + + BIND_CONSTANT(MOUSE_MODE_VISIBLE); + BIND_CONSTANT(MOUSE_MODE_HIDDEN); + BIND_CONSTANT(MOUSE_MODE_CAPTURED); + BIND_CONSTANT(MOUSE_MODE_CONFINED); + + ADD_SIGNAL(MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "connected"))); } -void Input::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const { +void Input::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { #ifdef TOOLS_ENABLED - String pf=p_function; - if (p_idx==0 && (pf=="is_action_pressed" || pf=="action_press" || pf=="action_release" || pf=="is_action_just_pressed" || pf=="is_action_just_released")) { + String pf = p_function; + if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released")) { List<PropertyInfo> pinfo; GlobalConfig::get_singleton()->get_property_list(&pinfo); - for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { - const PropertyInfo &pi=E->get(); + for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { + const PropertyInfo &pi = E->get(); if (!pi.name.begins_with("input/")) continue; - String name = pi.name.substr(pi.name.find("/")+1,pi.name.length()); - r_options->push_back("\""+name+"\""); - + String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); + r_options->push_back("\"" + name + "\""); } } #endif - } Input::Input() { - singleton=this; + singleton = this; } - ////////////////////////////////////////////////////////// - diff --git a/core/os/input.h b/core/os/input.h index 2cea154a50..86755e632c 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -30,20 +30,19 @@ #define INPUT_H #include "object.h" -#include "os/thread_safe.h" #include "os/main_loop.h" +#include "os/thread_safe.h" class Input : public Object { - GDCLASS( Input, Object ); + GDCLASS(Input, Object); static Input *singleton; protected: - static void _bind_methods(); -public: +public: enum MouseMode { MOUSE_MODE_VISIBLE, MOUSE_MODE_HIDDEN, @@ -56,57 +55,56 @@ public: static Input *get_singleton(); - virtual bool is_key_pressed(int p_scancode) const=0; - virtual bool is_mouse_button_pressed(int p_button) const=0; - virtual bool is_joy_button_pressed(int p_device, int p_button) const=0; - virtual bool is_action_pressed(const StringName& p_action) const=0; - virtual bool is_action_just_pressed(const StringName& p_action) const=0; - virtual bool is_action_just_released(const StringName& p_action) const=0; - - virtual float get_joy_axis(int p_device,int p_axis) const=0; - virtual String get_joy_name(int p_idx)=0; - virtual Array get_connected_joypads()=0; - virtual void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid)=0; - virtual void add_joy_mapping(String p_mapping, bool p_update_existing=false)=0; - 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)=0; - virtual void stop_joy_vibration(int p_device)=0; - - virtual Point2 get_mouse_pos() const=0; - virtual Point2 get_last_mouse_speed() const=0; - virtual int get_mouse_button_mask() const=0; - - virtual void warp_mouse_pos(const Vector2& p_to)=0; - - virtual Vector3 get_gravity() const=0; - virtual Vector3 get_accelerometer() const=0; - virtual Vector3 get_magnetometer() const=0; - virtual Vector3 get_gyroscope() const=0; - - virtual void action_press(const StringName& p_action)=0; - virtual void action_release(const StringName& p_action)=0; - - void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; - - virtual bool is_emulating_touchscreen() const=0; - - virtual void set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_hotspot=Vector2())=0; - virtual void set_mouse_in_window(bool p_in_window)=0; - - virtual String get_joy_button_string(int p_button)=0; - virtual String get_joy_axis_string(int p_axis)=0; - virtual int get_joy_button_index_from_string(String p_button)=0; - virtual int get_joy_axis_index_from_string(String p_axis)=0; + virtual bool is_key_pressed(int p_scancode) const = 0; + virtual bool is_mouse_button_pressed(int p_button) const = 0; + virtual bool is_joy_button_pressed(int p_device, int p_button) const = 0; + virtual bool is_action_pressed(const StringName &p_action) const = 0; + virtual bool is_action_just_pressed(const StringName &p_action) const = 0; + virtual bool is_action_just_released(const StringName &p_action) const = 0; + + virtual float get_joy_axis(int p_device, int p_axis) const = 0; + virtual String get_joy_name(int p_idx) = 0; + virtual Array get_connected_joypads() = 0; + virtual void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) = 0; + virtual void add_joy_mapping(String p_mapping, bool p_update_existing = false) = 0; + 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) = 0; + virtual void stop_joy_vibration(int p_device) = 0; + + virtual Point2 get_mouse_pos() const = 0; + virtual Point2 get_last_mouse_speed() const = 0; + virtual int get_mouse_button_mask() const = 0; + + virtual void warp_mouse_pos(const Vector2 &p_to) = 0; + + virtual Vector3 get_gravity() const = 0; + virtual Vector3 get_accelerometer() const = 0; + virtual Vector3 get_magnetometer() const = 0; + virtual Vector3 get_gyroscope() const = 0; + + virtual void action_press(const StringName &p_action) = 0; + virtual void action_release(const StringName &p_action) = 0; + + void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const; + + virtual bool is_emulating_touchscreen() const = 0; + + virtual void set_custom_mouse_cursor(const RES &p_cursor, const Vector2 &p_hotspot = Vector2()) = 0; + virtual void set_mouse_in_window(bool p_in_window) = 0; + + virtual String get_joy_button_string(int p_button) = 0; + virtual String get_joy_axis_string(int p_axis) = 0; + virtual int get_joy_button_index_from_string(String p_button) = 0; + virtual int get_joy_axis_index_from_string(String p_axis) = 0; Input(); }; VARIANT_ENUM_CAST(Input::MouseMode); - #endif // INPUT_H diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 4ef99558ad..ebb1f4ed01 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -34,11 +34,11 @@ */ bool InputEvent::operator==(const InputEvent &p_event) const { - if (type != p_event.type){ + if (type != p_event.type) { return false; } - switch(type) { + switch (type) { /** Current clang-format style doesn't play well with the aligned return values of that switch. */ /* clang-format off */ case NONE: @@ -91,9 +91,9 @@ bool InputEvent::operator==(const InputEvent &p_event) const { } InputEvent::operator String() const { - String str="Device "+itos(device)+" ID "+itos(ID)+" "; + String str = "Device " + itos(device) + " ID " + itos(ID) + " "; - switch(type) { + switch (type) { case NONE: { @@ -101,108 +101,107 @@ InputEvent::operator String() const { } break; case KEY: { - str+= "Event: Key "; - str=str+"Unicode: "+String::chr(key.unicode)+" Scan: "+itos( key.scancode )+" Echo: "+String(key.echo?"True":"False")+" Pressed"+String(key.pressed?"True":"False")+" Mod: "; + str += "Event: Key "; + str = str + "Unicode: " + String::chr(key.unicode) + " Scan: " + itos(key.scancode) + " Echo: " + String(key.echo ? "True" : "False") + " Pressed" + String(key.pressed ? "True" : "False") + " Mod: "; if (key.mod.shift) - str+="S"; + str += "S"; if (key.mod.control) - str+="C"; + str += "C"; if (key.mod.alt) - str+="A"; + str += "A"; if (key.mod.meta) - str+="M"; + str += "M"; return str; } break; case MOUSE_MOTION: { - str+= "Event: Motion "; - str=str+" Pos: " +itos(mouse_motion.x)+","+itos(mouse_motion.y)+" Rel: "+itos(mouse_motion.relative_x)+","+itos(mouse_motion.relative_y)+" Mask: "; - for (int i=0;i<8;i++) { + str += "Event: Motion "; + str = str + " Pos: " + itos(mouse_motion.x) + "," + itos(mouse_motion.y) + " Rel: " + itos(mouse_motion.relative_x) + "," + itos(mouse_motion.relative_y) + " Mask: "; + for (int i = 0; i < 8; i++) { - if ((1<<i)&mouse_motion.button_mask) - str+=itos(i+1); + if ((1 << i) & mouse_motion.button_mask) + str += itos(i + 1); } - str+=" Mod: "; + str += " Mod: "; if (key.mod.shift) - str+="S"; + str += "S"; if (key.mod.control) - str+="C"; + str += "C"; if (key.mod.alt) - str+="A"; + str += "A"; if (key.mod.meta) - str+="M"; + str += "M"; return str; } break; case MOUSE_BUTTON: { - str+= "Event: Button "; - str=str+"Pressed: "+itos(mouse_button.pressed)+" Pos: " +itos(mouse_button.x)+","+itos(mouse_button.y)+" Button: "+itos(mouse_button.button_index)+" Mask: "; - for (int i=0;i<8;i++) { + str += "Event: Button "; + str = str + "Pressed: " + itos(mouse_button.pressed) + " Pos: " + itos(mouse_button.x) + "," + itos(mouse_button.y) + " Button: " + itos(mouse_button.button_index) + " Mask: "; + for (int i = 0; i < 8; i++) { - if ((1<<i)&mouse_button.button_mask) - str+=itos(i+1); + if ((1 << i) & mouse_button.button_mask) + str += itos(i + 1); } - str+=" Mod: "; + str += " Mod: "; if (key.mod.shift) - str+="S"; + str += "S"; if (key.mod.control) - str+="C"; + str += "C"; if (key.mod.alt) - str+="A"; + str += "A"; if (key.mod.meta) - str+="M"; + str += "M"; - str+=String(" DoubleClick: ")+(mouse_button.doubleclick?"Yes":"No"); + str += String(" DoubleClick: ") + (mouse_button.doubleclick ? "Yes" : "No"); return str; } break; case JOYPAD_MOTION: { - str+= "Event: JoypadMotion "; - str=str+"Axis: "+itos(joy_motion.axis)+" Value: " +rtos(joy_motion.axis_value); + str += "Event: JoypadMotion "; + str = str + "Axis: " + itos(joy_motion.axis) + " Value: " + rtos(joy_motion.axis_value); return str; } break; case JOYPAD_BUTTON: { - str+= "Event: JoypadButton "; - str=str+"Pressed: "+itos(joy_button.pressed)+" Index: " +itos(joy_button.button_index)+" pressure "+rtos(joy_button.pressure); + str += "Event: JoypadButton "; + str = str + "Pressed: " + itos(joy_button.pressed) + " Index: " + itos(joy_button.button_index) + " pressure " + rtos(joy_button.pressure); return str; } break; case SCREEN_TOUCH: { - str+= "Event: ScreenTouch "; - str=str+"Pressed: "+itos(screen_touch.pressed)+" Index: " +itos(screen_touch.index)+" pos "+rtos(screen_touch.x)+","+rtos(screen_touch.y); + str += "Event: ScreenTouch "; + str = str + "Pressed: " + itos(screen_touch.pressed) + " Index: " + itos(screen_touch.index) + " pos " + rtos(screen_touch.x) + "," + rtos(screen_touch.y); return str; } break; case SCREEN_DRAG: { - str+= "Event: ScreenDrag "; - str=str+" Index: " +itos(screen_drag.index)+" pos "+rtos(screen_drag.x)+","+rtos(screen_drag.y); + str += "Event: ScreenDrag "; + str = str + " Index: " + itos(screen_drag.index) + " pos " + rtos(screen_drag.x) + "," + rtos(screen_drag.y); return str; } break; case ACTION: { - str+= "Event: Action: "+InputMap::get_singleton()->get_action_from_id(action.action)+" Pressed: "+itos(action.pressed); + str += "Event: Action: " + InputMap::get_singleton()->get_action_from_id(action.action) + " Pressed: " + itos(action.pressed); return str; } break; - } return ""; } -void InputEvent::set_as_action(const String& p_action, bool p_pressed) { +void InputEvent::set_as_action(const String &p_action, bool p_pressed) { - type=ACTION; - action.action=InputMap::get_singleton()->get_action_id(p_action); - action.pressed=p_pressed; + type = ACTION; + action.action = InputMap::get_singleton()->get_action_id(p_action); + action.pressed = p_pressed; } bool InputEvent::is_pressed() const { - switch(type) { + switch (type) { case KEY: return key.pressed; case MOUSE_BUTTON: return mouse_button.pressed; @@ -218,93 +217,89 @@ bool InputEvent::is_pressed() const { bool InputEvent::is_echo() const { - return (type==KEY && key.echo); + return (type == KEY && key.echo); } -bool InputEvent::is_action(const String& p_action) const { +bool InputEvent::is_action(const String &p_action) const { - return InputMap::get_singleton()->event_is_action(*this,p_action); + return InputMap::get_singleton()->event_is_action(*this, p_action); } -bool InputEvent::is_action_pressed(const String& p_action) const { +bool InputEvent::is_action_pressed(const String &p_action) const { return is_action(p_action) && is_pressed() && !is_echo(); } -bool InputEvent::is_action_released(const String& p_action) const { +bool InputEvent::is_action_released(const String &p_action) const { return is_action(p_action) && !is_pressed(); } uint32_t InputEventKey::get_scancode_with_modifiers() const { - uint32_t sc=scancode; + uint32_t sc = scancode; if (mod.control) - sc|=KEY_MASK_CTRL; + sc |= KEY_MASK_CTRL; if (mod.alt) - sc|=KEY_MASK_ALT; + sc |= KEY_MASK_ALT; if (mod.shift) - sc|=KEY_MASK_SHIFT; + sc |= KEY_MASK_SHIFT; if (mod.meta) - sc|=KEY_MASK_META; + sc |= KEY_MASK_META; return sc; - } -InputEvent InputEvent::xform_by(const Transform2D& p_xform) const { - +InputEvent InputEvent::xform_by(const Transform2D &p_xform) const { - InputEvent ev=*this; + InputEvent ev = *this; - switch(ev.type) { + switch (ev.type) { case InputEvent::MOUSE_BUTTON: { - Vector2 g = p_xform.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y)); - Vector2 l = p_xform.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y)); - ev.mouse_button.x=l.x; - ev.mouse_button.y=l.y; - ev.mouse_button.global_x=g.x; - ev.mouse_button.global_y=g.y; + Vector2 g = p_xform.xform(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y)); + Vector2 l = p_xform.xform(Vector2(ev.mouse_button.x, ev.mouse_button.y)); + ev.mouse_button.x = l.x; + ev.mouse_button.y = l.y; + ev.mouse_button.global_x = g.x; + ev.mouse_button.global_y = g.y; } break; case InputEvent::MOUSE_MOTION: { - Vector2 g = p_xform.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y)); - Vector2 l = p_xform.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y)); - Vector2 r = p_xform.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y)); - Vector2 s = p_xform.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_y)); - ev.mouse_motion.x=l.x; - ev.mouse_motion.y=l.y; - ev.mouse_motion.global_x=g.x; - ev.mouse_motion.global_y=g.y; - ev.mouse_motion.relative_x=r.x; - ev.mouse_motion.relative_y=r.y; - ev.mouse_motion.speed_x=s.x; - ev.mouse_motion.speed_y=s.y; + Vector2 g = p_xform.xform(Vector2(ev.mouse_motion.global_x, ev.mouse_motion.global_y)); + Vector2 l = p_xform.xform(Vector2(ev.mouse_motion.x, ev.mouse_motion.y)); + Vector2 r = p_xform.basis_xform(Vector2(ev.mouse_motion.relative_x, ev.mouse_motion.relative_y)); + Vector2 s = p_xform.basis_xform(Vector2(ev.mouse_motion.speed_x, ev.mouse_motion.speed_y)); + ev.mouse_motion.x = l.x; + ev.mouse_motion.y = l.y; + ev.mouse_motion.global_x = g.x; + ev.mouse_motion.global_y = g.y; + ev.mouse_motion.relative_x = r.x; + ev.mouse_motion.relative_y = r.y; + ev.mouse_motion.speed_x = s.x; + ev.mouse_motion.speed_y = s.y; } break; case InputEvent::SCREEN_TOUCH: { - - Vector2 t = p_xform.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y)); - ev.screen_touch.x=t.x; - ev.screen_touch.y=t.y; + Vector2 t = p_xform.xform(Vector2(ev.screen_touch.x, ev.screen_touch.y)); + ev.screen_touch.x = t.x; + ev.screen_touch.y = t.y; } break; case InputEvent::SCREEN_DRAG: { - - Vector2 t = p_xform.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y)); - Vector2 r = p_xform.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y)); - Vector2 s = p_xform.basis_xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y)); - ev.screen_drag.x=t.x; - ev.screen_drag.y=t.y; - ev.screen_drag.relative_x=r.x; - ev.screen_drag.relative_y=r.y; - ev.screen_drag.speed_x=s.x; - ev.screen_drag.speed_y=s.y; + Vector2 t = p_xform.xform(Vector2(ev.screen_drag.x, ev.screen_drag.y)); + Vector2 r = p_xform.basis_xform(Vector2(ev.screen_drag.relative_x, ev.screen_drag.relative_y)); + Vector2 s = p_xform.basis_xform(Vector2(ev.screen_drag.speed_x, ev.screen_drag.speed_y)); + ev.screen_drag.x = t.x; + ev.screen_drag.y = t.y; + ev.screen_drag.relative_x = r.x; + ev.screen_drag.relative_y = r.y; + ev.screen_drag.speed_x = s.x; + ev.screen_drag.speed_y = s.y; } break; } diff --git a/core/os/input_event.h b/core/os/input_event.h index 1af4ef20c2..fd3f8c4cec 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -29,33 +29,30 @@ #ifndef INPUT_EVENT_H #define INPUT_EVENT_H - -#include "typedefs.h" +#include "math_2d.h" #include "os/copymem.h" +#include "typedefs.h" #include "ustring.h" -#include "math_2d.h" /** @author Juan Linietsky <reduzio@gmail.com> */ - - /** * Input Event classes. These are used in the main loop. * The events are pretty obvious. */ enum { - BUTTON_LEFT=1, - BUTTON_RIGHT=2, - BUTTON_MIDDLE=3, - BUTTON_WHEEL_UP=4, - BUTTON_WHEEL_DOWN=5, - BUTTON_WHEEL_LEFT=6, - BUTTON_WHEEL_RIGHT=7, - BUTTON_MASK_LEFT=(1<<(BUTTON_LEFT-1)), - BUTTON_MASK_RIGHT=(1<<(BUTTON_RIGHT-1)), - BUTTON_MASK_MIDDLE=(1<<(BUTTON_MIDDLE-1)), + BUTTON_LEFT = 1, + BUTTON_RIGHT = 2, + BUTTON_MIDDLE = 3, + BUTTON_WHEEL_UP = 4, + BUTTON_WHEEL_DOWN = 5, + BUTTON_WHEEL_LEFT = 6, + BUTTON_WHEEL_RIGHT = 7, + BUTTON_MASK_LEFT = (1 << (BUTTON_LEFT - 1)), + BUTTON_MASK_RIGHT = (1 << (BUTTON_RIGHT - 1)), + BUTTON_MASK_MIDDLE = (1 << (BUTTON_MIDDLE - 1)), }; @@ -99,20 +96,20 @@ enum { JOY_SNES_Y = JOY_BUTTON_2, JOY_SNES_X = JOY_BUTTON_3, - JOY_SONY_CIRCLE=JOY_SNES_A, - JOY_SONY_X=JOY_SNES_B, - JOY_SONY_SQUARE=JOY_SNES_Y, - JOY_SONY_TRIANGLE=JOY_SNES_X, + JOY_SONY_CIRCLE = JOY_SNES_A, + JOY_SONY_X = JOY_SNES_B, + JOY_SONY_SQUARE = JOY_SNES_Y, + JOY_SONY_TRIANGLE = JOY_SNES_X, - JOY_SEGA_B=JOY_SNES_A, - JOY_SEGA_A=JOY_SNES_B, - JOY_SEGA_X=JOY_SNES_Y, - JOY_SEGA_Y=JOY_SNES_X, + JOY_SEGA_B = JOY_SNES_A, + JOY_SEGA_A = JOY_SNES_B, + JOY_SEGA_X = JOY_SNES_Y, + JOY_SEGA_Y = JOY_SNES_X, - JOY_XBOX_B=JOY_SEGA_B, - JOY_XBOX_A=JOY_SEGA_A, - JOY_XBOX_X=JOY_SEGA_X, - JOY_XBOX_Y=JOY_SEGA_Y, + JOY_XBOX_B = JOY_SEGA_B, + JOY_XBOX_A = JOY_SEGA_A, + JOY_XBOX_X = JOY_SEGA_X, + JOY_XBOX_Y = JOY_SEGA_Y, JOY_DS_A = JOY_SNES_A, JOY_DS_B = JOY_SNES_B, @@ -127,15 +124,15 @@ enum { // end of history - JOY_AXIS_0=0, - JOY_AXIS_1=1, - JOY_AXIS_2=2, - JOY_AXIS_3=3, - JOY_AXIS_4=4, - JOY_AXIS_5=5, - JOY_AXIS_6=6, - JOY_AXIS_7=7, - JOY_AXIS_MAX=8, + JOY_AXIS_0 = 0, + JOY_AXIS_1 = 1, + JOY_AXIS_2 = 2, + JOY_AXIS_3 = 3, + JOY_AXIS_4 = 4, + JOY_AXIS_5 = 5, + JOY_AXIS_6 = 6, + JOY_AXIS_7 = 7, + JOY_AXIS_MAX = 8, JOY_ANALOG_0_X = JOY_AXIS_0, JOY_ANALOG_0_Y = JOY_AXIS_1, @@ -150,7 +147,6 @@ enum { JOY_ANALOG_R2 = JOY_AXIS_7, }; - /** * Input Modifier Status * for keyboard/mouse events. @@ -161,32 +157,27 @@ struct InputModifierState { bool alt; #ifdef APPLE_STYLE_KEYS union { - bool command; - bool meta; //< windows/mac key + bool command; + bool meta; //< windows/mac key }; bool control; #else union { - bool command; //< windows/mac key - bool control; + bool command; //< windows/mac key + bool control; }; bool meta; //< windows/mac key #endif - bool operator==(const InputModifierState& rvalue) const { + bool operator==(const InputModifierState &rvalue) const { - return ( (shift==rvalue.shift) && (alt==rvalue.alt) && (control==rvalue.control) && (meta==rvalue.meta)); + return ((shift == rvalue.shift) && (alt == rvalue.alt) && (control == rvalue.control) && (meta == rvalue.meta)); } }; - - - - - -struct InputEventKey { +struct InputEventKey { InputModifierState mod; @@ -200,66 +191,61 @@ struct InputEventKey { bool echo; /// true if this is an echo key }; - -struct InputEventMouse { +struct InputEventMouse { InputModifierState mod; int button_mask; - float x,y; - float global_x,global_y; + float x, y; + float global_x, global_y; int pointer_index; }; struct InputEventMouseButton : public InputEventMouse { - int button_index; bool pressed; //otherwise released bool doubleclick; //last even less than doubleclick time - }; struct InputEventMouseMotion : public InputEventMouse { - float relative_x,relative_y; - float speed_x,speed_y; + float relative_x, relative_y; + float speed_x, speed_y; }; -struct InputEventJoypadMotion { +struct InputEventJoypadMotion { int axis; ///< Joypad axis float axis_value; ///< -1 to 1 }; -struct InputEventJoypadButton { +struct InputEventJoypadButton { int button_index; bool pressed; float pressure; //0 to 1 }; -struct InputEventScreenTouch { +struct InputEventScreenTouch { int index; - float x,y; + float x, y; bool pressed; }; -struct InputEventScreenDrag { +struct InputEventScreenDrag { int index; - float x,y; - float relative_x,relative_y; - float speed_x,speed_y; + float x, y; + float relative_x, relative_y; + float speed_x, speed_y; }; -struct InputEventAction { +struct InputEventAction { int action; bool pressed; }; - - struct InputEvent { enum Type { @@ -291,18 +277,16 @@ struct InputEvent { }; bool is_pressed() const; - bool is_action(const String& p_action) const; - bool is_action_pressed(const String& p_action) const; - bool is_action_released(const String& p_action) const; + bool is_action(const String &p_action) const; + bool is_action_pressed(const String &p_action) const; + bool is_action_released(const String &p_action) const; bool is_echo() const; - void set_as_action(const String& p_action, bool p_pressed); + void set_as_action(const String &p_action, bool p_pressed); - - InputEvent xform_by(const Transform2D& p_xform) const; + InputEvent xform_by(const Transform2D &p_xform) const; bool operator==(const InputEvent &p_event) const; operator String() const; - InputEvent() { zeromem(this,sizeof(InputEvent)); } + InputEvent() { zeromem(this, sizeof(InputEvent)); } }; - #endif diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index 40fa86d09f..a5f8bfa144 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -34,9 +34,9 @@ struct _KeyCodeText { const char *text; }; -static const _KeyCodeText _keycodes[]={ +static const _KeyCodeText _keycodes[] = { - /* clang-format off */ + /* clang-format off */ {KEY_ESCAPE ,"Escape"}, {KEY_TAB ,"Tab"}, {KEY_BACKTAB ,"BackTab"}, @@ -283,25 +283,105 @@ static const _KeyCodeText _keycodes[]={ {KEY_DIVISION ,"Division"}, {KEY_YDIAERESIS ,"Ydiaeresis"}, {0 ,0} - /* clang-format on */ + /* clang-format on */ }; bool keycode_has_unicode(uint32_t p_keycode) { - - switch(p_keycode) { - - case KEY_ESCAPE: case KEY_TAB: case KEY_BACKTAB: case KEY_BACKSPACE: case KEY_RETURN: case KEY_ENTER: case KEY_INSERT: case KEY_DELETE: case KEY_PAUSE: - case KEY_PRINT: case KEY_SYSREQ: case KEY_CLEAR: case KEY_HOME: case KEY_END: case KEY_LEFT: case KEY_UP: case KEY_RIGHT: case KEY_DOWN: case KEY_PAGEUP: - case KEY_PAGEDOWN: case KEY_SHIFT: case KEY_CONTROL: case KEY_META: case KEY_ALT: case KEY_CAPSLOCK: case KEY_NUMLOCK: case KEY_SCROLLLOCK: case KEY_F1: - case KEY_F2: case KEY_F3: case KEY_F4: case KEY_F5: case KEY_F6: case KEY_F7: case KEY_F8: case KEY_F9: case KEY_F10: case KEY_F11: case KEY_F12: case KEY_F13: case KEY_F14: - case KEY_F15: case KEY_F16: case KEY_KP_ENTER: case KEY_SUPER_L: case KEY_SUPER_R: case KEY_MENU: case KEY_HYPER_L: case KEY_HYPER_R: case KEY_HELP: - case KEY_DIRECTION_L: case KEY_DIRECTION_R: case KEY_BACK: case KEY_FORWARD: case KEY_STOP: case KEY_REFRESH: case KEY_VOLUMEDOWN: case KEY_VOLUMEMUTE: - case KEY_VOLUMEUP: case KEY_BASSBOOST: case KEY_BASSUP: case KEY_BASSDOWN: case KEY_TREBLEUP: case KEY_TREBLEDOWN: case KEY_MEDIAPLAY: case KEY_MEDIASTOP: - case KEY_MEDIAPREVIOUS: case KEY_MEDIANEXT: case KEY_MEDIARECORD: case KEY_HOMEPAGE: case KEY_FAVORITES: case KEY_SEARCH: case KEY_STANDBY: - case KEY_OPENURL: case KEY_LAUNCHMAIL: case KEY_LAUNCHMEDIA: case KEY_LAUNCH0: case KEY_LAUNCH1: case KEY_LAUNCH2: case KEY_LAUNCH3: case KEY_LAUNCH4: - case KEY_LAUNCH5: case KEY_LAUNCH6: case KEY_LAUNCH7: case KEY_LAUNCH8: case KEY_LAUNCH9: case KEY_LAUNCHA: case KEY_LAUNCHB: case KEY_LAUNCHC: case KEY_LAUNCHD: - case KEY_LAUNCHE: case KEY_LAUNCHF: + switch (p_keycode) { + + case KEY_ESCAPE: + case KEY_TAB: + case KEY_BACKTAB: + case KEY_BACKSPACE: + case KEY_RETURN: + case KEY_ENTER: + case KEY_INSERT: + case KEY_DELETE: + case KEY_PAUSE: + case KEY_PRINT: + case KEY_SYSREQ: + case KEY_CLEAR: + case KEY_HOME: + case KEY_END: + case KEY_LEFT: + case KEY_UP: + case KEY_RIGHT: + case KEY_DOWN: + case KEY_PAGEUP: + case KEY_PAGEDOWN: + case KEY_SHIFT: + case KEY_CONTROL: + case KEY_META: + case KEY_ALT: + case KEY_CAPSLOCK: + case KEY_NUMLOCK: + case KEY_SCROLLLOCK: + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + case KEY_F11: + case KEY_F12: + case KEY_F13: + case KEY_F14: + case KEY_F15: + case KEY_F16: + case KEY_KP_ENTER: + case KEY_SUPER_L: + case KEY_SUPER_R: + case KEY_MENU: + case KEY_HYPER_L: + case KEY_HYPER_R: + case KEY_HELP: + case KEY_DIRECTION_L: + case KEY_DIRECTION_R: + case KEY_BACK: + case KEY_FORWARD: + case KEY_STOP: + case KEY_REFRESH: + case KEY_VOLUMEDOWN: + case KEY_VOLUMEMUTE: + case KEY_VOLUMEUP: + case KEY_BASSBOOST: + case KEY_BASSUP: + case KEY_BASSDOWN: + case KEY_TREBLEUP: + case KEY_TREBLEDOWN: + case KEY_MEDIAPLAY: + case KEY_MEDIASTOP: + case KEY_MEDIAPREVIOUS: + case KEY_MEDIANEXT: + case KEY_MEDIARECORD: + case KEY_HOMEPAGE: + case KEY_FAVORITES: + case KEY_SEARCH: + case KEY_STANDBY: + case KEY_OPENURL: + case KEY_LAUNCHMAIL: + case KEY_LAUNCHMEDIA: + case KEY_LAUNCH0: + case KEY_LAUNCH1: + case KEY_LAUNCH2: + case KEY_LAUNCH3: + case KEY_LAUNCH4: + case KEY_LAUNCH5: + case KEY_LAUNCH6: + case KEY_LAUNCH7: + case KEY_LAUNCH8: + case KEY_LAUNCH9: + case KEY_LAUNCHA: + case KEY_LAUNCHB: + case KEY_LAUNCHC: + case KEY_LAUNCHD: + case KEY_LAUNCHE: + case KEY_LAUNCHF: return false; } @@ -311,133 +391,127 @@ bool keycode_has_unicode(uint32_t p_keycode) { String keycode_get_string(uint32_t p_code) { String codestr; - if (p_code&KEY_MASK_SHIFT) - codestr+="Shift+"; - if (p_code&KEY_MASK_ALT) - codestr+="Alt+"; - if (p_code&KEY_MASK_CTRL) - codestr+="Ctrl+"; - if (p_code&KEY_MASK_META) - codestr+="Meta+"; + if (p_code & KEY_MASK_SHIFT) + codestr += "Shift+"; + if (p_code & KEY_MASK_ALT) + codestr += "Alt+"; + if (p_code & KEY_MASK_CTRL) + codestr += "Ctrl+"; + if (p_code & KEY_MASK_META) + codestr += "Meta+"; - p_code&=KEY_CODE_MASK; + p_code &= KEY_CODE_MASK; - const _KeyCodeText *kct =&_keycodes[0]; + const _KeyCodeText *kct = &_keycodes[0]; - while(kct->text) { + while (kct->text) { - if (kct->code==(int)p_code) { + if (kct->code == (int)p_code) { - codestr+=kct->text; + codestr += kct->text; return codestr; } kct++; } - codestr+=String::chr(p_code); + codestr += String::chr(p_code); return codestr; - } -int find_keycode(const String& p_code) { +int find_keycode(const String &p_code) { - const _KeyCodeText *kct =&_keycodes[0]; + const _KeyCodeText *kct = &_keycodes[0]; - while(kct->text) { + while (kct->text) { - if (p_code.nocasecmp_to(kct->text)==0) { + if (p_code.nocasecmp_to(kct->text) == 0) { return kct->code; - } kct++; } return 0; - } - - - struct _KeyCodeReplace { int from; int to; }; -static const _KeyCodeReplace _keycode_replace_qwertz[]={ -{KEY_Y,KEY_Z}, -{KEY_Z,KEY_Y}, -{0,0} +static const _KeyCodeReplace _keycode_replace_qwertz[] = { + { KEY_Y, KEY_Z }, + { KEY_Z, KEY_Y }, + { 0, 0 } }; -static const _KeyCodeReplace _keycode_replace_azerty[]={ -{KEY_W,KEY_Z}, -{KEY_Z,KEY_W}, -{KEY_A,KEY_Q}, -{KEY_Q,KEY_A}, -{KEY_SEMICOLON,KEY_M}, -{KEY_M,KEY_SEMICOLON}, -{0,0} +static const _KeyCodeReplace _keycode_replace_azerty[] = { + { KEY_W, KEY_Z }, + { KEY_Z, KEY_W }, + { KEY_A, KEY_Q }, + { KEY_Q, KEY_A }, + { KEY_SEMICOLON, KEY_M }, + { KEY_M, KEY_SEMICOLON }, + { 0, 0 } }; -static const _KeyCodeReplace _keycode_replace_qzerty[]={ -{KEY_W,KEY_Z}, -{KEY_Z,KEY_W}, -{KEY_SEMICOLON,KEY_M}, -{KEY_M,KEY_SEMICOLON}, -{0,0} +static const _KeyCodeReplace _keycode_replace_qzerty[] = { + { KEY_W, KEY_Z }, + { KEY_Z, KEY_W }, + { KEY_SEMICOLON, KEY_M }, + { KEY_M, KEY_SEMICOLON }, + { 0, 0 } }; -static const _KeyCodeReplace _keycode_replace_dvorak[]={ -{KEY_UNDERSCORE,KEY_BRACELEFT}, -{KEY_EQUAL,KEY_BRACERIGHT}, -{KEY_Q,KEY_APOSTROPHE}, -{KEY_W,KEY_COMMA}, -{KEY_E,KEY_PERIOD}, -{KEY_R,KEY_P}, -{KEY_T,KEY_Y}, -{KEY_Y,KEY_F}, -{KEY_U,KEY_G}, -{KEY_I,KEY_C}, -{KEY_O,KEY_R}, -{KEY_P,KEY_L}, -{KEY_BRACELEFT,KEY_SLASH}, -{KEY_BRACERIGHT,KEY_EQUAL}, -{KEY_A,KEY_A}, -{KEY_S,KEY_O}, -{KEY_D,KEY_E}, -{KEY_F,KEY_U}, -{KEY_G,KEY_I}, -{KEY_H,KEY_D}, -{KEY_J,KEY_H}, -{KEY_K,KEY_T}, -{KEY_L,KEY_N}, -{KEY_SEMICOLON,KEY_S}, -{KEY_APOSTROPHE,KEY_UNDERSCORE}, -{KEY_Z,KEY_SEMICOLON}, -{KEY_X,KEY_Q}, -{KEY_C,KEY_J}, -{KEY_V,KEY_K}, -{KEY_B,KEY_X}, -{KEY_N,KEY_B}, -{KEY_M,KEY_M}, -{KEY_COMMA,KEY_W}, -{KEY_PERIOD,KEY_V}, -{KEY_SLASH,KEY_Z}, -{0,0} +static const _KeyCodeReplace _keycode_replace_dvorak[] = { + { KEY_UNDERSCORE, KEY_BRACELEFT }, + { KEY_EQUAL, KEY_BRACERIGHT }, + { KEY_Q, KEY_APOSTROPHE }, + { KEY_W, KEY_COMMA }, + { KEY_E, KEY_PERIOD }, + { KEY_R, KEY_P }, + { KEY_T, KEY_Y }, + { KEY_Y, KEY_F }, + { KEY_U, KEY_G }, + { KEY_I, KEY_C }, + { KEY_O, KEY_R }, + { KEY_P, KEY_L }, + { KEY_BRACELEFT, KEY_SLASH }, + { KEY_BRACERIGHT, KEY_EQUAL }, + { KEY_A, KEY_A }, + { KEY_S, KEY_O }, + { KEY_D, KEY_E }, + { KEY_F, KEY_U }, + { KEY_G, KEY_I }, + { KEY_H, KEY_D }, + { KEY_J, KEY_H }, + { KEY_K, KEY_T }, + { KEY_L, KEY_N }, + { KEY_SEMICOLON, KEY_S }, + { KEY_APOSTROPHE, KEY_UNDERSCORE }, + { KEY_Z, KEY_SEMICOLON }, + { KEY_X, KEY_Q }, + { KEY_C, KEY_J }, + { KEY_V, KEY_K }, + { KEY_B, KEY_X }, + { KEY_N, KEY_B }, + { KEY_M, KEY_M }, + { KEY_COMMA, KEY_W }, + { KEY_PERIOD, KEY_V }, + { KEY_SLASH, KEY_Z }, + { 0, 0 } }; -static const _KeyCodeReplace _keycode_replace_neo[]={ -{0,0} +static const _KeyCodeReplace _keycode_replace_neo[] = { + { 0, 0 } }; int keycode_get_count() { - const _KeyCodeText *kct =&_keycodes[0]; + const _KeyCodeText *kct = &_keycodes[0]; - int count=0; - while(kct->text) { + int count = 0; + while (kct->text) { count++; kct++; @@ -449,22 +523,21 @@ int keycode_get_value_by_index(int p_index) { return _keycodes[p_index].code; } -const char* keycode_get_name_by_index(int p_index) { +const char *keycode_get_name_by_index(int p_index) { return _keycodes[p_index].text; } - int latin_keyboard_keycode_convert(int p_keycode) { - const _KeyCodeReplace *kcr=NULL; - switch(OS::get_singleton()->get_latin_keyboard_variant()) { + const _KeyCodeReplace *kcr = NULL; + switch (OS::get_singleton()->get_latin_keyboard_variant()) { case OS::LATIN_KEYBOARD_QWERTY: return p_keycode; break; - case OS::LATIN_KEYBOARD_QWERTZ: kcr=_keycode_replace_qwertz; break; - case OS::LATIN_KEYBOARD_AZERTY: kcr=_keycode_replace_azerty; break; - case OS::LATIN_KEYBOARD_QZERTY: kcr=_keycode_replace_qzerty; break; - case OS::LATIN_KEYBOARD_DVORAK: kcr=_keycode_replace_dvorak; break; - case OS::LATIN_KEYBOARD_NEO: kcr=_keycode_replace_neo; break; + case OS::LATIN_KEYBOARD_QWERTZ: kcr = _keycode_replace_qwertz; break; + case OS::LATIN_KEYBOARD_AZERTY: kcr = _keycode_replace_azerty; break; + case OS::LATIN_KEYBOARD_QZERTY: kcr = _keycode_replace_qzerty; break; + case OS::LATIN_KEYBOARD_DVORAK: kcr = _keycode_replace_dvorak; break; + case OS::LATIN_KEYBOARD_NEO: kcr = _keycode_replace_neo; break; default: return p_keycode; } @@ -472,8 +545,8 @@ int latin_keyboard_keycode_convert(int p_keycode) { return p_keycode; } - while(kcr->from) { - if (kcr->from==p_keycode) + while (kcr->from) { + if (kcr->from == p_keycode) return kcr->to; kcr++; } diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 1357cc8b8e..1f6bc77334 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -47,290 +47,288 @@ modifiers. This way everything (char/keycode) can fit nicely in one 32 bits unsigned integer. */ enum { - SPKEY = (1<<24) + SPKEY = (1 << 24) }; enum KeyList { -/* CURSOR/FUNCTION/BROWSER/MULTIMEDIA/MISC KEYS */ - KEY_ESCAPE=SPKEY | 0x01, - KEY_TAB=SPKEY | 0x02, - KEY_BACKTAB=SPKEY | 0x03, - KEY_BACKSPACE=SPKEY | 0x04, - KEY_RETURN=SPKEY | 0x05, - KEY_ENTER=SPKEY | 0x06, - KEY_INSERT=SPKEY | 0x07, - KEY_DELETE=SPKEY | 0x08, - KEY_PAUSE=SPKEY | 0x09, - KEY_PRINT=SPKEY | 0x0A, - KEY_SYSREQ=SPKEY | 0x0B, - KEY_CLEAR=SPKEY | 0x0C, - KEY_HOME=SPKEY | 0x0D, - KEY_END=SPKEY | 0x0E, - KEY_LEFT=SPKEY | 0x0F, - KEY_UP=SPKEY | 0x10, - KEY_RIGHT=SPKEY | 0x11, - KEY_DOWN=SPKEY | 0x12, - KEY_PAGEUP=SPKEY | 0x13, - KEY_PAGEDOWN=SPKEY | 0x14, - KEY_SHIFT=SPKEY | 0x15, - KEY_CONTROL=SPKEY | 0x16, - KEY_META=SPKEY | 0x17, - KEY_ALT=SPKEY | 0x18, - KEY_CAPSLOCK=SPKEY | 0x19, - KEY_NUMLOCK=SPKEY | 0x1A, - KEY_SCROLLLOCK=SPKEY | 0x1B, - KEY_F1=SPKEY | 0x1C, - KEY_F2=SPKEY | 0x1D, - KEY_F3=SPKEY | 0x1E, - KEY_F4=SPKEY | 0x1F, - KEY_F5=SPKEY | 0x20, - KEY_F6=SPKEY | 0x21, - KEY_F7=SPKEY | 0x22, - KEY_F8=SPKEY | 0x23, - KEY_F9=SPKEY | 0x24, - KEY_F10=SPKEY | 0x25, - KEY_F11=SPKEY | 0x26, - KEY_F12=SPKEY | 0x27, - KEY_F13=SPKEY | 0x28, - KEY_F14=SPKEY | 0x29, - KEY_F15=SPKEY | 0x2A, - KEY_F16=SPKEY | 0x2B, - KEY_KP_ENTER=SPKEY | 0x80, - KEY_KP_MULTIPLY=SPKEY | 0x81, - KEY_KP_DIVIDE=SPKEY | 0x82, - KEY_KP_SUBTRACT=SPKEY | 0x83, - KEY_KP_PERIOD=SPKEY | 0x84, - KEY_KP_ADD=SPKEY | 0x85, - KEY_KP_0=SPKEY | 0x86, - KEY_KP_1=SPKEY | 0x87, - KEY_KP_2=SPKEY | 0x88, - KEY_KP_3=SPKEY | 0x89, - KEY_KP_4=SPKEY | 0x8A, - KEY_KP_5=SPKEY | 0x8B, - KEY_KP_6=SPKEY | 0x8C, - KEY_KP_7=SPKEY | 0x8D, - KEY_KP_8=SPKEY | 0x8E, - KEY_KP_9=SPKEY | 0x8F, - KEY_SUPER_L=SPKEY | 0x2C, - KEY_SUPER_R=SPKEY | 0x2D, - KEY_MENU=SPKEY | 0x2E, - KEY_HYPER_L=SPKEY | 0x2F, - KEY_HYPER_R=SPKEY | 0x30, - KEY_HELP=SPKEY | 0x31, - KEY_DIRECTION_L=SPKEY | 0x32, - KEY_DIRECTION_R=SPKEY | 0x33, - KEY_BACK=SPKEY | 0x40, - KEY_FORWARD=SPKEY | 0x41, - KEY_STOP=SPKEY | 0x42, - KEY_REFRESH=SPKEY | 0x43, - KEY_VOLUMEDOWN=SPKEY | 0x44, - KEY_VOLUMEMUTE=SPKEY | 0x45, - KEY_VOLUMEUP=SPKEY | 0x46, - KEY_BASSBOOST=SPKEY | 0x47, - KEY_BASSUP=SPKEY | 0x48, - KEY_BASSDOWN=SPKEY | 0x49, - KEY_TREBLEUP=SPKEY | 0x4A, - KEY_TREBLEDOWN=SPKEY | 0x4B, - KEY_MEDIAPLAY=SPKEY | 0x4C, - KEY_MEDIASTOP=SPKEY | 0x4D, - KEY_MEDIAPREVIOUS=SPKEY | 0x4E, - KEY_MEDIANEXT=SPKEY | 0x4F, - KEY_MEDIARECORD= SPKEY | 0x50, - KEY_HOMEPAGE=SPKEY | 0x51, - KEY_FAVORITES=SPKEY | 0x52, - KEY_SEARCH=SPKEY | 0x53, - KEY_STANDBY=SPKEY | 0x54, - KEY_OPENURL=SPKEY | 0x55, - KEY_LAUNCHMAIL=SPKEY | 0x56, - KEY_LAUNCHMEDIA=SPKEY | 0x57, - KEY_LAUNCH0=SPKEY | 0x58, - KEY_LAUNCH1=SPKEY | 0x59, - KEY_LAUNCH2=SPKEY | 0x5A, - KEY_LAUNCH3=SPKEY | 0x5B, - KEY_LAUNCH4=SPKEY | 0x5C, - KEY_LAUNCH5=SPKEY | 0x5D, - KEY_LAUNCH6=SPKEY | 0x5E, - KEY_LAUNCH7=SPKEY | 0x5F, - KEY_LAUNCH8=SPKEY | 0x60, - KEY_LAUNCH9=SPKEY | 0x61, - KEY_LAUNCHA=SPKEY | 0x62, - KEY_LAUNCHB=SPKEY | 0x63, - KEY_LAUNCHC=SPKEY | 0x64, - KEY_LAUNCHD=SPKEY | 0x65, - KEY_LAUNCHE=SPKEY | 0x66, - KEY_LAUNCHF=SPKEY | 0x67, + /* CURSOR/FUNCTION/BROWSER/MULTIMEDIA/MISC KEYS */ + KEY_ESCAPE = SPKEY | 0x01, + KEY_TAB = SPKEY | 0x02, + KEY_BACKTAB = SPKEY | 0x03, + KEY_BACKSPACE = SPKEY | 0x04, + KEY_RETURN = SPKEY | 0x05, + KEY_ENTER = SPKEY | 0x06, + KEY_INSERT = SPKEY | 0x07, + KEY_DELETE = SPKEY | 0x08, + KEY_PAUSE = SPKEY | 0x09, + KEY_PRINT = SPKEY | 0x0A, + KEY_SYSREQ = SPKEY | 0x0B, + KEY_CLEAR = SPKEY | 0x0C, + KEY_HOME = SPKEY | 0x0D, + KEY_END = SPKEY | 0x0E, + KEY_LEFT = SPKEY | 0x0F, + KEY_UP = SPKEY | 0x10, + KEY_RIGHT = SPKEY | 0x11, + KEY_DOWN = SPKEY | 0x12, + KEY_PAGEUP = SPKEY | 0x13, + KEY_PAGEDOWN = SPKEY | 0x14, + KEY_SHIFT = SPKEY | 0x15, + KEY_CONTROL = SPKEY | 0x16, + KEY_META = SPKEY | 0x17, + KEY_ALT = SPKEY | 0x18, + KEY_CAPSLOCK = SPKEY | 0x19, + KEY_NUMLOCK = SPKEY | 0x1A, + KEY_SCROLLLOCK = SPKEY | 0x1B, + KEY_F1 = SPKEY | 0x1C, + KEY_F2 = SPKEY | 0x1D, + KEY_F3 = SPKEY | 0x1E, + KEY_F4 = SPKEY | 0x1F, + KEY_F5 = SPKEY | 0x20, + KEY_F6 = SPKEY | 0x21, + KEY_F7 = SPKEY | 0x22, + KEY_F8 = SPKEY | 0x23, + KEY_F9 = SPKEY | 0x24, + KEY_F10 = SPKEY | 0x25, + KEY_F11 = SPKEY | 0x26, + KEY_F12 = SPKEY | 0x27, + KEY_F13 = SPKEY | 0x28, + KEY_F14 = SPKEY | 0x29, + KEY_F15 = SPKEY | 0x2A, + KEY_F16 = SPKEY | 0x2B, + KEY_KP_ENTER = SPKEY | 0x80, + KEY_KP_MULTIPLY = SPKEY | 0x81, + KEY_KP_DIVIDE = SPKEY | 0x82, + KEY_KP_SUBTRACT = SPKEY | 0x83, + KEY_KP_PERIOD = SPKEY | 0x84, + KEY_KP_ADD = SPKEY | 0x85, + KEY_KP_0 = SPKEY | 0x86, + KEY_KP_1 = SPKEY | 0x87, + KEY_KP_2 = SPKEY | 0x88, + KEY_KP_3 = SPKEY | 0x89, + KEY_KP_4 = SPKEY | 0x8A, + KEY_KP_5 = SPKEY | 0x8B, + KEY_KP_6 = SPKEY | 0x8C, + KEY_KP_7 = SPKEY | 0x8D, + KEY_KP_8 = SPKEY | 0x8E, + KEY_KP_9 = SPKEY | 0x8F, + KEY_SUPER_L = SPKEY | 0x2C, + KEY_SUPER_R = SPKEY | 0x2D, + KEY_MENU = SPKEY | 0x2E, + KEY_HYPER_L = SPKEY | 0x2F, + KEY_HYPER_R = SPKEY | 0x30, + KEY_HELP = SPKEY | 0x31, + KEY_DIRECTION_L = SPKEY | 0x32, + KEY_DIRECTION_R = SPKEY | 0x33, + KEY_BACK = SPKEY | 0x40, + KEY_FORWARD = SPKEY | 0x41, + KEY_STOP = SPKEY | 0x42, + KEY_REFRESH = SPKEY | 0x43, + KEY_VOLUMEDOWN = SPKEY | 0x44, + KEY_VOLUMEMUTE = SPKEY | 0x45, + KEY_VOLUMEUP = SPKEY | 0x46, + KEY_BASSBOOST = SPKEY | 0x47, + KEY_BASSUP = SPKEY | 0x48, + KEY_BASSDOWN = SPKEY | 0x49, + KEY_TREBLEUP = SPKEY | 0x4A, + KEY_TREBLEDOWN = SPKEY | 0x4B, + KEY_MEDIAPLAY = SPKEY | 0x4C, + KEY_MEDIASTOP = SPKEY | 0x4D, + KEY_MEDIAPREVIOUS = SPKEY | 0x4E, + KEY_MEDIANEXT = SPKEY | 0x4F, + KEY_MEDIARECORD = SPKEY | 0x50, + KEY_HOMEPAGE = SPKEY | 0x51, + KEY_FAVORITES = SPKEY | 0x52, + KEY_SEARCH = SPKEY | 0x53, + KEY_STANDBY = SPKEY | 0x54, + KEY_OPENURL = SPKEY | 0x55, + KEY_LAUNCHMAIL = SPKEY | 0x56, + KEY_LAUNCHMEDIA = SPKEY | 0x57, + KEY_LAUNCH0 = SPKEY | 0x58, + KEY_LAUNCH1 = SPKEY | 0x59, + KEY_LAUNCH2 = SPKEY | 0x5A, + KEY_LAUNCH3 = SPKEY | 0x5B, + KEY_LAUNCH4 = SPKEY | 0x5C, + KEY_LAUNCH5 = SPKEY | 0x5D, + KEY_LAUNCH6 = SPKEY | 0x5E, + KEY_LAUNCH7 = SPKEY | 0x5F, + KEY_LAUNCH8 = SPKEY | 0x60, + KEY_LAUNCH9 = SPKEY | 0x61, + KEY_LAUNCHA = SPKEY | 0x62, + KEY_LAUNCHB = SPKEY | 0x63, + KEY_LAUNCHC = SPKEY | 0x64, + KEY_LAUNCHD = SPKEY | 0x65, + KEY_LAUNCHE = SPKEY | 0x66, + KEY_LAUNCHF = SPKEY | 0x67, - KEY_UNKNOWN=SPKEY | 0xFFFFFF, + KEY_UNKNOWN = SPKEY | 0xFFFFFF, -/* PRINTABLE LATIN 1 CODES */ + /* PRINTABLE LATIN 1 CODES */ - KEY_SPACE=0x0020, - KEY_EXCLAM=0x0021, - KEY_QUOTEDBL=0x0022, - KEY_NUMBERSIGN=0x0023, - KEY_DOLLAR=0x0024, - KEY_PERCENT=0x0025, - KEY_AMPERSAND=0x0026, - KEY_APOSTROPHE=0x0027, - KEY_PARENLEFT=0x0028, - KEY_PARENRIGHT=0x0029, - KEY_ASTERISK=0x002A, - KEY_PLUS=0x002B, - KEY_COMMA=0x002C, - KEY_MINUS=0x002D, - KEY_PERIOD=0x002E, - KEY_SLASH=0x002F, - KEY_0=0x0030, - KEY_1=0x0031, - KEY_2=0x0032, - KEY_3=0x0033, - KEY_4=0x0034, - KEY_5=0x0035, - KEY_6=0x0036, - KEY_7=0x0037, - KEY_8=0x0038, - KEY_9=0x0039, - KEY_COLON=0x003A, - KEY_SEMICOLON=0x003B, - KEY_LESS=0x003C, - KEY_EQUAL=0x003D, - KEY_GREATER=0x003E, - KEY_QUESTION=0x003F, - KEY_AT=0x0040, - KEY_A=0x0041, - KEY_B=0x0042, - KEY_C=0x0043, - KEY_D=0x0044, - KEY_E=0x0045, - KEY_F=0x0046, - KEY_G=0x0047, - KEY_H=0x0048, - KEY_I=0x0049, - KEY_J=0x004A, - KEY_K=0x004B, - KEY_L=0x004C, - KEY_M=0x004D, - KEY_N=0x004E, - KEY_O=0x004F, - KEY_P=0x0050, - KEY_Q=0x0051, - KEY_R=0x0052, - KEY_S=0x0053, - KEY_T=0x0054, - KEY_U=0x0055, - KEY_V=0x0056, - KEY_W=0x0057, - KEY_X=0x0058, - KEY_Y=0x0059, - KEY_Z=0x005A, - KEY_BRACKETLEFT=0x005B, - KEY_BACKSLASH=0x005C, - KEY_BRACKETRIGHT=0x005D, - KEY_ASCIICIRCUM=0x005E, - KEY_UNDERSCORE=0x005F, - KEY_QUOTELEFT=0x0060, - KEY_BRACELEFT=0x007B, - KEY_BAR=0x007C, - KEY_BRACERIGHT=0x007D, - KEY_ASCIITILDE=0x007E, - KEY_NOBREAKSPACE=0x00A0, - KEY_EXCLAMDOWN=0x00A1, - KEY_CENT=0x00A2, - KEY_STERLING=0x00A3, - KEY_CURRENCY=0x00A4, - KEY_YEN=0x00A5, - KEY_BROKENBAR=0x00A6, - KEY_SECTION=0x00A7, - KEY_DIAERESIS=0x00A8, - KEY_COPYRIGHT=0x00A9, - KEY_ORDFEMININE=0x00AA, - KEY_GUILLEMOTLEFT=0x00AB, - KEY_NOTSIGN=0x00AC, - KEY_HYPHEN=0x00AD, - KEY_REGISTERED=0x00AE, - KEY_MACRON=0x00AF, - KEY_DEGREE=0x00B0, - KEY_PLUSMINUS=0x00B1, - KEY_TWOSUPERIOR=0x00B2, - KEY_THREESUPERIOR=0x00B3, - KEY_ACUTE=0x00B4, - KEY_MU=0x00B5, - KEY_PARAGRAPH=0x00B6, - KEY_PERIODCENTERED=0x00B7, - KEY_CEDILLA=0x00B8, - KEY_ONESUPERIOR=0x00B9, - KEY_MASCULINE=0x00BA, - KEY_GUILLEMOTRIGHT=0x00BB, - KEY_ONEQUARTER=0x00BC, - KEY_ONEHALF=0x00BD, - KEY_THREEQUARTERS=0x00BE, - KEY_QUESTIONDOWN=0x00BF, - KEY_AGRAVE=0x00C0, - KEY_AACUTE=0x00C1, - KEY_ACIRCUMFLEX=0x00C2, - KEY_ATILDE=0x00C3, - KEY_ADIAERESIS=0x00C4, - KEY_ARING=0x00C5, - KEY_AE=0x00C6, - KEY_CCEDILLA=0x00C7, - KEY_EGRAVE=0x00C8, - KEY_EACUTE=0x00C9, - KEY_ECIRCUMFLEX=0x00CA, - KEY_EDIAERESIS=0x00CB, - KEY_IGRAVE=0x00CC, - KEY_IACUTE=0x00CD, - KEY_ICIRCUMFLEX=0x00CE, - KEY_IDIAERESIS=0x00CF, - KEY_ETH=0x00D0, - KEY_NTILDE=0x00D1, - KEY_OGRAVE=0x00D2, - KEY_OACUTE=0x00D3, - KEY_OCIRCUMFLEX=0x00D4, - KEY_OTILDE=0x00D5, - KEY_ODIAERESIS=0x00D6, - KEY_MULTIPLY=0x00D7, - KEY_OOBLIQUE=0x00D8, - KEY_UGRAVE=0x00D9, - KEY_UACUTE=0x00DA, - KEY_UCIRCUMFLEX=0x00DB, - KEY_UDIAERESIS=0x00DC, - KEY_YACUTE=0x00DD, - KEY_THORN=0x00DE, - KEY_SSHARP=0x00DF, - - KEY_DIVISION=0x00F7, - KEY_YDIAERESIS=0x00FF, + KEY_SPACE = 0x0020, + KEY_EXCLAM = 0x0021, + KEY_QUOTEDBL = 0x0022, + KEY_NUMBERSIGN = 0x0023, + KEY_DOLLAR = 0x0024, + KEY_PERCENT = 0x0025, + KEY_AMPERSAND = 0x0026, + KEY_APOSTROPHE = 0x0027, + KEY_PARENLEFT = 0x0028, + KEY_PARENRIGHT = 0x0029, + KEY_ASTERISK = 0x002A, + KEY_PLUS = 0x002B, + KEY_COMMA = 0x002C, + KEY_MINUS = 0x002D, + KEY_PERIOD = 0x002E, + KEY_SLASH = 0x002F, + KEY_0 = 0x0030, + KEY_1 = 0x0031, + KEY_2 = 0x0032, + KEY_3 = 0x0033, + KEY_4 = 0x0034, + KEY_5 = 0x0035, + KEY_6 = 0x0036, + KEY_7 = 0x0037, + KEY_8 = 0x0038, + KEY_9 = 0x0039, + KEY_COLON = 0x003A, + KEY_SEMICOLON = 0x003B, + KEY_LESS = 0x003C, + KEY_EQUAL = 0x003D, + KEY_GREATER = 0x003E, + KEY_QUESTION = 0x003F, + KEY_AT = 0x0040, + KEY_A = 0x0041, + KEY_B = 0x0042, + KEY_C = 0x0043, + KEY_D = 0x0044, + KEY_E = 0x0045, + KEY_F = 0x0046, + KEY_G = 0x0047, + KEY_H = 0x0048, + KEY_I = 0x0049, + KEY_J = 0x004A, + KEY_K = 0x004B, + KEY_L = 0x004C, + KEY_M = 0x004D, + KEY_N = 0x004E, + KEY_O = 0x004F, + KEY_P = 0x0050, + KEY_Q = 0x0051, + KEY_R = 0x0052, + KEY_S = 0x0053, + KEY_T = 0x0054, + KEY_U = 0x0055, + KEY_V = 0x0056, + KEY_W = 0x0057, + KEY_X = 0x0058, + KEY_Y = 0x0059, + KEY_Z = 0x005A, + KEY_BRACKETLEFT = 0x005B, + KEY_BACKSLASH = 0x005C, + KEY_BRACKETRIGHT = 0x005D, + KEY_ASCIICIRCUM = 0x005E, + KEY_UNDERSCORE = 0x005F, + KEY_QUOTELEFT = 0x0060, + KEY_BRACELEFT = 0x007B, + KEY_BAR = 0x007C, + KEY_BRACERIGHT = 0x007D, + KEY_ASCIITILDE = 0x007E, + KEY_NOBREAKSPACE = 0x00A0, + KEY_EXCLAMDOWN = 0x00A1, + KEY_CENT = 0x00A2, + KEY_STERLING = 0x00A3, + KEY_CURRENCY = 0x00A4, + KEY_YEN = 0x00A5, + KEY_BROKENBAR = 0x00A6, + KEY_SECTION = 0x00A7, + KEY_DIAERESIS = 0x00A8, + KEY_COPYRIGHT = 0x00A9, + KEY_ORDFEMININE = 0x00AA, + KEY_GUILLEMOTLEFT = 0x00AB, + KEY_NOTSIGN = 0x00AC, + KEY_HYPHEN = 0x00AD, + KEY_REGISTERED = 0x00AE, + KEY_MACRON = 0x00AF, + KEY_DEGREE = 0x00B0, + KEY_PLUSMINUS = 0x00B1, + KEY_TWOSUPERIOR = 0x00B2, + KEY_THREESUPERIOR = 0x00B3, + KEY_ACUTE = 0x00B4, + KEY_MU = 0x00B5, + KEY_PARAGRAPH = 0x00B6, + KEY_PERIODCENTERED = 0x00B7, + KEY_CEDILLA = 0x00B8, + KEY_ONESUPERIOR = 0x00B9, + KEY_MASCULINE = 0x00BA, + KEY_GUILLEMOTRIGHT = 0x00BB, + KEY_ONEQUARTER = 0x00BC, + KEY_ONEHALF = 0x00BD, + KEY_THREEQUARTERS = 0x00BE, + KEY_QUESTIONDOWN = 0x00BF, + KEY_AGRAVE = 0x00C0, + KEY_AACUTE = 0x00C1, + KEY_ACIRCUMFLEX = 0x00C2, + KEY_ATILDE = 0x00C3, + KEY_ADIAERESIS = 0x00C4, + KEY_ARING = 0x00C5, + KEY_AE = 0x00C6, + KEY_CCEDILLA = 0x00C7, + KEY_EGRAVE = 0x00C8, + KEY_EACUTE = 0x00C9, + KEY_ECIRCUMFLEX = 0x00CA, + KEY_EDIAERESIS = 0x00CB, + KEY_IGRAVE = 0x00CC, + KEY_IACUTE = 0x00CD, + KEY_ICIRCUMFLEX = 0x00CE, + KEY_IDIAERESIS = 0x00CF, + KEY_ETH = 0x00D0, + KEY_NTILDE = 0x00D1, + KEY_OGRAVE = 0x00D2, + KEY_OACUTE = 0x00D3, + KEY_OCIRCUMFLEX = 0x00D4, + KEY_OTILDE = 0x00D5, + KEY_ODIAERESIS = 0x00D6, + KEY_MULTIPLY = 0x00D7, + KEY_OOBLIQUE = 0x00D8, + KEY_UGRAVE = 0x00D9, + KEY_UACUTE = 0x00DA, + KEY_UCIRCUMFLEX = 0x00DB, + KEY_UDIAERESIS = 0x00DC, + KEY_YACUTE = 0x00DD, + KEY_THORN = 0x00DE, + KEY_SSHARP = 0x00DF, + KEY_DIVISION = 0x00F7, + KEY_YDIAERESIS = 0x00FF, }; - enum KeyModifierMask { - KEY_CODE_MASK=((1<<25)-1), ///< Apply this mask to any keycode to remove modifiers. - KEY_MODIFIER_MASK=(0xFF<<24), ///< Apply this mask to isolate modifiers. - KEY_MASK_SHIFT = (1<<25), - KEY_MASK_ALT = (1<<26), - KEY_MASK_META = (1<<27), - KEY_MASK_CTRL = (1<<28), + KEY_CODE_MASK = ((1 << 25) - 1), ///< Apply this mask to any keycode to remove modifiers. + KEY_MODIFIER_MASK = (0xFF << 24), ///< Apply this mask to isolate modifiers. + KEY_MASK_SHIFT = (1 << 25), + KEY_MASK_ALT = (1 << 26), + KEY_MASK_META = (1 << 27), + KEY_MASK_CTRL = (1 << 28), #ifdef APPLE_STYLE_KEYS KEY_MASK_CMD = KEY_MASK_META, #else KEY_MASK_CMD = KEY_MASK_CTRL, #endif - KEY_MASK_KPAD = (1<<29), - KEY_MASK_GROUP_SWITCH = (1<<30) + KEY_MASK_KPAD = (1 << 29), + KEY_MASK_GROUP_SWITCH = (1 << 30) // bit 31 can't be used because variant uses regular 32 bits int as datatype }; String keycode_get_string(uint32_t p_code); bool keycode_has_unicode(uint32_t p_unicode); -int find_keycode(const String& p_code); +int find_keycode(const String &p_code); int keycode_get_count(); int keycode_get_value_by_index(int p_index); -const char* keycode_get_name_by_index(int p_index); +const char *keycode_get_name_by_index(int p_index); int latin_keyboard_keycode_convert(int p_keycode); #endif diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index dcda8e8952..644536d940 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -31,20 +31,20 @@ void MainLoop::_bind_methods() { - ClassDB::bind_method(D_METHOD("input_event","ev"),&MainLoop::input_event); - ClassDB::bind_method(D_METHOD("input_text","text"),&MainLoop::input_text); - ClassDB::bind_method(D_METHOD("init"),&MainLoop::init); - ClassDB::bind_method(D_METHOD("iteration","delta"),&MainLoop::iteration); - ClassDB::bind_method(D_METHOD("idle","delta"),&MainLoop::idle); - ClassDB::bind_method(D_METHOD("finish"),&MainLoop::finish); - - BIND_VMETHOD( MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"ev")) ); - BIND_VMETHOD( MethodInfo("_input_text",PropertyInfo(Variant::STRING,"text")) ); - 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::POOL_STRING_ARRAY,"files"),PropertyInfo(Variant::INT,"screen")) ); - BIND_VMETHOD( MethodInfo("_finalize") ); + ClassDB::bind_method(D_METHOD("input_event", "ev"), &MainLoop::input_event); + ClassDB::bind_method(D_METHOD("input_text", "text"), &MainLoop::input_text); + ClassDB::bind_method(D_METHOD("init"), &MainLoop::init); + ClassDB::bind_method(D_METHOD("iteration", "delta"), &MainLoop::iteration); + ClassDB::bind_method(D_METHOD("idle", "delta"), &MainLoop::idle); + ClassDB::bind_method(D_METHOD("finish"), &MainLoop::finish); + + BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::INPUT_EVENT, "ev"))); + BIND_VMETHOD(MethodInfo("_input_text", PropertyInfo(Variant::STRING, "text"))); + 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::POOL_STRING_ARRAY, "files"), PropertyInfo(Variant::INT, "screen"))); + BIND_VMETHOD(MethodInfo("_finalize")); BIND_CONSTANT(NOTIFICATION_WM_MOUSE_ENTER); BIND_CONSTANT(NOTIFICATION_WM_MOUSE_EXIT); @@ -53,36 +53,29 @@ void MainLoop::_bind_methods() { BIND_CONSTANT(NOTIFICATION_WM_QUIT_REQUEST); BIND_CONSTANT(NOTIFICATION_WM_UNFOCUS_REQUEST); BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING); - }; -void MainLoop::set_init_script(const Ref<Script>& p_init_script) { +void MainLoop::set_init_script(const Ref<Script> &p_init_script) { - init_script=p_init_script; + init_script = p_init_script; } MainLoop::MainLoop() { } - -MainLoop::~MainLoop() -{ +MainLoop::~MainLoop() { } - - -void MainLoop::input_text( const String& p_text ) { +void MainLoop::input_text(const String &p_text) { if (get_script_instance()) - get_script_instance()->call("_input_text",p_text); - + get_script_instance()->call("_input_text", p_text); } -void MainLoop::input_event( const InputEvent& p_event ) { +void MainLoop::input_event(const InputEvent &p_event) { if (get_script_instance()) - get_script_instance()->call("_input_event",p_event); - + get_script_instance()->call("_input_event", p_event); } void MainLoop::init() { @@ -92,30 +85,26 @@ void MainLoop::init() { if (get_script_instance()) get_script_instance()->call("_initialize"); - } bool MainLoop::iteration(float p_time) { if (get_script_instance()) - return get_script_instance()->call("_iteration",p_time); + return get_script_instance()->call("_iteration", p_time); return false; - } bool MainLoop::idle(float p_time) { if (get_script_instance()) - return get_script_instance()->call("_idle",p_time); + return get_script_instance()->call("_idle", p_time); return false; } -void MainLoop::drop_files(const Vector<String>& p_files,int p_from_screen) { - +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); - + get_script_instance()->call("_drop_files", p_files, p_from_screen); } void MainLoop::finish() { @@ -124,7 +113,4 @@ void MainLoop::finish() { get_script_instance()->call("_finalize"); set_script(RefPtr()); //clear script } - - } - diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 456a6be4d3..a33aeb9762 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -37,15 +37,15 @@ */ class MainLoop : public Object { - GDCLASS( MainLoop, Object ); + GDCLASS(MainLoop, Object); OBJ_CATEGORY("Main Loop"); Ref<Script> init_script; + protected: static void _bind_methods(); public: - enum { NOTIFICATION_WM_MOUSE_ENTER = 2, NOTIFICATION_WM_MOUSE_EXIT = 3, @@ -58,22 +58,20 @@ public: NOTIFICATION_TRANSLATION_CHANGED = 10, }; - virtual void input_event( const InputEvent& p_event ); - virtual void input_text( const String& p_text ); + virtual void input_event(const InputEvent &p_event); + virtual void input_text(const String &p_text); virtual void init(); virtual bool iteration(float p_time); virtual bool idle(float p_time); virtual void finish(); - virtual void drop_files(const Vector<String>& p_files,int p_from_screen=0); + virtual void drop_files(const Vector<String> &p_files, int p_from_screen = 0); - void set_init_script(const Ref<Script>& p_init_script); + void set_init_script(const Ref<Script> &p_init_script); MainLoop(); virtual ~MainLoop(); - - }; #endif diff --git a/core/os/memory.cpp b/core/os/memory.cpp index 37a523b763..b6866561fc 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -27,19 +27,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "memory.h" -#include "error_macros.h" #include "copymem.h" +#include "error_macros.h" #include <stdio.h> #include <stdlib.h> +void *operator new(size_t p_size, const char *p_description) { - -void * operator new(size_t p_size,const char *p_description) { - - return Memory::alloc_static( p_size, false ); + return Memory::alloc_static(p_size, false); } -void * operator new(size_t p_size,void* (*p_allocfunc)(size_t p_size)) { +void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) { return p_allocfunc(p_size); } @@ -47,38 +45,36 @@ void * operator new(size_t p_size,void* (*p_allocfunc)(size_t p_size)) { #include <stdio.h> #ifdef DEBUG_ENABLED -size_t Memory::mem_usage=0; -size_t Memory::max_usage=0; +size_t Memory::mem_usage = 0; +size_t Memory::max_usage = 0; #endif -size_t Memory::alloc_count=0; - - -void * Memory::alloc_static(size_t p_bytes,bool p_pad_align) { +size_t Memory::alloc_count = 0; +void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) { #ifdef DEBUG_ENABLED - bool prepad=true; + bool prepad = true; #else - bool prepad=p_pad_align; + bool prepad = p_pad_align; #endif - void * mem = malloc( p_bytes + (prepad?PAD_ALIGN:0)); + void *mem = malloc(p_bytes + (prepad ? PAD_ALIGN : 0)); alloc_count++; - ERR_FAIL_COND_V(!mem,NULL); + ERR_FAIL_COND_V(!mem, NULL); if (prepad) { - uint64_t *s = (uint64_t*)mem; - *s=p_bytes; + uint64_t *s = (uint64_t *)mem; + *s = p_bytes; - uint8_t *s8 = (uint8_t*)mem; + uint8_t *s8 = (uint8_t *)mem; #ifdef DEBUG_ENABLED - mem_usage+=p_bytes; - if (mem_usage>max_usage) { - max_usage=mem_usage; + mem_usage += p_bytes; + if (mem_usage > max_usage) { + max_usage = mem_usage; } #endif return s8 + PAD_ALIGN; @@ -87,74 +83,74 @@ void * Memory::alloc_static(size_t p_bytes,bool p_pad_align) { } } -void * Memory::realloc_static(void *p_memory,size_t p_bytes,bool p_pad_align) { +void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) { - if (p_memory==NULL) { - return alloc_static(p_bytes,p_pad_align); + if (p_memory == NULL) { + return alloc_static(p_bytes, p_pad_align); } - uint8_t *mem = (uint8_t*)p_memory; + uint8_t *mem = (uint8_t *)p_memory; #ifdef DEBUG_ENABLED - bool prepad=true; + bool prepad = true; #else - bool prepad=p_pad_align; + bool prepad = p_pad_align; #endif if (prepad) { - mem-=PAD_ALIGN; - uint64_t *s = (uint64_t*)mem; + mem -= PAD_ALIGN; + uint64_t *s = (uint64_t *)mem; #ifdef DEBUG_ENABLED - mem_usage-=*s; - mem_usage+=p_bytes; + mem_usage -= *s; + mem_usage += p_bytes; #endif - if (p_bytes==0) { + if (p_bytes == 0) { free(mem); return NULL; } else { - *s=p_bytes; + *s = p_bytes; - mem = (uint8_t*)realloc(mem,p_bytes+PAD_ALIGN); - ERR_FAIL_COND_V(!mem,NULL); + mem = (uint8_t *)realloc(mem, p_bytes + PAD_ALIGN); + ERR_FAIL_COND_V(!mem, NULL); - s = (uint64_t*)mem; + s = (uint64_t *)mem; - *s=p_bytes; + *s = p_bytes; - return mem+PAD_ALIGN; + return mem + PAD_ALIGN; } } else { - mem = (uint8_t*)realloc(mem,p_bytes); + mem = (uint8_t *)realloc(mem, p_bytes); - ERR_FAIL_COND_V(mem==NULL && p_bytes>0,NULL); + ERR_FAIL_COND_V(mem == NULL && p_bytes > 0, NULL); return mem; } } -void Memory::free_static(void *p_ptr,bool p_pad_align) { +void Memory::free_static(void *p_ptr, bool p_pad_align) { - ERR_FAIL_COND(p_ptr==NULL); + ERR_FAIL_COND(p_ptr == NULL); - uint8_t *mem = (uint8_t*)p_ptr; + uint8_t *mem = (uint8_t *)p_ptr; #ifdef DEBUG_ENABLED - bool prepad=true; + bool prepad = true; #else - bool prepad=p_pad_align; + bool prepad = p_pad_align; #endif alloc_count--; if (prepad) { - mem-=PAD_ALIGN; - uint64_t *s = (uint64_t*)mem; + mem -= PAD_ALIGN; + uint64_t *s = (uint64_t *)mem; #ifdef DEBUG_ENABLED - mem_usage-=*s; + mem_usage -= *s; #endif free(mem); @@ -162,23 +158,21 @@ void Memory::free_static(void *p_ptr,bool p_pad_align) { free(mem); } - } size_t Memory::get_mem_available() { return 0xFFFFFFFFFFFFF; - } -size_t Memory::get_mem_usage(){ +size_t Memory::get_mem_usage() { #ifdef DEBUG_ENABLED return mem_usage; #else return 0; #endif } -size_t Memory::get_mem_max_usage(){ +size_t Memory::get_mem_max_usage() { #ifdef DEBUG_ENABLED return max_usage; #else @@ -186,16 +180,12 @@ size_t Memory::get_mem_max_usage(){ #endif } - - - _GlobalNil::_GlobalNil() { - color=1; - left=this; - right=this; - parent=this; + color = 1; + left = this; + right = this; + parent = this; } _GlobalNil _GlobalNilClass::_nil; - diff --git a/core/os/memory.h b/core/os/memory.h index 49424037ff..b788068f53 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -29,9 +29,8 @@ #ifndef MEMORY_H #define MEMORY_H -#include <stddef.h> #include "safe_refcount.h" - +#include <stddef.h> /** @author Juan Linietsky <reduzio@gmail.com> @@ -41,9 +40,7 @@ #define PAD_ALIGN 16 //must always be greater than this at much #endif - - -class Memory{ +class Memory { Memory(); #ifdef DEBUG_ENABLED @@ -54,72 +51,65 @@ class Memory{ static size_t alloc_count; public: - - static void * alloc_static(size_t p_bytes,bool p_pad_align=false); - static void * realloc_static(void *p_memory,size_t p_bytes,bool p_pad_align=false); - static void free_static(void *p_ptr,bool p_pad_align=false); + static void *alloc_static(size_t p_bytes, bool p_pad_align = false); + static void *realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align = false); + static void free_static(void *p_ptr, bool p_pad_align = false); static size_t get_mem_available(); static size_t get_mem_usage(); static size_t get_mem_max_usage(); - - }; class DefaultAllocator { public: _FORCE_INLINE_ static void *alloc(size_t p_memory) { return Memory::alloc_static(p_memory, false); } - _FORCE_INLINE_ static void free(void *p_ptr) { return Memory::free_static(p_ptr,false); } - + _FORCE_INLINE_ static void free(void *p_ptr) { return Memory::free_static(p_ptr, false); } }; +void *operator new(size_t p_size, const char *p_description); ///< operator new that takes a description and uses MemoryStaticPool +void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)); ///< operator new that takes a description and uses MemoryStaticPool -void * operator new(size_t p_size,const char *p_description); ///< operator new that takes a description and uses MemoryStaticPool -void * operator new(size_t p_size,void* (*p_allocfunc)(size_t p_size)); ///< operator new that takes a description and uses MemoryStaticPool - -void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_description); ///< operator new that takes a description and uses a pointer to the preallocated memory +void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description); ///< operator new that takes a description and uses a pointer to the preallocated memory #define memalloc(m_size) Memory::alloc_static(m_size) -#define memrealloc(m_mem,m_size) Memory::realloc_static(m_mem,m_size) +#define memrealloc(m_mem, m_size) Memory::realloc_static(m_mem, m_size) #define memfree(m_size) Memory::free_static(m_size) - _ALWAYS_INLINE_ void postinitialize_handler(void *) {} - -template<class T> +template <class T> _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) { postinitialize_handler(p_obj); return p_obj; } -#define memnew(m_class) _post_initialize(new("") m_class) +#define memnew(m_class) _post_initialize(new ("") m_class) -_ALWAYS_INLINE_ void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_description) { +_ALWAYS_INLINE_ void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description) { //void *failptr=0; //ERR_FAIL_COND_V( check < p_size , failptr); /** bug, or strange compiler, most likely */ return p_pointer; } +#define memnew_allocator(m_class, m_allocator) _post_initialize(new (m_allocator::alloc) m_class) +#define memnew_placement(m_placement, m_class) _post_initialize(new (m_placement, sizeof(m_class), "") m_class) -#define memnew_allocator(m_class,m_allocator) _post_initialize(new(m_allocator::alloc) m_class) -#define memnew_placement(m_placement,m_class) _post_initialize(new(m_placement,sizeof(m_class),"") m_class) - - -_ALWAYS_INLINE_ bool predelete_handler(void *) { return true; } +_ALWAYS_INLINE_ bool predelete_handler(void *) { + return true; +} -template<class T> +template <class T> void memdelete(T *p_class) { if (!predelete_handler(p_class)) return; // doesn't want to be deleted p_class->~T(); - Memory::free_static(p_class,false); + Memory::free_static(p_class, false); } -template<class T,class A> +template <class T, class A> void memdelete_allocator(T *p_class) { if (!predelete_handler(p_class)) @@ -128,33 +118,35 @@ void memdelete_allocator(T *p_class) { A::free(p_class); } -#define memdelete_notnull(m_v) { if (m_v) memdelete(m_v); } - -#define memnew_arr( m_class, m_count ) memnew_arr_template<m_class>(m_count) +#define memdelete_notnull(m_v) \ + { \ + if (m_v) memdelete(m_v); \ + } +#define memnew_arr(m_class, m_count) memnew_arr_template<m_class>(m_count) -template<typename T> -T* memnew_arr_template(size_t p_elements,const char *p_descr="") { +template <typename T> +T *memnew_arr_template(size_t p_elements, const char *p_descr = "") { - if (p_elements==0) + if (p_elements == 0) return 0; /** overloading operator new[] cannot be done , because it may not return the real allocated address (it may pad the 'element count' before the actual array). Because of that, it must be done by hand. This is the same strategy used by std::vector, and the PoolVector class, so it should be safe.*/ size_t len = sizeof(T) * p_elements; - uint64_t *mem = (uint64_t*)Memory::alloc_static( len , true ); - T *failptr=0; //get rid of a warning - ERR_FAIL_COND_V( !mem, failptr ); - *(mem-1)=p_elements; + uint64_t *mem = (uint64_t *)Memory::alloc_static(len, true); + T *failptr = 0; //get rid of a warning + ERR_FAIL_COND_V(!mem, failptr); + *(mem - 1) = p_elements; - T* elems = (T*)mem; + T *elems = (T *)mem; /* call operator new */ - for (size_t i=0;i<p_elements;i++) { - new(&elems[i],sizeof(T),p_descr) T; + for (size_t i = 0; i < p_elements; i++) { + new (&elems[i], sizeof(T), p_descr) T; } - return (T*)mem; + return (T *)mem; } /** @@ -162,28 +154,27 @@ T* memnew_arr_template(size_t p_elements,const char *p_descr="") { * an allocated-with memnew_arr() array */ -template<typename T> +template <typename T> size_t memarr_len(const T *p_class) { - uint64_t* ptr = (uint64_t*)p_class; - return *(ptr-1); + uint64_t *ptr = (uint64_t *)p_class; + return *(ptr - 1); } -template<typename T> +template <typename T> void memdelete_arr(T *p_class) { - uint64_t* ptr = (uint64_t*)p_class; + uint64_t *ptr = (uint64_t *)p_class; - uint64_t elem_count = *(ptr-1); + uint64_t elem_count = *(ptr - 1); - for (uint64_t i=0;i<elem_count;i++) { + for (uint64_t i = 0; i < elem_count; i++) { p_class[i].~T(); }; - Memory::free_static(ptr,true); + Memory::free_static(ptr, true); } - struct _GlobalNil { int color; @@ -192,7 +183,6 @@ struct _GlobalNil { _GlobalNil *parent; _GlobalNil(); - }; struct _GlobalNilClass { @@ -200,6 +190,4 @@ struct _GlobalNilClass { static _GlobalNil _nil; }; - - #endif diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp index acdcb492d9..cdc18effdd 100644 --- a/core/os/mutex.cpp +++ b/core/os/mutex.cpp @@ -30,24 +30,19 @@ #include "error_macros.h" #include <stddef.h> - - -Mutex* (*Mutex::create_func)(bool)=0; +Mutex *(*Mutex::create_func)(bool) = 0; Mutex *Mutex::create(bool p_recursive) { - ERR_FAIL_COND_V( !create_func, 0 ); + ERR_FAIL_COND_V(!create_func, 0); return create_func(p_recursive); } - Mutex::~Mutex() { - - } -Mutex *_global_mutex=NULL; +Mutex *_global_mutex = NULL; void _global_lock() { @@ -59,4 +54,3 @@ void _global_unlock() { if (_global_mutex) _global_mutex->unlock(); } - diff --git a/core/os/mutex.h b/core/os/mutex.h index a1004965bb..8ec4f573b7 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -31,7 +31,6 @@ #include "error_list.h" - /** * @class Mutex * @author Juan Linietsky @@ -41,18 +40,16 @@ * Lockp( mutex ); */ - class Mutex { protected: - static Mutex* (*create_func)(bool); + static Mutex *(*create_func)(bool); public: + virtual void lock() = 0; ///< Lock the mutex, block if locked by someone else + virtual void unlock() = 0; ///< Unlock the mutex, let other threads continue + virtual Error try_lock() = 0; ///< Attempt to lock the mutex, OK on success, ERROR means it can't lock. - virtual void lock()=0; ///< Lock the mutex, block if locked by someone else - virtual void unlock()=0; ///< Unlock the mutex, let other threads continue - virtual Error try_lock()=0; ///< Attempt to lock the mutex, OK on success, ERROR means it can't lock. - - static Mutex * create(bool p_recursive=true); ///< Create a mutex + static Mutex *create(bool p_recursive = true); ///< Create a mutex virtual ~Mutex(); }; @@ -60,11 +57,15 @@ public: class MutexLock { Mutex *mutex; -public: - - MutexLock(Mutex* p_mutex) { mutex=p_mutex; if (mutex) mutex->lock(); } - ~MutexLock() { if (mutex) mutex->unlock(); } +public: + MutexLock(Mutex *p_mutex) { + mutex = p_mutex; + if (mutex) mutex->lock(); + } + ~MutexLock() { + if (mutex) mutex->unlock(); + } }; #endif diff --git a/core/os/os.cpp b/core/os/os.cpp index 1d670b4466..03b48f4554 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -35,15 +35,16 @@ #include <stdarg.h> -OS* OS::singleton=NULL; +OS *OS::singleton = NULL; -OS* OS::get_singleton() { +OS *OS::get_singleton() { return singleton; } -uint32_t OS::get_ticks_msec() const -{ return get_ticks_usec()/1000; } +uint32_t OS::get_ticks_msec() const { + return get_ticks_usec() / 1000; +} uint64_t OS::get_splash_tick_msec() const { return _msec_splash; @@ -55,29 +56,27 @@ uint64_t OS::get_unix_time() const { uint64_t OS::get_system_time_secs() const { return 0; } -void OS::debug_break() { +void OS::debug_break(){ // something }; +void OS::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) { -void OS::print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type) { - - const char* err_type; - switch(p_type) { - case ERR_ERROR: err_type="**ERROR**"; break; - case ERR_WARNING: err_type="**WARNING**"; break; - case ERR_SCRIPT: err_type="**SCRIPT ERROR**"; break; - case ERR_SHADER: err_type="**SHADER ERROR**"; break; + const char *err_type; + switch (p_type) { + case ERR_ERROR: err_type = "**ERROR**"; break; + case ERR_WARNING: err_type = "**WARNING**"; break; + case ERR_SCRIPT: err_type = "**SCRIPT ERROR**"; break; + case ERR_SHADER: err_type = "**SHADER ERROR**"; break; } if (p_rationale && *p_rationale) - print("%s: %s\n ",err_type,p_rationale); - print("%s: At: %s:%i:%s() - %s\n",err_type,p_file,p_line,p_function,p_code); + print("%s: %s\n ", err_type, p_rationale); + print("%s: At: %s:%i:%s() - %s\n", err_type, p_file, p_line, p_function, p_code); } -void OS::print(const char* p_format, ...) { - +void OS::print(const char *p_format, ...) { va_list argp; va_start(argp, p_format); @@ -87,7 +86,7 @@ void OS::print(const char* p_format, ...) { va_end(argp); }; -void OS::printerr(const char* p_format, ...) { +void OS::printerr(const char *p_format, ...) { va_list argp; va_start(argp, p_format); @@ -97,9 +96,8 @@ void OS::printerr(const char* p_format, ...) { va_end(argp); }; - void OS::set_keep_screen_on(bool p_enabled) { - _keep_screen_on=p_enabled; + _keep_screen_on = p_enabled; } bool OS::is_keep_screen_on() const { @@ -108,7 +106,7 @@ bool OS::is_keep_screen_on() const { void OS::set_low_processor_usage_mode(bool p_enabled) { - low_processor_usage_mode=p_enabled; + low_processor_usage_mode = p_enabled; } bool OS::is_in_low_processor_usage_mode() const { @@ -116,9 +114,9 @@ bool OS::is_in_low_processor_usage_mode() const { return low_processor_usage_mode; } -void OS::set_clipboard(const String& p_text) { +void OS::set_clipboard(const String &p_text) { - _local_clipboard=p_text; + _local_clipboard = p_text; } String OS::get_clipboard() const { @@ -135,41 +133,40 @@ int OS::get_process_ID() const { return -1; }; - bool OS::is_stdout_verbose() const { return _verbose_stdout; } -void OS::set_last_error(const char* p_error) { +void OS::set_last_error(const char *p_error) { GLOBAL_LOCK_FUNCTION - if (p_error==NULL) - p_error="Unknown Error"; + 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]; + 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:""; + return last_error ? last_error : ""; } -void OS::dump_memory_to_file(const char* p_file) { +void OS::dump_memory_to_file(const char *p_file) { //Memory::dump_static_mem_to_file(p_file); } -static FileAccess *_OSPRF=NULL; +static FileAccess *_OSPRF = NULL; static void _OS_printres(Object *p_obj) { @@ -177,12 +174,11 @@ static void _OS_printres(Object *p_obj) { if (!res) return; - String str = itos(res->get_instance_ID())+String(res->get_class())+":"+String(res->get_name())+" - "+res->get_path(); + String str = itos(res->get_instance_ID()) + String(res->get_class()) + ":" + String(res->get_name()) + " - " + res->get_path(); if (_OSPRF) _OSPRF->store_line(str); else print_line(str); - } bool OS::has_virtual_keyboard() const { @@ -190,61 +186,56 @@ bool OS::has_virtual_keyboard() const { return false; } -void OS::show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect) { - +void OS::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) { } -void OS::hide_virtual_keyboard(){ - +void OS::hide_virtual_keyboard() { } void OS::print_all_resources(String p_to_file) { - ERR_FAIL_COND(p_to_file!="" && _OSPRF); - if (p_to_file!="") { + ERR_FAIL_COND(p_to_file != "" && _OSPRF); + if (p_to_file != "") { Error err; - _OSPRF=FileAccess::open(p_to_file,FileAccess::WRITE,&err); - if (err!=OK) { - _OSPRF=NULL; - ERR_FAIL_COND(err!=OK); + _OSPRF = FileAccess::open(p_to_file, FileAccess::WRITE, &err); + if (err != OK) { + _OSPRF = NULL; + ERR_FAIL_COND(err != OK); } } ObjectDB::debug_objects(_OS_printres); - if (p_to_file!="") { + if (p_to_file != "") { if (_OSPRF) memdelete(_OSPRF); - _OSPRF=NULL; + _OSPRF = NULL; } } void OS::print_resources_in_use(bool p_short) { - - ResourceCache::dump(NULL,p_short); + ResourceCache::dump(NULL, p_short); } -void OS::dump_resources_to_file(const char* p_file) { +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; + last_error = NULL; } - void OS::set_no_window_mode(bool p_enable) { - _no_window=p_enable; + _no_window = p_enable; } bool OS::is_no_window_mode_enabled() const { @@ -258,7 +249,7 @@ int OS::get_exit_code() const { } void OS::set_exit_code(int p_code) { - _exit_code=p_code; + _exit_code = p_code; } String OS::get_locale() const { @@ -271,7 +262,6 @@ String OS::get_resource_dir() const { return GlobalConfig::get_singleton()->get_resource_path(); } - String OS::get_system_dir(SystemDir p_dir) const { return "."; @@ -280,8 +270,8 @@ String OS::get_system_dir(SystemDir p_dir) const { String OS::get_safe_application_name() const { String an = GlobalConfig::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],"-"); + for (int i = 0; i < invalid_char.size(); i++) { + an = an.replace(invalid_char[i], "-"); } return an; } @@ -296,14 +286,14 @@ Error OS::shell_open(String p_uri) { }; // implement these with the canvas? -Error OS::dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object* p_obj, String p_callback) { +Error OS::dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object *p_obj, String p_callback) { while (true) { print("%ls\n--------\n%ls\n", p_title.c_str(), p_description.c_str()); - for (int i=0; i<p_buttons.size(); i++) { - if (i>0) print(", "); - print("%i=%ls", i+1, p_buttons[i].c_str()); + for (int i = 0; i < p_buttons.size(); i++) { + if (i > 0) print(", "); + print("%i=%ls", i + 1, p_buttons[i].c_str()); }; print("\n"); String res = get_stdin_string().strip_edges(); @@ -319,7 +309,7 @@ Error OS::dialog_show(String p_title, String p_description, Vector<String> p_but return OK; }; -Error OS::dialog_input_text(String p_title, String p_description, String p_partial, Object* p_obj, String p_callback) { +Error OS::dialog_input_text(String p_title, String p_description, String p_partial, Object *p_obj, String p_callback) { ERR_FAIL_COND_V(!p_obj, FAILED); ERR_FAIL_COND_V(p_callback == "", FAILED); @@ -340,7 +330,7 @@ int OS::get_static_memory_usage() const { return Memory::get_mem_usage(); } -int OS::get_dynamic_memory_usage() const{ +int OS::get_dynamic_memory_usage() const { return MemoryPool::total_memory; } @@ -350,7 +340,7 @@ int OS::get_static_memory_peak_usage() const { return Memory::get_mem_max_usage(); } -Error OS::set_cwd(const String& p_cwd) { +Error OS::set_cwd(const String &p_cwd) { return ERR_CANT_OPEN; } @@ -367,13 +357,11 @@ int OS::get_free_static_memory() const { } void OS::yield() { - - } void OS::set_screen_orientation(ScreenOrientation p_orientation) { - _orientation=p_orientation; + _orientation = p_orientation; } OS::ScreenOrientation OS::get_screen_orientation() const { @@ -381,7 +369,6 @@ OS::ScreenOrientation OS::get_screen_orientation() const { return (OS::ScreenOrientation)_orientation; } - void OS::_ensure_data_dir() { String dd = get_data_dir(); @@ -393,45 +380,35 @@ void OS::_ensure_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); + if (err != OK) { + ERR_EXPLAIN("Error attempting to create data dir: " + dd); } - ERR_FAIL_COND(err!=OK); + ERR_FAIL_COND(err != OK); memdelete(da); - - } -void OS::set_icon(const Image& p_icon) { - - +void OS::set_icon(const Image &p_icon) { } String OS::get_model_name() const { - return "GenericDevice"; + return "GenericDevice"; } - -void OS::set_cmdline(const char* p_execpath, const List<String>& p_args) { +void OS::set_cmdline(const char *p_execpath, const List<String> &p_args) { _execpath = p_execpath; _cmdline = p_args; }; void OS::release_rendering_thread() { - - } void OS::make_rendering_thread() { - - } void OS::swap_buffers() { - } String OS::get_unique_ID() const { @@ -454,20 +431,19 @@ bool OS::native_video_is_playing() const { return false; }; -void OS::native_video_pause() { +void OS::native_video_pause(){ }; -void OS::native_video_unpause() { +void OS::native_video_unpause(){ }; -void OS::native_video_stop() { +void OS::native_video_stop(){ }; void OS::set_mouse_mode(MouseMode p_mode) { - } bool OS::can_use_threads() const { @@ -479,19 +455,16 @@ bool OS::can_use_threads() const { #endif } -OS::MouseMode OS::get_mouse_mode() const{ +OS::MouseMode OS::get_mouse_mode() const { return MOUSE_MODE_VISIBLE; } - OS::LatinKeyboardVariant OS::get_latin_keyboard_variant() const { return LATIN_KEYBOARD_QWERTY; } - - bool OS::is_joy_known(int p_device) { return true; } @@ -501,18 +474,15 @@ 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_vsync_enabled() const{ +bool OS::is_vsync_enabled() const { return true; } - PowerState OS::get_power_state() { return POWERSTATE_UNKNOWN; } @@ -524,26 +494,22 @@ int OS::get_power_percent_left() { } OS::OS() { - 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; - _verbose_stdout=false; - _no_window=false; - _exit_code=0; - _orientation=SCREEN_LANDSCAPE; - - _render_thread_mode=RENDER_THREAD_SAFE; - - - _allow_hidpi=true; + 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; + _verbose_stdout = false; + _no_window = false; + _exit_code = 0; + _orientation = SCREEN_LANDSCAPE; + + _render_thread_mode = RENDER_THREAD_SAFE; + + _allow_hidpi = true; Math::seed(1234567); } - OS::~OS() { - singleton=NULL; + singleton = NULL; } - - diff --git a/core/os/os.h b/core/os/os.h index 7c8100679a..46e57e5186 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -29,22 +29,21 @@ #ifndef OS_H #define OS_H -#include "ustring.h" -#include "list.h" -#include "vector.h" #include "engine.h" +#include "list.h" #include "os/main_loop.h" #include "power.h" +#include "ustring.h" +#include "vector.h" #include <stdarg.h> - /** @author Juan Linietsky <reduzio@gmail.com> */ class OS { - static OS* singleton; + static OS *singleton; String _execpath; List<String> _cmdline; bool _keep_screen_on; @@ -57,7 +56,6 @@ class OS { int _orientation; bool _allow_hidpi; - char *last_error; public: @@ -69,45 +67,51 @@ public: }; struct VideoMode { - int width,height; + int width, height; bool fullscreen; bool resizable; bool borderless_window; - float get_aspect() const { return (float)width/(float)height; } - VideoMode(int p_width=1024,int p_height=600,bool p_fullscreen=false, bool p_resizable = true,bool p_borderless_window=false) { width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; borderless_window=p_borderless_window; } + float get_aspect() const { return (float)width / (float)height; } + VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false) { + width = p_width; + height = p_height; + fullscreen = p_fullscreen; + resizable = p_resizable; + borderless_window = p_borderless_window; + } }; + protected: -friend class Main; + friend class Main; RenderThreadMode _render_thread_mode; // functions used by main to initialize/deintialize the OS - virtual int get_video_driver_count() const=0; - virtual const char * get_video_driver_name(int p_driver) const=0; + virtual int get_video_driver_count() const = 0; + virtual const char *get_video_driver_name(int p_driver) const = 0; - virtual VideoMode get_default_video_mode() const=0; + virtual VideoMode get_default_video_mode() const = 0; - virtual int get_audio_driver_count() const=0; - virtual const char * get_audio_driver_name(int p_driver) const=0; + virtual int get_audio_driver_count() const = 0; + virtual const char *get_audio_driver_name(int p_driver) const = 0; - virtual void initialize_core()=0; - virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver)=0; + virtual void initialize_core() = 0; + virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) = 0; - virtual void set_main_loop( MainLoop * p_main_loop )=0; - virtual void delete_main_loop()=0; + virtual void set_main_loop(MainLoop *p_main_loop) = 0; + virtual void delete_main_loop() = 0; - virtual void finalize()=0; - virtual void finalize_core()=0; + virtual void finalize() = 0; + virtual void finalize_core() = 0; - virtual void set_cmdline(const char* p_execpath, const List<String>& p_args); + virtual void set_cmdline(const char *p_execpath, const List<String> &p_args); void _ensure_data_dir(); public: - typedef int64_t ProcessID; - static OS* get_singleton(); + static OS *get_singleton(); enum ErrorType { ERR_ERROR, @@ -116,20 +120,18 @@ public: ERR_SHADER }; - virtual void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type=ERR_ERROR); + virtual void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR); - virtual void print(const char *p_format, ... ); - virtual void printerr(const char *p_format, ... ); - virtual void vprint(const char* p_format, va_list p_list, bool p_stderr=false)=0; - 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 print(const char *p_format, ...); + virtual void printerr(const char *p_format, ...); + virtual void vprint(const char *p_format, va_list p_list, bool p_stderr = false) = 0; + 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 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, @@ -140,30 +142,28 @@ public: virtual void set_mouse_mode(MouseMode p_mode); virtual MouseMode get_mouse_mode() const; + virtual void warp_mouse_pos(const Point2 &p_to) {} + virtual Point2 get_mouse_pos() const = 0; + virtual int get_mouse_button_state() const = 0; + virtual void set_window_title(const String &p_title) = 0; - virtual void warp_mouse_pos(const Point2& p_to) {} - virtual Point2 get_mouse_pos() const=0; - virtual int get_mouse_button_state() const=0; - virtual void set_window_title(const String& p_title)=0; - - virtual void set_clipboard(const String& p_text); + virtual void set_clipboard(const String &p_text); virtual String get_clipboard() const; - virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0)=0; - virtual VideoMode get_video_mode(int p_screen=0) const=0; - virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const=0; + virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0) = 0; + virtual VideoMode get_video_mode(int p_screen = 0) const = 0; + virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const = 0; - - virtual int get_screen_count() const{ return 1; } + virtual int get_screen_count() const { return 1; } virtual int get_current_screen() const { return 0; } - 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 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; - virtual void set_window_size(const Size2 p_size){} + virtual void set_window_position(const Point2 &p_position) {} + virtual Size2 get_window_size() const = 0; + virtual void set_window_size(const Size2 p_size) {} virtual void set_window_fullscreen(bool p_enabled) {} virtual bool is_window_fullscreen() const { return true; } virtual void set_window_resizable(bool p_enabled) {} @@ -172,12 +172,11 @@ public: virtual bool is_window_minimized() const { return false; } virtual void set_window_maximized(bool p_enabled) {} virtual bool is_window_maximized() const { return true; } - virtual void request_attention() { } + virtual void request_attention() {} virtual void set_borderless_window(int p_borderless) {} virtual bool get_borderless_window() { return 0; } - virtual void set_keep_screen_on(bool p_enabled); virtual bool is_keep_screen_on() const; virtual void set_low_processor_usage_mode(bool p_enabled); @@ -185,22 +184,21 @@ public: virtual String get_installed_templates_path() const { return ""; } virtual String get_executable_path() const; - 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)=0; - virtual Error kill(const ProcessID& p_pid)=0; + 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) = 0; + virtual Error kill(const ProcessID &p_pid) = 0; virtual int get_process_ID() const; virtual Error shell_open(String p_uri); - virtual Error set_cwd(const String& p_cwd); + virtual Error set_cwd(const String &p_cwd); - virtual bool has_environment(const String& p_var) const=0; - virtual String get_environment(const String& p_var) const=0; + virtual bool has_environment(const String &p_var) const = 0; + virtual String get_environment(const String &p_var) const = 0; - virtual String get_name()=0; + virtual String get_name() = 0; virtual List<String> get_cmdline_args() const { return _cmdline; } - virtual String get_model_name() const; - - virtual MainLoop *get_main_loop() const=0; + virtual String get_model_name() const; + virtual MainLoop *get_main_loop() const = 0; virtual void yield(); @@ -252,18 +250,17 @@ public: String name; }; - virtual Date get_date(bool local=false) const=0; - virtual Time get_time(bool local=false) const=0; - virtual TimeZoneInfo get_time_zone_info() const=0; + virtual Date get_date(bool local = false) const = 0; + virtual Time get_time(bool local = false) const = 0; + virtual TimeZoneInfo get_time_zone_info() const = 0; virtual uint64_t get_unix_time() const; virtual uint64_t get_system_time_secs() const; - virtual void delay_usec(uint32_t p_usec) const=0; - virtual uint64_t get_ticks_usec() const=0; + virtual void delay_usec(uint32_t p_usec) const = 0; + virtual uint64_t get_ticks_usec() const = 0; uint32_t get_ticks_msec() const; uint64_t get_splash_tick_msec() const; - virtual bool can_draw() const = 0; bool is_stdout_verbose() const; @@ -289,18 +286,17 @@ public: CURSOR_MAX }; - virtual bool has_virtual_keyboard() const; - virtual void show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect=Rect2()); + virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2()); virtual void hide_virtual_keyboard(); - virtual void set_cursor_shape(CursorShape p_shape)=0; + virtual void set_cursor_shape(CursorShape p_shape) = 0; virtual bool get_swap_ok_cancel() { return false; } - virtual void dump_memory_to_file(const char* p_file); - virtual void dump_resources_to_file(const char* p_file); - virtual void print_resources_in_use(bool p_short=false); - virtual void print_all_resources(String p_to_file=""); + virtual void dump_memory_to_file(const char *p_file); + virtual void dump_resources_to_file(const char *p_file); + virtual void print_resources_in_use(bool p_short = false); + virtual void print_all_resources(String p_to_file = ""); virtual int get_static_memory_usage() const; virtual int get_static_memory_peak_usage() const; @@ -328,7 +324,6 @@ public: virtual String get_system_dir(SystemDir p_dir) const; - virtual void set_no_window_mode(bool p_enable); virtual bool is_no_window_mode_enabled() const; @@ -357,8 +352,7 @@ public: virtual void make_rendering_thread(); virtual void swap_buffers(); - - virtual void set_icon(const Image& p_icon); + virtual void set_icon(const Image &p_icon); virtual int get_exit_code() const; virtual void set_exit_code(int p_code); @@ -375,9 +369,8 @@ public: virtual bool can_use_threads() const; - virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object* p_obj, String p_callback); - virtual Error dialog_input_text(String p_title, String p_description, String p_partial, Object* p_obj, String p_callback); - + virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, Object *p_obj, String p_callback); + virtual Error dialog_input_text(String p_title, String p_description, String p_partial, Object *p_obj, String p_callback); enum LatinKeyboardVariant { LATIN_KEYBOARD_QWERTY, @@ -388,12 +381,10 @@ public: LATIN_KEYBOARD_NEO, }; - virtual LatinKeyboardVariant get_latin_keyboard_variant() const; - virtual bool is_joy_known(int p_device); - virtual String get_joy_guid(int p_device)const; + virtual String get_joy_guid(int p_device) const; enum EngineContext { CONTEXT_EDITOR, @@ -404,18 +395,16 @@ public: virtual void set_use_vsync(bool p_enable); virtual bool is_vsync_enabled() const; - + virtual PowerState get_power_state(); virtual int get_power_seconds_left(); virtual int get_power_percent_left(); - virtual bool check_feature_support(const String& p_feature)=0; + virtual bool check_feature_support(const String &p_feature) = 0; bool is_hidpi_allowed() const { return _allow_hidpi; } OS(); virtual ~OS(); - }; #endif - diff --git a/core/os/power.h b/core/os/power.h index c92348ff50..9e70e82f5d 100644 --- a/core/os/power.h +++ b/core/os/power.h @@ -30,15 +30,12 @@ #ifndef CORE_OS_POWER_H_ #define CORE_OS_POWER_H_ - -typedef enum -{ - POWERSTATE_UNKNOWN, /**< cannot determine power status */ - POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ - POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */ - POWERSTATE_CHARGING, /**< Plugged in, charging battery */ - POWERSTATE_CHARGED /**< Plugged in, battery charged */ +typedef enum { + POWERSTATE_UNKNOWN, /**< cannot determine power status */ + POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ + POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */ + POWERSTATE_CHARGING, /**< Plugged in, charging battery */ + POWERSTATE_CHARGED /**< Plugged in, battery charged */ } PowerState; - #endif /* CORE_OS_POWER_H_ */ diff --git a/core/os/rw_lock.cpp b/core/os/rw_lock.cpp index 3af62aa8da..83f8a9ffde 100644 --- a/core/os/rw_lock.cpp +++ b/core/os/rw_lock.cpp @@ -32,19 +32,14 @@ #include <stddef.h> - -RWLock* (*RWLock::create_func)()=0; +RWLock *(*RWLock::create_func)() = 0; RWLock *RWLock::create() { - ERR_FAIL_COND_V( !create_func, 0 ); + ERR_FAIL_COND_V(!create_func, 0); return create_func(); } - RWLock::~RWLock() { - - } - diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h index 6b4af83bf9..6d3079df51 100644 --- a/core/os/rw_lock.h +++ b/core/os/rw_lock.h @@ -33,42 +33,48 @@ class RWLock { protected: - static RWLock* (*create_func)(); + static RWLock *(*create_func)(); public: + virtual void read_lock() = 0; ///< Lock the rwlock, block if locked by someone else + virtual void read_unlock() = 0; ///< Unlock the rwlock, let other threads continue + virtual Error read_try_lock() = 0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock. - virtual void read_lock()=0; ///< Lock the rwlock, block if locked by someone else - virtual void read_unlock()=0; ///< Unlock the rwlock, let other threads continue - virtual Error read_try_lock()=0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock. + virtual void write_lock() = 0; ///< Lock the rwlock, block if locked by someone else + virtual void write_unlock() = 0; ///< Unlock the rwlock, let other thwrites continue + virtual Error write_try_lock() = 0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock. - virtual void write_lock()=0; ///< Lock the rwlock, block if locked by someone else - virtual void write_unlock()=0; ///< Unlock the rwlock, let other thwrites continue - virtual Error write_try_lock()=0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock. - - static RWLock * create(); ///< Create a rwlock + static RWLock *create(); ///< Create a rwlock virtual ~RWLock(); }; - class RWLockRead { RWLock *lock; -public: - - RWLockRead(RWLock* p_lock) { lock=p_lock; if (lock) lock->read_lock(); } - ~RWLockRead() { if (lock) lock->read_unlock(); } +public: + RWLockRead(RWLock *p_lock) { + lock = p_lock; + if (lock) lock->read_lock(); + } + ~RWLockRead() { + if (lock) lock->read_unlock(); + } }; class RWLockWrite { RWLock *lock; -public: - - RWLockWrite(RWLock* p_lock) { lock=p_lock; if (lock) lock->write_lock(); } - ~RWLockWrite() { if (lock) lock->write_unlock(); } +public: + RWLockWrite(RWLock *p_lock) { + lock = p_lock; + if (lock) lock->write_lock(); + } + ~RWLockWrite() { + if (lock) lock->write_unlock(); + } }; #endif // RWLOCK_H diff --git a/core/os/semaphore.cpp b/core/os/semaphore.cpp index fe476c5888..6bbae72f63 100644 --- a/core/os/semaphore.cpp +++ b/core/os/semaphore.cpp @@ -29,16 +29,14 @@ #include "semaphore.h" #include "error_macros.h" -Semaphore* (*Semaphore::create_func)()=0; +Semaphore *(*Semaphore::create_func)() = 0; Semaphore *Semaphore::create() { - ERR_FAIL_COND_V( !create_func, 0 ); + ERR_FAIL_COND_V(!create_func, 0); return create_func(); } - Semaphore::~Semaphore() { - } diff --git a/core/os/semaphore.h b/core/os/semaphore.h index e0b4460b22..8956fb7c39 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -36,18 +36,16 @@ */ class Semaphore { protected: - static Semaphore* (*create_func)(); + static Semaphore *(*create_func)(); public: + virtual Error wait() = 0; ///< wait until semaphore has positive value, then decrement and pass + virtual Error post() = 0; ///< unlock the semaphore, incrementing the value + virtual int get() const = 0; ///< get semaphore value - virtual Error wait()=0; ///< wait until semaphore has positive value, then decrement and pass - virtual Error post()=0; ///< unlock the semaphore, incrementing the value - virtual int get() const=0; ///< get semaphore value - - static Semaphore * create(); ///< Create a mutex + static Semaphore *create(); ///< Create a mutex virtual ~Semaphore(); }; - #endif diff --git a/core/os/shell.cpp b/core/os/shell.cpp index 60f4203dbe..77726afd9d 100644 --- a/core/os/shell.cpp +++ b/core/os/shell.cpp @@ -28,24 +28,17 @@ /*************************************************************************/ #include "shell.h" +Shell *Shell::singleton = NULL; -Shell * Shell::singleton=NULL; - - -Shell * Shell::get_singleton() { +Shell *Shell::get_singleton() { return singleton; } - Shell::~Shell() { - } Shell::Shell() { - singleton=this; + singleton = this; } - - - diff --git a/core/os/shell.h b/core/os/shell.h index f26f01846e..b2b0aa2260 100644 --- a/core/os/shell.h +++ b/core/os/shell.h @@ -37,11 +37,11 @@ */ class Shell { - static Shell * singleton; -public: + static Shell *singleton; - static Shell * get_singleton(); - virtual void execute(String p_path)=0; +public: + static Shell *get_singleton(); + virtual void execute(String p_path) = 0; Shell(); virtual ~Shell(); diff --git a/core/os/thread.cpp b/core/os/thread.cpp index 689fed7537..1c6ccaa504 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -28,13 +28,12 @@ /*************************************************************************/ #include "thread.h" +Thread *(*Thread::create_func)(ThreadCreateCallback, void *, const Settings &) = NULL; +Thread::ID (*Thread::get_thread_ID_func)() = NULL; +void (*Thread::wait_to_finish_func)(Thread *) = NULL; +Error (*Thread::set_name_func)(const String &) = NULL; -Thread* (*Thread::create_func)(ThreadCreateCallback,void *,const Settings&)=NULL; -Thread::ID (*Thread::get_thread_ID_func)()=NULL; -void (*Thread::wait_to_finish_func)(Thread*)=NULL; -Error (*Thread::set_name_func)(const String&)=NULL; - -Thread::ID Thread::_main_thread_id=0; +Thread::ID Thread::_main_thread_id = 0; Thread::ID Thread::get_caller_ID() { @@ -43,11 +42,11 @@ Thread::ID Thread::get_caller_ID() { return 0; } -Thread* Thread::create(ThreadCreateCallback p_callback,void * p_user,const Settings& p_settings) { +Thread *Thread::create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings) { if (create_func) { - return create_func(p_callback,p_user,p_settings); + return create_func(p_callback, p_user, p_settings); } return NULL; } @@ -56,7 +55,6 @@ void Thread::wait_to_finish(Thread *p_thread) { if (wait_to_finish_func) wait_to_finish_func(p_thread); - } Error Thread::set_name(const String &p_name) { @@ -67,13 +65,8 @@ Error Thread::set_name(const String &p_name) { return ERR_UNAVAILABLE; }; -Thread::Thread() -{ +Thread::Thread() { } - -Thread::~Thread() -{ +Thread::~Thread() { } - - diff --git a/core/os/thread.h b/core/os/thread.h index 23ed76d486..9e0ab93cb9 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -29,7 +29,6 @@ #ifndef THREAD_H #define THREAD_H - #include "typedefs.h" /** @author Juan Linietsky <reduzio@gmail.com> @@ -39,54 +38,45 @@ typedef void (*ThreadCreateCallback)(void *p_userdata); - - class Thread { public: - enum Priority { PRIORITY_LOW, - PRIORITY_NORMAL, + PRIORITY_NORMAL, PRIORITY_HIGH }; struct Settings { Priority priority; - Settings() { priority=PRIORITY_NORMAL; } + Settings() { priority = PRIORITY_NORMAL; } }; - - typedef uint64_t ID; protected: - static Thread* (*create_func)(ThreadCreateCallback p_callback,void *,const Settings&); + static Thread *(*create_func)(ThreadCreateCallback p_callback, void *, const Settings &); static ID (*get_thread_ID_func)(); - static void (*wait_to_finish_func)(Thread*); - static Error (*set_name_func)(const String&); + static void (*wait_to_finish_func)(Thread *); + static Error (*set_name_func)(const String &); friend class Main; static ID _main_thread_id; - Thread(); -public: - virtual ID get_ID() const=0; +public: + virtual ID get_ID() const = 0; static Error set_name(const String &p_name); _FORCE_INLINE_ static ID get_main_ID() { return _main_thread_id; } ///< get the ID of the main thread static ID get_caller_ID(); ///< get the ID of the caller function ID static void wait_to_finish(Thread *p_thread); ///< waits until thread is finished, and deallocates it. - static Thread * create(ThreadCreateCallback p_callback,void * p_user,const Settings& p_settings=Settings()); ///< Static function to create a thread, will call p_callback - + static Thread *create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings = Settings()); ///< Static function to create a thread, will call p_callback virtual ~Thread(); - }; #endif - diff --git a/core/os/thread_dummy.cpp b/core/os/thread_dummy.cpp index 93a020b7a8..a17f7f09a8 100644 --- a/core/os/thread_dummy.cpp +++ b/core/os/thread_dummy.cpp @@ -30,7 +30,7 @@ #include "memory.h" -Thread* ThreadDummy::create(ThreadCreateCallback p_callback,void * p_user,const Thread::Settings& p_settings) { +Thread *ThreadDummy::create(ThreadCreateCallback p_callback, void *p_user, const Thread::Settings &p_settings) { return memnew(ThreadDummy); }; @@ -38,7 +38,7 @@ void ThreadDummy::make_default() { Thread::create_func = &ThreadDummy::create; }; -Mutex* MutexDummy::create(bool p_recursive) { +Mutex *MutexDummy::create(bool p_recursive) { return memnew(MutexDummy); }; @@ -46,14 +46,10 @@ void MutexDummy::make_default() { Mutex::create_func = &MutexDummy::create; }; - -Semaphore* SemaphoreDummy::create() { +Semaphore *SemaphoreDummy::create() { return memnew(SemaphoreDummy); }; void SemaphoreDummy::make_default() { Semaphore::create_func = &SemaphoreDummy::create; }; - - - diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h index 01e366e2fa..8d0ca0340d 100644 --- a/core/os/thread_dummy.h +++ b/core/os/thread_dummy.h @@ -29,13 +29,13 @@ #ifndef THREAD_DUMMY_H #define THREAD_DUMMY_H -#include "thread.h" #include "mutex.h" #include "semaphore.h" +#include "thread.h" class ThreadDummy : public Thread { - static Thread* create(ThreadCreateCallback p_callback,void * p_user,const Settings& p_settings=Settings()); + static Thread *create(ThreadCreateCallback p_callback, void *p_user, const Settings &p_settings = Settings()); public: virtual ID get_ID() const { return 0; }; @@ -45,12 +45,11 @@ public: class MutexDummy : public Mutex { - static Mutex* create(bool p_recursive); + static Mutex *create(bool p_recursive); public: - - virtual void lock() {}; - virtual void unlock() {}; + virtual void lock(){}; + virtual void unlock(){}; virtual Error try_lock() { return OK; }; static void make_default(); @@ -58,7 +57,7 @@ public: class SemaphoreDummy : public Semaphore { - static Semaphore* create(); + static Semaphore *create(); public: virtual Error wait() { return OK; }; @@ -66,7 +65,6 @@ public: virtual int get() const { return 0; }; ///< get semaphore value static void make_default(); - }; #endif diff --git a/core/os/thread_safe.cpp b/core/os/thread_safe.cpp index a0bfb86c82..ebdf86733c 100644 --- a/core/os/thread_safe.cpp +++ b/core/os/thread_safe.cpp @@ -42,5 +42,5 @@ ThreadSafe::ThreadSafe() { ThreadSafe::~ThreadSafe() { if (mutex) - memdelete( mutex ); + memdelete(mutex); } diff --git a/core/os/thread_safe.h b/core/os/thread_safe.h index c9a832b41b..a60773e8ed 100644 --- a/core/os/thread_safe.h +++ b/core/os/thread_safe.h @@ -29,41 +29,42 @@ #ifndef THREAD_SAFE_H #define THREAD_SAFE_H - #include "os/mutex.h" class ThreadSafe { Mutex *mutex; -public: - inline void lock() const { if (mutex) mutex->lock(); } - inline void unlock() const { if (mutex) mutex->unlock(); } +public: + inline void lock() const { + if (mutex) mutex->lock(); + } + inline void unlock() const { + if (mutex) mutex->unlock(); + } ThreadSafe(); ~ThreadSafe(); - }; - class ThreadSafeMethod { const ThreadSafe *_ts; + public: ThreadSafeMethod(const ThreadSafe *p_ts) { - _ts=p_ts; + _ts = p_ts; _ts->lock(); } ~ThreadSafeMethod() { _ts->unlock(); } }; - #ifndef NO_THREADS #define _THREAD_SAFE_CLASS_ ThreadSafe __thread__safe__; -#define _THREAD_SAFE_METHOD_ ThreadSafeMethod __thread_safe_method__(&__thread__safe__); +#define _THREAD_SAFE_METHOD_ ThreadSafeMethod __thread_safe_method__(&__thread__safe__); #define _THREAD_SAFE_LOCK_ __thread__safe__.lock(); #define _THREAD_SAFE_UNLOCK_ __thread__safe__.unlock(); @@ -76,7 +77,4 @@ public: #endif - - - #endif |