summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub4
-rw-r--r--core/bind/core_bind.cpp2
-rw-r--r--core/class_db.cpp2
-rw-r--r--core/global_config.cpp (renamed from core/globals.cpp)137
-rw-r--r--core/global_config.h (renamed from core/globals.h)4
-rw-r--r--core/hash_map.h61
-rw-r--r--core/hashfuncs.h42
-rw-r--r--core/input_map.cpp2
-rw-r--r--core/io/file_access_memory.cpp2
-rw-r--r--core/io/file_access_network.cpp2
-rw-r--r--core/io/file_access_pack.cpp6
-rw-r--r--core/io/packet_peer.cpp2
-rw-r--r--core/io/resource_format_binary.cpp2
-rw-r--r--core/io/resource_loader.cpp2
-rw-r--r--core/io/resource_saver.cpp2
-rw-r--r--core/math/math_funcs.h1
-rw-r--r--core/message_queue.cpp2
-rw-r--r--core/object.h2
-rw-r--r--core/os/dir_access.cpp2
-rw-r--r--core/os/file_access.cpp2
-rw-r--r--core/os/input.cpp2
-rw-r--r--core/os/os.cpp2
-rw-r--r--core/register_core_types.cpp2
-rw-r--r--core/script_debugger_remote.cpp2
-rw-r--r--core/translation.cpp2
-rw-r--r--core/ustring.cpp47
-rw-r--r--core/ustring.h2
-rw-r--r--core/variant.cpp187
-rw-r--r--core/variant.h5
29 files changed, 380 insertions, 152 deletions
diff --git a/core/SCsub b/core/SCsub
index 8d89f6427b..a9721a1052 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -13,7 +13,7 @@ for x in env.global_defaults:
gd_inc += '#include "platform/' + x + '/globals/global_defaults.h"\n'
gd_call += "\tregister_" + x + "_global_defaults();\n"
-gd_cpp = '#include "globals.h"\n'
+gd_cpp = '#include "global_config.h"\n'
gd_cpp += gd_inc
gd_cpp += "void GlobalConfig::register_global_defaults() {\n" + gd_call + "\n}\n"
@@ -45,7 +45,7 @@ if ("SCRIPT_AES256_ENCRYPTION_KEY" in os.environ):
print("Invalid AES256 encryption key, not 64 bits hex: " + e)
f = open("script_encryption_key.cpp", "wb")
-f.write("#include \"globals.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
+f.write("#include \"global_config.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
f.close()
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 7bd652349d..54ab51657b 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -31,7 +31,7 @@
#include "geometry.h"
#include "io/marshalls.h"
#include "io/base64.h"
-#include "core/globals.h"
+#include "core/global_config.h"
#include "io/file_access_encrypted.h"
#include "os/keyboard.h"
diff --git a/core/class_db.cpp b/core/class_db.cpp
index 76c2f0633a..4bdae45fb9 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -295,7 +295,7 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
OBJTYPE_RLOCK;
#ifdef DEBUG_METHODS_ENABLED
- uint64_t hash = hash_djb2_one_64(HashMapHahserDefault::hash(VERSION_FULL_NAME));
+ uint64_t hash = hash_djb2_one_64(HashMapHasherDefault::hash(VERSION_FULL_NAME));
List<StringName> names;
diff --git a/core/globals.cpp b/core/global_config.cpp
index 0c35a9f89a..b76991c04e 100644
--- a/core/globals.cpp
+++ b/core/global_config.cpp
@@ -26,7 +26,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "globals.h"
+#include "global_config.h"
#include "os/dir_access.h"
#include "os/file_access.h"
@@ -247,9 +247,22 @@ bool GlobalConfig::_load_resource_pack(const String& p_pack) {
Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
- //an absolute mess of a function, must be cleaned up and reorganized somehow at some point
+ //If looking for files in network, just use network!
- //_load_settings(p_path+"/override.cfg");
+ if (FileAccessNetworkClient::get_singleton()) {
+
+ if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
+
+ _load_settings("res://override.cfg");
+
+ }
+
+ return OK;
+ }
+
+ String exec_path = OS::get_singleton()->get_executable_path();
+
+ //Attempt with a passed main pack first
if (p_main_pack!="") {
@@ -257,8 +270,8 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
ERR_FAIL_COND_V(!ok,ERR_CANT_OPEN);
if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
-
- _load_settings("res://override.cfg");
+ //load override from location of the main pack
+ _load_settings(p_main_pack.get_base_dir().plus_file("override.cfg"));
}
@@ -266,21 +279,15 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
}
- if (OS::get_singleton()->get_executable_path()!="") {
+ //Attempt with execname.pck
+ if (exec_path!="") {
- if (_load_resource_pack(OS::get_singleton()->get_executable_path())) {
- if (p_path!="") {
- resource_path=p_path;
- } else {
- DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- resource_path=d->get_current_dir();
- memdelete(d);
+ if (_load_resource_pack(exec_path.get_basename()+".pck")) {
- }
if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
-
- _load_settings("res://override.cfg");
+ //load override from location of executable
+ _load_settings(exec_path.get_base_dir().plus_file("override.cfg"));
}
@@ -292,31 +299,19 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
}
- if (FileAccessNetworkClient::get_singleton()) {
-
- if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
-
- _load_settings("res://override.cfg");
-
- }
-
- return OK;
- }
-
+ //Try to use the filesystem for files, according to OS. (only Android -when reading from pck- and iOS use this)
if (OS::get_singleton()->get_resource_dir()!="") {
- //OS will call Globals->get_resource_path which will be empty if not overriden!
+ //OS will call Globals->get_resource_path which will be empty if not overriden!
//if the OS would rather use somewhere else, then it will not be empty.
+
resource_path=OS::get_singleton()->get_resource_dir().replace("\\","/");
if (resource_path.length() && resource_path[ resource_path.length()-1]=='/')
resource_path=resource_path.substr(0,resource_path.length()-1); // chop end
- print_line("has res dir: "+resource_path);
- if (!_load_resource_pack("res://data.pck"))
- _load_resource_pack("res://data.zip");
- // make sure this is load from the resource path
- print_line("exists engine cfg? "+itos(FileAccess::exists("/godot.cfg")));
+ // data.pck and data.zip are deprecated and no longer supported, apologies.
+ // make sure this is loaded from the resource path
+
if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
- print_line("loaded godot.cfg");
_load_settings("res://override.cfg");
}
@@ -324,67 +319,41 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
return OK;
}
- DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- if (!d) {
-
- resource_path = p_path;
-
- } else {
-
- d->change_dir(p_path);
-
- String candidate = d->get_current_dir();
- String current_dir = d->get_current_dir();
- String exec_name = OS::get_singleton()->get_executable_path().get_file().get_basename();
- bool found = false;
- bool first_time=true;
-
- while(true) {
- //try to load settings in ascending through dirs shape!
-
- //tries to open pack, but only first time
- if (first_time && (_load_resource_pack(current_dir+"/"+exec_name+".pck") || _load_resource_pack(current_dir+"/"+exec_name+".zip") )) {
- if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
+ //Nothing was found, try to find a godot.cfg somewhere!
- _load_settings("res://override.cfg");
- found=true;
-
-
- }
- break;
- } else if (first_time && (_load_resource_pack(current_dir+"/data.pck") || _load_resource_pack(current_dir+"/data.zip") )) {
- if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
+ DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ ERR_FAIL_COND_V(!d,ERR_CANT_CREATE);
- _load_settings("res://override.cfg");
- found=true;
+ d->change_dir(p_path);
+ String candidate = d->get_current_dir();
+ String current_dir = d->get_current_dir();
+ bool found = false;
- }
- break;
- } else if (_load_settings(current_dir+"/godot.cfg")==OK || _load_settings_binary(current_dir+"/godot.cfb")==OK) {
+ while(true) {
+ //try to load settings in ascending through dirs shape!
- _load_settings(current_dir+"/override.cfg");
- candidate=current_dir;
- found=true;
- break;
- }
+ if (_load_settings(current_dir+"/godot.cfg")==OK || _load_settings_binary(current_dir+"/godot.cfb")==OK) {
- d->change_dir("..");
- if (d->get_current_dir()==current_dir)
- break; //not doing anything useful
- current_dir=d->get_current_dir();
- first_time=false;
+ _load_settings(current_dir+"/override.cfg");
+ candidate=current_dir;
+ found=true;
+ break;
}
+ d->change_dir("..");
+ if (d->get_current_dir()==current_dir)
+ break; //not doing anything useful
+ current_dir=d->get_current_dir();
+ }
- resource_path=candidate;
- resource_path = resource_path.replace("\\","/"); // windows path to unix path just in case
- memdelete(d);
- if (!found)
- return ERR_FILE_NOT_FOUND;
- };
+ resource_path=candidate;
+ resource_path = resource_path.replace("\\","/"); // windows path to unix path just in case
+ memdelete(d);
+ if (!found)
+ return ERR_FILE_NOT_FOUND;
if (resource_path.length() && resource_path[ resource_path.length()-1]=='/')
resource_path=resource_path.substr(0,resource_path.length()-1); // chop end
diff --git a/core/globals.h b/core/global_config.h
index faf077f2a5..471f1ff885 100644
--- a/core/globals.h
+++ b/core/global_config.h
@@ -26,8 +26,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef GLOBALS_H
-#define GLOBALS_H
+#ifndef GLOBAL_CONFIG_H
+#define GLOBAL_CONFIG_H
#include "object.h"
#include "set.h"
diff --git a/core/hash_map.h b/core/hash_map.h
index 0d55206935..515fc6c4fe 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -30,40 +30,45 @@
#define HASH_MAP_H
#include "hashfuncs.h"
+#include "math_funcs.h"
#include "error_macros.h"
#include "ustring.h"
#include "os/memory.h"
#include "list.h"
-
-class HashMapHahserDefault {
-public:
-
+struct HashMapHasherDefault {
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
- static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) {
- uint64_t v=p_int;
- v = (~v) + (v << 18); // v = (v << 18) - v - 1;
- v = v ^ (v >> 31);
- v = v * 21; // v = (v + (v << 2)) + (v << 4);
- v = v ^ (v >> 11);
- v = v + (v << 6);
- v = v ^ (v >> 22);
- return (int) v;
- }
- static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash(uint64_t(p_int)); }
+ static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }
-
- static _FORCE_INLINE_ uint32_t hash(const uint32_t p_int) { return p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash(uint64_t(p_int)); }
+ static _FORCE_INLINE_ uint32_t hash(const float p_float) { return hash_djb2_one_float(p_float); }
+ static _FORCE_INLINE_ uint32_t hash(const double p_double){ return hash_djb2_one_float(p_double); }
+ static _FORCE_INLINE_ uint32_t hash(const uint32_t p_int) { return p_int; }
static _FORCE_INLINE_ uint32_t hash(const int32_t p_int) { return (uint32_t)p_int; }
- static _FORCE_INLINE_ uint32_t hash(const uint16_t p_int) { return p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const uint16_t p_int) { return p_int; }
static _FORCE_INLINE_ uint32_t hash(const int16_t p_int) { return (uint32_t)p_int; }
static _FORCE_INLINE_ uint32_t hash(const uint8_t p_int) { return p_int; }
- static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; }
- static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar) { return (uint32_t)p_wchar; }
+ static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar){ return (uint32_t)p_wchar; }
//static _FORCE_INLINE_ uint32_t hash(const void* p_ptr) { return uint32_t(uint64_t(p_ptr))*(0x9e3779b1L); }
};
+template <typename T>
+struct HashMapComparatorDefault {
+ static bool compare(const T& p_lhs, const T& p_rhs) {
+ return p_lhs == p_rhs;
+ }
+
+ bool compare(const float& p_lhs, const float& p_rhs) {
+ return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
+ }
+
+ bool compare(const double& p_lhs, const double& p_rhs) {
+ return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
+ }
+};
+
/**
* @class HashMap
* @author Juan Linietsky <reduzio@gmail.com>
@@ -74,13 +79,14 @@ public:
* @param TKey Key, search is based on it, needs to be hasheable. It is unique in this container.
* @param TData Data, data associated with the key
* @param Hasher Hasher object, needs to provide a valid static hash function for TKey
+ * @param Comparator comparator object, needs to be able to safely compare two TKey values. It needs to ensure that x == x for any items inserted in the map. Bear in mind that nan != nan when implementing an equality check.
* @param MIN_HASH_TABLE_POWER Miminum size of the hash table, as a power of two. You rarely need to change this parameter.
* @param RELATIONSHIP Relationship at which the hash table is resized. if amount of elements is RELATIONSHIP
* times bigger than the hash table, table is resized to solve this condition. if RELATIONSHIP is zero, table is always MIN_HASH_TABLE_POWER.
*
*/
-template<class TKey, class TData, class Hasher=HashMapHahserDefault,uint8_t MIN_HASH_TABLE_POWER=3,uint8_t RELATIONSHIP=8>
+template<class TKey, class TData, class Hasher=HashMapHasherDefault, class Comparator=HashMapComparatorDefault<TKey>, uint8_t MIN_HASH_TABLE_POWER=3,uint8_t RELATIONSHIP=8>
class HashMap {
public:
@@ -194,7 +200,6 @@ private:
}
-
/* I want to have only one function.. */
_FORCE_INLINE_ const Entry * get_entry( const TKey& p_key ) const {
@@ -206,7 +211,7 @@ private:
while (e) {
/* checking hash first avoids comparing key, which may take longer */
- if (e->hash == hash && e->pair.key == p_key ) {
+ if (e->hash == hash && Comparator::compare(e->pair.key,p_key) ) {
/* the pair exists in this hashtable, so just update data */
return e;
@@ -253,7 +258,6 @@ private:
for (int i=0;i<( 1<<p_t.hash_table_power );i++) {
hash_table[i]=NULL;
- /* elements will be in the reverse order, but it doesn't matter */
const Entry *e = p_t.hash_table[i];
@@ -385,7 +389,7 @@ public:
while (e) {
/* checking hash first avoids comparing key, which may take longer */
- if (e->hash == hash && e->pair.key == p_custom_key ) {
+ if (e->hash == hash && Comparator::compare(e->pair.key,p_custom_key) ) {
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
@@ -411,7 +415,7 @@ public:
while (e) {
/* checking hash first avoids comparing key, which may take longer */
- if (e->hash == hash && e->pair.key == p_custom_key ) {
+ if (e->hash == hash && Comparator::compare(e->pair.key,p_custom_key) ) {
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
@@ -442,7 +446,7 @@ public:
while (e) {
/* checking hash first avoids comparing key, which may take longer */
- if (e->hash == hash && e->pair.key == p_key ) {
+ if (e->hash == hash && Comparator::compare(e->pair.key,p_key) ) {
if (p) {
@@ -637,7 +641,8 @@ public:
clear();
}
-
};
+
+
#endif
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index e9e57d8b42..121d7e8c59 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -29,7 +29,8 @@
#ifndef HASHFUNCS_H
#define HASHFUNCS_H
-
+#include "math_funcs.h"
+#include "math_defs.h"
#include "typedefs.h"
/**
@@ -69,19 +70,52 @@ static inline uint32_t hash_djb2_one_32(uint32_t p_in,uint32_t p_prev=5381) {
return ((p_prev<<5)+p_prev)+p_in;
}
+static inline uint32_t hash_one_uint64(const uint64_t p_int) {
+ uint64_t v=p_int;
+ v = (~v) + (v << 18); // v = (v << 18) - v - 1;
+ v = v ^ (v >> 31);
+ v = v * 21; // v = (v + (v << 2)) + (v << 4);
+ v = v ^ (v >> 11);
+ v = v + (v << 6);
+ v = v ^ (v >> 22);
+ return (int) v;
+}
+
static inline uint32_t hash_djb2_one_float(float p_in,uint32_t p_prev=5381) {
union {
float f;
uint32_t i;
} u;
- // handle -0 case
- if (p_in==0.0f) u.f=0.0f;
- else u.f=p_in;
+ // Normalize +/- 0.0 and NaN values so they hash the same.
+ if (p_in==0.0f)
+ u.f=0.0;
+ else if (Math::is_nan(p_in))
+ u.f=Math_NAN;
+ else
+ u.f=p_in;
return ((p_prev<<5)+p_prev)+u.i;
}
+// Overload for real_t size changes
+static inline uint32_t hash_djb2_one_float(double p_in,uint32_t p_prev=5381) {
+ union {
+ double d;
+ uint64_t i;
+ } u;
+
+ // Normalize +/- 0.0 and NaN values so they hash the same.
+ if (p_in==0.0f)
+ u.d=0.0;
+ else if (Math::is_nan(p_in))
+ u.d=Math_NAN;
+ else
+ u.d=p_in;
+
+ return ((p_prev<<5)+p_prev) + hash_one_uint64(u.i);
+}
+
template<class T>
static inline uint32_t make_uint32_t(T p_in) {
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 249c75cea0..444c55cac6 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "input_map.h"
-#include "globals.h"
+#include "global_config.h"
#include "os/keyboard.h"
InputMap *InputMap::singleton=NULL;
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp
index 32eb003228..b4ba14ddc9 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -30,7 +30,7 @@
#include "os/dir_access.h"
#include "os/copymem.h"
-#include "globals.h"
+#include "global_config.h"
#include "map.h"
static Map<String, Vector<uint8_t> >* files = NULL;
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 7bf750f6e1..d9fdc9cedc 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "file_access_network.h"
#include "marshalls.h"
-#include "globals.h"
+#include "global_config.h"
#include "os/os.h"
#include "io/ip.h"
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index d63539a7a5..fa1bebde16 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -31,7 +31,7 @@
#include <stdio.h>
-#define PACK_VERSION 0
+#define PACK_VERSION 1
Error PackedData::add_pack(const String& p_path) {
@@ -167,8 +167,8 @@ bool PackedSourcePCK::try_open_pack(const String& p_path) {
uint32_t ver_minor = f->get_32();
uint32_t ver_rev = f->get_32();
- ERR_EXPLAIN("Pack version newer than supported by engine: "+itos(version));
- ERR_FAIL_COND_V( version > PACK_VERSION, ERR_INVALID_DATA);
+ ERR_EXPLAIN("Pack version unsupported: "+itos(version));
+ ERR_FAIL_COND_V( version != PACK_VERSION, ERR_INVALID_DATA);
ERR_EXPLAIN("Pack created with a newer version of the engine: "+itos(ver_major)+"."+itos(ver_minor)+"."+itos(ver_rev));
ERR_FAIL_COND_V( ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), ERR_INVALID_DATA);
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index aca095b6a5..cf5883121f 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -29,7 +29,7 @@
#include "packet_peer.h"
#include "io/marshalls.h"
-#include "globals.h"
+#include "global_config.h"
/* helpers / binders */
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 2c02dbcc9b..2d733842fa 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "version.h"
#include "resource_format_binary.h"
-#include "globals.h"
+#include "global_config.h"
#include "io/file_access_compressed.h"
#include "io/marshalls.h"
#include "os/dir_access.h"
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index b6d28bccfa..c14389eefa 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "resource_loader.h"
#include "print_string.h"
-#include "globals.h"
+#include "global_config.h"
#include "path_remap.h"
#include "os/file_access.h"
#include "os/os.h"
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 222d3e6bc0..f0bea30051 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "resource_saver.h"
-#include "globals.h"
+#include "global_config.h"
#include "os/file_access.h"
#include "script_language.h"
#include "resource_loader.h"
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 511af91835..51877891e3 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -39,6 +39,7 @@
#define Math_PI 3.14159265358979323846
#define Math_SQRT12 0.7071067811865475244008443621048490
#define Math_LN2 0.693147180559945309417
+#define Math_NAN NAN
class Math {
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index 668d321e05..50b52e4970 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "message_queue.h"
-#include "globals.h"
+#include "global_config.h"
#include "script_language.h"
MessageQueue *MessageQueue::singleton=NULL;
diff --git a/core/object.h b/core/object.h
index ba4fa62e1a..3fe31bee6b 100644
--- a/core/object.h
+++ b/core/object.h
@@ -680,7 +680,7 @@ class ObjectDB {
unsigned long i;
} u;
u.p=p_obj;
- return HashMapHahserDefault::hash((uint64_t)u.i);
+ return HashMapHasherDefault::hash((uint64_t)u.i);
}
};
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 804fe15c39..974225a3e8 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -30,7 +30,7 @@
#include "os/file_access.h"
#include "os/memory.h"
#include "os/os.h"
-#include "globals.h"
+#include "global_config.h"
String DirAccess::_get_root_path() const {
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 06723c5131..ae592720e8 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "file_access.h"
-#include "globals.h"
+#include "global_config.h"
#include "os/os.h"
#include "core/io/marshalls.h"
#include "io/md5.h"
diff --git a/core/os/input.cpp b/core/os/input.cpp
index e20c966ff2..34883e63ba 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -29,7 +29,7 @@
#include "input.h"
#include "input_map.h"
#include "os/os.h"
-#include "globals.h"
+#include "global_config.h"
Input *Input::singleton=NULL;
Input *Input::get_singleton() {
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 3a8e15a692..912f7f0b0f 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -29,7 +29,7 @@
#include "os.h"
#include "dir_access.h"
-#include "globals.h"
+#include "global_config.h"
#include "input.h"
#include "os/file_access.h"
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index ab94b56cdc..00f6f8662f 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -35,7 +35,7 @@
#include "io/packet_peer.h"
#include "math/a_star.h"
#include "math/triangle_mesh.h"
-#include "globals.h"
+#include "global_config.h"
#include "class_db.h"
#include "geometry.h"
#include "bind/core_bind.h"
diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp
index 62d14c4e5a..b14eb51b6c 100644
--- a/core/script_debugger_remote.cpp
+++ b/core/script_debugger_remote.cpp
@@ -30,7 +30,7 @@
#include "os/os.h"
#include "io/ip.h"
-#include "globals.h"
+#include "global_config.h"
#include "os/input.h"
void ScriptDebuggerRemote::_send_video_memory() {
diff --git a/core/translation.cpp b/core/translation.cpp
index 655bfd36b8..d9d4fe7784 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "translation.h"
-#include "globals.h"
+#include "global_config.h"
#include "io/resource_loader.h"
#include "os/os.h"
diff --git a/core/ustring.cpp b/core/ustring.cpp
index a0d26ea0af..7d88989d04 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -52,8 +52,40 @@
#define UPPERCASE(m_c) (((m_c)>='a' && (m_c)<='z')?((m_c)-('a'-'A')):(m_c))
#define LOWERCASE(m_c) (((m_c)>='A' && (m_c)<='Z')?((m_c)+('a'-'A')):(m_c))
+
+
+
/** STRING **/
+bool CharString::operator<(const CharString& p_right) const {
+
+ if (length()==0) {
+ return p_right.length()!=0;
+ }
+
+
+ const char *this_str=get_data();
+ const char *that_str=get_data();
+ while (true) {
+
+ if (*that_str==0 && *this_str==0)
+ return false; //this can't be equal, sadly
+ else if (*this_str==0)
+ return true; //if this is empty, and the other one is not, then we're less.. I think?
+ else if (*that_str==0)
+ return false; //otherwise the other one is smaller..
+ else if (*this_str < *that_str ) //more than
+ return true;
+ else if (*this_str > *that_str ) //less than
+ return false;
+
+ this_str++;
+ that_str++;
+ }
+
+ return false; //should never reach here anyway
+}
+
const char *CharString::get_data() const {
if (size())
@@ -4069,12 +4101,8 @@ String String::sprintf(const Array& values, bool* error) const {
case 'X': base = 16; capitalize = true; break;
}
// Get basic number.
- String str = String::num_int64(value, base, capitalize);
-
- // Sign.
- if (show_sign && value >= 0) {
- str = str.insert(0, "+");
- }
+ String str = String::num_int64(ABS(value), base, capitalize);
+ int number_len = str.length();
// Padding.
String pad_char = pad_with_zeroes ? String("0") : String(" ");
@@ -4084,6 +4112,13 @@ String String::sprintf(const Array& values, bool* error) const {
str = str.lpad(min_chars, pad_char);
}
+ // Sign.
+ if (show_sign && value >= 0) {
+ str = str.insert(pad_with_zeroes?0:str.length()-number_len, "+");
+ } else if (value < 0) {
+ str = str.insert(pad_with_zeroes?0:str.length()-number_len, "-");
+ }
+
formatted += str;
++value_index;
in_format = false;
diff --git a/core/ustring.h b/core/ustring.h
index 5665a23112..87289f9e16 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -41,6 +41,8 @@
class CharString : public Vector<char> {
public:
+
+ bool operator<(const CharString& p_right) const;
int length() const { return size() ? size()-1 : 0; }
const char *get_data() const;
operator const char*() {return get_data();};
diff --git a/core/variant.cpp b/core/variant.cpp
index 103c8f6746..132d7a1c88 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -28,6 +28,7 @@
/*************************************************************************/
#include "variant.h"
+#include "math_funcs.h"
#include "resource.h"
#include "print_string.h"
#include "scene/main/node.h"
@@ -2674,14 +2675,10 @@ uint32_t Variant::hash() const {
case INT: {
return _data._int;
-
} break;
case REAL: {
- MarshallFloat mf;
- mf.f=_data._real;
- return mf.i;
-
+ return hash_djb2_one_float(_data._real);
} break;
case STRING: {
@@ -2921,6 +2918,186 @@ uint32_t Variant::hash() const {
}
+#define hash_compare_scalar(p_lhs, p_rhs)\
+ ((p_lhs) == (p_rhs)) || (Math::is_nan(p_lhs) == Math::is_nan(p_rhs))
+
+#define hash_compare_vector2(p_lhs, p_rhs)\
+ (hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
+ (hash_compare_scalar((p_lhs).y, (p_rhs).y))
+
+#define hash_compare_vector3(p_lhs, p_rhs)\
+ (hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
+ (hash_compare_scalar((p_lhs).y, (p_rhs).y)) && \
+ (hash_compare_scalar((p_lhs).z, (p_rhs).z))
+
+#define hash_compare_quat(p_lhs, p_rhs)\
+ (hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
+ (hash_compare_scalar((p_lhs).y, (p_rhs).y)) && \
+ (hash_compare_scalar((p_lhs).z, (p_rhs).z)) && \
+ (hash_compare_scalar((p_lhs).w, (p_rhs).w))
+
+#define hash_compare_color(p_lhs, p_rhs)\
+ (hash_compare_scalar((p_lhs).r, (p_rhs).r)) && \
+ (hash_compare_scalar((p_lhs).g, (p_rhs).g)) && \
+ (hash_compare_scalar((p_lhs).b, (p_rhs).b)) && \
+ (hash_compare_scalar((p_lhs).a, (p_rhs).a))
+
+#define hash_compare_pool_array(p_lhs, p_rhs, p_type, p_compare_func)\
+ const PoolVector<p_type>& l = *reinterpret_cast<const PoolVector<p_type>*>(p_lhs);\
+ const PoolVector<p_type>& r = *reinterpret_cast<const PoolVector<p_type>*>(p_rhs);\
+ \
+ if(l.size() != r.size()) \
+ return false; \
+ \
+ PoolVector<p_type>::Read lr = l.read(); \
+ PoolVector<p_type>::Read rr = r.read(); \
+ \
+ for(int i = 0; i < l.size(); ++i) { \
+ if(! p_compare_func((lr[0]), (rr[0]))) \
+ return false; \
+ }\
+ \
+ return true
+
+bool Variant::hash_compare(const Variant& p_variant) const {
+ if (type != p_variant.type)
+ return false;
+
+ switch( type ) {
+ case REAL: {
+ return hash_compare_scalar(_data._real, p_variant._data._real);
+ } break;
+
+ case VECTOR2: {
+ const Vector2* l = reinterpret_cast<const Vector2*>(_data._mem);
+ const Vector2* r = reinterpret_cast<const Vector2*>(p_variant._data._mem);
+
+ return hash_compare_vector2(*l, *r);
+ } break;
+
+ case RECT2: {
+ const Rect2* l = reinterpret_cast<const Rect2*>(_data._mem);
+ const Rect2* r = reinterpret_cast<const Rect2*>(p_variant._data._mem);
+
+ return (hash_compare_vector2(l->pos, r->pos)) &&
+ (hash_compare_vector2(l->size, r->size));
+ } break;
+
+ case TRANSFORM2D: {
+ Transform2D* l = _data._transform2d;
+ Transform2D* r = p_variant._data._transform2d;
+
+ for(int i=0;i<3;i++) {
+ if (! (hash_compare_vector2(l->elements[i], r->elements[i])))
+ return false;
+ }
+
+ return true;
+ } break;
+
+ case VECTOR3: {
+ const Vector3* l = reinterpret_cast<const Vector3*>(_data._mem);
+ const Vector3* r = reinterpret_cast<const Vector3*>(p_variant._data._mem);
+
+ return hash_compare_vector3(*l, *r);
+ } break;
+
+ case PLANE: {
+ const Plane* l = reinterpret_cast<const Plane*>(_data._mem);
+ const Plane* r = reinterpret_cast<const Plane*>(p_variant._data._mem);
+
+ return (hash_compare_vector3(l->normal, r->normal)) &&
+ (hash_compare_scalar(l->d, r->d));
+ } break;
+
+ case RECT3: {
+ const Rect3* l = _data._rect3;
+ const Rect3* r = p_variant._data._rect3;
+
+ return (hash_compare_vector3(l->pos, r->pos) &&
+ (hash_compare_vector3(l->size, r->size)));
+
+ } break;
+
+ case QUAT: {
+ const Quat* l = reinterpret_cast<const Quat*>(_data._mem);
+ const Quat* r = reinterpret_cast<const Quat*>(p_variant._data._mem);
+
+ return hash_compare_quat(*l, *r);
+ } break;
+
+ case BASIS: {
+ const Basis* l = _data._basis;
+ const Basis* r = p_variant._data._basis;
+
+ for(int i=0;i<3;i++) {
+ if (! (hash_compare_vector3(l->elements[i], r->elements[i])))
+ return false;
+ }
+
+ return true;
+ } break;
+
+ case TRANSFORM: {
+ const Transform* l = _data._transform;
+ const Transform* r = p_variant._data._transform;
+
+ for(int i=0;i<3;i++) {
+ if (! (hash_compare_vector3(l->basis.elements[i], r->basis.elements[i])))
+ return false;
+ }
+
+ return hash_compare_vector3(l->origin, r->origin);
+ } break;
+
+ case COLOR: {
+ const Color* l = reinterpret_cast<const Color*>(_data._mem);
+ const Color* r = reinterpret_cast<const Color*>(p_variant._data._mem);
+
+ return hash_compare_color(*l, *r);
+ } break;
+
+ case ARRAY: {
+ const Array& l = *(reinterpret_cast<const Array*>(_data._mem));
+ const Array& r = *(reinterpret_cast<const Array*>(p_variant._data._mem));
+
+ if(l.size() != r.size())
+ return false;
+
+ for(int i = 0; i < l.size(); ++i) {
+ if(! l[0].hash_compare(r[0]))
+ return false;
+ }
+
+ return true;
+ } break;
+
+ case POOL_REAL_ARRAY: {
+ hash_compare_pool_array(_data._mem, p_variant._data._mem, real_t, hash_compare_scalar);
+ } break;
+
+ case POOL_VECTOR2_ARRAY: {
+ hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector2, hash_compare_vector2);
+ } break;
+
+ case POOL_VECTOR3_ARRAY: {
+ hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector3, hash_compare_vector3);
+ } break;
+
+ case POOL_COLOR_ARRAY: {
+ hash_compare_pool_array(_data._mem, p_variant._data._mem, Color, hash_compare_color);
+ } break;
+
+ default:
+ bool v;
+ Variant r;
+ evaluate(OP_EQUAL,*this,p_variant,r,v);
+ return r;
+ }
+
+ return false;
+}
+
bool Variant::is_ref() const {
diff --git a/core/variant.h b/core/variant.h
index 5936325c1b..f9ceca1ca0 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -421,6 +421,7 @@ public:
bool operator<(const Variant& p_variant) const;
uint32_t hash() const;
+ bool hash_compare(const Variant& p_variant) const;
bool booleanize(bool &valid) const;
void static_assign(const Variant& p_variant);
@@ -459,6 +460,10 @@ struct VariantHasher {
static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); }
};
+struct VariantComparator {
+
+ static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); }
+};
Variant::ObjData& Variant::_get_obj() {