aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp31
-rw-r--r--core/bind/core_bind.h8
-rw-r--r--core/dvector.h2
-rw-r--r--core/image.cpp2
-rw-r--r--core/input_map.cpp12
-rw-r--r--core/input_map.h2
-rw-r--r--core/io/config_file.cpp5
-rw-r--r--core/io/config_file.h2
-rw-r--r--core/io/resource_format_binary.cpp100
-rw-r--r--core/io/resource_format_binary.h1
-rw-r--r--core/io/resource_import.cpp238
-rw-r--r--core/io/resource_import.h76
-rw-r--r--core/io/resource_loader.cpp145
-rw-r--r--core/io/resource_loader.h9
-rw-r--r--core/math/a_star.cpp18
-rw-r--r--core/math/a_star.h8
-rw-r--r--core/math/audio_frame.h33
-rw-r--r--core/math/bsp_tree.cpp30
-rw-r--r--core/math/bsp_tree.h8
-rw-r--r--core/math/camera_matrix.cpp64
-rw-r--r--core/math/camera_matrix.h24
-rw-r--r--core/math/face3.cpp56
-rw-r--r--core/math/face3.h22
-rw-r--r--core/math/geometry.cpp22
-rw-r--r--core/math/geometry.h120
-rw-r--r--core/math/math_2d.cpp6
-rw-r--r--core/math/math_funcs.cpp87
-rw-r--r--core/math/math_funcs.h232
-rw-r--r--core/math/matrix3.cpp20
-rw-r--r--core/math/octree.h2
-rw-r--r--core/math/pcg.cpp15
-rw-r--r--core/math/pcg.h14
-rw-r--r--core/math/plane.h2
-rw-r--r--core/math/quat.cpp18
-rw-r--r--core/math/quat.h4
-rw-r--r--core/math/quick_hull.cpp6
-rw-r--r--core/math/rect3.cpp10
-rw-r--r--core/math/rect3.h24
-rw-r--r--core/math/triangle_mesh.cpp4
-rw-r--r--core/math/triangulate.cpp24
-rw-r--r--core/math/triangulate.h10
-rw-r--r--core/math/vector3.cpp74
-rw-r--r--core/math/vector3.h16
-rw-r--r--core/method_ptrcall.h16
-rw-r--r--core/object.h1
-rw-r--r--core/os/input.cpp3
-rw-r--r--core/os/input.h3
-rw-r--r--core/os/os.h3
-rw-r--r--core/pair.h9
-rw-r--r--core/path_remap.cpp182
-rw-r--r--core/path_remap.h35
-rw-r--r--core/register_core_types.cpp11
-rw-r--r--core/resource.cpp132
-rw-r--r--core/resource.h54
-rw-r--r--core/translation.cpp14
-rw-r--r--core/translation.h1
-rw-r--r--core/ustring.cpp16
-rw-r--r--core/ustring.h1
-rw-r--r--core/variant_parser.cpp10
59 files changed, 942 insertions, 1155 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index d4f61b7ff..636a3f07c 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -106,17 +106,12 @@ bool _ResourceLoader::has(const String &p_path) {
return ResourceCache::has(local_path);
};
-Ref<ResourceImportMetadata> _ResourceLoader::load_import_metadata(const String& p_path) {
-
- return ResourceLoader::load_import_metadata(p_path);
-}
void _ResourceLoader::_bind_methods() {
ClassDB::bind_method(_MD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL(""));
ClassDB::bind_method(_MD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false));
- ClassDB::bind_method(_MD("load_import_metadata:ResourceImportMetadata","path"),&_ResourceLoader::load_import_metadata);
ClassDB::bind_method(_MD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type);
ClassDB::bind_method(_MD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources);
ClassDB::bind_method(_MD("get_dependencies","path"),&_ResourceLoader::get_dependencies);
@@ -1732,6 +1727,11 @@ Variant _File::get_var() const {
return v;
}
+uint64_t _File::get_modified_time(const String &p_file) const {
+
+ return FileAccess::get_modified_time(p_file);
+}
+
void _File::_bind_methods() {
@@ -1780,6 +1780,7 @@ void _File::_bind_methods() {
ClassDB::bind_method(_MD("get_pascal_string"),&_File::get_pascal_string);
ClassDB::bind_method(_MD("file_exists","path"),&_File::file_exists);
+ ClassDB::bind_method(_MD("get_modified_time", "file"),&_File::get_modified_time);
BIND_CONSTANT( READ );
BIND_CONSTANT( WRITE );
@@ -1819,16 +1820,28 @@ Error _Directory::open(const String& p_path) {
return OK;
}
-Error _Directory::list_dir_begin() {
+Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) {
ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
+
+ _list_skip_navigational = p_skip_navigational;
+ _list_skip_hidden = p_skip_hidden;
+
return d->list_dir_begin();
}
String _Directory::get_next(){
ERR_FAIL_COND_V(!d,"");
- return d->get_next();
+
+ String next = d->get_next();
+ while (next != ""
+ && ((_list_skip_navigational && (next == "." || next == ".."))
+ || (_list_skip_hidden && d->current_is_hidden()))) {
+
+ next = d->get_next();
+ }
+ return next;
}
bool _Directory::current_is_dir() const{
@@ -1958,7 +1971,7 @@ void _Directory::_bind_methods() {
ClassDB::bind_method(_MD("open:Error","path"),&_Directory::open);
- ClassDB::bind_method(_MD("list_dir_begin"),&_Directory::list_dir_begin);
+ ClassDB::bind_method(_MD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false));
ClassDB::bind_method(_MD("get_next"),&_Directory::get_next);
ClassDB::bind_method(_MD("current_is_dir"),&_Directory::current_is_dir);
ClassDB::bind_method(_MD("list_dir_end"),&_Directory::list_dir_end);
@@ -2499,7 +2512,7 @@ void _ClassDB::_bind_methods() {
ClassDB::bind_method(_MD("class_exists","class"),&_ClassDB::class_exists);
ClassDB::bind_method(_MD("is_parent_class","class","inherits"),&_ClassDB::is_parent_class);
ClassDB::bind_method(_MD("can_instance","class"),&_ClassDB::can_instance);
- ClassDB::bind_method(_MD("instance","class"),&_ClassDB::instance);
+ ClassDB::bind_method(_MD("instance:Variant","class"),&_ClassDB::instance);
ClassDB::bind_method(_MD("class_has_signal","class","signal"),&_ClassDB::has_signal);
ClassDB::bind_method(_MD("class_get_signal","class","signal"),&_ClassDB::get_signal);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index f10714720..00cbb254d 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -54,7 +54,6 @@ public:
void set_abort_on_missing_resources(bool p_abort);
PoolStringArray get_dependencies(const String& p_path);
bool has(const String& p_path);
- Ref<ResourceImportMetadata> load_import_metadata(const String& p_path);
_ResourceLoader();
};
@@ -440,6 +439,8 @@ public:
bool file_exists(const String& p_name) const; ///< return true if a file exists
+ uint64_t get_modified_time(const String& p_file) const;
+
_File();
virtual ~_File();
@@ -456,7 +457,7 @@ public:
Error open(const String& p_path);
- Error list_dir_begin(); ///< This starts dir listing
+ Error list_dir_begin(bool p_skip_internal = false, bool p_skip_hidden = false); ///< This starts dir listing
String get_next();
bool current_is_dir() const;
@@ -485,6 +486,9 @@ public:
_Directory();
virtual ~_Directory();
+private:
+ bool _list_skip_navigational;
+ bool _list_skip_hidden;
};
class _Marshalls : public Reference {
diff --git a/core/dvector.h b/core/dvector.h
index cac9e8ef8..53a29738f 100644
--- a/core/dvector.h
+++ b/core/dvector.h
@@ -89,7 +89,7 @@ class PoolVector {
if (!alloc)
return;
- ERR_FAIL_COND(alloc->lock>0);
+// ERR_FAIL_COND(alloc->lock>0); should not be illegal to lock this for copy on write, as it's a copy on write after all
if (alloc->refcount.get()==1)
return; //nothing to do
diff --git a/core/image.cpp b/core/image.cpp
index ed505b0f7..2d038691f 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -2155,7 +2155,7 @@ void Image::fix_alpha_edges() {
return; //not needed
PoolVector<uint8_t> dcopy = data;
- PoolVector<uint8_t>::Read rp = data.read();
+ PoolVector<uint8_t>::Read rp = dcopy.read();
const uint8_t *srcptr=rp.ptr();
PoolVector<uint8_t>::Write wp = data.write();
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 8473bce80..dcce13ba1 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -107,7 +107,7 @@ List<StringName> InputMap::get_actions() const {
return actions;
}
-List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore=false) const {
+List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_action_test) const {
for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) {
@@ -123,7 +123,13 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const
case InputEvent::KEY: {
- same=(e.key.scancode==p_event.key.scancode && (p_mod_ignore || e.key.mod == p_event.key.mod));
+ if(p_action_test) {
+ uint32_t code = e.key.get_scancode_with_modifiers();
+ uint32_t event_code = p_event.key.get_scancode_with_modifiers();
+ same=(e.key.scancode==p_event.key.scancode && (!p_event.key.pressed || ((code & event_code) == code)));
+ } else {
+ same=(e.key.scancode==p_event.key.scancode && e.key.mod == p_event.key.mod);
+ }
} break;
case InputEvent::JOYPAD_BUTTON: {
@@ -230,7 +236,7 @@ bool InputMap::event_is_action(const InputEvent& p_event, const StringName& p_ac
return p_event.action.action==E->get().id;
}
- return _find_event(E->get().inputs,p_event,!p_event.is_pressed())!=NULL;
+ return _find_event(E->get().inputs,p_event,true)!=NULL;
}
const Map<StringName, InputMap::Action>& InputMap::get_action_map() const {
diff --git a/core/input_map.h b/core/input_map.h
index 306845fc8..6ccd24f29 100644
--- a/core/input_map.h
+++ b/core/input_map.h
@@ -46,7 +46,7 @@ private:
mutable Map<StringName, Action> input_map;
mutable Map<int,StringName> input_id_map;
- List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore) const;
+ List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_action_test=false) const;
Array _get_action_list(const StringName& p_action);
Array _get_actions();
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index a9de74080..b944906e7 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -119,7 +119,10 @@ void ConfigFile::get_section_keys(const String& p_section,List<String> *r_keys)
}
+void ConfigFile::erase_section(const String& p_section) {
+ values.erase(p_section);
+}
Error ConfigFile::save(const String& p_path){
@@ -215,6 +218,8 @@ void ConfigFile::_bind_methods(){
ClassDB::bind_method(_MD("get_sections"),&ConfigFile::_get_sections);
ClassDB::bind_method(_MD("get_section_keys","section"),&ConfigFile::_get_section_keys);
+ ClassDB::bind_method(_MD("erase_section","section"),&ConfigFile::erase_section);
+
ClassDB::bind_method(_MD("load:Error","path"),&ConfigFile::load);
ClassDB::bind_method(_MD("save:Error","path"),&ConfigFile::save);
diff --git a/core/io/config_file.h b/core/io/config_file.h
index 397342f90..c9c4a9fbc 100644
--- a/core/io/config_file.h
+++ b/core/io/config_file.h
@@ -54,6 +54,8 @@ public:
void get_sections(List<String> *r_sections) const;
void get_section_keys(const String& p_section,List<String> *r_keys) const;
+ void erase_section(const String& p_section);
+
Error save(const String& p_path);
Error load(const String& p_path);
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 4af350343..c75e47676 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -80,7 +80,8 @@ enum {
OBJECT_EXTERNAL_RESOURCE=1,
OBJECT_INTERNAL_RESOURCE=2,
OBJECT_EXTERNAL_RESOURCE_INDEX=3,
- FORMAT_VERSION=1,
+ //version 2: added 64 bits support for float and int
+ FORMAT_VERSION=2,
FORMAT_VERSION_CAN_RENAME_DEPS=1
@@ -758,30 +759,7 @@ Error ResourceInteractiveLoaderBinary::poll(){
resource_cache.push_back(res);
if (main) {
- if (importmd_ofs) {
- f->seek(importmd_ofs);
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- imd->set_editor(get_unicode_string());
- int sc = f->get_32();
- for(int i=0;i<sc;i++) {
-
- String src = get_unicode_string();
- String md5 = get_unicode_string();
- imd->add_source(src,md5);
- }
- int pc = f->get_32();
-
- for(int i=0;i<pc;i++) {
-
- String name = get_unicode_string();
- Variant val;
- parse_variant(val);
- imd->set_option(name,val);
- }
- res->set_import_metadata(imd);
-
- }
f->close();
resource=res;
error=ERR_FILE_EOF;
@@ -848,9 +826,6 @@ void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f,List<Stri
for(int i=0;i<external_resources.size();i++) {
String dep=external_resources[i].path;
- if (dep.ends_with("*")) {
- dep=ResourceLoader::guess_full_filename(dep,external_resources[i].type);
- }
if (p_add_types && external_resources[i].type!=String()) {
dep+="::"+external_resources[i].type;
@@ -1103,53 +1078,6 @@ bool ResourceFormatLoaderBinary::handles_type(const String& p_type) const{
return true; //handles all
}
-Error ResourceFormatLoaderBinary::load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const {
-
-
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
- if (!f) {
- return ERR_FILE_CANT_OPEN;
- }
-
- Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
- ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
- //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- ria->recognize(f);
- if(ria->error!=OK)
- return ERR_FILE_UNRECOGNIZED;
- f=ria->f;
- uint64_t imp_ofs = f->get_64();
-
- if (imp_ofs==0)
- return ERR_UNAVAILABLE;
-
- f->seek(imp_ofs);
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- imd->set_editor(ria->get_unicode_string());
- int sc = f->get_32();
- for(int i=0;i<sc;i++) {
-
- String src = ria->get_unicode_string();
- String md5 = ria->get_unicode_string();
- imd->add_source(src,md5);
- }
- int pc = f->get_32();
-
- for(int i=0;i<pc;i++) {
-
- String name = ria->get_unicode_string();
- Variant val;
- ria->parse_variant(val);
- imd->set_option(name,val);
- }
-
- r_var=imd;
-
- return OK;
-
-}
-
void ResourceFormatLoaderBinary::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types) {
@@ -2178,30 +2106,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
}
f->seek_end();
- print_line("SAVING: "+p_path);
- if (p_resource->get_import_metadata().is_valid()) {
- uint64_t md_pos = f->get_pos();
- Ref<ResourceImportMetadata> imd=p_resource->get_import_metadata();
- save_unicode_string(imd->get_editor());
- f->store_32(imd->get_source_count());
- for(int i=0;i<imd->get_source_count();i++) {
- save_unicode_string(imd->get_source_path(i));
- save_unicode_string(imd->get_source_md5(i));
- print_line("SAVE PATH: "+imd->get_source_path(i));
- print_line("SAVE MD5: "+imd->get_source_md5(i));
- }
- List<String> options;
- imd->get_options(&options);
- f->store_32(options.size());
- for(List<String>::Element *E=options.front();E;E=E->next()) {
- save_unicode_string(E->get());
- write_variant(imd->get_option(E->get()));
- }
-
- f->seek(md_at);
- f->store_64(md_pos);
- f->seek_end();
- }
f->store_buffer((const uint8_t*)"RSRC",4); //magic at end
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index 611029e79..1dac51cc5 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -109,7 +109,6 @@ public:
virtual bool handles_type(const String& p_type) const;
virtual String get_resource_type(const String &p_path) const;
virtual void get_dependencies(const String& p_path, List<String> *p_dependencies, bool p_add_types=false);
- virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const;
virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp
new file mode 100644
index 000000000..d0799cdbe
--- /dev/null
+++ b/core/io/resource_import.cpp
@@ -0,0 +1,238 @@
+#include "resource_import.h"
+#include "variant_parser.h"
+
+Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndType &r_path_and_type) const {
+
+ Error err;
+ FileAccess *f= FileAccess::open(p_path+".import",FileAccess::READ,&err);
+
+ if (!f)
+ return err;
+
+ VariantParser::StreamFile stream;
+ stream.f=f;
+
+ String assign;
+ Variant value;
+ VariantParser::Tag next_tag;
+
+ int lines=0;
+ String error_text;
+ while(true) {
+
+ assign=Variant();
+ next_tag.fields.clear();
+ next_tag.name=String();
+
+ err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL,true);
+ if (err==ERR_FILE_EOF) {
+ memdelete(f);
+ return OK;
+ }
+ else if (err!=OK) {
+ ERR_PRINTS("ResourceFormatImporter::load - "+p_path+".import:"+itos(lines)+" error: "+error_text);
+ memdelete(f);
+ return err;
+ }
+
+ if (assign!=String()) {
+ if (assign=="path") {
+ r_path_and_type.path=value;
+ } else if (assign=="type") {
+ r_path_and_type.type=value;
+ }
+
+ } else if (next_tag.name!="remap") {
+ break;
+ }
+ }
+
+ memdelete(f);
+
+ if (r_path_and_type.path==String() || r_path_and_type.type==String()) {
+ return ERR_FILE_CORRUPT;
+ }
+ return OK;
+
+}
+
+
+RES ResourceFormatImporter::load(const String &p_path,const String& p_original_path,Error *r_error) {
+
+ PathAndType pat;
+ Error err = _get_path_and_type(p_path,pat);
+
+ if (err!=OK) {
+
+ if (r_error)
+ *r_error=err;
+
+ return RES();
+ }
+
+
+ RES res = ResourceLoader::load(pat.path,pat.type,false,r_error);
+
+#ifdef TOOLS_ENABLED
+ res->set_import_last_modified_time( res->get_last_modified_time() ); //pass this, if used
+ res->set_import_path(pat.path);
+#endif
+
+ return res;
+
+}
+
+void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const{
+
+ print_line("getting exts from: "+itos(importers.size()));
+ Set<String> found;
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (!found.has(F->get())) {
+ print_line("adding ext "+String(F->get()));
+ p_extensions->push_back(F->get());
+ found.insert(F->get());
+ }
+ }
+ }
+}
+
+void ResourceFormatImporter::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const{
+
+ if (p_type=="") {
+ return get_recognized_extensions(p_extensions);
+ }
+
+ Set<String> found;
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ String res_type = E->get()->get_resource_type();
+ if (res_type==String())
+ continue;
+
+ if (!ClassDB::is_parent_class(res_type,p_type))
+ continue;
+
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (!found.has(F->get())) {
+ p_extensions->push_back(F->get());
+ found.insert(F->get());
+ }
+ }
+ }
+}
+
+bool ResourceFormatImporter::recognize_path(const String& p_path,const String& p_for_type) const{
+
+ return FileAccess::exists(p_path+".import");
+
+}
+
+bool ResourceFormatImporter::can_be_imported(const String& p_path) const {
+
+ return ResourceFormatLoader::recognize_path(p_path);
+}
+
+
+bool ResourceFormatImporter::handles_type(const String& p_type) const {
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+
+ String res_type = E->get()->get_resource_type();
+ if (res_type==String())
+ continue;
+ if (ClassDB::is_parent_class(res_type,p_type))
+ return true;
+
+ }
+
+ return true;
+}
+
+String ResourceFormatImporter::get_resource_type(const String &p_path) const {
+
+ PathAndType pat;
+ Error err = _get_path_and_type(p_path,pat);
+
+ if (err!=OK) {
+
+ return "";
+ }
+
+ return pat.type;
+}
+
+void ResourceFormatImporter::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types){
+
+ PathAndType pat;
+ Error err = _get_path_and_type(p_path,pat);
+
+ if (err!=OK) {
+
+ return;
+ }
+
+ return ResourceLoader::get_dependencies(pat.path,p_dependencies,p_add_types);
+}
+
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String& p_name) {
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ if (E->get()->get_importer_name()==p_name) {
+ return E->get();
+ }
+ }
+
+ return Ref<ResourceImporter>();
+}
+
+
+void ResourceFormatImporter::get_importers_for_extension(const String& p_extension,List<Ref<ResourceImporter> > *r_importers) {
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (p_extension.to_lower()==F->get()) {
+ r_importers->push_back(E->get());
+ }
+ }
+ }
+}
+
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String& p_extension) {
+
+
+ Ref<ResourceImporter> importer;
+ float priority=0;
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (p_extension.to_lower()==F->get() && E->get()->get_priority() > priority) {
+ importer=E->get();
+ priority=E->get()->get_priority();
+ }
+ }
+ }
+
+ return importer;
+}
+
+String ResourceFormatImporter::get_import_base_path(const String& p_for_file) const {
+
+ return "res://.import/"+p_for_file.get_file()+"-"+p_for_file.md5_text();
+}
+
+ResourceFormatImporter *ResourceFormatImporter::singleton=NULL;
+
+ResourceFormatImporter::ResourceFormatImporter() {
+ singleton=this;
+}
diff --git a/core/io/resource_import.h b/core/io/resource_import.h
new file mode 100644
index 000000000..939cecfbd
--- /dev/null
+++ b/core/io/resource_import.h
@@ -0,0 +1,76 @@
+#ifndef RESOURCE_IMPORT_H
+#define RESOURCE_IMPORT_H
+
+
+#include "io/resource_loader.h"
+class ResourceImporter;
+
+class ResourceFormatImporter : public ResourceFormatLoader {
+
+ struct PathAndType {
+ String path;
+ String type;
+ };
+
+
+ Error _get_path_and_type(const String& p_path,PathAndType & r_path_and_type) const;
+
+ static ResourceFormatImporter *singleton;
+
+ Set< Ref<ResourceImporter> > importers;
+public:
+
+ static ResourceFormatImporter *get_singleton() { return singleton; }
+ virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
+ virtual bool recognize_path(const String& p_path,const String& p_for_type=String()) const;
+ virtual bool handles_type(const String& p_type) const;
+ virtual String get_resource_type(const String &p_path) const;
+ virtual void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);
+
+ virtual bool can_be_imported(const String& p_path) const;
+
+
+ void add_importer(const Ref<ResourceImporter>& p_importer) { importers.insert(p_importer); }
+ Ref<ResourceImporter> get_importer_by_name(const String& p_name);
+ Ref<ResourceImporter> get_importer_by_extension(const String& p_extension);
+ void get_importers_for_extension(const String& p_extension,List<Ref<ResourceImporter> > *r_importers);
+
+ String get_import_base_path(const String& p_for_file) const;
+ ResourceFormatImporter();
+};
+
+
+class ResourceImporter : public Reference {
+
+ GDCLASS(ResourceImporter,Reference)
+public:
+ virtual String get_importer_name() const=0;
+ virtual String get_visible_name() const=0;
+ virtual void get_recognized_extensions(List<String> *p_extensions) const=0;
+ virtual String get_save_extension() const=0;
+ virtual String get_resource_type() const=0;
+ virtual float get_priority() const { return 1.0; }
+
+ struct ImportOption {
+ PropertyInfo option;
+ Variant default_value;
+
+ ImportOption(const PropertyInfo& p_info,const Variant& p_default) { option=p_info; default_value=p_default; }
+ ImportOption() {}
+ };
+
+
+ virtual int get_preset_count() const { return 0; }
+ virtual String get_preset_name(int p_idx) const { return String(); }
+
+ virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const=0;
+ virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const=0;
+
+
+ virtual Error import(const String& p_source_file,const String& p_save_path,const Map<StringName,Variant>& p_options,List<String>* r_platform_variants,List<String>* r_gen_files=NULL)=0;
+
+};
+
+#endif // RESOURCE_IMPORT_H
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 354efaa83..fbf6a2cea 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -47,21 +47,29 @@ Error ResourceInteractiveLoader::wait() {
return err;
}
+bool ResourceFormatLoader::recognize_path(const String& p_path,const String& p_for_type) const {
-bool ResourceFormatLoader::recognize(const String& p_extension) const {
+ String extension = p_path.get_extension();
List<String> extensions;
- get_recognized_extensions(&extensions);
+ if (p_for_type==String()) {
+ get_recognized_extensions(&extensions);
+ } else {
+ get_recognized_extensions_for_type(p_for_type,&extensions);
+ }
+
for (List<String>::Element *E=extensions.front();E;E=E->next()) {
- if (E->get().nocasecmp_to(p_extension.get_extension())==0)
+ if (E->get().nocasecmp_to(extension)==0)
return true;
}
return false;
+
}
+
void ResourceFormatLoader::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const {
if (p_type=="" || handles_type(p_type))
@@ -166,7 +174,7 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- local_path=find_complete_path(local_path,p_type_hint);
+
ERR_FAIL_COND_V(local_path=="",RES());
if (!p_no_cache && ResourceCache::has(local_path)) {
@@ -177,22 +185,16 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
return RES( ResourceCache::get(local_path ) );
}
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
-
if (OS::get_singleton()->is_stdout_verbose())
- print_line("load resource: "+remapped_path);
-
- String extension=remapped_path.get_extension();
+ print_line("load resource: "+local_path);
bool found=false;
for (int i=0;i<loader_count;i++) {
- if (!loader[i]->recognize(extension))
- continue;
- if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
+ if (!loader[i]->recognize_path(local_path,p_type_hint))
continue;
found=true;
- RES res = loader[i]->load(remapped_path,local_path,r_error);
+ RES res = loader[i]->load(local_path,local_path,r_error);
if (res.is_null())
continue;
if (!p_no_cache)
@@ -201,7 +203,7 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
res->set_edited(false);
if (timestamp_on_load) {
- uint64_t mt = FileAccess::get_modified_time(remapped_path);
+ uint64_t mt = FileAccess::get_modified_time(local_path);
//printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt);
res->set_last_modified_time(mt);
}
@@ -220,82 +222,6 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
}
-Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p_path) {
-
-
-
- String local_path;
- if (p_path.is_rel_path())
- local_path="res://"+p_path;
- else
- local_path = GlobalConfig::get_singleton()->localize_path(p_path);
-
- String extension=p_path.get_extension();
- Ref<ResourceImportMetadata> ret;
-
- for (int i=0;i<loader_count;i++) {
-
- if (!loader[i]->recognize(extension))
- continue;
-
- Error err = loader[i]->load_import_metadata(local_path,ret);
- if (err==OK)
- break;
- }
-
-
- return ret;
-
-}
-
-
-
-String ResourceLoader::find_complete_path(const String& p_path,const String& p_type) {
- //this is an old vestige when the engine saved files without extension.
- //remains here for compatibility with old projects and only because it
- //can be sometimes nice to open files using .* from a script and have it guess
- //the right extension.
-
- String local_path = p_path;
- if (local_path.ends_with("*")) {
-
- //find the extension for resource that ends with *
- local_path = local_path.substr(0,local_path.length()-1);
- List<String> extensions;
- get_recognized_extensions_for_type(p_type,&extensions);
- List<String> candidates;
-
- for(List<String>::Element *E=extensions.front();E;E=E->next()) {
-
- String path = local_path+E->get();
-
- if (PathRemap::get_singleton()->has_remap(path) || FileAccess::exists(path)) {
- candidates.push_back(path);
- }
-
- }
-
-
- if (candidates.size()==0) {
- return "";
- } else if (candidates.size()==1 || p_type=="") {
- return candidates.front()->get();
- } else {
-
- for(List<String>::Element *E=candidates.front();E;E=E->next()) {
-
- String rt = get_resource_type(E->get());
- if (ClassDB::is_parent_class(rt,p_type)) {
- return E->get();
- }
- }
-
- return "";
- }
- }
-
- return local_path;
-}
Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path,const String& p_type_hint,bool p_no_cache,Error *r_error) {
@@ -309,7 +235,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- local_path=find_complete_path(local_path,p_type_hint);
+
ERR_FAIL_COND_V(local_path=="",Ref<ResourceInteractiveLoader>());
@@ -329,19 +255,14 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
if (OS::get_singleton()->is_stdout_verbose())
print_line("load resource: ");
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
-
- String extension=remapped_path.get_extension();
bool found=false;
for (int i=0;i<loader_count;i++) {
- if (!loader[i]->recognize(extension))
- continue;
- if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
+ if (!loader[i]->recognize_path(local_path,p_type_hint))
continue;
found=true;
- Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(remapped_path,r_error);
+ Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(local_path,r_error);
if (ril.is_null())
continue;
if (!p_no_cache)
@@ -383,20 +304,16 @@ void ResourceLoader::get_dependencies(const String& p_path, List<String> *p_depe
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
-
- String extension=remapped_path.get_extension();
-
for (int i=0;i<loader_count;i++) {
- if (!loader[i]->recognize(extension))
+ if (!loader[i]->recognize_path(local_path))
continue;
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
*/
- loader[i]->get_dependencies(remapped_path,p_dependencies,p_add_types);
+ loader[i]->get_dependencies(local_path,p_dependencies,p_add_types);
}
}
@@ -410,20 +327,17 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String,
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
-
- String extension=remapped_path.get_extension();
for (int i=0;i<loader_count;i++) {
- if (!loader[i]->recognize(extension))
+ if (!loader[i]->recognize_path(local_path))
continue;
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
*/
- return loader[i]->rename_dependencies(p_path,p_map);
+ return loader[i]->rename_dependencies(local_path,p_map);
}
@@ -432,17 +346,6 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String,
}
-String ResourceLoader::guess_full_filename(const String &p_path,const String& p_type) {
-
- String local_path;
- if (p_path.is_rel_path())
- local_path="res://"+p_path;
- else
- local_path = GlobalConfig::get_singleton()->localize_path(p_path);
-
- return find_complete_path(local_path,p_type);
-
-}
String ResourceLoader::get_resource_type(const String &p_path) {
@@ -452,8 +355,6 @@ String ResourceLoader::get_resource_type(const String &p_path) {
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
- String extension=remapped_path.get_extension();
for (int i=0;i<loader_count;i++) {
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 7979bd02a..f464415e1 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -61,11 +61,10 @@ public:
virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const=0;
virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
- bool recognize(const String& p_extension) const;
+ virtual bool recognize_path(const String& p_path,const String& p_for_type=String()) const;
virtual bool handles_type(const String& p_type) const=0;
virtual String get_resource_type(const String &p_path) const=0;
virtual void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);
- virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const { return ERR_UNAVAILABLE; }
virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map) { return OK; }
virtual ~ResourceFormatLoader() {}
@@ -92,14 +91,12 @@ class ResourceLoader {
static DependencyErrorNotify dep_err_notify;
static bool abort_on_missing_resource;
- static String find_complete_path(const String& p_path,const String& p_type);
public:
static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL);
static RES load(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL);
- static Ref<ResourceImportMetadata> load_import_metadata(const String &p_path);
static void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions);
static void add_resource_format_loader(ResourceFormatLoader *p_format_loader,bool p_at_front=false);
@@ -107,8 +104,6 @@ public:
static void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);
static Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
- static String guess_full_filename(const String &p_path,const String& p_type);
-
static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load=p_timestamp; }
static void notify_load_error(const String& p_err) { if (err_notify) err_notify(err_notify_ud,p_err); }
@@ -122,4 +117,6 @@ public:
static bool get_abort_on_missing_resources() { return abort_on_missing_resource; }
};
+
+
#endif
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 2c45009a6..a1f471ebe 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -39,7 +39,7 @@ int AStar::get_available_point_id() const {
return points.back()->key()+1;
}
-void AStar::add_point(int p_id, const Vector3 &p_pos, float p_weight_scale) {
+void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
ERR_FAIL_COND(p_id<0);
if (!points.has(p_id)) {
Point *pt = memnew( Point );
@@ -62,7 +62,7 @@ Vector3 AStar::get_point_pos(int p_id) const{
return points[p_id]->pos;
}
-float AStar::get_point_weight_scale(int p_id) const{
+real_t AStar::get_point_weight_scale(int p_id) const{
ERR_FAIL_COND_V(!points.has(p_id),0);
@@ -145,11 +145,11 @@ void AStar::clear(){
int AStar::get_closest_point(const Vector3& p_point) const{
int closest_id=-1;
- float closest_dist=1e20;
+ real_t closest_dist=1e20;
for (const Map<int,Point*>::Element *E=points.front();E;E=E->next()) {
- float d = p_point.distance_squared_to(E->get()->pos);
+ real_t d = p_point.distance_squared_to(E->get()->pos);
if (closest_id<0 || d<closest_dist) {
closest_dist=d;
closest_id=E->key();
@@ -162,7 +162,7 @@ int AStar::get_closest_point(const Vector3& p_point) const{
}
Vector3 AStar::get_closest_pos_in_segment(const Vector3& p_point) const {
- float closest_dist = 1e20;
+ real_t closest_dist = 1e20;
bool found=false;
Vector3 closest_point;
@@ -175,7 +175,7 @@ Vector3 AStar::get_closest_pos_in_segment(const Vector3& p_point) const {
};
Vector3 p = Geometry::get_closest_point_to_segment(p_point,segment);
- float d = p_point.distance_squared_to(p);
+ real_t d = p_point.distance_squared_to(p);
if (!found || d<closest_dist) {
closest_point=p;
@@ -220,14 +220,14 @@ bool AStar::_solve(Point* begin_point, Point* end_point) {
//check open list
SelfList<Point> *least_cost_point=NULL;
- float least_cost=1e30;
+ real_t least_cost=1e30;
//this could be faster (cache previous results)
for (SelfList<Point> *E=open_list.first();E;E=E->next()) {
Point *p=E->self();
- float cost=p->distance;
+ real_t cost=p->distance;
cost+=p->pos.distance_to(end_point->pos);
cost*=p->weight_scale;
@@ -249,7 +249,7 @@ bool AStar::_solve(Point* begin_point, Point* end_point) {
Point* e=p->neighbours[i];
- float distance = p->pos.distance_to(e->pos) + p->distance;
+ real_t distance = p->pos.distance_to(e->pos) + p->distance;
distance*=e->weight_scale;
diff --git a/core/math/a_star.h b/core/math/a_star.h
index 35e6ead22..c4c955ed2 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -48,14 +48,14 @@ class AStar: public Reference {
int id;
Vector3 pos;
- float weight_scale;
+ real_t weight_scale;
uint64_t last_pass;
Vector<Point*> neighbours;
//used for pathfinding
Point *prev_point;
- float distance;
+ real_t distance;
Point() : list(this) {}
};
@@ -98,9 +98,9 @@ public:
int get_available_point_id() const;
- void add_point(int p_id,const Vector3& p_pos,float p_weight_scale=1);
+ void add_point(int p_id,const Vector3& p_pos,real_t p_weight_scale=1);
Vector3 get_point_pos(int p_id) const;
- float get_point_weight_scale(int p_id) const;
+ real_t get_point_weight_scale(int p_id) const;
void remove_point(int p_id);
void connect_points(int p_id,int p_with_id);
diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h
index dbababf76..acd74903b 100644
--- a/core/math/audio_frame.h
+++ b/core/math/audio_frame.h
@@ -3,8 +3,25 @@
#include "typedefs.h"
+
+static inline float undenormalise(volatile float f)
+{
+ union {
+ uint32_t i;
+ float f;
+ } v;
+
+ v.f = f;
+
+ // original: return (v.i & 0x7f800000) == 0 ? 0.0f : f;
+ // version from Tim Blechmann:
+ return (v.i & 0x7f800000) < 0x08000000 ? 0.0f : f;
+}
+
+
struct AudioFrame {
+ //left and right samples
float l,r;
_ALWAYS_INLINE_ const float& operator[](int idx) const { return idx==0?l:r; }
@@ -15,14 +32,30 @@ struct AudioFrame {
_ALWAYS_INLINE_ AudioFrame operator*(const AudioFrame& p_frame) const { return AudioFrame(l*p_frame.l,r*p_frame.r); }
_ALWAYS_INLINE_ AudioFrame operator/(const AudioFrame& p_frame) const { return AudioFrame(l/p_frame.l,r/p_frame.r); }
+ _ALWAYS_INLINE_ AudioFrame operator+(float p_sample) const { return AudioFrame(l+p_sample,r+p_sample); }
+ _ALWAYS_INLINE_ AudioFrame operator-(float p_sample) const { return AudioFrame(l-p_sample,r-p_sample); }
+ _ALWAYS_INLINE_ AudioFrame operator*(float p_sample) const { return AudioFrame(l*p_sample,r*p_sample); }
+ _ALWAYS_INLINE_ AudioFrame operator/(float p_sample) const { return AudioFrame(l/p_sample,r/p_sample); }
+
_ALWAYS_INLINE_ void operator+=(const AudioFrame& p_frame) { l+=p_frame.l; r+=p_frame.r; }
_ALWAYS_INLINE_ void operator-=(const AudioFrame& p_frame) { l-=p_frame.l; r-=p_frame.r; }
_ALWAYS_INLINE_ void operator*=(const AudioFrame& p_frame) { l*=p_frame.l; r*=p_frame.r; }
_ALWAYS_INLINE_ void operator/=(const AudioFrame& p_frame) { l/=p_frame.l; r/=p_frame.r; }
+ _ALWAYS_INLINE_ void operator+=(float p_sample) { l+=p_sample; r+=p_sample; }
+ _ALWAYS_INLINE_ void operator-=(float p_sample) { l-=p_sample; r-=p_sample; }
+ _ALWAYS_INLINE_ void operator*=(float p_sample) { l*=p_sample; r*=p_sample; }
+ _ALWAYS_INLINE_ void operator/=(float p_sample) { l/=p_sample; r/=p_sample; }
+
+ _ALWAYS_INLINE_ void undenormalise() {
+ l = ::undenormalise(l);
+ r = ::undenormalise(r);
+ }
+
_ALWAYS_INLINE_ AudioFrame(float p_l, float p_r) {l=p_l; r=p_r;}
_ALWAYS_INLINE_ AudioFrame(const AudioFrame& p_frame) {l=p_frame.l; r=p_frame.r;}
+ _ALWAYS_INLINE_ AudioFrame() {}
};
#endif
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index e2526f513..1ca638503 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -87,8 +87,8 @@ int BSP_Tree::_get_points_inside(int p_node,const Vector3* p_points,int *p_indic
max+=p_center;
min+=p_center;
- float dist_min = p.distance_to(min);
- float dist_max = p.distance_to(max);
+ real_t dist_min = p.distance_to(min);
+ real_t dist_max = p.distance_to(max);
if ((dist_min * dist_max) < CMP_EPSILON ) { //intersection, test point by point
@@ -290,13 +290,13 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const {
}
-static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,float p_tolerance) {
+static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,real_t p_tolerance) {
int ic = p_indices.size();
const int*indices=p_indices.ptr();
int best_plane = -1;
- float best_plane_cost = 1e20;
+ real_t best_plane_cost = 1e20;
// Loop to find the polygon that best divides the set.
@@ -317,7 +317,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
for(int k=0;k<3;k++) {
- float d = p.distance_to(g.vertex[j]);
+ real_t d = p.distance_to(g.vertex[j]);
if (Math::abs(d)>p_tolerance) {
@@ -340,13 +340,13 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
- //double split_cost = num_spanning / (double) face_count;
- double relation = Math::abs(num_over-num_under) / (double) ic;
+ //real_t split_cost = num_spanning / (real_t) face_count;
+ real_t relation = Math::abs(num_over-num_under) / (real_t) ic;
// being honest, i never found a way to add split cost to the mix in a meaninguful way
// in this engine, also, will likely be ignored anyway
- double plane_cost = /*split_cost +*/ relation;
+ real_t plane_cost = /*split_cost +*/ relation;
//printf("plane %i, %i over, %i under, %i spanning, cost is %g\n",i,num_over,num_under,num_spanning,plane_cost);
if (plane_cost<best_plane_cost) {
@@ -362,7 +362,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
}
-static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,float p_tolerance) {
+static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,real_t p_tolerance) {
ERR_FAIL_COND_V( p_nodes.size() == BSP_Tree::MAX_NODES, -1 );
@@ -400,7 +400,7 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
for(int j=0;j<3;j++) {
- float d = divisor_plane.distance_to(f.vertex[j]);
+ real_t d = divisor_plane.distance_to(f.vertex[j]);
if (Math::abs(d)>p_tolerance) {
if (d > 0)
@@ -473,7 +473,7 @@ BSP_Tree::operator Variant() const {
Dictionary d;
d["error_radius"]=error_radius;
- Vector<float> plane_values;
+ Vector<real_t> plane_values;
plane_values.resize(planes.size()*4);
for(int i=0;i<planes.size();i++) {
@@ -522,13 +522,13 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
if (d["planes"].get_type()==Variant::POOL_REAL_ARRAY) {
- PoolVector<float> src_planes=d["planes"];
+ PoolVector<real_t> src_planes=d["planes"];
int plane_count=src_planes.size();
ERR_FAIL_COND(plane_count%4);
planes.resize(plane_count/4);
if (plane_count) {
- PoolVector<float>::Read r = src_planes.read();
+ PoolVector<real_t>::Read r = src_planes.read();
for(int i=0;i<plane_count/4;i++) {
planes[i].normal.x=r[i*4+0];
@@ -562,7 +562,7 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
}
-BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) {
+BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,real_t p_error_radius) {
// compute aabb
@@ -615,7 +615,7 @@ BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) {
error_radius=p_error_radius;
}
-BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,float p_error_radius) {
+BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,real_t p_error_radius) {
nodes=p_nodes;
planes=p_planes;
diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h
index a64fffcb7..c0071438d 100644
--- a/core/math/bsp_tree.h
+++ b/core/math/bsp_tree.h
@@ -66,7 +66,7 @@ private:
Vector<Node> nodes;
Vector<Plane> planes;
Rect3 aabb;
- float error_radius;
+ real_t error_radius;
int _get_points_inside(int p_node,const Vector3* p_points,int *p_indices, const Vector3& p_center,const Vector3& p_half_extents,int p_indices_count) const;
@@ -91,8 +91,8 @@ public:
BSP_Tree();
BSP_Tree(const Variant& p_variant);
- BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius=0);
- BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,float p_error_radius=0);
+ BSP_Tree(const PoolVector<Face3>& p_faces,real_t p_error_radius=0);
+ BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,real_t p_error_radius=0);
~BSP_Tree();
};
@@ -110,7 +110,7 @@ bool BSP_Tree::_test_convex(const Node* p_nodes, const Plane* p_planes,int p_cur
const Plane& p=p_planes[n.plane];
- float min,max;
+ real_t min,max;
p_convex.project_range(p.normal,min,max);
bool go_under = min < p.d;
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 7669356f5..3b47a75c6 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -65,15 +65,15 @@ Plane CameraMatrix::xform4(const Plane& p_vec4) const {
return ret;
}
-void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p_z_near, float p_z_far,bool p_flip_fov) {
+void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far,bool p_flip_fov) {
if (p_flip_fov) {
p_fovy_degrees=get_fovy(p_fovy_degrees,1.0/p_aspect);
}
- float sine, cotangent, deltaZ;
- float radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
+ real_t sine, cotangent, deltaZ;
+ real_t radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
deltaZ = p_z_far - p_z_near;
sine = Math::sin(radians);
@@ -94,7 +94,7 @@ void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p
}
-void CameraMatrix::set_orthogonal(float p_left, float p_right, float p_bottom, float p_top, float p_znear, float p_zfar) {
+void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
set_identity();
@@ -109,7 +109,7 @@ void CameraMatrix::set_orthogonal(float p_left, float p_right, float p_bottom, f
}
-void CameraMatrix::set_orthogonal(float p_size, float p_aspect, float p_znear, float p_zfar,bool p_flip_fov) {
+void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar,bool p_flip_fov) {
if (!p_flip_fov) {
p_size*=p_aspect;
@@ -120,7 +120,7 @@ void CameraMatrix::set_orthogonal(float p_size, float p_aspect, float p_znear, f
-void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, float p_top, float p_near, float p_far) {
+void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
#if 0
///@TODO, give a check to this. I'm not sure if it's working.
set_identity();
@@ -134,14 +134,14 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa
matrix[3][2]=-1;
matrix[3][3]=0;
#else
- float *te = &matrix[0][0];
- float x = 2 * p_near / ( p_right - p_left );
- float y = 2 * p_near / ( p_top - p_bottom );
+ real_t *te = &matrix[0][0];
+ real_t x = 2 * p_near / ( p_right - p_left );
+ real_t y = 2 * p_near / ( p_top - p_bottom );
- float a = ( p_right + p_left ) / ( p_right - p_left );
- float b = ( p_top + p_bottom ) / ( p_top - p_bottom );
- float c = - ( p_far + p_near ) / ( p_far - p_near );
- float d = - 2 * p_far * p_near / ( p_far - p_near );
+ real_t a = ( p_right + p_left ) / ( p_right - p_left );
+ real_t b = ( p_top + p_bottom ) / ( p_top - p_bottom );
+ real_t c = - ( p_far + p_near ) / ( p_far - p_near );
+ real_t d = - 2 * p_far * p_near / ( p_far - p_near );
te[0] = x;
te[1] = 0;
@@ -166,9 +166,9 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa
-float CameraMatrix::get_z_far() const {
+real_t CameraMatrix::get_z_far() const {
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
Plane new_plane=Plane(matrix[ 3] - matrix[ 2],
matrix[ 7] - matrix[ 6],
matrix[11] - matrix[10],
@@ -179,9 +179,9 @@ float CameraMatrix::get_z_far() const {
return new_plane.d;
}
-float CameraMatrix::get_z_near() const {
+real_t CameraMatrix::get_z_near() const {
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
Plane new_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
@@ -191,9 +191,9 @@ float CameraMatrix::get_z_near() const {
return new_plane.d;
}
-void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const {
+void CameraMatrix::get_viewport_size(real_t& r_width, real_t& r_height) const {
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
@@ -223,7 +223,7 @@ void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const {
bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8points) const {
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
@@ -284,7 +284,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
Vector<Plane> planes;
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
Plane new_plane;
@@ -377,9 +377,9 @@ void CameraMatrix::invert() {
int i,j,k;
int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */
- float pvt_val; /* Value of current pivot element */
- float hold; /* Temporary storage */
- float determinat; /* Determinant */
+ real_t pvt_val; /* Value of current pivot element */
+ real_t hold; /* Temporary storage */
+ real_t determinat; /* Determinant */
determinat = 1.0;
for (k=0; k<4; k++) {
@@ -492,7 +492,7 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix& p_matrix) const {
void CameraMatrix::set_light_bias() {
- float *m=&matrix[0][0];
+ real_t *m=&matrix[0][0];
m[0]=0.5,
m[1]=0.0,
@@ -515,7 +515,7 @@ void CameraMatrix::set_light_bias() {
void CameraMatrix::set_light_atlas_rect(const Rect2& p_rect) {
- float *m=&matrix[0][0];
+ real_t *m=&matrix[0][0];
m[0]=p_rect.size.width,
m[1]=0.0,
@@ -545,9 +545,9 @@ CameraMatrix::operator String() const {
return str;
}
-float CameraMatrix::get_aspect() const {
+real_t CameraMatrix::get_aspect() const {
- float w,h;
+ real_t w,h;
get_viewport_size(w,h);
return w/h;
}
@@ -561,8 +561,8 @@ int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const {
}
-float CameraMatrix::get_fov() const {
- const float * matrix = (const float*)this->matrix;
+real_t CameraMatrix::get_fov() const {
+ const real_t * matrix = (const real_t*)this->matrix;
Plane right_plane=Plane(matrix[ 3] - matrix[ 0],
matrix[ 7] - matrix[ 4],
@@ -613,7 +613,7 @@ void CameraMatrix::scale_translate_to_fit(const Rect3& p_aabb) {
CameraMatrix::operator Transform() const {
Transform tr;
- const float *m=&matrix[0][0];
+ const real_t *m=&matrix[0][0];
tr.basis.elements[0][0]=m[0];
tr.basis.elements[1][0]=m[1];
@@ -637,7 +637,7 @@ CameraMatrix::operator Transform() const {
CameraMatrix::CameraMatrix(const Transform& p_transform) {
const Transform &tr = p_transform;
- float *m=&matrix[0][0];
+ real_t *m=&matrix[0][0];
m[0]=tr.basis.elements[0][0];
m[1]=tr.basis.elements[1][0];
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index 952f1e8fb..c96f8259b 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -48,32 +48,32 @@ struct CameraMatrix {
PLANE_BOTTOM
};
- float matrix[4][4];
+ real_t matrix[4][4];
void set_identity();
void set_zero();
void set_light_bias();
void set_light_atlas_rect(const Rect2& p_rect);
- void set_perspective(float p_fovy_degrees, float p_aspect, float p_z_near, float p_z_far,bool p_flip_fov=false);
- void set_orthogonal(float p_left, float p_right, float p_bottom, float p_top, float p_znear, float p_zfar);
- void set_orthogonal(float p_size, float p_aspect, float p_znear, float p_zfar,bool p_flip_fov=false);
- void set_frustum(float p_left, float p_right, float p_bottom, float p_top, float p_near, float p_far);
+ void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far,bool p_flip_fov=false);
+ void set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar);
+ void set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar,bool p_flip_fov=false);
+ void set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far);
- static float get_fovy(float p_fovx,float p_aspect) {
+ static real_t get_fovy(real_t p_fovx,real_t p_aspect) {
return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5))*2.0);
}
- float get_z_far() const;
- float get_z_near() const;
- float get_aspect() const;
- float get_fov() const;
+ real_t get_z_far() const;
+ real_t get_z_near() const;
+ real_t get_aspect() const;
+ real_t get_fov() const;
Vector<Plane> get_projection_planes(const Transform& p_transform) const;
bool get_endpoints(const Transform& p_transform,Vector3 *p_8points) const;
- void get_viewport_size(float& r_width, float& r_height) const;
+ void get_viewport_size(real_t& r_width, real_t& r_height) const;
void invert();
CameraMatrix inverse() const;
@@ -102,7 +102,7 @@ Vector3 CameraMatrix::xform(const Vector3& p_vec3) const {
ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0];
ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1];
ret.z = matrix[0][2] * p_vec3.x + matrix[1][2] * p_vec3.y + matrix[2][2] * p_vec3.z + matrix[3][2];
- float w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3];
+ real_t w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3];
return ret/w;
}
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index faf124593..60fab6748 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -168,8 +168,8 @@ Face3::Side Face3::get_side_of(const Face3& p_face,ClockDirection p_clock_dir) c
Vector3 Face3::get_random_point_inside() const {
- float a=Math::random(0,1);
- float b=Math::random(0,1);
+ real_t a=Math::random(0,1);
+ real_t b=Math::random(0,1);
if (a>b) {
SWAP(a,b);
}
@@ -215,9 +215,9 @@ bool Face3::intersects_aabb(const Rect3& p_aabb) const {
#define TEST_AXIS(m_ax)\
{\
- float aabb_min=p_aabb.pos.m_ax;\
- float aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
- float tri_min,tri_max;\
+ real_t aabb_min=p_aabb.pos.m_ax;\
+ real_t aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
+ real_t tri_min,tri_max;\
for (int i=0;i<3;i++) {\
if (i==0 || vertex[i].m_ax > tri_max)\
tri_max=vertex[i].m_ax;\
@@ -255,7 +255,7 @@ bool Face3::intersects_aabb(const Rect3& p_aabb) const {
continue; // coplanar
axis.normalize();
- float minA,maxA,minB,maxB;
+ real_t minA,maxA,minB,maxB;
p_aabb.project_range_in_plane(Plane(axis,0),minA,maxA);
project_range(axis,Transform(),minB,maxB);
@@ -272,12 +272,12 @@ Face3::operator String() const {
return String()+vertex[0]+", "+vertex[1]+", "+vertex[2];
}
-void Face3::project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const {
+void Face3::project_range(const Vector3& p_normal,const Transform& p_transform,real_t& r_min, real_t& r_max) const {
for (int i=0;i<3;i++) {
Vector3 v=p_transform.xform(vertex[i]);
- float d=p_normal.dot(v);
+ real_t d=p_normal.dot(v);
if (i==0 || d > r_max)
r_max=d;
@@ -316,11 +316,11 @@ void Face3::get_support(const Vector3& p_normal,const Transform& p_transform,Vec
/** FIND SUPPORT VERTEX **/
int vert_support_idx=-1;
- float support_max;
+ real_t support_max;
for (int i=0;i<3;i++) {
- float d=n.dot(vertex[i]);
+ real_t d=n.dot(vertex[i]);
if (i==0 || d > support_max) {
support_max=d;
@@ -336,7 +336,7 @@ void Face3::get_support(const Vector3& p_normal,const Transform& p_transform,Vec
continue;
// check if edge is valid as a support
- float dot=(vertex[i]-vertex[(i+1)%3]).normalized().dot(n);
+ real_t dot=(vertex[i]-vertex[(i+1)%3]).normalized().dot(n);
dot=ABS(dot);
if (dot < _EDGE_IS_VALID_SUPPORT_TRESHOLD) {
@@ -362,15 +362,15 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
Vector3 edge1 = vertex[2] - vertex[0];
Vector3 v0 = vertex[0] - p_point;
- float a = edge0.dot( edge0 );
- float b = edge0.dot( edge1 );
- float c = edge1.dot( edge1 );
- float d = edge0.dot( v0 );
- float e = edge1.dot( v0 );
+ real_t a = edge0.dot( edge0 );
+ real_t b = edge0.dot( edge1 );
+ real_t c = edge1.dot( edge1 );
+ real_t d = edge0.dot( v0 );
+ real_t e = edge1.dot( v0 );
- float det = a*c - b*b;
- float s = b*e - c*d;
- float t = b*d - a*e;
+ real_t det = a*c - b*b;
+ real_t s = b*e - c*d;
+ real_t t = b*d - a*e;
if ( s + t < det )
{
@@ -402,7 +402,7 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
}
else
{
- float invDet = 1.f / det;
+ real_t invDet = 1.f / det;
s *= invDet;
t *= invDet;
}
@@ -411,12 +411,12 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
{
if ( s < 0.f )
{
- float tmp0 = b+d;
- float tmp1 = c+e;
+ real_t tmp0 = b+d;
+ real_t tmp1 = c+e;
if ( tmp1 > tmp0 )
{
- float numer = tmp1 - tmp0;
- float denom = a-2*b+c;
+ real_t numer = tmp1 - tmp0;
+ real_t denom = a-2*b+c;
s = CLAMP( numer/denom, 0.f, 1.f );
t = 1-s;
}
@@ -430,8 +430,8 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
{
if ( a+d > b+e )
{
- float numer = c+e-b-d;
- float denom = a-2*b+c;
+ real_t numer = c+e-b-d;
+ real_t denom = a-2*b+c;
s = CLAMP( numer/denom, 0.f, 1.f );
t = 1-s;
}
@@ -443,8 +443,8 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
}
else
{
- float numer = c+e-b-d;
- float denom = a-2*b+c;
+ real_t numer = c+e-b-d;
+ real_t denom = a-2*b+c;
s = CLAMP( numer/denom, 0.f, 1.f );
t = 1.f - s;
}
diff --git a/core/math/face3.h b/core/math/face3.h
index e957f6432..a0da588ea 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -76,7 +76,7 @@ public:
ClockDirection get_clock_dir() const; ///< todo, test if this is returning the proper clockwisity
void get_support(const Vector3& p_normal,const Transform& p_transform,Vector3 *p_vertices,int* p_count,int p_max) const;
- void project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const;
+ void project_range(const Vector3& p_normal,const Transform& p_transform,real_t& r_min, real_t& r_max) const;
Rect3 get_aabb() const {
@@ -109,9 +109,9 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
(perp.z>0) ? -half_extents.z : half_extents.z
);
- float d = perp.dot(vertex[0]);
- float dist_a = perp.dot(ofs+sup)-d;
- float dist_b = perp.dot(ofs-sup)-d;
+ real_t d = perp.dot(vertex[0]);
+ real_t dist_a = perp.dot(ofs+sup)-d;
+ real_t dist_b = perp.dot(ofs-sup)-d;
if (dist_a*dist_b > 0)
return false; //does not intersect the plane
@@ -119,9 +119,9 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
#define TEST_AXIS(m_ax)\
{\
- float aabb_min=p_aabb.pos.m_ax;\
- float aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
- float tri_min,tri_max;\
+ real_t aabb_min=p_aabb.pos.m_ax;\
+ real_t aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
+ real_t tri_min,tri_max;\
for (int i=0;i<3;i++) {\
if (i==0 || vertex[i].m_ax > tri_max)\
tri_max=vertex[i].m_ax;\
@@ -236,16 +236,16 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
(axis.z>0) ? -half_extents.z : half_extents.z
);
- float maxB = axis.dot(ofs+sup2);
- float minB = axis.dot(ofs-sup2);
+ real_t maxB = axis.dot(ofs+sup2);
+ real_t minB = axis.dot(ofs-sup2);
if (minB>maxB) {
SWAP(maxB,minB);
}
- float minT=1e20,maxT=-1e20;
+ real_t minT=1e20,maxT=-1e20;
for (int k=0;k<3;k++) {
- float d=axis.dot(vertex[k]);
+ real_t d=axis.dot(vertex[k]);
if (d > maxT)
maxT=d;
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index bf3364a05..6570dfe67 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -580,7 +580,7 @@ static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int l
}
-PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,float *p_error ) {
+PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,real_t *p_error ) {
#define _MIN_SIZE 1.0
#define _MAX_LENGTH 20
@@ -755,7 +755,7 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector<Plane> &p_planes
#define SUBPLANE_SIZE 1024.0
- float subplane_size = 1024.0; // should compute this from the actual plane
+ real_t subplane_size = 1024.0; // should compute this from the actual plane
for (int i=0;i<p_planes.size();i++) {
Plane p =p_planes[i];
@@ -910,7 +910,7 @@ PoolVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) {
return planes;
}
-PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
+PoolVector<Plane> Geometry::build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis) {
PoolVector<Plane> planes;
@@ -933,7 +933,7 @@ PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height
}
-PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) {
+PoolVector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) {
PoolVector<Plane> planes;
@@ -957,7 +957,7 @@ PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p
for (int j=1;j<=p_lats;j++) {
//todo this is stupid, fix
- Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized();
+ Vector3 angle = normal.linear_interpolate(axis,j/(real_t)p_lats).normalized();
Vector3 pos = angle*p_radius;
planes.push_back( Plane( pos, angle ) );
planes.push_back( Plane( pos * axis_neg, angle * axis_neg) );
@@ -969,7 +969,7 @@ PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p
}
-PoolVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
+PoolVector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
PoolVector<Plane> planes;
@@ -991,7 +991,7 @@ PoolVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height,
for (int j=1;j<=p_lats;j++) {
- Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized();
+ Vector3 angle = normal.linear_interpolate(axis,j/(real_t)p_lats).normalized();
Vector3 pos = axis*p_height*0.5 + angle*p_radius;
planes.push_back( Plane( pos, angle ) );
planes.push_back( Plane( pos * axis_neg, angle * axis_neg) );
@@ -1108,13 +1108,13 @@ void Geometry::make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_resul
//find the result with the best aspect ratio
int best=-1;
- float best_aspect=1e20;
+ real_t best_aspect=1e20;
for(int i=0;i<results.size();i++) {
- float h = nearest_power_of_2(results[i].max_h);
- float w = nearest_power_of_2(results[i].max_w);
- float aspect = h>w ? h/w : w/h;
+ real_t h = nearest_power_of_2(results[i].max_h);
+ real_t w = nearest_power_of_2(results[i].max_w);
+ real_t aspect = h>w ? h/w : w/h;
if (aspect < best_aspect) {
best=i;
best_aspect=aspect;
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 25f5e11fc..13cbbdce6 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -48,15 +48,15 @@ public:
- static float get_closest_points_between_segments( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2, Vector2& c1, Vector2& c2) {
+ static real_t get_closest_points_between_segments( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2, Vector2& c1, Vector2& c2) {
Vector2 d1 = q1 - p1; // Direction vector of segment S1
Vector2 d2 = q2 - p2; // Direction vector of segment S2
Vector2 r = p1 - p2;
- float a = d1.dot(d1); // Squared length of segment S1, always nonnegative
- float e = d2.dot(d2); // Squared length of segment S2, always nonnegative
- float f = d2.dot(r);
- float s,t;
+ real_t a = d1.dot(d1); // Squared length of segment S1, always nonnegative
+ real_t e = d2.dot(d2); // Squared length of segment S2, always nonnegative
+ real_t f = d2.dot(r);
+ real_t s,t;
// Check if either or both segments degenerate into points
if (a <= CMP_EPSILON && e <= CMP_EPSILON) {
// Both segments degenerate into points
@@ -66,25 +66,25 @@ public:
}
if (a <= CMP_EPSILON) {
// First segment degenerates into a point
- s = 0.0f;
+ s = 0.0;
t = f / e; // s = 0 => t = (b*s + f) / e = f / e
- t = CLAMP(t, 0.0f, 1.0f);
+ t = CLAMP(t, 0.0, 1.0);
} else {
- float c = d1.dot(r);
+ real_t c = d1.dot(r);
if (e <= CMP_EPSILON) {
// Second segment degenerates into a point
- t = 0.0f;
- s = CLAMP(-c / a, 0.0f, 1.0f); // t = 0 => s = (b*t - c) / a = -c / a
+ t = 0.0;
+ s = CLAMP(-c / a, 0.0, 1.0); // t = 0 => s = (b*t - c) / a = -c / a
} else {
// The general nondegenerate case starts here
- float b = d1.dot(d2);
- float denom = a*e-b*b; // Always nonnegative
+ real_t b = d1.dot(d2);
+ real_t denom = a*e-b*b; // Always nonnegative
// If segments not parallel, compute closest point on L1 to L2 and
// clamp to segment S1. Else pick arbitrary s (here 0)
- if (denom != 0.0f) {
- s = CLAMP((b*f - c*e) / denom, 0.0f, 1.0f);
+ if (denom != 0.0) {
+ s = CLAMP((b*f - c*e) / denom, 0.0, 1.0);
} else
- s = 0.0f;
+ s = 0.0;
// Compute point on L2 closest to S1(s) using
// t = Dot((P1 + D1*s) - P2,D2) / Dot(D2,D2) = (b*s + f) / e
t = (b*s + f) / e;
@@ -92,12 +92,12 @@ public:
//If t in [0,1] done. Else clamp t, recompute s for the new value
// of t using s = Dot((P2 + D2*t) - P1,D1) / Dot(D1,D1)= (t*b - c) / a
// and clamp s to [0, 1]
- if (t < 0.0f) {
- t = 0.0f;
- s = CLAMP(-c / a, 0.0f, 1.0f);
- } else if (t > 1.0f) {
- t = 1.0f;
- s = CLAMP((b - c) / a, 0.0f, 1.0f);
+ if (t < 0.0) {
+ t = 0.0;
+ s = CLAMP(-c / a, 0.0, 1.0);
+ } else if (t > 1.0) {
+ t = 1.0;
+ s = CLAMP((b - c) / a, 0.0, 1.0);
}
}
}
@@ -113,8 +113,8 @@ public:
#define d_of(m,n,o,p) ( (m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z) )
//caluclate the parpametric position on the 2 curves, mua and mub
- float mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) );
- float mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1);
+ real_t mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) );
+ real_t mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1);
//clip the value between [0..1] constraining the solution to lie on the original curves
if (mua < 0) mua = 0;
@@ -125,7 +125,7 @@ public:
c2 = q1.linear_interpolate(q2,mub);
}
- static float get_closest_distance_between_segments( const Vector3& p_from_a,const Vector3& p_to_a, const Vector3& p_from_b,const Vector3& p_to_b) {
+ static real_t get_closest_distance_between_segments( const Vector3& p_from_a,const Vector3& p_to_a, const Vector3& p_from_b,const Vector3& p_to_b) {
Vector3 u = p_to_a - p_from_a;
Vector3 v = p_to_b - p_from_b;
Vector3 w = p_from_a - p_to_a;
@@ -273,22 +273,22 @@ public:
Vector3 sphere_pos=p_sphere_pos-p_from;
Vector3 rel=(p_to-p_from);
- float rel_l=rel.length();
+ real_t rel_l=rel.length();
if (rel_l<CMP_EPSILON)
return false; // both points are the same
Vector3 normal=rel/rel_l;
- float sphere_d=normal.dot(sphere_pos);
+ real_t sphere_d=normal.dot(sphere_pos);
//Vector3 ray_closest=normal*sphere_d;
- float ray_distance=sphere_pos.distance_to(normal*sphere_d);
+ real_t ray_distance=sphere_pos.distance_to(normal*sphere_d);
if (ray_distance>=p_sphere_radius)
return false;
- float inters_d2=p_sphere_radius*p_sphere_radius - ray_distance*ray_distance;
- float inters_d=sphere_d;
+ real_t inters_d2=p_sphere_radius*p_sphere_radius - ray_distance*ray_distance;
+ real_t inters_d=sphere_d;
if (inters_d2>=CMP_EPSILON)
inters_d-=Math::sqrt(inters_d2);
@@ -307,17 +307,17 @@ public:
return true;
}
- static inline bool segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius,Vector3* r_res=0,Vector3 *r_norm=0) {
+ static inline bool segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, real_t p_height,real_t p_radius,Vector3* r_res=0,Vector3 *r_norm=0) {
Vector3 rel=(p_to-p_from);
- float rel_l=rel.length();
+ real_t rel_l=rel.length();
if (rel_l<CMP_EPSILON)
return false; // both points are the same
// first check if they are parallel
Vector3 normal=(rel/rel_l);
Vector3 crs = normal.cross(Vector3(0,0,1));
- float crs_l=crs.length();
+ real_t crs_l=crs.length();
Vector3 z_dir;
@@ -328,13 +328,13 @@ public:
z_dir=crs/crs_l;
}
- float dist=z_dir.dot(p_from);
+ real_t dist=z_dir.dot(p_from);
if (dist>=p_radius)
return false; // too far away
// convert to 2D
- float w2=p_radius*p_radius-dist*dist;
+ real_t w2=p_radius*p_radius-dist*dist;
if (w2<CMP_EPSILON)
return false; //avoid numerical error
Size2 size(Math::sqrt(w2),p_height*0.5);
@@ -344,7 +344,7 @@ public:
Vector2 from2D(x_dir.dot(p_from),p_from.z);
Vector2 to2D(x_dir.dot(p_to),p_to.z);
- float min=0,max=1;
+ real_t min=0,max=1;
int axis=-1;
@@ -464,12 +464,12 @@ public:
Vector3 p=p_point-p_segment[0];
Vector3 n=p_segment[1]-p_segment[0];
- float l =n.length();
+ real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
- float d=n.dot(p);
+ real_t d=n.dot(p);
if (d<=0.0)
return p_segment[0]; // before first point
@@ -483,12 +483,12 @@ public:
Vector3 p=p_point-p_segment[0];
Vector3 n=p_segment[1]-p_segment[0];
- float l =n.length();
+ real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
- float d=n.dot(p);
+ real_t d=n.dot(p);
return p_segment[0]+n*d; // inside
}
@@ -497,12 +497,12 @@ public:
Vector2 p=p_point-p_segment[0];
Vector2 n=p_segment[1]-p_segment[0];
- float l =n.length();
+ real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
- float d=n.dot(p);
+ real_t d=n.dot(p);
if (d<=0.0)
return p_segment[0]; // before first point
@@ -529,12 +529,12 @@ public:
Vector2 p=p_point-p_segment[0];
Vector2 n=p_segment[1]-p_segment[0];
- float l =n.length();
+ real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
- float d=n.dot(p);
+ real_t d=n.dot(p);
return p_segment[0]+n*d; // inside
}
@@ -555,7 +555,7 @@ public:
if ((C.y<0 && D.y<0) || (C.y>=0 && D.y>=0))
return false;
- float ABpos=D.x+(C.x-D.x)*D.y/(D.y-C.y);
+ real_t ABpos=D.x+(C.x-D.x)*D.y/(D.y-C.y);
// Fail if segment C-D crosses line A-B outside of segment A-B.
if (ABpos<0 || ABpos>1.0)
@@ -595,7 +595,7 @@ public:
static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle,const Vector3& p_normal,const Vector3& p_sphere_pos, real_t p_sphere_radius,Vector3& r_triangle_contact,Vector3& r_sphere_contact) {
- float d=p_normal.dot(p_sphere_pos)-p_normal.dot(p_triangle[0]);
+ real_t d=p_normal.dot(p_sphere_pos)-p_normal.dot(p_triangle[0]);
if (d > p_sphere_radius || d < -p_sphere_radius) // not touching the plane of the face, return
return false;
@@ -629,7 +629,7 @@ public:
Vector3 axis =n1.cross(n2).cross(n1);
axis.normalize(); // ugh
- float ad=axis.dot(n2);
+ real_t ad=axis.dot(n2);
if (ABS(ad)>p_sphere_radius) {
// no chance with this edge, too far away
@@ -639,7 +639,7 @@ public:
// check point within edge capsule cylinder
/** 4th TEST INSIDE EDGE POINTS **/
- float sphere_at = n1.dot(n2);
+ real_t sphere_at = n1.dot(n2);
if (sphere_at>=0 && sphere_at<n1.dot(n1)) {
@@ -650,7 +650,7 @@ public:
return true;
}
- float r2=p_sphere_radius*p_sphere_radius;
+ real_t r2=p_sphere_radius*p_sphere_radius;
if (n2.length_squared()<r2) {
@@ -726,8 +726,8 @@ public:
int outside_count = 0;
for (int a = 0; a < polygon.size(); a++) {
- //float p_plane.d = (*this) * polygon[a];
- float dist = p_plane.distance_to(polygon[a]);
+ //real_t p_plane.d = (*this) * polygon[a];
+ real_t dist = p_plane.distance_to(polygon[a]);
if (dist <-CMP_POINT_IN_PLANE_EPSILON) {
location_cache[a] = LOC_INSIDE;
inside_count++;
@@ -761,8 +761,8 @@ public:
const Vector3& v2 = polygon[index];
Vector3 segment= v1 - v2;
- double den=p_plane.normal.dot( segment );
- double dist=p_plane.distance_to( v1 ) / den;
+ real_t den=p_plane.normal.dot( segment );
+ real_t dist=p_plane.distance_to( v1 ) / den;
dist=-dist;
clipped.push_back( v1 + segment * dist );
}
@@ -771,8 +771,8 @@ public:
if ((loc == LOC_INSIDE) && (location_cache[previous] == LOC_OUTSIDE)) {
const Vector3& v2 = polygon[previous];
Vector3 segment= v1 - v2;
- double den=p_plane.normal.dot( segment );
- double dist=p_plane.distance_to( v1 ) / den;
+ real_t den=p_plane.normal.dot( segment );
+ real_t dist=p_plane.distance_to( v1 ) / den;
dist=-dist;
clipped.push_back( v1 + segment * dist );
}
@@ -808,7 +808,7 @@ public:
static PoolVector< PoolVector< Face3 > > separate_objects( PoolVector< Face3 > p_array );
- static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, float *p_error=NULL ); ///< create a "wrap" that encloses the given geometry
+ static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, real_t *p_error=NULL ); ///< create a "wrap" that encloses the given geometry
struct MeshData {
@@ -884,9 +884,9 @@ public:
}
- static double vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B)
+ static real_t vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B)
{
- return (double)(A.x - O.x) * (B.y - O.y) - (double)(A.y - O.y) * (B.x - O.x);
+ return (real_t)(A.x - O.x) * (B.y - O.y) - (real_t)(A.y - O.y) * (B.x - O.x);
}
// Returns a list of points on the convex hull in counter-clockwise order.
@@ -918,10 +918,10 @@ public:
}
static MeshData build_convex_mesh(const PoolVector<Plane> &p_planes);
- static PoolVector<Plane> build_sphere_planes(float p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z);
+ static PoolVector<Plane> build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z);
static PoolVector<Plane> build_box_planes(const Vector3& p_extents);
- static PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
- static PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
+ static PoolVector<Plane> build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
+ static PoolVector<Plane> build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
static void make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, Size2i& r_size);
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp
index c6860ba2e..76eeece68 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -239,10 +239,10 @@ Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, co
real_t t3 = t2 * t;
Vector2 out;
- out = 0.5f * ( ( p1 * 2.0f) +
+ out = 0.5 * ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
- ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 +
- ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 );
+ ( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 +
+ ( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 );
return out;
/*
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 8353aa0eb..c730b4fa3 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -27,12 +27,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "math_funcs.h"
-
#include "core/os/os.h"
-#include "float.h"
-uint32_t Math::default_seed=1;
-
+pcg32_random_t Math::default_pcg = {1, PCG_DEFAULT_INC_64};
#define PHI 0x9e3779b9
@@ -40,59 +37,30 @@ uint32_t Math::default_seed=1;
static uint32_t Q[4096];
#endif
-uint32_t Math::rand_from_seed(uint32_t *seed) {
- // Xorshift31 PRNG
- if ( *seed == 0 ) *seed = Math::RANDOM_MAX;
- (*seed) ^= (*seed) << 13;
- (*seed) ^= (*seed) >> 17;
- (*seed) ^= (*seed) << 5;
- return (*seed) & Math::RANDOM_MAX;
+// TODO: we should eventually expose pcg.inc too
+uint32_t Math::rand_from_seed(uint64_t *seed) {
+ pcg32_random_t pcg = {*seed, PCG_DEFAULT_INC_64};
+ uint32_t r = pcg32_random_r(&pcg);
+ *seed = pcg.state;
+ return r;
}
-void Math::seed(uint32_t x) {
- default_seed=x;
+void Math::seed(uint64_t x) {
+ default_pcg.state=x;
}
void Math::randomize() {
OS::Time time = OS::get_singleton()->get_time();
- seed(OS::get_singleton()->get_ticks_usec()*(time.hour+1)*(time.min+1)*(time.sec+1)*rand()); /* *OS::get_singleton()->get_time().sec); // windows doesn't have get_time(), returns always 0 */
+ seed(OS::get_singleton()->get_ticks_usec()*(time.hour+1)*(time.min+1)*(time.sec+1)*rand()); // TODO: can be simplified.
}
uint32_t Math::rand() {
-
- return rand_from_seed(&default_seed);
-}
-
-double Math::randf() {
-
- return (double)rand() / (double)Math::RANDOM_MAX;
-}
-
-
-double Math::round(double p_val) {
-
- if (p_val>=0) {
- return ::floor(p_val+0.5);
- } else {
- p_val=-p_val;
- return -::floor(p_val+0.5);
- }
-}
-
-double Math::dectime(double p_value,double p_amount, double p_step) {
-
- float sgn = p_value < 0 ? -1.0 : 1.0;
- float val = absf(p_value);
- val-=p_amount*p_step;
- if (val<0.0)
- val=0.0;
- return val*sgn;
+ return pcg32_random_r(&default_pcg);
}
int Math::step_decimals(double p_step) {
-
static const int maxn=9;
static const double sd[maxn]={
0.9999, // somehow compensate for floating point error
@@ -106,7 +74,7 @@ int Math::step_decimals(double p_step) {
0.000000009999
};
- double as=absf(p_step);
+ double as=Math::abs(p_step);
for(int i=0;i<maxn;i++) {
if (as>=sd[i]) {
return i;
@@ -116,8 +84,16 @@ int Math::step_decimals(double p_step) {
return maxn;
}
-double Math::ease(double p_x, double p_c) {
+double Math::dectime(double p_value,double p_amount, double p_step) {
+ double sgn = p_value < 0 ? -1.0 : 1.0;
+ double val = Math::abs(p_value);
+ val-=p_amount*p_step;
+ if (val<0.0)
+ val=0.0;
+ return val*sgn;
+}
+double Math::ease(double p_x, double p_c) {
if (p_x<0)
p_x=0;
else if (p_x>1.0)
@@ -138,20 +114,16 @@ double Math::ease(double p_x, double p_c) {
}
} else
return 0; // no ease (raw)
-
}
double Math::stepify(double p_value,double p_step) {
-
if (p_step!=0) {
-
- p_value=floor( p_value / p_step + 0.5 ) * p_step;
+ p_value=Math::floor( p_value / p_step + 0.5 ) * p_step;
}
return p_value;
}
-
uint32_t Math::larger_prime(uint32_t p_val) {
static const uint32_t primes[] = {
@@ -200,22 +172,15 @@ uint32_t Math::larger_prime(uint32_t p_val) {
}
double Math::random(double from, double to) {
-
unsigned int r = Math::rand();
double ret = (double)r/(double)RANDOM_MAX;
return (ret)*(to-from) + from;
}
-double Math::pow(double x, double y) {
-
- return ::pow(x,y);
+float Math::random(float from, float to) {
+ unsigned int r = Math::rand();
+ float ret = (float)r/(float)RANDOM_MAX;
+ return (ret)*(to-from) + from;
}
-double Math::log(double x) {
-
- return ::log(x);
-}
-double Math::exp(double x) {
- return ::exp(x);
-}
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 8ce59224f..511af9183 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -31,18 +31,19 @@
#include "typedefs.h"
#include "math_defs.h"
+#include "pcg.h"
-#ifndef NO_MATH_H
#include <math.h>
-#endif
-
+#include <float.h>
+
#define Math_PI 3.14159265358979323846
#define Math_SQRT12 0.7071067811865475244008443621048490
+#define Math_LN2 0.693147180559945309417
class Math {
+ static pcg32_random_t default_pcg;
- static uint32_t default_seed;
public:
Math() {} // useless to instance
@@ -51,149 +52,122 @@ public:
};
- static _ALWAYS_INLINE_ double sin(double p_x) {
-
- return ::sin(p_x);
-
- }
-
- static _ALWAYS_INLINE_ double cos(double p_x) {
-
- return ::cos(p_x);
-
- }
-
- static _ALWAYS_INLINE_ double tan(double p_x) {
-
- return ::tan(p_x);
-
- }
- static _ALWAYS_INLINE_ double sinh(double p_x) {
-
- return ::sinh(p_x);
- }
-
- static _ALWAYS_INLINE_ double cosh(double p_x) {
-
- return ::cosh(p_x);
- }
-
- static _ALWAYS_INLINE_ double tanh(double p_x) {
-
- return ::tanh(p_x);
- }
+ static _ALWAYS_INLINE_ double sin(double p_x) { return ::sin(p_x); }
+ static _ALWAYS_INLINE_ float sin(float p_x) { return ::sinf(p_x); }
+ static _ALWAYS_INLINE_ double cos(double p_x) { return ::cos(p_x); }
+ static _ALWAYS_INLINE_ float cos(float p_x) { return ::cosf(p_x); }
- static _ALWAYS_INLINE_ double asin(double p_x) {
+ static _ALWAYS_INLINE_ double tan(double p_x) { return ::tan(p_x); }
+ static _ALWAYS_INLINE_ float tan(float p_x) { return ::tanf(p_x); }
- return ::asin(p_x);
+ static _ALWAYS_INLINE_ double sinh(double p_x) { return ::sinh(p_x); }
+ static _ALWAYS_INLINE_ float sinh(float p_x) { return ::sinhf(p_x); }
- }
+ static _ALWAYS_INLINE_ double cosh(double p_x) { return ::cosh(p_x); }
+ static _ALWAYS_INLINE_ float cosh(float p_x) { return ::coshf(p_x); }
- static _ALWAYS_INLINE_ double acos(double p_x) {
+ static _ALWAYS_INLINE_ double tanh(double p_x) { return ::tanh(p_x); }
+ static _ALWAYS_INLINE_ float tanh(float p_x) { return ::tanhf(p_x); }
- return ::acos(p_x);
- }
+ static _ALWAYS_INLINE_ double asin(double p_x) { return ::asin(p_x); }
+ static _ALWAYS_INLINE_ float asin(float p_x) { return ::asinf(p_x); }
- static _ALWAYS_INLINE_ double atan(double p_x) {
+ static _ALWAYS_INLINE_ double acos(double p_x) { return ::acos(p_x); }
+ static _ALWAYS_INLINE_ float acos(float p_x) { return ::acosf(p_x); }
- return ::atan(p_x);
- }
+ static _ALWAYS_INLINE_ double atan(double p_x) { return ::atan(p_x); }
+ static _ALWAYS_INLINE_ float atan(float p_x) { return ::atanf(p_x); }
- static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) {
+ static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { return ::atan2(p_y,p_x); }
+ static _ALWAYS_INLINE_ float atan2(float p_y, float p_x) { return ::atan2f(p_y,p_x); }
- return ::atan2(p_y,p_x);
+ static _ALWAYS_INLINE_ double sqrt(double p_x) { return ::sqrt(p_x); }
+ static _ALWAYS_INLINE_ float sqrt(float p_x) { return ::sqrtf(p_x); }
- }
+ static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) { return ::fmod(p_x,p_y); }
+ static _ALWAYS_INLINE_ float fmod(float p_x,float p_y) { return ::fmodf(p_x,p_y); }
- static _ALWAYS_INLINE_ double deg2rad(double p_y) {
+ static _ALWAYS_INLINE_ double floor(double p_x) { return ::floor(p_x); }
+ static _ALWAYS_INLINE_ float floor(float p_x) { return ::floorf(p_x); }
- return p_y*Math_PI/180.0;
- }
+ static _ALWAYS_INLINE_ double ceil(double p_x) { return ::ceil(p_x); }
+ static _ALWAYS_INLINE_ float ceil(float p_x) { return ::ceilf(p_x); }
- static _ALWAYS_INLINE_ double rad2deg(double p_y) {
+ static _ALWAYS_INLINE_ double pow(double p_x, double p_y) { return ::pow(p_x,p_y); }
+ static _ALWAYS_INLINE_ float pow(float p_x, float p_y) { return ::powf(p_x,p_y); }
- return p_y*180.0/Math_PI;
- }
+ static _ALWAYS_INLINE_ double log(double p_x) { return ::log(p_x); }
+ static _ALWAYS_INLINE_ float log(float p_x) { return ::logf(p_x); }
+ static _ALWAYS_INLINE_ double exp(double p_x) { return ::exp(p_x); }
+ static _ALWAYS_INLINE_ float exp(float p_x) { return ::expf(p_x); }
- static _ALWAYS_INLINE_ double sqrt(double p_x) {
+ static _ALWAYS_INLINE_ bool is_nan(double p_val) { return (p_val!=p_val); }
+ static _ALWAYS_INLINE_ bool is_nan(float p_val) { return (p_val!=p_val); }
- return ::sqrt(p_x);
+ static _ALWAYS_INLINE_ bool is_inf(double p_val) {
+ #ifdef _MSC_VER
+ return !_finite(p_val);
+ #else
+ return isinf(p_val);
+ #endif
}
-
- static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) {
-
- return ::fmod(p_x,p_y);
+
+ static _ALWAYS_INLINE_ bool is_inf(float p_val) {
+ #ifdef _MSC_VER
+ return !_finite(p_val);
+ #else
+ return isinf(p_val);
+ #endif
}
+
+ static _ALWAYS_INLINE_ double abs(double g) { return absd(g); }
+ static _ALWAYS_INLINE_ float abs(float g) { return absf(g); }
+ static _ALWAYS_INLINE_ int abs(int g) { return g > 0 ? g : -g; }
- static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) {
-
- if (p_x>=0) {
-
- return fmod(p_x,p_y);
+ static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) { return (p_x>=0) ? Math::fmod(p_x,p_y) : p_y-Math::fmod(-p_x,p_y); }
+ static _ALWAYS_INLINE_ float fposmod(float p_x,float p_y) { return (p_x>=0) ? Math::fmod(p_x,p_y) : p_y-Math::fmod(-p_x,p_y); }
- } else {
+ static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y*Math_PI/180.0; }
+ static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y*Math_PI/180.0; }
- return p_y-fmod(-p_x,p_y);
- }
-
- }
- static _ALWAYS_INLINE_ double floor(double p_x) {
+ static _ALWAYS_INLINE_ double rad2deg(double p_y) { return p_y*180.0/Math_PI; }
+ static _ALWAYS_INLINE_ float rad2deg(float p_y) { return p_y*180.0/Math_PI; }
- return ::floor(p_x);
- }
-
- static _ALWAYS_INLINE_ double ceil(double p_x) {
+ static _ALWAYS_INLINE_ double lerp(double a, double b, double c) { return a+(b-a)*c; }
+ static _ALWAYS_INLINE_ float lerp(float a, float b, float c) { return a+(b-a)*c; }
- return ::ceil(p_x);
- }
+ static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log( p_linear ) * 8.6858896380650365530225783783321; }
+ static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log( p_linear ) * 8.6858896380650365530225783783321; }
+ static _ALWAYS_INLINE_ double db2linear(double p_db) { return Math::exp( p_db * 0.11512925464970228420089957273422 ); }
+ static _ALWAYS_INLINE_ float db2linear(float p_db) { return Math::exp( p_db * 0.11512925464970228420089957273422 ); }
- static uint32_t rand_from_seed(uint32_t *seed);
+ static _ALWAYS_INLINE_ double round(double p_val) { return (p_val>=0) ? Math::floor(p_val+0.5) : -Math::floor(-p_val+0.5); }
+ static _ALWAYS_INLINE_ float round(float p_val) { return (p_val>=0) ? Math::floor(p_val+0.5) : -Math::floor(-p_val+0.5); }
+ // double only, as these functions are mainly used by the editor and not performance-critical,
static double ease(double p_x, double p_c);
static int step_decimals(double p_step);
static double stepify(double p_value,double p_step);
- static void seed(uint32_t x=0);
- static void randomize();
- static uint32_t larger_prime(uint32_t p_val);
static double dectime(double p_value,double p_amount, double p_step);
+ static uint32_t larger_prime(uint32_t p_val);
- static inline double linear2db(double p_linear) {
-
- return Math::log( p_linear ) * 8.6858896380650365530225783783321;
- }
-
- static inline double db2linear(double p_db) {
-
- return Math::exp( p_db * 0.11512925464970228420089957273422 );
- }
-
- static _ALWAYS_INLINE_ bool is_nan(double p_val) {
-
- return (p_val!=p_val);
- }
-
- static _ALWAYS_INLINE_ bool is_inf(double p_val) {
-
- #ifdef _MSC_VER
- return !_finite(p_val);
- #else
- return isinf(p_val);
- #endif
-
- }
-
+ static void seed(uint64_t x=0);
+ static void randomize();
+ static uint32_t rand_from_seed(uint64_t *seed);
static uint32_t rand();
- static double randf();
-
- static double round(double p_val);
+ static _ALWAYS_INLINE_ double randf() { return (double)rand() / (double)Math::RANDOM_MAX; }
+ static _ALWAYS_INLINE_ float randd() { return (float)rand() / (float)Math::RANDOM_MAX; }
static double random(double from, double to);
+ static float random(float from, float to);
+ static real_t random(int from, int to) { return (real_t)random((real_t)from, (real_t)to); }
- static _FORCE_INLINE_ bool isequal_approx(real_t a, real_t b) {
+
+ static _ALWAYS_INLINE_ bool isequal_approx(real_t a, real_t b) {
// TODO: Comparing floats for approximate-equality is non-trivial.
// Using epsilon should cover the typical cases in Godot (where a == b is used to compare two reals), such as matrix and vector comparison operators.
// A proper implementation in terms of ULPs should eventually replace the contents of this function.
@@ -203,18 +177,7 @@ public:
}
- static _FORCE_INLINE_ real_t abs(real_t g) {
-
-#ifdef REAL_T_IS_DOUBLE
-
- return absd(g);
-#else
-
- return absf(g);
-#endif
- }
-
- static _FORCE_INLINE_ float absf(float g) {
+ static _ALWAYS_INLINE_ float absf(float g) {
union {
float f;
@@ -226,7 +189,7 @@ public:
return u.f;
}
- static _FORCE_INLINE_ double absd(double g) {
+ static _ALWAYS_INLINE_ double absd(double g) {
union {
double d;
@@ -238,12 +201,12 @@ public:
}
//this function should be as fast as possible and rounding mode should not matter
- static _FORCE_INLINE_ int fast_ftoi(float a) {
+ static _ALWAYS_INLINE_ int fast_ftoi(float a) {
static int b;
#if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone?
- b = (int)((a>0.0f) ? (a + 0.5f):(a -0.5f));
+ b = (int)((a>0.0) ? (a + 0.5):(a -0.5));
#elif defined(_MSC_VER) && _MSC_VER < 1800
__asm fld a
@@ -266,23 +229,16 @@ public:
#if defined(__GNUC__)
- static _FORCE_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
+ static _ALWAYS_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
+ static _ALWAYS_INLINE_ int64_t dtoll(float p_float) { return (int64_t)p_float; } ///@TODO OPTIMIZE and rename
#else
- static _FORCE_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
+ static _ALWAYS_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
+ static _ALWAYS_INLINE_ int64_t dtoll(float p_float) { return (int64_t)p_float; } ///@TODO OPTIMIZE and rename
#endif
- static _FORCE_INLINE_ float lerp(float a, float b, float c) {
-
- return a+(b-a)*c;
- }
-
- static double pow(double x, double y);
- static double log(double x);
- static double exp(double x);
-
- static _FORCE_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h)
+ static _ALWAYS_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h)
{
uint16_t h_exp, h_sig;
uint32_t f_sgn, f_exp, f_sig;
@@ -314,7 +270,7 @@ public:
}
}
- static _FORCE_INLINE_ float halfptr_to_float(const uint16_t *h) {
+ static _ALWAYS_INLINE_ float halfptr_to_float(const uint16_t *h) {
union {
uint32_t u32;
@@ -325,7 +281,7 @@ public:
return u.f32;
}
- static _FORCE_INLINE_ uint16_t make_half_float(float f) {
+ static _ALWAYS_INLINE_ uint16_t make_half_float(float f) {
union {
float fv;
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index e9c344258..1fabfbbd4 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -504,9 +504,9 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
ERR_FAIL_COND(is_rotation() == false);
- double angle,x,y,z; // variables for result
- double epsilon = 0.01; // margin to allow for rounding errors
- double epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
+ real_t angle,x,y,z; // variables for result
+ real_t epsilon = 0.01; // margin to allow for rounding errors
+ real_t epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
if ( (Math::abs(elements[1][0]-elements[0][1])< epsilon)
&& (Math::abs(elements[2][0]-elements[0][2])< epsilon)
@@ -525,12 +525,12 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
}
// otherwise this singularity is angle = 180
angle = Math_PI;
- double xx = (elements[0][0]+1)/2;
- double yy = (elements[1][1]+1)/2;
- double zz = (elements[2][2]+1)/2;
- double xy = (elements[1][0]+elements[0][1])/4;
- double xz = (elements[2][0]+elements[0][2])/4;
- double yz = (elements[2][1]+elements[1][2])/4;
+ real_t xx = (elements[0][0]+1)/2;
+ real_t yy = (elements[1][1]+1)/2;
+ real_t zz = (elements[2][2]+1)/2;
+ real_t xy = (elements[1][0]+elements[0][1])/4;
+ real_t xz = (elements[2][0]+elements[0][2])/4;
+ real_t yz = (elements[2][1]+elements[1][2])/4;
if ((xx > yy) && (xx > zz)) { // elements[0][0] is the largest diagonal term
if (xx< epsilon) {
x = 0;
@@ -567,7 +567,7 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
return;
}
// as we have reached here there are no singularities so we can handle normally
- double s = Math::sqrt((elements[1][2] - elements[2][1])*(elements[1][2] - elements[2][1])
+ real_t s = Math::sqrt((elements[1][2] - elements[2][1])*(elements[1][2] - elements[2][1])
+(elements[2][0] - elements[0][2])*(elements[2][0] - elements[0][2])
+(elements[0][1] - elements[1][0])*(elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise
diff --git a/core/math/octree.h b/core/math/octree.h
index 3630922d1..e566df6a4 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -435,7 +435,7 @@ int Octree<T,use_pairs,AL>::get_subindex(OctreeElementID p_id) const {
template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant) {
- float element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues
+ real_t element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues
if (p_octant->aabb.size.x/OCTREE_DIVISOR < element_size) {
//if (p_octant->aabb.size.x*0.5 < element_size) {
diff --git a/core/math/pcg.cpp b/core/math/pcg.cpp
new file mode 100644
index 000000000..eac3b36d3
--- /dev/null
+++ b/core/math/pcg.cpp
@@ -0,0 +1,15 @@
+// *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org
+// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
+
+#include "pcg.h"
+
+uint32_t pcg32_random_r(pcg32_random_t* rng)
+{
+ uint64_t oldstate = rng->state;
+ // Advance internal state
+ rng->state = oldstate * 6364136223846793005ULL + (rng->inc|1);
+ // Calculate output function (XSH RR), uses old state for max ILP
+ uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
+ uint32_t rot = oldstate >> 59u;
+ return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
+}
diff --git a/core/math/pcg.h b/core/math/pcg.h
new file mode 100644
index 000000000..81f4c9770
--- /dev/null
+++ b/core/math/pcg.h
@@ -0,0 +1,14 @@
+// *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org
+// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
+
+#ifndef RANDOM_H
+#define RANDOM_H
+
+#include "typedefs.h"
+
+#define PCG_DEFAULT_INC_64 1442695040888963407ULL
+
+typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t;
+uint32_t pcg32_random_r(pcg32_random_t* rng);
+
+#endif // RANDOM_H
diff --git a/core/math/plane.h b/core/math/plane.h
index f746ea206..8235c5913 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -99,7 +99,7 @@ real_t Plane::distance_to(const Vector3 &p_point) const {
bool Plane::has_point(const Vector3 &p_point,real_t _epsilon) const {
- float dist=normal.dot(p_point) - d;
+ real_t dist=normal.dot(p_point) - d;
dist=ABS(dist);
return ( dist <= _epsilon);
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index 055e2b7c3..4085f9b84 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -124,8 +124,8 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
// Standard case (slerp)
real_t sine = Math::sqrt(1 - cosine*cosine);
real_t angle = Math::atan2(sine, cosine);
- real_t inv_sine = 1.0f / sine;
- real_t coeff_0 = Math::sin((1.0f - t) * angle) * inv_sine;
+ real_t inv_sine = 1.0 / sine;
+ real_t coeff_0 = Math::sin((1.0 - t) * angle) * inv_sine;
real_t coeff_1 = Math::sin(t * angle) * inv_sine;
Quat ret= src * coeff_0 + dst * coeff_1;
@@ -137,7 +137,7 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
// 2. "rkP" and "q" are almost invedste of each other (cosine ~= -1), there
// are an infinite number of possibilities interpolation. but we haven't
// have method to fix this case, so just use linear interpolation here.
- Quat ret = src * (1.0f - t) + dst *t;
+ Quat ret = src * (1.0 - t) + dst *t;
// taking the complement requires renormalisation
ret.normalize();
return ret;
@@ -194,14 +194,14 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
const Quat &from = *this;
- float dot = from.dot(q);
+ real_t dot = from.dot(q);
- if (Math::absf(dot) > 0.9999f) return from;
+ if (Math::absf(dot) > 0.9999) return from;
- float theta = Math::acos(dot),
- sinT = 1.0f / Math::sin(theta),
+ real_t theta = Math::acos(dot),
+ sinT = 1.0 / Math::sin(theta),
newFactor = Math::sin(t * theta) * sinT,
- invFactor = Math::sin((1.0f - t) * theta) * sinT;
+ invFactor = Math::sin((1.0 - t) * theta) * sinT;
return Quat(invFactor * from.x + newFactor * q.x,
invFactor * from.y + newFactor * q.y,
@@ -259,7 +259,7 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const {
//the only way to do slerp :|
- float t2 = (1.0-t)*t*2;
+ real_t t2 = (1.0-t)*t*2;
Quat sp = this->slerp(q,t);
Quat sq = prep.slerpni(postq,t);
return sp.slerpni(sq,t2);
diff --git a/core/math/quat.h b/core/math/quat.h
index 43c2cab9e..d3a50343a 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -119,8 +119,8 @@ public:
w=0;
} else {
- real_t s = Math::sqrt((1.0f + d) * 2.0f);
- real_t rs = 1.0f / s;
+ real_t s = Math::sqrt((1.0 + d) * 2.0);
+ real_t rs = 1.0 / s;
x=c.x*rs;
y=c.y*rs;
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index 756e48d0b..32fc0e01e 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -86,7 +86,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
if (!valid_points[i])
continue;
- float d = p_points[i][longest_axis];
+ real_t d = p_points[i][longest_axis];
if (i==0 || d < min) {
simplex[0]=i;
@@ -105,7 +105,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
{
- float maxd;
+ real_t maxd;
Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]];
for(int i=0;i<p_points.size();i++) {
@@ -127,7 +127,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
//fourth vertex is the one most further away from the plane
{
- float maxd;
+ real_t maxd;
Plane p(p_points[simplex[0]],p_points[simplex[1]],p_points[simplex[2]]);
for(int i=0;i<p_points.size();i++) {
diff --git a/core/math/rect3.cpp b/core/math/rect3.cpp
index e0b064650..d3f95b89e 100644
--- a/core/math/rect3.cpp
+++ b/core/math/rect3.cpp
@@ -30,7 +30,7 @@
#include "print_string.h"
-float Rect3::get_area() const {
+real_t Rect3::get_area() const {
return size.x*size.y*size.z;
@@ -114,8 +114,8 @@ bool Rect3::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3*
Vector3 c1, c2;
Vector3 end = pos+size;
- float near=-1e20;
- float far=1e20;
+ real_t near=-1e20;
+ real_t far=1e20;
int axis=0;
for (int i=0;i<3;i++){
@@ -159,7 +159,7 @@ bool Rect3::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector
real_t min=0,max=1;
int axis=0;
- float sign=0;
+ real_t sign=0;
for(int i=0;i<3;i++) {
real_t seg_from=p_from[i];
@@ -167,7 +167,7 @@ bool Rect3::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector
real_t box_begin=pos[i];
real_t box_end=box_begin+size[i];
real_t cmin,cmax;
- float csign;
+ real_t csign;
if (seg_from < seg_to) {
diff --git a/core/math/rect3.h b/core/math/rect3.h
index 80c67200f..902592b02 100644
--- a/core/math/rect3.h
+++ b/core/math/rect3.h
@@ -33,6 +33,8 @@
#include "vector3.h"
#include "plane.h"
+#include "math_defs.h"
+
/**
* AABB / AABB (Axis Aligned Bounding Box)
* This is implemented by a point (pos) and the box size
@@ -45,7 +47,7 @@ public:
Vector3 pos;
Vector3 size;
- float get_area() const; /// get area
+ real_t get_area() const; /// get area
_FORCE_INLINE_ bool has_no_area() const {
return (size.x<=CMP_EPSILON || size.y<=CMP_EPSILON || size.z<=CMP_EPSILON);
@@ -74,7 +76,7 @@ public:
Rect3 intersection(const Rect3& p_aabb) const; ///get box where two intersect, empty if no intersection occurs
bool intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
- _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, float t0, float t1) const;
+ _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, real_t t0, real_t t1) const;
_FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
bool intersects_plane(const Plane &p_plane) const;
@@ -98,7 +100,7 @@ public:
_FORCE_INLINE_ Vector3 get_endpoint(int p_point) const;
Rect3 expand(const Vector3& p_vector) const;
- _FORCE_INLINE_ void project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max) const;
+ _FORCE_INLINE_ void project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const;
_FORCE_INLINE_ void expand_to(const Vector3& p_vector); /** expand to contain a point if necesary */
operator String() const;
@@ -293,13 +295,13 @@ inline void Rect3::expand_to(const Vector3& p_vector) {
size=end-begin;
}
-void Rect3::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max) const {
+void Rect3::project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const {
Vector3 half_extents( size.x * 0.5, size.y * 0.5, size.z * 0.5 );
Vector3 center( pos.x + half_extents.x, pos.y + half_extents.y, pos.z + half_extents.z );
- float length = p_plane.normal.abs().dot(half_extents);
- float distance = p_plane.distance_to( center );
+ real_t length = p_plane.normal.abs().dot(half_extents);
+ real_t distance = p_plane.distance_to( center );
r_min = distance - length;
r_max = distance + length;
}
@@ -334,14 +336,14 @@ inline real_t Rect3::get_shortest_axis_size() const {
return max_size;
}
-bool Rect3::smits_intersect_ray(const Vector3 &from,const Vector3& dir, float t0, float t1) const {
+bool Rect3::smits_intersect_ray(const Vector3 &from,const Vector3& dir, real_t t0, real_t t1) const {
- float divx=1.0/dir.x;
- float divy=1.0/dir.y;
- float divz=1.0/dir.z;
+ real_t divx=1.0/dir.x;
+ real_t divy=1.0/dir.y;
+ real_t divz=1.0/dir.z;
Vector3 upbound=pos+size;
- float tmin, tmax, tymin, tymax, tzmin, tzmax;
+ real_t tmin, tmax, tymin, tymax, tzmin, tzmax;
if (dir.x >= 0) {
tmin = (pos.x - from.x) * divx;
tmax = (upbound.x - from.x) * divx;
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index 86f8bf29e..247cb90a4 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -340,7 +340,7 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end
if (f3.intersects_segment(p_begin,p_end,&res)) {
- float nd = n.dot(res);
+ real_t nd = n.dot(res);
if (nd<d) {
d=nd;
@@ -462,7 +462,7 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec
if (f3.intersects_ray(p_begin,p_dir,&res)) {
- float nd = n.dot(res);
+ real_t nd = n.dot(res);
if (nd<d) {
d=nd;
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index 82b49be7f..128b6ca33 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -28,19 +28,19 @@
/*************************************************************************/
#include "triangulate.h"
-float Triangulate::get_area(const Vector<Vector2> &contour)
+real_t Triangulate::get_area(const Vector<Vector2> &contour)
{
int n = contour.size();
const Vector2 *c=&contour[0];
- float A=0.0f;
+ real_t A=0.0;
for(int p=n-1,q=0; q<n; p=q++)
{
A+= c[p].cross(c[q]);
}
- return A*0.5f;
+ return A*0.5;
}
/*
@@ -48,14 +48,14 @@ float Triangulate::get_area(const Vector<Vector2> &contour)
defined by A, B, C.
*/
-bool Triangulate::is_inside_triangle(float Ax, float Ay,
- float Bx, float By,
- float Cx, float Cy,
- float Px, float Py)
+bool Triangulate::is_inside_triangle(real_t Ax, real_t Ay,
+ real_t Bx, real_t By,
+ real_t Cx, real_t Cy,
+ real_t Px, real_t Py)
{
- float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
- float cCROSSap, bCROSScp, aCROSSbp;
+ real_t ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
+ real_t cCROSSap, bCROSScp, aCROSSbp;
ax = Cx - Bx; ay = Cy - By;
bx = Ax - Cx; by = Ay - Cy;
@@ -68,13 +68,13 @@ bool Triangulate::is_inside_triangle(float Ax, float Ay,
cCROSSap = cx*apy - cy*apx;
bCROSScp = bx*cpy - by*cpx;
- return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
+ return ((aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0));
};
bool Triangulate::snip(const Vector<Vector2> &p_contour,int u,int v,int w,int n,const Vector<int>& V)
{
int p;
- float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
+ real_t Ax, Ay, Bx, By, Cx, Cy, Px, Py;
const Vector2 *contour=&p_contour[0];
Ax = contour[V[u]].x;
@@ -112,7 +112,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result
/* we want a counter-clockwise polygon in V */
- if ( 0.0f < get_area(contour) )
+ if ( 0.0 < get_area(contour) )
for (int v=0; v<n; v++) V[v] = v;
else
for(int v=0; v<n; v++) V[v] = (n-1)-v;
diff --git a/core/math/triangulate.h b/core/math/triangulate.h
index d22677a8b..ce7733451 100644
--- a/core/math/triangulate.h
+++ b/core/math/triangulate.h
@@ -45,14 +45,14 @@ public:
static bool triangulate(const Vector< Vector2 > &contour, Vector<int> &result);
// compute area of a contour/polygon
- static float get_area(const Vector< Vector2 > &contour);
+ static real_t get_area(const Vector< Vector2 > &contour);
// decide if point Px/Py is inside triangle defined by
// (Ax,Ay) (Bx,By) (Cx,Cy)
- static bool is_inside_triangle(float Ax, float Ay,
- float Bx, float By,
- float Cx, float Cy,
- float Px, float Py);
+ static bool is_inside_triangle(real_t Ax, real_t Ay,
+ real_t Bx, real_t By,
+ real_t Cx, real_t Cy,
+ real_t Px, real_t Py);
private:
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 3eb978333..2ab5fa046 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -30,12 +30,12 @@
#include "matrix3.h"
-void Vector3::rotate(const Vector3& p_axis,float p_phi) {
+void Vector3::rotate(const Vector3& p_axis,real_t p_phi) {
*this=Basis(p_axis,p_phi).xform(*this);
}
-Vector3 Vector3::rotated(const Vector3& p_axis,float p_phi) const {
+Vector3 Vector3::rotated(const Vector3& p_axis,real_t p_phi) const {
Vector3 r = *this;
r.rotate(p_axis,p_phi);
@@ -63,13 +63,13 @@ int Vector3::max_axis() const {
}
-void Vector3::snap(float p_val) {
+void Vector3::snap(real_t p_val) {
x=Math::stepify(x,p_val);
y=Math::stepify(y,p_val);
z=Math::stepify(z,p_val);
}
-Vector3 Vector3::snapped(float p_val) const {
+Vector3 Vector3::snapped(real_t p_val) const {
Vector3 v=*this;
v.snap(p_val);
@@ -77,7 +77,7 @@ Vector3 Vector3::snapped(float p_val) const {
}
-Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const {
+Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
@@ -87,9 +87,9 @@ Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, c
{
//normalize
- float ab = p0.distance_to(p1);
- float bc = p1.distance_to(p2);
- float cd = p2.distance_to(p3);
+ real_t ab = p0.distance_to(p1);
+ real_t bc = p1.distance_to(p2);
+ real_t cd = p2.distance_to(p3);
if (ab>0)
p0 = p1+(p0-p1)*(bc/ab);
@@ -98,41 +98,41 @@ Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, c
}
- float t = p_t;
- float t2 = t * t;
- float t3 = t2 * t;
+ real_t t = p_t;
+ real_t t2 = t * t;
+ real_t t3 = t2 * t;
Vector3 out;
- out = 0.5f * ( ( p1 * 2.0f) +
+ out = 0.5 * ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
- ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 +
- ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 );
+ ( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 +
+ ( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 );
return out;
}
-Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const {
+Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
Vector3 p2=p_b;
Vector3 p3=p_post_b;
- float t = p_t;
- float t2 = t * t;
- float t3 = t2 * t;
+ real_t t = p_t;
+ real_t t2 = t * t;
+ real_t t3 = t2 * t;
Vector3 out;
- out = 0.5f * ( ( p1 * 2.0f) +
+ out = 0.5 * ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
- ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 +
- ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 );
+ ( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 +
+ ( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 );
return out;
}
#if 0
-Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const {
+Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
@@ -141,9 +141,9 @@ Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, co
if (true) {
- float ab = p0.distance_to(p1);
- float bc = p1.distance_to(p2);
- float cd = p2.distance_to(p3);
+ real_t ab = p0.distance_to(p1);
+ real_t bc = p1.distance_to(p2);
+ real_t cd = p2.distance_to(p3);
//if (ab>bc) {
if (ab>0)
@@ -156,23 +156,23 @@ Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, co
//}
}
- float t = p_t;
- float t2 = t * t;
- float t3 = t2 * t;
+ real_t t = p_t;
+ real_t t2 = t * t;
+ real_t t3 = t2 * t;
Vector3 out;
- out.x = 0.5f * ( ( 2.0f * p1.x ) +
+ out.x = 0.5 * ( ( 2.0 * p1.x ) +
( -p0.x + p2.x ) * t +
- ( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 +
- ( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 );
- out.y = 0.5f * ( ( 2.0f * p1.y ) +
+ ( 2.0 * p0.x - 5.0 * p1.x + 4 * p2.x - p3.x ) * t2 +
+ ( -p0.x + 3.0 * p1.x - 3.0 * p2.x + p3.x ) * t3 );
+ out.y = 0.5 * ( ( 2.0 * p1.y ) +
( -p0.y + p2.y ) * t +
- ( 2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y ) * t2 +
- ( -p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y ) * t3 );
- out.z = 0.5f * ( ( 2.0f * p1.z ) +
+ ( 2.0 * p0.y - 5.0 * p1.y + 4 * p2.y - p3.y ) * t2 +
+ ( -p0.y + 3.0 * p1.y - 3.0 * p2.y + p3.y ) * t3 );
+ out.z = 0.5 * ( ( 2.0 * p1.z ) +
( -p0.z + p2.z ) * t +
- ( 2.0f * p0.z - 5.0f * p1.z + 4 * p2.z - p3.z ) * t2 +
- ( -p0.z + 3.0f * p1.z - 3.0f * p2.z + p3.z ) * t3 );
+ ( 2.0 * p0.z - 5.0 * p1.z + 4 * p2.z - p3.z ) * t2 +
+ ( -p0.z + 3.0 * p1.z - 3.0 * p2.z + p3.z ) * t3 );
return out;
}
# endif
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 9ae9b69df..a289f9bf4 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -79,17 +79,17 @@ struct Vector3 {
_FORCE_INLINE_ void zero();
- void snap(float p_val);
- Vector3 snapped(float p_val) const;
+ void snap(real_t p_val);
+ Vector3 snapped(real_t p_val) const;
- void rotate(const Vector3& p_axis,float p_phi);
- Vector3 rotated(const Vector3& p_axis,float p_phi) const;
+ void rotate(const Vector3& p_axis,real_t p_phi);
+ Vector3 rotated(const Vector3& p_axis,real_t p_phi) const;
/* Static Methods between 2 vector3s */
- _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,float p_t) const;
- Vector3 cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const;
- Vector3 cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const;
+ _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,real_t p_t) const;
+ Vector3 cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const;
+ Vector3 cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const;
_FORCE_INLINE_ Vector3 cross(const Vector3& p_b) const;
_FORCE_INLINE_ real_t dot(const Vector3& p_b) const;
@@ -195,7 +195,7 @@ Vector3 Vector3::ceil() const {
return Vector3( Math::ceil(x), Math::ceil(y), Math::ceil(z) );
}
-Vector3 Vector3::linear_interpolate(const Vector3& p_b,float p_t) const {
+Vector3 Vector3::linear_interpolate(const Vector3& p_b,real_t p_t) const {
return Vector3(
x+(p_t * (p_b.x-x)),
diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h
index 36b42c84f..a35e44b66 100644
--- a/core/method_ptrcall.h
+++ b/core/method_ptrcall.h
@@ -74,7 +74,7 @@ MAKE_PTRARG(Vector3);
MAKE_PTRARG(Transform2D);
MAKE_PTRARG(Plane);
MAKE_PTRARG(Quat);
-MAKE_PTRARG(AABB);
+MAKE_PTRARG(Rect3);
MAKE_PTRARG(Basis);
MAKE_PTRARG(Transform);
MAKE_PTRARG(Color);
@@ -84,13 +84,13 @@ MAKE_PTRARG(RID);
MAKE_PTRARG(InputEvent);
MAKE_PTRARG(Dictionary);
MAKE_PTRARG(Array);
-MAKE_PTRARG(ByteArray);
-MAKE_PTRARG(IntArray);
-MAKE_PTRARG(RealArray);
-MAKE_PTRARG(StringArray);
-MAKE_PTRARG(Vector2Array);
-MAKE_PTRARG(Vector3Array);
-MAKE_PTRARG(ColorArray);
+MAKE_PTRARG(PoolByteArray);
+MAKE_PTRARG(PoolIntArray);
+MAKE_PTRARG(PoolRealArray);
+MAKE_PTRARG(PoolStringArray);
+MAKE_PTRARG(PoolVector2Array);
+MAKE_PTRARG(PoolVector3Array);
+MAKE_PTRARG(PoolColorArray);
MAKE_PTRARG(Variant);
diff --git a/core/object.h b/core/object.h
index b9a800afc..3032452cc 100644
--- a/core/object.h
+++ b/core/object.h
@@ -103,6 +103,7 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_SCRIPT_VARIABLE=8192,
PROPERTY_USAGE_STORE_IF_NULL=16384,
PROPERTY_USAGE_ANIMATE_AS_TRIGGER=32768,
+ PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED=65536,
PROPERTY_USAGE_DEFAULT=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK,
PROPERTY_USAGE_DEFAULT_INTL=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_INTERNATIONALIZED,
diff --git a/core/os/input.cpp b/core/os/input.cpp
index e53aa82b1..4e7b03745 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -38,7 +38,7 @@ Input *Input::get_singleton() {
}
void Input::set_mouse_mode(MouseMode p_mode) {
- ERR_FAIL_INDEX(p_mode,3);
+ ERR_FAIL_INDEX(p_mode,4);
OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode);
}
@@ -87,6 +87,7 @@ void Input::_bind_methods() {
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")) );
}
diff --git a/core/os/input.h b/core/os/input.h
index 82c7a80d3..2cea154a5 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -47,7 +47,8 @@ public:
enum MouseMode {
MOUSE_MODE_VISIBLE,
MOUSE_MODE_HIDDEN,
- MOUSE_MODE_CAPTURED
+ MOUSE_MODE_CAPTURED,
+ MOUSE_MODE_CONFINED
};
void set_mouse_mode(MouseMode p_mode);
diff --git a/core/os/os.h b/core/os/os.h
index ea03481a9..42c7c18b0 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -131,7 +131,8 @@ public:
enum MouseMode {
MOUSE_MODE_VISIBLE,
MOUSE_MODE_HIDDEN,
- MOUSE_MODE_CAPTURED
+ MOUSE_MODE_CAPTURED,
+ MOUSE_MODE_CONFINED
};
virtual void set_mouse_mode(MouseMode p_mode);
diff --git a/core/pair.h b/core/pair.h
index d75cbed64..174ffb388 100644
--- a/core/pair.h
+++ b/core/pair.h
@@ -39,4 +39,13 @@ struct Pair {
Pair( F p_first, S p_second) { first=p_first; second=p_second; }
};
+template<class F,class S>
+struct PairSort {
+
+ bool operator()(const Pair<F,S>& A, const Pair<F,S>& B) const {
+ return A.first < B.first;
+ }
+};
+
+
#endif // PAIR_H
diff --git a/core/path_remap.cpp b/core/path_remap.cpp
index ed77fd884..bbaba71bb 100644
--- a/core/path_remap.cpp
+++ b/core/path_remap.cpp
@@ -28,185 +28,3 @@
/*************************************************************************/
#include "path_remap.h"
-#include "globals.h"
-#include "os/os.h"
-#include "translation.h"
-
-PathRemap* PathRemap::singleton=NULL;
-
-PathRemap* PathRemap::get_singleton() {
-
- return singleton;
-}
-
-void PathRemap::add_remap(const String& p_from, const String& p_to,const String& p_locale) {
-
- if (!remap.has(p_from)) {
- remap[p_from]=RemapData();
- }
-
- if (p_locale==String())
- remap[p_from].always=p_to;
- else
- remap[p_from].locale[p_locale]=p_to;
-}
-
-
-String PathRemap::get_remap(const String& p_from) const {
-
- const RemapData *ptr=remap.getptr(p_from);
- if (!ptr) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap failed: "+p_from);
- return p_from;
- } else {
-
- const RemapData *ptr2=NULL;
-
- String locale = TranslationServer::get_singleton()->get_locale();
-
- if (ptr->locale.has(locale)) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap found: "+p_from+" -> "+ptr->locale[locale]);
-
- ptr2=remap.getptr(ptr->locale[locale]);
-
- if (ptr2 && ptr2->always!=String()) //may have atlas or export remap too
- return ptr2->always;
- else
- return ptr->locale[locale];
- }
-
- int p = locale.find("_");
- if (p!=-1) {
- locale=locale.substr(0,p);
- if (ptr->locale.has(locale)) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap found: "+p_from+" -> "+ptr->locale[locale]);
-
- ptr2=remap.getptr(ptr->locale[locale]);
-
- if (ptr2 && ptr2->always!=String()) //may have atlas or export remap too
- return ptr2->always;
- else
- return ptr->locale[locale];
-
- }
- }
-
- if (ptr->always!=String()) {
- if (OS::get_singleton()->is_stdout_verbose()) {
- print_line("remap found: "+p_from+" -> "+ptr->always);
- }
- return ptr->always;
- }
-
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap failed: "+p_from);
-
- return p_from;
- }
-}
-bool PathRemap::has_remap(const String& p_from) const{
-
- return remap.has(p_from);
-}
-
-void PathRemap::erase_remap(const String& p_from){
-
- ERR_FAIL_COND(!remap.has(p_from));
- remap.erase(p_from);
-}
-
-void PathRemap::clear_remaps() {
-
- remap.clear();
-}
-
-void PathRemap::load_remaps() {
-
- // default remaps first
- PoolVector<String> remaps;
- if (GlobalConfig::get_singleton()->has("remap/all")) {
- remaps = GlobalConfig::get_singleton()->get("remap/all");
- }
-
- {
- int rlen = remaps.size();
-
- ERR_FAIL_COND( rlen%2 );
- PoolVector<String>::Read r = remaps.read();
- for(int i=0;i<rlen/2;i++) {
-
- String from = r[i*2+0];
- String to = r[i*2+1];
- add_remap(from,to);
- }
- }
-
-
- // platform remaps second, so override
- if (GlobalConfig::get_singleton()->has("remap/"+OS::get_singleton()->get_name())) {
- remaps = GlobalConfig::get_singleton()->get("remap/"+OS::get_singleton()->get_name());
- } else {
- remaps.resize(0);
- }
- //remaps = Globals::get_singleton()->get("remap/PSP");
- {
- int rlen = remaps.size();
-
- ERR_FAIL_COND( rlen%2 );
- PoolVector<String>::Read r = remaps.read();
- for(int i=0;i<rlen/2;i++) {
-
- String from = r[i*2+0];
- String to = r[i*2+1];
- //print_line("add remap: "+from+" -> "+to);
- add_remap(from,to);
- }
- }
-
-
- //locale based remaps
-
- if (GlobalConfig::get_singleton()->has("locale/translation_remaps")) {
-
- Dictionary remaps = GlobalConfig::get_singleton()->get("locale/translation_remaps");
- List<Variant> rk;
- remaps.get_key_list(&rk);
- for(List<Variant>::Element *E=rk.front();E;E=E->next()) {
-
- String source = E->get();
- PoolStringArray sa = remaps[E->get()];
- int sas = sa.size();
- PoolStringArray::Read r = sa.read();
-
- for(int i=0;i<sas;i++) {
-
- String s = r[i];
- int qp = s.find_last(":");
- if (qp!=-1) {
- String path = s.substr(0,qp);
- String locale = s.substr(qp+1,s.length());
- add_remap(source,path,locale);
- }
- }
- }
-
- }
-
-}
-
-void PathRemap::_bind_methods() {
-
- ClassDB::bind_method(_MD("add_remap","from","to","locale"),&PathRemap::add_remap,DEFVAL(String()));
- ClassDB::bind_method(_MD("has_remap","path"),&PathRemap::has_remap);
- ClassDB::bind_method(_MD("get_remap","path"),&PathRemap::get_remap);
- ClassDB::bind_method(_MD("erase_remap","path"),&PathRemap::erase_remap);
- ClassDB::bind_method(_MD("clear_remaps"),&PathRemap::clear_remaps);
-}
-
-PathRemap::PathRemap() {
-
- singleton=this;
-}
diff --git a/core/path_remap.h b/core/path_remap.h
index a106030f9..966bb10ea 100644
--- a/core/path_remap.h
+++ b/core/path_remap.h
@@ -29,39 +29,4 @@
#ifndef PATH_REMAP_H
#define PATH_REMAP_H
-#include "hash_map.h"
-#include "ustring.h"
-#include "object.h"
-
-
-class PathRemap : public Object {
-
- GDCLASS(PathRemap,Object);
-
- static PathRemap* singleton;
- struct RemapData {
- String always;
- Map<String,String> locale;
- };
-
- HashMap<String,RemapData> remap;
-protected:
-
- static void _bind_methods();
-public:
-
- void add_remap(const String& p_from, const String& p_to,const String& p_locale=String());
- bool has_remap(const String& p_from) const;
- //_FORCE_INLINE_ String get_remap(const String& p_from) const { const String *ptr=remap.getptr(p_from); if (!ptr) return p_from; else return *ptr; }
- String get_remap(const String& p_from) const;
- void erase_remap(const String& p_from);
- void clear_remaps();
-
- void load_remaps();
-
- static PathRemap* get_singleton();
-
- PathRemap();
-};
-
#endif // PATH_REMAP_H
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 242d36042..ab94b56cd 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -45,6 +45,7 @@
#include "compressed_translation.h"
#include "io/translation_loader_po.h"
#include "io/resource_format_binary.h"
+#include "io/resource_import.h"
#include "io/stream_peer_ssl.h"
#include "os/input.h"
#include "core/io/xml_parser.h"
@@ -57,7 +58,7 @@
static ResourceFormatSaverBinary *resource_saver_binary=NULL;
static ResourceFormatLoaderBinary *resource_loader_binary=NULL;
-
+static ResourceFormatImporter *resource_format_importer=NULL;
static _ResourceLoader *_resource_loader=NULL;
static _ResourceSaver *_resource_saver=NULL;
@@ -105,12 +106,14 @@ void register_core_types() {
resource_loader_binary = memnew( ResourceFormatLoaderBinary );
ResourceLoader::add_resource_format_loader(resource_loader_binary);
+ resource_format_importer = memnew( ResourceFormatImporter );
+ ResourceLoader::add_resource_format_loader(resource_format_importer);
+
ClassDB::register_class<Object>();
ClassDB::register_class<Reference>();
ClassDB::register_class<WeakRef>();
- ClassDB::register_class<ResourceImportMetadata>();
ClassDB::register_class<Resource>();
ClassDB::register_class<FuncRef>();
ClassDB::register_virtual_class<StreamPeer>();
@@ -179,13 +182,11 @@ void register_core_singletons() {
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Geometry",_Geometry::get_singleton()) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceLoader",_ResourceLoader::get_singleton()) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceSaver",_ResourceSaver::get_singleton()) );
- GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("PathRemap",PathRemap::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("OS",_OS::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Engine",_Engine::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ClassDB",_classdb ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Marshalls",_Marshalls::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("TranslationServer",TranslationServer::get_singleton() ) );
- GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("TS",TranslationServer::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Input",Input::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("InputMap",InputMap::get_singleton() ) );
@@ -209,6 +210,8 @@ void unregister_core_types() {
memdelete(resource_saver_binary);
if (resource_loader_binary)
memdelete(resource_loader_binary);
+ if (resource_format_importer)
+ memdelete(resource_format_importer);
memdelete( resource_format_po );
diff --git a/core/resource.cpp b/core/resource.cpp
index 4b09a506f..9b5bac5f3 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -35,119 +35,6 @@
#include <stdio.h>
-void ResourceImportMetadata::set_editor(const String& p_editor) {
-
- editor=p_editor;
-}
-
-String ResourceImportMetadata::get_editor() const{
-
- return editor;
-}
-
-void ResourceImportMetadata::add_source(const String& p_path,const String& p_md5) {
-
- Source s;
- s.md5=p_md5;
- s.path=p_path;
- sources.push_back(s);
-}
-
-String ResourceImportMetadata::get_source_path(int p_idx) const{
- ERR_FAIL_INDEX_V(p_idx,sources.size(),String());
- return sources[p_idx].path;
-}
-String ResourceImportMetadata::get_source_md5(int p_idx) const{
- ERR_FAIL_INDEX_V(p_idx,sources.size(),String());
- return sources[p_idx].md5;
-}
-
-void ResourceImportMetadata::set_source_md5(int p_idx,const String& p_md5) {
-
- ERR_FAIL_INDEX(p_idx,sources.size());
- sources[p_idx].md5=p_md5;
-
-}
-
-void ResourceImportMetadata::remove_source(int p_idx){
-
- ERR_FAIL_INDEX(p_idx,sources.size());
- sources.remove(p_idx);
-
-}
-
-int ResourceImportMetadata::get_source_count() const {
-
- return sources.size();
-}
-void ResourceImportMetadata::set_option(const String& p_key, const Variant& p_value) {
-
- if (p_value.get_type()==Variant::NIL) {
- options.erase(p_key);
- return;
- }
-
- ERR_FAIL_COND(p_value.get_type() == Variant::OBJECT);
- ERR_FAIL_COND(p_value.get_type() == Variant::_RID);
-
- options[p_key]=p_value;
-
-}
-
-bool ResourceImportMetadata::has_option(const String& p_key) const {
-
- return options.has(p_key);
-}
-
-Variant ResourceImportMetadata::get_option(const String& p_key) const {
-
- ERR_FAIL_COND_V(!options.has(p_key),Variant());
-
- return options[p_key];
-}
-
-void ResourceImportMetadata::get_options(List<String> *r_options) const {
-
- for(Map<String,Variant>::Element *E=options.front();E;E=E->next()) {
-
- r_options->push_back(E->key());
- }
-
-}
-
-PoolStringArray ResourceImportMetadata::_get_options() const {
-
- PoolStringArray option_names;
- option_names.resize(options.size());
- int i=0;
- for(Map<String,Variant>::Element *E=options.front();E;E=E->next()) {
-
- option_names.set(i++,E->key());
- }
-
- return option_names;
-}
-
-void ResourceImportMetadata::_bind_methods() {
-
- ClassDB::bind_method(_MD("set_editor","name"),&ResourceImportMetadata::set_editor);
- ClassDB::bind_method(_MD("get_editor"),&ResourceImportMetadata::get_editor);
- ClassDB::bind_method(_MD("add_source","path","md5"),&ResourceImportMetadata::add_source, "");
- ClassDB::bind_method(_MD("get_source_path","idx"),&ResourceImportMetadata::get_source_path);
- ClassDB::bind_method(_MD("get_source_md5","idx"),&ResourceImportMetadata::get_source_md5);
- ClassDB::bind_method(_MD("set_source_md5","idx", "md5"),&ResourceImportMetadata::set_source_md5);
- ClassDB::bind_method(_MD("remove_source","idx"),&ResourceImportMetadata::remove_source);
- ClassDB::bind_method(_MD("get_source_count"),&ResourceImportMetadata::get_source_count);
- ClassDB::bind_method(_MD("set_option","key","value"),&ResourceImportMetadata::set_option);
- ClassDB::bind_method(_MD("get_option","key"),&ResourceImportMetadata::get_option);
- ClassDB::bind_method(_MD("get_options"),&ResourceImportMetadata::_get_options);
-}
-
-ResourceImportMetadata::ResourceImportMetadata() {
-
-
-}
-
void Resource::emit_changed() {
@@ -381,21 +268,6 @@ void Resource::notify_change_to_owners() {
}
}
-void Resource::set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata) {
-#ifdef TOOLS_ENABLED
- import_metadata=p_metadata;
-#endif
-}
-
-Ref<ResourceImportMetadata> Resource::get_import_metadata() const {
-
-#ifdef TOOLS_ENABLED
- return import_metadata;
-#else
- return Ref<ResourceImportMetadata>();
-#endif
-
-}
#ifdef TOOLS_ENABLED
@@ -461,8 +333,6 @@ void Resource::_bind_methods() {
ClassDB::bind_method(_MD("set_name","name"),&Resource::set_name);
ClassDB::bind_method(_MD("get_name"),&Resource::get_name);
ClassDB::bind_method(_MD("get_rid"),&Resource::get_rid);
- ClassDB::bind_method(_MD("set_import_metadata","metadata"),&Resource::set_import_metadata);
- ClassDB::bind_method(_MD("get_import_metadata"),&Resource::get_import_metadata);
ClassDB::bind_method(_MD("set_local_to_scene","enable"),&Resource::set_local_to_scene);
ClassDB::bind_method(_MD("is_local_to_scene"),&Resource::is_local_to_scene);
ClassDB::bind_method(_MD("get_local_scene:Node"),&Resource::get_local_scene);
@@ -483,9 +353,11 @@ Resource::Resource() {
#ifdef TOOLS_ENABLED
last_modified_time=0;
+ import_last_modified_time=0;
#endif
subindex=0;
+ local_to_scene=false;
local_scene=NULL;
}
diff --git a/core/resource.h b/core/resource.h
index 2b071c8e1..b29077a3b 100644
--- a/core/resource.h
+++ b/core/resource.h
@@ -46,47 +46,6 @@ virtual String get_base_extension() const { return m_ext; }\
private:
-class ResourceImportMetadata : public Reference {
-
- GDCLASS( ResourceImportMetadata, Reference );
-
- struct Source {
- String path;
- String md5;
- };
-
- Vector<Source> sources;
- String editor;
-
- Map<String,Variant> options;
-
- PoolStringArray _get_options() const;
-
-protected:
-
- static void _bind_methods();
-public:
-
- void set_editor(const String& p_editor);
- String get_editor() const;
-
- void add_source(const String& p_path,const String& p_md5="");
- String get_source_path(int p_idx) const;
- String get_source_md5(int p_idx) const;
- void set_source_md5(int p_idx,const String& p_md5);
- void remove_source(int p_idx);
- int get_source_count() const;
-
- void set_option(const String& p_key, const Variant& p_value);
- Variant get_option(const String& p_key) const;
- bool has_option(const String& p_key) const;
-
- void get_options(List<String> *r_options) const;
-
-
- ResourceImportMetadata();
-};
-
class Resource : public Reference {
@@ -106,8 +65,9 @@ friend class ResourceCache;
virtual bool _use_builtin_script() const { return true; }
#ifdef TOOLS_ENABLED
- Ref<ResourceImportMetadata> import_metadata;
uint64_t last_modified_time;
+ uint64_t import_last_modified_time;
+ String import_path;
#endif
bool local_to_scene;
@@ -147,10 +107,6 @@ public:
Ref<Resource> duplicate(bool p_subresources=false);
Ref<Resource> duplicate_for_local_scene(Node *p_scene,Map<Ref<Resource>,Ref<Resource> >& remap_cache);
-
- void set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata);
- Ref<ResourceImportMetadata> get_import_metadata() const;
-
void set_local_to_scene(bool p_enable);
bool is_local_to_scene() const;
virtual void setup_local_to_scene();
@@ -164,6 +120,12 @@ public:
virtual void set_last_modified_time(uint64_t p_time) { last_modified_time=p_time; }
uint64_t get_last_modified_time() const { return last_modified_time; }
+ virtual void set_import_last_modified_time(uint64_t p_time) { import_last_modified_time=p_time; }
+ uint64_t get_import_last_modified_time() const { return import_last_modified_time; }
+
+ void set_import_path(const String& p_path) { import_path=p_path; }
+ String get_import_path() const { return import_path; }
+
#endif
virtual RID get_rid() const; // some resources may offer conversion to RID
diff --git a/core/translation.cpp b/core/translation.cpp
index d5ec61b8d..8835cb133 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -751,6 +751,20 @@ static const char* locale_names[]={
0
};
+bool TranslationServer::is_locale_valid(const String& p_locale) {
+
+ const char **ptr=locale_list;
+
+ while (*ptr) {
+
+ if (*ptr==p_locale)
+ return true;
+ ptr++;
+ }
+
+ return false;
+
+}
Vector<String> TranslationServer::get_all_locales() {
diff --git a/core/translation.h b/core/translation.h
index 85ab4a229..feed35254 100644
--- a/core/translation.h
+++ b/core/translation.h
@@ -102,6 +102,7 @@ public:
static Vector<String> get_all_locales();
static Vector<String> get_all_locale_names();
+ static bool is_locale_valid(const String& p_locale);
void set_tool_translation(const Ref<Translation>& p_translation);
StringName tool_translate(const StringName& p_message) const;
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 71934b295..a0d26ea0a 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3410,8 +3410,17 @@ String String::c_escape() const {
escaped=escaped.replace("\t","\\t");
escaped=escaped.replace("\v","\\v");
escaped=escaped.replace("\'","\\'");
- escaped=escaped.replace("\"","\\\"");
escaped=escaped.replace("\?","\\?");
+ escaped=escaped.replace("\"","\\\"");
+
+ return escaped;
+}
+
+String String::c_escape_multiline() const {
+
+ String escaped=*this;
+ escaped=escaped.replace("\\","\\\\");
+ escaped=escaped.replace("\"","\\\"");
return escaped;
}
@@ -3898,10 +3907,9 @@ String String::get_extension() const {
String String::plus_file(const String& p_file) const {
if (empty())
return p_file;
- if (operator [](length()-1)=='/' || p_file.operator [](0)=='/')
+ if (operator [](length()-1)=='/' || (p_file.size()>0 && p_file.operator [](0)=='/'))
return *this+p_file;
- else
- return *this+"/"+p_file;
+ return *this+"/"+p_file;
}
String String::percent_encode() const {
diff --git a/core/ustring.h b/core/ustring.h
index 426762a9e..5665a2311 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -218,6 +218,7 @@ public:
String http_escape() const;
String http_unescape() const;
String c_escape() const;
+ String c_escape_multiline() const;
String c_unescape() const;
String json_escape() const;
String word_wrap(int p_chars_per_line) const;
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index a833a275d..1e938b489 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -1873,7 +1873,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
String str=p_variant;
- str="\""+str.c_escape()+"\"";
+ str="\""+str.c_escape_multiline()+"\"";
p_store_string_func(p_store_string_ud, str );
} break;
case Variant::VECTOR2: {
@@ -2091,7 +2091,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
dict.get_key_list(&keys);
keys.sort();
- p_store_string_func(p_store_string_ud,"{ ");
+ p_store_string_func(p_store_string_ud,"{\n");
for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
/*
@@ -2099,14 +2099,14 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
continue;
*/
write(E->get(),p_store_string_func,p_store_string_ud,p_encode_res_func,p_encode_res_ud);
- p_store_string_func(p_store_string_ud,":");
+ p_store_string_func(p_store_string_ud,": ");
write(dict[E->get()],p_store_string_func,p_store_string_ud,p_encode_res_func,p_encode_res_ud);
if (E->next())
- p_store_string_func(p_store_string_ud,", ");
+ p_store_string_func(p_store_string_ud,",\n");
}
- p_store_string_func(p_store_string_ud," }");
+ p_store_string_func(p_store_string_ud,"\n}");
} break;