summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub74
-rw-r--r--core/allocators.h2
-rw-r--r--core/array.cpp54
-rw-r--r--core/array.h13
-rw-r--r--core/bind/SCsub4
-rw-r--r--core/bind/core_bind.cpp930
-rw-r--r--core/bind/core_bind.h156
-rw-r--r--core/color.cpp24
-rw-r--r--core/color.h3
-rw-r--r--core/color_names.inc150
-rw-r--r--core/command_queue_mt.cpp2
-rw-r--r--core/command_queue_mt.h2
-rw-r--r--core/compressed_translation.cpp34
-rw-r--r--core/compressed_translation.h10
-rw-r--r--core/core_string_names.cpp2
-rw-r--r--core/core_string_names.h2
-rw-r--r--core/dictionary.cpp136
-rw-r--r--core/dictionary.h12
-rw-r--r--core/dvector.cpp43
-rw-r--r--core/dvector.h510
-rw-r--r--core/engine.cpp (renamed from core/os/memory_pool_static.cpp)89
-rw-r--r--core/engine.h (renamed from core/os/memory_pool_dynamic.h)77
-rw-r--r--core/error_list.h26
-rw-r--r--core/error_macros.cpp2
-rw-r--r--core/error_macros.h5
-rw-r--r--core/event_queue.cpp2
-rw-r--r--core/event_queue.h2
-rw-r--r--core/func_ref.cpp8
-rw-r--r--core/func_ref.h4
-rw-r--r--core/global_constants.cpp33
-rw-r--r--core/global_constants.h2
-rw-r--r--core/globals.cpp815
-rw-r--r--core/globals.h23
-rw-r--r--core/hash_map.h18
-rw-r--r--core/hashfuncs.h7
-rw-r--r--core/helper/value_evaluator.h4
-rw-r--r--core/image.cpp1301
-rw-r--r--core/image.h214
-rw-r--r--core/image_quantize.cpp365
-rw-r--r--core/input_map.cpp42
-rw-r--r--core/input_map.h6
-rw-r--r--core/int_types.h2
-rw-r--r--core/io/SCsub8
-rw-r--r--core/io/compression.cpp2
-rw-r--r--core/io/compression.h2
-rw-r--r--core/io/config_file.cpp26
-rw-r--r--core/io/config_file.h8
-rw-r--r--core/io/file_access_buffered.cpp6
-rw-r--r--core/io/file_access_buffered.h2
-rw-r--r--core/io/file_access_buffered_fa.h13
-rw-r--r--core/io/file_access_compressed.cpp2
-rw-r--r--core/io/file_access_compressed.h2
-rw-r--r--core/io/file_access_encrypted.cpp2
-rw-r--r--core/io/file_access_encrypted.h2
-rw-r--r--core/io/file_access_memory.cpp10
-rw-r--r--core/io/file_access_memory.h2
-rw-r--r--core/io/file_access_network.cpp22
-rw-r--r--core/io/file_access_network.h4
-rw-r--r--core/io/file_access_pack.cpp6
-rw-r--r--core/io/file_access_pack.h4
-rw-r--r--core/io/file_access_zip.cpp4
-rw-r--r--core/io/file_access_zip.h2
-rw-r--r--core/io/http_client.cpp98
-rw-r--r--core/io/http_client.h16
-rw-r--r--core/io/image_loader.cpp6
-rw-r--r--core/io/image_loader.h2
-rw-r--r--core/io/ip.cpp67
-rw-r--r--core/io/ip.h22
-rw-r--r--core/io/ip_address.cpp206
-rw-r--r--core/io/ip_address.h37
-rw-r--r--core/io/json.cpp31
-rw-r--r--core/io/json.h6
-rw-r--r--core/io/marshalls.cpp236
-rw-r--r--core/io/marshalls.h2
-rw-r--r--core/io/networked_multiplayer_peer.cpp16
-rw-r--r--core/io/networked_multiplayer_peer.h2
-rw-r--r--core/io/packet_peer.cpp33
-rw-r--r--core/io/packet_peer.h16
-rw-r--r--core/io/packet_peer_udp.cpp38
-rw-r--r--core/io/packet_peer_udp.h15
-rw-r--r--core/io/pck_packer.cpp191
-rw-r--r--core/io/pck_packer.h (renamed from core/os/memory_pool_dynamic.cpp)37
-rw-r--r--core/io/resource_format_binary.cpp318
-rw-r--r--core/io/resource_format_binary.h2
-rw-r--r--core/io/resource_format_xml.cpp2889
-rw-r--r--core/io/resource_format_xml.h170
-rw-r--r--core/io/resource_loader.cpp56
-rw-r--r--core/io/resource_loader.h4
-rw-r--r--core/io/resource_saver.cpp8
-rw-r--r--core/io/resource_saver.h2
-rw-r--r--core/io/stream_peer.cpp124
-rw-r--r--core/io/stream_peer.h16
-rw-r--r--core/io/stream_peer_ssl.cpp12
-rw-r--r--core/io/stream_peer_ssl.h14
-rw-r--r--core/io/stream_peer_tcp.cpp36
-rw-r--r--core/io/stream_peer_tcp.h15
-rw-r--r--core/io/tcp_server.cpp21
-rw-r--r--core/io/tcp_server.h11
-rw-r--r--core/io/translation_loader_po.cpp6
-rw-r--r--core/io/translation_loader_po.h2
-rw-r--r--core/io/xml_parser.cpp36
-rw-r--r--core/io/xml_parser.h4
-rw-r--r--core/io/zip.c2
-rw-r--r--core/io/zip_io.h2
-rw-r--r--core/list.h2
-rw-r--r--core/make_binders.py189
-rw-r--r--core/map.h4
-rw-r--r--core/math/SCsub4
-rw-r--r--core/math/a_star.cpp82
-rw-r--r--core/math/a_star.h37
-rw-r--r--core/math/aabb.cpp50
-rw-r--r--core/math/aabb.h55
-rw-r--r--core/math/bsp_tree.cpp32
-rw-r--r--core/math/bsp_tree.h12
-rw-r--r--core/math/camera_matrix.cpp37
-rw-r--r--core/math/camera_matrix.h9
-rw-r--r--core/math/face3.cpp4
-rw-r--r--core/math/face3.h12
-rw-r--r--core/math/geometry.cpp50
-rw-r--r--core/math/geometry.h18
-rw-r--r--core/math/math_2d.cpp175
-rw-r--r--core/math/math_2d.h148
-rw-r--r--core/math/math_defs.h2
-rw-r--r--core/math/math_funcs.cpp148
-rw-r--r--core/math/math_funcs.h254
-rw-r--r--core/math/matrix3.cpp360
-rw-r--r--core/math/matrix3.h126
-rw-r--r--core/math/octree.h56
-rw-r--r--core/math/plane.cpp2
-rw-r--r--core/math/plane.h2
-rw-r--r--core/math/quat.cpp93
-rw-r--r--core/math/quat.h15
-rw-r--r--core/math/quick_hull.cpp6
-rw-r--r--core/math/quick_hull.h2
-rw-r--r--core/math/transform.cpp13
-rw-r--r--core/math/transform.h24
-rw-r--r--core/math/triangle_mesh.cpp56
-rw-r--r--core/math/triangle_mesh.h18
-rw-r--r--core/math/triangulate.cpp18
-rw-r--r--core/math/triangulate.h4
-rw-r--r--core/math/triangulator.cpp2
-rw-r--r--core/math/vector3.cpp16
-rw-r--r--core/math/vector3.h220
-rw-r--r--core/message_queue.cpp10
-rw-r--r--core/message_queue.h2
-rw-r--r--core/method_bind.cpp2
-rw-r--r--core/method_bind.h6
-rw-r--r--core/method_ptrcall.h68
-rw-r--r--core/object.cpp204
-rw-r--r--core/object.h164
-rw-r--r--core/object_type_db.cpp419
-rw-r--r--core/object_type_db.h115
-rw-r--r--core/os/SCsub4
-rw-r--r--core/os/copymem.cpp42
-rw-r--r--core/os/copymem.h89
-rw-r--r--core/os/dir_access.cpp8
-rw-r--r--core/os/dir_access.h4
-rw-r--r--core/os/file_access.cpp6
-rw-r--r--core/os/file_access.h2
-rw-r--r--core/os/input.cpp68
-rw-r--r--core/os/input.h13
-rw-r--r--core/os/input_event.cpp23
-rw-r--r--core/os/input_event.h30
-rw-r--r--core/os/keyboard.cpp2
-rw-r--r--core/os/keyboard.h2
-rw-r--r--core/os/main_loop.cpp16
-rw-r--r--core/os/main_loop.h16
-rw-r--r--core/os/memory.cpp156
-rw-r--r--core/os/memory.h229
-rw-r--r--core/os/memory_pool_dynamic_prealloc.cpp116
-rw-r--r--core/os/memory_pool_dynamic_prealloc.h60
-rw-r--r--core/os/memory_pool_dynamic_static.cpp272
-rw-r--r--core/os/memory_pool_dynamic_static.h86
-rw-r--r--core/os/memory_pool_static.h69
-rw-r--r--core/os/mutex.cpp2
-rw-r--r--core/os/mutex.h2
-rw-r--r--core/os/os.cpp101
-rw-r--r--core/os/os.h44
-rw-r--r--core/os/rw_lock.cpp21
-rw-r--r--core/os/rw_lock.h46
-rw-r--r--core/os/semaphore.cpp2
-rw-r--r--core/os/semaphore.h2
-rw-r--r--core/os/shell.cpp2
-rw-r--r--core/os/shell.h2
-rw-r--r--core/os/thread.cpp2
-rw-r--r--core/os/thread.h2
-rw-r--r--core/os/thread_dummy.cpp2
-rw-r--r--core/os/thread_dummy.h2
-rw-r--r--core/os/thread_safe.cpp2
-rw-r--r--core/os/thread_safe.h2
-rw-r--r--core/packed_data_container.cpp62
-rw-r--r--core/packed_data_container.h12
-rw-r--r--core/pair.h5
-rw-r--r--core/path_db.cpp2
-rw-r--r--core/path_db.h2
-rw-r--r--core/path_remap.cpp32
-rw-r--r--core/path_remap.h4
-rw-r--r--core/pool_allocator.cpp6
-rw-r--r--core/pool_allocator.h2
-rw-r--r--core/print_string.cpp2
-rw-r--r--core/print_string.h2
-rw-r--r--core/ref_ptr.cpp2
-rw-r--r--core/ref_ptr.h2
-rw-r--r--core/reference.cpp10
-rw-r--r--core/reference.h6
-rw-r--r--core/register_core_types.cpp150
-rw-r--r--core/register_core_types.h3
-rw-r--r--core/resource.cpp234
-rw-r--r--core/resource.h30
-rw-r--r--core/rid.cpp14
-rw-r--r--core/rid.h206
-rw-r--r--core/ring_buffer.h2
-rw-r--r--core/safe_refcount.cpp72
-rw-r--r--core/safe_refcount.h315
-rw-r--r--core/script_debugger_local.cpp2
-rw-r--r--core/script_debugger_local.h2
-rw-r--r--core/script_debugger_remote.cpp27
-rw-r--r--core/script_debugger_remote.h2
-rw-r--r--core/script_language.cpp16
-rw-r--r--core/script_language.h6
-rw-r--r--core/self_list.h2
-rw-r--r--core/set.h6
-rw-r--r--core/simple_type.h2
-rw-r--r--core/sort.h2
-rw-r--r--core/string_db.cpp55
-rw-r--r--core/string_db.h5
-rw-r--r--core/translation.cpp102
-rw-r--r--core/translation.h12
-rw-r--r--core/typedefs.h6
-rw-r--r--core/ucaps.h2
-rw-r--r--core/undo_redo.cpp37
-rw-r--r--core/undo_redo.h5
-rw-r--r--core/ustring.cpp283
-rw-r--r--core/ustring.h13
-rw-r--r--core/variant.cpp592
-rw-r--r--core/variant.h93
-rw-r--r--core/variant_call.cpp768
-rw-r--r--core/variant_construct_string.cpp2
-rw-r--r--core/variant_op.cpp657
-rw-r--r--core/variant_parser.cpp260
-rw-r--r--core/variant_parser.h2
-rw-r--r--core/vector.h75
-rw-r--r--core/vmap.h2
-rw-r--r--core/vset.h2
244 files changed, 8221 insertions, 11058 deletions
diff --git a/core/SCsub b/core/SCsub
index 4ce91c794f..8d89f6427b 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -1,65 +1,67 @@
+#!/usr/bin/env python
+
Import('env')
-env.core_sources=[]
+env.core_sources = []
-gd_call=""
-gd_inc=""
+gd_call = ""
+gd_inc = ""
for x in env.global_defaults:
- env.core_sources.append("#platform/"+x+"/globals/global_defaults.cpp")
- gd_inc+='#include "platform/'+x+'/globals/global_defaults.h"\n'
- gd_call+="\tregister_"+x+"_global_defaults();\n"
+ env.core_sources.append("#platform/" + x + "/globals/global_defaults.cpp")
+ gd_inc += '#include "platform/' + x + '/globals/global_defaults.h"\n'
+ gd_call += "\tregister_" + x + "_global_defaults();\n"
-gd_cpp='#include "globals.h"\n'
-gd_cpp+=gd_inc
-gd_cpp+="void Globals::register_global_defaults() {\n"+gd_call+"\n}\n"
+gd_cpp = '#include "globals.h"\n'
+gd_cpp += gd_inc
+gd_cpp += "void GlobalConfig::register_global_defaults() {\n" + gd_call + "\n}\n"
-f = open("global_defaults.cpp","wb")
+f = open("global_defaults.cpp", "wb")
f.write(gd_cpp)
f.close()
import os
txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
if ("SCRIPT_AES256_ENCRYPTION_KEY" in os.environ):
- e=os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
- txt = ""
- ec_valid=True
- if (len(e)!=64):
- ec_valid=False
- else:
-
- for i in range(len(e)>>1):
- if (i>0):
- txt+=","
- txts="0x"+e[i*2:i*2+2]
- try:
- int(txts,16)
- except:
- ec_valid=False
- txt+=txts
- if (not ec_valid):
- txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
- print("Invalid AES256 encryption key, not 64 bits hex: "+e)
+ e = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
+ txt = ""
+ ec_valid = True
+ if (len(e) != 64):
+ ec_valid = False
+ else:
+
+ for i in range(len(e) >> 1):
+ if (i > 0):
+ txt += ","
+ txts = "0x" + e[i * 2:i * 2 + 2]
+ try:
+ int(txts, 16)
+ except:
+ ec_valid = False
+ txt += txts
+ if (not ec_valid):
+ txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
+ print("Invalid AES256 encryption key, not 64 bits hex: " + e)
f = open("script_encryption_key.cpp", "wb")
f.write("#include \"globals.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
f.close()
-env.add_source_files(env.core_sources,"*.cpp")
+env.add_source_files(env.core_sources, "*.cpp")
Export('env')
import make_binders
-env.Command(['method_bind.inc','method_bind_ext.inc'], 'make_binders.py', make_binders.run)
+env.Command(['method_bind.inc', 'method_bind_ext.inc'], 'make_binders.py', make_binders.run)
-SConscript('os/SCsub');
-SConscript('math/SCsub');
-SConscript('io/SCsub');
-SConscript('bind/SCsub');
+SConscript('os/SCsub')
+SConscript('math/SCsub')
+SConscript('io/SCsub')
+SConscript('bind/SCsub')
-lib = env.Library("core",env.core_sources)
+lib = env.Library("core", env.core_sources)
env.Prepend(LIBS=[lib])
diff --git a/core/allocators.h b/core/allocators.h
index 4a5fd7a119..14deeb8739 100644
--- a/core/allocators.h
+++ b/core/allocators.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/array.cpp b/core/array.cpp
index 23792f90fc..b9c8f543da 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,7 +36,6 @@ struct ArrayPrivate {
SafeRefCount refcount;
Vector<Variant> array;
- bool shared;
};
void Array::_ref(const Array& p_from) const {
@@ -54,20 +53,9 @@ void Array::_ref(const Array& p_from) const {
_unref();
- if (_fp->shared) {
+ _p = p_from._p;
- _p = p_from._p;
- } else {
-
- _p = memnew( ArrayPrivate );
- _p->shared=false;
- _p->refcount.init();
- _p->array=_fp->array;
-
- if (_fp->refcount.unref())
- memdelete(_fp);
- }
}
void Array::_unref() const {
@@ -106,10 +94,6 @@ void Array::clear() {
_p->array.clear();
}
-bool Array::is_shared() const {
-
- return _p->shared;
-}
bool Array::operator==(const Array& p_array) const {
@@ -150,6 +134,16 @@ void Array::erase(const Variant& p_value) {
_p->array.erase(p_value);
}
+Variant Array::front() const {
+ ERR_FAIL_COND_V(_p->array.size() == 0, Variant());
+ return operator[](0);
+}
+
+Variant Array::back() const {
+ ERR_FAIL_COND_V(_p->array.size() == 0, Variant());
+ return operator[](_p->array.size() - 1);
+}
+
int Array::find(const Variant& p_value, int p_from) const {
return _p->array.find(p_value, p_from);
@@ -276,16 +270,26 @@ void Array::push_front(const Variant& p_value) {
_p->array.insert(0,p_value);
}
-void Array::pop_back(){
+Variant Array::pop_back(){
- if (!_p->array.empty())
- _p->array.resize( _p->array.size() -1 );
+ if (!_p->array.empty()) {
+ int n = _p->array.size() - 1;
+ Variant ret = _p->array.get(n);
+ _p->array.resize(n);
+ return ret;
+ }
+ return Variant();
}
-void Array::pop_front(){
- if (!_p->array.empty())
+Variant Array::pop_front(){
+
+ if (!_p->array.empty()) {
+ Variant ret = _p->array.get(0);
_p->array.remove(0);
+ return ret;
+ }
+ return Variant();
}
@@ -296,11 +300,11 @@ Array::Array(const Array& p_from) {
_ref(p_from);
}
-Array::Array(bool p_shared) {
+Array::Array() {
_p = memnew( ArrayPrivate );
_p->refcount.init();
- _p->shared=p_shared;
+
}
Array::~Array() {
diff --git a/core/array.h b/core/array.h
index dfc902525c..16ab16002c 100644
--- a/core/array.h
+++ b/core/array.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -53,8 +53,6 @@ public:
bool empty() const;
void clear();
- bool is_shared() const;
-
bool operator==(const Array& p_array) const;
uint32_t hash() const;
@@ -67,6 +65,9 @@ public:
void insert(int p_pos, const Variant& p_value);
void remove(int p_pos);
+ Variant front() const;
+ Variant back() const;
+
void sort();
void sort_custom(Object *p_obj,const StringName& p_function);
void invert();
@@ -80,11 +81,11 @@ public:
void erase(const Variant& p_value);
void push_front(const Variant& p_value);
- void pop_back();
- void pop_front();
+ Variant pop_back();
+ Variant pop_front();
Array(const Array& p_from);
- Array(bool p_shared=false);
+ Array();
~Array();
};
diff --git a/core/bind/SCsub b/core/bind/SCsub
index 7b4a6acbc0..4efc902717 100644
--- a/core/bind/SCsub
+++ b/core/bind/SCsub
@@ -1,5 +1,7 @@
+#!/usr/bin/env python
+
Import('env')
-env.add_source_files(env.core_sources,"*.cpp")
+env.add_source_files(env.core_sources, "*.cpp")
Export('env')
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 4e815d044d..657f527a51 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -69,11 +69,11 @@ RES _ResourceLoader::load(const String &p_path,const String& p_type_hint, bool p
return ret;
}
-DVector<String> _ResourceLoader::get_recognized_extensions_for_type(const String& p_type) {
+PoolVector<String> _ResourceLoader::get_recognized_extensions_for_type(const String& p_type) {
List<String> exts;
ResourceLoader::get_recognized_extensions_for_type(p_type,&exts);
- DVector<String> ret;
+ PoolVector<String> ret;
for(List<String>::Element *E=exts.front();E;E=E->next()) {
ret.push_back(E->get());
@@ -87,12 +87,12 @@ void _ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
ResourceLoader::set_abort_on_missing_resources(p_abort);
}
-StringArray _ResourceLoader::get_dependencies(const String& p_path) {
+PoolStringArray _ResourceLoader::get_dependencies(const String& p_path) {
List<String> deps;
ResourceLoader::get_dependencies(p_path, &deps);
- StringArray ret;
+ PoolStringArray ret;
for(List<String>::Element *E=deps.front();E;E=E->next()) {
ret.push_back(E->get());
}
@@ -102,7 +102,7 @@ StringArray _ResourceLoader::get_dependencies(const String& p_path) {
bool _ResourceLoader::has(const String &p_path) {
- String local_path = Globals::get_singleton()->localize_path(p_path);
+ String local_path = GlobalConfig::get_singleton()->localize_path(p_path);
return ResourceCache::has(local_path);
};
@@ -114,13 +114,13 @@ Ref<ResourceImportMetadata> _ResourceLoader::load_import_metadata(const String&
void _ResourceLoader::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL(""));
- ObjectTypeDB::bind_method(_MD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("load_import_metadata:ResourceImportMetadata","path"),&_ResourceLoader::load_import_metadata);
- ObjectTypeDB::bind_method(_MD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type);
- ObjectTypeDB::bind_method(_MD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources);
- ObjectTypeDB::bind_method(_MD("get_dependencies","path"),&_ResourceLoader::get_dependencies);
- ObjectTypeDB::bind_method(_MD("has","path"),&_ResourceLoader::has);
+ 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);
+ ClassDB::bind_method(_MD("has","path"),&_ResourceLoader::has);
}
_ResourceLoader::_ResourceLoader() {
@@ -135,12 +135,12 @@ Error _ResourceSaver::save(const String &p_path,const RES& p_resource, uint32_t
return ResourceSaver::save(p_path,p_resource, p_flags);
}
-DVector<String> _ResourceSaver::get_recognized_extensions(const RES& p_resource) {
+PoolVector<String> _ResourceSaver::get_recognized_extensions(const RES& p_resource) {
- ERR_FAIL_COND_V(p_resource.is_null(),DVector<String>());
+ ERR_FAIL_COND_V(p_resource.is_null(),PoolVector<String>());
List<String> exts;
ResourceSaver::get_recognized_extensions(p_resource,&exts);
- DVector<String> ret;
+ PoolVector<String> ret;
for(List<String>::Element *E=exts.front();E;E=E->next()) {
ret.push_back(E->get());
@@ -153,8 +153,8 @@ _ResourceSaver *_ResourceSaver::singleton=NULL;
void _ResourceSaver::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("save","path","resource:Resource","flags"),&_ResourceSaver::save,DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("get_recognized_extensions","type"),&_ResourceSaver::get_recognized_extensions);
+ ClassDB::bind_method(_MD("save","path","resource:Resource","flags"),&_ResourceSaver::save,DEFVAL(0));
+ ClassDB::bind_method(_MD("get_recognized_extensions","type"),&_ResourceSaver::get_recognized_extensions);
BIND_CONSTANT(FLAG_RELATIVE_PATHS);
BIND_CONSTANT(FLAG_BUNDLE_RESOURCES);
@@ -340,24 +340,6 @@ Array _OS::get_fullscreen_mode_list(int p_screen) const {
return vmarr;
}
-void _OS::set_iterations_per_second(int p_ips) {
-
- OS::get_singleton()->set_iterations_per_second(p_ips);
-}
-int _OS::get_iterations_per_second() const {
-
- return OS::get_singleton()->get_iterations_per_second();
-
-}
-
-void _OS::set_target_fps(int p_fps) {
- OS::get_singleton()->set_target_fps(p_fps);
-}
-
-float _OS::get_target_fps() const {
- return OS::get_singleton()->get_target_fps();
-}
-
void _OS::set_low_processor_usage_mode(bool p_enabled) {
OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
@@ -449,22 +431,10 @@ String _OS::get_latin_keyboard_variant() const {
String _OS::get_model_name() const {
- return OS::get_singleton()->get_model_name();
-}
-
-MainLoop *_OS::get_main_loop() const {
-
- return OS::get_singleton()->get_main_loop();
-}
-
-void _OS::set_time_scale(float p_scale) {
- OS::get_singleton()->set_time_scale(p_scale);
+ return OS::get_singleton()->get_model_name();
}
-float _OS::get_time_scale() {
- return OS::get_singleton()->get_time_scale();
-}
bool _OS::is_ok_left_and_cancel_right() const {
@@ -480,9 +450,9 @@ void _OS::set_use_vsync(bool p_enable) {
OS::get_singleton()->set_use_vsync(p_enable);
}
-bool _OS::is_vsnc_enabled() const {
+bool _OS::is_vsync_enabled() const {
- return OS::get_singleton()->is_vsnc_enabled();
+ return OS::get_singleton()->is_vsync_enabled();
}
@@ -553,6 +523,16 @@ void _OS::set_icon(const Image& p_icon) {
OS::get_singleton()->set_icon(p_icon);
}
+int _OS::get_exit_code() const {
+
+ return OS::get_singleton()->get_exit_code();
+}
+
+void _OS::set_exit_code(int p_code) {
+
+ OS::get_singleton()->set_exit_code(p_code);
+}
+
/**
* Get current datetime with consideration for utc and
* dst
@@ -794,10 +774,6 @@ bool _OS::can_draw() const {
return OS::get_singleton()->can_draw();
}
-int _OS::get_frames_drawn() {
-
- return OS::get_singleton()->get_frames_drawn();
-}
int _OS::get_processor_count() const {
@@ -836,7 +812,7 @@ void _OS::print_all_textures_by_size() {
for (List<Ref<Resource> >::Element *E=rsrc.front();E;E=E->next()) {
- if (!E->get()->is_type("ImageTexture"))
+ if (!E->get()->is_class("ImageTexture"))
continue;
Size2 size = E->get()->call("get_size");
@@ -878,18 +854,18 @@ void _OS::print_resources_by_type(const Vector<String>& p_types) {
bool found = false;
for (int i=0; i<p_types.size(); i++) {
- if (r->is_type(p_types[i]))
+ if (r->is_class(p_types[i]))
found = true;
}
if (!found)
continue;
- if (!type_count.has(r->get_type())) {
- type_count[r->get_type()]=0;
+ if (!type_count.has(r->get_class())) {
+ type_count[r->get_class()]=0;
}
- type_count[r->get_type()]++;
+ type_count[r->get_class()]++;
}
};
@@ -926,11 +902,6 @@ String _OS::get_data_dir() const {
return OS::get_singleton()->get_data_dir();
};
-float _OS::get_frames_per_second() const {
-
- return OS::get_singleton()->get_frames_per_second();
-}
-
Error _OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
return OS::get_singleton()->native_video_play(p_path, p_volume, p_audio_track, p_subtitle_track);
@@ -995,10 +966,7 @@ String _OS::get_system_dir(SystemDir p_dir) const {
return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir));
}
-String _OS::get_custom_level() const {
- return OS::get_singleton()->get_custom_level();
-}
String _OS::get_scancode_string(uint32_t p_code) const {
@@ -1018,163 +986,149 @@ void _OS::alert(const String& p_alert,const String& p_title) {
OS::get_singleton()->alert(p_alert,p_title);
}
-Dictionary _OS::get_engine_version() const {
-
- return OS::get_singleton()->get_engine_version();
-}
-
_OS *_OS::singleton=NULL;
void _OS::_bind_methods() {
- //ObjectTypeDB::bind_method(_MD("get_mouse_pos"),&_OS::get_mouse_pos);
- //ObjectTypeDB::bind_method(_MD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled);
-
- ObjectTypeDB::bind_method(_MD("set_clipboard","clipboard"),&_OS::set_clipboard);
- ObjectTypeDB::bind_method(_MD("get_clipboard"),&_OS::get_clipboard);
-
- ObjectTypeDB::bind_method(_MD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("get_video_mode_size","screen"),&_OS::get_video_mode,DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("is_video_mode_fullscreen","screen"),&_OS::is_video_mode_fullscreen,DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
-
-
- ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count);
- ObjectTypeDB::bind_method(_MD("get_current_screen"),&_OS::get_current_screen);
- ObjectTypeDB::bind_method(_MD("set_current_screen","screen"),&_OS::set_current_screen);
- ObjectTypeDB::bind_method(_MD("get_screen_position","screen"),&_OS::get_screen_position,DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("get_screen_size","screen"),&_OS::get_screen_size,DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("get_screen_dpi","screen"),&_OS::get_screen_dpi,DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position);
- ObjectTypeDB::bind_method(_MD("set_window_position","position"),&_OS::set_window_position);
- ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size);
- ObjectTypeDB::bind_method(_MD("set_window_size","size"),&_OS::set_window_size);
- ObjectTypeDB::bind_method(_MD("set_window_fullscreen","enabled"),&_OS::set_window_fullscreen);
- ObjectTypeDB::bind_method(_MD("is_window_fullscreen"),&_OS::is_window_fullscreen);
- ObjectTypeDB::bind_method(_MD("set_window_resizable","enabled"),&_OS::set_window_resizable);
- ObjectTypeDB::bind_method(_MD("is_window_resizable"),&_OS::is_window_resizable);
- ObjectTypeDB::bind_method(_MD("set_window_minimized", "enabled"),&_OS::set_window_minimized);
- ObjectTypeDB::bind_method(_MD("is_window_minimized"),&_OS::is_window_minimized);
- ObjectTypeDB::bind_method(_MD("set_window_maximized", "enabled"),&_OS::set_window_maximized);
- ObjectTypeDB::bind_method(_MD("is_window_maximized"),&_OS::is_window_maximized);
- ObjectTypeDB::bind_method(_MD("request_attention"), &_OS::request_attention);
-
- ObjectTypeDB::bind_method(_MD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
- ObjectTypeDB::bind_method(_MD("get_borderless_window"), &_OS::get_borderless_window);
-
- ObjectTypeDB::bind_method(_MD("set_screen_orientation","orientation"),&_OS::set_screen_orientation);
- ObjectTypeDB::bind_method(_MD("get_screen_orientation"),&_OS::get_screen_orientation);
-
- ObjectTypeDB::bind_method(_MD("set_keep_screen_on","enabled"),&_OS::set_keep_screen_on);
- ObjectTypeDB::bind_method(_MD("is_keep_screen_on"),&_OS::is_keep_screen_on);
-
- ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second);
- ObjectTypeDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second);
- ObjectTypeDB::bind_method(_MD("set_target_fps","target_fps"),&_OS::set_target_fps);
- ObjectTypeDB::bind_method(_MD("get_target_fps"),&_OS::get_target_fps);
-
- ObjectTypeDB::bind_method(_MD("set_time_scale","time_scale"),&_OS::set_time_scale);
- ObjectTypeDB::bind_method(_MD("get_time_scale"),&_OS::get_time_scale);
-
- ObjectTypeDB::bind_method(_MD("has_touchscreen_ui_hint"),&_OS::has_touchscreen_ui_hint);
-
- ObjectTypeDB::bind_method(_MD("set_window_title","title"),&_OS::set_window_title);
-
- ObjectTypeDB::bind_method(_MD("set_low_processor_usage_mode","enable"),&_OS::set_low_processor_usage_mode);
- ObjectTypeDB::bind_method(_MD("is_in_low_processor_usage_mode"),&_OS::is_in_low_processor_usage_mode);
-
- ObjectTypeDB::bind_method(_MD("get_processor_count"),&_OS::get_processor_count);
-
- ObjectTypeDB::bind_method(_MD("get_executable_path"),&_OS::get_executable_path);
- ObjectTypeDB::bind_method(_MD("execute","path","arguments","blocking","output"),&_OS::execute,DEFVAL(Array()));
- ObjectTypeDB::bind_method(_MD("kill","pid"),&_OS::kill);
- ObjectTypeDB::bind_method(_MD("shell_open","uri"),&_OS::shell_open);
- ObjectTypeDB::bind_method(_MD("get_process_ID"),&_OS::get_process_ID);
-
- ObjectTypeDB::bind_method(_MD("get_environment","environment"),&_OS::get_environment);
- ObjectTypeDB::bind_method(_MD("has_environment","environment"),&_OS::has_environment);
-
- ObjectTypeDB::bind_method(_MD("get_name"),&_OS::get_name);
- ObjectTypeDB::bind_method(_MD("get_cmdline_args"),&_OS::get_cmdline_args);
- ObjectTypeDB::bind_method(_MD("get_main_loop"),&_OS::get_main_loop);
-
- ObjectTypeDB::bind_method(_MD("get_datetime","utc"),&_OS::get_datetime,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("get_date","utc"),&_OS::get_date,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("get_time","utc"),&_OS::get_time,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("get_time_zone_info"),&_OS::get_time_zone_info);
- ObjectTypeDB::bind_method(_MD("get_unix_time"),&_OS::get_unix_time);
- ObjectTypeDB::bind_method(_MD("get_datetime_from_unix_time", "unix_time_val"),
+ //ClassDB::bind_method(_MD("get_mouse_pos"),&_OS::get_mouse_pos);
+ //ClassDB::bind_method(_MD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled);
+
+ ClassDB::bind_method(_MD("set_clipboard","clipboard"),&_OS::set_clipboard);
+ ClassDB::bind_method(_MD("get_clipboard"),&_OS::get_clipboard);
+
+ //will not delete for now, just unexpose
+ //ClassDB::bind_method(_MD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0));
+ //ClassDB::bind_method(_MD("get_video_mode_size","screen"),&_OS::get_video_mode,DEFVAL(0));
+ //ClassDB::bind_method(_MD("is_video_mode_fullscreen","screen"),&_OS::is_video_mode_fullscreen,DEFVAL(0));
+ //ClassDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0));
+ //ClassDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
+
+
+ ClassDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count);
+ ClassDB::bind_method(_MD("get_current_screen"),&_OS::get_current_screen);
+ ClassDB::bind_method(_MD("set_current_screen","screen"),&_OS::set_current_screen);
+ ClassDB::bind_method(_MD("get_screen_position","screen"),&_OS::get_screen_position,DEFVAL(0));
+ ClassDB::bind_method(_MD("get_screen_size","screen"),&_OS::get_screen_size,DEFVAL(0));
+ ClassDB::bind_method(_MD("get_screen_dpi","screen"),&_OS::get_screen_dpi,DEFVAL(0));
+ ClassDB::bind_method(_MD("get_window_position"),&_OS::get_window_position);
+ ClassDB::bind_method(_MD("set_window_position","position"),&_OS::set_window_position);
+ ClassDB::bind_method(_MD("get_window_size"),&_OS::get_window_size);
+ ClassDB::bind_method(_MD("set_window_size","size"),&_OS::set_window_size);
+ ClassDB::bind_method(_MD("set_window_fullscreen","enabled"),&_OS::set_window_fullscreen);
+ ClassDB::bind_method(_MD("is_window_fullscreen"),&_OS::is_window_fullscreen);
+ ClassDB::bind_method(_MD("set_window_resizable","enabled"),&_OS::set_window_resizable);
+ ClassDB::bind_method(_MD("is_window_resizable"),&_OS::is_window_resizable);
+ ClassDB::bind_method(_MD("set_window_minimized", "enabled"),&_OS::set_window_minimized);
+ ClassDB::bind_method(_MD("is_window_minimized"),&_OS::is_window_minimized);
+ ClassDB::bind_method(_MD("set_window_maximized", "enabled"),&_OS::set_window_maximized);
+ ClassDB::bind_method(_MD("is_window_maximized"),&_OS::is_window_maximized);
+ ClassDB::bind_method(_MD("request_attention"), &_OS::request_attention);
+
+ ClassDB::bind_method(_MD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
+ ClassDB::bind_method(_MD("get_borderless_window"), &_OS::get_borderless_window);
+
+ ClassDB::bind_method(_MD("set_screen_orientation","orientation"),&_OS::set_screen_orientation);
+ ClassDB::bind_method(_MD("get_screen_orientation"),&_OS::get_screen_orientation);
+
+ ClassDB::bind_method(_MD("set_keep_screen_on","enabled"),&_OS::set_keep_screen_on);
+ ClassDB::bind_method(_MD("is_keep_screen_on"),&_OS::is_keep_screen_on);
+
+
+ ClassDB::bind_method(_MD("has_touchscreen_ui_hint"),&_OS::has_touchscreen_ui_hint);
+
+ ClassDB::bind_method(_MD("set_window_title","title"),&_OS::set_window_title);
+
+ ClassDB::bind_method(_MD("set_low_processor_usage_mode","enable"),&_OS::set_low_processor_usage_mode);
+ ClassDB::bind_method(_MD("is_in_low_processor_usage_mode"),&_OS::is_in_low_processor_usage_mode);
+
+ ClassDB::bind_method(_MD("get_processor_count"),&_OS::get_processor_count);
+
+ ClassDB::bind_method(_MD("get_executable_path"),&_OS::get_executable_path);
+ ClassDB::bind_method(_MD("execute","path","arguments","blocking","output"),&_OS::execute,DEFVAL(Array()));
+ ClassDB::bind_method(_MD("kill","pid"),&_OS::kill);
+ ClassDB::bind_method(_MD("shell_open","uri"),&_OS::shell_open);
+ ClassDB::bind_method(_MD("get_process_ID"),&_OS::get_process_ID);
+
+ ClassDB::bind_method(_MD("get_environment","environment"),&_OS::get_environment);
+ ClassDB::bind_method(_MD("has_environment","environment"),&_OS::has_environment);
+
+ ClassDB::bind_method(_MD("get_name"),&_OS::get_name);
+ ClassDB::bind_method(_MD("get_cmdline_args"),&_OS::get_cmdline_args);
+
+ ClassDB::bind_method(_MD("get_datetime","utc"),&_OS::get_datetime,DEFVAL(false));
+ ClassDB::bind_method(_MD("get_date","utc"),&_OS::get_date,DEFVAL(false));
+ ClassDB::bind_method(_MD("get_time","utc"),&_OS::get_time,DEFVAL(false));
+ ClassDB::bind_method(_MD("get_time_zone_info"),&_OS::get_time_zone_info);
+ ClassDB::bind_method(_MD("get_unix_time"),&_OS::get_unix_time);
+ ClassDB::bind_method(_MD("get_datetime_from_unix_time", "unix_time_val"),
&_OS::get_datetime_from_unix_time);
- ObjectTypeDB::bind_method(_MD("get_unix_time_from_datetime", "datetime"),
+ ClassDB::bind_method(_MD("get_unix_time_from_datetime", "datetime"),
&_OS::get_unix_time_from_datetime);
- ObjectTypeDB::bind_method(_MD("get_system_time_secs"), &_OS::get_system_time_secs);
+ ClassDB::bind_method(_MD("get_system_time_secs"), &_OS::get_system_time_secs);
- ObjectTypeDB::bind_method(_MD("set_icon","icon"),&_OS::set_icon);
+ ClassDB::bind_method(_MD("set_icon","icon"),&_OS::set_icon);
- ObjectTypeDB::bind_method(_MD("delay_usec","usec"),&_OS::delay_usec);
- ObjectTypeDB::bind_method(_MD("delay_msec","msec"),&_OS::delay_msec);
- ObjectTypeDB::bind_method(_MD("get_ticks_msec"),&_OS::get_ticks_msec);
- ObjectTypeDB::bind_method(_MD("get_splash_tick_msec"),&_OS::get_splash_tick_msec);
- ObjectTypeDB::bind_method(_MD("get_locale"),&_OS::get_locale);
- ObjectTypeDB::bind_method(_MD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant);
- ObjectTypeDB::bind_method(_MD("get_model_name"),&_OS::get_model_name);
+ ClassDB::bind_method(_MD("get_exit_code"),&_OS::get_exit_code);
+ ClassDB::bind_method(_MD("set_exit_code","code"),&_OS::set_exit_code);
- ObjectTypeDB::bind_method(_MD("get_custom_level"),&_OS::get_custom_level);
+ ClassDB::bind_method(_MD("delay_usec","usec"),&_OS::delay_usec);
+ ClassDB::bind_method(_MD("delay_msec","msec"),&_OS::delay_msec);
+ ClassDB::bind_method(_MD("get_ticks_msec"),&_OS::get_ticks_msec);
+ ClassDB::bind_method(_MD("get_splash_tick_msec"),&_OS::get_splash_tick_msec);
+ ClassDB::bind_method(_MD("get_locale"),&_OS::get_locale);
+ ClassDB::bind_method(_MD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant);
+ ClassDB::bind_method(_MD("get_model_name"),&_OS::get_model_name);
- ObjectTypeDB::bind_method(_MD("can_draw"),&_OS::can_draw);
- ObjectTypeDB::bind_method(_MD("get_frames_drawn"),&_OS::get_frames_drawn);
- ObjectTypeDB::bind_method(_MD("is_stdout_verbose"),&_OS::is_stdout_verbose);
- ObjectTypeDB::bind_method(_MD("can_use_threads"),&_OS::can_use_threads);
+ ClassDB::bind_method(_MD("can_draw"),&_OS::can_draw);
+ ClassDB::bind_method(_MD("is_stdout_verbose"),&_OS::is_stdout_verbose);
- ObjectTypeDB::bind_method(_MD("is_debug_build"),&_OS::is_debug_build);
+ ClassDB::bind_method(_MD("can_use_threads"),&_OS::can_use_threads);
- //ObjectTypeDB::bind_method(_MD("get_mouse_button_state"),&_OS::get_mouse_button_state);
+ ClassDB::bind_method(_MD("is_debug_build"),&_OS::is_debug_build);
- ObjectTypeDB::bind_method(_MD("dump_memory_to_file","file"),&_OS::dump_memory_to_file);
- ObjectTypeDB::bind_method(_MD("dump_resources_to_file","file"),&_OS::dump_resources_to_file);
- ObjectTypeDB::bind_method(_MD("has_virtual_keyboard"),&_OS::has_virtual_keyboard);
- ObjectTypeDB::bind_method(_MD("show_virtual_keyboard", "existing_text"),&_OS::show_virtual_keyboard,DEFVAL(""));
- ObjectTypeDB::bind_method(_MD("hide_virtual_keyboard"),&_OS::hide_virtual_keyboard);
- ObjectTypeDB::bind_method(_MD("print_resources_in_use","short"),&_OS::print_resources_in_use,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("print_all_resources","tofile"),&_OS::print_all_resources,DEFVAL(""));
+ //ClassDB::bind_method(_MD("get_mouse_button_state"),&_OS::get_mouse_button_state);
- ObjectTypeDB::bind_method(_MD("get_static_memory_usage"),&_OS::get_static_memory_usage);
- ObjectTypeDB::bind_method(_MD("get_static_memory_peak_usage"),&_OS::get_static_memory_peak_usage);
- ObjectTypeDB::bind_method(_MD("get_dynamic_memory_usage"),&_OS::get_dynamic_memory_usage);
+ ClassDB::bind_method(_MD("dump_memory_to_file","file"),&_OS::dump_memory_to_file);
+ ClassDB::bind_method(_MD("dump_resources_to_file","file"),&_OS::dump_resources_to_file);
+ ClassDB::bind_method(_MD("has_virtual_keyboard"),&_OS::has_virtual_keyboard);
+ ClassDB::bind_method(_MD("show_virtual_keyboard", "existing_text"),&_OS::show_virtual_keyboard,DEFVAL(""));
+ ClassDB::bind_method(_MD("hide_virtual_keyboard"),&_OS::hide_virtual_keyboard);
+ ClassDB::bind_method(_MD("print_resources_in_use","short"),&_OS::print_resources_in_use,DEFVAL(false));
+ ClassDB::bind_method(_MD("print_all_resources","tofile"),&_OS::print_all_resources,DEFVAL(""));
- ObjectTypeDB::bind_method(_MD("get_data_dir"),&_OS::get_data_dir);
- ObjectTypeDB::bind_method(_MD("get_system_dir","dir"),&_OS::get_system_dir);
- ObjectTypeDB::bind_method(_MD("get_unique_ID"),&_OS::get_unique_ID);
+ ClassDB::bind_method(_MD("get_static_memory_usage"),&_OS::get_static_memory_usage);
+ ClassDB::bind_method(_MD("get_static_memory_peak_usage"),&_OS::get_static_memory_peak_usage);
+ ClassDB::bind_method(_MD("get_dynamic_memory_usage"),&_OS::get_dynamic_memory_usage);
- ObjectTypeDB::bind_method(_MD("is_ok_left_and_cancel_right"),&_OS::is_ok_left_and_cancel_right);
+ ClassDB::bind_method(_MD("get_data_dir"),&_OS::get_data_dir);
+ ClassDB::bind_method(_MD("get_system_dir","dir"),&_OS::get_system_dir);
+ ClassDB::bind_method(_MD("get_unique_ID"),&_OS::get_unique_ID);
- ObjectTypeDB::bind_method(_MD("get_frames_per_second"),&_OS::get_frames_per_second);
+ ClassDB::bind_method(_MD("is_ok_left_and_cancel_right"),&_OS::is_ok_left_and_cancel_right);
- ObjectTypeDB::bind_method(_MD("print_all_textures_by_size"),&_OS::print_all_textures_by_size);
- ObjectTypeDB::bind_method(_MD("print_resources_by_type","types"),&_OS::print_resources_by_type);
- ObjectTypeDB::bind_method(_MD("native_video_play","path","volume","audio_track","subtitle_track"),&_OS::native_video_play);
- ObjectTypeDB::bind_method(_MD("native_video_is_playing"),&_OS::native_video_is_playing);
- ObjectTypeDB::bind_method(_MD("native_video_stop"),&_OS::native_video_stop);
- ObjectTypeDB::bind_method(_MD("native_video_pause"),&_OS::native_video_pause);
- ObjectTypeDB::bind_method(_MD("native_video_unpause"),&_OS::native_video_unpause);
+ ClassDB::bind_method(_MD("print_all_textures_by_size"),&_OS::print_all_textures_by_size);
+ ClassDB::bind_method(_MD("print_resources_by_type","types"),&_OS::print_resources_by_type);
- ObjectTypeDB::bind_method(_MD("get_scancode_string","code"),&_OS::get_scancode_string);
- ObjectTypeDB::bind_method(_MD("is_scancode_unicode","code"),&_OS::is_scancode_unicode);
- ObjectTypeDB::bind_method(_MD("find_scancode_from_string","string"),&_OS::find_scancode_from_string);
+ ClassDB::bind_method(_MD("native_video_play","path","volume","audio_track","subtitle_track"),&_OS::native_video_play);
+ ClassDB::bind_method(_MD("native_video_is_playing"),&_OS::native_video_is_playing);
+ ClassDB::bind_method(_MD("native_video_stop"),&_OS::native_video_stop);
+ ClassDB::bind_method(_MD("native_video_pause"),&_OS::native_video_pause);
+ ClassDB::bind_method(_MD("native_video_unpause"),&_OS::native_video_unpause);
- ObjectTypeDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap);
+ ClassDB::bind_method(_MD("get_scancode_string","code"),&_OS::get_scancode_string);
+ ClassDB::bind_method(_MD("is_scancode_unicode","code"),&_OS::is_scancode_unicode);
+ ClassDB::bind_method(_MD("find_scancode_from_string","string"),&_OS::find_scancode_from_string);
- ObjectTypeDB::bind_method(_MD("alert","text","title"),&_OS::alert,DEFVAL("Alert!"));
+ ClassDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap);
- ObjectTypeDB::bind_method(_MD("set_thread_name","name"),&_OS::set_thread_name);
+ ClassDB::bind_method(_MD("alert","text","title"),&_OS::alert,DEFVAL("Alert!"));
- ObjectTypeDB::bind_method(_MD("set_use_vsync","enable"),&_OS::set_use_vsync);
- ObjectTypeDB::bind_method(_MD("is_vsnc_enabled"),&_OS::is_vsnc_enabled);
+ ClassDB::bind_method(_MD("set_thread_name","name"),&_OS::set_thread_name);
- ObjectTypeDB::bind_method(_MD("get_engine_version"),&_OS::get_engine_version);
+ ClassDB::bind_method(_MD("set_use_vsync","enable"),&_OS::set_use_vsync);
+ ClassDB::bind_method(_MD("is_vsync_enabled"),&_OS::is_vsync_enabled);
BIND_CONSTANT( DAY_SUNDAY );
BIND_CONSTANT( DAY_MONDAY );
@@ -1232,16 +1186,16 @@ _Geometry *_Geometry::get_singleton() {
return singleton;
}
-DVector<Plane> _Geometry::build_box_planes(const Vector3& p_extents) {
+PoolVector<Plane> _Geometry::build_box_planes(const Vector3& p_extents) {
return Geometry::build_box_planes(p_extents);
}
-DVector<Plane> _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
+PoolVector<Plane> _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
return Geometry::build_cylinder_planes(p_radius,p_height,p_sides,p_axis);
}
-DVector<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(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
return Geometry::build_capsule_planes(p_radius,p_height,p_sides,p_lats,p_axis);
}
@@ -1262,22 +1216,22 @@ Variant _Geometry::segment_intersects_segment_2d(const Vector2& p_from_a,const V
};
};
-DVector<Vector2> _Geometry::get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2) {
+PoolVector<Vector2> _Geometry::get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2) {
Vector2 r1, r2;
Geometry::get_closest_points_between_segments(p1,q1,p2,q2,r1,r2);
- DVector<Vector2> r;
+ PoolVector<Vector2> r;
r.resize(2);
r.set(0,r1);
r.set(1,r2);
return r;
}
-DVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2) {
+PoolVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2) {
Vector3 r1, r2;
Geometry::get_closest_points_between_segments(p1,p2,q1,q2,r1,r2);
- DVector<Vector3> r;
+ PoolVector<Vector3> r;
r.resize(2);
r.set(0,r1);
r.set(1,r2);
@@ -1314,9 +1268,9 @@ bool _Geometry::point_is_inside_triangle(const Vector2& s, const Vector2& a, con
return Geometry::is_point_in_triangle(s,a,b,c);
}
-DVector<Vector3> _Geometry::segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius) {
+PoolVector<Vector3> _Geometry::segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius) {
- DVector<Vector3> r;
+ PoolVector<Vector3> r;
Vector3 res,norm;
if (!Geometry::segment_intersects_sphere(p_from,p_to,p_sphere_pos,p_sphere_radius,&res,&norm))
return r;
@@ -1326,9 +1280,9 @@ DVector<Vector3> _Geometry::segment_intersects_sphere( const Vector3& p_from, co
r.set(1,norm);
return r;
}
-DVector<Vector3> _Geometry::segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius) {
+PoolVector<Vector3> _Geometry::segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius) {
- DVector<Vector3> r;
+ PoolVector<Vector3> r;
Vector3 res,norm;
if (!Geometry::segment_intersects_cylinder(p_from,p_to,p_height,p_radius,&res,&norm))
return r;
@@ -1339,9 +1293,9 @@ DVector<Vector3> _Geometry::segment_intersects_cylinder( const Vector3& p_from,
return r;
}
-DVector<Vector3> _Geometry::segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes) {
+PoolVector<Vector3> _Geometry::segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes) {
- DVector<Vector3> r;
+ PoolVector<Vector3> r;
Vector3 res,norm;
if (!Geometry::segment_intersects_convex(p_from,p_to,p_planes.ptr(),p_planes.size(),&res,&norm))
return r;
@@ -1396,29 +1350,29 @@ int _Geometry::get_uv84_normal_bit(const Vector3& p_vector) {
void _Geometry::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("build_box_planes","extents"),&_Geometry::build_box_planes);
- ObjectTypeDB::bind_method(_MD("build_cylinder_planes","radius","height","sides","axis"),&_Geometry::build_cylinder_planes,DEFVAL(Vector3::AXIS_Z));
- ObjectTypeDB::bind_method(_MD("build_capsule_planes","radius","height","sides","lats","axis"),&_Geometry::build_capsule_planes,DEFVAL(Vector3::AXIS_Z));
- ObjectTypeDB::bind_method(_MD("segment_intersects_circle","segment_from","segment_to","circle_pos","circle_radius"),&_Geometry::segment_intersects_circle);
- ObjectTypeDB::bind_method(_MD("segment_intersects_segment_2d","from_a","to_a","from_b","to_b"),&_Geometry::segment_intersects_segment_2d);
+ ClassDB::bind_method(_MD("build_box_planes","extents"),&_Geometry::build_box_planes);
+ ClassDB::bind_method(_MD("build_cylinder_planes","radius","height","sides","axis"),&_Geometry::build_cylinder_planes,DEFVAL(Vector3::AXIS_Z));
+ ClassDB::bind_method(_MD("build_capsule_planes","radius","height","sides","lats","axis"),&_Geometry::build_capsule_planes,DEFVAL(Vector3::AXIS_Z));
+ ClassDB::bind_method(_MD("segment_intersects_circle","segment_from","segment_to","circle_pos","circle_radius"),&_Geometry::segment_intersects_circle);
+ ClassDB::bind_method(_MD("segment_intersects_segment_2d","from_a","to_a","from_b","to_b"),&_Geometry::segment_intersects_segment_2d);
- ObjectTypeDB::bind_method(_MD("get_closest_points_between_segments_2d","p1","q1","p2","q2"),&_Geometry::get_closest_points_between_segments_2d);
- ObjectTypeDB::bind_method(_MD("get_closest_points_between_segments","p1","p2","q1","q2"),&_Geometry::get_closest_points_between_segments);
+ ClassDB::bind_method(_MD("get_closest_points_between_segments_2d","p1","q1","p2","q2"),&_Geometry::get_closest_points_between_segments_2d);
+ ClassDB::bind_method(_MD("get_closest_points_between_segments","p1","p2","q1","q2"),&_Geometry::get_closest_points_between_segments);
- ObjectTypeDB::bind_method(_MD("get_closest_point_to_segment","point","s1","s2"),&_Geometry::get_closest_point_to_segment);
+ ClassDB::bind_method(_MD("get_closest_point_to_segment","point","s1","s2"),&_Geometry::get_closest_point_to_segment);
- ObjectTypeDB::bind_method(_MD("get_uv84_normal_bit","normal"),&_Geometry::get_uv84_normal_bit);
+ ClassDB::bind_method(_MD("get_uv84_normal_bit","normal"),&_Geometry::get_uv84_normal_bit);
- ObjectTypeDB::bind_method(_MD("ray_intersects_triangle","from","dir","a","b","c"),&_Geometry::ray_intersects_triangle);
- ObjectTypeDB::bind_method(_MD("segment_intersects_triangle","from","to","a","b","c"),&_Geometry::segment_intersects_triangle);
- ObjectTypeDB::bind_method(_MD("segment_intersects_sphere","from","to","spos","sradius"),&_Geometry::segment_intersects_sphere);
- ObjectTypeDB::bind_method(_MD("segment_intersects_cylinder","from","to","height","radius"),&_Geometry::segment_intersects_cylinder);
- ObjectTypeDB::bind_method(_MD("segment_intersects_convex","from","to","planes"),&_Geometry::segment_intersects_convex);
- ObjectTypeDB::bind_method(_MD("point_is_inside_triangle","point","a","b","c"),&_Geometry::point_is_inside_triangle);
+ ClassDB::bind_method(_MD("ray_intersects_triangle","from","dir","a","b","c"),&_Geometry::ray_intersects_triangle);
+ ClassDB::bind_method(_MD("segment_intersects_triangle","from","to","a","b","c"),&_Geometry::segment_intersects_triangle);
+ ClassDB::bind_method(_MD("segment_intersects_sphere","from","to","spos","sradius"),&_Geometry::segment_intersects_sphere);
+ ClassDB::bind_method(_MD("segment_intersects_cylinder","from","to","height","radius"),&_Geometry::segment_intersects_cylinder);
+ ClassDB::bind_method(_MD("segment_intersects_convex","from","to","planes"),&_Geometry::segment_intersects_convex);
+ ClassDB::bind_method(_MD("point_is_inside_triangle","point","a","b","c"),&_Geometry::point_is_inside_triangle);
- ObjectTypeDB::bind_method(_MD("triangulate_polygon","polygon"),&_Geometry::triangulate_polygon);
+ ClassDB::bind_method(_MD("triangulate_polygon","polygon"),&_Geometry::triangulate_polygon);
- ObjectTypeDB::bind_method(_MD("make_atlas","sizes"),&_Geometry::make_atlas);
+ ClassDB::bind_method(_MD("make_atlas","sizes"),&_Geometry::make_atlas);
}
@@ -1566,9 +1520,9 @@ real_t _File::get_real() const{
return f->get_real();
}
-DVector<uint8_t> _File::get_buffer(int p_length) const{
+PoolVector<uint8_t> _File::get_buffer(int p_length) const{
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
ERR_FAIL_COND_V(!f,data);
ERR_FAIL_COND_V(p_length<0,data);
@@ -1576,11 +1530,11 @@ DVector<uint8_t> _File::get_buffer(int p_length) const{
return data;
Error err = data.resize(p_length);
ERR_FAIL_COND_V(err!=OK,data);
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
int len = f->get_buffer(&w[0],p_length);
- ERR_FAIL_COND_V( len < 0 , DVector<uint8_t>());
+ ERR_FAIL_COND_V( len < 0 , PoolVector<uint8_t>());
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
if (len < p_length)
data.resize(p_length);
@@ -1735,7 +1689,7 @@ void _File::store_line(const String& p_string){
f->store_line(p_string);
}
-void _File::store_buffer(const DVector<uint8_t>& p_buffer){
+void _File::store_buffer(const PoolVector<uint8_t>& p_buffer){
ERR_FAIL_COND(!f);
@@ -1743,7 +1697,7 @@ void _File::store_buffer(const DVector<uint8_t>& p_buffer){
if (len==0)
return;
- DVector<uint8_t>::Read r = p_buffer.read();
+ PoolVector<uint8_t>::Read r = p_buffer.read();
f->store_buffer(&r[0],len);
}
@@ -1762,13 +1716,13 @@ void _File::store_var(const Variant& p_var) {
Error err = encode_variant(p_var,NULL,len);
ERR_FAIL_COND( err != OK );
- DVector<uint8_t> buff;
+ PoolVector<uint8_t> buff;
buff.resize(len);
- DVector<uint8_t>::Write w = buff.write();
+ PoolVector<uint8_t>::Write w = buff.write();
err = encode_variant(p_var,&w[0],len);
ERR_FAIL_COND( err != OK );
- w=DVector<uint8_t>::Write();
+ w=PoolVector<uint8_t>::Write();
store_32(len);
store_buffer(buff);
@@ -1778,10 +1732,10 @@ Variant _File::get_var() const {
ERR_FAIL_COND_V(!f,Variant());
uint32_t len = get_32();
- DVector<uint8_t> buff = get_buffer(len);
+ PoolVector<uint8_t> buff = get_buffer(len);
ERR_FAIL_COND_V(buff.size() != len, Variant());
- DVector<uint8_t>::Read r = buff.read();
+ PoolVector<uint8_t>::Read r = buff.read();
Variant v;
Error err = decode_variant(v,&r[0],len);
@@ -1793,51 +1747,51 @@ Variant _File::get_var() const {
void _File::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("open_encrypted","path","mode_flags","key"),&_File::open_encrypted);
- ObjectTypeDB::bind_method(_MD("open_encrypted_with_pass","path","mode_flags","pass"),&_File::open_encrypted_pass);
-
- ObjectTypeDB::bind_method(_MD("open","path","flags"),&_File::open);
- ObjectTypeDB::bind_method(_MD("close"),&_File::close);
- ObjectTypeDB::bind_method(_MD("is_open"),&_File::is_open);
- ObjectTypeDB::bind_method(_MD("seek","pos"),&_File::seek);
- ObjectTypeDB::bind_method(_MD("seek_end","pos"),&_File::seek_end,DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("get_pos"),&_File::get_pos);
- ObjectTypeDB::bind_method(_MD("get_len"),&_File::get_len);
- ObjectTypeDB::bind_method(_MD("eof_reached"),&_File::eof_reached);
- ObjectTypeDB::bind_method(_MD("get_8"),&_File::get_8);
- ObjectTypeDB::bind_method(_MD("get_16"),&_File::get_16);
- ObjectTypeDB::bind_method(_MD("get_32"),&_File::get_32);
- ObjectTypeDB::bind_method(_MD("get_64"),&_File::get_64);
- ObjectTypeDB::bind_method(_MD("get_float"),&_File::get_float);
- ObjectTypeDB::bind_method(_MD("get_double"),&_File::get_double);
- ObjectTypeDB::bind_method(_MD("get_real"),&_File::get_real);
- ObjectTypeDB::bind_method(_MD("get_buffer","len"),&_File::get_buffer);
- ObjectTypeDB::bind_method(_MD("get_line"),&_File::get_line);
- ObjectTypeDB::bind_method(_MD("get_as_text"),&_File::get_as_text);
- ObjectTypeDB::bind_method(_MD("get_md5","path"),&_File::get_md5);
- ObjectTypeDB::bind_method(_MD("get_sha256","path"),&_File::get_sha256);
- ObjectTypeDB::bind_method(_MD("get_endian_swap"),&_File::get_endian_swap);
- ObjectTypeDB::bind_method(_MD("set_endian_swap","enable"),&_File::set_endian_swap);
- ObjectTypeDB::bind_method(_MD("get_error:Error"),&_File::get_error);
- ObjectTypeDB::bind_method(_MD("get_var"),&_File::get_var);
- ObjectTypeDB::bind_method(_MD("get_csv_line","delim"),&_File::get_csv_line,DEFVAL(","));
-
- ObjectTypeDB::bind_method(_MD("store_8","value"),&_File::store_8);
- ObjectTypeDB::bind_method(_MD("store_16","value"),&_File::store_16);
- ObjectTypeDB::bind_method(_MD("store_32","value"),&_File::store_32);
- ObjectTypeDB::bind_method(_MD("store_64","value"),&_File::store_64);
- ObjectTypeDB::bind_method(_MD("store_float","value"),&_File::store_float);
- ObjectTypeDB::bind_method(_MD("store_double","value"),&_File::store_double);
- ObjectTypeDB::bind_method(_MD("store_real","value"),&_File::store_real);
- ObjectTypeDB::bind_method(_MD("store_buffer","buffer"),&_File::store_buffer);
- ObjectTypeDB::bind_method(_MD("store_line","line"),&_File::store_line);
- ObjectTypeDB::bind_method(_MD("store_string","string"),&_File::store_string);
- ObjectTypeDB::bind_method(_MD("store_var","value"),&_File::store_var);
-
- ObjectTypeDB::bind_method(_MD("store_pascal_string","string"),&_File::store_pascal_string);
- ObjectTypeDB::bind_method(_MD("get_pascal_string"),&_File::get_pascal_string);
-
- ObjectTypeDB::bind_method(_MD("file_exists","path"),&_File::file_exists);
+ ClassDB::bind_method(_MD("open_encrypted","path","mode_flags","key"),&_File::open_encrypted);
+ ClassDB::bind_method(_MD("open_encrypted_with_pass","path","mode_flags","pass"),&_File::open_encrypted_pass);
+
+ ClassDB::bind_method(_MD("open","path","flags"),&_File::open);
+ ClassDB::bind_method(_MD("close"),&_File::close);
+ ClassDB::bind_method(_MD("is_open"),&_File::is_open);
+ ClassDB::bind_method(_MD("seek","pos"),&_File::seek);
+ ClassDB::bind_method(_MD("seek_end","pos"),&_File::seek_end,DEFVAL(0));
+ ClassDB::bind_method(_MD("get_pos"),&_File::get_pos);
+ ClassDB::bind_method(_MD("get_len"),&_File::get_len);
+ ClassDB::bind_method(_MD("eof_reached"),&_File::eof_reached);
+ ClassDB::bind_method(_MD("get_8"),&_File::get_8);
+ ClassDB::bind_method(_MD("get_16"),&_File::get_16);
+ ClassDB::bind_method(_MD("get_32"),&_File::get_32);
+ ClassDB::bind_method(_MD("get_64"),&_File::get_64);
+ ClassDB::bind_method(_MD("get_float"),&_File::get_float);
+ ClassDB::bind_method(_MD("get_double"),&_File::get_double);
+ ClassDB::bind_method(_MD("get_real"),&_File::get_real);
+ ClassDB::bind_method(_MD("get_buffer","len"),&_File::get_buffer);
+ ClassDB::bind_method(_MD("get_line"),&_File::get_line);
+ ClassDB::bind_method(_MD("get_as_text"),&_File::get_as_text);
+ ClassDB::bind_method(_MD("get_md5","path"),&_File::get_md5);
+ ClassDB::bind_method(_MD("get_sha256","path"),&_File::get_sha256);
+ ClassDB::bind_method(_MD("get_endian_swap"),&_File::get_endian_swap);
+ ClassDB::bind_method(_MD("set_endian_swap","enable"),&_File::set_endian_swap);
+ ClassDB::bind_method(_MD("get_error:Error"),&_File::get_error);
+ ClassDB::bind_method(_MD("get_var"),&_File::get_var);
+ ClassDB::bind_method(_MD("get_csv_line","delim"),&_File::get_csv_line,DEFVAL(","));
+
+ ClassDB::bind_method(_MD("store_8","value"),&_File::store_8);
+ ClassDB::bind_method(_MD("store_16","value"),&_File::store_16);
+ ClassDB::bind_method(_MD("store_32","value"),&_File::store_32);
+ ClassDB::bind_method(_MD("store_64","value"),&_File::store_64);
+ ClassDB::bind_method(_MD("store_float","value"),&_File::store_float);
+ ClassDB::bind_method(_MD("store_double","value"),&_File::store_double);
+ ClassDB::bind_method(_MD("store_real","value"),&_File::store_real);
+ ClassDB::bind_method(_MD("store_buffer","buffer"),&_File::store_buffer);
+ ClassDB::bind_method(_MD("store_line","line"),&_File::store_line);
+ ClassDB::bind_method(_MD("store_string","string"),&_File::store_string);
+ ClassDB::bind_method(_MD("store_var","value"),&_File::store_var);
+
+ ClassDB::bind_method(_MD("store_pascal_string","string"),&_File::store_pascal_string);
+ ClassDB::bind_method(_MD("get_pascal_string"),&_File::get_pascal_string);
+
+ ClassDB::bind_method(_MD("file_exists","path"),&_File::file_exists);
BIND_CONSTANT( READ );
BIND_CONSTANT( WRITE );
@@ -1877,9 +1831,9 @@ Error _Directory::open(const String& p_path) {
return OK;
}
-bool _Directory::list_dir_begin() {
+Error _Directory::list_dir_begin() {
- ERR_FAIL_COND_V(!d,false);
+ ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
return d->list_dir_begin();
}
@@ -1910,6 +1864,10 @@ String _Directory::get_drive(int p_drive){
ERR_FAIL_COND_V(!d,"");
return d->get_drive(p_drive);
}
+int _Directory::get_current_drive() {
+ ERR_FAIL_COND_V(!d,0);
+ return d->get_current_drive();
+}
Error _Directory::change_dir(String p_dir){
@@ -2011,24 +1969,25 @@ Error _Directory::remove(String p_name){
void _Directory::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("open:Error","path"),&_Directory::open);
- ObjectTypeDB::bind_method(_MD("list_dir_begin"),&_Directory::list_dir_begin);
- ObjectTypeDB::bind_method(_MD("get_next"),&_Directory::get_next);
- ObjectTypeDB::bind_method(_MD("current_is_dir"),&_Directory::current_is_dir);
- ObjectTypeDB::bind_method(_MD("list_dir_end"),&_Directory::list_dir_end);
- ObjectTypeDB::bind_method(_MD("get_drive_count"),&_Directory::get_drive_count);
- ObjectTypeDB::bind_method(_MD("get_drive","idx"),&_Directory::get_drive);
- ObjectTypeDB::bind_method(_MD("change_dir:Error","todir"),&_Directory::change_dir);
- ObjectTypeDB::bind_method(_MD("get_current_dir"),&_Directory::get_current_dir);
- ObjectTypeDB::bind_method(_MD("make_dir:Error","path"),&_Directory::make_dir);
- ObjectTypeDB::bind_method(_MD("make_dir_recursive:Error","path"),&_Directory::make_dir_recursive);
- ObjectTypeDB::bind_method(_MD("file_exists","path"),&_Directory::file_exists);
- ObjectTypeDB::bind_method(_MD("dir_exists","path"),&_Directory::dir_exists);
-// ObjectTypeDB::bind_method(_MD("get_modified_time","file"),&_Directory::get_modified_time);
- ObjectTypeDB::bind_method(_MD("get_space_left"),&_Directory::get_space_left);
- ObjectTypeDB::bind_method(_MD("copy:Error","from","to"),&_Directory::copy);
- ObjectTypeDB::bind_method(_MD("rename:Error","from","to"),&_Directory::rename);
- ObjectTypeDB::bind_method(_MD("remove:Error","path"),&_Directory::remove);
+ ClassDB::bind_method(_MD("open:Error","path"),&_Directory::open);
+ ClassDB::bind_method(_MD("list_dir_begin"),&_Directory::list_dir_begin);
+ 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);
+ ClassDB::bind_method(_MD("get_drive_count"),&_Directory::get_drive_count);
+ ClassDB::bind_method(_MD("get_drive","idx"),&_Directory::get_drive);
+ ClassDB::bind_method(_MD("get_current_drive"),&_Directory::get_current_drive);
+ ClassDB::bind_method(_MD("change_dir:Error","todir"),&_Directory::change_dir);
+ ClassDB::bind_method(_MD("get_current_dir"),&_Directory::get_current_dir);
+ ClassDB::bind_method(_MD("make_dir:Error","path"),&_Directory::make_dir);
+ ClassDB::bind_method(_MD("make_dir_recursive:Error","path"),&_Directory::make_dir_recursive);
+ ClassDB::bind_method(_MD("file_exists","path"),&_Directory::file_exists);
+ ClassDB::bind_method(_MD("dir_exists","path"),&_Directory::dir_exists);
+ //ClassDB::bind_method(_MD("get_modified_time","file"),&_Directory::get_modified_time);
+ ClassDB::bind_method(_MD("get_space_left"),&_Directory::get_space_left);
+ ClassDB::bind_method(_MD("copy:Error","from","to"),&_Directory::copy);
+ ClassDB::bind_method(_MD("rename:Error","from","to"),&_Directory::rename);
+ ClassDB::bind_method(_MD("remove:Error","path"),&_Directory::remove);
}
@@ -2043,23 +2002,30 @@ _Directory::~_Directory() {
memdelete(d);
}
+_Marshalls* _Marshalls::singleton=NULL;
+
+_Marshalls *_Marshalls::get_singleton()
+{
+ return singleton;
+}
+
String _Marshalls::variant_to_base64(const Variant& p_var) {
int len;
Error err = encode_variant(p_var,NULL,len);
ERR_FAIL_COND_V( err != OK, "" );
- DVector<uint8_t> buff;
+ PoolVector<uint8_t> buff;
buff.resize(len);
- DVector<uint8_t>::Write w = buff.write();
+ PoolVector<uint8_t>::Write w = buff.write();
err = encode_variant(p_var,&w[0],len);
ERR_FAIL_COND_V( err != OK, "" );
int b64len = len / 3 * 4 + 4 + 1;
- DVector<uint8_t> b64buff;
+ PoolVector<uint8_t> b64buff;
b64buff.resize(b64len);
- DVector<uint8_t>::Write w64 = b64buff.write();
+ PoolVector<uint8_t>::Write w64 = b64buff.write();
int strlen = base64_encode((char*)(&w64[0]), (char*)(&w[0]), len);
//OS::get_singleton()->print("len is %i, vector size is %i\n", b64len, strlen);
@@ -2074,9 +2040,9 @@ Variant _Marshalls::base64_to_variant(const String& p_str) {
int strlen = p_str.length();
CharString cstr = p_str.ascii();
- DVector<uint8_t> buf;
+ PoolVector<uint8_t> buf;
buf.resize(strlen / 4 * 3 + 1);
- DVector<uint8_t>::Write w = buf.write();
+ PoolVector<uint8_t>::Write w = buf.write();
int len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
@@ -2087,15 +2053,15 @@ Variant _Marshalls::base64_to_variant(const String& p_str) {
return v;
};
-String _Marshalls::raw_to_base64(const DVector<uint8_t> &p_arr) {
+String _Marshalls::raw_to_base64(const PoolVector<uint8_t> &p_arr) {
int len = p_arr.size();
- DVector<uint8_t>::Read r = p_arr.read();
+ PoolVector<uint8_t>::Read r = p_arr.read();
int b64len = len / 3 * 4 + 4 + 1;
- DVector<uint8_t> b64buff;
+ PoolVector<uint8_t> b64buff;
b64buff.resize(b64len);
- DVector<uint8_t>::Write w64 = b64buff.write();
+ PoolVector<uint8_t>::Write w64 = b64buff.write();
int strlen = base64_encode((char*)(&w64[0]), (char*)(&r[0]), len);
w64[strlen] = 0;
@@ -2104,22 +2070,22 @@ String _Marshalls::raw_to_base64(const DVector<uint8_t> &p_arr) {
return ret;
};
-DVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
+PoolVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
int strlen = p_str.length();
CharString cstr = p_str.ascii();
int arr_len;
- DVector<uint8_t> buf;
+ PoolVector<uint8_t> buf;
{
buf.resize(strlen / 4 * 3 + 1);
- DVector<uint8_t>::Write w = buf.write();
+ PoolVector<uint8_t>::Write w = buf.write();
arr_len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
};
buf.resize(arr_len);
- // conversion from DVector<uint8_t> to raw array?
+ // conversion from PoolVector<uint8_t> to raw array?
return buf;
};
@@ -2129,9 +2095,9 @@ String _Marshalls::utf8_to_base64(const String& p_str) {
int len = cstr.length();
int b64len = len / 3 * 4 + 4 + 1;
- DVector<uint8_t> b64buff;
+ PoolVector<uint8_t> b64buff;
b64buff.resize(b64len);
- DVector<uint8_t>::Write w64 = b64buff.write();
+ PoolVector<uint8_t>::Write w64 = b64buff.write();
int strlen = base64_encode((char*)(&w64[0]), (char*)cstr.get_data(), len);
@@ -2146,9 +2112,9 @@ String _Marshalls::base64_to_utf8(const String& p_str) {
int strlen = p_str.length();
CharString cstr = p_str.ascii();
- DVector<uint8_t> buf;
+ PoolVector<uint8_t> buf;
buf.resize(strlen / 4 * 3 + 1 + 1);
- DVector<uint8_t>::Write w = buf.write();
+ PoolVector<uint8_t>::Write w = buf.write();
int len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
@@ -2161,14 +2127,14 @@ String _Marshalls::base64_to_utf8(const String& p_str) {
void _Marshalls::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("variant_to_base64:String","variant"),&_Marshalls::variant_to_base64);
- ObjectTypeDB::bind_method(_MD("base64_to_variant:Variant","base64_str"),&_Marshalls::base64_to_variant);
+ ClassDB::bind_method(_MD("variant_to_base64:String","variant"),&_Marshalls::variant_to_base64);
+ ClassDB::bind_method(_MD("base64_to_variant:Variant","base64_str"),&_Marshalls::base64_to_variant);
- ObjectTypeDB::bind_method(_MD("raw_to_base64:String","array"),&_Marshalls::raw_to_base64);
- ObjectTypeDB::bind_method(_MD("base64_to_raw:RawArray","base64_str"),&_Marshalls::base64_to_raw);
+ ClassDB::bind_method(_MD("raw_to_base64:String","array"),&_Marshalls::raw_to_base64);
+ ClassDB::bind_method(_MD("base64_to_raw:RawArray","base64_str"),&_Marshalls::base64_to_raw);
- ObjectTypeDB::bind_method(_MD("utf8_to_base64:String","utf8_str"),&_Marshalls::utf8_to_base64);
- ObjectTypeDB::bind_method(_MD("base64_to_utf8:String","base64_str"),&_Marshalls::base64_to_utf8);
+ ClassDB::bind_method(_MD("utf8_to_base64:String","utf8_str"),&_Marshalls::utf8_to_base64);
+ ClassDB::bind_method(_MD("base64_to_utf8:String","base64_str"),&_Marshalls::base64_to_utf8);
};
@@ -2192,8 +2158,8 @@ Error _Semaphore::post() {
void _Semaphore::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("wait:Error"),&_Semaphore::wait);
- ObjectTypeDB::bind_method(_MD("post:Error"),&_Semaphore::post);
+ ClassDB::bind_method(_MD("wait:Error"),&_Semaphore::wait);
+ ClassDB::bind_method(_MD("post:Error"),&_Semaphore::post);
}
@@ -2229,9 +2195,9 @@ void _Mutex::unlock(){
void _Mutex::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("lock"),&_Mutex::lock);
- ObjectTypeDB::bind_method(_MD("try_lock:Error"),&_Mutex::try_lock);
- ObjectTypeDB::bind_method(_MD("unlock"),&_Mutex::unlock);
+ ClassDB::bind_method(_MD("lock"),&_Mutex::lock);
+ ClassDB::bind_method(_MD("try_lock:Error"),&_Mutex::try_lock);
+ ClassDB::bind_method(_MD("unlock"),&_Mutex::unlock);
}
@@ -2351,10 +2317,10 @@ Variant _Thread::wait_to_finish() {
void _Thread::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("start:Error","instance","method","userdata","priority"),&_Thread::start,DEFVAL(Variant()),DEFVAL(PRIORITY_NORMAL));
- ObjectTypeDB::bind_method(_MD("get_id"),&_Thread::get_id);
- ObjectTypeDB::bind_method(_MD("is_active"),&_Thread::is_active);
- ObjectTypeDB::bind_method(_MD("wait_to_finish:Variant"),&_Thread::wait_to_finish);
+ ClassDB::bind_method(_MD("start:Error","instance","method","userdata","priority"),&_Thread::start,DEFVAL(Variant()),DEFVAL(PRIORITY_NORMAL));
+ ClassDB::bind_method(_MD("get_id"),&_Thread::get_id);
+ ClassDB::bind_method(_MD("is_active"),&_Thread::is_active);
+ ClassDB::bind_method(_MD("wait_to_finish:Variant"),&_Thread::wait_to_finish);
BIND_CONSTANT( PRIORITY_LOW );
BIND_CONSTANT( PRIORITY_NORMAL );
@@ -2375,3 +2341,289 @@ _Thread::~_Thread() {
}
ERR_FAIL_COND(active==true);
}
+/////////////////////////////////////
+
+
+PoolStringArray _ClassDB::get_class_list() const {
+
+ List<StringName> classes;
+ ClassDB::get_class_list(&classes);
+
+ PoolStringArray ret;
+ ret.resize(classes.size());
+ int idx=0;
+ for (List<StringName>::Element *E=classes.front();E;E=E->next()) {
+ ret.set(idx++,E->get());
+ }
+
+ return ret;
+
+}
+PoolStringArray _ClassDB::get_inheriters_from_class( const StringName& p_class) const {
+
+ List<StringName> classes;
+ ClassDB::get_inheriters_from_class(p_class,&classes);
+
+ PoolStringArray ret;
+ ret.resize(classes.size());
+ int idx=0;
+ for (List<StringName>::Element *E=classes.front();E;E=E->next()) {
+ ret.set(idx++,E->get());
+ }
+
+ return ret;
+}
+StringName _ClassDB::get_parent_class(const StringName& p_class) const {
+
+ return ClassDB::get_parent_class(p_class);
+}
+bool _ClassDB::class_exists(const StringName &p_class) const {
+
+ return ClassDB::class_exists(p_class);
+}
+bool _ClassDB::is_parent_class(const StringName &p_class,const StringName& p_inherits) const {
+
+ return ClassDB::is_parent_class(p_class,p_inherits);
+}
+bool _ClassDB::can_instance(const StringName &p_class) const {
+
+ return ClassDB::can_instance(p_class);
+}
+Variant _ClassDB::instance(const StringName &p_class) const {
+
+ Object *obj = ClassDB::instance(p_class);
+ if (!obj)
+ return Variant();
+
+ Reference *r = obj->cast_to<Reference>();
+ if (r) {
+ return REF(r);
+ } else {
+ return obj;
+ }
+}
+
+bool _ClassDB::has_signal(StringName p_class,StringName p_signal) const {
+
+ return ClassDB::has_signal(p_class,p_signal);
+}
+Dictionary _ClassDB::get_signal(StringName p_class,StringName p_signal) const {
+
+ MethodInfo signal;
+ if (ClassDB::get_signal(p_class,p_signal,&signal)) {
+ return signal.operator Dictionary();
+ } else {
+ return Dictionary();
+ }
+
+}
+Array _ClassDB::get_signal_list(StringName p_class,bool p_no_inheritance) const {
+
+ List<MethodInfo> signals;
+ ClassDB::get_signal_list(p_class,&signals,p_no_inheritance);
+ Array ret;
+
+ for (List<MethodInfo>::Element *E=signals.front();E;E=E->next()) {
+ ret.push_back(E->get().operator Dictionary());
+ }
+
+ return ret;
+}
+
+Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) const {
+
+ List<PropertyInfo> plist;
+ ClassDB::get_property_list(p_class,&plist,p_no_inheritance);
+ Array ret;
+ for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
+ ret.push_back(E->get().operator Dictionary());
+ }
+
+ return ret;
+
+
+}
+
+bool _ClassDB::has_method(StringName p_class,StringName p_method,bool p_no_inheritance) const {
+
+ return ClassDB::has_method(p_class,p_method,p_no_inheritance);
+}
+
+
+Array _ClassDB::get_method_list(StringName p_class,bool p_no_inheritance) const {
+
+ List<MethodInfo> methods;
+ ClassDB::get_method_list(p_class,&methods,p_no_inheritance);
+ Array ret;
+
+ for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
+ ret.push_back(E->get().operator Dictionary());
+ }
+
+ return ret;
+}
+
+PoolStringArray _ClassDB::get_integer_constant_list(const StringName& p_class, bool p_no_inheritance) const {
+
+ List<String> constants;
+ ClassDB::get_integer_constant_list(p_class,&constants,p_no_inheritance);
+
+ PoolStringArray ret;
+ ret.resize(constants.size());
+ int idx=0;
+ for (List<String>::Element *E=constants.front();E;E=E->next()) {
+ ret.set(idx++,E->get());
+ }
+
+ return ret;
+}
+
+bool _ClassDB::has_integer_constant(const StringName& p_class, const StringName &p_name) const {
+
+ bool success;
+ ClassDB::get_integer_constant(p_class,p_name,&success);
+ return success;
+}
+
+int _ClassDB::get_integer_constant(const StringName& p_class, const StringName &p_name) const {
+
+ bool found;
+ int c = ClassDB::get_integer_constant(p_class,p_name,&found);
+ ERR_FAIL_COND_V(!found,0);
+ return c;
+
+}
+StringName _ClassDB::get_category(const StringName& p_node) const {
+
+ return ClassDB::get_category(p_node);
+}
+
+bool _ClassDB::is_class_enabled(StringName p_class) const {
+
+ return ClassDB::is_class_enabled(p_class);
+}
+
+void _ClassDB::_bind_methods() {
+
+ ClassDB::bind_method(_MD("get_class_list"),&_ClassDB::get_class_list);
+ ClassDB::bind_method(_MD("get_inheriters_from_class","class"),&_ClassDB::get_inheriters_from_class);
+ ClassDB::bind_method(_MD("get_parent_class","class"),&_ClassDB::get_parent_class);
+ 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("class_has_signal","class","signal"),&_ClassDB::has_signal);
+ ClassDB::bind_method(_MD("class_get_signal","class","signal"),&_ClassDB::get_signal);
+ ClassDB::bind_method(_MD("class_get_signal_list","class","no_inheritance"),&_ClassDB::get_signal_list,DEFVAL(false));
+
+ ClassDB::bind_method(_MD("class_get_property_list","class","no_inheritance"),&_ClassDB::get_property_list,DEFVAL(false));
+
+ ClassDB::bind_method(_MD("class_has_method","class","method","no_inheritance"),&_ClassDB::has_method,DEFVAL(false));
+
+ ClassDB::bind_method(_MD("class_get_method_list","class","no_inheritance"),&_ClassDB::get_method_list,DEFVAL(false));
+
+ ClassDB::bind_method(_MD("class_get_integer_constant_list","class","no_inheritance"),&_ClassDB::get_integer_constant_list,DEFVAL(false));
+
+ ClassDB::bind_method(_MD("class_has_integer_constant","class","name"),&_ClassDB::has_integer_constant);
+ ClassDB::bind_method(_MD("class_get_integer_constant","class","name"),&_ClassDB::get_integer_constant);
+
+ ClassDB::bind_method(_MD("class_get_category","class"),&_ClassDB::get_category);
+ ClassDB::bind_method(_MD("is_class_enabled","class"),&_ClassDB::is_class_enabled);
+
+
+}
+
+_ClassDB::_ClassDB(){
+
+
+}
+_ClassDB::~_ClassDB(){
+
+
+}
+///////////////////////////////
+
+
+void _Engine::set_iterations_per_second(int p_ips) {
+
+ Engine::get_singleton()->set_iterations_per_second(p_ips);
+}
+int _Engine::get_iterations_per_second() const {
+
+ return Engine::get_singleton()->get_iterations_per_second();
+
+}
+
+void _Engine::set_target_fps(int p_fps) {
+ Engine::get_singleton()->set_target_fps(p_fps);
+}
+
+float _Engine::get_target_fps() const {
+ return Engine::get_singleton()->get_target_fps();
+}
+
+
+
+float _Engine::get_frames_per_second() const {
+
+ return Engine::get_singleton()->get_frames_per_second();
+}
+
+String _Engine::get_custom_level() const {
+
+ return Engine::get_singleton()->get_custom_level();
+}
+
+void _Engine::set_time_scale(float p_scale) {
+ Engine::get_singleton()->set_time_scale(p_scale);
+}
+
+float _Engine::get_time_scale() {
+
+ return Engine::get_singleton()->get_time_scale();
+}
+
+int _Engine::get_frames_drawn() {
+
+ return Engine::get_singleton()->get_frames_drawn();
+}
+
+MainLoop *_Engine::get_main_loop() const {
+
+ //needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
+ return OS::get_singleton()->get_main_loop();
+}
+
+Dictionary _Engine::get_version_info() const {
+
+ return Engine::get_singleton()->get_version_info();
+}
+
+
+void _Engine::_bind_methods() {
+
+ ClassDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_Engine::set_iterations_per_second);
+ ClassDB::bind_method(_MD("get_iterations_per_second"),&_Engine::get_iterations_per_second);
+ ClassDB::bind_method(_MD("set_target_fps","target_fps"),&_Engine::set_target_fps);
+ ClassDB::bind_method(_MD("get_target_fps"),&_Engine::get_target_fps);
+
+ ClassDB::bind_method(_MD("set_time_scale","time_scale"),&_Engine::set_time_scale);
+ ClassDB::bind_method(_MD("get_time_scale"),&_Engine::get_time_scale);
+
+ ClassDB::bind_method(_MD("get_custom_level"),&_Engine::get_custom_level);
+
+ ClassDB::bind_method(_MD("get_frames_drawn"),&_Engine::get_frames_drawn);
+ ClassDB::bind_method(_MD("get_frames_per_second"),&_Engine::get_frames_per_second);
+
+ ClassDB::bind_method(_MD("get_main_loop:MainLoop"),&_Engine::get_main_loop);
+
+ ClassDB::bind_method(_MD("get_version_info"),&_Engine::get_version_info);
+
+}
+
+_Engine *_Engine::singleton = NULL;
+
+_Engine::_Engine() {
+ singleton=this;
+}
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 14203ae863..f10714720f 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -38,7 +38,7 @@
class _ResourceLoader : public Object {
- OBJ_TYPE(_ResourceLoader,Object);
+ GDCLASS(_ResourceLoader,Object);
protected:
@@ -50,9 +50,9 @@ public:
static _ResourceLoader *get_singleton() { return singleton; }
Ref<ResourceInteractiveLoader> load_interactive(const String& p_path,const String& p_type_hint="");
RES load(const String &p_path,const String& p_type_hint="", bool p_no_cache = false);
- DVector<String> get_recognized_extensions_for_type(const String& p_type);
+ PoolVector<String> get_recognized_extensions_for_type(const String& p_type);
void set_abort_on_missing_resources(bool p_abort);
- StringArray get_dependencies(const String& p_path);
+ PoolStringArray get_dependencies(const String& p_path);
bool has(const String& p_path);
Ref<ResourceImportMetadata> load_import_metadata(const String& p_path);
@@ -60,7 +60,7 @@ public:
};
class _ResourceSaver : public Object {
- OBJ_TYPE(_ResourceSaver,Object);
+ GDCLASS(_ResourceSaver,Object);
protected:
@@ -81,7 +81,7 @@ public:
static _ResourceSaver *get_singleton() { return singleton; }
Error save(const String &p_path,const RES& p_resource, uint32_t p_flags);
- DVector<String> get_recognized_extensions(const RES& p_resource);
+ PoolVector<String> get_recognized_extensions(const RES& p_resource);
_ResourceSaver();
@@ -90,7 +90,7 @@ public:
class MainLoop;
class _OS : public Object {
- OBJ_TYPE(_OS,Object);
+ GDCLASS(_OS,Object);
protected:
@@ -169,12 +169,6 @@ public:
void native_video_unpause();
void native_video_stop();
- void set_iterations_per_second(int p_ips);
- int get_iterations_per_second() const;
-
- void set_target_fps(int p_fps);
- float get_target_fps() const;
-
void set_low_processor_usage_mode(bool p_enabled);
bool is_in_low_processor_usage_mode() const;
@@ -196,11 +190,7 @@ public:
String get_latin_keyboard_variant() const;
String get_model_name() const;
- MainLoop *get_main_loop() const;
-
- String get_custom_level() const;
- float get_frames_per_second() const;
void dump_memory_to_file(const String& p_file);
void dump_resources_to_file(const String& p_file);
@@ -246,6 +236,9 @@ public:
void set_use_file_access_save_and_swap(bool p_enable);
void set_icon(const Image& p_icon);
+
+ int get_exit_code() const;
+ void set_exit_code(int p_code);
Dictionary get_date(bool utc) const;
Dictionary get_time(bool utc) const;
Dictionary get_datetime(bool utc) const;
@@ -268,8 +261,6 @@ public:
bool can_draw() const;
- int get_frames_drawn();
-
bool is_stdout_verbose() const;
int get_processor_count() const;
@@ -310,17 +301,13 @@ public:
void set_keep_screen_on(bool p_enabled);
bool is_keep_screen_on() const;
- void set_time_scale(float p_scale);
- float get_time_scale();
bool is_ok_left_and_cancel_right() const;
Error set_thread_name(const String& p_name);
void set_use_vsync(bool p_enable);
- bool is_vsnc_enabled() const;
-
- Dictionary get_engine_version() const;
+ bool is_vsync_enabled() const;
static _OS *get_singleton() { return singleton; }
@@ -333,7 +320,7 @@ VARIANT_ENUM_CAST(_OS::ScreenOrientation);
class _Geometry : public Object {
- OBJ_TYPE(_Geometry, Object);
+ GDCLASS(_Geometry, Object);
static _Geometry *singleton;
protected:
@@ -342,20 +329,20 @@ protected:
public:
static _Geometry *get_singleton();
- DVector<Plane> build_box_planes(const Vector3& p_extents);
- DVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
- DVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
+ PoolVector<Plane> build_box_planes(const Vector3& p_extents);
+ PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
+ PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
Variant segment_intersects_segment_2d(const Vector2& p_from_a,const Vector2& p_to_a,const Vector2& p_from_b,const Vector2& p_to_b);
- DVector<Vector2> get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2);
- DVector<Vector3> get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2);
+ PoolVector<Vector2> get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2);
+ PoolVector<Vector3> get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2);
Vector3 get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b);
Variant ray_intersects_triangle( const Vector3& p_from, const Vector3& p_dir, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
Variant segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
bool point_is_inside_triangle(const Vector2& s, const Vector2& a, const Vector2& b, const Vector2& c) const;
- DVector<Vector3> segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius);
- DVector<Vector3> segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius);
- DVector<Vector3> segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes);
+ PoolVector<Vector3> segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius);
+ PoolVector<Vector3> segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius);
+ PoolVector<Vector3> segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes);
real_t segment_intersects_circle(const Vector2& p_from, const Vector2& p_to, const Vector2& p_circle_pos, real_t p_circle_radius);
int get_uv84_normal_bit(const Vector3& p_vector);
@@ -371,7 +358,7 @@ public:
class _File : public Reference {
- OBJ_TYPE(_File,Reference);
+ GDCLASS(_File,Reference);
FileAccess *f;
bool eswap;
protected:
@@ -413,7 +400,7 @@ public:
Variant get_var() const;
- DVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
+ PoolVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
String get_line() const;
String get_as_text() const;
String get_md5(const String& p_path) const;
@@ -447,7 +434,7 @@ public:
Vector<String> get_csv_line(String delim=",") const;
- void store_buffer(const DVector<uint8_t>& p_buffer); ///< store an array of bytes
+ void store_buffer(const PoolVector<uint8_t>& p_buffer); ///< store an array of bytes
void store_var(const Variant& p_var);
@@ -460,7 +447,7 @@ public:
class _Directory : public Reference {
- OBJ_TYPE(_Directory,Reference);
+ GDCLASS(_Directory,Reference);
DirAccess *d;
protected:
@@ -469,7 +456,7 @@ public:
Error open(const String& p_path);
- bool list_dir_begin(); ///< This starts dir listing
+ Error list_dir_begin(); ///< This starts dir listing
String get_next();
bool current_is_dir() const;
@@ -477,6 +464,7 @@ public:
int get_drive_count();
String get_drive(int p_drive);
+ int get_current_drive();
Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
String get_current_dir(); ///< return current dir location
@@ -501,7 +489,9 @@ public:
class _Marshalls : public Reference {
- OBJ_TYPE(_Marshalls,Reference);
+ GDCLASS(_Marshalls,Reference);
+
+ static _Marshalls* singleton;
protected:
@@ -510,22 +500,25 @@ protected:
public:
+ static _Marshalls* get_singleton();
+
String variant_to_base64(const Variant& p_var);
Variant base64_to_variant(const String& p_str);
- String raw_to_base64(const DVector<uint8_t>& p_arr);
- DVector<uint8_t> base64_to_raw(const String& p_str);
+ String raw_to_base64(const PoolVector<uint8_t>& p_arr);
+ PoolVector<uint8_t> base64_to_raw(const String& p_str);
String utf8_to_base64(const String& p_str);
String base64_to_utf8(const String& p_str);
- _Marshalls() {};
+ _Marshalls() { singleton = this; }
+ ~_Marshalls() { singleton = NULL; }
};
class _Mutex : public Reference {
- OBJ_TYPE(_Mutex,Reference);
+ GDCLASS(_Mutex,Reference);
Mutex *mutex;
static void _bind_methods();
@@ -541,7 +534,7 @@ public:
class _Semaphore : public Reference {
- OBJ_TYPE(_Semaphore,Reference);
+ GDCLASS(_Semaphore,Reference);
Semaphore *semaphore;
static void _bind_methods();
@@ -556,7 +549,7 @@ public:
class _Thread : public Reference {
- OBJ_TYPE(_Thread,Reference);
+ GDCLASS(_Thread,Reference);
protected:
@@ -586,4 +579,77 @@ public:
~_Thread();
};
+class _ClassDB : public Object {
+
+ GDCLASS(_ClassDB,Object)
+
+protected:
+ static void _bind_methods();
+public:
+
+ PoolStringArray get_class_list() const;
+ PoolStringArray get_inheriters_from_class( const StringName& p_class) const;
+ StringName get_parent_class(const StringName& p_class) const;
+ bool class_exists(const StringName &p_class) const;
+ bool is_parent_class(const StringName &p_class,const StringName& p_inherits) const;
+ bool can_instance(const StringName &p_class) const;
+ Variant instance(const StringName &p_class) const;
+
+ bool has_signal(StringName p_class,StringName p_signal) const;
+ Dictionary get_signal(StringName p_class,StringName p_signal) const;
+ Array get_signal_list(StringName p_class,bool p_no_inheritance=false) const;
+
+ Array get_property_list(StringName p_class, bool p_no_inheritance=false) const;
+
+ bool has_method(StringName p_class,StringName p_method,bool p_no_inheritance=false) const;
+
+
+ Array get_method_list(StringName p_class,bool p_no_inheritance=false) const;
+
+ PoolStringArray get_integer_constant_list(const StringName& p_class, bool p_no_inheritance=false) const;
+ bool has_integer_constant(const StringName& p_class, const StringName &p_name) const;
+ int get_integer_constant(const StringName& p_class, const StringName &p_name) const;
+ StringName get_category(const StringName& p_node) const;
+
+ bool is_class_enabled(StringName p_class) const;
+
+ _ClassDB();
+ ~_ClassDB();
+};
+
+
+class _Engine : public Object {
+ GDCLASS(_Engine,Object);
+
+protected:
+
+ static void _bind_methods();
+ static _Engine *singleton;
+
+public:
+
+ static _Engine* get_singleton() { return singleton; }
+ void set_iterations_per_second(int p_ips);
+ int get_iterations_per_second() const;
+
+ void set_target_fps(int p_fps);
+ float get_target_fps() const;
+
+ float get_frames_per_second() const;
+
+ int get_frames_drawn();
+
+ void set_time_scale(float p_scale);
+ float get_time_scale();
+
+ String get_custom_level() const;
+
+ MainLoop *get_main_loop() const;
+
+ Dictionary get_version_info() const;
+
+ _Engine();
+};
+
+
#endif // CORE_BIND_H
diff --git a/core/color.cpp b/core/color.cpp
index bf9c94462f..89accbb6d2 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,6 +29,8 @@
#include "color.h"
#include "math_funcs.h"
#include "print_string.h"
+#include "map.h"
+#include "color_names.inc"
uint32_t Color::to_ARGB32() const {
@@ -327,7 +329,25 @@ bool Color::html_is_valid(const String& p_color) {
}
-
+Color Color::named(const String &p_name) {
+ if (_named_colors.empty()) _populate_named_colors(); // from color_names.inc
+ String name = p_name;
+ // Normalize name
+ name = name.replace(" ", "");
+ name = name.replace("-", "");
+ name = name.replace("_", "");
+ name = name.replace("'", "");
+ name = name.replace(".", "");
+ name = name.to_lower();
+
+ const Map<String, Color>::Element* color = _named_colors.find(name);
+ if(color) {
+ return color->value();
+ } else {
+ ERR_EXPLAIN("Invalid Color Name: "+p_name);
+ ERR_FAIL_V(Color());
+ }
+}
String _to_hex(float p_val) {
diff --git a/core/color.h b/core/color.h
index 5b671d5f62..50a6761340 100644
--- a/core/color.h
+++ b/core/color.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -111,6 +111,7 @@ struct Color {
static Color hex(uint32_t p_hex);
static Color html(const String& p_color);
static bool html_is_valid(const String& p_color);
+ static Color named(const String& p_name);
String to_html(bool p_alpha=true) const;
_FORCE_INLINE_ bool operator<(const Color& p_color) const; //used in set keys
diff --git a/core/color_names.inc b/core/color_names.inc
new file mode 100644
index 0000000000..7b674bb289
--- /dev/null
+++ b/core/color_names.inc
@@ -0,0 +1,150 @@
+// Names from https://en.wikipedia.org/wiki/List_of_colors (through https://raw.githubusercontent.com/SuperUserNameMan/color_to_name/616a7cddafefda91478b7bc26167de97fb5badb1/godot_version.gd), slightly edited and normalized
+static Map<String, Color> _named_colors;
+static void _populate_named_colors() {
+ if(!_named_colors.empty()) return;
+ _named_colors.insert("aliceblue", Color(0.94, 0.97, 1.00));
+ _named_colors.insert("antiquewhite", Color(0.98, 0.92, 0.84));
+ _named_colors.insert("aqua", Color(0.00, 1.00, 1.00));
+ _named_colors.insert("aquamarine", Color(0.50, 1.00, 0.83));
+ _named_colors.insert("azure", Color(0.94, 1.00, 1.00));
+ _named_colors.insert("beige", Color(0.96, 0.96, 0.86));
+ _named_colors.insert("bisque", Color(1.00, 0.89, 0.77));
+ _named_colors.insert("black", Color(0.00, 0.00, 0.00));
+ _named_colors.insert("blanchedalmond", Color(1.00, 0.92, 0.80));
+ _named_colors.insert("blue", Color(0.00, 0.00, 1.00));
+ _named_colors.insert("blueviolet", Color(0.54, 0.17, 0.89));
+ _named_colors.insert("brown", Color(0.65, 0.16, 0.16));
+ _named_colors.insert("burlywood", Color(0.87, 0.72, 0.53));
+ _named_colors.insert("cadetblue", Color(0.37, 0.62, 0.63));
+ _named_colors.insert("chartreuse", Color(0.50, 1.00, 0.00));
+ _named_colors.insert("chocolate", Color(0.82, 0.41, 0.12));
+ _named_colors.insert("coral", Color(1.00, 0.50, 0.31));
+ _named_colors.insert("cornflower", Color(0.39, 0.58, 0.93));
+ _named_colors.insert("cornsilk", Color(1.00, 0.97, 0.86));
+ _named_colors.insert("crimson", Color(0.86, 0.08, 0.24));
+ _named_colors.insert("cyan", Color(0.00, 1.00, 1.00));
+ _named_colors.insert("darkblue", Color(0.00, 0.00, 0.55));
+ _named_colors.insert("darkcyan", Color(0.00, 0.55, 0.55));
+ _named_colors.insert("darkgoldenrod", Color(0.72, 0.53, 0.04));
+ _named_colors.insert("darkgray", Color(0.66, 0.66, 0.66));
+ _named_colors.insert("darkgreen", Color(0.00, 0.39, 0.00));
+ _named_colors.insert("darkkhaki", Color(0.74, 0.72, 0.42));
+ _named_colors.insert("darkmagenta", Color(0.55, 0.00, 0.55));
+ _named_colors.insert("darkolivegreen", Color(0.33, 0.42, 0.18));
+ _named_colors.insert("darkorange", Color(1.00, 0.55, 0.00));
+ _named_colors.insert("darkorchid", Color(0.60, 0.20, 0.80));
+ _named_colors.insert("darkred", Color(0.55, 0.00, 0.00));
+ _named_colors.insert("darksalmon", Color(0.91, 0.59, 0.48));
+ _named_colors.insert("darkseagreen", Color(0.56, 0.74, 0.56));
+ _named_colors.insert("darkslateblue", Color(0.28, 0.24, 0.55));
+ _named_colors.insert("darkslategray", Color(0.18, 0.31, 0.31));
+ _named_colors.insert("darkturquoise", Color(0.00, 0.81, 0.82));
+ _named_colors.insert("darkviolet", Color(0.58, 0.00, 0.83));
+ _named_colors.insert("deeppink", Color(1.00, 0.08, 0.58));
+ _named_colors.insert("deepskyblue", Color(0.00, 0.75, 1.00));
+ _named_colors.insert("dimgray", Color(0.41, 0.41, 0.41));
+ _named_colors.insert("dodgerblue", Color(0.12, 0.56, 1.00));
+ _named_colors.insert("firebrick", Color(0.70, 0.13, 0.13));
+ _named_colors.insert("floralwhite", Color(1.00, 0.98, 0.94));
+ _named_colors.insert("forestgreen", Color(0.13, 0.55, 0.13));
+ _named_colors.insert("fuchsia", Color(1.00, 0.00, 1.00));
+ _named_colors.insert("gainsboro", Color(0.86, 0.86, 0.86));
+ _named_colors.insert("ghostwhite", Color(0.97, 0.97, 1.00));
+ _named_colors.insert("gold", Color(1.00, 0.84, 0.00));
+ _named_colors.insert("goldenrod", Color(0.85, 0.65, 0.13));
+ _named_colors.insert("gray", Color(0.75, 0.75, 0.75));
+ _named_colors.insert("webgray", Color(0.50, 0.50, 0.50));
+ _named_colors.insert("green", Color(0.00, 1.00, 0.00));
+ _named_colors.insert("webgreen", Color(0.00, 0.50, 0.00));
+ _named_colors.insert("greenyellow", Color(0.68, 1.00, 0.18));
+ _named_colors.insert("honeydew", Color(0.94, 1.00, 0.94));
+ _named_colors.insert("hotpink", Color(1.00, 0.41, 0.71));
+ _named_colors.insert("indianred", Color(0.80, 0.36, 0.36));
+ _named_colors.insert("indigo", Color(0.29, 0.00, 0.51));
+ _named_colors.insert("ivory", Color(1.00, 1.00, 0.94));
+ _named_colors.insert("khaki", Color(0.94, 0.90, 0.55));
+ _named_colors.insert("lavender", Color(0.90, 0.90, 0.98));
+ _named_colors.insert("lavenderblush", Color(1.00, 0.94, 0.96));
+ _named_colors.insert("lawngreen", Color(0.49, 0.99, 0.00));
+ _named_colors.insert("lemonchiffon", Color(1.00, 0.98, 0.80));
+ _named_colors.insert("lightblue", Color(0.68, 0.85, 0.90));
+ _named_colors.insert("lightcoral", Color(0.94, 0.50, 0.50));
+ _named_colors.insert("lightcyan", Color(0.88, 1.00, 1.00));
+ _named_colors.insert("lightgoldenrod", Color(0.98, 0.98, 0.82));
+ _named_colors.insert("lightgray", Color(0.83, 0.83, 0.83));
+ _named_colors.insert("lightgreen", Color(0.56, 0.93, 0.56));
+ _named_colors.insert("lightpink", Color(1.00, 0.71, 0.76));
+ _named_colors.insert("lightsalmon", Color(1.00, 0.63, 0.48));
+ _named_colors.insert("lightseagreen", Color(0.13, 0.70, 0.67));
+ _named_colors.insert("lightskyblue", Color(0.53, 0.81, 0.98));
+ _named_colors.insert("lightslategray", Color(0.47, 0.53, 0.60));
+ _named_colors.insert("lightsteelblue", Color(0.69, 0.77, 0.87));
+ _named_colors.insert("lightyellow", Color(1.00, 1.00, 0.88));
+ _named_colors.insert("lime", Color(0.00, 1.00, 0.00));
+ _named_colors.insert("limegreen", Color(0.20, 0.80, 0.20));
+ _named_colors.insert("linen", Color(0.98, 0.94, 0.90));
+ _named_colors.insert("magenta", Color(1.00, 0.00, 1.00));
+ _named_colors.insert("maroon", Color(0.69, 0.19, 0.38));
+ _named_colors.insert("webmaroon", Color(0.50, 0.00, 0.00));
+ _named_colors.insert("mediumaquamarine", Color(0.40, 0.80, 0.67));
+ _named_colors.insert("mediumblue", Color(0.00, 0.00, 0.80));
+ _named_colors.insert("mediumorchid", Color(0.73, 0.33, 0.83));
+ _named_colors.insert("mediumpurple", Color(0.58, 0.44, 0.86));
+ _named_colors.insert("mediumseagreen", Color(0.24, 0.70, 0.44));
+ _named_colors.insert("mediumslateblue", Color(0.48, 0.41, 0.93));
+ _named_colors.insert("mediumspringgreen", Color(0.00, 0.98, 0.60));
+ _named_colors.insert("mediumturquoise", Color(0.28, 0.82, 0.80));
+ _named_colors.insert("mediumvioletred", Color(0.78, 0.08, 0.52));
+ _named_colors.insert("midnightblue", Color(0.10, 0.10, 0.44));
+ _named_colors.insert("mintcream", Color(0.96, 1.00, 0.98));
+ _named_colors.insert("mistyrose", Color(1.00, 0.89, 0.88));
+ _named_colors.insert("moccasin", Color(1.00, 0.89, 0.71));
+ _named_colors.insert("navajowhite", Color(1.00, 0.87, 0.68));
+ _named_colors.insert("navyblue", Color(0.00, 0.00, 0.50));
+ _named_colors.insert("oldlace", Color(0.99, 0.96, 0.90));
+ _named_colors.insert("olive", Color(0.50, 0.50, 0.00));
+ _named_colors.insert("olivedrab", Color(0.42, 0.56, 0.14));
+ _named_colors.insert("orange", Color(1.00, 0.65, 0.00));
+ _named_colors.insert("orangered", Color(1.00, 0.27, 0.00));
+ _named_colors.insert("orchid", Color(0.85, 0.44, 0.84));
+ _named_colors.insert("palegoldenrod", Color(0.93, 0.91, 0.67));
+ _named_colors.insert("palegreen", Color(0.60, 0.98, 0.60));
+ _named_colors.insert("paleturquoise", Color(0.69, 0.93, 0.93));
+ _named_colors.insert("palevioletred", Color(0.86, 0.44, 0.58));
+ _named_colors.insert("papayawhip", Color(1.00, 0.94, 0.84));
+ _named_colors.insert("peachpuff", Color(1.00, 0.85, 0.73));
+ _named_colors.insert("peru", Color(0.80, 0.52, 0.25));
+ _named_colors.insert("pink", Color(1.00, 0.75, 0.80));
+ _named_colors.insert("plum", Color(0.87, 0.63, 0.87));
+ _named_colors.insert("powderblue", Color(0.69, 0.88, 0.90));
+ _named_colors.insert("purple", Color(0.63, 0.13, 0.94));
+ _named_colors.insert("webpurple", Color(0.50, 0.00, 0.50));
+ _named_colors.insert("rebeccapurple", Color(0.40, 0.20, 0.60));
+ _named_colors.insert("red", Color(1.00, 0.00, 0.00));
+ _named_colors.insert("rosybrown", Color(0.74, 0.56, 0.56));
+ _named_colors.insert("royalblue", Color(0.25, 0.41, 0.88));
+ _named_colors.insert("saddlebrown", Color(0.55, 0.27, 0.07));
+ _named_colors.insert("salmon", Color(0.98, 0.50, 0.45));
+ _named_colors.insert("sandybrown", Color(0.96, 0.64, 0.38));
+ _named_colors.insert("seagreen", Color(0.18, 0.55, 0.34));
+ _named_colors.insert("seashell", Color(1.00, 0.96, 0.93));
+ _named_colors.insert("sienna", Color(0.63, 0.32, 0.18));
+ _named_colors.insert("silver", Color(0.75, 0.75, 0.75));
+ _named_colors.insert("skyblue", Color(0.53, 0.81, 0.92));
+ _named_colors.insert("slateblue", Color(0.42, 0.35, 0.80));
+ _named_colors.insert("slategray", Color(0.44, 0.50, 0.56));
+ _named_colors.insert("snow", Color(1.00, 0.98, 0.98));
+ _named_colors.insert("springgreen", Color(0.00, 1.00, 0.50));
+ _named_colors.insert("steelblue", Color(0.27, 0.51, 0.71));
+ _named_colors.insert("tan", Color(0.82, 0.71, 0.55));
+ _named_colors.insert("teal", Color(0.00, 0.50, 0.50));
+ _named_colors.insert("thistle", Color(0.85, 0.75, 0.85));
+ _named_colors.insert("tomato", Color(1.00, 0.39, 0.28));
+ _named_colors.insert("turquoise", Color(0.25, 0.88, 0.82));
+ _named_colors.insert("violet", Color(0.93, 0.51, 0.93));
+ _named_colors.insert("wheat", Color(0.96, 0.87, 0.70));
+ _named_colors.insert("white", Color(1.00, 1.00, 1.00));
+ _named_colors.insert("whitesmoke", Color(0.96, 0.96, 0.96));
+ _named_colors.insert("yellow", Color(1.00, 1.00, 0.00));
+ _named_colors.insert("yellowgreen", Color(0.60, 0.80, 0.20));
+}
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index acd3aeddfb..9b1c052eb9 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index 409543bf25..779bbe1b58 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp
index b104b8062a..1e3a51fede 100644
--- a/core/compressed_translation.cpp
+++ b/core/compressed_translation.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -356,8 +356,8 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
hash_table.resize(size);
bucket_table.resize(bucket_table_size);
- DVector<int>::Write htwb = hash_table.write();
- DVector<int>::Write btwb = bucket_table.write();
+ PoolVector<int>::Write htwb = hash_table.write();
+ PoolVector<int>::Write btwb = bucket_table.write();
uint32_t *htw = (uint32_t*)&htwb[0];
uint32_t *btw = (uint32_t*)&btwb[0];
@@ -392,7 +392,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
print_line("total collisions: "+itos(collisions));
strings.resize(total_compression_size);
- DVector<uint8_t>::Write cw = strings.write();
+ PoolVector<uint8_t>::Write cw = strings.write();
for(int i=0;i<compressed.size();i++) {
memcpy(&cw[compressed[i].offset],compressed[i].compressed.get_data(),compressed[i].compressed.size());
@@ -454,11 +454,11 @@ StringName PHashTranslation::get_message(const StringName& p_src_text) const {
uint32_t h = hash(0,str.get_data());
- DVector<int>::Read htr = hash_table.read();
+ PoolVector<int>::Read htr = hash_table.read();
const uint32_t *htptr = (const uint32_t*)&htr[0];
- DVector<int>::Read btr = bucket_table.read();
+ PoolVector<int>::Read btr = bucket_table.read();
const uint32_t *btptr = (const uint32_t*)&btr[0];
- DVector<uint8_t>::Read sr = strings.read();
+ PoolVector<uint8_t>::Read sr = strings.read();
const char *sptr= (const char*)&sr[0];
uint32_t p = htptr[ h % htsize];
@@ -467,7 +467,7 @@ StringName PHashTranslation::get_message(const StringName& p_src_text) const {
//print_line("Hash: "+itos(p));
if (p==0xFFFFFFFF) {
-// print_line("GETMSG: Nothing!");
+ //print_line("GETMSG: Nothing!");
return StringName(); //nothing
}
@@ -489,7 +489,7 @@ StringName PHashTranslation::get_message(const StringName& p_src_text) const {
//print_line("bucket pos: "+itos(idx));
if (idx==-1) {
-// print_line("GETMSG: Not in Bucket!");
+ //print_line("GETMSG: Not in Bucket!");
return StringName();
}
@@ -497,8 +497,8 @@ StringName PHashTranslation::get_message(const StringName& p_src_text) const {
String rstr;
rstr.parse_utf8(&sptr[ bucket.elem[idx].str_offset ], bucket.elem[idx].uncomp_size );
-// print_line("Uncompressed, size: "+itos(bucket.elem[idx].comp_size));
-// print_line("Return: "+rstr);
+ //print_line("Uncompressed, size: "+itos(bucket.elem[idx].comp_size));
+ //print_line("Return: "+rstr);
return rstr;
} else {
@@ -508,8 +508,8 @@ StringName PHashTranslation::get_message(const StringName& p_src_text) const {
smaz_decompress(&sptr[ bucket.elem[idx].str_offset ], bucket.elem[idx].comp_size,uncomp.ptr(),bucket.elem[idx].uncomp_size );
String rstr;
rstr.parse_utf8(uncomp.get_data());
-// print_line("Compressed, size: "+itos(bucket.elem[idx].comp_size));
-// print_line("Return: "+rstr);
+ //print_line("Compressed, size: "+itos(bucket.elem[idx].comp_size));
+ //print_line("Return: "+rstr);
return rstr;
}
@@ -518,15 +518,15 @@ StringName PHashTranslation::get_message(const StringName& p_src_text) const {
void PHashTranslation::_get_property_list( List<PropertyInfo> *p_list) const{
- p_list->push_back( PropertyInfo(Variant::INT_ARRAY, "hash_table"));
- p_list->push_back( PropertyInfo(Variant::INT_ARRAY, "bucket_table"));
- p_list->push_back( PropertyInfo(Variant::RAW_ARRAY, "strings"));
+ p_list->push_back( PropertyInfo(Variant::POOL_INT_ARRAY, "hash_table"));
+ p_list->push_back( PropertyInfo(Variant::POOL_INT_ARRAY, "bucket_table"));
+ p_list->push_back( PropertyInfo(Variant::POOL_BYTE_ARRAY, "strings"));
p_list->push_back( PropertyInfo(Variant::OBJECT, "load_from",PROPERTY_HINT_RESOURCE_TYPE,"Translation",PROPERTY_USAGE_EDITOR));
}
void PHashTranslation::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("generate","from:Translation"),&PHashTranslation::generate);
+ ClassDB::bind_method(_MD("generate","from:Translation"),&PHashTranslation::generate);
}
PHashTranslation::PHashTranslation()
diff --git a/core/compressed_translation.h b/core/compressed_translation.h
index a1406ce1b2..cb1e084051 100644
--- a/core/compressed_translation.h
+++ b/core/compressed_translation.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,7 +33,7 @@
class PHashTranslation : public Translation {
- OBJ_TYPE(PHashTranslation,Translation);
+ GDCLASS(PHashTranslation,Translation);
//this translation uses a sort of modified perfect hash algorithm
@@ -42,9 +42,9 @@ class PHashTranslation : public Translation {
//of catching untranslated strings
//load/store friendly types
- DVector<int> hash_table;
- DVector<int> bucket_table;
- DVector<uint8_t> strings;
+ PoolVector<int> hash_table;
+ PoolVector<int> bucket_table;
+ PoolVector<uint8_t> strings;
struct Bucket {
diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp
index 8605b9131b..a173f98602 100644
--- a/core/core_string_names.cpp
+++ b/core/core_string_names.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/core_string_names.h b/core/core_string_names.h
index ef9e846c47..7d3754786c 100644
--- a/core/core_string_names.h
+++ b/core/core_string_names.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index 6770b798f1..3b4d3b65d0 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,7 +29,6 @@
#include "dictionary.h"
#include "safe_refcount.h"
#include "variant.h"
-#include "io/json.h"
struct _DictionaryVariantHash {
@@ -37,62 +36,96 @@ struct _DictionaryVariantHash {
};
+
+
+
struct DictionaryPrivate {
+ struct Data {
+ Variant variant;
+ int order;
+ };
+
SafeRefCount refcount;
- HashMap<Variant,Variant,_DictionaryVariantHash> variant_map;
- bool shared;
+ HashMap<Variant,Data,_DictionaryVariantHash> variant_map;
+ int counter;
};
+struct DictionaryPrivateSort {
-void Dictionary::get_key_list( List<Variant> *p_keys) const {
+ bool operator()(const HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair *A,const HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair *B) const {
- _p->variant_map.get_key_list(p_keys);
-}
+ return A->data.order < B->data.order;
+ }
+};
-void Dictionary::_copy_on_write() const {
+void Dictionary::get_key_list( List<Variant> *p_keys) const {
- //make a copy of what we have
- if (_p->shared)
+ if (_p->variant_map.empty())
return;
- DictionaryPrivate *p = memnew(DictionaryPrivate);
- p->shared=_p->shared;
- p->variant_map=_p->variant_map;
- p->refcount.init();
- _unref();
- _p=p;
+ int count = _p->variant_map.size();
+ const HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair **pairs = (const HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair**)alloca( count * sizeof(HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair *) );
+ _p->variant_map.get_key_value_ptr_array(pairs);
+
+ SortArray<const HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair*,DictionaryPrivateSort> sort;
+ sort.sort(pairs,count);
+
+ for(int i=0;i<count;i++) {
+ p_keys->push_back(pairs[i]->key);
+ }
+
}
Variant& Dictionary::operator[](const Variant& p_key) {
- _copy_on_write();
- return _p->variant_map[p_key];
+ DictionaryPrivate::Data *v =_p->variant_map.getptr(p_key);
+
+ if (!v) {
+
+ DictionaryPrivate::Data d;
+ d.order=_p->counter++;
+ _p->variant_map[p_key]=d;
+ v =_p->variant_map.getptr(p_key);
+
+ }
+ return v->variant;
}
const Variant& Dictionary::operator[](const Variant& p_key) const {
- return _p->variant_map[p_key];
+ return _p->variant_map[p_key].variant;
}
const Variant* Dictionary::getptr(const Variant& p_key) const {
- return _p->variant_map.getptr(p_key);
+ const DictionaryPrivate::Data *v =_p->variant_map.getptr(p_key);
+ if (!v)
+ return NULL;
+ else
+ return &v->variant;
}
+
Variant* Dictionary::getptr(const Variant& p_key) {
- _copy_on_write();
- return _p->variant_map.getptr(p_key);
+ DictionaryPrivate::Data *v =_p->variant_map.getptr(p_key);
+ if (!v)
+ return NULL;
+ else
+ return &v->variant;
+
+
}
Variant Dictionary::get_valid(const Variant& p_key) const {
- const Variant *v = getptr(p_key);
+ DictionaryPrivate::Data *v =_p->variant_map.getptr(p_key);
if (!v)
return Variant();
- return *v;
+ else
+ return v->variant;
}
@@ -121,7 +154,8 @@ bool Dictionary::has_all(const Array& p_keys) const {
}
void Dictionary::erase(const Variant& p_key) {
- _copy_on_write();
+
+
_p->variant_map.erase(p_key);
}
@@ -149,13 +183,8 @@ void Dictionary::_ref(const Dictionary& p_from) const {
void Dictionary::clear() {
- _copy_on_write();
_p->variant_map.clear();
-}
-
-bool Dictionary::is_shared() const {
-
- return _p->shared;
+ _p->counter=0;
}
@@ -203,11 +232,20 @@ Array Dictionary::values() const {
Array varr;
varr.resize(size());
- const Variant *key=NULL;
- int i=0;
- while((key=next(key))){
- varr[i++] = _p->variant_map[*key];
+ if (_p->variant_map.empty())
+ return varr;
+
+ int count = _p->variant_map.size();
+ const HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair **pairs = (const HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair**)alloca( count * sizeof(HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair *) );
+ _p->variant_map.get_key_value_ptr_array(pairs);
+
+ SortArray<const HashMap<Variant,DictionaryPrivate::Data,_DictionaryVariantHash>::Pair*,DictionaryPrivateSort> sort;
+ sort.sort(pairs,count);
+
+ for(int i=0;i<count;i++) {
+ varr[i]=pairs[i]->data.variant;
}
+
return varr;
}
@@ -216,25 +254,9 @@ const Variant* Dictionary::next(const Variant* p_key) const {
return _p->variant_map.next(p_key);
}
-
-Error Dictionary::parse_json(const String& p_json) {
-
- String errstr;
- int errline=0;
- if (p_json != ""){
- Error err = JSON::parse(p_json,*this,errstr,errline);
- if (err!=OK) {
- ERR_EXPLAIN("Error parsing JSON: "+errstr+" at line: "+itos(errline));
- ERR_FAIL_COND_V(err!=OK,err);
- }
- }
-
- return OK;
-}
-
Dictionary Dictionary::copy() const {
- Dictionary n(is_shared());
+ Dictionary n;
List<Variant> keys;
get_key_list(&keys);
@@ -246,11 +268,6 @@ Dictionary Dictionary::copy() const {
return n;
}
-String Dictionary::to_json() const {
-
- return JSON::print(*this);
-}
-
void Dictionary::operator=(const Dictionary& p_dictionary) {
@@ -265,11 +282,12 @@ Dictionary::Dictionary(const Dictionary& p_from) {
}
-Dictionary::Dictionary(bool p_shared) {
+Dictionary::Dictionary() {
_p=memnew( DictionaryPrivate );
_p->refcount.init();
- _p->shared=p_shared;
+ _p->counter=0;
+
}
Dictionary::~Dictionary() {
diff --git a/core/dictionary.h b/core/dictionary.h
index 6a5f4e20e6..a1bf291d6b 100644
--- a/core/dictionary.h
+++ b/core/dictionary.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -43,7 +43,7 @@ class Dictionary {
mutable DictionaryPrivate *_p;
- void _copy_on_write() const;
+
void _ref(const Dictionary& p_from) const;
void _unref() const;
public:
@@ -62,12 +62,6 @@ public:
bool empty() const;
void clear();
-
- Error parse_json(const String& p_json);
- String to_json() const;
-
- bool is_shared() const;
-
bool has(const Variant& p_key) const;
bool has_all(const Array& p_keys) const;
@@ -86,7 +80,7 @@ public:
Dictionary copy() const;
Dictionary(const Dictionary& p_from);
- Dictionary(bool p_shared=false);
+ Dictionary();
~Dictionary();
};
diff --git a/core/dvector.cpp b/core/dvector.cpp
index fa06399139..f6b5a5fcbf 100644
--- a/core/dvector.cpp
+++ b/core/dvector.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,3 +30,44 @@
Mutex* dvector_lock=NULL;
+PoolAllocator *MemoryPool::memory_pool=NULL;
+uint8_t *MemoryPool::pool_memory=NULL;
+size_t *MemoryPool::pool_size=NULL;
+
+
+MemoryPool::Alloc *MemoryPool::allocs=NULL;
+MemoryPool::Alloc *MemoryPool::free_list=NULL;
+uint32_t MemoryPool::alloc_count=0;
+uint32_t MemoryPool::allocs_used=0;
+Mutex *MemoryPool::alloc_mutex=NULL;
+
+size_t MemoryPool::total_memory=0;
+size_t MemoryPool::max_memory=0;
+
+
+void MemoryPool::setup(uint32_t p_max_allocs) {
+
+ allocs = memnew_arr( Alloc, p_max_allocs);
+ alloc_count = p_max_allocs;
+ allocs_used=0;
+
+ for(uint32_t i=0;i<alloc_count-1;i++) {
+
+ allocs[i].free_list=&allocs[i+1];
+ }
+
+ free_list=&allocs[0];
+
+ alloc_mutex = Mutex::create();
+
+}
+
+void MemoryPool::cleanup() {
+
+ memdelete_arr(allocs);
+ memdelete(alloc_mutex);
+
+ ERR_EXPLAINC("There are still MemoryPool allocs in use at exit!");
+ ERR_FAIL_COND(allocs_used>0);
+
+}
diff --git a/core/dvector.h b/core/dvector.h
index 9a54641617..cac9e8ef85 100644
--- a/core/dvector.h
+++ b/core/dvector.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,6 +30,46 @@
#define DVECTOR_H
#include "os/memory.h"
+#include "os/copymem.h"
+#include "pool_allocator.h"
+#include "safe_refcount.h"
+#include "os/rw_lock.h"
+
+struct MemoryPool {
+
+ //avoid accessing these directly, must be public for template access
+
+ static PoolAllocator *memory_pool;
+ static uint8_t *pool_memory;
+ static size_t *pool_size;
+
+
+ struct Alloc {
+
+ SafeRefCount refcount;
+ uint32_t lock;
+ void *mem;
+ PoolAllocator::ID pool_id;
+ size_t size;
+
+ Alloc *free_list;
+
+ Alloc() { mem=NULL; lock=0; pool_id=POOL_ALLOCATOR_INVALID_ID; size=0; free_list=NULL; }
+ };
+
+
+ static Alloc *allocs;
+ static Alloc *free_list;
+ static uint32_t alloc_count;
+ static uint32_t allocs_used;
+ static Mutex *alloc_mutex;
+ static size_t total_memory;
+ static size_t max_memory;
+
+
+ static void setup(uint32_t p_max_allocs=(1<<16));
+ static void cleanup();
+};
/**
@@ -37,182 +77,302 @@
*/
-extern Mutex* dvector_lock;
-
template<class T>
-class DVector {
+class PoolVector {
+
+ MemoryPool::Alloc *alloc;
- mutable MID mem;
+ void _copy_on_write() {
- void copy_on_write() {
- if (!mem.is_valid())
+ if (!alloc)
return;
- if (dvector_lock)
- dvector_lock->lock();
+ ERR_FAIL_COND(alloc->lock>0);
- MID_Lock lock( mem );
+ if (alloc->refcount.get()==1)
+ return; //nothing to do
- if ( *(int*)lock.data() == 1 ) {
- // one reference, means no refcount changes
- if (dvector_lock)
- dvector_lock->unlock();
- return;
+ //must allocate something
+
+ MemoryPool::alloc_mutex->lock();
+ if (MemoryPool::allocs_used==MemoryPool::alloc_count) {
+ MemoryPool::alloc_mutex->unlock();
+ ERR_EXPLAINC("All memory pool allocations are in use, can't COW.");
+ ERR_FAIL();
}
- MID new_mem= dynalloc( mem.get_size() );
+ MemoryPool::Alloc *old_alloc = alloc;
- if (!new_mem.is_valid()) {
+ //take one from the free list
+ alloc = MemoryPool::free_list;
+ MemoryPool::free_list = alloc->free_list;
+ //increment the used counter
+ MemoryPool::allocs_used++;
- if (dvector_lock)
- dvector_lock->unlock();
- ERR_FAIL_COND( new_mem.is_valid() ); // out of memory
+ //copy the alloc data
+ alloc->size=old_alloc->size;
+ alloc->refcount.init();
+ alloc->pool_id=POOL_ALLOCATOR_INVALID_ID;
+ alloc->lock=0;
+
+#ifdef DEBUG_ENABLED
+ MemoryPool::total_memory+=alloc->size;
+ if (MemoryPool::total_memory>MemoryPool::max_memory) {
+ MemoryPool::max_memory=MemoryPool::total_memory;
}
+#endif
- MID_Lock dst_lock( new_mem );
+ MemoryPool::alloc_mutex->unlock();
- int *rc = (int*)dst_lock.data();
- *rc=1;
+ if (MemoryPool::memory_pool) {
- T * dst = (T*)(rc + 1 );
- T * src =(T*) ((int*)lock.data() + 1 );
+ } else {
+ alloc->mem = memalloc( alloc->size );
+ }
- int count = (mem.get_size() - sizeof(int)) / sizeof(T);
+ {
+ Write w;
+ w._ref(alloc);
+ Read r;
+ r._ref(old_alloc);
+
+ int cur_elements = alloc->size/sizeof(T);
+ T*dst = (T*)w.ptr();
+ const T*src = (const T*)r.ptr();
+ for(int i=0;i<cur_elements;i++) {
+ memnew_placement(&dst[i],T(src[i]));
+ }
+ }
- for (int i=0;i<count;i++) {
- memnew_placement( &dst[i], T(src[i]) );
- }
+ if (old_alloc->refcount.unref()==true) {
+ //this should never happen but..
- (*(int*)lock.data())--;
+#ifdef DEBUG_ENABLED
+ MemoryPool::alloc_mutex->lock();
+ MemoryPool::total_memory-=old_alloc->size;
+ MemoryPool::alloc_mutex->unlock();
+#endif
- // unlock all
- dst_lock=MID_Lock();
- lock=MID_Lock();
+ {
+ Write w;
+ w._ref(old_alloc);
- mem=new_mem;
+ int cur_elements = old_alloc->size/sizeof(T);
+ T*elems = (T*)w.ptr();
+ for(int i=0;i<cur_elements;i++) {
+ elems[i].~T();
+ }
- if (dvector_lock)
- dvector_lock->unlock();
+ }
- }
+ if (MemoryPool::memory_pool) {
+ //resize memory pool
+ //if none, create
+ //if some resize
+ } else {
- void reference( const DVector& p_dvector ) {
- unreference();
+ memfree( old_alloc->mem );
+ old_alloc->mem=NULL;
+ old_alloc->size=0;
- if (dvector_lock)
- dvector_lock->lock();
- if (!p_dvector.mem.is_valid()) {
+ MemoryPool::alloc_mutex->lock();
+ old_alloc->free_list=MemoryPool::free_list;
+ MemoryPool::free_list=old_alloc;
+ MemoryPool::allocs_used--;
+ MemoryPool::alloc_mutex->unlock();
+ }
- if (dvector_lock)
- dvector_lock->unlock();
- return;
}
- MID_Lock lock(p_dvector.mem);
+ }
- int * rc = (int*)lock.data();
- (*rc)++;
+ void _reference( const PoolVector& p_dvector ) {
- lock = MID_Lock();
- mem=p_dvector.mem;
+ if (alloc==p_dvector.alloc)
+ return;
- if (dvector_lock)
- dvector_lock->unlock();
+ _unreference();
- }
+ if (!p_dvector.alloc) {
+ return;
+ }
+ if (p_dvector.alloc->refcount.ref()) {
+ alloc=p_dvector.alloc;
+ }
- void unreference() {
+ }
- if (dvector_lock)
- dvector_lock->lock();
- if (!mem.is_valid()) {
+ void _unreference() {
- if (dvector_lock)
- dvector_lock->unlock();
+ if (!alloc)
return;
- }
- MID_Lock lock(mem);
-
- int * rc = (int*)lock.data();
- (*rc)--;
+ if (alloc->refcount.unref()==false) {
+ alloc=NULL;
+ return;
+ }
- if (*rc==0) {
- // no one else using it, destruct
+ //must be disposed!
- T * t= (T*)(rc+1);
- int count = (mem.get_size() - sizeof(int)) / sizeof(T);
+ {
+ int cur_elements = alloc->size/sizeof(T);
+ Write w = write();
- for (int i=0;i<count;i++) {
+ for (int i=0;i<cur_elements;i++) {
- t[i].~T();
+ w[i].~T();
}
}
+#ifdef DEBUG_ENABLED
+ MemoryPool::alloc_mutex->lock();
+ MemoryPool::total_memory-=alloc->size;
+ MemoryPool::alloc_mutex->unlock();
+#endif
+
+
+ if (MemoryPool::memory_pool) {
+ //resize memory pool
+ //if none, create
+ //if some resize
+ } else {
+
+ memfree( alloc->mem );
+ alloc->mem=NULL;
+ alloc->size=0;
- lock = MID_Lock();
- mem = MID ();
+ MemoryPool::alloc_mutex->lock();
+ alloc->free_list=MemoryPool::free_list;
+ MemoryPool::free_list=alloc;
+ MemoryPool::allocs_used--;
+ MemoryPool::alloc_mutex->unlock();
- if (dvector_lock)
- dvector_lock->unlock();
+ }
+ alloc=NULL;
}
public:
- class Read {
- friend class DVector;
- MID_Lock lock;
- const T * mem;
+ class Access {
+ friend class PoolVector;
+ protected:
+ MemoryPool::Alloc *alloc;
+ T * mem;
+
+ _FORCE_INLINE_ void _ref(MemoryPool::Alloc *p_alloc) {
+ alloc=p_alloc;
+ if (alloc) {
+ if (atomic_increment(&alloc->lock)==1) {
+ if (MemoryPool::memory_pool) {
+ //lock it and get mem
+ }
+ }
+
+ mem = (T*)alloc->mem;
+ }
+ }
+
+ _FORCE_INLINE_ void _unref() {
+
+
+ if (alloc) {
+ if (atomic_decrement(&alloc->lock)==0) {
+ if (MemoryPool::memory_pool) {
+ //put mem back
+ }
+ }
+
+ mem = NULL;
+ alloc=NULL;
+ }
+
+
+ }
+
+ Access() {
+ alloc=NULL;
+ mem=NULL;
+ }
+
+
+ public:
+ virtual ~Access() {
+ _unref();
+ }
+ };
+
+ class Read : public Access {
public:
- _FORCE_INLINE_ const T& operator[](int p_index) const { return mem[p_index]; }
- _FORCE_INLINE_ const T *ptr() const { return mem; }
+ _FORCE_INLINE_ const T& operator[](int p_index) const { return this->mem[p_index]; }
+ _FORCE_INLINE_ const T *ptr() const { return this->mem; }
+
+ void operator=(const Read& p_read) {
+ if (this->alloc==p_read.alloc)
+ return;
+ this->_unref();
+ this->_ref(p_read.alloc);
+ }
+
+ Read(const Read& p_read) {
+ this->_ref(p_read.alloc);
+ }
+
+ Read() {}
+
- Read() { mem=NULL; }
};
- class Write {
- friend class DVector;
- MID_Lock lock;
- T * mem;
+ class Write : public Access {
public:
- _FORCE_INLINE_ T& operator[](int p_index) { return mem[p_index]; }
- _FORCE_INLINE_ T *ptr() { return mem; }
+ _FORCE_INLINE_ T& operator[](int p_index) const { return this->mem[p_index]; }
+ _FORCE_INLINE_ T *ptr() const { return this->mem; }
+
+ void operator=(const Write& p_read) {
+ if (this->alloc==p_read.alloc)
+ return;
+ this->_unref();
+ this->_ref(p_read.alloc);
+ }
+
+ Write(const Write& p_read) {
+ this->_ref(p_read.alloc);
+ }
+
+ Write() {}
- Write() { mem=NULL; }
};
Read read() const {
Read r;
- if (mem.is_valid()) {
- r.lock = MID_Lock( mem );
- r.mem = (const T*)((int*)r.lock.data()+1);
+ if (alloc) {
+ r._ref(alloc);
}
return r;
+
}
Write write() {
Write w;
- if (mem.is_valid()) {
- copy_on_write();
- w.lock = MID_Lock( mem );
- w.mem = (T*)((int*)w.lock.data()+1);
+ if (alloc) {
+ _copy_on_write(); //make sure there is only one being acessed
+ w._ref(alloc);
}
return w;
}
@@ -250,7 +410,7 @@ public:
void set(int p_index, const T& p_val);
void push_back(const T& p_val);
void append(const T& p_val) { push_back(p_val); }
- void append_array(const DVector<T>& p_arr) {
+ void append_array(const PoolVector<T>& p_arr) {
int ds = p_arr.size();
if (ds==0)
return;
@@ -262,7 +422,7 @@ public:
w[bs+i]=r[i];
}
- DVector<T> subarray(int p_from, int p_to) {
+ PoolVector<T> subarray(int p_from, int p_to) {
if (p_from<0) {
p_from=size()+p_from;
@@ -271,15 +431,15 @@ public:
p_to=size()+p_to;
}
if (p_from<0 || p_from>=size()) {
- DVector<T>& aux=*((DVector<T>*)0); // nullreturn
+ PoolVector<T>& aux=*((PoolVector<T>*)0); // nullreturn
ERR_FAIL_COND_V(p_from<0 || p_from>=size(),aux)
}
if (p_to<0 || p_to>=size()) {
- DVector<T>& aux=*((DVector<T>*)0); // nullreturn
+ PoolVector<T>& aux=*((PoolVector<T>*)0); // nullreturn
ERR_FAIL_COND_V(p_to<0 || p_to>=size(),aux)
}
- DVector<T> slice;
+ PoolVector<T> slice;
int span=1 + p_to - p_from;
slice.resize(span);
Read r = read();
@@ -307,7 +467,7 @@ public:
}
- bool is_locked() const { return mem.is_locked(); }
+ bool is_locked() const { return alloc && alloc->lock>0; }
inline const T operator[](int p_index) const;
@@ -315,27 +475,27 @@ public:
void invert();
- void operator=(const DVector& p_dvector) { reference(p_dvector); }
- DVector() {}
- DVector(const DVector& p_dvector) { reference(p_dvector); }
- ~DVector() { unreference(); }
+ void operator=(const PoolVector& p_dvector) { _reference(p_dvector); }
+ PoolVector() { alloc=NULL; }
+ PoolVector(const PoolVector& p_dvector) { alloc=NULL; _reference(p_dvector); }
+ ~PoolVector() { _unreference(); }
};
template<class T>
-int DVector<T>::size() const {
+int PoolVector<T>::size() const {
- return mem.is_valid() ? ((mem.get_size() - sizeof(int)) / sizeof(T) ) : 0;
+ return alloc ? alloc->size/sizeof(T) : 0;
}
template<class T>
-T DVector<T>::get(int p_index) const {
+T PoolVector<T>::get(int p_index) const {
return operator[](p_index);
}
template<class T>
-void DVector<T>::set(int p_index, const T& p_val) {
+void PoolVector<T>::set(int p_index, const T& p_val) {
if (p_index<0 || p_index>=size()) {
ERR_FAIL_COND(p_index<0 || p_index>=size());
@@ -346,14 +506,14 @@ void DVector<T>::set(int p_index, const T& p_val) {
}
template<class T>
-void DVector<T>::push_back(const T& p_val) {
+void PoolVector<T>::push_back(const T& p_val) {
resize( size() + 1 );
set( size() -1, p_val );
}
template<class T>
-const T DVector<T>::operator[](int p_index) const {
+const T PoolVector<T>::operator[](int p_index) const {
if (p_index<0 || p_index>=size()) {
T& aux=*((T*)0); //nullreturn
@@ -367,86 +527,122 @@ const T DVector<T>::operator[](int p_index) const {
template<class T>
-Error DVector<T>::resize(int p_size) {
+Error PoolVector<T>::resize(int p_size) {
- if (dvector_lock)
- dvector_lock->lock();
- bool same = p_size==size();
+ if (alloc==NULL) {
- if (dvector_lock)
- dvector_lock->unlock();
- // no further locking is necesary because we are supposed to own the only copy of this (using copy on write)
+ if (p_size==0)
+ return OK; //nothing to do here
- if (same)
- return OK;
+ //must allocate something
+ MemoryPool::alloc_mutex->lock();
+ if (MemoryPool::allocs_used==MemoryPool::alloc_count) {
+ MemoryPool::alloc_mutex->unlock();
+ ERR_EXPLAINC("All memory pool allocations are in use.");
+ ERR_FAIL_V(ERR_OUT_OF_MEMORY);
+ }
- if (p_size == 0 ) {
+ //take one from the free list
+ alloc = MemoryPool::free_list;
+ MemoryPool::free_list = alloc->free_list;
+ //increment the used counter
+ MemoryPool::allocs_used++;
- unreference();
- return OK;
+ //cleanup the alloc
+ alloc->size=0;
+ alloc->refcount.init();
+ alloc->pool_id=POOL_ALLOCATOR_INVALID_ID;
+ MemoryPool::alloc_mutex->unlock();
+
+ } else {
+
+ ERR_FAIL_COND_V( alloc->lock>0, ERR_LOCKED ); //can't resize if locked!
}
+ size_t new_size = sizeof(T)*p_size;
- copy_on_write(); // make it unique
+ if (alloc->size==new_size)
+ return OK; //nothing to do
- ERR_FAIL_COND_V( mem.is_locked(), ERR_LOCKED ); // if after copy on write, memory is locked, fail.
+ if (p_size == 0 ) {
+ _unreference();
+ return OK;
+ }
- if (p_size > size() ) {
+ _copy_on_write(); // make it unique
- int oldsize=size();
+#ifdef DEBUG_ENABLED
+ MemoryPool::alloc_mutex->lock();
+ MemoryPool::total_memory-=alloc->size;
+ MemoryPool::total_memory+=new_size;
+ if (MemoryPool::total_memory>MemoryPool::max_memory) {
+ MemoryPool::max_memory=MemoryPool::total_memory;
+ }
+ MemoryPool::alloc_mutex->unlock();
+#endif
- MID_Lock lock;
- if (oldsize==0) {
+ int cur_elements = alloc->size / sizeof(T);
- mem = dynalloc( p_size * sizeof(T) + sizeof(int) );
- lock=MID_Lock(mem);
- int *rc = ((int*)lock.data());
- *rc=1;
+ if (p_size > cur_elements ) {
+ if (MemoryPool::memory_pool) {
+ //resize memory pool
+ //if none, create
+ //if some resize
} else {
- if (dynrealloc( mem, p_size * sizeof(T) + sizeof(int) )!=OK ) {
-
- ERR_FAIL_V(ERR_OUT_OF_MEMORY); // out of memory
+ if (alloc->size==0) {
+ alloc->mem = memalloc( new_size );
+ } else {
+ alloc->mem = memrealloc( alloc->mem, new_size );
}
-
- lock=MID_Lock(mem);
}
+ alloc->size=new_size;
+ Write w = write();
+ for (int i=cur_elements;i<p_size;i++) {
- T *t = (T*)((int*)lock.data() + 1);
-
- for (int i=oldsize;i<p_size;i++) {
-
- memnew_placement(&t[i], T );
+ memnew_placement(&w[i], T );
}
- lock = MID_Lock(); // clear
- } else {
-
- int oldsize=size();
-
- MID_Lock lock(mem);
+ } else {
- T *t = (T*)((int*)lock.data() + 1);
+ {
+ Write w = write();
+ for (int i=p_size;i<cur_elements;i++) {
- for (int i=p_size;i<oldsize;i++) {
+ w[i].~T();
+ }
- t[i].~T();
}
- lock = MID_Lock(); // clear
+ if (MemoryPool::memory_pool) {
+ //resize memory pool
+ //if none, create
+ //if some resize
+ } else {
- if (dynrealloc( mem, p_size * sizeof(T) + sizeof(int) )!=OK ) {
+ if (new_size==0) {
+ memfree( alloc->mem );
+ alloc->mem=NULL;
+ alloc->size=0;
- ERR_FAIL_V(ERR_OUT_OF_MEMORY); // wtf error
- }
+ MemoryPool::alloc_mutex->lock();
+ alloc->free_list=MemoryPool::free_list;
+ MemoryPool::free_list=alloc;
+ MemoryPool::allocs_used--;
+ MemoryPool::alloc_mutex->unlock();
+ } else {
+ alloc->mem = memrealloc( alloc->mem, new_size );
+ alloc->size=new_size;
+ }
+ }
}
@@ -454,7 +650,7 @@ Error DVector<T>::resize(int p_size) {
}
template<class T>
-void DVector<T>::invert() {
+void PoolVector<T>::invert() {
T temp;
Write w = write();
int s = size();
diff --git a/core/os/memory_pool_static.cpp b/core/engine.cpp
index 88c2ba3b3e..eb6d8a3478 100644
--- a/core/os/memory_pool_static.cpp
+++ b/core/engine.cpp
@@ -1,11 +1,11 @@
/*************************************************************************/
-/* memory_pool_static.cpp */
+/* engine.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -26,24 +26,93 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "memory_pool_static.h"
+#include "engine.h"
+#include "version.h"
-MemoryPoolStatic *MemoryPoolStatic::singleton=0;
+void Engine::set_iterations_per_second(int p_ips) {
-MemoryPoolStatic *MemoryPoolStatic::get_singleton() {
+ ips=p_ips;
+}
+int Engine::get_iterations_per_second() const {
- return singleton;
+ return ips;
}
+void Engine::set_target_fps(int p_fps) {
+ _target_fps=p_fps>0? p_fps : 0;
+}
-MemoryPoolStatic::MemoryPoolStatic() {
+float Engine::get_target_fps() const {
+ return _target_fps;
+}
- singleton=this;
+uint64_t Engine::get_frames_drawn() {
+
+ return frames_drawn;
+}
+
+void Engine::set_frame_delay(uint32_t p_msec) {
+
+ _frame_delay=p_msec;
}
+uint32_t Engine::get_frame_delay() const {
-MemoryPoolStatic::~MemoryPoolStatic() {
- singleton=NULL;
+ return _frame_delay;
}
+void Engine::set_time_scale(float p_scale) {
+
+ _time_scale=p_scale;
+}
+
+float Engine::get_time_scale() const {
+
+ return _time_scale;
+}
+Dictionary Engine::get_version_info() const {
+
+ Dictionary dict;
+ dict["major"] = VERSION_MAJOR;
+ dict["minor"] = VERSION_MINOR;
+ #ifdef VERSION_PATCH
+ dict["patch"] = VERSION_PATCH;
+ #else
+ dict["patch"] = 0;
+ #endif
+ dict["status"] = _MKSTR(VERSION_STATUS);
+ dict["revision"] = _MKSTR(VERSION_REVISION);
+ dict["year"] = VERSION_YEAR;
+
+ String stringver = String(dict["major"]) + "." + String(dict["minor"]);
+ if ((int)dict["patch"] != 0)
+ stringver += "." + String(dict["patch"]);
+ stringver += "-" + String(dict["status"]) + " (" + String(dict["revision"]) + ")";
+ dict["string"] = stringver;
+
+ return dict;
+}
+
+
+Engine *Engine::singleton=NULL;
+
+Engine *Engine::get_singleton() {
+ return singleton;
+}
+
+Engine::Engine()
+{
+
+ singleton=this;
+ frames_drawn=0;
+ ips=60;
+ _frame_delay=0;
+ _fps=1;
+ _target_fps=0;
+ _time_scale=1.0;
+ _pixel_snap=false;
+ _fixed_frames=0;
+ _idle_frames=0;
+ _in_fixed=false;
+}
diff --git a/core/os/memory_pool_dynamic.h b/core/engine.h
index 70752fb10d..9af4219a68 100644
--- a/core/os/memory_pool_dynamic.h
+++ b/core/engine.h
@@ -1,11 +1,11 @@
/*************************************************************************/
-/* memory_pool_dynamic.h */
+/* engine.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -26,54 +26,63 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef MEMORY_POOL_DYNAMIC_H
-#define MEMORY_POOL_DYNAMIC_H
+#ifndef ENGINE_H
+#define ENGINE_H
-#include "typedefs.h"
+#include "ustring.h"
+#include "list.h"
+#include "vector.h"
+#include "os/main_loop.h"
+class Engine {
-class MemoryPoolDynamic {
+friend class Main;
- static MemoryPoolDynamic* singleton;
-protected:
-friend class Memory;
-friend class MID;
+ String _custom_level;
+ uint64_t frames_drawn;
+ uint32_t _frame_delay;
- enum {
+ int ips;
+ float _fps;
+ int _target_fps;
+ float _time_scale;
+ bool _pixel_snap;
+ uint64_t _fixed_frames;
+ uint64_t _idle_frames;
+ bool _in_fixed;
- INVALID_ID=0xFFFFFFFF
- };
-
- static MemoryPoolDynamic* get_singleton();
-
- typedef uint64_t ID;
+ static Engine *singleton;
+public:
+ static Engine *get_singleton();
- virtual ID alloc(size_t p_amount,const char* p_description)=0;
- virtual void free(ID p_id)=0;
- virtual Error realloc(ID p_id, size_t p_amount)=0;
- virtual bool is_valid(ID p_id)=0;
- virtual size_t get_size(ID p_id) const=0;
- virtual const char* get_description(ID p_id) const=0;
+ virtual void set_iterations_per_second(int p_ips);
+ virtual int get_iterations_per_second() const;
- virtual Error lock(ID p_id)=0;
- virtual void * get(ID p_ID)=0;
- virtual Error unlock(ID p_id)=0;
- virtual bool is_locked(ID p_id) const=0;
+ virtual void set_target_fps(int p_fps);
+ virtual float get_target_fps() const;
- virtual size_t get_available_mem() const=0;
- virtual size_t get_total_usage() const=0;
+ virtual float get_frames_per_second() const { return _fps; }
- MemoryPoolDynamic();
-public:
- virtual ~MemoryPoolDynamic();
+ String get_custom_level() const { return _custom_level; }
-};
+ uint64_t get_frames_drawn();
+ uint64_t get_fixed_frames() const { return _fixed_frames; }
+ uint64_t get_idle_frames() const { return _idle_frames; }
+ bool is_in_fixed_frame() const { return _in_fixed; }
-#endif
+ void set_time_scale(float p_scale);
+ float get_time_scale() const;
+ void set_frame_delay(uint32_t p_msec);
+ uint32_t get_frame_delay() const;
+ _FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; }
+ Dictionary get_version_info() const;
+ Engine();
+};
+#endif // ENGINE_H
diff --git a/core/error_list.h b/core/error_list.h
index cb531f527f..c3cd9b399d 100644
--- a/core/error_list.h
+++ b/core/error_list.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -57,33 +57,33 @@ enum Error {
ERR_FILE_MISSING_DEPENDENCIES,
ERR_FILE_EOF,
ERR_CANT_OPEN, ///< Can't open a resource/socket/file
- ERR_CANT_CREATE,
- ERROR_QUERY_FAILED, // (20)
+ ERR_CANT_CREATE, // (20)
+ ERROR_QUERY_FAILED,
ERR_ALREADY_IN_USE,
ERR_LOCKED, ///< resource is locked
ERR_TIMEOUT,
- ERR_CANT_CONNECT,
- ERR_CANT_RESOLVE, // (25)
+ ERR_CANT_CONNECT, // (25)
+ ERR_CANT_RESOLVE,
ERR_CONNECTION_ERROR,
ERR_CANT_AQUIRE_RESOURCE,
ERR_CANT_FORK,
- ERR_INVALID_DATA, ///< Data passed is invalid
- ERR_INVALID_PARAMETER, ///< Parameter passed is invalid (30)
+ ERR_INVALID_DATA, ///< Data passed is invalid (30)
+ ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
ERR_ALREADY_EXISTS, ///< When adding, item already exists
ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
ERR_DATABASE_CANT_READ, ///< database is full
- ERR_DATABASE_CANT_WRITE, ///< database is full
- ERR_COMPILATION_FAILED, // (35)
+ ERR_DATABASE_CANT_WRITE, ///< database is full (35)
+ ERR_COMPILATION_FAILED,
ERR_METHOD_NOT_FOUND,
ERR_LINK_FAILED,
ERR_SCRIPT_FAILED,
- ERR_CYCLIC_LINK,
- ERR_INVALID_DECLARATION, // (40)
+ ERR_CYCLIC_LINK, // (40)
+ ERR_INVALID_DECLARATION,
ERR_DUPLICATE_SYMBOL,
ERR_PARSE_ERROR,
ERR_BUSY,
- ERR_SKIP,
- ERR_HELP, ///< user requested help!! (45)
+ ERR_SKIP, // (45)
+ ERR_HELP, ///< user requested help!!
ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
diff --git a/core/error_macros.cpp b/core/error_macros.cpp
index 03e5ba37da..53a361fa3a 100644
--- a/core/error_macros.cpp
+++ b/core/error_macros.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/error_macros.h b/core/error_macros.h
index 6d931e899e..ac86ef432b 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -49,7 +49,8 @@
enum ErrorHandlerType {
ERR_HANDLER_ERROR,
ERR_HANDLER_WARNING,
- ERR_HANDLER_SCRIPT
+ ERR_HANDLER_SCRIPT,
+ ERR_HANDLER_SHADER,
};
typedef void (*ErrorHandlerFunc)(void*,const char*,const char*,int p_line,const char *, const char *,ErrorHandlerType p_type);
diff --git a/core/event_queue.cpp b/core/event_queue.cpp
index 958ef41132..587283cc79 100644
--- a/core/event_queue.cpp
+++ b/core/event_queue.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/event_queue.h b/core/event_queue.h
index 99e853fd28..d15ff81bc7 100644
--- a/core/event_queue.h
+++ b/core/event_queue.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/func_ref.cpp b/core/func_ref.cpp
index ca890111be..1e8c229810 100644
--- a/core/func_ref.cpp
+++ b/core/func_ref.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -61,12 +61,12 @@ void FuncRef::_bind_methods() {
MethodInfo mi;
mi.name="call_func";
Vector<Variant> defargs;
- ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call_func:Variant",&FuncRef::call_func,mi,defargs);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call_func:Variant",&FuncRef::call_func,mi,defargs);
}
- ObjectTypeDB::bind_method(_MD("set_instance","instance"),&FuncRef::set_instance);
- ObjectTypeDB::bind_method(_MD("set_function","name"),&FuncRef::set_function);
+ ClassDB::bind_method(_MD("set_instance","instance"),&FuncRef::set_instance);
+ ClassDB::bind_method(_MD("set_function","name"),&FuncRef::set_function);
}
diff --git a/core/func_ref.h b/core/func_ref.h
index 140dcd6b1c..0c9bca4680 100644
--- a/core/func_ref.h
+++ b/core/func_ref.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,7 +33,7 @@
class FuncRef : public Reference{
- OBJ_TYPE(FuncRef,Reference);
+ GDCLASS(FuncRef,Reference);
ObjectID id;
StringName function;
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index 2594be63ac..936facdd23 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -329,7 +329,7 @@ static _GlobalConstant _global_constants[]={
BIND_GLOBAL_CONSTANT( BUTTON_MASK_RIGHT ),
BIND_GLOBAL_CONSTANT( BUTTON_MASK_MIDDLE ),
- //joysticks
+ //joypads
BIND_GLOBAL_CONSTANT( JOY_BUTTON_0 ),
BIND_GLOBAL_CONSTANT( JOY_BUTTON_1 ),
BIND_GLOBAL_CONSTANT( JOY_BUTTON_2 ),
@@ -463,7 +463,12 @@ static _GlobalConstant _global_constants[]={
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_LENGTH ),
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_KEY_ACCEL ),
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FLAGS ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_ALL_FLAGS ),
+
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_LAYERS_2D_RENDER ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_LAYERS_2D_PHYSICS ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_LAYERS_3D_RENDER ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_LAYERS_3D_PHYSICS),
+
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FILE ),
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_DIR ),
BIND_GLOBAL_CONSTANT( PROPERTY_HINT_GLOBAL_FILE ),
@@ -483,7 +488,7 @@ static _GlobalConstant _global_constants[]={
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_CHECKABLE ),
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_CHECKED ),
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_INTERNATIONALIZED ),
- BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_BUNDLE ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_GROUP ),
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_CATEGORY ),
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORE_IF_NONZERO ),
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORE_IF_NONONE ),
@@ -512,11 +517,11 @@ static _GlobalConstant _global_constants[]={
{"TYPE_VECTOR2",Variant::VECTOR2}, // 5
{"TYPE_RECT2",Variant::RECT2},
{"TYPE_VECTOR3",Variant::VECTOR3},
- {"TYPE_MATRIX32",Variant::MATRIX32},
+ {"TYPE_TRANSFORM2D",Variant::TRANSFORM2D},
{"TYPE_PLANE",Variant::PLANE},
{"TYPE_QUAT",Variant::QUAT}, // 10
- {"TYPE_AABB",Variant::_AABB}, //sorry naming convention fail :( not like it's used often
- {"TYPE_MATRIX3",Variant::MATRIX3},
+ {"TYPE_RECT3",Variant::RECT3}, //sorry naming convention fail :( not like it's used often
+ {"TYPE_BASIS",Variant::BASIS},
{"TYPE_TRANSFORM",Variant::TRANSFORM},
{"TYPE_COLOR",Variant::COLOR},
{"TYPE_IMAGE",Variant::IMAGE}, // 15
@@ -526,13 +531,13 @@ static _GlobalConstant _global_constants[]={
{"TYPE_INPUT_EVENT",Variant::INPUT_EVENT},
{"TYPE_DICTIONARY",Variant::DICTIONARY}, // 20
{"TYPE_ARRAY",Variant::ARRAY},
- {"TYPE_RAW_ARRAY",Variant::RAW_ARRAY},
- {"TYPE_INT_ARRAY",Variant::INT_ARRAY},
- {"TYPE_REAL_ARRAY",Variant::REAL_ARRAY},
- {"TYPE_STRING_ARRAY",Variant::STRING_ARRAY}, // 25
- {"TYPE_VECTOR2_ARRAY",Variant::VECTOR2_ARRAY},
- {"TYPE_VECTOR3_ARRAY",Variant::VECTOR3_ARRAY},
- {"TYPE_COLOR_ARRAY",Variant::COLOR_ARRAY},
+ {"TYPE_RAW_ARRAY",Variant::POOL_BYTE_ARRAY},
+ {"TYPE_INT_ARRAY",Variant::POOL_INT_ARRAY},
+ {"TYPE_REAL_ARRAY",Variant::POOL_REAL_ARRAY},
+ {"TYPE_STRING_ARRAY",Variant::POOL_STRING_ARRAY}, // 25
+ {"TYPE_VECTOR2_ARRAY",Variant::POOL_VECTOR2_ARRAY},
+ {"TYPE_VECTOR3_ARRAY",Variant::POOL_VECTOR3_ARRAY},
+ {"TYPE_COLOR_ARRAY",Variant::POOL_COLOR_ARRAY},
{"TYPE_MAX",Variant::VARIANT_MAX},
{NULL,0}
diff --git a/core/global_constants.h b/core/global_constants.h
index f7f6677482..3270dcd151 100644
--- a/core/global_constants.h
+++ b/core/global_constants.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/globals.cpp b/core/globals.cpp
index b822f52f15..a4c24a6cc8 100644
--- a/core/globals.cpp
+++ b/core/globals.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,25 +36,26 @@
#include "os/os.h"
#include "io/file_access_pack.h"
#include "io/file_access_network.h"
+#include "variant_parser.h"
+GlobalConfig *GlobalConfig::singleton=NULL;
-Globals *Globals::singleton=NULL;
-
-Globals *Globals::get_singleton() {
+GlobalConfig *GlobalConfig::get_singleton() {
return singleton;
}
-String Globals::get_resource_path() const {
+String GlobalConfig::get_resource_path() const {
return resource_path;
};
-String Globals::localize_path(const String& p_path) const {
+String GlobalConfig::localize_path(const String& p_path) const {
if (resource_path=="")
return p_path; //not initialied yet
- if (p_path.begins_with("res://") || p_path.begins_with("user://"))
+ if (p_path.begins_with("res://") || p_path.begins_with("user://") ||
+ (p_path.is_abs_path() && !p_path.begins_with(resource_path)))
return p_path.simplify_path();
@@ -95,21 +96,14 @@ String Globals::localize_path(const String& p_path) const {
}
-void Globals::set_persisting(const String& p_name, bool p_persist) {
+void GlobalConfig::set_initial_value(const String& p_name, const Variant & p_value) {
ERR_FAIL_COND(!props.has(p_name));
- props[p_name].persist=p_persist;
-}
-
-bool Globals::is_persisting(const String& p_name) const {
-
- ERR_FAIL_COND_V(!props.has(p_name),false);
- return props[p_name].persist;
-
+ props[p_name].initial=p_value;
}
-String Globals::globalize_path(const String& p_path) const {
+String GlobalConfig::globalize_path(const String& p_path) const {
if (p_path.begins_with("res://")) {
@@ -124,7 +118,7 @@ String Globals::globalize_path(const String& p_path) const {
}
-bool Globals::_set(const StringName& p_name, const Variant& p_value) {
+bool GlobalConfig::_set(const StringName& p_name, const Variant& p_value) {
_THREAD_SAFE_METHOD_
@@ -168,7 +162,7 @@ bool Globals::_set(const StringName& p_name, const Variant& p_value) {
return true;
}
-bool Globals::_get(const StringName& p_name,Variant &r_ret) const {
+bool GlobalConfig::_get(const StringName& p_name,Variant &r_ret) const {
_THREAD_SAFE_METHOD_
@@ -189,7 +183,7 @@ struct _VCSort {
bool operator<(const _VCSort& p_vcs) const{ return order==p_vcs.order?name<p_vcs.name:order< p_vcs.order; }
};
-void Globals::_get_property_list(List<PropertyInfo> *p_list) const {
+void GlobalConfig::_get_property_list(List<PropertyInfo> *p_list) const {
_THREAD_SAFE_METHOD_
@@ -207,13 +201,9 @@ void Globals::_get_property_list(List<PropertyInfo> *p_list) const {
vc.order=v->order;
vc.type=v->variant.get_type();
if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload"))
- vc.flags=PROPERTY_USAGE_CHECKABLE|PROPERTY_USAGE_STORAGE;
+ vc.flags=PROPERTY_USAGE_STORAGE;
else
- vc.flags=PROPERTY_USAGE_CHECKABLE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_STORAGE;
-
- if (v->persist) {
- vc.flags|=PROPERTY_USAGE_CHECKED;
- }
+ vc.flags=PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_STORAGE;
vclist.insert(vc);
}
@@ -232,7 +222,7 @@ void Globals::_get_property_list(List<PropertyInfo> *p_list) const {
-bool Globals::_load_resource_pack(const String& p_pack) {
+bool GlobalConfig::_load_resource_pack(const String& p_pack) {
if (PackedData::get_singleton()->is_disabled())
return false;
@@ -249,7 +239,7 @@ bool Globals::_load_resource_pack(const String& p_pack) {
return true;
}
-Error Globals::setup(const String& p_path,const String & p_main_pack) {
+Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
//an absolute mess of a function, must be cleaned up and reorganized somehow at some point
@@ -339,7 +329,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
String candidate = d->get_current_dir();
String current_dir = d->get_current_dir();
- String exec_name = OS::get_singleton()->get_executable_path().get_file().basename();
+ String exec_name = OS::get_singleton()->get_executable_path().get_file().get_basename();
bool found = false;
bool first_time=true;
@@ -396,366 +386,20 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
return OK;
}
-bool Globals::has(String p_var) const {
+bool GlobalConfig::has(String p_var) const {
_THREAD_SAFE_METHOD_
return props.has(p_var);
}
-static Vector<String> _decode_params(const String& p_string) {
-
- int begin=p_string.find("(");
- ERR_FAIL_COND_V(begin==-1,Vector<String>());
- begin++;
- int end=p_string.find(")");
- ERR_FAIL_COND_V(end<begin,Vector<String>());
- return p_string.substr(begin,end-begin).split(",");
-}
-
-static String _get_chunk(const String& str,int &pos, int close_pos) {
-
-
- enum {
- MIN_COMMA,
- MIN_COLON,
- MIN_CLOSE,
- MIN_QUOTE,
- MIN_PARENTHESIS,
- MIN_CURLY_OPEN,
- MIN_OPEN
- };
-
- int min_pos=close_pos;
- int min_what=MIN_CLOSE;
-
-#define TEST_MIN(m_how,m_what) \
-{\
-int res = str.find(m_how,pos);\
-if (res!=-1 && res < min_pos) {\
- min_pos=res;\
- min_what=m_what;\
-}\
-}\
-
-
- TEST_MIN(",",MIN_COMMA);
- TEST_MIN("[",MIN_OPEN);
- TEST_MIN("{",MIN_CURLY_OPEN);
- TEST_MIN("(",MIN_PARENTHESIS);
- TEST_MIN("\"",MIN_QUOTE);
-
- int end=min_pos;
-
-
- switch(min_what) {
-
- case MIN_COMMA: {
- } break;
- case MIN_CLOSE: {
- //end because it's done
- } break;
- case MIN_QUOTE: {
- end=str.find("\"",min_pos+1)+1;
- ERR_FAIL_COND_V(end==-1,Variant());
-
- } break;
- case MIN_PARENTHESIS: {
-
- end=str.find(")",min_pos+1)+1;
- ERR_FAIL_COND_V(end==-1,Variant());
-
- } break;
- case MIN_OPEN: {
- int level=1;
- end++;
- while(end<close_pos) {
-
- if (str[end]=='[')
- level++;
- if (str[end]==']') {
- level--;
- if (level==0)
- break;
- }
- end++;
- }
- ERR_FAIL_COND_V(level!=0,Variant());
- end++;
- } break;
- case MIN_CURLY_OPEN: {
- int level=1;
- end++;
- while(end<close_pos) {
-
- if (str[end]=='{')
- level++;
- if (str[end]=='}') {
- level--;
- if (level==0)
- break;
- }
- end++;
- }
- ERR_FAIL_COND_V(level!=0,Variant());
- end++;
- } break;
-
- }
-
- String ret = str.substr(pos,end-pos);
-
- pos=end;
- while(pos<close_pos) {
- if (str[pos]!=',' && str[pos]!=' ' && str[pos]!=':')
- break;
- pos++;
- }
-
- return ret;
-
-}
-
-static Variant _decode_variant(const String& p_string) {
-
-
- String str = p_string.strip_edges();
-
- if (str.nocasecmp_to("true")==0)
- return Variant(true);
- if (str.nocasecmp_to("false")==0)
- return Variant(false);
- if (str.nocasecmp_to("nil")==0)
- return Variant();
- if (str.is_valid_float()) {
- if (str.find(".")==-1)
- return str.to_int();
- else
- return str.to_double();
-
- }
- if (str.begins_with("#")) { //string
- return Color::html(str);
- }
- if (str.begins_with("\"")) { //string
- int end = str.find_last("\"");
- ERR_FAIL_COND_V(end==0,Variant());
- return str.substr(1,end-1).xml_unescape();
-
- }
-
- if (str.begins_with("[")) { //array
-
- int close_pos = str.find_last("]");
- ERR_FAIL_COND_V(close_pos==-1,Variant());
- Array array;
-
- int pos=1;
-
- while(pos<close_pos) {
-
- String s = _get_chunk(str,pos,close_pos);
- array.push_back(_decode_variant(s));
- }
- return array;
-
- }
-
- if (str.begins_with("{")) { //array
-
- int close_pos = str.find_last("}");
- ERR_FAIL_COND_V(close_pos==-1,Variant());
- Dictionary d;
-
- int pos=1;
-
- while(pos<close_pos) {
-
- String key = _get_chunk(str,pos,close_pos);
- String data = _get_chunk(str,pos,close_pos);
- d[_decode_variant(key)]=_decode_variant(data);
- }
- return d;
-
- }
- if (str.begins_with("key")) {
- Vector<String> params = _decode_params(p_string);
- ERR_FAIL_COND_V(params.size()!=1 && params.size()!=2,Variant());
- int scode=0;
-
- if (params[0].is_numeric()) {
- scode=params[0].to_int();
- if (scode<10)
- scode+=KEY_0;
- } else
- scode=find_keycode(params[0]);
-
- InputEvent ie;
- ie.type=InputEvent::KEY;
- ie.key.scancode=scode;
-
- if (params.size()==2) {
- String mods=params[1];
- if (mods.findn("C")!=-1)
- ie.key.mod.control=true;
- if (mods.findn("A")!=-1)
- ie.key.mod.alt=true;
- if (mods.findn("S")!=-1)
- ie.key.mod.shift=true;
- if (mods.findn("M")!=-1)
- ie.key.mod.meta=true;
- }
- return ie;
-
- }
-
- if (str.begins_with("mbutton")) {
- Vector<String> params = _decode_params(p_string);
- ERR_FAIL_COND_V(params.size()!=2,Variant());
-
- InputEvent ie;
- ie.type=InputEvent::MOUSE_BUTTON;
- ie.device=params[0].to_int();
- ie.mouse_button.button_index=params[1].to_int();
-
- return ie;
- }
-
- if (str.begins_with("jbutton")) {
- Vector<String> params = _decode_params(p_string);
- ERR_FAIL_COND_V(params.size()!=2,Variant());
-
- InputEvent ie;
- ie.type=InputEvent::JOYSTICK_BUTTON;
- ie.device=params[0].to_int();
- ie.joy_button.button_index=params[1].to_int();
-
- return ie;
- }
-
- if (str.begins_with("jaxis")) {
- Vector<String> params = _decode_params(p_string);
- ERR_FAIL_COND_V(params.size()!=2,Variant());
-
- InputEvent ie;
- ie.type=InputEvent::JOYSTICK_MOTION;
- ie.device=params[0].to_int();
- int axis = params[1].to_int();;
- ie.joy_motion.axis=axis>>1;
- ie.joy_motion.axis_value=axis&1?1:-1;
-
- return ie;
- }
- if (str.begins_with("img")) {
- Vector<String> params = _decode_params(p_string);
- if (params.size()==0) {
- return Image();
- }
-
- ERR_FAIL_COND_V(params.size()!=5,Image());
-
- String format=params[0].strip_edges();
-
- Image::Format imgformat;
-
- if (format=="grayscale") {
- imgformat=Image::FORMAT_GRAYSCALE;
- } else if (format=="intensity") {
- imgformat=Image::FORMAT_INTENSITY;
- } else if (format=="grayscale_alpha") {
- imgformat=Image::FORMAT_GRAYSCALE_ALPHA;
- } else if (format=="rgb") {
- imgformat=Image::FORMAT_RGB;
- } else if (format=="rgba") {
- imgformat=Image::FORMAT_RGBA;
- } else if (format=="indexed") {
- imgformat=Image::FORMAT_INDEXED;
- } else if (format=="indexed_alpha") {
- imgformat=Image::FORMAT_INDEXED_ALPHA;
- } else if (format=="bc1") {
- imgformat=Image::FORMAT_BC1;
- } else if (format=="bc2") {
- imgformat=Image::FORMAT_BC2;
- } else if (format=="bc3") {
- imgformat=Image::FORMAT_BC3;
- } else if (format=="bc4") {
- imgformat=Image::FORMAT_BC4;
- } else if (format=="bc5") {
- imgformat=Image::FORMAT_BC5;
- } else if (format=="custom") {
- imgformat=Image::FORMAT_CUSTOM;
- } else {
-
- ERR_FAIL_V( Image() );
- }
-
- int mipmaps=params[1].to_int();
- int w=params[2].to_int();
- int h=params[3].to_int();
-
- if (w == 0 && h == 0) {
- //r_v = Image(w, h, imgformat);
- return Image();
- };
-
-
- String data=params[4];
- int datasize=data.length()/2;
- DVector<uint8_t> pixels;
- pixels.resize(datasize);
- DVector<uint8_t>::Write wb = pixels.write();
- const CharType *cptr=data.c_str();
-
- int idx=0;
- uint8_t byte;
- while( idx<datasize*2) {
-
- CharType c=*(cptr++);
-
- ERR_FAIL_COND_V(c=='<',ERR_FILE_CORRUPT);
-
- if ( (c>='0' && c<='9') || (c>='A' && c<='F') || (c>='a' && c<='f') ) {
-
- if (idx&1) {
-
- byte|=HEX2CHR(c);
- wb[idx>>1]=byte;
- } else {
-
- byte=HEX2CHR(c)<<4;
- }
-
- idx++;
- }
-
- }
-
- wb = DVector<uint8_t>::Write();
-
- return Image(w,h,mipmaps,imgformat,pixels);
- }
-
- if (str.find(",")!=-1) { //vector2 or vector3
- Vector<float> farr = str.split_floats(",",true);
- if (farr.size()==2) {
- return Point2(farr[0],farr[1]);
- }
- if (farr.size()==3) {
- return Vector3(farr[0],farr[1],farr[2]);
- }
- ERR_FAIL_V(Variant());
- }
-
-
- return Variant();
-}
-void Globals::set_registering_order(bool p_enable) {
+void GlobalConfig::set_registering_order(bool p_enable) {
registering_order=p_enable;
}
-Error Globals::_load_settings_binary(const String p_path) {
+Error GlobalConfig::_load_settings_binary(const String p_path) {
Error err;
FileAccess *f= FileAccess::open(p_path,FileAccess::READ,&err);
@@ -777,7 +421,7 @@ Error Globals::_load_settings_binary(const String p_path) {
uint32_t count=f->get_32();
- for(int i=0;i<count;i++) {
+ for(uint32_t i=0;i<count;i++) {
uint32_t slen=f->get_32();
CharString cs;
@@ -796,7 +440,7 @@ Error Globals::_load_settings_binary(const String p_path) {
ERR_EXPLAIN("Error decoding property: "+key);
ERR_CONTINUE(err!=OK);
set(key,value);
- set_persisting(key,true);
+
}
set_registering_order(true);
@@ -804,284 +448,85 @@ Error Globals::_load_settings_binary(const String p_path) {
return OK;
}
-Error Globals::_load_settings(const String p_path) {
+Error GlobalConfig::_load_settings(const String p_path) {
+
Error err;
FileAccess *f= FileAccess::open(p_path,FileAccess::READ,&err);
- if (err!=OK) {
-
- return err;
- }
-
-
- String line;
- String section;
- String subpath;
-
- set_registering_order(false);
+ if (!f)
+ return ERR_CANT_OPEN;
- int line_count = 0;
+ VariantParser::StreamFile stream;
+ stream.f=f;
- while(!f->eof_reached()) {
+ String assign;
+ Variant value;
+ VariantParser::Tag next_tag;
- String line = f->get_line().strip_edges();
- line_count++;
+ int lines=0;
+ String error_text;
- if (line=="")
- continue;
-
- // find comments
-
- {
-
- int pos=0;
- while (true) {
- int ret = line.find(";",pos);
- if (ret==-1)
- break;
-
- int qc=0;
- for(int i=0;i<ret;i++) {
-
- if (line[i]=='"')
- qc++;
- }
-
- if ( !(qc&1) ) {
- //not inside string, real comment
- line=line.substr(0,ret);
- break;
-
- }
+ String section;
- pos=ret+1;
+ 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("GlobalConfig::load - "+p_path+":"+itos(lines)+" error: "+error_text);
+ memdelete(f);
+ return err;
}
- if (line.begins_with("[")) {
-
- int end = line.find_last("]");
- ERR_CONTINUE(end!=line.length()-1);
-
- String section=line.substr(1,line.length()-2);
-
- if (section=="global" || section == "")
- subpath="";
- else
- subpath=section+"/";
-
- } else if (line.find("=")!=-1) {
-
-
- int eqpos = line.find("=");
- String var=line.substr(0,eqpos).strip_edges();
- String value=line.substr(eqpos+1,line.length()).strip_edges();
-
- Variant val = _decode_variant(value);
-
- set(subpath+var,val);
- set_persisting(subpath+var,true);
- //props[subpath+var]=VariantContainer(val,last_order++,true);
-
- } else {
-
- if (line.length() > 0) {
- ERR_PRINT(String("Syntax error on line "+itos(line_count)+" of file "+p_path).ascii().get_data());
- };
- };
+ if (assign!=String()) {
+ set(section+"/"+assign,value);
+ } else if (next_tag.name!=String()) {
+ section=next_tag.name;
+ }
}
memdelete(f);
- set_registering_order(true);
-
return OK;
-}
-
-static String _encode_variant(const Variant& p_variant) {
-
- switch(p_variant.get_type()) {
-
- case Variant::BOOL: {
- bool val = p_variant;
- return (val?"true":"false");
- } break;
- case Variant::INT: {
- int val = p_variant;
- return itos(val);
- } break;
- case Variant::REAL: {
- float val = p_variant;
- return rtos(val)+(val==int(val)?".0":"");
- } break;
- case Variant::VECTOR2: {
- Vector2 val = p_variant;
- return String("Vector2(")+rtos(val.x)+String(", ")+rtos(val.y)+String(")");
- } break;
- case Variant::VECTOR3: {
- Vector3 val = p_variant;
- return String("Vector3(")+rtos(val.x)+ String(", ") +rtos(val.y)+ String(", ") +rtos(val.z)+String(")");
- } break;
- case Variant::STRING: {
- String val = p_variant;
- return "\""+val.xml_escape()+"\"";
- } break;
- case Variant::COLOR: {
-
- Color val = p_variant;
- return "#"+val.to_html();
- } break;
- case Variant::STRING_ARRAY:
- case Variant::INT_ARRAY:
- case Variant::REAL_ARRAY:
- case Variant::ARRAY: {
- Array arr = p_variant;
- String str="[";
- for(int i=0;i<arr.size();i++) {
-
- if (i>0)
- str+=", ";
- str+=_encode_variant(arr[i]);
- }
- str+="]";
- return str;
- } break;
- case Variant::DICTIONARY: {
- Dictionary d = p_variant;
- String str="{";
- List<Variant> keys;
- d.get_key_list(&keys);
- for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
-
- if (E!=keys.front())
- str+=", ";
- str+=_encode_variant(E->get());
- str+=":";
- str+=_encode_variant(d[E->get()]);
-
- }
- str+="}";
- return str;
- } break;
- case Variant::IMAGE: {
- String str="img(";
-
- Image img=p_variant;
- if (!img.empty()) {
-
- String format;
- switch(img.get_format()) {
-
- case Image::FORMAT_GRAYSCALE: format="grayscale"; break;
- case Image::FORMAT_INTENSITY: format="intensity"; break;
- case Image::FORMAT_GRAYSCALE_ALPHA: format="grayscale_alpha"; break;
- case Image::FORMAT_RGB: format="rgb"; break;
- case Image::FORMAT_RGBA: format="rgba"; break;
- case Image::FORMAT_INDEXED : format="indexed"; break;
- case Image::FORMAT_INDEXED_ALPHA: format="indexed_alpha"; break;
- case Image::FORMAT_BC1: format="bc1"; break;
- case Image::FORMAT_BC2: format="bc2"; break;
- case Image::FORMAT_BC3: format="bc3"; break;
- case Image::FORMAT_BC4: format="bc4"; break;
- case Image::FORMAT_BC5: format="bc5"; break;
- case Image::FORMAT_CUSTOM: format="custom custom_size="+itos(img.get_data().size())+""; break;
- default: {}
- }
-
- str+=format+", ";
- str+=itos(img.get_mipmaps())+", ";
- str+=itos(img.get_width())+", ";
- str+=itos(img.get_height())+", ";
- DVector<uint8_t> data = img.get_data();
- int ds=data.size();
- DVector<uint8_t>::Read r = data.read();
- for(int i=0;i<ds;i++) {
- uint8_t byte = r[i];
- const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- char bstr[3]={ hex[byte>>4], hex[byte&0xF], 0};
- str+=bstr;
- }
- }
- str+=")";
- return str;
- } break;
- case Variant::INPUT_EVENT: {
-
- InputEvent ev = p_variant;
-
- switch(ev.type) {
-
- case InputEvent::KEY: {
-
- String mods;
- if (ev.key.mod.control)
- mods+="C";
- if (ev.key.mod.shift)
- mods+="S";
- if (ev.key.mod.alt)
- mods+="A";
- if (ev.key.mod.meta)
- mods+="M";
- if (mods!="")
- mods=", "+mods;
-
- return "key("+keycode_get_string(ev.key.scancode)+mods+")";
- } break;
- case InputEvent::MOUSE_BUTTON: {
- return "mbutton("+itos(ev.device)+", "+itos(ev.mouse_button.button_index)+")";
- } break;
- case InputEvent::JOYSTICK_BUTTON: {
-
- return "jbutton("+itos(ev.device)+", "+itos(ev.joy_button.button_index)+")";
- } break;
- case InputEvent::JOYSTICK_MOTION: {
-
- return "jaxis("+itos(ev.device)+", "+itos(ev.joy_motion.axis * 2 + (ev.joy_motion.axis_value<0?0:1))+")";
- } break;
- default: {
-
- return "nil";
- } break;
-
- }
- } break;
- default: {}
- }
-
- return "nil"; //don't know wha to do with this
}
-int Globals::get_order(const String& p_name) const {
+
+int GlobalConfig::get_order(const String& p_name) const {
ERR_FAIL_COND_V(!props.has(p_name),-1);
return props[p_name].order;
}
-void Globals::set_order(const String& p_name, int p_order){
+void GlobalConfig::set_order(const String& p_name, int p_order){
ERR_FAIL_COND(!props.has(p_name));
props[p_name].order=p_order;
}
-void Globals::clear(const String& p_name) {
+void GlobalConfig::clear(const String& p_name) {
ERR_FAIL_COND(!props.has(p_name));
props.erase(p_name);
}
-Error Globals::save() {
+Error GlobalConfig::save() {
return save_custom(get_resource_path()+"/engine.cfg");
}
-Error Globals::_save_settings_binary(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom) {
+Error GlobalConfig::_save_settings_binary(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom) {
Error err;
@@ -1150,7 +595,7 @@ Error Globals::_save_settings_binary(const String& p_file,const Map<String,List<
}
-Error Globals::_save_settings_text(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom) {
+Error GlobalConfig::_save_settings_text(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom) {
Error err;
FileAccess *file = FileAccess::open(p_file,FileAccess::WRITE,&err);
@@ -1178,7 +623,10 @@ Error Globals::_save_settings_text(const String& p_file,const Map<String,List<St
else
value = get(key);
- file->store_string(F->get()+"="+_encode_variant(value)+"\n");
+
+ String vstr;
+ VariantWriter::write_to_string(value,vstr);
+ file->store_string(F->get()+"="+vstr+"\n");
}
}
@@ -1189,12 +637,12 @@ Error Globals::_save_settings_text(const String& p_file,const Map<String,List<St
return OK;
}
-Error Globals::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
+Error GlobalConfig::_save_custom_bnd(const String &p_file) { // add other params as dictionary and array?
return save_custom(p_file);
};
-Error Globals::save_custom(const String& p_path,const CustomMap& p_custom,const Set<String>& p_ignore_masks) {
+Error GlobalConfig::save_custom(const String& p_path,const CustomMap& p_custom,const Set<String>& p_ignore_masks) {
ERR_FAIL_COND_V(p_path=="",ERR_INVALID_PARAMETER);
@@ -1227,8 +675,8 @@ Error Globals::save_custom(const String& p_path,const CustomMap& p_custom,const
vc.name=G->key();//*k;
vc.order=v->order;
vc.type=v->variant.get_type();
- vc.flags=PROPERTY_USAGE_CHECKABLE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_STORAGE;
- if (!v->persist)
+ vc.flags=PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_STORAGE;
+ if (v->variant==v->initial)
continue;
@@ -1322,20 +770,23 @@ Error Globals::save_custom(const String& p_path,const CustomMap& p_custom,const
Variant _GLOBAL_DEF( const String& p_var, const Variant& p_default) {
- if (Globals::get_singleton()->has(p_var))
- return Globals::get_singleton()->get(p_var);
- Globals::get_singleton()->set(p_var,p_default);
+ if (GlobalConfig::get_singleton()->has(p_var)) {
+ GlobalConfig::get_singleton()->set_initial_value(p_var,p_default);
+ return GlobalConfig::get_singleton()->get(p_var);
+ }
+ GlobalConfig::get_singleton()->set(p_var,p_default);
+ GlobalConfig::get_singleton()->set_initial_value(p_var,p_default);
return p_default;
}
-void Globals::add_singleton(const Singleton &p_singleton) {
+void GlobalConfig::add_singleton(const Singleton &p_singleton) {
singletons.push_back(p_singleton);
singleton_ptrs[p_singleton.name]=p_singleton.ptr;
}
-Object* Globals::get_singleton_object(const String& p_name) const {
+Object* GlobalConfig::get_singleton_object(const String& p_name) const {
const Map<StringName,Object*>::Element *E=singleton_ptrs.find(p_name);
@@ -1346,21 +797,21 @@ Object* Globals::get_singleton_object(const String& p_name) const {
};
-bool Globals::has_singleton(const String& p_name) const {
+bool GlobalConfig::has_singleton(const String& p_name) const {
return get_singleton_object(p_name) != NULL;
};
-void Globals::get_singletons(List<Singleton> *p_singletons) {
+void GlobalConfig::get_singletons(List<Singleton> *p_singletons) {
for(List<Singleton>::Element *E=singletons.front();E;E=E->next())
p_singletons->push_back(E->get());
}
-Vector<String> Globals::get_optimizer_presets() const {
+Vector<String> GlobalConfig::get_optimizer_presets() const {
List<PropertyInfo> pi;
- Globals::get_singleton()->get_property_list(&pi);
+ GlobalConfig::get_singleton()->get_property_list(&pi);
Vector<String> names;
for (List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) {
@@ -1376,7 +827,7 @@ Vector<String> Globals::get_optimizer_presets() const {
}
-void Globals::_add_property_info_bind(const Dictionary& p_info) {
+void GlobalConfig::_add_property_info_bind(const Dictionary& p_info) {
ERR_FAIL_COND(!p_info.has("name"));
ERR_FAIL_COND(!p_info.has("type"));
@@ -1395,44 +846,63 @@ void Globals::_add_property_info_bind(const Dictionary& p_info) {
set_custom_property_info(pinfo.name, pinfo);
}
-void Globals::set_custom_property_info(const String& p_prop,const PropertyInfo& p_info) {
+void GlobalConfig::set_custom_property_info(const String& p_prop,const PropertyInfo& p_info) {
ERR_FAIL_COND(!props.has(p_prop));
custom_prop_info[p_prop]=p_info;
+ custom_prop_info[p_prop].name=p_prop;
}
-void Globals::set_disable_platform_override(bool p_disable) {
+void GlobalConfig::set_disable_platform_override(bool p_disable) {
disable_platform_override=p_disable;
}
-bool Globals::is_using_datapack() const {
+bool GlobalConfig::is_using_datapack() const {
return using_datapack;
}
-void Globals::_bind_methods() {
+bool GlobalConfig::property_can_revert(const String& p_name) {
- ObjectTypeDB::bind_method(_MD("has","name"),&Globals::has);
- ObjectTypeDB::bind_method(_MD("set_order","name","pos"),&Globals::set_order);
- ObjectTypeDB::bind_method(_MD("get_order","name"),&Globals::get_order);
- ObjectTypeDB::bind_method(_MD("set_persisting","name","enable"),&Globals::set_persisting);
- ObjectTypeDB::bind_method(_MD("is_persisting","name"),&Globals::is_persisting);
- ObjectTypeDB::bind_method(_MD("add_property_info", "hint"),&Globals::_add_property_info_bind);
- ObjectTypeDB::bind_method(_MD("clear","name"),&Globals::clear);
- ObjectTypeDB::bind_method(_MD("localize_path","path"),&Globals::localize_path);
- ObjectTypeDB::bind_method(_MD("globalize_path","path"),&Globals::globalize_path);
- ObjectTypeDB::bind_method(_MD("save"),&Globals::save);
- ObjectTypeDB::bind_method(_MD("has_singleton","name"),&Globals::has_singleton);
- ObjectTypeDB::bind_method(_MD("get_singleton","name"),&Globals::get_singleton_object);
- ObjectTypeDB::bind_method(_MD("load_resource_pack","pack"),&Globals::_load_resource_pack);
+ if (!props.has(p_name))
+ return false;
+
+ return props[p_name].initial!=props[p_name].variant;
+
+}
+
+Variant GlobalConfig::property_get_revert(const String& p_name) {
+
+ if (!props.has(p_name))
+ return Variant();
+
+ return props[p_name].initial;
+}
- ObjectTypeDB::bind_method(_MD("save_custom","file"),&Globals::_save_custom_bnd);
+void GlobalConfig::_bind_methods() {
+
+ ClassDB::bind_method(_MD("has","name"),&GlobalConfig::has);
+ ClassDB::bind_method(_MD("set_order","name","pos"),&GlobalConfig::set_order);
+ ClassDB::bind_method(_MD("get_order","name"),&GlobalConfig::get_order);
+ ClassDB::bind_method(_MD("set_initial_value","name","value"),&GlobalConfig::set_initial_value);
+ ClassDB::bind_method(_MD("add_property_info", "hint"),&GlobalConfig::_add_property_info_bind);
+ ClassDB::bind_method(_MD("clear","name"),&GlobalConfig::clear);
+ ClassDB::bind_method(_MD("localize_path","path"),&GlobalConfig::localize_path);
+ ClassDB::bind_method(_MD("globalize_path","path"),&GlobalConfig::globalize_path);
+ ClassDB::bind_method(_MD("save"),&GlobalConfig::save);
+ ClassDB::bind_method(_MD("has_singleton","name"),&GlobalConfig::has_singleton);
+ ClassDB::bind_method(_MD("get_singleton","name"),&GlobalConfig::get_singleton_object);
+ ClassDB::bind_method(_MD("load_resource_pack","pack"),&GlobalConfig::_load_resource_pack);
+ ClassDB::bind_method(_MD("property_can_revert","name"),&GlobalConfig::property_can_revert);
+ ClassDB::bind_method(_MD("property_get_revert","name"),&GlobalConfig::property_get_revert);
+
+ ClassDB::bind_method(_MD("save_custom","file"),&GlobalConfig::_save_custom_bnd);
}
-Globals::Globals() {
+GlobalConfig::GlobalConfig() {
singleton=this;
@@ -1445,14 +915,14 @@ Globals::Globals() {
InputEvent key;
key.type=InputEvent::KEY;
InputEvent joyb;
- joyb.type=InputEvent::JOYSTICK_BUTTON;
+ joyb.type=InputEvent::JOYPAD_BUTTON;
- set("application/name","" );
- set("application/main_scene","");
+ GLOBAL_DEF("application/name","" );
+ GLOBAL_DEF("application/main_scene","");
custom_prop_info["application/main_scene"]=PropertyInfo(Variant::STRING,"application/main_scene",PROPERTY_HINT_FILE,"tscn,scn,xscn,xml,res");
- set("application/disable_stdout",false);
- set("application/use_shared_user_dir",true);
+ GLOBAL_DEF("application/disable_stdout",false);
+ GLOBAL_DEF("application/use_shared_user_dir",true);
key.key.scancode=KEY_RETURN;
@@ -1463,7 +933,7 @@ Globals::Globals() {
va.push_back(key);
joyb.joy_button.button_index=JOY_BUTTON_0;
va.push_back(joyb);
- set("input/ui_accept",va);
+ GLOBAL_DEF("input/ui_accept",va);
input_presets.push_back("input/ui_accept");
va=Array();
@@ -1471,7 +941,7 @@ Globals::Globals() {
va.push_back(key);
joyb.joy_button.button_index=JOY_BUTTON_3;
va.push_back(joyb);
- set("input/ui_select",va);
+ GLOBAL_DEF("input/ui_select",va);
input_presets.push_back("input/ui_select");
va=Array();
@@ -1479,20 +949,20 @@ Globals::Globals() {
va.push_back(key);
joyb.joy_button.button_index=JOY_BUTTON_1;
va.push_back(joyb);
- set("input/ui_cancel",va);
+ GLOBAL_DEF("input/ui_cancel",va);
input_presets.push_back("input/ui_cancel");
va=Array();
key.key.scancode=KEY_TAB;
va.push_back(key);
- set("input/ui_focus_next",va);
+ GLOBAL_DEF("input/ui_focus_next",va);
input_presets.push_back("input/ui_focus_next");
va=Array();
key.key.scancode=KEY_TAB;
key.key.mod.shift=true;
va.push_back(key);
- set("input/ui_focus_prev",va);
+ GLOBAL_DEF("input/ui_focus_prev",va);
input_presets.push_back("input/ui_focus_prev");
key.key.mod.shift=false;
@@ -1501,7 +971,7 @@ Globals::Globals() {
va.push_back(key);
joyb.joy_button.button_index=JOY_DPAD_LEFT;
va.push_back(joyb);
- set("input/ui_left",va);
+ GLOBAL_DEF("input/ui_left",va);
input_presets.push_back("input/ui_left");
va=Array();
@@ -1509,7 +979,7 @@ Globals::Globals() {
va.push_back(key);
joyb.joy_button.button_index=JOY_DPAD_RIGHT;
va.push_back(joyb);
- set("input/ui_right",va);
+ GLOBAL_DEF("input/ui_right",va);
input_presets.push_back("input/ui_right");
va=Array();
@@ -1517,7 +987,7 @@ Globals::Globals() {
va.push_back(key);
joyb.joy_button.button_index=JOY_DPAD_UP;
va.push_back(joyb);
- set("input/ui_up",va);
+ GLOBAL_DEF("input/ui_up",va);
input_presets.push_back("input/ui_up");
va=Array();
@@ -1525,36 +995,35 @@ Globals::Globals() {
va.push_back(key);
joyb.joy_button.button_index=JOY_DPAD_DOWN;
va.push_back(joyb);
- set("input/ui_down",va);
+ GLOBAL_DEF("input/ui_down",va);
input_presets.push_back("input/ui_down");
va=Array();
key.key.scancode=KEY_PAGEUP;
va.push_back(key);
- set("input/ui_page_up",va);
+ GLOBAL_DEF("input/ui_page_up",va);
input_presets.push_back("input/ui_page_up");
va=Array();
key.key.scancode=KEY_PAGEDOWN;
va.push_back(key);
- set("input/ui_page_down",va);
+ GLOBAL_DEF("input/ui_page_down",va);
input_presets.push_back("input/ui_page_down");
-// set("display/orientation", "landscape");
+ //GLOBAL_DEF("display/handheld/orientation", "landscape");
- custom_prop_info["display/orientation"]=PropertyInfo(Variant::STRING,"display/orientation",PROPERTY_HINT_ENUM,"landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
- custom_prop_info["render/mipmap_policy"]=PropertyInfo(Variant::INT,"render/mipmap_policy",PROPERTY_HINT_ENUM,"Allow,Allow For Po2,Disallow");
- custom_prop_info["render/thread_model"]=PropertyInfo(Variant::INT,"render/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded");
- custom_prop_info["physics_2d/thread_model"]=PropertyInfo(Variant::INT,"physics_2d/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded");
+ custom_prop_info["display/handheld/orientation"]=PropertyInfo(Variant::STRING,"display/handheld/orientation",PROPERTY_HINT_ENUM,"landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
+ custom_prop_info["rendering/threads/thread_model"]=PropertyInfo(Variant::INT,"rendering/threads/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded");
+ custom_prop_info["physics/2d/thread_model"]=PropertyInfo(Variant::INT,"physics/2d/thread_model",PROPERTY_HINT_ENUM,"Single-Unsafe,Single-Safe,Multi-Threaded");
- set("debug/profiler_max_functions",16384);
+ GLOBAL_DEF("debug/profiler/max_functions",16384);
using_datapack=false;
}
-Globals::~Globals() {
+GlobalConfig::~GlobalConfig() {
singleton=NULL;
}
diff --git a/core/globals.h b/core/globals.h
index 5e0bdb0e54..faf077f2a5 100644
--- a/core/globals.h
+++ b/core/globals.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,9 +37,9 @@
*/
-class Globals : public Object {
+class GlobalConfig : public Object {
- OBJ_TYPE( Globals, Object );
+ GDCLASS( GlobalConfig, Object );
_THREAD_SAFE_CLASS_
public:
@@ -62,6 +62,7 @@ protected:
int order;
bool persist;
Variant variant;
+ Variant initial;
bool hide_from_editor;
bool overrided;
VariantContainer(){ order=0; hide_from_editor=false; persist=false; overrided=false; }
@@ -82,7 +83,7 @@ protected:
bool _get(const StringName& p_name,Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
- static Globals *singleton;
+ static GlobalConfig *singleton;
Error _load_settings(const String p_path);
Error _load_settings_binary(const String p_path);
@@ -109,12 +110,14 @@ public:
String localize_path(const String& p_path) const;
String globalize_path(const String& p_path) const;
- void set_persisting(const String& p_name, bool p_persist);
- bool is_persisting(const String& p_name) const;
+
+ void set_initial_value(const String& p_name, const Variant & p_value);
+ bool property_can_revert(const String& p_name);
+ Variant property_get_revert(const String& p_name);
String get_resource_path() const;
- static Globals *get_singleton();
+ static GlobalConfig *get_singleton();
void clear(const String& p_name);
int get_order(const String& p_name) const;
@@ -144,12 +147,14 @@ public:
void set_registering_order(bool p_registering);
- Globals();
- ~Globals();
+ GlobalConfig();
+ ~GlobalConfig();
};
//not a macro any longer
Variant _GLOBAL_DEF( const String& p_var, const Variant& p_default);
#define GLOBAL_DEF(m_var,m_value) _GLOBAL_DEF(m_var,m_value)
+#define GLOBAL_GET(m_var) GlobalConfig::get_singleton()->get(m_var)
+
#endif
diff --git a/core/hash_map.h b/core/hash_map.h
index e83710c700..0d55206935 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -61,7 +61,7 @@ public:
static _FORCE_INLINE_ uint32_t hash(const uint8_t p_int) { return p_int; }
static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; }
static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar) { return (uint32_t)p_wchar; }
-// static _FORCE_INLINE_ uint32_t hash(const void* p_ptr) { return uint32_t(uint64_t(p_ptr))*(0x9e3779b1L); }
+ //static _FORCE_INLINE_ uint32_t hash(const void* p_ptr) { return uint32_t(uint64_t(p_ptr))*(0x9e3779b1L); }
};
/**
@@ -596,6 +596,20 @@ public:
hash_table_power=0;
}
+ void get_key_value_ptr_array(const Pair **p_pairs) const {
+ if (!hash_table)
+ return;
+ for(int i=0;i<(1<<hash_table_power);i++) {
+
+ Entry *e=hash_table[i];
+ while(e) {
+ *p_pairs=&e->pair;
+ p_pairs++;
+ e=e->next;
+ }
+ }
+ }
+
void get_key_list(List<TKey> *p_keys) const {
if (!hash_table)
return;
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index a917ee5edb..e9e57d8b42 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -74,7 +74,10 @@ static inline uint32_t hash_djb2_one_float(float p_in,uint32_t p_prev=5381) {
float f;
uint32_t i;
} u;
- u.f=p_in;
+
+ // handle -0 case
+ if (p_in==0.0f) u.f=0.0f;
+ else u.f=p_in;
return ((p_prev<<5)+p_prev)+u.i;
}
diff --git a/core/helper/value_evaluator.h b/core/helper/value_evaluator.h
index 461c505ee7..9ea03db4c6 100644
--- a/core/helper/value_evaluator.h
+++ b/core/helper/value_evaluator.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,7 +33,7 @@
class ValueEvaluator : public Object {
- OBJ_TYPE(ValueEvaluator, Object);
+ GDCLASS(ValueEvaluator, Object);
public:
virtual double eval(const String& p_text) {
return p_text.to_double();
diff --git a/core/image.cpp b/core/image.cpp
index 90051d7d0d..d769e6a0b3 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,86 +36,186 @@
const char* Image::format_names[Image::FORMAT_MAX]={
- "Grayscale",
- "Intensity",
- "GrayscaleAlpha",
- "RGB",
- "RGBA",
- "Indexed",
- "IndexedAlpha",
- "YUV422",
- "YUV444",
- "BC1",
- "BC2",
- "BC3",
- "BC4",
- "BC5",
- "PVRTC2",
- "PVRTC2Alpha",
+ "Lum8", //luminance
+ "LumAlpha8", //luminance-alpha
+ "Red8",
+ "RedGreen",
+ "RGB8",
+ "RGBA8",
+ "RGB565", //16 bit
+ "RGBA4444",
+ "RGBA5551",
+ "RFloat", //float
+ "RGFloat",
+ "RGBFloat",
+ "RGBAFloat",
+ "RHalf", //half float
+ "RGHalf",
+ "RGBHalf",
+ "RGBAHalf",
+ "DXT1", //s3tc
+ "DXT3",
+ "DXT5",
+ "ATI1",
+ "ATI2",
+ "BPTC_RGBA",
+ "BPTC_RGBF",
+ "BPTC_RGBFU",
+ "PVRTC2", //pvrtc
+ "PVRTC2A",
"PVRTC4",
- "PVRTC4Alpha",
- "ETC",
- "ATC",
- "ATCAlphaExp",
- "ATCAlphaInterp",
+ "PVRTC4A",
+ "ETC", //etc1
+ "ETC2_R11", //etc2
+ "ETC2_R11S", //signed", NOT srgb.
+ "ETC2_RG11",
+ "ETC2_RG11S",
+ "ETC2_RGB8",
+ "ETC2_RGBA8",
+ "ETC2_RGB8A1",
};
SavePNGFunc Image::save_png_func = NULL;
-void Image::_put_pixel(int p_x,int p_y, const BColor& p_color, unsigned char *p_data) {
- _put_pixelw(p_x,p_y,width,p_color,p_data);
+void Image::_put_pixelb(int p_x,int p_y, uint32_t p_pixelsize,uint8_t *p_dst,const uint8_t *p_src) {
+
+ uint32_t ofs=(p_y*width+p_x)*p_pixelsize;
+
+ for(uint32_t i=0;i<p_pixelsize;i++) {
+ p_dst[ofs+i]=p_src[i];
+ }
}
-void Image::_put_pixelw(int p_x,int p_y, int p_width, const BColor& p_color, unsigned char *p_data) {
+void Image::_get_pixelb(int p_x,int p_y, uint32_t p_pixelsize,const uint8_t *p_src,uint8_t *p_dst) {
+ uint32_t ofs=(p_y*width+p_x)*p_pixelsize;
- int ofs=p_y*p_width+p_x;
+ for(uint32_t i=0;i<p_pixelsize;i++) {
+ p_dst[ofs]=p_src[ofs+i];
+ }
- switch(format) {
- case FORMAT_GRAYSCALE: {
+}
- p_data[ofs]=p_color.gray();
- } break;
- case FORMAT_INTENSITY: {
- p_data[ofs]=p_color.a;
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
+int Image::get_format_pixel_size(Format p_format) {
+
+ switch(p_format) {
+ case FORMAT_L8: return 1; //luminance
+ case FORMAT_LA8: return 2; //luminance-alpha
+ case FORMAT_R8: return 1;
+ case FORMAT_RG8: return 2;
+ case FORMAT_RGB8: return 3;
+ case FORMAT_RGBA8: return 4;
+ case FORMAT_RGB565: return 2; //16 bit
+ case FORMAT_RGBA4444: return 2;
+ case FORMAT_RGBA5551: return 2;
+ case FORMAT_RF: return 4; //float
+ case FORMAT_RGF: return 8;
+ case FORMAT_RGBF: return 12;
+ case FORMAT_RGBAF: return 16;
+ case FORMAT_RH: return 2; //half float
+ case FORMAT_RGH: return 4;
+ case FORMAT_RGBH: return 8;
+ case FORMAT_RGBAH: return 12;
+ case FORMAT_DXT1: return 1; //s3tc bc1
+ case FORMAT_DXT3: return 1; //bc2
+ case FORMAT_DXT5: return 1; //bc3
+ case FORMAT_ATI1: return 1; //bc4
+ case FORMAT_ATI2: return 1; //bc5
+ case FORMAT_BPTC_RGBA: return 1; //btpc bc6h
+ case FORMAT_BPTC_RGBF: return 1; //float /
+ case FORMAT_BPTC_RGBFU: return 1; //unsigned float
+ case FORMAT_PVRTC2: return 1; //pvrtc
+ case FORMAT_PVRTC2A: return 1;
+ case FORMAT_PVRTC4: return 1;
+ case FORMAT_PVRTC4A: return 1;
+ case FORMAT_ETC: return 1; //etc1
+ case FORMAT_ETC2_R11: return 1; //etc2
+ case FORMAT_ETC2_R11S: return 1; //signed: return 1; NOT srgb.
+ case FORMAT_ETC2_RG11: return 1;
+ case FORMAT_ETC2_RG11S: return 1;
+ case FORMAT_ETC2_RGB8: return 1;
+ case FORMAT_ETC2_RGBA8: return 1;
+ case FORMAT_ETC2_RGB8A1: return 1;
+ case FORMAT_MAX: {}
+
- p_data[ofs*2]=p_color.gray();
- p_data[ofs*2+1]=p_color.a;
+ }
+ return 0;
+}
+
+void Image::get_format_min_pixel_size(Format p_format,int &r_w, int &r_h) {
+
+
+ switch(p_format) {
+ case FORMAT_DXT1: //s3tc bc1
+ case FORMAT_DXT3: //bc2
+ case FORMAT_DXT5: //bc3
+ case FORMAT_ATI1: //bc4
+ case FORMAT_ATI2: { //bc5 case case FORMAT_DXT1:
+ r_w=4;
+ r_h=4;
} break;
- case FORMAT_RGB: {
+ case FORMAT_PVRTC2:
+ case FORMAT_PVRTC2A: {
- p_data[ofs*3+0]=p_color.r;
- p_data[ofs*3+1]=p_color.g;
- p_data[ofs*3+2]=p_color.b;
+ r_w=16;
+ r_h=8;
+ } break;
+ case FORMAT_PVRTC4A:
+ case FORMAT_PVRTC4: {
+ r_w=8;
+ r_h=8;
} break;
- case FORMAT_RGBA: {
+ case FORMAT_ETC: {
- p_data[ofs*4+0]=p_color.r;
- p_data[ofs*4+1]=p_color.g;
- p_data[ofs*4+2]=p_color.b;
- p_data[ofs*4+3]=p_color.a;
+ r_w=4;
+ r_h=4;
+ } break;
+ case FORMAT_BPTC_RGBA:
+ case FORMAT_BPTC_RGBF:
+ case FORMAT_BPTC_RGBFU: {
+ r_w=4;
+ r_h=4;
} break;
- case FORMAT_INDEXED:
- case FORMAT_INDEXED_ALPHA: {
+ case FORMAT_ETC2_R11: //etc2
+ case FORMAT_ETC2_R11S: //signed: NOT srgb.
+ case FORMAT_ETC2_RG11:
+ case FORMAT_ETC2_RG11S:
+ case FORMAT_ETC2_RGB8:
+ case FORMAT_ETC2_RGBA8:
+ case FORMAT_ETC2_RGB8A1: {
+
+ r_w=4;
+ r_h=4;
- ERR_FAIL();
} break;
- default: {};
+ default: {
+ r_w=1;
+ r_h=1;
+ } break;
}
}
+int Image::get_format_pixel_rshift(Format p_format) {
+
+ if (p_format==FORMAT_DXT1 || p_format==FORMAT_ATI1 || p_format==FORMAT_PVRTC4 || p_format==FORMAT_PVRTC4A || p_format==FORMAT_ETC || p_format==FORMAT_ETC2_R11 || p_format==FORMAT_ETC2_R11S || p_format==FORMAT_ETC2_RGB8 || p_format==FORMAT_ETC2_RGB8A1)
+ return 1;
+ else if (p_format==FORMAT_PVRTC2 || p_format==FORMAT_PVRTC2A)
+ return 2;
+ else
+ return 0;
+}
+
void Image::_get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width,int &r_height) const {
@@ -126,7 +226,7 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width
int pixel_size = get_format_pixel_size(format);
int pixel_rshift = get_format_pixel_rshift(format);
int minw,minh;
- _get_format_min_data_size(format,minw,minh);
+ get_format_min_pixel_size(format,minw,minh);
for(int i=0;i<p_mipmap;i++) {
int s = w*h;
@@ -173,191 +273,76 @@ void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap,int &r_ofs, int &
}
-void Image::put_pixel(int p_x,int p_y, const Color& p_color,int p_mipmap){
-
- ERR_FAIL_INDEX(p_mipmap,mipmaps+1);
- int ofs,w,h;
- _get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
- ERR_FAIL_INDEX(p_x,w);
- ERR_FAIL_INDEX(p_y,h);
-
- DVector<uint8_t>::Write wp = data.write();
- unsigned char *data_ptr=wp.ptr();
-
- _put_pixelw(p_x,p_y,w,BColor(p_color.r*255,p_color.g*255,p_color.b*255,p_color.a*255),&data_ptr[ofs]);
+int Image::get_width() const {
+ return width;
}
+int Image::get_height() const{
-Image::BColor Image::_get_pixel(int p_x,int p_y,const unsigned char *p_data,int p_data_size) const{
-
- return _get_pixelw(p_x,p_y,width,p_data,p_data_size);
+ return height;
}
-Image::BColor Image::_get_pixelw(int p_x,int p_y,int p_width,const unsigned char *p_data,int p_data_size) const{
- int ofs=p_y*p_width+p_x;
- BColor result(0,0,0,0);
- switch(format) {
-
- case FORMAT_GRAYSCALE: {
-
- result=BColor(p_data[ofs],p_data[ofs],p_data[ofs],255.0);
- } break;
- case FORMAT_INTENSITY: {
-
- result=BColor(255,255,255,p_data[ofs]);
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
-
- result=BColor(p_data[ofs*2],p_data[ofs*2],p_data[ofs*2],p_data[ofs*2+1]);
-
- } break;
- case FORMAT_RGB: {
-
- result=BColor(p_data[ofs*3],p_data[ofs*3+1],p_data[ofs*3+2]);
-
- } break;
- case FORMAT_RGBA: {
-
- result=BColor(p_data[ofs*4],p_data[ofs*4+1],p_data[ofs*4+2],p_data[ofs*4+3]);
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- int pitch = 4;
- const uint8_t* pal = &p_data[ p_data_size - pitch * 256 ];
- int idx = p_data[ofs];
- result=BColor(pal[idx * pitch + 0] , pal[idx * pitch + 1] , pal[idx * pitch + 2] , pal[idx * pitch + 3] );
-
- } break;
- case FORMAT_INDEXED: {
-
- int pitch = 3;
- const uint8_t* pal = &p_data[ p_data_size - pitch * 256 ];
- int idx = p_data[ofs];
- result=BColor(pal[idx * pitch + 0] , pal[idx * pitch + 1] , pal[idx * pitch + 2] ,255);
- } break;
- case FORMAT_YUV_422: {
-
- int y, u, v;
- if (p_x % 2) {
- const uint8_t* yp = &p_data[p_width * 2 * p_y + p_x * 2];
- u = *(yp-1);
- y = yp[0];
- v = yp[1];
- } else {
-
- const uint8_t* yp = &p_data[p_width * 2 * p_y + p_x * 2];
- y = yp[0];
- u = yp[1];
- v = yp[3];
- };
-
- int32_t r = 1.164 * (y - 16) + 1.596 * (v - 128);
- int32_t g = 1.164 * (y - 16) - 0.813 * (v - 128) - 0.391 * (u - 128);
- int32_t b = 1.164 * (y - 16) + 2.018 * (u - 128);
- result = BColor(CLAMP(r, 0, 255), CLAMP(g, 0, 255), CLAMP(b, 0, 255));
- } break;
- case FORMAT_YUV_444: {
-
- uint8_t y, u, v;
- const uint8_t* yp = &p_data[p_width * 3 * p_y + p_x * 3];
- y = yp[0];
- u = yp[1];
- v = yp[2];
-
- int32_t r = 1.164 * (y - 16) + 1.596 * (v - 128);
- int32_t g = 1.164 * (y - 16) - 0.813 * (v - 128) - 0.391 * (u - 128);
- int32_t b = 1.164 * (y - 16) + 2.018 * (u - 128);
- result = BColor(CLAMP(r, 0, 255), CLAMP(g, 0, 255), CLAMP(b, 0, 255));
- } break;
- default:{}
-
- }
-
- return result;
+bool Image::has_mipmaps() const {
+ return mipmaps;
}
-void Image::put_indexed_pixel(int p_x, int p_y, uint8_t p_idx,int p_mipmap) {
-
- ERR_FAIL_COND(format != FORMAT_INDEXED && format != FORMAT_INDEXED_ALPHA);
- ERR_FAIL_INDEX(p_mipmap,mipmaps+1);
- int ofs,w,h;
- _get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
- ERR_FAIL_INDEX(p_x,w);
- ERR_FAIL_INDEX(p_y,h);
-
- data.set(ofs + p_y * w + p_x, p_idx);
-};
-
-uint8_t Image::get_indexed_pixel(int p_x, int p_y,int p_mipmap) const {
+int Image::get_mipmap_count() const {
- ERR_FAIL_COND_V(format != FORMAT_INDEXED && format != FORMAT_INDEXED_ALPHA, 0);
-
- ERR_FAIL_INDEX_V(p_mipmap,mipmaps+1,0);
- int ofs,w,h;
- _get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
- ERR_FAIL_INDEX_V(p_x,w,0);
- ERR_FAIL_INDEX_V(p_y,h,0);
-
-
- return data[ofs + p_y * w + p_x];
-};
-
-void Image::set_pallete(const DVector<uint8_t>& p_data) {
-
-
- int len = p_data.size();
-
- ERR_FAIL_COND(format != FORMAT_INDEXED && format != FORMAT_INDEXED_ALPHA);
- ERR_FAIL_COND(format == FORMAT_INDEXED && len!=(256*3));
- ERR_FAIL_COND(format == FORMAT_INDEXED_ALPHA && len!=(256*4));
-
- int ofs,w,h;
- _get_mipmap_offset_and_size(mipmaps+1,ofs,w,h);
+ if (mipmaps)
+ return get_image_required_mipmaps(width,height,format);
+ else
+ return 0;
+}
- int pal_ofs = ofs;
- data.resize(pal_ofs + p_data.size());
- DVector<uint8_t>::Write wp = data.write();
- unsigned char *dst=wp.ptr() + pal_ofs;
+//using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers
+template<uint32_t read_bytes,bool read_alpha,uint32_t write_bytes,bool write_alpha,bool read_gray,bool write_gray>
+static void _convert( int p_width,int p_height,const uint8_t* p_src,uint8_t* p_dst ){
- DVector<uint8_t>::Read r = p_data.read();
- const unsigned char *src=r.ptr();
- copymem(dst, src, len);
-};
-int Image::get_width() const {
+ for(int y=0;y<p_height;y++) {
+ for(int x=0;x<p_width;x++) {
- return width;
-}
-int Image::get_height() const{
+ const uint8_t *rofs = &p_src[((y*p_width)+x)*(read_bytes+(read_alpha?1:0))];
+ uint8_t *wofs = &p_dst[((y*p_width)+x)*(write_bytes+(write_alpha?1:0))];
- return height;
-}
+ uint8_t rgba[4];
-int Image::get_mipmaps() const {
+ if (read_gray) {
+ rgba[0]=rofs[0];
+ rgba[1]=rofs[0];
+ rgba[2]=rofs[0];
+ } else {
+ for(uint32_t i=0;i<MAX(read_bytes,write_bytes);i++) {
+ rgba[i]=(i<read_bytes)?rofs[i]:0;
+ }
+ }
- return mipmaps;
-}
+ if (read_alpha || write_alpha) {
+ rgba[3]=read_alpha?rofs[read_bytes]:255;
+ }
-Color Image::get_pixel(int p_x,int p_y,int p_mipmap) const {
+ if (write_gray) {
+ //TODO: not correct grayscale, should use fixed point version of actual weights
+ wofs[0]=uint8_t((uint16_t(rofs[0])+uint16_t(rofs[1])+uint16_t(rofs[2]))/3);
+ } else {
+ for(uint32_t i=0;i<write_bytes;i++) {
+ wofs[i]=rgba[i];
+ }
+ }
- ERR_FAIL_INDEX_V(p_mipmap,mipmaps+1,Color());
- int ofs,w,h;
- _get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
- ERR_FAIL_INDEX_V(p_x,w,Color());
- ERR_FAIL_INDEX_V(p_y,h,Color());
+ if (write_alpha) {
+ wofs[write_bytes]=rgba[3];
+ }
+ }
+ }
- int len = data.size();
- DVector<uint8_t>::Read r = data.read();
- const unsigned char*data_ptr=r.ptr();
- BColor c = _get_pixelw(p_x,p_y,w,&data_ptr[ofs],len);
- return Color( c.r/255.0,c.g/255.0,c.b/255.0,c.a/255.0 );
}
void Image::convert( Format p_new_format ){
@@ -368,58 +353,74 @@ void Image::convert( Format p_new_format ){
if (p_new_format==format)
return;
- if (format>=FORMAT_BC1 || p_new_format>=FORMAT_BC1) {
-
- ERR_EXPLAIN("Cannot convert to <-> from compressed/custom image formats (for now).");
- ERR_FAIL();
- }
-
- if (p_new_format==FORMAT_INDEXED || p_new_format==FORMAT_INDEXED_ALPHA) {
+ if (format>=FORMAT_RGB565 || p_new_format>=FORMAT_RGB565) {
- return;
+ ERR_EXPLAIN("Cannot convert to <-> from non byte formats.");
+ ERR_FAIL();
}
Image new_img(width,height,0,p_new_format);
- int len=data.size();
+ //int len=data.size();
- DVector<uint8_t>::Read r = data.read();
- DVector<uint8_t>::Write w = new_img.data.write();
+ PoolVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Write w = new_img.data.write();
const uint8_t *rptr = r.ptr();
uint8_t *wptr = w.ptr();
- if (p_new_format==FORMAT_RGBA && format==FORMAT_INDEXED_ALPHA) {
-
- //optimized unquantized form
- int dataend = len-256*4;
- const uint32_t *palpos = (const uint32_t*)&rptr[dataend];
- uint32_t *dst32 = (uint32_t *)wptr;
+ int conversion_type = format | p_new_format<<8;
+
+ switch(conversion_type) {
+
+ case FORMAT_L8|(FORMAT_LA8<<8): _convert<1,false,1,true,true,true>( width, height,rptr, wptr ); break;
+ case FORMAT_L8|(FORMAT_R8<<8): _convert<1,false,1,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_L8|(FORMAT_RG8<<8): _convert<1,false,2,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_L8|(FORMAT_RGB8<<8): _convert<1,false,3,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_L8|(FORMAT_RGBA8<<8): _convert<1,false,3,true,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_L8<<8): _convert<1,true,1,false,true,true>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_R8<<8): _convert<1,true,1,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_RG8<<8): _convert<1,true,2,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_RGB8<<8): _convert<1,true,3,false,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_LA8|(FORMAT_RGBA8<<8): _convert<1,true,3,true,true,false>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_L8<<8): _convert<1,false,1,false,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_LA8<<8): _convert<1,false,1,true,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_RG8<<8): _convert<1,false,2,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_RGB8<<8): _convert<1,false,3,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_R8|(FORMAT_RGBA8<<8): _convert<1,false,3,true,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_L8<<8): _convert<2,false,1,false,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_LA8<<8): _convert<2,false,1,true,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_R8<<8): _convert<2,false,1,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_RGB8<<8): _convert<2,false,3,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RG8|(FORMAT_RGBA8<<8): _convert<2,false,3,true,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_L8<<8): _convert<3,false,1,false,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_LA8<<8): _convert<3,false,1,true,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_R8<<8): _convert<3,false,1,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_RG8<<8): _convert<3,false,2,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGB8|(FORMAT_RGBA8<<8): _convert<3,false,3,true,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_L8<<8): _convert<3,true,1,false,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_LA8<<8): _convert<3,true,1,true,false,true>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_R8<<8): _convert<3,true,1,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_RG8<<8): _convert<3,true,2,false,false,false>( width, height,rptr, wptr ); break;
+ case FORMAT_RGBA8|(FORMAT_RGB8<<8): _convert<3,true,3,false,false,false>( width, height,rptr, wptr ); break;
- for(int i=0;i<dataend;i++)
- dst32[i]=palpos[rptr[i]]; //since this is read/write, endianness is not a problem
+ }
- } else {
- //this is temporary, must find a faster way to do it.
- for(int i=0;i<width;i++)
- for(int j=0;j<height;j++)
- new_img._put_pixel(i,j,_get_pixel(i,j,rptr,len),wptr);
- }
+ r = PoolVector<uint8_t>::Read();
+ w = PoolVector<uint8_t>::Write();
- r = DVector<uint8_t>::Read();
- w = DVector<uint8_t>::Write();
+ bool gen_mipmaps=mipmaps;
- bool gen_mipmaps=mipmaps>0;
+ //mipmaps=false;
*this=new_img;
if (gen_mipmaps)
generate_mipmaps();
-
}
Image::Format Image::get_format() const{
@@ -460,13 +461,13 @@ static void _scale_cubic(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_wi
int xmax = width - 1;
// temporary pointer
- for ( int y = 0; y < p_dst_height; y++ ) {
+ for ( uint32_t y = 0; y < p_dst_height; y++ ) {
// Y coordinates
oy = (double) y * yfac - 0.5f;
oy1 = (int) oy;
dy = oy - (double) oy1;
- for ( int x = 0; x < p_dst_width; x++ ) {
+ for ( uint32_t x = 0; x < p_dst_width; x++ ) {
// X coordinates
ox = (double) x * xfac - 0.5f;
ox1 = (int) ox;
@@ -650,14 +651,10 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
Image dst( p_width, p_height, 0, format );
- if (format==FORMAT_INDEXED)
- p_interpolation=INTERPOLATE_NEAREST;
-
-
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
const unsigned char*r_ptr=r.ptr();
- DVector<uint8_t>::Write w = dst.data.write();
+ PoolVector<uint8_t>::Write w = dst.data.write();
unsigned char*w_ptr=w.ptr();
@@ -696,8 +693,8 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
}
- r = DVector<uint8_t>::Read();
- w = DVector<uint8_t>::Write();
+ r = PoolVector<uint8_t>::Read();
+ w = PoolVector<uint8_t>::Write();
if (mipmaps>0)
dst.generate_mipmaps();
@@ -722,18 +719,33 @@ void Image::crop( int p_width, int p_height ) {
if (p_width==width && p_height==height)
return;
+ uint8_t pdata[16]; //largest is 16
+ uint32_t pixel_size = get_format_pixel_size(format);
+
Image dst( p_width, p_height,0, format );
+ {
+ PoolVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Write w = dst.data.write();
+
+ for (int y=0;y<p_height;y++) {
+
+ for (int x=0;x<p_width;x++) {
- for (int y=0;y<p_height;y++) {
+ if ((x>=width || y>=height)) {
+ for(uint32_t i=0;i<pixel_size;i++)
+ pdata[i]=0;
+ } else {
+ _get_pixelb(x,y,pixel_size,r.ptr(),pdata);
+ }
- for (int x=0;x<p_width;x++) {
- Color col = (x>=width || y>=height)? Color() : get_pixel(x,y);
- dst.put_pixel(x,y,col);
+ dst._put_pixelb(x,y,pixel_size,w.ptr(),pdata);
+ }
}
}
+
if (mipmaps>0)
dst.generate_mipmaps();
*this=dst;
@@ -754,18 +766,28 @@ void Image::flip_y() {
+ {
+ PoolVector<uint8_t>::Write w = data.write();
+ uint8_t up[16];
+ uint8_t down[16];
+ uint32_t pixel_size = get_format_pixel_size(format);
+
+ for (int y=0;y<height;y++) {
+
+ for (int x=0;x<width;x++) {
- for (int y=0;y<(height/2);y++) {
- for (int x=0;x<width;x++) {
+ _get_pixelb(x,y,pixel_size,w.ptr(),up);
+ _get_pixelb(x,height-y-1,pixel_size,w.ptr(),down);
- Color up = get_pixel(x,y);
- Color down = get_pixel(x,height-y-1);
+ _put_pixelb(x,height-y-1,pixel_size,w.ptr(),up);
+ _put_pixelb(x,y,pixel_size,w.ptr(),down);
- put_pixel(x,y,down);
- put_pixel(x,height-y-1,up);
+ }
}
}
+
+
if (gm)
generate_mipmaps();;
@@ -782,15 +804,25 @@ void Image::flip_x() {
if (gm)
clear_mipmaps();;
- for (int y=0;y<(height/2);y++) {
- for (int x=0;x<width;x++) {
+ {
+ PoolVector<uint8_t>::Write w = data.write();
+ uint8_t up[16];
+ uint8_t down[16];
+ uint32_t pixel_size = get_format_pixel_size(format);
+
+ for (int y=0;y<height;y++) {
+
+ for (int x=0;x<width;x++) {
- Color up = get_pixel(x,y);
- Color down = get_pixel(width-x-1,y);
- put_pixel(x,y,down);
- put_pixel(width-x-1,y,up);
+ _get_pixelb(x,y,pixel_size,w.ptr(),up);
+ _get_pixelb(width-x-1,y,pixel_size,w.ptr(),down);
+
+ _put_pixelb(width-x-1,y,pixel_size,w.ptr(),up);
+ _put_pixelb(x,y,pixel_size,w.ptr(),down);
+
+ }
}
}
@@ -809,15 +841,7 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format,int &r
int pixsize=get_format_pixel_size(p_format);
int pixshift=get_format_pixel_rshift(p_format);
int minw,minh;
- _get_format_min_data_size(p_format,minw,minh);
-
-
- switch(p_format) {
-
- case FORMAT_INDEXED: pixsize=1; size=256*3; break;
- case FORMAT_INDEXED_ALPHA: pixsize=1; size=256*4;break;
- default: {}
- } ;
+ get_format_min_pixel_size(p_format,minw,minh);
while(true) {
@@ -849,20 +873,7 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format,int &r
bool Image::_can_modify(Format p_format) const {
- switch(p_format) {
-
- //these are OK
- case FORMAT_GRAYSCALE:
- case FORMAT_INTENSITY:
- case FORMAT_GRAYSCALE_ALPHA:
- case FORMAT_RGB:
- case FORMAT_RGBA:
- return true;
- default:
- return false;
- }
-
- return false;
+ return p_format<FORMAT_RGB565;
}
template<int CC>
@@ -903,23 +914,23 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
void Image::expand_x2_hq2x() {
- ERR_FAIL_COND(format>=FORMAT_INDEXED);
+ ERR_FAIL_COND(!_can_modify(format));
Format current = format;
- bool mipmaps=get_mipmaps();
- if (mipmaps) {
+ bool mm=has_mipmaps();
+ if (mm) {
clear_mipmaps();
}
- if (current!=FORMAT_RGBA)
- convert(FORMAT_RGBA);
+ if (current!=FORMAT_RGBA8)
+ convert(FORMAT_RGBA8);
- DVector<uint8_t> dest;
+ PoolVector<uint8_t> dest;
dest.resize(width*2*height*2*4);
{
- DVector<uint8_t>::Read r = data.read();
- DVector<uint8_t>::Write w = dest.write();
+ PoolVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Write w = dest.write();
hq2x_resize((const uint32_t*)r.ptr(),width,height,(uint32_t*)w.ptr());
@@ -930,7 +941,7 @@ void Image::expand_x2_hq2x() {
data=dest;
- if (current!=FORMAT_RGBA)
+ if (current!=FORMAT_RGBA8)
convert(current);
if (mipmaps) {
@@ -941,7 +952,6 @@ void Image::expand_x2_hq2x() {
void Image::shrink_x2() {
- ERR_FAIL_COND(format==FORMAT_INDEXED || format==FORMAT_INDEXED_ALPHA);
ERR_FAIL_COND( data.size()==0 );
@@ -949,7 +959,7 @@ void Image::shrink_x2() {
if (mipmaps) {
//just use the lower mipmap as base and copy all
- DVector<uint8_t> new_img;
+ PoolVector<uint8_t> new_img;
int ofs = get_mipmap_offset(1);
@@ -958,36 +968,36 @@ void Image::shrink_x2() {
{
- DVector<uint8_t>::Write w=new_img.write();
- DVector<uint8_t>::Read r=data.read();
+ PoolVector<uint8_t>::Write w=new_img.write();
+ PoolVector<uint8_t>::Read r=data.read();
copymem(w.ptr(),&r[ofs],new_size);
}
- mipmaps--;
width/=2;
height/=2;
data=new_img;
} else {
- DVector<uint8_t> new_img;
+ PoolVector<uint8_t> new_img;
- ERR_FAIL_COND( format>=FORMAT_INDEXED );
+ ERR_FAIL_COND( !_can_modify(format) );
int ps = get_format_pixel_size(format);
new_img.resize((width/2)*(height/2)*ps);
{
- DVector<uint8_t>::Write w=new_img.write();
- DVector<uint8_t>::Read r=data.read();
+ PoolVector<uint8_t>::Write w=new_img.write();
+ PoolVector<uint8_t>::Read r=data.read();
switch(format) {
- case FORMAT_GRAYSCALE:
- case FORMAT_INTENSITY: _generate_po2_mipmap<1>(r.ptr(), w.ptr(), width,height); break;
- case FORMAT_GRAYSCALE_ALPHA: _generate_po2_mipmap<2>(r.ptr(), w.ptr(), width,height); break;
- case FORMAT_RGB: _generate_po2_mipmap<3>(r.ptr(), w.ptr(), width,height); break;
- case FORMAT_RGBA: _generate_po2_mipmap<4>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_L8:
+ case FORMAT_R8: _generate_po2_mipmap<1>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_LA8: _generate_po2_mipmap<2>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RG8: _generate_po2_mipmap<2>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RGB8: _generate_po2_mipmap<3>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RGBA8: _generate_po2_mipmap<4>(r.ptr(), w.ptr(), width,height); break;
default: {}
}
}
@@ -999,7 +1009,7 @@ void Image::shrink_x2() {
}
}
-Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
+Error Image::generate_mipmaps(bool p_keep_existing) {
if (!_can_modify(format)) {
ERR_EXPLAIN("Cannot generate mipmaps in indexed, compressed or custom image formats.");
@@ -1007,15 +1017,17 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
}
+ int mmcount = get_mipmap_count();
+
int from_mm=1;
if (p_keep_existing) {
- from_mm=mipmaps+1;
+ from_mm=mmcount+1;
}
- int size = _get_dst_image_size(width,height,format,mipmaps,p_mipmaps);
+ int size = _get_dst_image_size(width,height,format,mmcount);
data.resize(size);
- DVector<uint8_t>::Write wp=data.write();
+ PoolVector<uint8_t>::Write wp=data.write();
if (nearest_power_of_2(width)==uint32_t(width) && nearest_power_of_2(height)==uint32_t(height)) {
//use fast code for powers of 2
@@ -1023,7 +1035,7 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
int prev_h=height;
int prev_w=width;
- for(int i=1;i<mipmaps;i++) {
+ for(int i=1;i<mmcount;i++) {
int ofs,w,h;
@@ -1033,11 +1045,12 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
switch(format) {
- case FORMAT_GRAYSCALE:
- case FORMAT_INTENSITY: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
- case FORMAT_GRAYSCALE_ALPHA: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
- case FORMAT_RGB: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
- case FORMAT_RGBA: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
+ case FORMAT_L8:
+ case FORMAT_R8: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
+ case FORMAT_LA8:
+ case FORMAT_RG8: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
+ case FORMAT_RGB8: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
+ case FORMAT_RGBA8: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break;
default: {}
}
}
@@ -1056,7 +1069,7 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
int prev_h=height;
int prev_w=width;
- for(int i=1;i<mipmaps;i++) {
+ for(int i=1;i<mmcount;i++) {
int ofs,w,h;
@@ -1066,11 +1079,12 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
switch(format) {
- case FORMAT_GRAYSCALE:
- case FORMAT_INTENSITY: _scale_bilinear<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
- case FORMAT_GRAYSCALE_ALPHA: _scale_bilinear<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
- case FORMAT_RGB: _scale_bilinear<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
- case FORMAT_RGBA: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
+ case FORMAT_L8:
+ case FORMAT_R8: _scale_bilinear<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
+ case FORMAT_LA8:
+ case FORMAT_RG8: _scale_bilinear<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
+ case FORMAT_RGB8:_scale_bilinear<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
+ case FORMAT_RGBA8: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break;
default: {}
}
}
@@ -1083,92 +1097,32 @@ Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
}
-
-
return OK;
}
void Image::clear_mipmaps() {
- if (mipmaps==0)
+ if (!mipmaps)
return;
- if (format==FORMAT_CUSTOM) {
- ERR_EXPLAIN("Cannot clear mipmaps in indexed, compressed or custom image formats.");
- ERR_FAIL();
-
- }
-
if (empty())
return;
int ofs,w,h;
_get_mipmap_offset_and_size(1,ofs,w,h);
- int palsize = get_format_pallete_size(format);
- DVector<uint8_t> pallete;
- ERR_FAIL_COND(ofs+palsize > data.size()); //bug?
- if (palsize) {
-
- pallete.resize(palsize);
- DVector<uint8_t>::Read r = data.read();
- DVector<uint8_t>::Write w = pallete.write();
-
- copymem(&w[0],&r[data.size()-palsize],palsize);
- }
-
- data.resize(ofs+palsize);
+ data.resize(ofs);
- if (palsize) {
-
- DVector<uint8_t>::Read r = pallete.read();
- DVector<uint8_t>::Write w = data.write();
-
- copymem(&w[ofs],&r[0],palsize);
- }
-
- mipmaps=0;
+ mipmaps=false;
}
-void Image::make_normalmap(float p_height_scale) {
-
- if (!_can_modify(format)) {
- ERR_EXPLAIN("Cannot crop in indexed, compressed or custom image formats.");
- ERR_FAIL();
- }
-
- ERR_FAIL_COND( empty() );
-
- Image normalmap(width,height,0, FORMAT_RGB);
- /*
- for (int y=0;y<height;y++) {
- for (int x=0;x<width;x++) {
-
- float center=get_pixel(x,y).gray()/255.0;
- float up=(y>0)?get_pixel(x,y-1).gray()/255.0:center;
- float down=(y<(height-1))?get_pixel(x,y+1).gray()/255.0:center;
- float left=(x>0)?get_pixel(x-1,y).gray()/255.0:center;
- float right=(x<(width-1))?get_pixel(x+1,y).gray()/255.0:center;
-
-
- // uhm, how do i do this? ....
-
- Color result( (uint8_t)((normal.x+1.0)*127.0), (uint8_t)((normal.y+1.0)*127.0), (uint8_t)((normal.z+1.0)*127.0) );
-
- normalmap.put_pixel( x, y, result );
- }
-
- }
- */
- *this=normalmap;
-}
bool Image::empty() const {
return (data.size()==0);
}
-DVector<uint8_t> Image::get_data() const {
+PoolVector<uint8_t> Image::get_data() const {
return data;
}
@@ -1180,38 +1134,36 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format
int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps?-1:0);
data.resize( size );
{
- DVector<uint8_t>::Write w= data.write();
+ PoolVector<uint8_t>::Write w= data.write();
zeromem(w.ptr(),size);
}
width=p_width;
height=p_height;
- mipmaps=mm;
+ mipmaps=p_use_mipmaps;
format=p_format;
}
-void Image::create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data) {
+void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const PoolVector<uint8_t>& p_data) {
ERR_FAIL_INDEX(p_width-1,MAX_WIDTH);
ERR_FAIL_INDEX(p_height-1,MAX_HEIGHT);
- if (p_format < FORMAT_CUSTOM) {
- int mm;
- int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_mipmaps);
+ int mm;
+ int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps);
- if (size!=p_data.size()) {
- ERR_EXPLAIN("Expected data size of "+itos(size)+" in Image::create()");
- ERR_FAIL_COND(p_data.size()!=size);
- }
- };
+ if (size!=p_data.size()) {
+ ERR_EXPLAIN("Expected data size of "+itos(size)+" in Image::create()");
+ ERR_FAIL_COND(p_data.size()!=size);
+ }
height=p_height;
width=p_width;
format=p_format;
data=p_data;
- mipmaps=p_mipmaps;
+ mipmaps=p_use_mipmaps;
}
@@ -1220,7 +1172,7 @@ void Image::create( const char ** p_xpm ) {
int size_width,size_height;
int pixelchars=0;
- mipmaps=0;
+ mipmaps=false;
bool has_alpha=false;
enum Status {
@@ -1235,6 +1187,8 @@ void Image::create( const char ** p_xpm ) {
HashMap<String,Color> colormap;
int colormap_size;
+ uint32_t pixel_size;
+ PoolVector<uint8_t>::Write w;
while (status!=DONE) {
@@ -1286,7 +1240,7 @@ void Image::create( const char ** p_xpm ) {
uint8_t col_r;
uint8_t col_g;
uint8_t col_b;
-// uint8_t col_a=255;
+ //uint8_t col_a=255;
for (int i=0;i<6;i++) {
@@ -1327,7 +1281,9 @@ void Image::create( const char ** p_xpm ) {
if (line==colormap_size) {
status=READING_PIXELS;
- create(size_width,size_height,0,has_alpha?FORMAT_RGBA:FORMAT_RGB);
+ create(size_width,size_height,0,has_alpha?FORMAT_RGBA8:FORMAT_RGB8);
+ w=data.write();
+ pixel_size=has_alpha?4:3;
}
} break;
case READING_PIXELS: {
@@ -1341,7 +1297,11 @@ void Image::create( const char ** p_xpm ) {
Color *colorptr = colormap.getptr(pixelstr);
ERR_FAIL_COND(!colorptr);
- put_pixel(x,y,*colorptr);
+ uint8_t pixel[4];
+ for(uint32_t i=0;i<pixel_size;i++) {
+ pixel[i]=CLAMP((*colorptr)[i]*255,0,255);
+ }
+ _put_pixelb(x,y,pixel_size,w.ptr(),pixel);
}
@@ -1382,9 +1342,8 @@ void Image::create( const char ** p_xpm ) {
bool Image::is_invisible() const {
- if (format==FORMAT_GRAYSCALE ||
- format==FORMAT_RGB ||
- format==FORMAT_INDEXED)
+ if (format==FORMAT_L8 ||
+ format==FORMAT_RGB8 || format==FORMAT_RG8)
return false;
int len = data.size();
@@ -1392,25 +1351,18 @@ bool Image::is_invisible() const {
if (len==0)
return true;
- if (format >= FORMAT_YUV_422 && format <= FORMAT_YUV_444)
- return false;
int w,h;
_get_mipmap_offset_and_size(1,len,w,h);
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
const unsigned char *data_ptr=r.ptr();
bool detected=false;
switch(format) {
- case FORMAT_INTENSITY: {
- for(int i=0;i<len;i++) {
- DETECT_NON_ALPHA(data_ptr[i]);
- }
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
+ case FORMAT_LA8: {
for(int i=0;i<(len>>1);i++) {
@@ -1418,25 +1370,18 @@ bool Image::is_invisible() const {
}
} break;
- case FORMAT_RGBA: {
+ case FORMAT_RGBA8: {
for(int i=0;i<(len>>2);i++) {
DETECT_NON_ALPHA(data_ptr[(i<<2)+3])
}
} break;
- case FORMAT_INDEXED: {
- return false;
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- return false;
- } break;
- case FORMAT_PVRTC2_ALPHA:
- case FORMAT_PVRTC4_ALPHA:
- case FORMAT_BC2:
- case FORMAT_BC3: {
+ case FORMAT_PVRTC2A:
+ case FORMAT_PVRTC4A:
+ case FORMAT_DXT3:
+ case FORMAT_DXT5: {
detected=true;
} break;
default: {}
@@ -1447,36 +1392,24 @@ bool Image::is_invisible() const {
Image::AlphaMode Image::detect_alpha() const {
- if (format==FORMAT_GRAYSCALE ||
- format==FORMAT_RGB ||
- format==FORMAT_INDEXED)
- return ALPHA_NONE;
int len = data.size();
if (len==0)
return ALPHA_NONE;
- if (format >= FORMAT_YUV_422 && format <= FORMAT_YUV_444)
- return ALPHA_NONE;
-
int w,h;
_get_mipmap_offset_and_size(1,len,w,h);
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
const unsigned char *data_ptr=r.ptr();
bool bit=false;
bool detected=false;
switch(format) {
- case FORMAT_INTENSITY: {
- for(int i=0;i<len;i++) {
- DETECT_ALPHA(data_ptr[i]);
- }
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
+ case FORMAT_LA8: {
for(int i=0;i<(len>>1);i++) {
@@ -1484,25 +1417,17 @@ Image::AlphaMode Image::detect_alpha() const {
}
} break;
- case FORMAT_RGBA: {
+ case FORMAT_RGBA8: {
for(int i=0;i<(len>>2);i++) {
DETECT_ALPHA(data_ptr[(i<<2)+3])
}
- } break;
- case FORMAT_INDEXED: {
-
- return ALPHA_NONE;
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- return ALPHA_BLEND;
- } break;
- case FORMAT_PVRTC2_ALPHA:
- case FORMAT_PVRTC4_ALPHA:
- case FORMAT_BC2:
- case FORMAT_BC3: {
+ } break;
+ case FORMAT_PVRTC2A:
+ case FORMAT_PVRTC4A:
+ case FORMAT_DXT3:
+ case FORMAT_DXT5: {
detected=true;
} break;
default: {}
@@ -1528,97 +1453,20 @@ Error Image::save_png(const String& p_path) {
return ERR_UNAVAILABLE;
return save_png_func(p_path, *this);
-};
+}
bool Image::operator==(const Image& p_image) const {
if (data.size() == 0 && p_image.data.size() == 0)
return true;
- DVector<uint8_t>::Read r = data.read();
- DVector<uint8_t>::Read pr = p_image.data.read();
+ PoolVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read pr = p_image.data.read();
return r.ptr() == pr.ptr();
}
-int Image::get_format_pixel_size(Format p_format) {
-
- switch(p_format) {
- case FORMAT_GRAYSCALE: {
-
- return 1;
- } break;
- case FORMAT_INTENSITY: {
-
- return 1;
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
- return 2;
- } break;
- case FORMAT_RGB: {
-
- return 3;
- } break;
- case FORMAT_RGBA: {
-
- return 4;
- } break;
- case FORMAT_INDEXED: {
-
- return 1;
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- return 1;
- } break;
- case FORMAT_BC1:
- case FORMAT_BC2:
- case FORMAT_BC3:
- case FORMAT_BC4:
- case FORMAT_BC5: {
-
- return 1;
- } break;
- case FORMAT_PVRTC2:
- case FORMAT_PVRTC2_ALPHA: {
-
- return 1;
- } break;
- case FORMAT_PVRTC4:
- case FORMAT_PVRTC4_ALPHA: {
-
- return 1;
- } break;
- case FORMAT_ATC:
- case FORMAT_ATC_ALPHA_EXPLICIT:
- case FORMAT_ATC_ALPHA_INTERPOLATED: {
-
- return 1;
- } break;
- case FORMAT_ETC: {
-
- return 1;
- } break;
- case FORMAT_YUV_422: {
- return 2;
- };
- case FORMAT_YUV_444: {
- return 3;
- } break;
- case FORMAT_CUSTOM: {
-
- ERR_EXPLAIN("pixel size requested for custom image format, and it's unknown obviously");
- ERR_FAIL_V(1);
- } break;
- default:{
- ERR_EXPLAIN("Cannot obtain pixel size from this format");
- ERR_FAIL_V(1);
-
- }
- }
- return 0;
-}
int Image::get_image_data_size(int p_width, int p_height, Format p_format,int p_mipmaps) {
@@ -1635,105 +1483,12 @@ int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format
}
-void Image::_get_format_min_data_size(Format p_format,int &r_w, int &r_h) {
-
-
- switch(p_format) {
- case FORMAT_BC1:
- case FORMAT_BC2:
- case FORMAT_BC3:
- case FORMAT_BC4:
- case FORMAT_BC5: {
- r_w=4;
- r_h=4;
- } break;
- case FORMAT_PVRTC2:
- case FORMAT_PVRTC2_ALPHA: {
-
- r_w=16;
- r_h=8;
- } break;
- case FORMAT_PVRTC4_ALPHA:
- case FORMAT_PVRTC4: {
-
- r_w=8;
- r_h=8;
- } break;
- case FORMAT_ATC:
- case FORMAT_ATC_ALPHA_EXPLICIT:
- case FORMAT_ATC_ALPHA_INTERPOLATED: {
-
- r_w=8;
- r_h=8;
-
- } break;
-
- case FORMAT_ETC: {
-
- r_w=4;
- r_h=4;
- } break;
- default: {
- r_w=1;
- r_h=1;
- } break;
- }
-
-}
-
-
-int Image::get_format_pixel_rshift(Format p_format) {
-
- if (p_format==FORMAT_BC1 || p_format==FORMAT_BC4 || p_format==FORMAT_ATC || p_format==FORMAT_PVRTC4 || p_format==FORMAT_PVRTC4_ALPHA || p_format==FORMAT_ETC)
- return 1;
- else if (p_format==FORMAT_PVRTC2 || p_format==FORMAT_PVRTC2_ALPHA)
- return 2;
- else
- return 0;
-}
-
-int Image::get_format_pallete_size(Format p_format) {
-
- switch(p_format) {
- case FORMAT_GRAYSCALE: {
-
- return 0;
- } break;
- case FORMAT_INTENSITY: {
-
- return 0;
- } break;
- case FORMAT_GRAYSCALE_ALPHA: {
-
- return 0;
- } break;
- case FORMAT_RGB: {
-
- return 0;
- } break;
- case FORMAT_RGBA: {
-
- return 0;
- } break;
- case FORMAT_INDEXED: {
-
- return 3*256;
- } break;
- case FORMAT_INDEXED_ALPHA: {
-
- return 4*256;
- } break;
- default:{}
- }
- return 0;
-}
Error Image::_decompress_bc() {
- print_line("decompressing bc");
int wd=width,ht=height;
if (wd%4!=0) {
@@ -1745,13 +1500,13 @@ Error Image::_decompress_bc() {
int mm;
- int size = _get_dst_image_size(wd,ht,FORMAT_RGBA,mm,mipmaps);
+ int size = _get_dst_image_size(wd,ht,FORMAT_RGBA8,mm);
- DVector<uint8_t> newdata;
+ PoolVector<uint8_t> newdata;
newdata.resize(size);
- DVector<uint8_t>::Write w = newdata.write();
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Write w = newdata.write();
+ PoolVector<uint8_t>::Read r = data.read();
int rofs=0;
int wofs=0;
@@ -1762,7 +1517,7 @@ Error Image::_decompress_bc() {
switch(format) {
- case FORMAT_BC1: {
+ case FORMAT_DXT1: {
int len = (wd*ht)/16;
uint8_t* dst=&w[wofs];
@@ -1788,8 +1543,8 @@ Error Image::_decompress_bc() {
col_b|=src[2];
uint8_t table[4][4]={
- { (col_a>>11)<<3, ((col_a>>5)&0x3f)<<2, ((col_a)&0x1f)<<3, 255 },
- { (col_b>>11)<<3, ((col_b>>5)&0x3f)<<2, ((col_b)&0x1f)<<3, 255 },
+ { uint8_t((col_a>>11)<<3), uint8_t(((col_a>>5)&0x3f)<<2),uint8_t(((col_a)&0x1f)<<3), 255 },
+ { uint8_t((col_b>>11)<<3), uint8_t(((col_b>>5)&0x3f)<<2),uint8_t(((col_b)&0x1f)<<3), 255 },
{0,0,0,255},
{0,0,0,255}
};
@@ -1841,7 +1596,7 @@ Error Image::_decompress_bc() {
ht/=2;
} break;
- case FORMAT_BC2: {
+ case FORMAT_DXT3: {
int len = (wd*ht)/16;
uint8_t* dst=&w[wofs];
@@ -1885,8 +1640,9 @@ Error Image::_decompress_bc() {
col_b|=src[8+2];
uint8_t table[4][4]={
- { (col_a>>11)<<3, ((col_a>>5)&0x3f)<<2, ((col_a)&0x1f)<<3, 255 },
- { (col_b>>11)<<3, ((col_b>>5)&0x3f)<<2, ((col_b)&0x1f)<<3, 255 },
+ { uint8_t((col_a>>11)<<3), uint8_t(((col_a>>5)&0x3f)<<2),uint8_t(((col_a)&0x1f)<<3), 255 },
+ { uint8_t((col_b>>11)<<3), uint8_t(((col_b>>5)&0x3f)<<2),uint8_t(((col_b)&0x1f)<<3), 255 },
+
{0,0,0,255},
{0,0,0,255}
};
@@ -1933,7 +1689,7 @@ Error Image::_decompress_bc() {
ht/=2;
} break;
- case FORMAT_BC3: {
+ case FORMAT_DXT5: {
int len = (wd*ht)/16;
uint8_t* dst=&w[wofs];
@@ -2001,9 +1757,10 @@ Error Image::_decompress_bc() {
col_b<<=8;
col_b|=src[8+2];
- uint8_t table[4][4]={
- { (col_a>>11)<<3, ((col_a>>5)&0x3f)<<2, ((col_a)&0x1f)<<3, 255 },
- { (col_b>>11)<<3, ((col_b>>5)&0x3f)<<2, ((col_b)&0x1f)<<3, 255 },
+ uint8_t table[4][4]={
+ { uint8_t((col_a>>11)<<3), uint8_t(((col_a>>5)&0x3f)<<2),uint8_t(((col_a)&0x1f)<<3), 255 },
+ { uint8_t((col_b>>11)<<3), uint8_t(((col_b>>5)&0x3f)<<2),uint8_t(((col_b)&0x1f)<<3), 255 },
+
{0,0,0,255},
{0,0,0,255}
};
@@ -2057,22 +1814,23 @@ Error Image::_decompress_bc() {
}
- w=DVector<uint8_t>::Write();
- r=DVector<uint8_t>::Read();
+ w=PoolVector<uint8_t>::Write();
+ r=PoolVector<uint8_t>::Read();
data=newdata;
- format=FORMAT_RGBA;
+ format=FORMAT_RGBA8;
if (wd!=width || ht!=height) {
- //todo, crop
- width=wd;
- height=ht;
+
+ SWAP(width,wd);
+ SWAP(height,ht);
+ crop(wd,ht);
}
return OK;
}
bool Image::is_compressed() const {
- return format>=FORMAT_BC1;
+ return format>=FORMAT_RGB565;
}
@@ -2085,12 +1843,14 @@ Image Image::decompressed() const {
Error Image::decompress() {
- if (format>=FORMAT_BC1 && format<=FORMAT_BC5 )
+ if (format>=FORMAT_DXT1 && format<=FORMAT_ATI2 )
_decompress_bc();//_image_decompress_bc(this);
- else if (format>=FORMAT_PVRTC2 && format<=FORMAT_PVRTC4_ALPHA && _image_decompress_pvrtc)
+ else if (format>=FORMAT_PVRTC2 && format<=FORMAT_PVRTC4A&& _image_decompress_pvrtc)
_image_decompress_pvrtc(this);
else if (format==FORMAT_ETC && _image_decompress_etc)
_image_decompress_etc(this);
+ else if (format>=FORMAT_ETC2_R11 && format<=FORMAT_ETC2_RGB8A1 && _image_decompress_etc)
+ _image_decompress_etc2(this);
else
return ERR_UNAVAILABLE;
return OK;
@@ -2101,7 +1861,12 @@ Error Image::compress(CompressMode p_mode) {
switch(p_mode) {
- case COMPRESS_BC: {
+ case COMPRESS_16BIT: {
+
+ //ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
+ //_image_compress_bc_func(this);
+ } break;
+ case COMPRESS_S3TC: {
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
_image_compress_bc_func(this);
@@ -2121,6 +1886,11 @@ Error Image::compress(CompressMode p_mode) {
ERR_FAIL_COND_V(!_image_compress_etc_func, ERR_UNAVAILABLE);
_image_compress_etc_func(this);
} break;
+ case COMPRESS_ETC2: {
+
+ ERR_FAIL_COND_V(!_image_compress_etc_func, ERR_UNAVAILABLE);
+ _image_compress_etc_func(this);
+ } break;
}
@@ -2133,14 +1903,14 @@ Image Image::compressed(int p_mode) {
ret.compress((Image::CompressMode)p_mode);
return ret;
-};
+}
Image::Image(const char **p_xpm) {
width=0;
height=0;
- mipmaps=0;
- format=FORMAT_GRAYSCALE;
+ mipmaps=false;
+ format=FORMAT_L8;
create(p_xpm);
}
@@ -2150,37 +1920,28 @@ Image::Image(int p_width, int p_height,bool p_use_mipmaps, Format p_format) {
width=0;
height=0;
- mipmaps=0;
- format=FORMAT_GRAYSCALE;
+ mipmaps=p_use_mipmaps;
+ format=FORMAT_L8;
create(p_width,p_height,p_use_mipmaps,p_format);
}
-Image::Image(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data) {
+Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const PoolVector<uint8_t>& p_data) {
width=0;
height=0;
- mipmaps=0;
- format=FORMAT_GRAYSCALE;
+ mipmaps=p_mipmaps;
+ format=FORMAT_L8;
create(p_width,p_height,p_mipmaps,p_format,p_data);
}
-Image Image::brushed(const Image& p_src, const Image& p_brush, const Point2& p_dest) const {
-
- Image img = *this;
- img.brush_transfer(p_src,p_brush,p_dest);
- return img;
-}
-
Rect2 Image::get_used_rect() const {
- if (format==FORMAT_GRAYSCALE ||
- format==FORMAT_RGB ||
- format==FORMAT_INDEXED || format>FORMAT_INDEXED_ALPHA)
+ if (format!=FORMAT_LA8 && format!=FORMAT_RGBA8)
return Rect2(Point2(),Size2(width,height));
int len = data.size();
@@ -2188,16 +1949,18 @@ Rect2 Image::get_used_rect() const {
if (len==0)
return Rect2();
- int data_size = len;
- DVector<uint8_t>::Read r = data.read();
+ //int data_size = len;
+ PoolVector<uint8_t>::Read r = data.read();
const unsigned char *rptr=r.ptr();
+ int ps = format==FORMAT_LA8?2:4;
int minx=0xFFFFFF,miny=0xFFFFFFF;
int maxx=-1,maxy=-1;
- for(int i=0;i<width;i++) {
- for(int j=0;j<height;j++) {
+ for(int j=0;j<height;j++) {
+ for(int i=0;i<width;i++) {
+
- bool opaque = _get_pixel(i,j,rptr,data_size).a>2;
+ bool opaque = rptr[(j*width+i)*ps+(ps-1)]>2;
if (!opaque)
continue;
if (i>maxx)
@@ -2225,101 +1988,47 @@ Image Image::get_rect(const Rect2& p_area) const {
img.blit_rect(*this, p_area, Point2(0, 0));
return img;
-};
-
-void Image::brush_transfer(const Image& p_src, const Image& p_brush, const Point2& p_dest) {
-
-
- ERR_FAIL_COND( width != p_src.width || height !=p_src.height);
-
- int dst_data_size = data.size();
- DVector<uint8_t>::Write wp = data.write();
- unsigned char *dst_data_ptr=wp.ptr();
-
-
- int src_data_size = p_src.data.size();
- DVector<uint8_t>::Read rp = p_src.data.read();
- const unsigned char *src_data_ptr=rp.ptr();
-
- int brush_data_size = p_brush.data.size();
- DVector<uint8_t>::Read bp = p_brush.data.read();
- const unsigned char *src_brush_ptr=bp.ptr();
-
- int bw = p_brush.get_width();
- int bh = p_brush.get_height();
- int dx=p_dest.x;
- int dy=p_dest.y;
-
- for(int i=dy;i<dy+bh;i++) {
-
- if (i<0 || i >= height)
- continue;
- for(int j=dx;j<dx+bw;j++) {
-
- if (j<0 || j>=width)
- continue;
-
- BColor src = p_src._get_pixel(j,i,src_data_ptr,src_data_size);
- BColor dst = _get_pixel(j,i,dst_data_ptr,dst_data_size);
- BColor brush = p_brush._get_pixel(j-dx,i-dy,src_brush_ptr,brush_data_size);
- uint32_t mult = brush.r;
- dst.r = dst.r + (((int32_t(src.r)-int32_t(dst.r))*mult)>>8);
- dst.g = dst.g + (((int32_t(src.g)-int32_t(dst.g))*mult)>>8);
- dst.b = dst.b + (((int32_t(src.b)-int32_t(dst.b))*mult)>>8);
- dst.a = dst.a + (((int32_t(src.a)-int32_t(dst.a))*mult)>>8);
- _put_pixel(j,i,dst,dst_data_ptr);
- }
- }
}
-
void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& p_dest) {
int dsize=data.size();
int srcdsize=p_src.data.size();
ERR_FAIL_COND( dsize==0 );
ERR_FAIL_COND( srcdsize==0 );
+ ERR_FAIL_COND( format!=p_src.format );
+ Rect2i local_src_rect = Rect2i(0,0,width,height).clip( Rect2i(p_dest+p_src_rect.pos,p_src_rect.size) );
- Rect2 rrect = Rect2(0,0,p_src.width,p_src.height).clip(p_src_rect);
+ if (local_src_rect.size.x<=0 || local_src_rect.size.y<=0)
+ return;
+ Rect2i src_rect( p_src_rect.pos + ( local_src_rect.pos - p_dest), local_src_rect.size );
- DVector<uint8_t>::Write wp = data.write();
- unsigned char *dst_data_ptr=wp.ptr();
+ PoolVector<uint8_t>::Write wp = data.write();
+ uint8_t *dst_data_ptr=wp.ptr();
- DVector<uint8_t>::Read rp = p_src.data.read();
- const unsigned char *src_data_ptr=rp.ptr();
+ PoolVector<uint8_t>::Read rp = p_src.data.read();
+ const uint8_t *src_data_ptr=rp.ptr();
- if ((format==FORMAT_INDEXED || format == FORMAT_INDEXED_ALPHA) && (p_src.format==FORMAT_INDEXED || p_src.format == FORMAT_INDEXED_ALPHA)) {
+ int pixel_size=get_format_pixel_size(format);
- Point2i desti(p_dest.x, p_dest.y);
- Point2i srci(rrect.pos.x, rrect.pos.y);
+ for(int i=0;i<src_rect.size.y;i++) {
- for(int i=0;i<rrect.size.y;i++) {
- if (i<0 || i >= height)
- continue;
- for(int j=0;j<rrect.size.x;j++) {
+ for(int j=0;j<src_rect.size.x;j++) {
- if (j<0 || j>=width)
- continue;
+ int src_x = src_rect.pos.x+j;
+ int src_y = src_rect.pos.y+i;
- dst_data_ptr[width * (desti.y + i) + desti.x + j] = src_data_ptr[p_src.width * (srci.y+i) + srci.x+j];
- }
- }
+ int dst_x = local_src_rect.pos.x+j;
+ int dst_y = local_src_rect.pos.y+i;
- } else {
-
- for(int i=0;i<rrect.size.y;i++) {
-
- if (i<0 || i >= height)
- continue;
- for(int j=0;j<rrect.size.x;j++) {
-
- if (j<0 || j>=width)
- continue;
+ const uint8_t *src = &src_data_ptr[ (src_y*p_src.width+src_x)*pixel_size];
+ uint8_t *dst = &dst_data_ptr[ (dst_y*width+dst_x)*pixel_size];
- _put_pixel(p_dest.x+j,p_dest.y+i,p_src._get_pixel(rrect.pos.x+j,rrect.pos.y+i,src_data_ptr,srcdsize),dst_data_ptr);
+ for(int k=0;k<pixel_size;k++) {
+ dst[k]=src[k];
}
}
}
@@ -2334,14 +2043,16 @@ void (*Image::_image_compress_bc_func)(Image *)=NULL;
void (*Image::_image_compress_pvrtc2_func)(Image *)=NULL;
void (*Image::_image_compress_pvrtc4_func)(Image *)=NULL;
void (*Image::_image_compress_etc_func)(Image *)=NULL;
+void (*Image::_image_compress_etc2_func)(Image *)=NULL;
void (*Image::_image_decompress_pvrtc)(Image *)=NULL;
void (*Image::_image_decompress_bc)(Image *)=NULL;
void (*Image::_image_decompress_etc)(Image *)=NULL;
+void (*Image::_image_decompress_etc2)(Image *)=NULL;
-DVector<uint8_t> (*Image::lossy_packer)(const Image& ,float )=NULL;
-Image (*Image::lossy_unpacker)(const DVector<uint8_t>& )=NULL;
-DVector<uint8_t> (*Image::lossless_packer)(const Image& )=NULL;
-Image (*Image::lossless_unpacker)(const DVector<uint8_t>& )=NULL;
+PoolVector<uint8_t> (*Image::lossy_packer)(const Image& ,float )=NULL;
+Image (*Image::lossy_unpacker)(const PoolVector<uint8_t>& )=NULL;
+PoolVector<uint8_t> (*Image::lossless_packer)(const Image& )=NULL;
+Image (*Image::lossless_unpacker)(const PoolVector<uint8_t>& )=NULL;
void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) {
@@ -2352,11 +2063,11 @@ void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) {
void Image::normalmap_to_xy() {
- convert(Image::FORMAT_RGBA);
+ convert(Image::FORMAT_RGBA8);
{
int len = data.size()/4;
- DVector<uint8_t>::Write wp = data.write();
+ PoolVector<uint8_t>::Write wp = data.write();
unsigned char *data_ptr=wp.ptr();
for(int i=0;i<len;i++) {
@@ -2367,7 +2078,7 @@ void Image::normalmap_to_xy() {
}
}
- convert(Image::FORMAT_GRAYSCALE_ALPHA);
+ convert(Image::FORMAT_LA8);
}
void Image::srgb_to_linear() {
@@ -2378,12 +2089,12 @@ void Image::srgb_to_linear() {
static const uint8_t srgb2lin[256]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153, 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248, 250, 252};
- ERR_FAIL_COND( format!=FORMAT_RGB && format!=FORMAT_RGBA );
+ ERR_FAIL_COND( format!=FORMAT_RGB8 && format!=FORMAT_RGBA8 );
- if (format==FORMAT_RGBA) {
+ if (format==FORMAT_RGBA8) {
int len = data.size()/4;
- DVector<uint8_t>::Write wp = data.write();
+ PoolVector<uint8_t>::Write wp = data.write();
unsigned char *data_ptr=wp.ptr();
for(int i=0;i<len;i++) {
@@ -2393,10 +2104,10 @@ void Image::srgb_to_linear() {
data_ptr[(i<<2)+2]=srgb2lin[ data_ptr[(i<<2)+2] ];
}
- } else if (format==FORMAT_RGB) {
+ } else if (format==FORMAT_RGB8) {
int len = data.size()/3;
- DVector<uint8_t>::Write wp = data.write();
+ PoolVector<uint8_t>::Write wp = data.write();
unsigned char *data_ptr=wp.ptr();
for(int i=0;i<len;i++) {
@@ -2414,21 +2125,21 @@ void Image::premultiply_alpha() {
if (data.size()==0)
return;
- if (format!=FORMAT_RGBA)
+ if (format!=FORMAT_RGBA8)
return; //not needed
- DVector<uint8_t>::Write wp = data.write();
+ PoolVector<uint8_t>::Write wp = data.write();
unsigned char *data_ptr=wp.ptr();
for(int i=0;i<height;i++) {
for(int j=0;j<width;j++) {
- BColor bc = _get_pixel(j,i,data_ptr,0);
- bc.r=(int(bc.r)*int(bc.a))>>8;
- bc.g=(int(bc.g)*int(bc.a))>>8;
- bc.b=(int(bc.b)*int(bc.a))>>8;
- _put_pixel(j,i,bc,data_ptr);
+ uint8_t *ptr = &data_ptr[(i*width+j)*4];
+
+ ptr[0]=(uint16_t(ptr[0])*uint16_t(ptr[3]))>>8;
+ ptr[1]=(uint16_t(ptr[1])*uint16_t(ptr[3]))>>8;
+ ptr[2]=(uint16_t(ptr[2])*uint16_t(ptr[3]))>>8;
}
}
}
@@ -2438,14 +2149,14 @@ void Image::fix_alpha_edges() {
if (data.size()==0)
return;
- if (format!=FORMAT_RGBA)
+ if (format!=FORMAT_RGBA8)
return; //not needed
- DVector<uint8_t> dcopy = data;
- DVector<uint8_t>::Read rp = data.read();
- const uint8_t *rptr=rp.ptr();
+ PoolVector<uint8_t> dcopy = data;
+ PoolVector<uint8_t>::Read rp = data.read();
+ const uint8_t *srcptr=rp.ptr();
- DVector<uint8_t>::Write wp = data.write();
+ PoolVector<uint8_t>::Write wp = data.write();
unsigned char *data_ptr=wp.ptr();
const int max_radius=4;
@@ -2455,13 +2166,16 @@ void Image::fix_alpha_edges() {
for(int i=0;i<height;i++) {
for(int j=0;j<width;j++) {
- BColor bc = _get_pixel(j,i,rptr,0);
- if (bc.a>=alpha_treshold)
+ const uint8_t *rptr = &srcptr[(i*width+j)*4];
+ uint8_t *wptr = &data_ptr[(i*width+j)*4];
+
+ if (rptr[3]>=alpha_treshold)
continue;
int closest_dist=max_dist;
- BColor closest_color;
- closest_color.a=bc.a;
+ uint8_t closest_color[3];
+
+
int from_x = MAX(0,j-max_radius);
int to_x = MIN(width-1,j+max_radius);
int from_y = MAX(0,i-max_radius);
@@ -2476,22 +2190,25 @@ void Image::fix_alpha_edges() {
if (dist>=closest_dist)
continue;
- const uint8_t * rp = &rptr[(k*width+l)<<2];
+ const uint8_t * rp = &srcptr[(k*width+l)<<2];
if (rp[3]<alpha_treshold)
continue;
- closest_dist=dist;
- closest_color.r=rp[0];
- closest_color.g=rp[1];
- closest_color.b=rp[2];
+ closest_color[0]=rp[0];
+ closest_color[1]=rp[1];
+ closest_color[2]=rp[2];
}
}
- if (closest_dist!=max_dist)
- _put_pixel(j,i,closest_color,data_ptr);
+ if (closest_dist!=max_dist) {
+
+ wptr[0]=closest_color[0];
+ wptr[1]=closest_color[1];
+ wptr[2]=closest_color[2];
+ }
}
}
@@ -2508,8 +2225,8 @@ Image::Image(const uint8_t* p_mem_png_jpg, int p_len) {
width=0;
height=0;
- mipmaps=0;
- format=FORMAT_GRAYSCALE;
+ mipmaps=false;
+ format=FORMAT_L8;
if (_png_mem_loader_func) {
*this = _png_mem_loader_func(p_mem_png_jpg,p_len);
@@ -2525,8 +2242,8 @@ Image::Image() {
width=0;
height=0;
- mipmaps=0;
- format = FORMAT_GRAYSCALE;
+ mipmaps=false;
+ format = FORMAT_L8;
}
Image::~Image() {
diff --git a/core/image.h b/core/image.h
index 0f0b345eb9..620160147b 100644
--- a/core/image.h
+++ b/core/image.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -55,35 +55,44 @@ public:
static SavePNGFunc save_png_func;
enum Format {
- FORMAT_GRAYSCALE, ///< one byte per pixel, 0-255
- FORMAT_INTENSITY, ///< one byte per pixel, 0-255
- FORMAT_GRAYSCALE_ALPHA, ///< two bytes per pixel, 0-255. alpha 0-255
- FORMAT_RGB, ///< one byte R, one byte G, one byte B
- FORMAT_RGBA, ///< one byte R, one byte G, one byte B, one byte A
- FORMAT_INDEXED, ///< index byte 0-256, and after image end, 256*3 bytes of palette
- FORMAT_INDEXED_ALPHA, ///< index byte 0-256, and after image end, 256*4 bytes of palette (alpha)
- FORMAT_YUV_422,
- FORMAT_YUV_444,
- FORMAT_BC1, // DXT1
- FORMAT_BC2, // DXT3
- FORMAT_BC3, // DXT5
- FORMAT_BC4, // ATI1
- FORMAT_BC5, // ATI2
- FORMAT_PVRTC2,
- FORMAT_PVRTC2_ALPHA,
- FORMAT_PVRTC4,
- FORMAT_PVRTC4_ALPHA,
- FORMAT_ETC, // regular ETC, no transparency
- FORMAT_ATC,
- FORMAT_ATC_ALPHA_EXPLICIT,
- FORMAT_ATC_ALPHA_INTERPOLATED,
- /*FORMAT_ETC2_R, for the future..
- FORMAT_ETC2_RG,
- FORMAT_ETC2_RGB,
- FORMAT_ETC2_RGBA1,
- FORMAT_ETC2_RGBA,*/
- FORMAT_CUSTOM,
+ FORMAT_L8, //luminance
+ FORMAT_LA8, //luminance-alpha
+ FORMAT_R8,
+ FORMAT_RG8,
+ FORMAT_RGB8,
+ FORMAT_RGBA8,
+ FORMAT_RGB565, //16 bit
+ FORMAT_RGBA4444,
+ FORMAT_RGBA5551,
+ FORMAT_RF, //float
+ FORMAT_RGF,
+ FORMAT_RGBF,
+ FORMAT_RGBAF,
+ FORMAT_RH, //half float
+ FORMAT_RGH,
+ FORMAT_RGBH,
+ FORMAT_RGBAH,
+ FORMAT_DXT1, //s3tc bc1
+ FORMAT_DXT3, //bc2
+ FORMAT_DXT5, //bc3
+ FORMAT_ATI1, //bc4
+ FORMAT_ATI2, //bc5
+ FORMAT_BPTC_RGBA, //btpc bc6h
+ FORMAT_BPTC_RGBF, //float /
+ FORMAT_BPTC_RGBFU, //unsigned float
+ FORMAT_PVRTC2, //pvrtc
+ FORMAT_PVRTC2A,
+ FORMAT_PVRTC4,
+ FORMAT_PVRTC4A,
+ FORMAT_ETC, //etc1
+ FORMAT_ETC2_R11, //etc2
+ FORMAT_ETC2_R11S, //signed, NOT srgb.
+ FORMAT_ETC2_RG11,
+ FORMAT_ETC2_RG11S,
+ FORMAT_ETC2_RGB8,
+ FORMAT_ETC2_RGBA8,
+ FORMAT_ETC2_RGB8A1,
FORMAT_MAX
};
@@ -96,110 +105,43 @@ public:
/* INTERPOLATE GAUSS */
};
+ //some functions provided by something else
+
static Image (*_png_mem_loader_func)(const uint8_t* p_png,int p_size);
static Image (*_jpg_mem_loader_func)(const uint8_t* p_png,int p_size);
+
static void (*_image_compress_bc_func)(Image *);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
static void (*_image_compress_etc_func)(Image *);
+ static void (*_image_compress_etc2_func)(Image *);
+
static void (*_image_decompress_pvrtc)(Image *);
static void (*_image_decompress_bc)(Image *);
static void (*_image_decompress_etc)(Image *);
+ static void (*_image_decompress_etc2)(Image *);
Error _decompress_bc();
- static DVector<uint8_t> (*lossy_packer)(const Image& p_image,float p_quality);
- static Image (*lossy_unpacker)(const DVector<uint8_t>& p_buffer);
- static DVector<uint8_t> (*lossless_packer)(const Image& p_image);
- static Image (*lossless_unpacker)(const DVector<uint8_t>& p_buffer);
+ static PoolVector<uint8_t> (*lossy_packer)(const Image& p_image,float p_quality);
+ static Image (*lossy_unpacker)(const PoolVector<uint8_t>& p_buffer);
+ static PoolVector<uint8_t> (*lossless_packer)(const Image& p_image);
+ static Image (*lossless_unpacker)(const PoolVector<uint8_t>& p_buffer);
private:
- //internal byte based color
- struct BColor {
- union {
- uint8_t col[4];
- struct {
- uint8_t r,g,b,a;
- };
- };
-
- bool operator==(const BColor& p_color) const { for(int i=0;i<4;i++) {if (col[i]!=p_color.col[i]) return false; } return true; }
- _FORCE_INLINE_ uint8_t gray() const { return (uint16_t(col[0])+uint16_t(col[1])+uint16_t(col[2]))/3; }
- _FORCE_INLINE_ BColor() {}
- BColor(uint8_t p_r,uint8_t p_g,uint8_t p_b,uint8_t p_a=255) { col[0]=p_r; col[1]=p_g; col[2]=p_b; col[3]=p_a; }
- };
-
- //median cut classes
-
- struct BColorPos {
-
- uint32_t index;
- BColor color;
- struct SortR {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.r < cb.color.r; }
- };
-
- struct SortG {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.g < cb.color.g; }
- };
-
- struct SortB {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.b < cb.color.b; }
- };
-
- struct SortA {
-
- bool operator()(const BColorPos& ca, const BColorPos& cb) const { return ca.color.a < cb.color.a; }
- };
- };
-
- struct SPTree {
-
- bool leaf;
- uint8_t split_plane;
- uint8_t split_value;
- union {
- int left;
- int color;
- };
- int right;
- SPTree() { leaf=true; left=-1; right=-1;}
- };
-
- struct MCBlock {
-
- BColorPos min_color,max_color;
- BColorPos *colors;
- int sp_idx;
- int color_count;
- int get_longest_axis_index() const;
- int get_longest_axis_length() const;
- bool operator<(const MCBlock& p_block) const;
- void shrink();
- MCBlock();
- MCBlock(BColorPos *p_colors,int p_color_count);
- };
-
Format format;
- DVector<uint8_t> data;
- int width,height,mipmaps;
-
-
+ PoolVector<uint8_t> data;
+ int width,height;
+ bool mipmaps;
- _FORCE_INLINE_ BColor _get_pixel(int p_x,int p_y,const unsigned char *p_data,int p_data_size) const;
- _FORCE_INLINE_ BColor _get_pixelw(int p_x,int p_y,int p_width,const unsigned char *p_data,int p_data_size) const;
- _FORCE_INLINE_ void _put_pixelw(int p_x,int p_y, int p_width, const BColor& p_color, unsigned char *p_data);
- _FORCE_INLINE_ void _put_pixel(int p_x,int p_y, const BColor& p_color, unsigned char *p_data);
_FORCE_INLINE_ void _get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width, int &r_height) const; //get where the mipmap begins in data
- _FORCE_INLINE_ static void _get_format_min_data_size(Format p_format,int &r_w, int &r_h);
static int _get_dst_image_size(int p_width, int p_height, Format p_format,int &r_mipmaps,int p_mipmaps=-1);
bool _can_modify(Format p_format) const;
+ _FORCE_INLINE_ void _put_pixelb(int p_x,int p_y, uint32_t p_pixelsize,uint8_t *p_dst,const uint8_t *p_src);
+ _FORCE_INLINE_ void _get_pixelb(int p_x,int p_y, uint32_t p_pixelsize,const uint8_t *p_src,uint8_t *p_dst);
public:
@@ -207,20 +149,11 @@ public:
int get_width() const; ///< Get image width
int get_height() const; ///< Get image height
- int get_mipmaps() const;
-
- /**
- * Get a pixel from the image. for grayscale or indexed formats, use Color::gray to obtain the actual
- * value.
- */
- Color get_pixel(int p_x,int p_y,int p_mipmap=0) const;
- /**
- * Set a pixel into the image. for grayscale or indexed formats, a suitable Color constructor.
- */
- void put_pixel(int p_x,int p_y, const Color& p_color,int p_mipmap=0); /* alpha and index are averaged */
+ bool has_mipmaps() const;
+ int get_mipmap_count() const;
/**
- * Convert the image to another format, as close as it can be done.
+ * Convert the image to another format, conversion only to raw byte format
*/
void convert( Format p_new_format );
@@ -259,25 +192,21 @@ public:
void flip_x();
void flip_y();
+
/**
* Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
*/
- Error generate_mipmaps(int p_amount=-1,bool p_keep_existing=false);
+ Error generate_mipmaps(bool p_keep_existing=false);
void clear_mipmaps();
- /**
- * Generate a normal map from a grayscale image
- */
-
- void make_normalmap(float p_height_scale=1.0);
/**
* Create a new image of a given size and format. Current image will be lost
*/
void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
- void create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
+ void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const PoolVector<uint8_t>& p_data);
void create( const char ** p_xpm );
/**
@@ -285,7 +214,7 @@ public:
*/
bool empty() const;
- DVector<uint8_t> get_data() const;
+ PoolVector<uint8_t> get_data() const;
Error load(const String& p_path);
Error save_png(const String& p_path);
@@ -301,7 +230,7 @@ public:
/**
* import an image of a specific size and format from a pointer
*/
- Image(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data);
+ Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const PoolVector<uint8_t>& p_data);
enum AlphaMode {
ALPHA_NONE,
@@ -312,32 +241,27 @@ public:
AlphaMode detect_alpha() const;
bool is_invisible() const;
- void put_indexed_pixel(int p_x, int p_y, uint8_t p_idx,int p_mipmap=0);
- uint8_t get_indexed_pixel(int p_x, int p_y,int p_mipmap=0) const;
- void set_pallete(const DVector<uint8_t>& p_data);
-
static int get_format_pixel_size(Format p_format);
static int get_format_pixel_rshift(Format p_format);
- static int get_format_pallete_size(Format p_format);
+ static void get_format_min_pixel_size(Format p_format,int &r_w, int &r_h);
+
static int get_image_data_size(int p_width, int p_height, Format p_format,int p_mipmaps=0);
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
-
-
bool operator==(const Image& p_image) const;
- void quantize();
-
enum CompressMode {
- COMPRESS_BC,
+ COMPRESS_16BIT,
+ COMPRESS_S3TC,
COMPRESS_PVRTC2,
COMPRESS_PVRTC4,
- COMPRESS_ETC
+ COMPRESS_ETC,
+ COMPRESS_ETC2
};
- Error compress(CompressMode p_mode=COMPRESS_BC);
+ Error compress(CompressMode p_mode=COMPRESS_S3TC);
Image compressed(int p_mode); /* from the Image::CompressMode enum */
Error decompress();
Image decompressed() const;
@@ -349,8 +273,6 @@ public:
void normalmap_to_xy();
void blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& p_dest);
- void brush_transfer(const Image& p_src, const Image& p_brush, const Point2& p_dest);
- Image brushed(const Image& p_src, const Image& p_brush, const Point2& p_dest) const;
Rect2 get_used_rect() const;
Image get_rect(const Rect2& p_area) const;
diff --git a/core/image_quantize.cpp b/core/image_quantize.cpp
deleted file mode 100644
index f6fe7a88a0..0000000000
--- a/core/image_quantize.cpp
+++ /dev/null
@@ -1,365 +0,0 @@
-/*************************************************************************/
-/* image_quantize.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "image.h"
-#include <stdio.h>
-#include "print_string.h"
-#ifdef TOOLS_ENABLED
-#include "set.h"
-#include "sort.h"
-#include "os/os.h"
-
-//#define QUANTIZE_SPEED_OVER_QUALITY
-
-
-Image::MCBlock::MCBlock() {
-
-
-}
-
-Image::MCBlock::MCBlock(BColorPos *p_colors,int p_color_count) {
-
- colors=p_colors;
- color_count=p_color_count;
- min_color.color=BColor(255,255,255,255);
- max_color.color=BColor(0,0,0,0);
- shrink();
-}
-
-int Image::MCBlock::get_longest_axis_index() const {
-
- int max_dist=-1;
- int max_index=0;
-
- for(int i=0;i<4;i++) {
-
- int d = max_color.color.col[i]-min_color.color.col[i];
- if (d>max_dist) {
- max_index=i;
- max_dist=d;
- }
- }
-
- return max_index;
-}
-int Image::MCBlock::get_longest_axis_length() const {
-
- int max_dist=-1;
-
- for(int i=0;i<4;i++) {
-
- int d = max_color.color.col[i]-min_color.color.col[i];
- if (d>max_dist) {
- max_dist=d;
- }
- }
-
- return max_dist;
-}
-
-bool Image::MCBlock::operator<(const MCBlock& p_block) const {
-
- int alen = get_longest_axis_length();
- int blen = p_block.get_longest_axis_length();
- if (alen==blen) {
-
- return colors < p_block.colors;
- } else
- return alen < blen;
-
-}
-
-void Image::MCBlock::shrink() {
-
- min_color=colors[0];
- max_color=colors[0];
-
- for(int i=1;i<color_count;i++) {
-
- for(int j=0;j<4;j++) {
-
- min_color.color.col[j]=MIN(min_color.color.col[j],colors[i].color.col[j]);
- max_color.color.col[j]=MAX(max_color.color.col[j],colors[i].color.col[j]);
- }
- }
-}
-
-
-
-
-void Image::quantize() {
-
- bool has_alpha = detect_alpha()!=ALPHA_NONE;
-
- bool quantize_fast=OS::get_singleton()->has_environment("QUANTIZE_FAST");
-
- convert(FORMAT_RGBA);
-
- ERR_FAIL_COND( format!=FORMAT_RGBA );
-
- DVector<uint8_t> indexed_data;
-
-
- {
- int color_count = data.size()/4;
-
- ERR_FAIL_COND(color_count==0);
-
- Set<MCBlock> block_queue;
-
- DVector<BColorPos> data_colors;
- data_colors.resize(color_count);
-
- DVector<BColorPos>::Write dcw=data_colors.write();
-
- DVector<uint8_t>::Read dr = data.read();
- const BColor * drptr=(const BColor*)&dr[0];
- BColorPos *bcptr=&dcw[0];
-
-
-
- {
- for(int i=0;i<color_count;i++) {
-
- //uint32_t data_ofs=i<<2;
- bcptr[i].color=drptr[i];//BColor(drptr[data_ofs+0],drptr[data_ofs+1],drptr[data_ofs+2],drptr[data_ofs+3]);
- bcptr[i].index=i;
- }
-
- }
-
- //printf("color count: %i\n",color_count);
- /*
- for(int i=0;i<color_count;i++) {
-
- BColor bc = ((BColor*)&wb[0])[i];
- printf("%i - %i,%i,%i,%i\n",i,bc.r,bc.g,bc.b,bc.a);
- }*/
-
- MCBlock initial_block((BColorPos*)&dcw[0],color_count);
-
- block_queue.insert(initial_block);
-
- while( block_queue.size() < 256 && block_queue.back()->get().color_count > 1 ) {
-
- MCBlock longest = block_queue.back()->get();
- //printf("longest: %i (%i)\n",longest.get_longest_axis_index(),longest.get_longest_axis_length());
-
- block_queue.erase(block_queue.back());
-
- BColorPos *first = longest.colors;
- BColorPos *median = longest.colors + (longest.color_count+1)/2;
- BColorPos *end = longest.colors + longest.color_count;
-
-#if 0
- int lai =longest.get_longest_axis_index();
- switch(lai) {
-#if 0
- case 0: { SortArray<BColorPos,BColorPos::SortR> sort; sort.sort(first,end-first); } break;
- case 1: { SortArray<BColorPos,BColorPos::SortG> sort; sort.sort(first,end-first); } break;
- case 2: { SortArray<BColorPos,BColorPos::SortB> sort; sort.sort(first,end-first); } break;
- case 3: { SortArray<BColorPos,BColorPos::SortA> sort; sort.sort(first,end-first); } break;
-#else
- case 0: { SortArray<BColorPos,BColorPos::SortR> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 1: { SortArray<BColorPos,BColorPos::SortG> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 2: { SortArray<BColorPos,BColorPos::SortB> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 3: { SortArray<BColorPos,BColorPos::SortA> sort; sort.nth_element(0,end-first,median-first,first); } break;
-#endif
-
- }
-
- //avoid same color from being split in 2
- //search forward and flip
- BColorPos *median_end=median;
- BColorPos *p=median_end+1;
-
- while(p!=end) {
- if (median_end->color==p->color) {
- SWAP(*(median_end+1),*p);
- median_end++;
- }
- p++;
- }
-
- //search backward and flip
- BColorPos *median_begin=median;
- p=median_begin-1;
-
- while(p!=(first-1)) {
- if (median_begin->color==p->color) {
- SWAP(*(median_begin-1),*p);
- median_begin--;
- }
- p--;
- }
-
-
- if (first < median_begin) {
- median=median_begin;
- } else if (median_end < end-1) {
- median=median_end+1;
- } else {
- break; //shouldn't have arrived here, since it means all pixels are equal, but wathever
- }
-
- MCBlock left(first,median-first);
- MCBlock right(median,end-median);
-
- block_queue.insert(left);
- block_queue.insert(right);
-
-#else
- switch(longest.get_longest_axis_index()) {
- case 0: { SortArray<BColorPos,BColorPos::SortR> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 1: { SortArray<BColorPos,BColorPos::SortG> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 2: { SortArray<BColorPos,BColorPos::SortB> sort; sort.nth_element(0,end-first,median-first,first); } break;
- case 3: { SortArray<BColorPos,BColorPos::SortA> sort; sort.nth_element(0,end-first,median-first,first); } break;
-
- }
-
- MCBlock left(first,median-first);
- MCBlock right(median,end-median);
-
- block_queue.insert(left);
- block_queue.insert(right);
-
-
-#endif
-
-
- }
-
- while(block_queue.size() > 256) {
-
- block_queue.erase(block_queue.front());// erase least significant
- }
-
- int res_colors=0;
-
- int comp_size = (has_alpha?4:3);
- indexed_data.resize(color_count + 256*comp_size);
-
- DVector<uint8_t>::Write iw = indexed_data.write();
- uint8_t *iwptr=&iw[0];
- BColor pallete[256];
-
- // print_line("applying quantization - res colors "+itos(block_queue.size()));
-
- while(block_queue.size()) {
-
- const MCBlock &b = block_queue.back()->get();
-
- uint64_t sum[4]={0,0,0,0};
-
- for(int i=0;i<b.color_count;i++) {
-
- sum[0]+=b.colors[i].color.col[0];
- sum[1]+=b.colors[i].color.col[1];
- sum[2]+=b.colors[i].color.col[2];
- sum[3]+=b.colors[i].color.col[3];
- }
-
- BColor c( sum[0]/b.color_count, sum[1]/b.color_count, sum[2]/b.color_count, sum[3]/b.color_count );
-
-
-
- //printf(" %i: %i,%i,%i,%i out of %i\n",res_colors,c.r,c.g,c.b,c.a,b.color_count);
-
-
-
- for(int i=0;i<comp_size;i++) {
- iwptr[ color_count + res_colors * comp_size + i ] = c.col[i];
- }
-
- if (quantize_fast) {
- for(int i=0;i<b.color_count;i++) {
- iwptr[b.colors[i].index]=res_colors;
- }
- } else {
-
- pallete[res_colors]=c;
- }
-
-
- res_colors++;
-
- block_queue.erase(block_queue.back());
-
- }
-
-
- if (!quantize_fast) {
-
- for(int i=0;i<color_count;i++) {
-
- const BColor &c=drptr[i];
- uint8_t best_dist_idx=0;
- uint32_t dist=0xFFFFFFFF;
-
- for(int j=0;j<res_colors;j++) {
-
- const BColor &pc=pallete[j];
- uint32_t d = 0;
- { int16_t v = (int16_t)c.r-(int16_t)pc.r; d+=v*v; }
- { int16_t v = (int16_t)c.g-(int16_t)pc.g; d+=v*v; }
- { int16_t v = (int16_t)c.b-(int16_t)pc.b; d+=v*v; }
- { int16_t v = (int16_t)c.a-(int16_t)pc.a; d+=v*v; }
-
- if (d<=dist) {
- best_dist_idx=j;
- dist=d;
- }
- }
-
-
- iwptr[ i ] = best_dist_idx;
-
- }
- }
-
- //iw = DVector<uint8_t>::Write();
- //dr = DVector<uint8_t>::Read();
- //wb = DVector<uint8_t>::Write();
- }
-
- print_line(itos(indexed_data.size()));
- data=indexed_data;
- format=has_alpha?FORMAT_INDEXED_ALPHA:FORMAT_INDEXED;
-
-
-} //do none
-
-
-
-#else
-
-
-void Image::quantize() {} //do none
-
-
-#endif
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 09cb7ce426..bcae630c76 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,19 +34,19 @@ InputMap *InputMap::singleton=NULL;
void InputMap::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("has_action","action"),&InputMap::has_action);
- ObjectTypeDB::bind_method(_MD("get_action_id","action"),&InputMap::get_action_id);
- ObjectTypeDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id);
- ObjectTypeDB::bind_method(_MD("get_actions"),&InputMap::_get_actions);
- ObjectTypeDB::bind_method(_MD("add_action","action"),&InputMap::add_action);
- ObjectTypeDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action);
+ ClassDB::bind_method(_MD("has_action","action"),&InputMap::has_action);
+ ClassDB::bind_method(_MD("get_action_id","action"),&InputMap::get_action_id);
+ ClassDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id);
+ ClassDB::bind_method(_MD("get_actions"),&InputMap::_get_actions);
+ ClassDB::bind_method(_MD("add_action","action"),&InputMap::add_action);
+ ClassDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action);
- ObjectTypeDB::bind_method(_MD("action_add_event","action","event"),&InputMap::action_add_event);
- ObjectTypeDB::bind_method(_MD("action_has_event","action","event"),&InputMap::action_has_event);
- ObjectTypeDB::bind_method(_MD("action_erase_event","action","event"),&InputMap::action_erase_event);
- ObjectTypeDB::bind_method(_MD("get_action_list","action"),&InputMap::_get_action_list);
- ObjectTypeDB::bind_method(_MD("event_is_action","event","action"),&InputMap::event_is_action);
- ObjectTypeDB::bind_method(_MD("load_from_globals"),&InputMap::load_from_globals);
+ ClassDB::bind_method(_MD("action_add_event","action","event"),&InputMap::action_add_event);
+ ClassDB::bind_method(_MD("action_has_event","action","event"),&InputMap::action_has_event);
+ ClassDB::bind_method(_MD("action_erase_event","action","event"),&InputMap::action_erase_event);
+ ClassDB::bind_method(_MD("get_action_list","action"),&InputMap::_get_action_list);
+ ClassDB::bind_method(_MD("event_is_action","event","action"),&InputMap::event_is_action);
+ ClassDB::bind_method(_MD("load_from_globals"),&InputMap::load_from_globals);
}
@@ -106,7 +106,7 @@ List<StringName> InputMap::get_actions() const {
return actions;
}
-List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event) const {
+List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore=false) const {
for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) {
@@ -122,10 +122,10 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const
case InputEvent::KEY: {
- same=(e.key.scancode==p_event.key.scancode && e.key.mod == p_event.key.mod);
+ same=(e.key.scancode==p_event.key.scancode && (p_mod_ignore || e.key.mod == p_event.key.mod));
} break;
- case InputEvent::JOYSTICK_BUTTON: {
+ case InputEvent::JOYPAD_BUTTON: {
same=(e.joy_button.button_index==p_event.joy_button.button_index);
@@ -135,7 +135,7 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const
same=(e.mouse_button.button_index==p_event.mouse_button.button_index);
} break;
- case InputEvent::JOYSTICK_MOTION: {
+ case InputEvent::JOYPAD_MOTION: {
same=(e.joy_motion.axis==p_event.joy_motion.axis && (e.joy_motion.axis_value < 0) == (p_event.joy_motion.axis_value < 0));
@@ -229,7 +229,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)!=NULL;
+ return _find_event(E->get().inputs,p_event,!p_event.is_pressed())!=NULL;
}
const Map<StringName, InputMap::Action>& InputMap::get_action_map() const {
@@ -241,7 +241,7 @@ void InputMap::load_from_globals() {
input_map.clear();;
List<PropertyInfo> pinfo;
- Globals::get_singleton()->get_property_list(&pinfo);
+ GlobalConfig::get_singleton()->get_property_list(&pinfo);
for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
const PropertyInfo &pi=E->get();
@@ -253,7 +253,7 @@ void InputMap::load_from_globals() {
add_action(name);
- Array va = Globals::get_singleton()->get(pi.name);;
+ Array va = GlobalConfig::get_singleton()->get(pi.name);;
for(int i=0;i<va.size();i++) {
@@ -324,7 +324,7 @@ void InputMap::load_default() {
key.key.scancode=KEY_PAGEDOWN;
action_add_event("ui_page_down",key);
-// set("display/orientation", "landscape");
+ //set("display/handheld/orientation", "landscape");
}
diff --git a/core/input_map.h b/core/input_map.h
index 21c479588d..306845fc89 100644
--- a/core/input_map.h
+++ b/core/input_map.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,7 +34,7 @@
class InputMap : public Object {
- OBJ_TYPE( InputMap, Object );
+ GDCLASS( InputMap, Object );
public:
struct Action {
int id;
@@ -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) const;
+ List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore) const;
Array _get_action_list(const StringName& p_action);
Array _get_actions();
diff --git a/core/int_types.h b/core/int_types.h
index 7d7c4b16b0..a7f04c680e 100644
--- a/core/int_types.h
+++ b/core/int_types.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/SCsub b/core/io/SCsub
index 3ff9b355a4..6789aa8bc6 100644
--- a/core/io/SCsub
+++ b/core/io/SCsub
@@ -1,7 +1,9 @@
+#!/usr/bin/env python
+
Import('env')
-env.add_source_files(env.core_sources,"*.cpp")
-env.add_source_files(env.core_sources,"*.c")
-#env.core_sources.append("io/fastlz.c")
+env.add_source_files(env.core_sources, "*.cpp")
+env.add_source_files(env.core_sources, "*.c")
+# env.core_sources.append("io/fastlz.c")
Export('env')
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index ca44d24911..0d3b494106 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/compression.h b/core/io/compression.h
index e0a4d31a51..fc00d02dda 100644
--- a/core/io/compression.h
+++ b/core/io/compression.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index e0dc7ef9fa..a9de740806 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,11 +31,11 @@
#include "os/file_access.h"
#include "variant_parser.h"
-StringArray ConfigFile::_get_sections() const {
+PoolStringArray ConfigFile::_get_sections() const {
List<String> s;
get_sections(&s);
- StringArray arr;
+ PoolStringArray arr;
arr.resize(s.size());
int idx=0;
for(const List<String>::Element *E=s.front();E;E=E->next()) {
@@ -46,11 +46,11 @@ StringArray ConfigFile::_get_sections() const {
return arr;
}
-StringArray ConfigFile::_get_section_keys(const String& p_section) const{
+PoolStringArray ConfigFile::_get_section_keys(const String& p_section) const{
List<String> s;
get_section_keys(p_section,&s);
- StringArray arr;
+ PoolStringArray arr;
arr.resize(s.size());
int idx=0;
for(const List<String>::Element *E=s.front();E;E=E->next()) {
@@ -206,17 +206,17 @@ Error ConfigFile::load(const String& p_path) {
void ConfigFile::_bind_methods(){
- ObjectTypeDB::bind_method(_MD("set_value","section","key","value"),&ConfigFile::set_value);
- ObjectTypeDB::bind_method(_MD("get_value:Variant","section","key","default"),&ConfigFile::get_value,DEFVAL(Variant()));
+ ClassDB::bind_method(_MD("set_value","section","key","value"),&ConfigFile::set_value);
+ ClassDB::bind_method(_MD("get_value:Variant","section","key","default"),&ConfigFile::get_value,DEFVAL(Variant()));
- ObjectTypeDB::bind_method(_MD("has_section","section"),&ConfigFile::has_section);
- ObjectTypeDB::bind_method(_MD("has_section_key","section","key"),&ConfigFile::has_section_key);
+ ClassDB::bind_method(_MD("has_section","section"),&ConfigFile::has_section);
+ ClassDB::bind_method(_MD("has_section_key","section","key"),&ConfigFile::has_section_key);
- ObjectTypeDB::bind_method(_MD("get_sections"),&ConfigFile::_get_sections);
- ObjectTypeDB::bind_method(_MD("get_section_keys","section"),&ConfigFile::_get_section_keys);
+ ClassDB::bind_method(_MD("get_sections"),&ConfigFile::_get_sections);
+ ClassDB::bind_method(_MD("get_section_keys","section"),&ConfigFile::_get_section_keys);
- ObjectTypeDB::bind_method(_MD("load:Error","path"),&ConfigFile::load);
- ObjectTypeDB::bind_method(_MD("save:Error","path"),&ConfigFile::save);
+ 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 4708fefeaa..397342f90f 100644
--- a/core/io/config_file.h
+++ b/core/io/config_file.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,12 +34,12 @@
class ConfigFile : public Reference {
- OBJ_TYPE(ConfigFile,Reference);
+ GDCLASS(ConfigFile,Reference);
Map< String, Map<String, Variant> > values;
- StringArray _get_sections() const;
- StringArray _get_section_keys(const String& p_section) const;
+ PoolStringArray _get_sections() const;
+ PoolStringArray _get_section_keys(const String& p_section) const;
protected:
static void _bind_methods();
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp
index e6b01475b6..71518de38b 100644
--- a/core/io/file_access_buffered.cpp
+++ b/core/io/file_access_buffered.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -117,7 +117,7 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest,int p_elements) const {
int size = (cache.buffer.size() - (file.offset - cache.offset));
size = size - (size % 4);
- //DVector<uint8_t>::Read read = cache.buffer.read();
+ //PoolVector<uint8_t>::Read read = cache.buffer.read();
//memcpy(p_dest, read.ptr() + (file.offset - cache.offset), size);
memcpy(p_dest, cache.buffer.ptr() + (file.offset - cache.offset), size);
p_dest += size;
@@ -152,7 +152,7 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest,int p_elements) const {
};
int r = MIN(left, to_read);
- //DVector<uint8_t>::Read read = cache.buffer.read();
+ //PoolVector<uint8_t>::Read read = cache.buffer.read();
//memcpy(p_dest+total_read, &read.ptr()[file.offset - cache.offset], r);
memcpy(p_dest+total_read, cache.buffer.ptr() + (file.offset - cache.offset), r);
diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h
index 058c26b8a9..be8ea714b1 100644
--- a/core/io/file_access_buffered.h
+++ b/core/io/file_access_buffered.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h
index afa79db06f..000c2b45f3 100644
--- a/core/io/file_access_buffered_fa.h
+++ b/core/io/file_access_buffered_fa.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -53,7 +53,7 @@ class FileAccessBufferedFA : public FileAccessBuffered {
cache.buffer.resize(p_size);
// on dvector
- //DVector<uint8_t>::Write write = cache.buffer.write();
+ //PoolVector<uint8_t>::Write write = cache.buffer.write();
//f.get_buffer(write.ptr(), p_size);
// on vector
@@ -127,10 +127,11 @@ public:
set_error(OK);
};
-// static void make_default() {
-
- //FileAccess::create_func = FileAccessBufferedFA<T>::create;
-// };
+ /*
+ static void make_default() {
+ FileAccess::create_func = FileAccessBufferedFA<T>::create;
+ };
+ */
virtual uint64_t _get_modified_time(const String& p_file) {
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 2547d2d065..3bcfade526 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h
index f9e7cd98bd..70034120f9 100644
--- a/core/io/file_access_compressed.h
+++ b/core/io/file_access_compressed.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 4d4b4d8ee7..039458237d 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/file_access_encrypted.h b/core/io/file_access_encrypted.h
index 34926faadf..51ed9a8677 100644
--- a/core/io/file_access_encrypted.h
+++ b/core/io/file_access_encrypted.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp
index 11a425001e..32eb003228 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -42,8 +42,8 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {
}
String name;
- if (Globals::get_singleton())
- name = Globals::get_singleton()->globalize_path(p_name);
+ if (GlobalConfig::get_singleton())
+ name = GlobalConfig::get_singleton()->globalize_path(p_name);
else
name = p_name;
//name = DirAccess::normalize_path(name);
@@ -68,7 +68,7 @@ FileAccess* FileAccessMemory::create() {
bool FileAccessMemory::file_exists(const String& p_name) {
String name = fix_path(p_name);
-// name = DirAccess::normalize_path(name);
+ //name = DirAccess::normalize_path(name);
return files && (files->find(name) != NULL);
}
@@ -87,7 +87,7 @@ Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) {
ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND);
String name = fix_path(p_path);
-// name = DirAccess::normalize_path(name);
+ //name = DirAccess::normalize_path(name);
Map<String, Vector<uint8_t> >::Element* E = files->find(name);
ERR_FAIL_COND_V(!E, ERR_FILE_NOT_FOUND);
diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h
index 287f3dfe04..c6dda07971 100644
--- a/core/io/file_access_memory.h
+++ b/core/io/file_access_memory.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index a3c839e761..7bf750f6e1 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -206,7 +206,7 @@ Error FileAccessNetworkClient::connect(const String& p_host,int p_port,const Str
}
DEBUG_PRINT("IP: "+String(ip)+" port "+itos(p_port));
- Error err = client->connect(ip,p_port);
+ Error err = client->connect_to_host(ip,p_port);
ERR_FAIL_COND_V(err,err);
while(client->get_status()==StreamPeerTCP::STATUS_CONNECTING) {
//DEBUG_PRINT("trying to connect....");
@@ -325,7 +325,7 @@ Error FileAccessNetwork::_open(const String& p_path, int p_mode_flags) {
last_page=-1;
last_page_buff=NULL;
-// buffers.clear();
+ //buffers.clear();
nc->unlock_mutex();
DEBUG_PRINT("OPEN POST");
DEBUG_TIME("open_post");
@@ -437,7 +437,7 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const{
p_length=total_size-pos;
}
-// FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
+ //FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
uint8_t *buff=last_page_buff;
@@ -528,6 +528,14 @@ uint64_t FileAccessNetwork::_get_modified_time(const String& p_file){
}
+void FileAccessNetwork::configure() {
+
+ GLOBAL_DEF("network/remote_fs/page_size",65536);
+ GLOBAL_DEF("network/remote_fs/page_read_ahead",4);
+ GLOBAL_DEF("network/remote_fs/max_pages",20);
+
+}
+
FileAccessNetwork::FileAccessNetwork() {
eof_flag=false;
@@ -541,9 +549,9 @@ FileAccessNetwork::FileAccessNetwork() {
id=nc->last_id++;
nc->accesses[id]=this;
nc->unlock_mutex();
- page_size = GLOBAL_DEF("remote_fs/page_size",65536);
- read_ahead = GLOBAL_DEF("remote_fs/page_read_ahead",4);
- max_pages = GLOBAL_DEF("remote_fs/max_pages",20);
+ page_size = GLOBAL_GET("network/remote_fs/page_size");
+ read_ahead = GLOBAL_GET("network/remote_fs/page_read_ahead");
+ max_pages = GLOBAL_GET("network/remote_fs/max_pages");
last_activity_val=0;
waiting_on_page=-1;
last_page=-1;
diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h
index 0073209ab8..4dbfb04b10 100644
--- a/core/io/file_access_network.h
+++ b/core/io/file_access_network.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -162,6 +162,8 @@ public:
virtual uint64_t _get_modified_time(const String& p_file);
+ static void configure();
+
FileAccessNetwork();
~FileAccessNetwork();
};
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index 1632b841c6..d63539a7a5 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -340,7 +340,7 @@ FileAccessPack::~FileAccessPack() {
//////////////////////////////////////////////////////////////////////////////////
-bool DirAccessPack::list_dir_begin() {
+Error DirAccessPack::list_dir_begin() {
list_dirs.clear();
@@ -356,7 +356,7 @@ bool DirAccessPack::list_dir_begin() {
list_files.push_back(E->get());
}
- return true;
+ return OK;
}
String DirAccessPack::get_next(){
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h
index f5dae6d51d..0a1320e57b 100644
--- a/core/io/file_access_pack.h
+++ b/core/io/file_access_pack.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -209,7 +209,7 @@ class DirAccessPack : public DirAccess {
public:
- virtual bool list_dir_begin();
+ virtual Error list_dir_begin();
virtual String get_next();
virtual bool current_is_dir() const;
virtual bool current_is_hidden() const;
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index 41f43bf54d..87f07cb7b1 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -165,7 +165,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
bool ZipArchive::try_open_pack(const String& p_name) {
//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
- if (p_name.extension().nocasecmp_to("zip") != 0 && p_name.extension().nocasecmp_to("pcz") != 0)
+ if (p_name.get_extension().nocasecmp_to("zip") != 0 && p_name.get_extension().nocasecmp_to("pcz") != 0)
return false;
zlib_filefunc_def io;
diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h
index 0a927b72f2..e34bc1283a 100644
--- a/core/io/file_access_zip.h
+++ b/core/io/file_access_zip.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 2a831dd992..63c8abbbad 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,10 +29,14 @@
#include "http_client.h"
#include "io/stream_peer_ssl.h"
+void HTTPClient::set_ip_type(IP::Type p_type) {
+ ip_type = p_type;
+}
-Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host){
+Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,bool p_verify_host){
close();
+ tcp_connection->set_ip_type(ip_type);
conn_port=p_port;
conn_host=p_host;
@@ -53,7 +57,7 @@ Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_ve
if (conn_host.is_valid_ip_address()) {
//is ip
- Error err = tcp_connection->connect(IP_Address(conn_host),p_port);
+ Error err = tcp_connection->connect_to_host(IP_Address(conn_host),p_port);
if (err) {
status=STATUS_CANT_CONNECT;
return err;
@@ -62,7 +66,7 @@ Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_ve
status=STATUS_CONNECTING;
} else {
//is hostname
- resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host);
+ resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host, ip_type);
status=STATUS_RESOLVING;
}
@@ -83,7 +87,7 @@ Ref<StreamPeer> HTTPClient::get_connection() const {
return connection;
}
-Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vector<String>& p_headers,const DVector<uint8_t>& p_body) {
+Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vector<String>& p_headers,const PoolVector<uint8_t>& p_body) {
ERR_FAIL_INDEX_V(p_method,METHOD_MAX,ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(status!=STATUS_CONNECTED,ERR_INVALID_PARAMETER);
@@ -116,7 +120,7 @@ Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vecto
request+="\r\n";
CharString cs=request.utf8();
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
//Maybe this goes faster somehow?
for(int i=0;i<cs.length();i++) {
@@ -124,7 +128,7 @@ Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vecto
}
data.append_array( p_body );
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
Error err = connection->put_data(&r[0], data.size());
if (err) {
@@ -189,7 +193,7 @@ Error HTTPClient::send_body_text(const String& p_body){
return OK;
}
-Error HTTPClient::send_body_data(const ByteArray& p_body){
+Error HTTPClient::send_body_data(const PoolByteArray& p_body){
return OK;
}
@@ -228,7 +232,7 @@ Error HTTPClient::get_response_headers(List<String> *r_response) {
void HTTPClient::close(){
if (tcp_connection->get_status()!=StreamPeerTCP::STATUS_NONE)
- tcp_connection->disconnect();
+ tcp_connection->disconnect_from_host();
connection.unref();
status=STATUS_DISCONNECTED;
@@ -263,7 +267,7 @@ Error HTTPClient::poll(){
case IP::RESOLVER_STATUS_DONE: {
IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving);
- Error err = tcp_connection->connect(host,conn_port);
+ Error err = tcp_connection->connect_to_host(host,conn_port);
IP::get_singleton()->erase_resolve_item(resolving);
resolving=IP::RESOLVER_INVALID_ID;
if (err) {
@@ -296,7 +300,7 @@ Error HTTPClient::poll(){
case StreamPeerTCP::STATUS_CONNECTED: {
if (ssl) {
Ref<StreamPeerSSL> ssl = StreamPeerSSL::create();
- Error err = ssl->connect(tcp_connection,true,ssl_verify_host?conn_host:String());
+ Error err = ssl->connect_to_stream(tcp_connection,true,ssl_verify_host?conn_host:String());
if (err!=OK) {
close();
status=STATUS_SSL_HANDSHAKE_ERROR;
@@ -440,11 +444,11 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
return ret;
}
-StringArray HTTPClient::_get_response_headers() {
+PoolStringArray HTTPClient::_get_response_headers() {
List<String> rh;
get_response_headers(&rh);
- StringArray ret;
+ PoolStringArray ret;
ret.resize(rh.size());
int idx=0;
for(const List<String>::Element *E=rh.front();E;E=E->next()) {
@@ -459,9 +463,9 @@ int HTTPClient::get_response_body_length() const {
return body_size;
}
-ByteArray HTTPClient::read_response_body_chunk() {
+PoolByteArray HTTPClient::read_response_body_chunk() {
- ERR_FAIL_COND_V( status !=STATUS_BODY, ByteArray() );
+ ERR_FAIL_COND_V( status !=STATUS_BODY, PoolByteArray() );
Error err=OK;
@@ -483,7 +487,7 @@ ByteArray HTTPClient::read_response_body_chunk() {
if (chunk.size()>32) {
ERR_PRINT("HTTP Invalid chunk hex len");
status=STATUS_CONNECTION_ERROR;
- return ByteArray();
+ return PoolByteArray();
}
if (chunk.size()>2 && chunk[chunk.size()-2]=='\r' && chunk[chunk.size()-1]=='\n') {
@@ -501,14 +505,14 @@ ByteArray HTTPClient::read_response_body_chunk() {
else {
ERR_PRINT("HTTP Chunk len not in hex!!");
status=STATUS_CONNECTION_ERROR;
- return ByteArray();
+ return PoolByteArray();
}
len<<=4;
len|=v;
if (len>(1<<24)) {
ERR_PRINT("HTTP Chunk too big!! >16mb");
status=STATUS_CONNECTION_ERROR;
- return ByteArray();
+ return PoolByteArray();
}
}
@@ -517,7 +521,7 @@ ByteArray HTTPClient::read_response_body_chunk() {
//end!
status=STATUS_CONNECTED;
chunk.clear();
- return ByteArray();
+ return PoolByteArray();
}
chunk_left=len+2;
@@ -538,13 +542,13 @@ ByteArray HTTPClient::read_response_body_chunk() {
if (chunk[chunk.size()-2]!='\r' || chunk[chunk.size()-1]!='\n') {
ERR_PRINT("HTTP Invalid chunk terminator (not \\r\\n)");
status=STATUS_CONNECTION_ERROR;
- return ByteArray();
+ return PoolByteArray();
}
- ByteArray ret;
+ PoolByteArray ret;
ret.resize(chunk.size()-2);
{
- ByteArray::Write w = ret.write();
+ PoolByteArray::Write w = ret.write();
copymem(w.ptr(),chunk.ptr(),chunk.size()-2);
}
chunk.clear();
@@ -560,9 +564,9 @@ ByteArray HTTPClient::read_response_body_chunk() {
} else {
int to_read = MIN(body_left,read_chunk_size);
- ByteArray ret;
+ PoolByteArray ret;
ret.resize(to_read);
- ByteArray::Write w = ret.write();
+ PoolByteArray::Write w = ret.write();
int _offset = 0;
while (to_read > 0) {
int rec=0;
@@ -599,7 +603,7 @@ ByteArray HTTPClient::read_response_body_chunk() {
status=STATUS_CONNECTED;
}
- return ByteArray();
+ return PoolByteArray();
}
HTTPClient::Status HTTPClient::get_status() const {
@@ -635,31 +639,32 @@ Error HTTPClient::_get_http_data(uint8_t* p_buffer, int p_bytes,int &r_received)
void HTTPClient::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("connect:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect,DEFVAL(false),DEFVAL(true));
- ObjectTypeDB::bind_method(_MD("set_connection","connection:StreamPeer"),&HTTPClient::set_connection);
- ObjectTypeDB::bind_method(_MD("get_connection:StreamPeer"),&HTTPClient::get_connection);
- ObjectTypeDB::bind_method(_MD("request_raw","method","url","headers","body"),&HTTPClient::request_raw);
- ObjectTypeDB::bind_method(_MD("request","method","url","headers","body"),&HTTPClient::request,DEFVAL(String()));
- ObjectTypeDB::bind_method(_MD("send_body_text","body"),&HTTPClient::send_body_text);
- ObjectTypeDB::bind_method(_MD("send_body_data","body"),&HTTPClient::send_body_data);
- ObjectTypeDB::bind_method(_MD("close"),&HTTPClient::close);
+ ClassDB::bind_method(_MD("set_ip_type","ip_type"),&HTTPClient::set_ip_type);
+ ClassDB::bind_method(_MD("connect_to_host:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect_to_host,DEFVAL(false),DEFVAL(true));
+ ClassDB::bind_method(_MD("set_connection","connection:StreamPeer"),&HTTPClient::set_connection);
+ ClassDB::bind_method(_MD("get_connection:StreamPeer"),&HTTPClient::get_connection);
+ ClassDB::bind_method(_MD("request_raw","method","url","headers","body"),&HTTPClient::request_raw);
+ ClassDB::bind_method(_MD("request","method","url","headers","body"),&HTTPClient::request,DEFVAL(String()));
+ ClassDB::bind_method(_MD("send_body_text","body"),&HTTPClient::send_body_text);
+ ClassDB::bind_method(_MD("send_body_data","body"),&HTTPClient::send_body_data);
+ ClassDB::bind_method(_MD("close"),&HTTPClient::close);
- ObjectTypeDB::bind_method(_MD("has_response"),&HTTPClient::has_response);
- ObjectTypeDB::bind_method(_MD("is_response_chunked"),&HTTPClient::is_response_chunked);
- ObjectTypeDB::bind_method(_MD("get_response_code"),&HTTPClient::get_response_code);
- ObjectTypeDB::bind_method(_MD("get_response_headers"),&HTTPClient::_get_response_headers);
- ObjectTypeDB::bind_method(_MD("get_response_headers_as_dictionary"),&HTTPClient::_get_response_headers_as_dictionary);
- ObjectTypeDB::bind_method(_MD("get_response_body_length"),&HTTPClient::get_response_body_length);
- ObjectTypeDB::bind_method(_MD("read_response_body_chunk"),&HTTPClient::read_response_body_chunk);
- ObjectTypeDB::bind_method(_MD("set_read_chunk_size","bytes"),&HTTPClient::set_read_chunk_size);
+ ClassDB::bind_method(_MD("has_response"),&HTTPClient::has_response);
+ ClassDB::bind_method(_MD("is_response_chunked"),&HTTPClient::is_response_chunked);
+ ClassDB::bind_method(_MD("get_response_code"),&HTTPClient::get_response_code);
+ ClassDB::bind_method(_MD("get_response_headers"),&HTTPClient::_get_response_headers);
+ ClassDB::bind_method(_MD("get_response_headers_as_dictionary"),&HTTPClient::_get_response_headers_as_dictionary);
+ ClassDB::bind_method(_MD("get_response_body_length"),&HTTPClient::get_response_body_length);
+ ClassDB::bind_method(_MD("read_response_body_chunk"),&HTTPClient::read_response_body_chunk);
+ ClassDB::bind_method(_MD("set_read_chunk_size","bytes"),&HTTPClient::set_read_chunk_size);
- ObjectTypeDB::bind_method(_MD("set_blocking_mode","enabled"),&HTTPClient::set_blocking_mode);
- ObjectTypeDB::bind_method(_MD("is_blocking_mode_enabled"),&HTTPClient::is_blocking_mode_enabled);
+ ClassDB::bind_method(_MD("set_blocking_mode","enabled"),&HTTPClient::set_blocking_mode);
+ ClassDB::bind_method(_MD("is_blocking_mode_enabled"),&HTTPClient::is_blocking_mode_enabled);
- ObjectTypeDB::bind_method(_MD("get_status"),&HTTPClient::get_status);
- ObjectTypeDB::bind_method(_MD("poll:Error"),&HTTPClient::poll);
+ ClassDB::bind_method(_MD("get_status"),&HTTPClient::get_status);
+ ClassDB::bind_method(_MD("poll:Error"),&HTTPClient::poll);
- ObjectTypeDB::bind_method(_MD("query_string_from_dict:String","fields"),&HTTPClient::query_string_from_dict);
+ ClassDB::bind_method(_MD("query_string_from_dict:String","fields"),&HTTPClient::query_string_from_dict);
BIND_CONSTANT( METHOD_GET );
@@ -761,6 +766,7 @@ String HTTPClient::query_string_from_dict(const Dictionary& p_dict) {
HTTPClient::HTTPClient(){
+ ip_type = IP::TYPE_ANY;
tcp_connection = StreamPeerTCP::create_ref();
resolving = IP::RESOLVER_INVALID_ID;
status=STATUS_DISCONNECTED;
diff --git a/core/io/http_client.h b/core/io/http_client.h
index 32d2e72101..496d22530b 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,7 +37,7 @@
class HTTPClient : public Reference {
- OBJ_TYPE(HTTPClient,Reference);
+ GDCLASS(HTTPClient,Reference);
public:
enum ResponseCode {
@@ -132,6 +132,7 @@ public:
private:
+ IP::Type ip_type;
Status status;
IP::ResolverID resolving;
int conn_port;
@@ -155,7 +156,7 @@ private:
Vector<String> response_headers;
static void _bind_methods();
- StringArray _get_response_headers();
+ PoolStringArray _get_response_headers();
Dictionary _get_response_headers_as_dictionary();
int read_chunk_size;
@@ -164,16 +165,17 @@ private:
public:
+ void set_ip_type(IP::Type p_type);
//Error connect_and_get(const String& p_url,bool p_verify_host=true); //connects to a full url and perform request
- Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true);
+ Error connect_to_host(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true);
void set_connection(const Ref<StreamPeer>& p_connection);
Ref<StreamPeer> get_connection() const;
- Error request_raw( Method p_method, const String& p_url, const Vector<String>& p_headers,const DVector<uint8_t>& p_body);
+ Error request_raw( Method p_method, const String& p_url, const Vector<String>& p_headers,const PoolVector<uint8_t>& p_body);
Error request( Method p_method, const String& p_url, const Vector<String>& p_headers,const String& p_body=String());
Error send_body_text(const String& p_body);
- Error send_body_data(const ByteArray& p_body);
+ Error send_body_data(const PoolByteArray& p_body);
void close();
@@ -185,7 +187,7 @@ public:
Error get_response_headers(List<String> *r_response);
int get_response_body_length() const;
- ByteArray read_response_body_chunk(); // can't get body as partial text because of most encodings UTF8, gzip, etc.
+ PoolByteArray read_response_body_chunk(); // can't get body as partial text because of most encodings UTF8, gzip, etc.
void set_blocking_mode(bool p_enable); //useful mostly if running in a thread
bool is_blocking_mode_enabled() const;
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index ac6c00dc61..2b01e865f4 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,7 +36,7 @@ bool ImageFormatLoader::recognize(const String& p_extension) const {
get_recognized_extensions(&extensions);
for (List<String>::Element *E=extensions.front();E;E=E->next()) {
- if (E->get().nocasecmp_to(p_extension.extension())==0)
+ if (E->get().nocasecmp_to(p_extension.get_extension())==0)
return true;
}
@@ -56,7 +56,7 @@ Error ImageLoader::load_image(String p_file,Image *p_image, FileAccess *p_custom
}
}
- String extension = p_file.extension();
+ String extension = p_file.get_extension();
for (int i=0;i<loader_count;i++) {
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index c799837792..4de7706ab0 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index a77aace07f..0eb1f221c9 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -43,10 +43,12 @@ struct _IP_ResolverPrivate {
volatile IP::ResolverStatus status;
IP_Address response;
String hostname;
+ IP::Type type;
void clear() {
status = IP::RESOLVER_STATUS_NONE;
response = IP_Address();
+ type = IP::TYPE_NONE;
hostname="";
};
@@ -78,9 +80,9 @@ struct _IP_ResolverPrivate {
if (queue[i].status!=IP::RESOLVER_STATUS_WAITING)
continue;
- queue[i].response=IP::get_singleton()->resolve_hostname(queue[i].hostname);
+ queue[i].response=IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type);
- if (queue[i].response.host==0)
+ if (queue[i].response==IP_Address())
queue[i].status=IP::RESOLVER_STATUS_ERROR;
else
queue[i].status=IP::RESOLVER_STATUS_DONE;
@@ -105,25 +107,30 @@ struct _IP_ResolverPrivate {
HashMap<String, IP_Address> cache;
+ static String get_cache_key(String p_hostname, IP::Type p_type) {
+ return itos(p_type) + p_hostname;
+ }
+
};
-IP_Address IP::resolve_hostname(const String& p_hostname) {
+IP_Address IP::resolve_hostname(const String& p_hostname, IP::Type p_type) {
- GLOBAL_LOCK_FUNCTION
+ GLOBAL_LOCK_FUNCTION;
- if (resolver->cache.has(p_hostname))
- return resolver->cache[p_hostname];
+ String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type);
+ if (resolver->cache.has(key))
+ return resolver->cache[key];
- IP_Address res = _resolve_hostname(p_hostname);
- resolver->cache[p_hostname]=res;
+ IP_Address res = _resolve_hostname(p_hostname, p_type);
+ resolver->cache[key]=res;
return res;
}
-IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname) {
+IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname, IP::Type p_type) {
- GLOBAL_LOCK_FUNCTION
+ GLOBAL_LOCK_FUNCTION;
ResolverID id = resolver->find_empty_id();
@@ -132,9 +139,11 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname) {
return id;
}
+ String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type);
resolver->queue[id].hostname=p_hostname;
- if (resolver->cache.has(p_hostname)) {
- resolver->queue[id].response=resolver->cache[p_hostname];
+ resolver->queue[id].type = p_type;
+ if (resolver->cache.has(key)) {
+ resolver->queue[id].response=resolver->cache[key];
resolver->queue[id].status=IP::RESOLVER_STATUS_DONE;
} else {
resolver->queue[id].response=IP_Address();
@@ -145,10 +154,6 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String& p_hostname) {
resolver->resolve_queues();
}
-
-
-
-
return id;
}
@@ -187,6 +192,17 @@ void IP::erase_resolve_item(ResolverID p_id) {
}
+void IP::clear_cache(const String &p_hostname) {
+
+ if (p_hostname.empty()) {
+ resolver->cache.clear();
+ } else {
+ resolver->cache.erase(_IP_ResolverPrivate::get_cache_key(p_hostname, IP::TYPE_NONE));
+ resolver->cache.erase(_IP_ResolverPrivate::get_cache_key(p_hostname, IP::TYPE_IPV4));
+ resolver->cache.erase(_IP_ResolverPrivate::get_cache_key(p_hostname, IP::TYPE_IPV6));
+ resolver->cache.erase(_IP_ResolverPrivate::get_cache_key(p_hostname, IP::TYPE_ANY));
+ }
+};
Array IP::_get_local_addresses() const {
@@ -202,12 +218,13 @@ Array IP::_get_local_addresses() const {
void IP::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("resolve_hostname","host"),&IP::resolve_hostname);
- ObjectTypeDB::bind_method(_MD("resolve_hostname_queue_item","host"),&IP::resolve_hostname_queue_item);
- ObjectTypeDB::bind_method(_MD("get_resolve_item_status","id"),&IP::get_resolve_item_status);
- ObjectTypeDB::bind_method(_MD("get_resolve_item_address","id"),&IP::get_resolve_item_address);
- ObjectTypeDB::bind_method(_MD("erase_resolve_item","id"),&IP::erase_resolve_item);
- ObjectTypeDB::bind_method(_MD("get_local_addresses"),&IP::_get_local_addresses);
+ ClassDB::bind_method(_MD("resolve_hostname","host","ip_type"),&IP::resolve_hostname,DEFVAL(IP::TYPE_ANY));
+ ClassDB::bind_method(_MD("resolve_hostname_queue_item","host","ip_type"),&IP::resolve_hostname_queue_item,DEFVAL(IP::TYPE_ANY));
+ ClassDB::bind_method(_MD("get_resolve_item_status","id"),&IP::get_resolve_item_status);
+ ClassDB::bind_method(_MD("get_resolve_item_address","id"),&IP::get_resolve_item_address);
+ ClassDB::bind_method(_MD("erase_resolve_item","id"),&IP::erase_resolve_item);
+ ClassDB::bind_method(_MD("get_local_addresses"),&IP::_get_local_addresses);
+ ClassDB::bind_method(_MD("clear_cache"),&IP::clear_cache, DEFVAL(""));
BIND_CONSTANT( RESOLVER_STATUS_NONE );
BIND_CONSTANT( RESOLVER_STATUS_WAITING );
@@ -217,6 +234,10 @@ void IP::_bind_methods() {
BIND_CONSTANT( RESOLVER_MAX_QUERIES );
BIND_CONSTANT( RESOLVER_INVALID_ID );
+ BIND_CONSTANT( TYPE_NONE );
+ BIND_CONSTANT( TYPE_IPV4 );
+ BIND_CONSTANT( TYPE_IPV6 );
+ BIND_CONSTANT( TYPE_ANY );
}
diff --git a/core/io/ip.h b/core/io/ip.h
index 38c86e7ba3..3e028f2613 100644
--- a/core/io/ip.h
+++ b/core/io/ip.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,7 +36,7 @@
struct _IP_ResolverPrivate;
class IP : public Object {
- OBJ_TYPE( IP, Object );
+ GDCLASS( IP, Object );
OBJ_CATEGORY("Networking");
public:
@@ -48,6 +48,14 @@ public:
RESOLVER_STATUS_ERROR,
};
+ enum Type {
+
+ TYPE_NONE = 0,
+ TYPE_IPV4 = 1,
+ TYPE_IPV6 = 2,
+ TYPE_ANY = 3,
+ };
+
enum {
RESOLVER_MAX_QUERIES = 32,
RESOLVER_INVALID_ID=-1
@@ -65,7 +73,7 @@ protected:
static IP*singleton;
static void _bind_methods();
- virtual IP_Address _resolve_hostname(const String& p_hostname)=0;
+ virtual IP_Address _resolve_hostname(const String& p_hostname, Type p_type = TYPE_ANY)=0;
Array _get_local_addresses() const;
static IP* (*_create)();
@@ -73,14 +81,16 @@ public:
- IP_Address resolve_hostname(const String& p_hostname);
+ IP_Address resolve_hostname(const String& p_hostname, Type p_type = TYPE_ANY);
// async resolver hostname
- ResolverID resolve_hostname_queue_item(const String& p_hostname);
+ ResolverID resolve_hostname_queue_item(const String& p_hostname, Type p_type = TYPE_ANY);
ResolverStatus get_resolve_item_status(ResolverID p_id) const;
IP_Address get_resolve_item_address(ResolverID p_id) const;
virtual void get_local_addresses(List<IP_Address> *r_addresses) const=0;
void erase_resolve_item(ResolverID p_id);
+ void clear_cache(const String& p_hostname = "");
+
static IP* get_singleton();
static IP* create();
@@ -91,4 +101,6 @@ public:
};
+VARIANT_ENUM_CAST(IP::Type);
+
#endif // IP_H
diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp
index 7a51bce7c6..1fda7fed7b 100644
--- a/core/io/ip_address.cpp
+++ b/core/io/ip_address.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,29 +32,209 @@ IP_Address::operator Variant() const {
return operator String();
}*/
+
+#include <string.h>
+#include <stdio.h>
+
IP_Address::operator String() const {
- return itos(field[0])+"."+itos(field[1])+"."+itos(field[2])+"."+itos(field[3]);
+ if(is_ipv4())
+ // IPv4 address mapped to IPv6
+ return itos(field8[12])+"."+itos(field8[13])+"."+itos(field8[14])+"."+itos(field8[15]);
+ String ret;
+ for (int i=0; i<8; i++) {
+ if (i > 0)
+ ret = ret + ":";
+ uint16_t num = (field8[i*2] << 8) + field8[i*2+1];
+ ret = ret + String::num_int64(num, 16);
+ };
+
+ return ret;
}
-IP_Address::IP_Address(const String& p_string) {
+static void _parse_hex(const String& p_string, int p_start, uint8_t* p_dst) {
+
+ uint16_t ret = 0;
+ for (int i=p_start; i<p_start + 4; i++) {
+
+ if (i >= p_string.length()) {
+ break;
+ };
+
+ int n = 0;
+ CharType c = p_string[i];
+ if (c >= '0' && c <= '9') {
+
+ n = c - '0';
+ } else if (c >= 'a' && c <= 'f') {
+ n = 10 + (c - 'a');
+ } else if (c >= 'A' && c <= 'F') {
+ n = 10 + (c - 'A');
+ } else if (c == ':') {
+ break;
+ } else {
+ ERR_EXPLAIN("Invalid character in ipv6 address: " + p_string);
+ ERR_FAIL();
+ };
+ ret = ret << 4;
+ ret += n;
+ };
+
+ p_dst[0] = ret >> 8;
+ p_dst[1] = ret & 0xff;
+};
+
+void IP_Address::_parse_ipv6(const String& p_string) {
+
+ static const int parts_total = 8;
+ int parts[parts_total] = {0};
+ int parts_count = 0;
+ bool part_found = false;
+ bool part_skip = false;
+ bool part_ipv4 = false;
+ int parts_idx = 0;
+
+ for (int i=0; i<p_string.length(); i++) {
+
+ CharType c = p_string[i];
+ if (c == ':') {
+
+ if (i == 0) {
+ continue; // next must be a ":"
+ };
+ if (!part_found) {
+ part_skip = true;
+ parts[parts_idx++] = -1;
+ };
+ part_found = false;
+ } else if (c == '.') {
+
+ part_ipv4 = true;
+
+ } else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
+ if (!part_found) {
+ parts[parts_idx++] = i;
+ part_found = true;
+ ++parts_count;
+ };
+ } else {
+
+ ERR_EXPLAIN("Invalid character in IPv6 address: " + p_string);
+ ERR_FAIL();
+ };
+ };
+
+ int parts_extra = 0;
+ if (part_skip) {
+ parts_extra = parts_total - parts_count;
+ };
+
+ int idx = 0;
+ for (int i=0; i<parts_idx; i++) {
+
+ if (parts[i] == -1) {
+
+ for (int j=0; j<parts_extra; j++) {
+ field16[idx++] = 0;
+ };
+ continue;
+ };
+
+ if (part_ipv4 && i == parts_idx - 1) {
+ _parse_ipv4(p_string, parts[i], (uint8_t*)&field16[idx]); // should be the last one
+ } else {
+ _parse_hex(p_string, parts[i], (uint8_t*)&(field16[idx++]));
+ };
+ };
+
+};
+
+void IP_Address::_parse_ipv4(const String& p_string, int p_start, uint8_t* p_ret) {
- host=0;
- int slices = p_string.get_slice_count(".");
+ String ip;
+ if (p_start != 0) {
+ ip = p_string.substr(p_start, p_string.length() - p_start);
+ } else {
+ ip = p_string;
+ };
+
+ int slices = ip.get_slice_count(".");
if (slices!=4) {
- ERR_EXPLAIN("Invalid IP Address String: "+p_string);
+ ERR_EXPLAIN("Invalid IP Address String: "+ip);
ERR_FAIL();
}
for(int i=0;i<4;i++) {
-
- field[i]=p_string.get_slicec('.',i).to_int();
+ p_ret[i]=ip.get_slicec('.',i).to_int();
}
+};
+
+void IP_Address::clear() {
+
+ memset(&field8[0], 0, sizeof(field8));
+};
+
+bool IP_Address::is_ipv4() const{
+ return (field32[0]==0 && field32[1]==0 && field16[4]==0 && field16[5]==0xffff);
+}
+
+const uint8_t *IP_Address::get_ipv4() const{
+ ERR_FAIL_COND_V(!is_ipv4(),0);
+ return &(field8[12]);
+}
+
+void IP_Address::set_ipv4(const uint8_t *p_ip) {
+ clear();
+ field16[5]=0xffff;
+ field32[3]=*((const uint32_t *)p_ip);
}
-IP_Address::IP_Address(uint8_t p_a,uint8_t p_b,uint8_t p_c,uint8_t p_d) {
+const uint8_t *IP_Address::get_ipv6() const{
+ return field8;
+}
+
+void IP_Address::set_ipv6(const uint8_t *p_buf) {
+ clear();
+ for (int i=0; i<16; i++)
+ field8[i] = p_buf[i];
+}
+
+IP_Address::IP_Address(const String& p_string) {
+
+ clear();
+ if (p_string.find(":") >= 0) {
+
+ _parse_ipv6(p_string);
+ } else {
+ // Mapped to IPv6
+ field16[5] = 0xffff;
+ _parse_ipv4(p_string, 0, &field8[12]);
+ };
+}
+
+_FORCE_INLINE_ static void _32_to_buf(uint8_t* p_dst, uint32_t p_n) {
+
+ p_dst[0] = (p_n >> 24) & 0xff;
+ p_dst[1] = (p_n >> 16) & 0xff;
+ p_dst[2] = (p_n >> 8) & 0xff;
+ p_dst[3] = (p_n >> 0) & 0xff;
+};
+
+IP_Address::IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, bool is_v6) {
+
+ clear();
+ if (!is_v6) {
+ // Mapped to IPv6
+ field16[5]=0xffff;
+ field8[12]=p_a;
+ field8[13]=p_b;
+ field8[14]=p_c;
+ field8[15]=p_d;
+ } else {
+
+ _32_to_buf(&field8[0], p_a);
+ _32_to_buf(&field8[4], p_b);
+ _32_to_buf(&field8[8], p_c);
+ _32_to_buf(&field8[12], p_d);
+ }
- field[0]=p_a;
- field[1]=p_b;
- field[2]=p_c;
- field[3]=p_d;
}
diff --git a/core/io/ip_address.h b/core/io/ip_address.h
index 1292311729..87f32b0ac2 100644
--- a/core/io/ip_address.h
+++ b/core/io/ip_address.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,22 +33,45 @@
struct IP_Address {
+private:
+
union {
- uint8_t field[4];
- uint32_t host;
+ uint8_t field8[16];
+ uint16_t field16[8];
+ uint32_t field32[4];
};
+protected:
+ void _parse_ipv6(const String& p_string);
+ void _parse_ipv4(const String& p_string, int p_start, uint8_t* p_ret);
+
+public:
//operator Variant() const;
bool operator==(const IP_Address& p_ip) const {
- return host==p_ip.host;
+ for (int i=0; i<4; i++)
+ if (field32[i] != p_ip.field32[i])
+ return false;
+ return true;
}
bool operator!=(const IP_Address& p_ip) const {
- return host!=p_ip.host;
+ for (int i=0; i<4; i++)
+ if (field32[i] != p_ip.field32[i])
+ return true;
+ return false;
}
+
+ void clear();
+ bool is_ipv4() const;
+ const uint8_t *get_ipv4() const;
+ void set_ipv4(const uint8_t *p_ip);
+
+ const uint8_t *get_ipv6() const;
+ void set_ipv6(const uint8_t *buf);
+
operator String() const;
IP_Address(const String& p_string);
- IP_Address(uint8_t p_a,uint8_t p_b,uint8_t p_c,uint8_t p_d);
- IP_Address() { host=0; }
+ IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, bool is_v6=false);
+ IP_Address() { clear(); }
};
diff --git a/core/io/json.cpp b/core/io/json.cpp
index f9a8638d06..c0aa530a12 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -52,9 +52,9 @@ String JSON::_print_var(const Variant& p_var) {
case Variant::BOOL: return p_var.operator bool() ? "true": "false";
case Variant::INT: return itos(p_var);
case Variant::REAL: return rtos(p_var);
- case Variant::INT_ARRAY:
- case Variant::REAL_ARRAY:
- case Variant::STRING_ARRAY:
+ case Variant::POOL_INT_ARRAY:
+ case Variant::POOL_REAL_ARRAY:
+ case Variant::POOL_STRING_ARRAY:
case Variant::ARRAY: {
String s = "[";
@@ -92,9 +92,9 @@ String JSON::_print_var(const Variant& p_var) {
}
-String JSON::print(const Dictionary& p_dict) {
+String JSON::print(const Variant& p_var) {
- return _print_var(p_dict);
+ return _print_var(p_var);
}
@@ -288,7 +288,7 @@ Error JSON::_parse_value(Variant &value,Token& token,const CharType *p_str,int &
if (token.type==TK_CURLY_BRACKET_OPEN) {
- Dictionary d(true);
+ Dictionary d;
Error err = _parse_object(d,p_str,index,p_len,line,r_err_str);
if (err)
return err;
@@ -296,7 +296,7 @@ Error JSON::_parse_value(Variant &value,Token& token,const CharType *p_str,int &
return OK;
} else if (token.type==TK_BRACKET_OPEN) {
- Array a(true);
+ Array a;
Error err = _parse_array(a,p_str,index,p_len,line,r_err_str);
if (err)
return err;
@@ -450,27 +450,24 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i
}
-Error JSON::parse(const String& p_json,Dictionary& r_ret,String &r_err_str,int &r_err_line) {
+Error JSON::parse(const String& p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
const CharType *str = p_json.ptr();
int idx = 0;
int len = p_json.length();
Token token;
- int line=0;
+ r_err_line=0;
String aux_key;
- Error err = _get_token(str,idx,len,token,line,r_err_str);
+ Error err = _get_token(str,idx,len,token,r_err_line,r_err_str);
if (err)
return err;
- if (token.type!=TK_CURLY_BRACKET_OPEN) {
+ err = _parse_value(r_ret,token,str,idx,len,r_err_line,r_err_str);
- r_err_str="Expected '{'";
- return ERR_PARSE_ERROR;
- }
-
- return _parse_object(r_ret,str,idx,len,r_err_line,r_err_str);
+ return err;
+
}
diff --git a/core/io/json.h b/core/io/json.h
index a2803269cb..97457d223e 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -74,8 +74,8 @@ class JSON {
static Error _parse_object(Dictionary &object,const CharType *p_str,int &index, int p_len,int &line,String &r_err_str);
public:
- static String print(const Dictionary& p_dict);
- static Error parse(const String& p_json,Dictionary& r_ret,String &r_err_str,int &r_err_line);
+ static String print(const Variant &p_var);
+ static Error parse(const String& p_json,Variant& r_ret,String &r_err_str,int &r_err_line);
};
#endif // JSON_H
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index c9bd38c654..e958edc93e 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,6 +31,10 @@
#include "os/keyboard.h"
#include <stdio.h>
+
+#define ENCODE_MASK 0xFF
+#define ENCODE_FLAG_64 1<<16
+
Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *r_len) {
const uint8_t * buf=p_buffer;
@@ -44,14 +48,14 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
uint32_t type=decode_uint32(buf);
- ERR_FAIL_COND_V(type>=Variant::VARIANT_MAX,ERR_INVALID_DATA);
+ ERR_FAIL_COND_V((type&ENCODE_MASK)>=Variant::VARIANT_MAX,ERR_INVALID_DATA);
buf+=4;
len-=4;
if (r_len)
*r_len=4;
- switch(type) {
+ switch(type&ENCODE_MASK) {
case Variant::NIL: {
@@ -68,19 +72,35 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
case Variant::INT: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
- int val = decode_uint32(buf);
- r_variant=val;
- if (r_len)
- (*r_len)+=4;
+ if (type&ENCODE_FLAG_64) {
+ int64_t val = decode_uint64(buf);
+ r_variant=val;
+ if (r_len)
+ (*r_len)+=8;
+
+ } else {
+ int32_t val = decode_uint32(buf);
+ r_variant=val;
+ if (r_len)
+ (*r_len)+=4;
+ }
} break;
case Variant::REAL: {
ERR_FAIL_COND_V(len<(int)4,ERR_INVALID_DATA);
- float val = decode_float(buf);
- r_variant=val;
- if (r_len)
- (*r_len)+=4;
+
+ if (type&ENCODE_FLAG_64) {
+ double val = decode_double(buf);
+ r_variant=val;
+ if (r_len)
+ (*r_len)+=8;
+ } else {
+ float val = decode_float(buf);
+ r_variant=val;
+ if (r_len)
+ (*r_len)+=4;
+ }
} break;
case Variant::STRING: {
@@ -144,10 +164,10 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
(*r_len)+=4*3;
} break;
- case Variant::MATRIX32: {
+ case Variant::TRANSFORM2D: {
ERR_FAIL_COND_V(len<(int)4*6,ERR_INVALID_DATA);
- Matrix32 val;
+ Transform2D val;
for(int i=0;i<3;i++) {
for(int j=0;j<2;j++) {
@@ -189,10 +209,10 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
(*r_len)+=4*4;
} break;
- case Variant::_AABB: {
+ case Variant::RECT3: {
ERR_FAIL_COND_V(len<(int)4*6,ERR_INVALID_DATA);
- AABB val;
+ Rect3 val;
val.pos.x=decode_float(&buf[0]);
val.pos.y=decode_float(&buf[4]);
val.pos.z=decode_float(&buf[8]);
@@ -205,10 +225,10 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
(*r_len)+=4*6;
} break;
- case Variant::MATRIX3: {
+ case Variant::BASIS: {
ERR_FAIL_COND_V(len<(int)4*9,ERR_INVALID_DATA);
- Matrix3 val;
+ Basis val;
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
@@ -272,11 +292,11 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (datalen>0) {
len-=5*4;
ERR_FAIL_COND_V( len < datalen, ERR_INVALID_DATA );
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
data.resize(datalen);
- DVector<uint8_t>::Write wr = data.write();
+ PoolVector<uint8_t>::Write wr = data.write();
copymem(&wr[0],&buf[20],datalen);
- wr = DVector<uint8_t>::Write();
+ wr = PoolVector<uint8_t>::Write();
@@ -423,7 +443,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
(*r_len)+=4;
} break;
- case InputEvent::JOYSTICK_BUTTON: {
+ case InputEvent::JOYPAD_BUTTON: {
ie.joy_button.button_index=decode_uint32(&buf[12]);
if (r_len)
@@ -435,7 +455,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (r_len)
(*r_len)+=4;
} break;
- case InputEvent::JOYSTICK_MOTION: {
+ case InputEvent::JOYPAD_MOTION: {
ie.joy_motion.axis=decode_uint32(&buf[12]);
ie.joy_motion.axis_value=decode_float(&buf[16]);
@@ -451,7 +471,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t count = decode_uint32(buf);
- bool shared = count&0x80000000;
+ // bool shared = count&0x80000000;
count&=0x7FFFFFFF;
buf+=4;
@@ -461,7 +481,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
(*r_len)+=4;
}
- Dictionary d(shared);
+ Dictionary d;
for(uint32_t i=0;i<count;i++) {
@@ -496,7 +516,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t count = decode_uint32(buf);
- bool shared = count&0x80000000;
+ // bool shared = count&0x80000000;
count&=0x7FFFFFFF;
buf+=4;
@@ -506,7 +526,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
(*r_len)+=4;
}
- Array varr(shared);
+ Array varr;
for(uint32_t i=0;i<count;i++) {
@@ -528,7 +548,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
} break;
// arrays
- case Variant::RAW_ARRAY: {
+ case Variant::POOL_BYTE_ARRAY: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t count = decode_uint32(buf);
@@ -537,17 +557,17 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
ERR_FAIL_COND_V((int)count>len,ERR_INVALID_DATA);
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
if (count) {
data.resize(count);
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
for(int i=0;i<count;i++) {
w[i]=buf[i];
}
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
}
r_variant=data;
@@ -561,7 +581,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
} break;
- case Variant::INT_ARRAY: {
+ case Variant::POOL_INT_ARRAY: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t count = decode_uint32(buf);
@@ -569,18 +589,18 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4>len,ERR_INVALID_DATA);
- DVector<int> data;
+ PoolVector<int> data;
if (count) {
//const int*rbuf=(const int*)buf;
data.resize(count);
- DVector<int>::Write w = data.write();
+ PoolVector<int>::Write w = data.write();
for(int i=0;i<count;i++) {
w[i]=decode_uint32(&buf[i*4]);
}
- w = DVector<int>::Write();
+ w = PoolVector<int>::Write();
}
r_variant=Variant(data);
if (r_len) {
@@ -588,7 +608,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
}
} break;
- case Variant::REAL_ARRAY: {
+ case Variant::POOL_REAL_ARRAY: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t count = decode_uint32(buf);
@@ -596,18 +616,18 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4>len,ERR_INVALID_DATA);
- DVector<float> data;
+ PoolVector<float> data;
if (count) {
//const float*rbuf=(const float*)buf;
data.resize(count);
- DVector<float>::Write w = data.write();
+ PoolVector<float>::Write w = data.write();
for(int i=0;i<count;i++) {
w[i]=decode_float(&buf[i*4]);
}
- w = DVector<float>::Write();
+ w = PoolVector<float>::Write();
}
r_variant=data;
@@ -617,13 +637,13 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
} break;
- case Variant::STRING_ARRAY: {
+ case Variant::POOL_STRING_ARRAY: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t count = decode_uint32(buf);
ERR_FAIL_COND_V(count<0,ERR_INVALID_DATA);
- DVector<String> strings;
+ PoolVector<String> strings;
buf+=4;
len-=4;
@@ -667,7 +687,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
} break;
- case Variant::VECTOR2_ARRAY: {
+ case Variant::POOL_VECTOR2_ARRAY: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t count = decode_uint32(buf);
@@ -676,7 +696,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4*2>len,ERR_INVALID_DATA);
- DVector<Vector2> varray;
+ PoolVector<Vector2> varray;
if (r_len) {
(*r_len)+=4;
@@ -684,7 +704,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (count) {
varray.resize(count);
- DVector<Vector2>::Write w = varray.write();
+ PoolVector<Vector2>::Write w = varray.write();
for(int i=0;i<(int)count;i++) {
@@ -705,7 +725,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
r_variant=varray;
} break;
- case Variant::VECTOR3_ARRAY: {
+ case Variant::POOL_VECTOR3_ARRAY: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t count = decode_uint32(buf);
@@ -714,7 +734,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4*3>len,ERR_INVALID_DATA);
- DVector<Vector3> varray;
+ PoolVector<Vector3> varray;
if (r_len) {
(*r_len)+=4;
@@ -722,7 +742,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (count) {
varray.resize(count);
- DVector<Vector3>::Write w = varray.write();
+ PoolVector<Vector3>::Write w = varray.write();
for(int i=0;i<(int)count;i++) {
@@ -744,7 +764,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
r_variant=varray;
} break;
- case Variant::COLOR_ARRAY: {
+ case Variant::POOL_COLOR_ARRAY: {
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA);
uint32_t count = decode_uint32(buf);
@@ -753,7 +773,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
len-=4;
ERR_FAIL_COND_V((int)count*4*4>len,ERR_INVALID_DATA);
- DVector<Color> carray;
+ PoolVector<Color> carray;
if (r_len) {
(*r_len)+=4;
@@ -761,7 +781,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int *
if (count) {
carray.resize(count);
- DVector<Color>::Write w = carray.write();
+ PoolVector<Color>::Write w = carray.write();
for(int i=0;i<(int)count;i++) {
@@ -796,8 +816,28 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len=0;
+ uint32_t flags=0;
+
+ switch(p_variant.get_type()) {
+
+ case Variant::INT: {
+ int64_t val = p_variant;
+ if (val>0x7FFFFFFF || val < -0x80000000) {
+ flags|=ENCODE_FLAG_64;
+ }
+ } break;
+ case Variant::REAL: {
+
+ double d = p_variant;
+ float f = d;
+ if (double(f)!=d) {
+ flags|=ENCODE_FLAG_64; //always encode real as double
+ }
+ } break;
+ }
+
if (buf) {
- encode_uint32(p_variant.get_type(),buf);
+ encode_uint32(p_variant.get_type()|flags,buf);
buf+=4;
}
r_len+=4;
@@ -819,20 +859,42 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
} break;
case Variant::INT: {
- if (buf) {
- encode_uint32(p_variant.operator int(),buf);
- }
+ int64_t val = p_variant;
+ if (val>0x7FFFFFFF || val < -0x80000000) {
+ //64 bits
+ if (buf) {
+ encode_uint64(val,buf);
+ }
- r_len+=4;
+ r_len+=8;
+ } else {
+ if (buf) {
+ encode_uint32(int32_t(val),buf);
+ }
+ r_len+=4;
+ }
} break;
case Variant::REAL: {
- if (buf) {
- encode_float(p_variant.operator float(),buf);
+ double d = p_variant;
+ float f = d;
+ if (double(f)!=d) {
+ if (buf) {
+ encode_double(p_variant.operator double(),buf);
+ }
+
+ r_len+=8;
+
+ } else {
+
+ if (buf) {
+ encode_double(p_variant.operator float(),buf);
+ }
+
+ r_len+=4;
}
- r_len+=4;
} break;
case Variant::NODE_PATH: {
@@ -942,10 +1004,10 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len+=3*4;
} break;
- case Variant::MATRIX32: {
+ case Variant::TRANSFORM2D: {
if (buf) {
- Matrix32 val=p_variant;
+ Transform2D val=p_variant;
for(int i=0;i<3;i++) {
for(int j=0;j<2;j++) {
@@ -984,10 +1046,10 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len+=4*4;
} break;
- case Variant::_AABB: {
+ case Variant::RECT3: {
if (buf) {
- AABB aabb=p_variant;
+ Rect3 aabb=p_variant;
encode_float(aabb.pos.x,&buf[0]);
encode_float(aabb.pos.y,&buf[4]);
encode_float(aabb.pos.z,&buf[8]);
@@ -1000,10 +1062,10 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
} break;
- case Variant::MATRIX3: {
+ case Variant::BASIS: {
if (buf) {
- Matrix3 val=p_variant;
+ Basis val=p_variant;
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
@@ -1055,17 +1117,17 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
case Variant::IMAGE: {
Image image = p_variant;
- DVector<uint8_t> data=image.get_data();
+ PoolVector<uint8_t> data=image.get_data();
if (buf) {
encode_uint32(image.get_format(),&buf[0]);
- encode_uint32(image.get_mipmaps(),&buf[4]);
+ encode_uint32(image.has_mipmaps(),&buf[4]);
encode_uint32(image.get_width(),&buf[8]);
encode_uint32(image.get_height(),&buf[12]);
int ds=data.size();
encode_uint32(ds,&buf[16]);
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
copymem(&buf[20],&r[0],ds);
}
@@ -1130,7 +1192,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
}
llen+=4;
} break;
- case InputEvent::JOYSTICK_BUTTON: {
+ case InputEvent::JOYPAD_BUTTON: {
if (buf) {
@@ -1146,7 +1208,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
}
llen+=4;
} break;
- case InputEvent::JOYSTICK_MOTION: {
+ case InputEvent::JOYPAD_MOTION: {
if (buf) {
@@ -1170,7 +1232,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
Dictionary d = p_variant;
if (buf) {
- encode_uint32(uint32_t(d.size())|(d.is_shared()?0x80000000:0),buf);
+ encode_uint32(uint32_t(d.size()),buf);
buf+=4;
}
r_len+=4;
@@ -1213,7 +1275,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
Array v = p_variant;
if (buf) {
- encode_uint32(uint32_t(v.size())|(v.is_shared()?0x80000000:0),buf);
+ encode_uint32(uint32_t(v.size()),buf);
buf+=4;
}
@@ -1232,16 +1294,16 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
} break;
// arrays
- case Variant::RAW_ARRAY: {
+ case Variant::POOL_BYTE_ARRAY: {
- DVector<uint8_t> data = p_variant;
+ PoolVector<uint8_t> data = p_variant;
int datalen=data.size();
int datasize=sizeof(uint8_t);
if (buf) {
encode_uint32(datalen,buf);
buf+=4;
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
copymem(buf,&r[0],datalen*datasize);
}
@@ -1251,16 +1313,16 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len++;
} break;
- case Variant::INT_ARRAY: {
+ case Variant::POOL_INT_ARRAY: {
- DVector<int> data = p_variant;
+ PoolVector<int> data = p_variant;
int datalen=data.size();
int datasize=sizeof(int32_t);
if (buf) {
encode_uint32(datalen,buf);
buf+=4;
- DVector<int>::Read r = data.read();
+ PoolVector<int>::Read r = data.read();
for(int i=0;i<datalen;i++)
encode_uint32(r[i],&buf[i*datasize]);
@@ -1269,16 +1331,16 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len+=4+datalen*datasize;
} break;
- case Variant::REAL_ARRAY: {
+ case Variant::POOL_REAL_ARRAY: {
- DVector<real_t> data = p_variant;
+ PoolVector<real_t> data = p_variant;
int datalen=data.size();
int datasize=sizeof(real_t);
if (buf) {
encode_uint32(datalen,buf);
buf+=4;
- DVector<real_t>::Read r = data.read();
+ PoolVector<real_t>::Read r = data.read();
for(int i=0;i<datalen;i++)
encode_float(r[i],&buf[i*datasize]);
@@ -1287,10 +1349,10 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len+=4+datalen*datasize;
} break;
- case Variant::STRING_ARRAY: {
+ case Variant::POOL_STRING_ARRAY: {
- DVector<String> data = p_variant;
+ PoolVector<String> data = p_variant;
int len=data.size();
if (buf) {
@@ -1321,9 +1383,9 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
}
} break;
- case Variant::VECTOR2_ARRAY: {
+ case Variant::POOL_VECTOR2_ARRAY: {
- DVector<Vector2> data = p_variant;
+ PoolVector<Vector2> data = p_variant;
int len=data.size();
if (buf) {
@@ -1349,9 +1411,9 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len+=4*2*len;
} break;
- case Variant::VECTOR3_ARRAY: {
+ case Variant::POOL_VECTOR3_ARRAY: {
- DVector<Vector3> data = p_variant;
+ PoolVector<Vector3> data = p_variant;
int len=data.size();
if (buf) {
@@ -1378,9 +1440,9 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) {
r_len+=4*3*len;
} break;
- case Variant::COLOR_ARRAY: {
+ case Variant::POOL_COLOR_ARRAY: {
- DVector<Color> data = p_variant;
+ PoolVector<Color> data = p_variant;
int len=data.size();
if (buf) {
diff --git a/core/io/marshalls.h b/core/io/marshalls.h
index 6a46e9882a..f04ec9a256 100644
--- a/core/io/marshalls.h
+++ b/core/io/marshalls.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/networked_multiplayer_peer.cpp b/core/io/networked_multiplayer_peer.cpp
index 47e5f3729c..6133401a8c 100644
--- a/core/io/networked_multiplayer_peer.cpp
+++ b/core/io/networked_multiplayer_peer.cpp
@@ -3,18 +3,18 @@
void NetworkedMultiplayerPeer::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_transfer_mode","mode"), &NetworkedMultiplayerPeer::set_transfer_mode );
- ObjectTypeDB::bind_method(_MD("set_target_peer","id"), &NetworkedMultiplayerPeer::set_target_peer );
+ ClassDB::bind_method(_MD("set_transfer_mode","mode"), &NetworkedMultiplayerPeer::set_transfer_mode );
+ ClassDB::bind_method(_MD("set_target_peer","id"), &NetworkedMultiplayerPeer::set_target_peer );
- ObjectTypeDB::bind_method(_MD("get_packet_peer"), &NetworkedMultiplayerPeer::get_packet_peer );
+ ClassDB::bind_method(_MD("get_packet_peer"), &NetworkedMultiplayerPeer::get_packet_peer );
- ObjectTypeDB::bind_method(_MD("poll"), &NetworkedMultiplayerPeer::poll );
+ ClassDB::bind_method(_MD("poll"), &NetworkedMultiplayerPeer::poll );
- ObjectTypeDB::bind_method(_MD("get_connection_status"), &NetworkedMultiplayerPeer::get_connection_status );
- ObjectTypeDB::bind_method(_MD("get_unique_id"), &NetworkedMultiplayerPeer::get_unique_id );
+ ClassDB::bind_method(_MD("get_connection_status"), &NetworkedMultiplayerPeer::get_connection_status );
+ ClassDB::bind_method(_MD("get_unique_id"), &NetworkedMultiplayerPeer::get_unique_id );
- ObjectTypeDB::bind_method(_MD("set_refuse_new_connections","enable"), &NetworkedMultiplayerPeer::set_refuse_new_connections );
- ObjectTypeDB::bind_method(_MD("is_refusing_new_connections"), &NetworkedMultiplayerPeer::is_refusing_new_connections );
+ ClassDB::bind_method(_MD("set_refuse_new_connections","enable"), &NetworkedMultiplayerPeer::set_refuse_new_connections );
+ ClassDB::bind_method(_MD("is_refusing_new_connections"), &NetworkedMultiplayerPeer::is_refusing_new_connections );
BIND_CONSTANT( TRANSFER_MODE_UNRELIABLE );
BIND_CONSTANT( TRANSFER_MODE_UNRELIABLE_ORDERED );
diff --git a/core/io/networked_multiplayer_peer.h b/core/io/networked_multiplayer_peer.h
index 485200a9a9..a59d9367d1 100644
--- a/core/io/networked_multiplayer_peer.h
+++ b/core/io/networked_multiplayer_peer.h
@@ -5,7 +5,7 @@
class NetworkedMultiplayerPeer : public PacketPeer {
- OBJ_TYPE(NetworkedMultiplayerPeer,PacketPeer);
+ GDCLASS(NetworkedMultiplayerPeer,PacketPeer);
protected:
static void _bind_methods();
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index 8e96697ac9..5ff09f9fb0 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -39,7 +39,7 @@ PacketPeer::PacketPeer() {
last_get_error=OK;
}
-Error PacketPeer::get_packet_buffer(DVector<uint8_t> &r_buffer) const {
+Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) const {
const uint8_t *buffer;
int buffer_size;
@@ -51,7 +51,7 @@ Error PacketPeer::get_packet_buffer(DVector<uint8_t> &r_buffer) const {
if (buffer_size==0)
return OK;
- DVector<uint8_t>::Write w = r_buffer.write();
+ PoolVector<uint8_t>::Write w = r_buffer.write();
for(int i=0;i<buffer_size;i++)
w[i]=buffer[i];
@@ -59,13 +59,13 @@ Error PacketPeer::get_packet_buffer(DVector<uint8_t> &r_buffer) const {
}
-Error PacketPeer::put_packet_buffer(const DVector<uint8_t> &p_buffer) {
+Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) {
int len = p_buffer.size();
if (len==0)
return OK;
- DVector<uint8_t>::Read r = p_buffer.read();
+ PoolVector<uint8_t>::Read r = p_buffer.read();
return put_packet(&r[0],len);
}
@@ -108,12 +108,12 @@ Variant PacketPeer::_bnd_get_var() const {
return var;
};
-Error PacketPeer::_put_packet(const DVector<uint8_t> &p_buffer) {
+Error PacketPeer::_put_packet(const PoolVector<uint8_t> &p_buffer) {
return put_packet_buffer(p_buffer);
}
-DVector<uint8_t> PacketPeer::_get_packet() const {
+PoolVector<uint8_t> PacketPeer::_get_packet() const {
- DVector<uint8_t> raw;
+ PoolVector<uint8_t> raw;
last_get_error=get_packet_buffer(raw);
return raw;
}
@@ -126,12 +126,12 @@ Error PacketPeer::_get_packet_error() const {
void PacketPeer::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("get_var:Variant"),&PacketPeer::_bnd_get_var);
- ObjectTypeDB::bind_method(_MD("put_var", "var:Variant"),&PacketPeer::put_var);
- ObjectTypeDB::bind_method(_MD("get_packet"),&PacketPeer::_get_packet);
- ObjectTypeDB::bind_method(_MD("put_packet:Error", "buffer"),&PacketPeer::_put_packet);
- ObjectTypeDB::bind_method(_MD("get_packet_error:Error"),&PacketPeer::_get_packet_error);
- ObjectTypeDB::bind_method(_MD("get_available_packet_count"),&PacketPeer::get_available_packet_count);
+ ClassDB::bind_method(_MD("get_var:Variant"),&PacketPeer::_bnd_get_var);
+ ClassDB::bind_method(_MD("put_var", "var:Variant"),&PacketPeer::put_var);
+ ClassDB::bind_method(_MD("get_packet"),&PacketPeer::_get_packet);
+ ClassDB::bind_method(_MD("put_packet:Error", "buffer"),&PacketPeer::_put_packet);
+ ClassDB::bind_method(_MD("get_packet_error:Error"),&PacketPeer::_get_packet_error);
+ ClassDB::bind_method(_MD("get_available_packet_count"),&PacketPeer::get_available_packet_count);
};
/***************/
@@ -145,7 +145,7 @@ void PacketPeerStream::_set_stream_peer(REF p_peer) {
void PacketPeerStream::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_stream_peer","peer:StreamPeer"),&PacketPeerStream::_set_stream_peer);
+ ClassDB::bind_method(_MD("set_stream_peer","peer:StreamPeer"),&PacketPeerStream::_set_stream_peer);
}
Error PacketPeerStream::_poll_buffer() const {
@@ -265,7 +265,8 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {
PacketPeerStream::PacketPeerStream() {
- int rbsize=GLOBAL_DEF( "core/packet_stream_peer_max_buffer_po2",(16));
+ int rbsize=GLOBAL_GET( "network/packets/packet_stream_peer_max_buffer_po2");
+
ring_buffer.resize(rbsize);
temp_buffer.resize(1<<rbsize);
diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h
index b29fc22af0..bacd5214f1 100644
--- a/core/io/packet_peer.h
+++ b/core/io/packet_peer.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,7 +34,7 @@
#include "ring_buffer.h"
class PacketPeer : public Reference {
- OBJ_TYPE( PacketPeer, Reference );
+ GDCLASS( PacketPeer, Reference );
Variant _bnd_get_var() const;
void _bnd_put_var(const Variant& p_var);
@@ -42,8 +42,8 @@ class PacketPeer : public Reference {
static void _bind_methods();
- Error _put_packet(const DVector<uint8_t> &p_buffer);
- DVector<uint8_t> _get_packet() const;
+ Error _put_packet(const PoolVector<uint8_t> &p_buffer);
+ PoolVector<uint8_t> _get_packet() const;
Error _get_packet_error() const;
@@ -59,8 +59,8 @@ public:
/* helpers / binders */
- virtual Error get_packet_buffer(DVector<uint8_t> &r_buffer) const;
- virtual Error put_packet_buffer(const DVector<uint8_t> &p_buffer);
+ virtual Error get_packet_buffer(PoolVector<uint8_t> &r_buffer) const;
+ virtual Error put_packet_buffer(const PoolVector<uint8_t> &p_buffer);
virtual Error get_var(Variant &r_variant) const;
virtual Error put_var(const Variant& p_packet);
@@ -71,7 +71,7 @@ public:
class PacketPeerStream : public PacketPeer {
- OBJ_TYPE(PacketPeerStream,PacketPeer);
+ GDCLASS(PacketPeerStream,PacketPeer);
//the way the buffers work sucks, will change later
@@ -92,6 +92,8 @@ public:
virtual int get_max_packet_size() const;
+
+
void set_stream_peer(const Ref<StreamPeer>& p_peer);
void set_input_buffer_max_size(int p_max_size);
PacketPeerStream();
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp
index efc619e414..9fec807bfb 100644
--- a/core/io/packet_peer_udp.cpp
+++ b/core/io/packet_peer_udp.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,45 +29,44 @@
#include "packet_peer_udp.h"
#include "io/ip.h"
-
PacketPeerUDP* (*PacketPeerUDP::_create)()=NULL;
-int PacketPeerUDP::_get_packet_address() const {
-
- IP_Address ip = get_packet_address();
- return ip.host;
-}
-
String PacketPeerUDP::_get_packet_ip() const {
return get_packet_address();
}
-Error PacketPeerUDP::_set_send_address(const String& p_address,int p_port) {
+Error PacketPeerUDP::_set_dest_address(const String& p_address, int p_port) {
IP_Address ip;
if (p_address.is_valid_ip_address()) {
ip=p_address;
} else {
- ip=IP::get_singleton()->resolve_hostname(p_address);
+ ip=IP::get_singleton()->resolve_hostname(p_address, ip_type);
if (ip==IP_Address())
return ERR_CANT_RESOLVE;
}
- set_send_address(ip,p_port);
+ set_dest_address(ip,p_port);
return OK;
}
+void PacketPeerUDP::set_ip_type(IP::Type p_type) {
+ close();
+ ip_type = p_type;
+}
+
void PacketPeerUDP::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("listen:Error","port","recv_buf_size"),&PacketPeerUDP::listen,DEFVAL(65536));
- ObjectTypeDB::bind_method(_MD("close"),&PacketPeerUDP::close);
- ObjectTypeDB::bind_method(_MD("wait:Error"),&PacketPeerUDP::wait);
- ObjectTypeDB::bind_method(_MD("is_listening"),&PacketPeerUDP::is_listening);
- ObjectTypeDB::bind_method(_MD("get_packet_ip"),&PacketPeerUDP::_get_packet_ip);
- ObjectTypeDB::bind_method(_MD("get_packet_address"),&PacketPeerUDP::_get_packet_address);
- ObjectTypeDB::bind_method(_MD("get_packet_port"),&PacketPeerUDP::get_packet_port);
- ObjectTypeDB::bind_method(_MD("set_send_address","host","port"),&PacketPeerUDP::_set_send_address);
+ ClassDB::bind_method(_MD("set_ip_type","ip_type"),&PacketPeerUDP::set_ip_type);
+ ClassDB::bind_method(_MD("listen:Error","port", "recv_buf_size"),&PacketPeerUDP::listen,DEFVAL(65536));
+ ClassDB::bind_method(_MD("close"),&PacketPeerUDP::close);
+ ClassDB::bind_method(_MD("wait:Error"),&PacketPeerUDP::wait);
+ ClassDB::bind_method(_MD("is_listening"),&PacketPeerUDP::is_listening);
+ ClassDB::bind_method(_MD("get_packet_ip"),&PacketPeerUDP::_get_packet_ip);
+ //ClassDB::bind_method(_MD("get_packet_address"),&PacketPeerUDP::_get_packet_address);
+ ClassDB::bind_method(_MD("get_packet_port"),&PacketPeerUDP::get_packet_port);
+ ClassDB::bind_method(_MD("set_dest_address","host","port"),&PacketPeerUDP::_set_dest_address);
}
@@ -88,4 +87,5 @@ PacketPeerUDP* PacketPeerUDP::create() {
PacketPeerUDP::PacketPeerUDP()
{
+ ip_type = IP::TYPE_ANY;
}
diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h
index 70d92834fc..17952b4ac1 100644
--- a/core/io/packet_peer_udp.h
+++ b/core/io/packet_peer_udp.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,30 +30,33 @@
#define PACKET_PEER_UDP_H
+#include "io/ip.h"
#include "io/packet_peer.h"
class PacketPeerUDP : public PacketPeer {
- OBJ_TYPE(PacketPeerUDP,PacketPeer);
+ GDCLASS(PacketPeerUDP,PacketPeer);
protected:
+ IP::Type ip_type;
+
static PacketPeerUDP* (*_create)();
static void _bind_methods();
- int _get_packet_address() const;
String _get_packet_ip() const;
- virtual Error _set_send_address(const String& p_address,int p_port);
+ virtual Error _set_dest_address(const String& p_address,int p_port);
public:
- virtual Error listen(int p_port,int p_recv_buffer_size=65536)=0;
+ virtual void set_ip_type(IP::Type p_type);
+ virtual Error listen(int p_port, int p_recv_buffer_size=65536)=0;
virtual void close()=0;
virtual Error wait()=0;
virtual bool is_listening() const=0;
virtual IP_Address get_packet_address() const=0;
virtual int get_packet_port() const=0;
- virtual void set_send_address(const IP_Address& p_address,int p_port)=0;
+ virtual void set_dest_address(const IP_Address& p_address,int p_port)=0;
static Ref<PacketPeerUDP> create_ref();
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
new file mode 100644
index 0000000000..a9f357a7c8
--- /dev/null
+++ b/core/io/pck_packer.cpp
@@ -0,0 +1,191 @@
+/*************************************************************************/
+/* pkc_packer.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#include "pck_packer.h"
+
+#include "core/os/file_access.h"
+
+static uint64_t _align(uint64_t p_n, int p_alignment) {
+
+ if (p_alignment == 0)
+ return p_n;
+
+ uint64_t rest = p_n % p_alignment;
+ if (rest == 0)
+ return p_n;
+ else
+ return p_n + (p_alignment - rest);
+};
+
+static void _pad(FileAccess* p_file, int p_bytes) {
+
+ for (int i=0; i<p_bytes; i++) {
+
+ p_file->store_8(0);
+ };
+};
+
+void PCKPacker::_bind_methods() {
+
+ ClassDB::bind_method(_MD("pck_start","pck_name","alignment"),&PCKPacker::pck_start);
+ ClassDB::bind_method(_MD("add_file","pck_path","source_path"),&PCKPacker::add_file);
+ ClassDB::bind_method(_MD("flush","verbose"),&PCKPacker::flush);
+};
+
+
+Error PCKPacker::pck_start(const String& p_file, int p_alignment) {
+
+ file = FileAccess::open(p_file, FileAccess::WRITE);
+ if (file == NULL) {
+
+ return ERR_CANT_CREATE;
+ };
+
+ alignment = p_alignment;
+
+ file->store_32(0x43504447); // MAGIC
+ file->store_32(0); // # version
+ file->store_32(0); // # major
+ file->store_32(0); // # minor
+ file->store_32(0); // # revision
+
+ for (int i=0; i<16; i++) {
+
+ file->store_32(0); // reserved
+ };
+
+ files.clear();
+
+ return OK;
+};
+
+Error PCKPacker::add_file(const String& p_file, const String& p_src) {
+
+ FileAccess* f = FileAccess::open(p_src, FileAccess::READ);
+ if (!f) {
+ return ERR_FILE_CANT_OPEN;
+ };
+
+ File pf;
+ pf.path = p_file;
+ pf.src_path = p_src;
+ pf.size = f->get_len();
+ pf.offset_offset = 0;
+
+ files.push_back(pf);
+
+ f->close();
+ memdelete(f);
+
+ return OK;
+};
+
+Error PCKPacker::flush(bool p_verbose) {
+
+ if (!file) {
+ ERR_FAIL_COND_V(!file, ERR_INVALID_PARAMETER);
+ return ERR_INVALID_PARAMETER;
+ };
+
+ // write the index
+
+ file->store_32(files.size());
+
+ for (int i=0; i<files.size(); i++) {
+
+ file->store_pascal_string(files[i].path);
+ files[i].offset_offset = file->get_pos();
+ file->store_64(0); // offset
+ file->store_64(files[i].size); // size
+
+ // # empty md5
+ file->store_32(0);
+ file->store_32(0);
+ file->store_32(0);
+ file->store_32(0);
+ };
+
+
+ uint64_t ofs = file->get_pos();
+ ofs = _align(ofs, alignment);
+
+ _pad(file, ofs - file->get_pos());
+
+ const uint32_t buf_max = 65536;
+ uint8_t *buf = memnew_arr(uint8_t, buf_max);
+
+ int count = 0;
+ for (int i=0; i<files.size(); i++) {
+
+ FileAccess* src = FileAccess::open(files[i].src_path, FileAccess::READ);
+ uint64_t to_write = files[i].size;
+ while (to_write > 0) {
+
+ int read = src->get_buffer(buf, MIN(to_write, buf_max));
+ file->store_buffer(buf, read);
+ to_write -= read;
+ };
+
+ uint64_t pos = file->get_pos();
+ file->seek(files[i].offset_offset); // go back to store the file's offset
+ file->store_64(ofs);
+ file->seek(pos);
+
+ ofs = _align(ofs + files[i].size, alignment);
+ _pad(file, ofs - pos);
+
+ src->close();
+ memdelete(src);
+ count += 1;
+ if (p_verbose) {
+ if (count % 100 == 0) {
+ printf("%i/%i (%.2f)\r", count, files.size(), float(count) / files.size() * 100);
+ fflush(stdout);
+ };
+ };
+ };
+
+ if (p_verbose)
+ printf("\n");
+
+ file->close();
+
+ return OK;
+};
+
+PCKPacker::PCKPacker() {
+
+ file = NULL;
+};
+
+PCKPacker::~PCKPacker() {
+ if (file != NULL) {
+ memdelete(file);
+ };
+ file = NULL;
+};
diff --git a/core/os/memory_pool_dynamic.cpp b/core/io/pck_packer.h
index 6be8d0a36d..a4eba04f2d 100644
--- a/core/os/memory_pool_dynamic.cpp
+++ b/core/io/pck_packer.h
@@ -1,11 +1,11 @@
/*************************************************************************/
-/* memory_pool_dynamic.cpp */
+/* pck_packer.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -26,25 +26,34 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "memory_pool_dynamic.h"
+#include "core/reference.h"
+class FileAccess;
-MemoryPoolDynamic* MemoryPoolDynamic::singleton=NULL;
+class PCKPacker : public Reference {
+ GDCLASS(PCKPacker, Reference);
-MemoryPoolDynamic* MemoryPoolDynamic::get_singleton() {
+ FileAccess* file;
+ int alignment;
- return singleton;
-}
+ static void _bind_methods();
+ struct File {
-MemoryPoolDynamic::MemoryPoolDynamic() {
+ String path;
+ String src_path;
+ int size;
+ uint64_t offset_offset;
+ };
+ Vector<File> files;
- ERR_FAIL_COND(singleton!=NULL);
- singleton=this;
-}
+public:
+ Error pck_start(const String& p_file, int p_alignment);
+ Error add_file(const String& p_file, const String& p_src);
+ Error flush(bool p_verbose = false);
-MemoryPoolDynamic::~MemoryPoolDynamic() {
- singleton=NULL;
-}
+ PCKPacker();
+ ~PCKPacker();
+};
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 0544fd6ba8..4af3503434 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -68,35 +68,14 @@ enum {
VARIANT_VECTOR3_ARRAY=35,
VARIANT_COLOR_ARRAY=36,
VARIANT_VECTOR2_ARRAY=37,
+ VARIANT_INT64=40,
+ VARIANT_DOUBLE=41,
IMAGE_ENCODING_EMPTY=0,
IMAGE_ENCODING_RAW=1,
IMAGE_ENCODING_LOSSLESS=2,
IMAGE_ENCODING_LOSSY=3,
- IMAGE_FORMAT_GRAYSCALE=0,
- IMAGE_FORMAT_INTENSITY=1,
- IMAGE_FORMAT_GRAYSCALE_ALPHA=2,
- IMAGE_FORMAT_RGB=3,
- IMAGE_FORMAT_RGBA=4,
- IMAGE_FORMAT_INDEXED=5,
- IMAGE_FORMAT_INDEXED_ALPHA=6,
- IMAGE_FORMAT_BC1=7,
- IMAGE_FORMAT_BC2=8,
- IMAGE_FORMAT_BC3=9,
- IMAGE_FORMAT_BC4=10,
- IMAGE_FORMAT_BC5=11,
- IMAGE_FORMAT_PVRTC2=12,
- IMAGE_FORMAT_PVRTC2_ALPHA=13,
- IMAGE_FORMAT_PVRTC4=14,
- IMAGE_FORMAT_PVRTC4_ALPHA=15,
- IMAGE_FORMAT_ETC=16,
- IMAGE_FORMAT_ATC=17,
- IMAGE_FORMAT_ATC_ALPHA_EXPLICIT=18,
- IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED=19,
- IMAGE_FORMAT_CUSTOM=30,
-
-
OBJECT_EMPTY=0,
OBJECT_EXTERNAL_RESOURCE=1,
OBJECT_INTERNAL_RESOURCE=2,
@@ -139,10 +118,18 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
r_v=int(f->get_32());
} break;
+ case VARIANT_INT64: {
+
+ r_v=int64_t(f->get_64());
+ } break;
case VARIANT_REAL: {
r_v=f->get_real();
} break;
+ case VARIANT_DOUBLE: {
+
+ r_v=f->get_double();
+ } break;
case VARIANT_STRING: {
r_v=get_unicode_string();
@@ -193,7 +180,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
} break;
case VARIANT_AABB: {
- AABB v;
+ Rect3 v;
v.pos.x=f->get_real();
v.pos.y=f->get_real();
v.pos.z=f->get_real();
@@ -205,7 +192,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
} break;
case VARIANT_MATRIX32: {
- Matrix32 v;
+ Transform2D v;
v.elements[0].x=f->get_real();
v.elements[0].y=f->get_real();
v.elements[1].x=f->get_real();
@@ -217,7 +204,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
} break;
case VARIANT_MATRIX3: {
- Matrix3 v;
+ Basis v;
v.elements[0].x=f->get_real();
v.elements[0].y=f->get_real();
v.elements[0].z=f->get_real();
@@ -269,56 +256,40 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t height = f->get_32();
uint32_t mipmaps = f->get_32();
uint32_t format = f->get_32();
- Image::Format fmt;
- switch(format) {
-
- case IMAGE_FORMAT_GRAYSCALE: { fmt=Image::FORMAT_GRAYSCALE; } break;
- case IMAGE_FORMAT_INTENSITY: { fmt=Image::FORMAT_INTENSITY; } break;
- case IMAGE_FORMAT_GRAYSCALE_ALPHA: { fmt=Image::FORMAT_GRAYSCALE_ALPHA; } break;
- case IMAGE_FORMAT_RGB: { fmt=Image::FORMAT_RGB; } break;
- case IMAGE_FORMAT_RGBA: { fmt=Image::FORMAT_RGBA; } break;
- case IMAGE_FORMAT_INDEXED: { fmt=Image::FORMAT_INDEXED; } break;
- case IMAGE_FORMAT_INDEXED_ALPHA: { fmt=Image::FORMAT_INDEXED_ALPHA; } break;
- case IMAGE_FORMAT_BC1: { fmt=Image::FORMAT_BC1; } break;
- case IMAGE_FORMAT_BC2: { fmt=Image::FORMAT_BC2; } break;
- case IMAGE_FORMAT_BC3: { fmt=Image::FORMAT_BC3; } break;
- case IMAGE_FORMAT_BC4: { fmt=Image::FORMAT_BC4; } break;
- case IMAGE_FORMAT_BC5: { fmt=Image::FORMAT_BC5; } break;
- case IMAGE_FORMAT_PVRTC2: { fmt=Image::FORMAT_PVRTC2; } break;
- case IMAGE_FORMAT_PVRTC2_ALPHA: { fmt=Image::FORMAT_PVRTC2_ALPHA; } break;
- case IMAGE_FORMAT_PVRTC4: { fmt=Image::FORMAT_PVRTC4; } break;
- case IMAGE_FORMAT_PVRTC4_ALPHA: { fmt=Image::FORMAT_PVRTC4_ALPHA; } break;
- case IMAGE_FORMAT_ETC: { fmt=Image::FORMAT_ETC; } break;
- case IMAGE_FORMAT_ATC: { fmt=Image::FORMAT_ATC; } break;
- case IMAGE_FORMAT_ATC_ALPHA_EXPLICIT: { fmt=Image::FORMAT_ATC_ALPHA_EXPLICIT; } break;
- case IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED: { fmt=Image::FORMAT_ATC_ALPHA_INTERPOLATED; } break;
- case IMAGE_FORMAT_CUSTOM: { fmt=Image::FORMAT_CUSTOM; } break;
- default: {
-
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- }
+ const uint32_t format_version_shift=24;
+ const uint32_t format_version_mask=format_version_shift-1;
+ uint32_t format_version = format>>format_version_shift;
+
+ const uint32_t current_version = 0;
+ if (format_version>current_version) {
+
+ ERR_PRINT("Format version for encoded binary image is too new");
+ return ERR_PARSE_ERROR;
}
+ Image::Format fmt=Image::Format(format&format_version_mask); //if format changes, we can add a compatibility bit on top
+
+
uint32_t datalen = f->get_32();
- DVector<uint8_t> imgdata;
+ PoolVector<uint8_t> imgdata;
imgdata.resize(datalen);
- DVector<uint8_t>::Write w = imgdata.write();
+ PoolVector<uint8_t>::Write w = imgdata.write();
f->get_buffer(w.ptr(),datalen);
_advance_padding(datalen);
- w=DVector<uint8_t>::Write();
+ w=PoolVector<uint8_t>::Write();
r_v=Image(width,height,mipmaps,fmt,imgdata);
} else {
//compressed
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
data.resize(f->get_32());
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
f->get_buffer(w.ptr(),data.size());
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
Image img;
@@ -394,7 +365,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
if (path.find("://")==-1 && path.is_rel_path()) {
// path is relative to file being loaded, so convert to a resource path
- path=Globals::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
+ path=GlobalConfig::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
}
@@ -424,7 +395,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
if (path.find("://")==-1 && path.is_rel_path()) {
// path is relative to file being loaded, so convert to a resource path
- path=Globals::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
+ path=GlobalConfig::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
}
@@ -455,7 +426,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
case VARIANT_DICTIONARY: {
uint32_t len=f->get_32();
- Dictionary d(len&0x80000000); //last bit means shared
+ Dictionary d; //last bit means shared
len&=0x7FFFFFFF;
for(uint32_t i=0;i<len;i++) {
Variant key;
@@ -471,7 +442,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
case VARIANT_ARRAY: {
uint32_t len=f->get_32();
- Array a(len&0x80000000); //last bit means shared
+ Array a; //last bit means shared
len&=0x7FFFFFFF;
a.resize(len);
for(uint32_t i=0;i<len;i++) {
@@ -487,12 +458,12 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<uint8_t> array;
+ PoolVector<uint8_t> array;
array.resize(len);
- DVector<uint8_t>::Write w = array.write();
+ PoolVector<uint8_t>::Write w = array.write();
f->get_buffer(w.ptr(),len);
_advance_padding(len);
- w=DVector<uint8_t>::Write();
+ w=PoolVector<uint8_t>::Write();
r_v=array;
} break;
@@ -500,9 +471,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<int> array;
+ PoolVector<int> array;
array.resize(len);
- DVector<int>::Write w = array.write();
+ PoolVector<int>::Write w = array.write();
f->get_buffer((uint8_t*)w.ptr(),len*4);
#ifdef BIG_ENDIAN_ENABLED
{
@@ -514,16 +485,16 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
}
#endif
- w=DVector<int>::Write();
+ w=PoolVector<int>::Write();
r_v=array;
} break;
case VARIANT_REAL_ARRAY: {
uint32_t len = f->get_32();
- DVector<real_t> array;
+ PoolVector<real_t> array;
array.resize(len);
- DVector<real_t>::Write w = array.write();
+ PoolVector<real_t>::Write w = array.write();
f->get_buffer((uint8_t*)w.ptr(),len*sizeof(real_t));
#ifdef BIG_ENDIAN_ENABLED
{
@@ -536,18 +507,18 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
#endif
- w=DVector<real_t>::Write();
+ w=PoolVector<real_t>::Write();
r_v=array;
} break;
case VARIANT_STRING_ARRAY: {
uint32_t len = f->get_32();
- DVector<String> array;
+ PoolVector<String> array;
array.resize(len);
- DVector<String>::Write w = array.write();
+ PoolVector<String>::Write w = array.write();
for(uint32_t i=0;i<len;i++)
w[i]=get_unicode_string();
- w=DVector<String>::Write();
+ w=PoolVector<String>::Write();
r_v=array;
@@ -556,9 +527,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<Vector2> array;
+ PoolVector<Vector2> array;
array.resize(len);
- DVector<Vector2>::Write w = array.write();
+ PoolVector<Vector2>::Write w = array.write();
if (sizeof(Vector2)==8) {
f->get_buffer((uint8_t*)w.ptr(),len*sizeof(real_t)*2);
#ifdef BIG_ENDIAN_ENABLED
@@ -576,7 +547,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
ERR_EXPLAIN("Vector2 size is NOT 8!");
ERR_FAIL_V(ERR_UNAVAILABLE);
}
- w=DVector<Vector2>::Write();
+ w=PoolVector<Vector2>::Write();
r_v=array;
} break;
@@ -584,9 +555,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<Vector3> array;
+ PoolVector<Vector3> array;
array.resize(len);
- DVector<Vector3>::Write w = array.write();
+ PoolVector<Vector3>::Write w = array.write();
if (sizeof(Vector3)==12) {
f->get_buffer((uint8_t*)w.ptr(),len*sizeof(real_t)*3);
#ifdef BIG_ENDIAN_ENABLED
@@ -604,7 +575,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
ERR_EXPLAIN("Vector3 size is NOT 12!");
ERR_FAIL_V(ERR_UNAVAILABLE);
}
- w=DVector<Vector3>::Write();
+ w=PoolVector<Vector3>::Write();
r_v=array;
} break;
@@ -612,9 +583,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
uint32_t len = f->get_32();
- DVector<Color> array;
+ PoolVector<Color> array;
array.resize(len);
- DVector<Color>::Write w = array.write();
+ PoolVector<Color>::Write w = array.write();
if (sizeof(Color)==16) {
f->get_buffer((uint8_t*)w.ptr(),len*sizeof(real_t)*4);
#ifdef BIG_ENDIAN_ENABLED
@@ -632,7 +603,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
ERR_EXPLAIN("Color size is NOT 16!");
ERR_FAIL_V(ERR_UNAVAILABLE);
}
- w=DVector<Color>::Write();
+ w=PoolVector<Color>::Write();
r_v=array;
} break;
@@ -739,7 +710,7 @@ Error ResourceInteractiveLoaderBinary::poll(){
String t = get_unicode_string();
- Object *obj = ObjectTypeDB::instance(t);
+ Object *obj = ClassDB::instance(t);
if (!obj) {
error=ERR_FILE_CORRUPT;
ERR_EXPLAIN(local_path+":Resource of unrecognized type in file: "+t);
@@ -750,7 +721,7 @@ Error ResourceInteractiveLoaderBinary::poll(){
if (!r) {
error=ERR_FILE_CORRUPT;
memdelete(obj); //bye
- ERR_EXPLAIN(local_path+":Resoucre type in resource field not a resource, type is: "+obj->get_type());
+ ERR_EXPLAIN(local_path+":Resoucre type in resource field not a resource, type is: "+obj->get_class());
ERR_FAIL_COND_V(!r,ERR_FILE_CORRUPT);
}
@@ -1086,9 +1057,9 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(cons
}
Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
+ 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->set_local_path( Globals::get_singleton()->localize_path(p_path) );
ria->open(f);
@@ -1103,7 +1074,7 @@ void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String
}
List<String> extensions;
- ObjectTypeDB::get_extensions_for_type(p_type,&extensions);
+ ClassDB::get_extensions_for_type(p_type,&extensions);
extensions.sort();
@@ -1116,7 +1087,7 @@ void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String
void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_extensions) const{
List<String> extensions;
- ObjectTypeDB::get_resource_base_extensions(&extensions);
+ ClassDB::get_resource_base_extensions(&extensions);
extensions.sort();
for(List<String>::Element *E=extensions.front();E;E=E->next()) {
@@ -1141,9 +1112,9 @@ Error ResourceFormatLoaderBinary::load_import_metadata(const String &p_path, Ref
}
Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
+ 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->set_local_path( Globals::get_singleton()->localize_path(p_path) );
ria->recognize(f);
if(ria->error!=OK)
return ERR_FILE_UNRECOGNIZED;
@@ -1186,16 +1157,16 @@ void ResourceFormatLoaderBinary::get_dependencies(const String& p_path,List<Stri
ERR_FAIL_COND(!f);
Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
+ 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->set_local_path( Globals::get_singleton()->localize_path(p_path) );
ria->get_dependencies(f,p_dependencies,p_add_types);
}
Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const Map<String,String>& p_map) {
-// Error error=OK;
+ //Error error=OK;
FileAccess *f=FileAccess::open(p_path,FileAccess::READ);
@@ -1276,10 +1247,10 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const
}
Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
+ ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
ria->res_path=ria->local_path;
ria->remaps=p_map;
- // ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
+ //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
ria->open(f);
err = ria->poll();
@@ -1411,9 +1382,9 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const
}
Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
+ 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->set_local_path( Globals::get_singleton()->localize_path(p_path) );
String r = ria->recognize(f);
return r;
@@ -1455,15 +1426,33 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
} break;
case Variant::INT: {
- f->store_32(VARIANT_INT);
- int val=p_property;
- f->store_32(val);
+ int64_t val = p_property;
+ if (val>0x7FFFFFFF || val < -0x80000000) {
+ f->store_32(VARIANT_INT64);
+ f->store_64(val);
+
+ } else {
+ f->store_32(VARIANT_INT);
+ int val=p_property;
+ f->store_32(int32_t(val));
+
+ }
+
} break;
case Variant::REAL: {
- f->store_32(VARIANT_REAL);
- real_t val=p_property;
- f->store_real(val);
+
+ double d = p_property;
+ float fl = d;
+ if (double(fl)!=d) {
+ f->store_32(VARIANT_DOUBLE);
+ f->store_double(d);
+ } else {
+
+ f->store_32(VARIANT_REAL);
+ f->store_real(fl);
+
+ }
} break;
case Variant::STRING: {
@@ -1520,10 +1509,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
f->store_real(val.w);
} break;
- case Variant::_AABB: {
+ case Variant::RECT3: {
f->store_32(VARIANT_AABB);
- AABB val=p_property;
+ Rect3 val=p_property;
f->store_real(val.pos.x);
f->store_real(val.pos.y);
f->store_real(val.pos.z);
@@ -1532,10 +1521,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
f->store_real(val.size.z);
} break;
- case Variant::MATRIX32: {
+ case Variant::TRANSFORM2D: {
f->store_32(VARIANT_MATRIX32);
- Matrix32 val=p_property;
+ Transform2D val=p_property;
f->store_real(val.elements[0].x);
f->store_real(val.elements[0].y);
f->store_real(val.elements[1].x);
@@ -1544,10 +1533,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
f->store_real(val.elements[2].y);
} break;
- case Variant::MATRIX3: {
+ case Variant::BASIS: {
f->store_32(VARIANT_MATRIX3);
- Matrix3 val=p_property;
+ Basis val=p_property;
f->store_real(val.elements[0].x);
f->store_real(val.elements[0].y);
f->store_real(val.elements[0].z);
@@ -1599,7 +1588,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
int encoding=IMAGE_ENCODING_RAW;
float quality=0.7;
- if (val.get_format() <= Image::FORMAT_INDEXED_ALPHA) {
+ if (!val.is_compressed()) {
//can only compress uncompressed stuff
if (p_hint.hint==PROPERTY_HINT_IMAGE_COMPRESS_LOSSY && Image::lossy_packer) {
@@ -1621,42 +1610,17 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
f->store_32(val.get_width());
f->store_32(val.get_height());
- f->store_32(val.get_mipmaps());
- switch(val.get_format()) {
-
- case Image::FORMAT_GRAYSCALE: f->store_32(IMAGE_FORMAT_GRAYSCALE ); break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
- case Image::FORMAT_INTENSITY: f->store_32(IMAGE_FORMAT_INTENSITY ); break; ///< one byte per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255
- case Image::FORMAT_GRAYSCALE_ALPHA: f->store_32(IMAGE_FORMAT_GRAYSCALE_ALPHA ); break; ///< two bytes per pixel: f->store_32(IMAGE_FORMAT_ ); break; 0-255. alpha 0-255
- case Image::FORMAT_RGB: f->store_32(IMAGE_FORMAT_RGB ); break; ///< one byte R: f->store_32(IMAGE_FORMAT_ ); break; one byte G: f->store_32(IMAGE_FORMAT_ ); break; one byte B
- case Image::FORMAT_RGBA: f->store_32(IMAGE_FORMAT_RGBA ); break; ///< one byte R: f->store_32(IMAGE_FORMAT_ ); break; one byte G: f->store_32(IMAGE_FORMAT_ ); break; one byte B: f->store_32(IMAGE_FORMAT_ ); break; one byte A
- case Image::FORMAT_INDEXED: f->store_32(IMAGE_FORMAT_INDEXED ); break; ///< index byte 0-256: f->store_32(IMAGE_FORMAT_ ); break; and after image end: f->store_32(IMAGE_FORMAT_ ); break; 256*3 bytes of palette
- case Image::FORMAT_INDEXED_ALPHA: f->store_32(IMAGE_FORMAT_INDEXED_ALPHA ); break; ///< index byte 0-256: f->store_32(IMAGE_FORMAT_ ); break; and after image end: f->store_32(IMAGE_FORMAT_ ); break; 256*4 bytes of palette (alpha)
- case Image::FORMAT_BC1: f->store_32(IMAGE_FORMAT_BC1 ); break; // DXT1
- case Image::FORMAT_BC2: f->store_32(IMAGE_FORMAT_BC2 ); break; // DXT3
- case Image::FORMAT_BC3: f->store_32(IMAGE_FORMAT_BC3 ); break; // DXT5
- case Image::FORMAT_BC4: f->store_32(IMAGE_FORMAT_BC4 ); break; // ATI1
- case Image::FORMAT_BC5: f->store_32(IMAGE_FORMAT_BC5 ); break; // ATI2
- case Image::FORMAT_PVRTC2: f->store_32(IMAGE_FORMAT_PVRTC2 ); break;
- case Image::FORMAT_PVRTC2_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC2_ALPHA ); break;
- case Image::FORMAT_PVRTC4: f->store_32(IMAGE_FORMAT_PVRTC4 ); break;
- case Image::FORMAT_PVRTC4_ALPHA: f->store_32(IMAGE_FORMAT_PVRTC4_ALPHA ); break;
- case Image::FORMAT_ETC: f->store_32(IMAGE_FORMAT_ETC); break;
- case Image::FORMAT_ATC: f->store_32(IMAGE_FORMAT_ATC); break;
- case Image::FORMAT_ATC_ALPHA_EXPLICIT: f->store_32(IMAGE_FORMAT_ATC_ALPHA_EXPLICIT); break;
- case Image::FORMAT_ATC_ALPHA_INTERPOLATED: f->store_32(IMAGE_FORMAT_ATC_ALPHA_INTERPOLATED); break;
- case Image::FORMAT_CUSTOM: f->store_32(IMAGE_FORMAT_CUSTOM ); break;
- default: {}
-
- }
+ f->store_32(val.has_mipmaps());
+ f->store_32(val.get_format()); //if format changes we can add a compatibility version bit
int dlen = val.get_data().size();
f->store_32(dlen);
- DVector<uint8_t>::Read r = val.get_data().read();
+ PoolVector<uint8_t>::Read r = val.get_data().read();
f->store_buffer(r.ptr(),dlen);
_pad_buffer(dlen);
} else {
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
if (encoding==IMAGE_ENCODING_LOSSY) {
data=Image::lossy_packer(val,quality);
@@ -1668,7 +1632,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
int ds=data.size();
f->store_32(ds);
if (ds>0) {
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
f->store_buffer(r.ptr(),ds);
_pad_buffer(ds);
@@ -1737,15 +1701,17 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
f->store_32(VARIANT_DICTIONARY);
Dictionary d = p_property;
- f->store_32(uint32_t(d.size())|(d.is_shared()?0x80000000:0));
+ f->store_32(uint32_t(d.size()));
List<Variant> keys;
d.get_key_list(&keys);
for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
- //if (!_check_type(dict[E->get()]))
- // continue;
+ /*
+ if (!_check_type(dict[E->get()]))
+ continue;
+ */
write_variant(E->get());
write_variant(d[E->get()]);
@@ -1757,66 +1723,66 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
f->store_32(VARIANT_ARRAY);
Array a=p_property;
- f->store_32(uint32_t(a.size())|(a.is_shared()?0x80000000:0));
+ f->store_32(uint32_t(a.size()));
for(int i=0;i<a.size();i++) {
write_variant(a[i]);
}
} break;
- case Variant::RAW_ARRAY: {
+ case Variant::POOL_BYTE_ARRAY: {
f->store_32(VARIANT_RAW_ARRAY);
- DVector<uint8_t> arr = p_property;
+ PoolVector<uint8_t> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<uint8_t>::Read r = arr.read();
+ PoolVector<uint8_t>::Read r = arr.read();
f->store_buffer(r.ptr(),len);
_pad_buffer(len);
} break;
- case Variant::INT_ARRAY: {
+ case Variant::POOL_INT_ARRAY: {
f->store_32(VARIANT_INT_ARRAY);
- DVector<int> arr = p_property;
+ PoolVector<int> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<int>::Read r = arr.read();
+ PoolVector<int>::Read r = arr.read();
for(int i=0;i<len;i++)
f->store_32(r[i]);
} break;
- case Variant::REAL_ARRAY: {
+ case Variant::POOL_REAL_ARRAY: {
f->store_32(VARIANT_REAL_ARRAY);
- DVector<real_t> arr = p_property;
+ PoolVector<real_t> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<real_t>::Read r = arr.read();
+ PoolVector<real_t>::Read r = arr.read();
for(int i=0;i<len;i++) {
f->store_real(r[i]);
}
} break;
- case Variant::STRING_ARRAY: {
+ case Variant::POOL_STRING_ARRAY: {
f->store_32(VARIANT_STRING_ARRAY);
- DVector<String> arr = p_property;
+ PoolVector<String> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<String>::Read r = arr.read();
+ PoolVector<String>::Read r = arr.read();
for(int i=0;i<len;i++) {
save_unicode_string(r[i]);
}
} break;
- case Variant::VECTOR3_ARRAY: {
+ case Variant::POOL_VECTOR3_ARRAY: {
f->store_32(VARIANT_VECTOR3_ARRAY);
- DVector<Vector3> arr = p_property;
+ PoolVector<Vector3> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<Vector3>::Read r = arr.read();
+ PoolVector<Vector3>::Read r = arr.read();
for(int i=0;i<len;i++) {
f->store_real(r[i].x);
f->store_real(r[i].y);
@@ -1824,26 +1790,26 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
}
} break;
- case Variant::VECTOR2_ARRAY: {
+ case Variant::POOL_VECTOR2_ARRAY: {
f->store_32(VARIANT_VECTOR2_ARRAY);
- DVector<Vector2> arr = p_property;
+ PoolVector<Vector2> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<Vector2>::Read r = arr.read();
+ PoolVector<Vector2>::Read r = arr.read();
for(int i=0;i<len;i++) {
f->store_real(r[i].x);
f->store_real(r[i].y);
}
} break;
- case Variant::COLOR_ARRAY: {
+ case Variant::POOL_COLOR_ARRAY: {
f->store_32(VARIANT_COLOR_ARRAY);
- DVector<Color> arr = p_property;
+ PoolVector<Color> arr = p_property;
int len=arr.size();
f->store_32(len);
- DVector<Color>::Read r = arr.read();
+ PoolVector<Color>::Read r = arr.read();
for(int i=0;i<len;i++) {
f->store_real(r[i].r);
f->store_real(r[i].g);
@@ -1889,7 +1855,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant& p_variant
for(List<PropertyInfo>::Element *E=property_list.front();E;E=E->next()) {
- if (E->get().usage&PROPERTY_USAGE_STORAGE || (bundle_resources && E->get().usage&PROPERTY_USAGE_BUNDLE)) {
+ if (E->get().usage&PROPERTY_USAGE_STORAGE) {
_find_resources(res->get(E->get().name));
}
@@ -2066,7 +2032,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
}
//f->store_32(saved_resources.size()+external_resources.size()); // load steps -not needed
- save_unicode_string(p_resource->get_type());
+ save_unicode_string(p_resource->get_class());
uint64_t md_at = f->get_pos();
f->store_64(0); //offset to impoty metadata
for(int i=0;i<14;i++)
@@ -2083,7 +2049,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
ResourceData &rd = resources.push_back(ResourceData())->get();
- rd.type=E->get()->get_type();
+ rd.type=E->get()->get_class();
List<PropertyInfo> property_list;
E->get()->get_property_list( &property_list );
@@ -2092,7 +2058,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
if (skip_editor && F->get().name.begins_with("__editor"))
continue;
- if (F->get().usage&PROPERTY_USAGE_STORAGE || (bundle_resources && F->get().usage&PROPERTY_USAGE_BUNDLE)) {
+ if (F->get().usage&PROPERTY_USAGE_STORAGE ) {
Property p;
p.name_idx=get_string_index(F->get().name);
p.value=E->get()->get(F->get().name);
@@ -2128,7 +2094,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
for(int i=0;i<save_order.size();i++) {
- save_unicode_string(save_order[i]->get_save_type());
+ save_unicode_string(save_order[i]->get_save_class());
String path = save_order[i]->get_path();
path=relative_paths?local_path.path_to_file(path):path;
save_unicode_string(path);
@@ -2186,7 +2152,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
}
Vector<uint64_t> ofs_table;
-// int saved_idx=0;
+ //int saved_idx=0;
//now actually save the resources
for(List<ResourceData>::Element *E=resources.front();E;E=E->next()) {
@@ -2256,7 +2222,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
Error ResourceFormatSaverBinary::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {
- String local_path = Globals::get_singleton()->localize_path(p_path);
+ String local_path = GlobalConfig::get_singleton()->localize_path(p_path);
ResourceFormatSaverBinaryInstance saver;
return saver.save(local_path,p_resource,p_flags);
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index b8be3080b8..611029e792 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp
deleted file mode 100644
index 44fbaf02ac..0000000000
--- a/core/io/resource_format_xml.cpp
+++ /dev/null
@@ -1,2889 +0,0 @@
-/*************************************************************************/
-/* resource_format_xml.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "resource_format_xml.h"
-#include "globals.h"
-#include "version.h"
-#include "os/dir_access.h"
-
-
-ResourceInteractiveLoaderXML::Tag* ResourceInteractiveLoaderXML::parse_tag(bool *r_exit, bool p_printerr, List<String> *r_order) {
-
-
- while(get_char()!='<' && !f->eof_reached()) {}
- if (f->eof_reached()) {
- return NULL;
- }
-
- Tag tag;
- bool exit=false;
- if (r_exit)
- *r_exit=false;
-
- bool complete=false;
- while(!f->eof_reached()) {
-
- CharType c=get_char();
- if (c<33 && tag.name.length() && !exit) {
- break;
- } else if (c=='>') {
- complete=true;
- break;
- } else if (c=='/') {
- exit=true;
- } else {
- tag.name+=c;
- }
- }
-
- if (f->eof_reached()) {
-
- return NULL;
- }
-
- if (exit) {
- if (!tag_stack.size()) {
- if (!p_printerr)
- return NULL;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unmatched exit tag </"+tag.name+">");
- ERR_FAIL_COND_V(!tag_stack.size(),NULL);
- }
-
- if (tag_stack.back()->get().name!=tag.name) {
- if (!p_printerr)
- return NULL;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Mismatched exit tag. Got </"+tag.name+">, expected </"+tag_stack.back()->get().name+">");
- ERR_FAIL_COND_V(tag_stack.back()->get().name!=tag.name,NULL);
- }
-
- if (!complete) {
- while(get_char()!='>' && !f->eof_reached()) {}
- if (f->eof_reached())
- return NULL;
- }
-
- if (r_exit)
- *r_exit=true;
-
- tag_stack.pop_back();
- return NULL;
-
- }
-
- if (!complete) {
- String name;
- CharString r_value;
- bool reading_value=false;
-
- while(!f->eof_reached()) {
-
- CharType c=get_char();
- if (c=='>') {
- if (r_value.size()) {
-
- r_value.push_back(0);
- String str;
- str.parse_utf8(r_value.get_data());
- tag.args[name]=str;
- if (r_order)
- r_order->push_back(name);
- }
- break;
-
- } else if ( ((!reading_value && (c<33)) || c=='=' || c=='"' || c=='\'') && tag.name.length()) {
-
- if (!reading_value && name.length()) {
-
- reading_value=true;
- } else if (reading_value && r_value.size()) {
-
- r_value.push_back(0);
- String str;
- str.parse_utf8(r_value.get_data());
- tag.args[name]=str;
- if (r_order)
- r_order->push_back(name);
- name="";
- r_value.clear();
- reading_value=false;
- }
-
- } else if (reading_value) {
-
- r_value.push_back(c);
- } else {
-
- name+=c;
- }
- }
-
- if (f->eof_reached())
- return NULL;
- }
-
- tag_stack.push_back(tag);
-
- return &tag_stack.back()->get();
-}
-
-
-Error ResourceInteractiveLoaderXML::close_tag(const String& p_name) {
-
- int level=0;
- bool inside_tag=false;
-
- while(true) {
-
- if (f->eof_reached()) {
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": EOF found while attempting to find </"+p_name+">");
- ERR_FAIL_COND_V( f->eof_reached(), ERR_FILE_CORRUPT );
- }
-
- uint8_t c = get_char();
-
- if (c == '<') {
-
- if (inside_tag) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Malformed XML. Already inside Tag.");
- ERR_FAIL_COND_V(inside_tag,ERR_FILE_CORRUPT);
- }
- inside_tag=true;
- c = get_char();
- if (c == '/') {
-
- --level;
- } else {
-
- ++level;
- };
- } else if (c == '>') {
-
- if (!inside_tag) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Malformed XML. Already outside Tag");
- ERR_FAIL_COND_V(!inside_tag,ERR_FILE_CORRUPT);
- }
- inside_tag=false;
- if (level == -1) {
- tag_stack.pop_back();
- return OK;
- };
- };
- }
-
- return OK;
-}
-
-void ResourceInteractiveLoaderXML::unquote(String& p_str) {
-
-
- p_str=p_str.strip_edges().replace("\"","").xml_unescape();
-
- /*p_str=p_str.strip_edges();
- p_str=p_str.replace("\"","");
- p_str=p_str.replace("&gt;","<");
- p_str=p_str.replace("&lt;",">");
- p_str=p_str.replace("&apos;","'");
- p_str=p_str.replace("&quot;","\"");
- for (int i=1;i<32;i++) {
-
- char chr[2]={i,0};
- p_str=p_str.replace("&#"+String::num(i)+";",chr);
- }
- p_str=p_str.replace("&amp;","&");
-*/
- //p_str.parse_utf8( p_str.ascii(true).get_data() );
-
-}
-
-Error ResourceInteractiveLoaderXML::goto_end_of_tag() {
-
- uint8_t c;
- while(true) {
-
- c=get_char();
- if (c=='>') //closetag
- break;
- if (f->eof_reached()) {
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": EOF found while attempting to find close tag.");
- ERR_FAIL_COND_V( f->eof_reached(), ERR_FILE_CORRUPT );
- }
-
- }
- tag_stack.pop_back();
-
- return OK;
-}
-
-
-Error ResourceInteractiveLoaderXML::parse_property_data(String &r_data) {
-
- r_data="";
- CharString cs;
- while(true) {
-
- CharType c=get_char();
- if (c=='<')
- break;
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- cs.push_back(c);
- }
-
- cs.push_back(0);
-
- r_data.parse_utf8(cs.get_data());
-
- while(get_char()!='>' && !f->eof_reached()) {}
- if (f->eof_reached()) {
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Malformed XML.");
- ERR_FAIL_COND_V( f->eof_reached(), ERR_FILE_CORRUPT );
- }
-
- r_data=r_data.strip_edges();
- tag_stack.pop_back();
-
- return OK;
-}
-
-
-Error ResourceInteractiveLoaderXML::_parse_array_element(Vector<char> &buff,bool p_number_only,FileAccess *f,bool *end) {
-
- if (buff.empty())
- buff.resize(32); // optimi
-
- int buff_max=buff.size();
- int buff_size=0;
- *end=false;
- char *buffptr=&buff[0];
- bool found=false;
- bool quoted=false;
-
- while(true) {
-
- char c=get_char();
-
- if (c==0) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": File corrupt (zero found).");
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- } else if (c=='"') {
- quoted=!quoted;
- } else if ((!quoted && ((p_number_only && c<33) || c==',')) || c=='<') {
-
-
- if (c=='<') {
- *end=true;
- break;
- }
- if (c<32 && f->eof_reached()) {
- *end=true;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": File corrupt (unexpected EOF).");
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- }
-
- if (found)
- break;
-
- } else {
-
- found=true;
- if (buff_size>=buff_max) {
-
- buff_max++;
- buff.resize(buff_max);
- buffptr=buff.ptr();
-
- }
-
- buffptr[buff_size]=c;
- buff_size++;
- }
- }
-
- if (buff_size>=buff_max) {
-
- buff_max++;
- buff.resize(buff_max);
-
- }
-
- buff[buff_size]=0;
- buff_size++;
-
- return OK;
-}
-
-Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) {
-
- bool exit;
- Tag *tag = parse_tag(&exit);
-
- if (!tag) {
- if (exit) // shouldn't have exited
- return ERR_FILE_EOF;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": File corrupt (No Property Tag).");
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- }
-
- r_v=Variant();
- r_name="";
-
-
- //ERR_FAIL_COND_V(tag->name!="property",ERR_FILE_CORRUPT);
- //ERR_FAIL_COND_V(!tag->args.has("name"),ERR_FILE_CORRUPT);
-// ERR_FAIL_COND_V(!tag->args.has("type"),ERR_FILE_CORRUPT);
-
- //String name=tag->args["name"];
- //ERR_FAIL_COND_V(name=="",ERR_FILE_CORRUPT);
- String type=tag->name;
- String name=tag->args["name"];
-
- if (type=="") {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": 'type' field is empty.");
- ERR_FAIL_COND_V(type=="",ERR_FILE_CORRUPT);
- }
-
- if (type=="dictionary") {
-
- Dictionary d( tag->args.has("shared") && (String(tag->args["shared"])=="true" || String(tag->args["shared"])=="1"));
-
- while(true) {
-
- Error err;
- String tagname;
- Variant key;
-
- int dictline = get_current_line();
-
-
- err=parse_property(key,tagname);
-
- if (err && err!=ERR_FILE_EOF) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error parsing dictionary: "+name+" (from line "+itos(dictline)+")");
- ERR_FAIL_COND_V(err && err!=ERR_FILE_EOF,err);
- }
- //ERR_FAIL_COND_V(tagname!="key",ERR_FILE_CORRUPT);
- if (err)
- break;
- Variant value;
- err=parse_property(value,tagname);
- if (err) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error parsing dictionary: "+name+" (from line "+itos(dictline)+")");
- }
-
- ERR_FAIL_COND_V(err,err);
- //ERR_FAIL_COND_V(tagname!="value",ERR_FILE_CORRUPT);
-
- d[key]=value;
- }
-
-
- //err=parse_property_data(name); // skip the rest
- //ERR_FAIL_COND_V(err,err);
-
- r_name=name;
- r_v=d;
- return OK;
-
- } else if (type=="array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
-
-
- int len=tag->args["len"].to_int();
- bool shared = tag->args.has("shared") && (String(tag->args["shared"])=="true" || String(tag->args["shared"])=="1");
-
- Array array(shared);
- array.resize(len);
-
- Error err;
- Variant v;
- String tagname;
- int idx=0;
- while( (err=parse_property(v,tagname))==OK ) {
-
- ERR_CONTINUE( idx <0 || idx >=len );
-
- array.set(idx,v);
- idx++;
- }
-
- if (idx!=len) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array (size mismatch): "+name);
- ERR_FAIL_COND_V(idx!=len,err);
- }
-
- if (err!=ERR_FILE_EOF) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array: "+name);
- ERR_FAIL_COND_V(err!=ERR_FILE_EOF,err);
- }
-
- //err=parse_property_data(name); // skip the rest
- //ERR_FAIL_COND_V(err,err);
-
- r_name=name;
- r_v=array;
- return OK;
-
- } else if (type=="resource") {
-
- if (tag->args.has("path")) {
-
- String path=tag->args["path"];
- String hint;
- if (tag->args.has("resource_type"))
- hint=tag->args["resource_type"];
-
- if (path.begins_with("local://"))
- path=path.replace("local://",local_path+"::");
- else if (path.find("://")==-1 && path.is_rel_path()) {
- // path is relative to file being loaded, so convert to a resource path
- path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
-
- }
-
- if (remaps.has(path)) {
- path=remaps[path];
- }
-
- //take advantage of the resource loader cache. The resource is cached on it, even if
- RES res=ResourceLoader::load(path,hint);
-
-
- if (res.is_null()) {
-
- WARN_PRINT(String("Couldn't load resource: "+path).ascii().get_data());
- }
-
- r_v=res.get_ref_ptr();
- } else if (tag->args.has("external")) {
-
- int index = tag->args["external"].to_int();
- if (ext_resources.has(index)) {
- String path=ext_resources[index].path;
- String type=ext_resources[index].type;
-
- //take advantage of the resource loader cache. The resource is cached on it, even if
- RES res=ResourceLoader::load(path,type);
-
- if (res.is_null()) {
-
- WARN_PRINT(String("Couldn't load externalresource: "+path).ascii().get_data());
- }
-
- r_v=res.get_ref_ptr();
- } else {
- WARN_PRINT(String("Invalid external resource index: "+itos(index)).ascii().get_data());
-
- }
- }
-
-
-
-
- Error err=goto_end_of_tag();
- if (err) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error closing <resource> tag.");
- ERR_FAIL_COND_V(err,err);
- }
-
-
- r_name=name;
-
- return OK;
-
- } else if (type=="image") {
-
- if (!tag->args.has("encoding")) {
- //empty image
- r_v=Image();
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- return OK;
- }
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'encoding' field.");
- ERR_FAIL_COND_V( !tag->args.has("encoding"), ERR_FILE_CORRUPT );
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'width' field.");
- ERR_FAIL_COND_V( !tag->args.has("width"), ERR_FILE_CORRUPT );
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'height' field.");
- ERR_FAIL_COND_V( !tag->args.has("height"), ERR_FILE_CORRUPT );
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Image missing 'format' field.");
- ERR_FAIL_COND_V( !tag->args.has("format"), ERR_FILE_CORRUPT );
-
- String encoding=tag->args["encoding"];
-
- if (encoding=="raw") {
- String width=tag->args["width"];
- String height=tag->args["height"];
- String format=tag->args["format"];
- int mipmaps=tag->args.has("mipmaps")?int(tag->args["mipmaps"].to_int()):int(0);
- int custom_size = tag->args.has("custom_size")?int(tag->args["custom_size"].to_int()):int(0);
-
- r_name=name;
-
- Image::Format imgformat;
-
-
- if (format=="grayscale") {
- imgformat=Image::FORMAT_GRAYSCALE;
- } else if (format=="intensity") {
- imgformat=Image::FORMAT_INTENSITY;
- } else if (format=="grayscale_alpha") {
- imgformat=Image::FORMAT_GRAYSCALE_ALPHA;
- } else if (format=="rgb") {
- imgformat=Image::FORMAT_RGB;
- } else if (format=="rgba") {
- imgformat=Image::FORMAT_RGBA;
- } else if (format=="indexed") {
- imgformat=Image::FORMAT_INDEXED;
- } else if (format=="indexed_alpha") {
- imgformat=Image::FORMAT_INDEXED_ALPHA;
- } else if (format=="bc1") {
- imgformat=Image::FORMAT_BC1;
- } else if (format=="bc2") {
- imgformat=Image::FORMAT_BC2;
- } else if (format=="bc3") {
- imgformat=Image::FORMAT_BC3;
- } else if (format=="bc4") {
- imgformat=Image::FORMAT_BC4;
- } else if (format=="bc5") {
- imgformat=Image::FORMAT_BC5;
- } else if (format=="pvrtc2") {
- imgformat=Image::FORMAT_PVRTC2;
- } else if (format=="pvrtc2a") {
- imgformat=Image::FORMAT_PVRTC2_ALPHA;
- } else if (format=="pvrtc4") {
- imgformat=Image::FORMAT_PVRTC4;
- } else if (format=="pvrtc4a") {
- imgformat=Image::FORMAT_PVRTC4_ALPHA;
- } else if (format=="etc") {
- imgformat=Image::FORMAT_ETC;
- } else if (format=="atc") {
- imgformat=Image::FORMAT_ATC;
- } else if (format=="atcai") {
- imgformat=Image::FORMAT_ATC_ALPHA_INTERPOLATED;
- } else if (format=="atcae") {
- imgformat=Image::FORMAT_ATC_ALPHA_EXPLICIT;
- } else if (format=="custom") {
- imgformat=Image::FORMAT_CUSTOM;
- } else {
-
- ERR_FAIL_V( ERR_FILE_CORRUPT );
- }
-
-
- int datasize;
- int w=width.to_int();
- int h=height.to_int();
-
- if (w == 0 && h == 0) {
- //r_v = Image(w, h, imgformat);
- r_v=Image();
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- return OK;
- };
-
- if (imgformat==Image::FORMAT_CUSTOM) {
-
- datasize=custom_size;
- } else {
-
- datasize = Image::get_image_data_size(h,w,imgformat,mipmaps);
- }
-
- if (datasize==0) {
- //r_v = Image(w, h, imgformat);
- r_v=Image();
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- return OK;
- };
-
- DVector<uint8_t> pixels;
- pixels.resize(datasize);
- DVector<uint8_t>::Write wb = pixels.write();
-
- int idx=0;
- uint8_t byte;
- while( idx<datasize*2) {
-
- CharType c=get_char();
-
- ERR_FAIL_COND_V(c=='<',ERR_FILE_CORRUPT);
-
- if ( (c>='0' && c<='9') || (c>='A' && c<='F') || (c>='a' && c<='f') ) {
-
- if (idx&1) {
-
- byte|=HEX2CHR(c);
- wb[idx>>1]=byte;
- } else {
-
- byte=HEX2CHR(c)<<4;
- }
-
- idx++;
- }
-
- }
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
- wb=DVector<uint8_t>::Write();
-
- r_v=Image(w,h,mipmaps,imgformat,pixels);
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- ERR_FAIL_COND_V(err,err);
-
- return OK;
- }
-
- ERR_FAIL_V(ERR_FILE_CORRUPT);
-
- } else if (type=="raw_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": RawArray missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();
-
- DVector<uint8_t> bytes;
- bytes.resize(len);
- DVector<uint8_t>::Write w=bytes.write();
- uint8_t *bytesptr=w.ptr();
- int idx=0;
- uint8_t byte;
-
- while( idx<len*2) {
-
- CharType c=get_char();
- if (c<=32)
- continue;
-
- if (idx&1) {
-
- byte|=HEX2CHR(c);
- bytesptr[idx>>1]=byte;
- //printf("%x\n",int(byte));
- } else {
-
- byte=HEX2CHR(c)<<4;
- }
-
- idx++;
- }
-
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
- w=DVector<uint8_t>::Write();
- r_v=bytes;
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
-
- } else if (type=="int_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();
-
- DVector<int> ints;
- ints.resize(len);
- DVector<int>::Write w=ints.write();
- int *intsptr=w.ptr();
- int idx=0;
- String str;
-#if 0
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
- if (c<33 || c==',' || c=='<') {
-
- if (str.length()) {
-
- intsptr[idx]=str.to_int();
- str="";
- idx++;
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
-
-#else
-
- Vector<char> tmpdata;
-
- while( idx<len ) {
-
- bool end=false;
- Error err = _parse_array_element(tmpdata,true,f,&end);
- ERR_FAIL_COND_V(err,err);
-
- intsptr[idx]=String::to_int(&tmpdata[0]);
- idx++;
- if (end)
- break;
-
- }
-
-#endif
- w=DVector<int>::Write();
-
- r_v=ints;
- Error err=goto_end_of_tag();
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
- } else if (type=="real_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();;
-
- DVector<real_t> reals;
- reals.resize(len);
- DVector<real_t>::Write w=reals.write();
- real_t *realsptr=w.ptr();
- int idx=0;
- String str;
-
-
-#if 0
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c<33 || c==',' || c=='<') {
-
- if (str.length()) {
-
- realsptr[idx]=str.to_double();
- str="";
- idx++;
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
-
-#else
-
-
-
- Vector<char> tmpdata;
-
- while( idx<len ) {
-
- bool end=false;
- Error err = _parse_array_element(tmpdata,true,f,&end);
- ERR_FAIL_COND_V(err,err);
-
- realsptr[idx]=String::to_double(&tmpdata[0]);
- idx++;
-
- if (end)
- break;
- }
-
-#endif
-
- w=DVector<real_t>::Write();
- r_v=reals;
-
- Error err=goto_end_of_tag();
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
- } else if (type=="string_array") {
-#if 0
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();
-
- DVector<String> strings;
- strings.resize(len);
- DVector<String>::Write w=strings.write();
- String *stringsptr=w.ptr();
- int idx=0;
- String str;
-
- bool inside_str=false;
- CharString cs;
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c=='"') {
- if (inside_str) {
-
- cs.push_back(0);
- String str;
- str.parse_utf8(cs.get_data());
- unquote(str);
- stringsptr[idx]=str;
- cs.clear();
- idx++;
- inside_str=false;
- } else {
- inside_str=true;
- }
- } else if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
-
-
- } else if (inside_str){
-
- cs.push_back(c);
- }
- }
- w=DVector<String>::Write();
- r_v=strings;
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- ERR_FAIL_COND_V(err,err);
-
- r_name=name;
-
- return OK;
-#endif
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": String Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
-
-
- int len=tag->args["len"].to_int();
-
- StringArray array;
- array.resize(len);
- DVector<String>::Write w = array.write();
-
- Error err;
- Variant v;
- String tagname;
- int idx=0;
-
-
- while( (err=parse_property(v,tagname))==OK ) {
-
- ERR_CONTINUE( idx <0 || idx >=len );
- String str = v; //convert back to string
- w[idx]=str;
- idx++;
- }
-
- if (idx!=len) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array (size mismatch): "+name);
- ERR_FAIL_COND_V(idx!=len,err);
- }
-
- if (err!=ERR_FILE_EOF) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Error loading array: "+name);
- ERR_FAIL_COND_V(err!=ERR_FILE_EOF,err);
- }
-
- //err=parse_property_data(name); // skip the rest
- //ERR_FAIL_COND_V(err,err);
-
- r_name=name;
- r_v=array;
- return OK;
-
- } else if (type=="vector3_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();;
-
- DVector<Vector3> vectors;
- vectors.resize(len);
- DVector<Vector3>::Write w=vectors.write();
- Vector3 *vectorsptr=w.ptr();
- int idx=0;
- int subidx=0;
- Vector3 auxvec;
- String str;
-
-// uint64_t tbegin = OS::get_singleton()->get_ticks_usec();
-#if 0
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c<33 || c==',' || c=='<') {
-
- if (str.length()) {
-
- auxvec[subidx]=str.to_double();
- subidx++;
- str="";
- if (subidx==3) {
- vectorsptr[idx]=auxvec;
-
- idx++;
- subidx=0;
- }
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
-#else
-
- Vector<char> tmpdata;
-
- while( idx<len ) {
-
- bool end=false;
- Error err = _parse_array_element(tmpdata,true,f,&end);
- ERR_FAIL_COND_V(err,err);
-
-
- auxvec[subidx]=String::to_double(&tmpdata[0]);
- subidx++;
- if (subidx==3) {
- vectorsptr[idx]=auxvec;
-
- idx++;
- subidx=0;
- }
-
- if (end)
- break;
- }
-
-
-
-#endif
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Premature end of vector3 array");
- ERR_FAIL_COND_V(idx<len,ERR_FILE_CORRUPT);
-// double time_taken = (OS::get_singleton()->get_ticks_usec() - tbegin)/1000000.0;
-
-
- w=DVector<Vector3>::Write();
- r_v=vectors;
- String sdfsdfg;
- Error err=goto_end_of_tag();
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
-
- } else if (type=="vector2_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();;
-
- DVector<Vector2> vectors;
- vectors.resize(len);
- DVector<Vector2>::Write w=vectors.write();
- Vector2 *vectorsptr=w.ptr();
- int idx=0;
- int subidx=0;
- Vector2 auxvec;
- String str;
-
-// uint64_t tbegin = OS::get_singleton()->get_ticks_usec();
-#if 0
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c<22 || c==',' || c=='<') {
-
- if (str.length()) {
-
- auxvec[subidx]=str.to_double();
- subidx++;
- str="";
- if (subidx==2) {
- vectorsptr[idx]=auxvec;
-
- idx++;
- subidx=0;
- }
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
-#else
-
- Vector<char> tmpdata;
-
- while( idx<len ) {
-
- bool end=false;
- Error err = _parse_array_element(tmpdata,true,f,&end);
- ERR_FAIL_COND_V(err,err);
-
-
- auxvec[subidx]=String::to_double(&tmpdata[0]);
- subidx++;
- if (subidx==2) {
- vectorsptr[idx]=auxvec;
-
- idx++;
- subidx=0;
- }
-
- if (end)
- break;
- }
-
-
-
-#endif
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Premature end of vector2 array");
- ERR_FAIL_COND_V(idx<len,ERR_FILE_CORRUPT);
-// double time_taken = (OS::get_singleton()->get_ticks_usec() - tbegin)/1000000.0;
-
-
- w=DVector<Vector2>::Write();
- r_v=vectors;
- String sdfsdfg;
- Error err=goto_end_of_tag();
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
-
- } else if (type=="color_array") {
-
- if (!tag->args.has("len")) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
- ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
- }
- int len=tag->args["len"].to_int();;
-
- DVector<Color> colors;
- colors.resize(len);
- DVector<Color>::Write w=colors.write();
- Color *colorsptr=w.ptr();
- int idx=0;
- int subidx=0;
- Color auxcol;
- String str;
-
- while( idx<len ) {
-
-
- CharType c=get_char();
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
-
-
- if (c<33 || c==',' || c=='<') {
-
- if (str.length()) {
-
- auxcol[subidx]=str.to_double();
- subidx++;
- str="";
- if (subidx==4) {
- colorsptr[idx]=auxcol;
- idx++;
- subidx=0;
- }
- }
-
- if (c=='<') {
-
- while(get_char()!='>' && !f->eof_reached()) {}
- ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
- break;
- }
-
- } else {
-
- str+=c;
- }
- }
- w=DVector<Color>::Write();
- r_v=colors;
- String sdfsdfg;
- Error err=parse_property_data(sdfsdfg);
- ERR_FAIL_COND_V(err,err);
- r_name=name;
-
- return OK;
- }
-
-
- String data;
- Error err = parse_property_data(data);
- ERR_FAIL_COND_V(err!=OK,err);
-
- if (type=="nil") {
- // uh do nothing
-
- } else if (type=="bool") {
- // uh do nothing
- if (data.nocasecmp_to("true")==0 || data.to_int()!=0)
- r_v=true;
- else
- r_v=false;
- } else if (type=="int") {
-
- r_v=data.to_int();
- } else if (type=="real") {
-
- r_v=data.to_double();
- } else if (type=="string") {
-
- String str=data;
- unquote(str);
- r_v=str;
- } else if (type=="vector3") {
-
-
- r_v=Vector3(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double()
- );
-
- } else if (type=="vector2") {
-
-
- r_v=Vector2(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double()
- );
-
- } else if (type=="plane") {
-
- r_v=Plane(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double(),
- data.get_slicec(',',3).to_double()
- );
-
- } else if (type=="quaternion") {
-
- r_v=Quat(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double(),
- data.get_slicec(',',3).to_double()
- );
-
- } else if (type=="rect2") {
-
- r_v=Rect2(
- Vector2(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double()
- ),
- Vector2(
- data.get_slicec(',',2).to_double(),
- data.get_slicec(',',3).to_double()
- )
- );
-
-
- } else if (type=="aabb") {
-
- r_v=AABB(
- Vector3(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double()
- ),
- Vector3(
- data.get_slicec(',',3).to_double(),
- data.get_slicec(',',4).to_double(),
- data.get_slicec(',',5).to_double()
- )
- );
-
- } else if (type=="matrix32") {
-
- Matrix32 m3;
- for (int i=0;i<3;i++) {
- for (int j=0;j<2;j++) {
- m3.elements[i][j]=data.get_slicec(',',i*2+j).to_double();
- }
- }
- r_v=m3;
-
- } else if (type=="matrix3") {
-
- Matrix3 m3;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
- m3.elements[i][j]=data.get_slicec(',',i*3+j).to_double();
- }
- }
- r_v=m3;
-
- } else if (type=="transform") {
-
- Transform tr;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
- tr.basis.elements[i][j]=data.get_slicec(',',i*3+j).to_double();
- }
-
- }
- tr.origin=Vector3(
- data.get_slicec(',',9).to_double(),
- data.get_slicec(',',10).to_double(),
- data.get_slicec(',',11).to_double()
- );
- r_v=tr;
-
- } else if (type=="color") {
-
- r_v=Color(
- data.get_slicec(',',0).to_double(),
- data.get_slicec(',',1).to_double(),
- data.get_slicec(',',2).to_double(),
- data.get_slicec(',',3).to_double()
- );
-
- } else if (type=="node_path") {
-
- String str=data;
- unquote(str);
- r_v=NodePath( str );
- } else if (type=="input_event") {
-
- // ?
- } else {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unrecognized tag in file: "+type);
- ERR_FAIL_V(ERR_FILE_CORRUPT);
- }
- r_name=name;
- return OK;
-}
-
-
-
-int ResourceInteractiveLoaderXML::get_current_line() const {
-
- return lines;
-}
-
-
-uint8_t ResourceInteractiveLoaderXML::get_char() const {
-
- uint8_t c = f->get_8();
- if (c=='\n')
- lines++;
- return c;
-
-}
-
-
-
-
-///
-
-void ResourceInteractiveLoaderXML::set_local_path(const String& p_local_path) {
-
- res_path=p_local_path;
-}
-
-Ref<Resource> ResourceInteractiveLoaderXML::get_resource() {
-
- return resource;
-}
-Error ResourceInteractiveLoaderXML::poll() {
-
- if (error!=OK)
- return error;
-
- bool exit;
- Tag *tag = parse_tag(&exit);
-
-
- if (!tag) {
- error=ERR_FILE_CORRUPT;
- if (!exit) // shouldn't have exited
- ERR_FAIL_V(error);
- error=ERR_FILE_EOF;
- return error;
- }
-
- RES res;
- //Object *obj=NULL;
-
- bool main;
-
- if (tag->name=="ext_resource") {
-
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> missing 'path' field.");
- ERR_FAIL_COND_V(!tag->args.has("path"),ERR_FILE_CORRUPT);
-
- String type="Resource";
- if (tag->args.has("type"))
- type=tag->args["type"];
-
- String path = tag->args["path"];
-
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> can't use a local path, this is a bug?.");
- ERR_FAIL_COND_V(path.begins_with("local://"),ERR_FILE_CORRUPT);
-
- if (path.find("://")==-1 && path.is_rel_path()) {
- // path is relative to file being loaded, so convert to a resource path
- path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
- }
-
- if (remaps.has(path)) {
- path=remaps[path];
- }
-
- RES res = ResourceLoader::load(path,type);
-
- if (res.is_null()) {
-
- if (ResourceLoader::get_abort_on_missing_resources()) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> referenced nonexistent resource at: "+path);
- ERR_FAIL_V(error);
- } else {
- ResourceLoader::notify_dependency_error(local_path,path,type);
- }
- } else {
-
- resource_cache.push_back(res);
- }
-
- if (tag->args.has("index")) {
- ExtResource er;
- er.path=path;
- er.type=type;
- ext_resources[tag->args["index"].to_int()]=er;
- }
-
-
- Error err = close_tag("ext_resource");
- if (err)
- return error;
-
-
- error=OK;
- resource_current++;
- return error;
-
- } else if (tag->name=="resource") {
-
- main=false;
- } else if (tag->name=="main_resource") {
- main=true;
- } else {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": unexpected main tag: "+tag->name);
- error=ERR_FILE_CORRUPT;
- ERR_FAIL_V(error);
- }
-
-
- String type;
- String path;
- int subres=0;
-
- if (!main) {
- //loading resource
-
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <resource> missing 'len' field.");
- ERR_FAIL_COND_V(!tag->args.has("path"),ERR_FILE_CORRUPT);
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <resource> missing 'type' field.");
- ERR_FAIL_COND_V(!tag->args.has("type"),ERR_FILE_CORRUPT);
- path=tag->args["path"];
-
- error=OK;
-
- if (path.begins_with("local://")) {
- //built-in resource (but really external)
-
- path=path.replace("local://","");
- subres=path.to_int();
- path=local_path+"::"+path;
- }
-
-
- if (ResourceCache::has(path)) {
- Error err = close_tag(tag->name);
- if (err) {
- error=ERR_FILE_CORRUPT;
- }
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Unable to close <resource> tag.");
- ERR_FAIL_COND_V( err, err );
- resource_current++;
- error=OK;
- return OK;
- }
-
- type = tag->args["type"];
- } else {
- type=resource_type;
- }
-
- Object *obj = ObjectTypeDB::instance(type);
- if (!obj) {
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Object of unrecognized type in file: "+type);
- }
- ERR_FAIL_COND_V(!obj,ERR_FILE_CORRUPT);
-
- Resource *r = obj->cast_to<Resource>();
- if (!r) {
- error=ERR_FILE_CORRUPT;
- memdelete(obj); //bye
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Object type in resource field not a resource, type is: "+obj->get_type());
- ERR_FAIL_COND_V(!r,ERR_FILE_CORRUPT);
- }
-
- res = RES( r );
- if (path!="")
- r->set_path(path);
- r->set_subindex(subres);
-
- //load properties
-
- while(true) {
-
- String name;
- Variant v;
- Error err;
- err = parse_property(v,name);
- if (err==ERR_FILE_EOF) //tag closed
- break;
- if (err!=OK) {
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": XML Parsing aborted.");
- ERR_FAIL_COND_V(err!=OK,ERR_FILE_CORRUPT);
- }
-
- obj->set(name,v);
- }
-#ifdef TOOLS_ENABLED
- res->set_edited(false);
-#endif
- resource_cache.push_back(res); //keep it in mem until finished loading
- resource_current++;
- if (main) {
- f->close();
- resource=res;
- if (!ResourceCache::has(res_path)) {
- resource->set_path(res_path);
- }
- error=ERR_FILE_EOF;
- return error;
-
- }
- error=OK;
- return OK;
-}
-
-int ResourceInteractiveLoaderXML::get_stage() const {
-
- return resource_current;
-}
-int ResourceInteractiveLoaderXML::get_stage_count() const {
-
- return resources_total;//+ext_resources;
-}
-
-ResourceInteractiveLoaderXML::~ResourceInteractiveLoaderXML() {
-
- memdelete(f);
-}
-
-void ResourceInteractiveLoaderXML::get_dependencies(FileAccess *f,List<String> *p_dependencies,bool p_add_types) {
-
-
- open(f);
- ERR_FAIL_COND(error!=OK);
-
- while(true) {
- bool exit;
- Tag *tag = parse_tag(&exit);
-
-
- if (!tag) {
- error=ERR_FILE_CORRUPT;
- ERR_FAIL_COND(!exit);
- error=ERR_FILE_EOF;
- return;
- }
-
- if (tag->name!="ext_resource") {
-
- return;
- }
-
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> missing 'path' field.");
- ERR_FAIL_COND(!tag->args.has("path"));
-
- String path = tag->args["path"];
-
- ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> can't use a local path, this is a bug?.");
- ERR_FAIL_COND(path.begins_with("local://"));
-
- if (path.find("://")==-1 && path.is_rel_path()) {
- // path is relative to file being loaded, so convert to a resource path
- path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
- }
-
- if (path.ends_with("*")) {
- ERR_FAIL_COND(!tag->args.has("type"));
- String type = tag->args["type"];
- path = ResourceLoader::guess_full_filename(path,type);
- }
-
- if (p_add_types && tag->args.has("type")) {
- path+="::"+tag->args["type"];
- }
-
- p_dependencies->push_back(path);
-
- Error err = close_tag("ext_resource");
- if (err)
- return;
-
- error=OK;
- }
-
-}
-
-Error ResourceInteractiveLoaderXML::rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map) {
-
- open(p_f);
- ERR_FAIL_COND_V(error!=OK,error);
-
- //FileAccess
-
- bool old_format=false;
-
- FileAccess *fw = NULL;
-
- String base_path=local_path.get_base_dir();
-
- while(true) {
- bool exit;
- List<String> order;
-
- Tag *tag = parse_tag(&exit,true,&order);
-
- bool done=false;
-
- if (!tag) {
- if (fw) {
- memdelete(fw);
- }
- error=ERR_FILE_CORRUPT;
- ERR_FAIL_COND_V(!exit,error);
- error=ERR_FILE_EOF;
-
- return error;
- }
-
- if (tag->name=="ext_resource") {
-
- if (!tag->args.has("index") || !tag->args.has("path") || !tag->args.has("type")) {
- old_format=true;
- break;
- }
-
- if (!fw) {
-
- fw=FileAccess::open(p_path+".depren",FileAccess::WRITE);
- fw->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //no escape
- fw->store_line("<resource_file type=\""+resource_type+"\" subresource_count=\""+itos(resources_total)+"\" version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\" version_name=\""+VERSION_FULL_NAME+"\">");
-
- }
-
- String path = tag->args["path"];
- String index = tag->args["index"];
- String type = tag->args["type"];
-
-
- bool relative=false;
- if (!path.begins_with("res://")) {
- path=base_path.plus_file(path).simplify_path();
- relative=true;
- }
-
-
- if (p_map.has(path)) {
- String np=p_map[path];
- path=np;
- }
-
- if (relative) {
- //restore relative
- path=base_path.path_to_file(path);
- }
-
- tag->args["path"]=path;
- tag->args["index"]=index;
- tag->args["type"]=type;
-
- } else {
-
- done=true;
- }
-
- String tagt="\t<";
- if (exit)
- tagt+="/";
- tagt+=tag->name;
-
- for(List<String>::Element *E=order.front();E;E=E->next()) {
- tagt+=" "+E->get()+"=\""+tag->args[E->get()]+"\"";
- }
- tagt+=">";
- fw->store_line(tagt);
- if (done)
- break;
- close_tag("ext_resource");
- fw->store_line("\t</ext_resource>");
-
- }
-
-
- if (old_format) {
- if (fw)
- memdelete(fw);
-
- DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- da->remove(p_path+".depren");
- memdelete(da);
- //fuck it, use the old approach;
-
- WARN_PRINT(("This file is old, so it can't refactor dependencies, opening and resaving: "+p_path).utf8().get_data());
-
- Error err;
- FileAccess *f2 = FileAccess::open(p_path,FileAccess::READ,&err);
- if (err!=OK) {
- ERR_FAIL_COND_V(err!=OK,ERR_FILE_CANT_OPEN);
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
- ria->remaps=p_map;
- // ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- ria->open(f2);
-
- err = ria->poll();
-
- while(err==OK) {
- err=ria->poll();
- }
-
- ERR_FAIL_COND_V(err!=ERR_FILE_EOF,ERR_FILE_CORRUPT);
- RES res = ria->get_resource();
- ERR_FAIL_COND_V(!res.is_valid(),ERR_FILE_CORRUPT);
-
- return ResourceFormatSaverXML::singleton->save(p_path,res);
- }
-
- if (!fw) {
-
- return OK; //nothing to rename, do nothing
- }
-
- uint8_t c=f->get_8();
- while(!f->eof_reached()) {
- fw->store_8(c);
- c=f->get_8();
- }
- f->close();
-
- bool all_ok = fw->get_error()==OK;
-
- memdelete(fw);
-
- if (!all_ok) {
- return ERR_CANT_CREATE;
- }
-
- DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- da->remove(p_path);
- da->rename(p_path+".depren",p_path);
- memdelete(da);
-
- return OK;
-
-}
-
-
-void ResourceInteractiveLoaderXML::open(FileAccess *p_f) {
-
- error=OK;
-
- lines=1;
- f=p_f;
-
-
- ResourceInteractiveLoaderXML::Tag *tag = parse_tag();
- if (!tag || tag->name!="?xml" || !tag->args.has("version") || !tag->args.has("encoding") || tag->args["encoding"]!="UTF-8") {
-
- error=ERR_FILE_CORRUPT;
- ResourceLoader::notify_load_error("XML is invalid (missing header tags)");
- ERR_EXPLAIN("Not a XML:UTF-8 File: "+local_path);
- ERR_FAIL();
- }
-
- tag_stack.clear();
-
- tag = parse_tag();
-
-
- if (!tag || tag->name!="resource_file" || !tag->args.has("type") || !tag->args.has("version")) {
-
- ResourceLoader::notify_load_error(local_path+": XML is not a valid resource file.");
- error=ERR_FILE_CORRUPT;
- ERR_EXPLAIN("Unrecognized XML File: "+local_path);
- ERR_FAIL();
- }
-
-
- if (tag->args.has("subresource_count"))
- resources_total=tag->args["subresource_count"].to_int();
- resource_current=0;
- resource_type=tag->args["type"];
-
- String version = tag->args["version"];
- if (version.get_slice_count(".")!=2) {
-
- error=ERR_FILE_CORRUPT;
- ResourceLoader::notify_load_error(local_path+":XML version string is invalid: "+version);
- ERR_EXPLAIN("Invalid Version String '"+version+"'' in file: "+local_path);
- ERR_FAIL();
- }
-
- int major = version.get_slicec('.',0).to_int();
- if (major>VERSION_MAJOR) {
-
- error=ERR_FILE_UNRECOGNIZED;
- ResourceLoader::notify_load_error(local_path+": File Format '"+version+"' is too new. Please upgrade to a newer engine version.");
- ERR_EXPLAIN("File Format '"+version+"' is too new! Please upgrade to a a new engine version: "+local_path);
- ERR_FAIL();
-
- }
-
- /*
- String preload_depts = "deps/"+local_path.md5_text();
- if (Globals::get_singleton()->has(preload_depts)) {
- ext_resources.clear();
- //ignore external resources and use these
- NodePath depts=Globals::get_singleton()->get(preload_depts);
-
- for(int i=0;i<depts.get_name_count();i++) {
- ext_resources.push_back(depts.get_name(i));
- }
- print_line(local_path+" - EXTERNAL RESOURCES: "+itos(ext_resources.size()));
- }
-*/
-
-}
-
-String ResourceInteractiveLoaderXML::recognize(FileAccess *p_f) {
-
- error=OK;
-
- lines=1;
- f=p_f;
-
- ResourceInteractiveLoaderXML::Tag *tag = parse_tag();
- if (!tag || tag->name!="?xml" || !tag->args.has("version") || !tag->args.has("encoding") || tag->args["encoding"]!="UTF-8") {
-
-
- return ""; //unrecognized
- }
-
- tag_stack.clear();
-
- tag = parse_tag();
-
- if (!tag || tag->name!="resource_file" || !tag->args.has("type") || !tag->args.has("version")) {
-
- return ""; //unrecognized
- }
-
- return tag->args["type"];
-
-}
-
-/////////////////////
-
-Ref<ResourceInteractiveLoader> ResourceFormatLoaderXML::load_interactive(const String &p_path, Error *r_error) {
-
- if (r_error)
- *r_error=ERR_CANT_OPEN;
-
- Error err;
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err);
-
-
- if (err!=OK) {
-
- ERR_FAIL_COND_V(err!=OK,Ref<ResourceInteractiveLoader>());
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- ria->open(f);
-
- return ria;
-}
-
-void ResourceFormatLoaderXML::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const {
-
- if (p_type=="") {
- get_recognized_extensions(p_extensions);
- return;
- }
-
- List<String> extensions;
- ObjectTypeDB::get_extensions_for_type(p_type,&extensions);
-
- extensions.sort();
-
- for(List<String>::Element *E=extensions.front();E;E=E->next()) {
- String ext = E->get().to_lower();
- if (ext=="res")
- continue;
- p_extensions->push_back("x"+ext);
- }
-
- p_extensions->push_back("xml");
-
-
-}
-void ResourceFormatLoaderXML::get_recognized_extensions(List<String> *p_extensions) const{
-
- List<String> extensions;
- ObjectTypeDB::get_resource_base_extensions(&extensions);
- extensions.sort();
-
- for(List<String>::Element *E=extensions.front();E;E=E->next()) {
- String ext = E->get().to_lower();
- if (ext=="res")
- continue;
- p_extensions->push_back("x"+ext);
- }
-
- p_extensions->push_back("xml");
-}
-
-bool ResourceFormatLoaderXML::handles_type(const String& p_type) const{
-
- return true;
-}
-String ResourceFormatLoaderXML::get_resource_type(const String &p_path) const{
-
-
- String ext=p_path.extension().to_lower();
- if (!ext.begins_with("x")) //a lie but..
- return "";
-
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
- if (!f) {
-
- return ""; //could not rwead
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- String r = ria->recognize(f);
- return r;
-}
-
-
-void ResourceFormatLoaderXML::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types) {
-
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
- if (!f) {
-
- ERR_FAIL();
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- ria->get_dependencies(f,p_dependencies,p_add_types);
-
-
-}
-
-Error ResourceFormatLoaderXML::rename_dependencies(const String &p_path,const Map<String,String>& p_map) {
-
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
- if (!f) {
-
- ERR_FAIL_V(ERR_CANT_OPEN);
- }
-
- Ref<ResourceInteractiveLoaderXML> ria = memnew( ResourceInteractiveLoaderXML );
- ria->local_path=Globals::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- return ria->rename_dependencies(f,p_path,p_map);
-}
-
-
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-/****************************************************************************************/
-
-
-
-void ResourceFormatSaverXMLInstance::escape(String& p_str) {
-
- p_str=p_str.replace("&","&amp;");
- p_str=p_str.replace("<","&lt;");
- p_str=p_str.replace(">","&gt;");
- p_str=p_str.replace("'","&apos;");
- p_str=p_str.replace("\"","&quot;");
- for (char i=1;i<32;i++) {
-
- char chr[2]={i,0};
- const char hexn[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
- const char hex[8]={'&','#','0','0',hexn[i>>4],hexn[i&0xf],';',0};
-
- p_str=p_str.replace(chr,hex);
- }
-
-
-}
-void ResourceFormatSaverXMLInstance::write_tabs(int p_diff) {
-
- for (int i=0;i<depth+p_diff;i++) {
-
- f->store_8('\t');
- }
-}
-
-void ResourceFormatSaverXMLInstance::write_string(String p_str,bool p_escape) {
-
- /* write an UTF8 string */
- if (p_escape)
- escape(p_str);
-
- f->store_string(p_str);;
- /*
- CharString cs=p_str.utf8();
- const char *data=cs.get_data();
-
- while (*data) {
- f->store_8(*data);
- data++;
- }*/
-
-
-}
-
-void ResourceFormatSaverXMLInstance::enter_tag(const char* p_tag,const String& p_args) {
-
- f->store_8('<');
- int cc = 0;
- const char *c=p_tag;
- while(*c) {
- cc++;
- c++;
- }
- f->store_buffer((const uint8_t*)p_tag,cc);
- if (p_args.length()) {
- f->store_8(' ');
- f->store_string(p_args);
- }
- f->store_8('>');
- depth++;
-
-}
-void ResourceFormatSaverXMLInstance::exit_tag(const char* p_tag) {
-
- depth--;
- f->store_8('<');
- f->store_8('/');
- int cc = 0;
- const char *c=p_tag;
- while(*c) {
- cc++;
- c++;
- }
- f->store_buffer((const uint8_t*)p_tag,cc);
- f->store_8('>');
-
-}
-
-/*
-static bool _check_type(const Variant& p_property) {
-
- if (p_property.get_type()==Variant::_RID)
- return false;
- if (p_property.get_type()==Variant::OBJECT) {
- RES res = p_property;
- if (res.is_null())
- return false;
- }
-
- return true;
-}*/
-
-void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const Variant& p_property,bool *r_ok) {
-
- if (r_ok)
- *r_ok=false;
-
- const char* type;
- String params;
- bool oneliner=true;
-
- switch( p_property.get_type() ) {
-
- case Variant::NIL: type="nil"; break;
- case Variant::BOOL: type="bool"; break;
- case Variant::INT: type="int"; break;
- case Variant::REAL: type="real"; break;
- case Variant::STRING: type="string"; break;
- case Variant::VECTOR2: type="vector2"; break;
- case Variant::RECT2: type="rect2"; break;
- case Variant::VECTOR3: type="vector3"; break;
- case Variant::PLANE: type="plane"; break;
- case Variant::_AABB: type="aabb"; break;
- case Variant::QUAT: type="quaternion"; break;
- case Variant::MATRIX32: type="matrix32"; break;
- case Variant::MATRIX3: type="matrix3"; break;
- case Variant::TRANSFORM: type="transform"; break;
- case Variant::COLOR: type="color"; break;
- case Variant::IMAGE: {
- type="image";
- Image img=p_property;
- if (img.empty()) {
- write_tabs();
- enter_tag(type,"name=\""+p_name+"\"");
- exit_tag(type);
- if (r_ok)
- *r_ok=true;
- return;
- }
- params+="encoding=\"raw\"";
- params+=" width=\""+itos(img.get_width())+"\"";
- params+=" height=\""+itos(img.get_height())+"\"";
- params+=" mipmaps=\""+itos(img.get_mipmaps())+"\"";
-
- switch(img.get_format()) {
-
- case Image::FORMAT_GRAYSCALE: params+=" format=\"grayscale\""; break;
- case Image::FORMAT_INTENSITY: params+=" format=\"intensity\""; break;
- case Image::FORMAT_GRAYSCALE_ALPHA: params+=" format=\"grayscale_alpha\""; break;
- case Image::FORMAT_RGB: params+=" format=\"rgb\""; break;
- case Image::FORMAT_RGBA: params+=" format=\"rgba\""; break;
- case Image::FORMAT_INDEXED : params+=" format=\"indexed\""; break;
- case Image::FORMAT_INDEXED_ALPHA: params+=" format=\"indexed_alpha\""; break;
- case Image::FORMAT_BC1: params+=" format=\"bc1\""; break;
- case Image::FORMAT_BC2: params+=" format=\"bc2\""; break;
- case Image::FORMAT_BC3: params+=" format=\"bc3\""; break;
- case Image::FORMAT_BC4: params+=" format=\"bc4\""; break;
- case Image::FORMAT_BC5: params+=" format=\"bc5\""; break;
- case Image::FORMAT_PVRTC2: params+=" format=\"pvrtc2\""; break;
- case Image::FORMAT_PVRTC2_ALPHA: params+=" format=\"pvrtc2a\""; break;
- case Image::FORMAT_PVRTC4: params+=" format=\"pvrtc4\""; break;
- case Image::FORMAT_PVRTC4_ALPHA: params+=" format=\"pvrtc4a\""; break;
- case Image::FORMAT_ETC: params+=" format=\"etc\""; break;
- case Image::FORMAT_ATC: params+=" format=\"atc\""; break;
- case Image::FORMAT_ATC_ALPHA_EXPLICIT: params+=" format=\"atcae\""; break;
- case Image::FORMAT_ATC_ALPHA_INTERPOLATED: params+=" format=\"atcai\""; break;
- case Image::FORMAT_CUSTOM: params+=" format=\"custom\" custom_size=\""+itos(img.get_data().size())+"\""; break;
- default: {}
- }
- } break;
- case Variant::NODE_PATH: type="node_path"; break;
- case Variant::OBJECT: {
- type="resource";
- RES res = p_property;
- if (res.is_null()) {
- write_tabs();
- enter_tag(type,"name=\""+p_name+"\"");
- exit_tag(type);
- if (r_ok)
- *r_ok=true;
-
- return; // don't save it
- }
-
- if (external_resources.has(res)) {
-
- params="external=\""+itos(external_resources[res])+"\"";
- } else {
- params="resource_type=\""+res->get_save_type()+"\"";
-
-
- if (res->get_path().length() && res->get_path().find("::")==-1) {
- //external resource
- String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path();
- escape(path);
- params+=" path=\""+path+"\"";
- } else {
-
- //internal resource
- ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?");
- ERR_FAIL_COND(!resource_set.has(res));
-
- params+=" path=\"local://"+itos(res->get_subindex())+"\"";
- }
- }
-
- } break;
- case Variant::INPUT_EVENT: type="input_event"; break;
- case Variant::DICTIONARY: type="dictionary"; params="shared=\""+String(p_property.is_shared()?"true":"false")+"\""; oneliner=false; break;
- case Variant::ARRAY: type="array"; params="len=\""+itos(p_property.operator Array().size())+"\" shared=\""+String(p_property.is_shared()?"true":"false")+"\""; oneliner=false; break;
-
- case Variant::RAW_ARRAY: type="raw_array"; params="len=\""+itos(p_property.operator DVector < uint8_t >().size())+"\""; break;
- case Variant::INT_ARRAY: type="int_array"; params="len=\""+itos(p_property.operator DVector < int >().size())+"\""; break;
- case Variant::REAL_ARRAY: type="real_array"; params="len=\""+itos(p_property.operator DVector < real_t >().size())+"\""; break;
- case Variant::STRING_ARRAY: oneliner=false; type="string_array"; params="len=\""+itos(p_property.operator DVector < String >().size())+"\""; break;
- case Variant::VECTOR2_ARRAY: type="vector2_array"; params="len=\""+itos(p_property.operator DVector < Vector2 >().size())+"\""; break;
- case Variant::VECTOR3_ARRAY: type="vector3_array"; params="len=\""+itos(p_property.operator DVector < Vector3 >().size())+"\""; break;
- case Variant::COLOR_ARRAY: type="color_array"; params="len=\""+itos(p_property.operator DVector < Color >().size())+"\""; break;
- default: {
-
- ERR_PRINT("Unknown Variant type.");
- ERR_FAIL();
- }
-
- }
-
- write_tabs();
-
- if (p_name!="") {
- if (params.length())
- enter_tag(type,"name=\""+p_name+"\" "+params);
- else
- enter_tag(type,"name=\""+p_name+"\"");
- } else {
- if (params.length())
- enter_tag(type," "+params);
- else
- enter_tag(type,String());
- }
-
- if (!oneliner)
- f->store_8('\n');
- else
- f->store_8(' ');
-
-
- switch( p_property.get_type() ) {
-
- case Variant::NIL: {
-
- } break;
- case Variant::BOOL: {
-
- write_string( p_property.operator bool() ? "True":"False" );
- } break;
- case Variant::INT: {
-
- write_string( itos(p_property.operator int()) );
- } break;
- case Variant::REAL: {
-
- write_string( rtos(p_property.operator real_t()) );
- } break;
- case Variant::STRING: {
-
- String str=p_property;
- escape(str);
- str="\""+str+"\"";
- write_string( str,false );
- } break;
- case Variant::VECTOR2: {
-
- Vector2 v = p_property;
- write_string( rtoss(v.x) +", "+rtoss(v.y) );
- } break;
- case Variant::RECT2: {
-
- Rect2 aabb = p_property;
- write_string( rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y) );
-
- } break;
- case Variant::VECTOR3: {
-
- Vector3 v = p_property;
- write_string( rtoss(v.x) +", "+rtoss(v.y)+", "+rtoss(v.z) );
- } break;
- case Variant::PLANE: {
-
- Plane p = p_property;
- write_string( rtoss(p.normal.x) +", "+rtoss(p.normal.y)+", "+rtoss(p.normal.z)+", "+rtoss(p.d) );
-
- } break;
- case Variant::_AABB: {
-
- AABB aabb = p_property;
- write_string( rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.pos.z) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y) +", "+rtoss(aabb.size.z) );
-
- } break;
- case Variant::QUAT: {
-
- Quat quat = p_property;
- write_string( rtoss(quat.x)+", "+rtoss(quat.y)+", "+rtoss(quat.z)+", "+rtoss(quat.w)+", ");
-
- } break;
- case Variant::MATRIX32: {
-
- String s;
- Matrix32 m3 = p_property;
- for (int i=0;i<3;i++) {
- for (int j=0;j<2;j++) {
-
- if (i!=0 || j!=0)
- s+=", ";
- s+=rtoss( m3.elements[i][j] );
- }
- }
-
- write_string(s);
-
- } break;
- case Variant::MATRIX3: {
-
- String s;
- Matrix3 m3 = p_property;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
-
- if (i!=0 || j!=0)
- s+=", ";
- s+=rtoss( m3.elements[i][j] );
- }
- }
-
- write_string(s);
-
- } break;
- case Variant::TRANSFORM: {
-
- String s;
- Transform t = p_property;
- Matrix3 &m3 = t.basis;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
-
- if (i!=0 || j!=0)
- s+=", ";
- s+=rtoss( m3.elements[i][j] );
- }
- }
-
- s=s+", "+rtoss(t.origin.x) +", "+rtoss(t.origin.y)+", "+rtoss(t.origin.z);
-
- write_string(s);
- } break;
-
- // misc types
- case Variant::COLOR: {
-
- Color c = p_property;
- write_string( rtoss(c.r) +", "+rtoss(c.g)+", "+rtoss(c.b)+", "+rtoss(c.a) );
-
- } break;
- case Variant::IMAGE: {
-
- String s;
- Image img = p_property;
- DVector<uint8_t> data = img.get_data();
- int len = data.size();
- DVector<uint8_t>::Read r = data.read();
- const uint8_t *ptr=r.ptr();;
- for (int i=0;i<len;i++) {
-
- uint8_t byte = ptr[i];
- const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- char str[3]={ hex[byte>>4], hex[byte&0xF], 0};
- s+=str;
- }
-
- write_string(s);
- } break;
- case Variant::NODE_PATH: {
-
- String str=p_property;
- escape(str);
- str="\""+str+"\"";
- write_string( str,false);
-
- } break;
-
- case Variant::OBJECT: {
- /* this saver does not save resources in here
- RES res = p_property;
-
- if (!res.is_null()) {
-
- String path=res->get_path();
- if (!res->is_shared() || !path.length()) {
- // if no path, or path is from inside a scene
- write_object( *res );
- }
-
- }
- */
-
- } break;
- case Variant::INPUT_EVENT: {
-
- write_string( p_property.operator String() );
- } break;
- case Variant::DICTIONARY: {
-
- Dictionary dict = p_property;
-
-
- List<Variant> keys;
- dict.get_key_list(&keys);
- keys.sort();
-
- for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
-
- //if (!_check_type(dict[E->get()]))
- // continue;
- bool ok;
- write_property("",E->get(),&ok);
- ERR_CONTINUE(!ok);
-
- write_property("",dict[E->get()],&ok);
- if (!ok)
- write_property("",Variant()); //at least make the file consistent..
- }
-
-
-
-
- } break;
- case Variant::ARRAY: {
-
- Array array = p_property;
- int len=array.size();
- for (int i=0;i<len;i++) {
-
- write_property("",array[i]);
-
- }
-
- } break;
-
- case Variant::RAW_ARRAY: {
-
- String s;
- DVector<uint8_t> data = p_property;
- int len = data.size();
- DVector<uint8_t>::Read r = data.read();
- const uint8_t *ptr=r.ptr();;
- for (int i=0;i<len;i++) {
-
- uint8_t byte = ptr[i];
- const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- char str[3]={ hex[byte>>4], hex[byte&0xF], 0};
- s+=str;
- }
-
- write_string(s,false);
-
- } break;
- case Variant::INT_ARRAY: {
-
- DVector<int> data = p_property;
- int len = data.size();
- DVector<int>::Read r = data.read();
- const int *ptr=r.ptr();;
- write_tabs();
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(", ",false);
-
- write_string(itos(ptr[i]),false);
- }
-
-
-
- } break;
- case Variant::REAL_ARRAY: {
-
- DVector<real_t> data = p_property;
- int len = data.size();
- DVector<real_t>::Read r = data.read();
- const real_t *ptr=r.ptr();;
- write_tabs();
- String cm=", " ;
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(cm,false);
- write_string(rtoss(ptr[i]),false);
- }
-
-
- } break;
- case Variant::STRING_ARRAY: {
-
- DVector<String> data = p_property;
- int len = data.size();
- DVector<String>::Read r = data.read();
- const String *ptr=r.ptr();;
- String s;
- //write_string("\n");
-
-
-
- for (int i=0;i<len;i++) {
-
- write_tabs(0);
- String str=ptr[i];
- escape(str);
- write_string("<string> \""+str+"\" </string>\n",false);
- }
- } break;
- case Variant::VECTOR2_ARRAY: {
-
- DVector<Vector2> data = p_property;
- int len = data.size();
- DVector<Vector2>::Read r = data.read();
- const Vector2 *ptr=r.ptr();;
- write_tabs();
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(", ",false);
- write_string(rtoss(ptr[i].x),false);
- write_string(", "+rtoss(ptr[i].y),false);
-
- }
-
-
- } break;
- case Variant::VECTOR3_ARRAY: {
-
- DVector<Vector3> data = p_property;
- int len = data.size();
- DVector<Vector3>::Read r = data.read();
- const Vector3 *ptr=r.ptr();;
- write_tabs();
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(", ",false);
- write_string(rtoss(ptr[i].x),false);
- write_string(", "+rtoss(ptr[i].y),false);
- write_string(", "+rtoss(ptr[i].z),false);
-
- }
-
-
- } break;
- case Variant::COLOR_ARRAY: {
-
- DVector<Color> data = p_property;
- int len = data.size();
- DVector<Color>::Read r = data.read();
- const Color *ptr=r.ptr();;
- write_tabs();
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- write_string(", ",false);
-
- write_string(rtoss(ptr[i].r),false);
- write_string(", "+rtoss(ptr[i].g),false);
- write_string(", "+rtoss(ptr[i].b),false);
- write_string(", "+rtoss(ptr[i].a),false);
-
- }
-
- } break;
- default: {}
-
- }
- if (oneliner)
- f->store_8(' ');
- else
- write_tabs(-1);
- exit_tag(type);
-
- f->store_8('\n');
-
- if (r_ok)
- *r_ok=true;
-
-}
-
-
-void ResourceFormatSaverXMLInstance::_find_resources(const Variant& p_variant,bool p_main) {
-
-
- switch(p_variant.get_type()) {
- case Variant::OBJECT: {
-
-
- RES res = p_variant.operator RefPtr();
-
- if (res.is_null() || external_resources.has(res))
- return;
-
- if (!p_main && (!bundle_resources ) && res->get_path().length() && res->get_path().find("::") == -1 ) {
- int index = external_resources.size();
- external_resources[res]=index;
- return;
- }
-
- if (resource_set.has(res))
- return;
-
- List<PropertyInfo> property_list;
-
- res->get_property_list( &property_list );
- property_list.sort();
-
- List<PropertyInfo>::Element *I=property_list.front();
-
- while(I) {
-
- PropertyInfo pi=I->get();
-
- if (pi.usage&PROPERTY_USAGE_STORAGE || (bundle_resources && pi.usage&PROPERTY_USAGE_BUNDLE)) {
-
- Variant v=res->get(I->get().name);
- _find_resources(v);
- }
-
- I=I->next();
- }
-
- resource_set.insert( res ); //saved after, so the childs it needs are available when loaded
- saved_resources.push_back(res);
-
- } break;
- case Variant::ARRAY: {
-
- Array varray=p_variant;
- int len=varray.size();
- for(int i=0;i<len;i++) {
-
- Variant v=varray.get(i);
- _find_resources(v);
- }
-
- } break;
- case Variant::DICTIONARY: {
-
- Dictionary d=p_variant;
- List<Variant> keys;
- d.get_key_list(&keys);
- for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
-
- Variant v = d[E->get()];
- _find_resources(v);
- }
- } break;
- default: {}
- }
-
-}
-
-
-
-Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {
-
- Error err;
- f = FileAccess::open(p_path, FileAccess::WRITE,&err);
- ERR_FAIL_COND_V( err, ERR_CANT_OPEN );
- FileAccessRef _fref(f);
-
- local_path = Globals::get_singleton()->localize_path(p_path);
-
- relative_paths=p_flags&ResourceSaver::FLAG_RELATIVE_PATHS;
- skip_editor=p_flags&ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES;
- bundle_resources=p_flags&ResourceSaver::FLAG_BUNDLE_RESOURCES;
- takeover_paths=p_flags&ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
- if (!p_path.begins_with("res://")) {
- takeover_paths=false;
- }
- depth=0;
-
- // save resources
- _find_resources(p_resource,true);
-
- ERR_FAIL_COND_V(err!=OK,err);
-
- write_string("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>",false); //no escape
- write_string("\n",false);
- enter_tag("resource_file","type=\""+p_resource->get_type()+"\" subresource_count=\""+itos(saved_resources.size()+external_resources.size())+"\" version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\" version_name=\""+VERSION_FULL_NAME+"\"");
- write_string("\n",false);
-
- for(Map<RES,int>::Element *E=external_resources.front();E;E=E->next()) {
-
- write_tabs();
- String p = E->key()->get_path();
-
- enter_tag("ext_resource","path=\""+p+"\" type=\""+E->key()->get_save_type()+"\" index=\""+itos(E->get())+"\""); //bundled
- exit_tag("ext_resource"); //bundled
- write_string("\n",false);
- }
-
- Set<int> used_indices;
-
- for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) {
-
- RES res = E->get();
- if (E->next() && (res->get_path()=="" || res->get_path().find("::") != -1 )) {
-
- if (res->get_subindex()!=0) {
- if (used_indices.has(res->get_subindex())) {
- res->set_subindex(0); //repeated
- } else {
- used_indices.insert(res->get_subindex());
- }
- }
- }
- }
-
- for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) {
-
- RES res = E->get();
- ERR_CONTINUE(!resource_set.has(res));
- bool main = (E->next()==NULL);
-
- write_tabs();
-
- if (main)
- enter_tag("main_resource",""); //bundled
- else if (res->get_path().length() && res->get_path().find("::") == -1 )
- enter_tag("resource","type=\""+res->get_type()+"\" path=\""+res->get_path()+"\""); //bundled
- else {
-
- if (res->get_subindex()==0) {
- int new_subindex=1;
- if (used_indices.size()) {
- new_subindex=used_indices.back()->get()+1;
- }
-
- res->set_subindex(new_subindex);
- used_indices.insert(new_subindex);
- }
-
- int idx = res->get_subindex();
- enter_tag("resource","type=\""+res->get_type()+"\" path=\"local://"+itos(idx)+"\"");
- if (takeover_paths) {
- res->set_path(p_path+"::"+itos(idx),true);
- }
-#ifdef TOOLS_ENABLED
- res->set_edited(false);
-#endif
-
-
- }
- write_string("\n",false);
-
-
- List<PropertyInfo> property_list;
- res->get_property_list(&property_list);
-// property_list.sort();
- for(List<PropertyInfo>::Element *PE = property_list.front();PE;PE=PE->next()) {
-
-
- if (skip_editor && PE->get().name.begins_with("__editor"))
- continue;
-
- if (PE->get().usage&PROPERTY_USAGE_STORAGE || (bundle_resources && PE->get().usage&PROPERTY_USAGE_BUNDLE)) {
-
- String name = PE->get().name;
- Variant value = res->get(name);
-
-
- if ((PE->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero())||(PE->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && value.is_one()) )
- continue;
-
-
- write_property(name,value);
- }
-
-
- }
-
- write_string("\n",false);
- write_tabs(-1);
- if (main)
- exit_tag("main_resource");
- else
- exit_tag("resource");
-
- write_string("\n",false);
- }
-
- exit_tag("resource_file");
- if (f->get_error()!=OK && f->get_error()!=ERR_FILE_EOF) {
- f->close();
- return ERR_CANT_CREATE;
- }
-
- f->close();
- //memdelete(f);
-
- return OK;
-}
-
-
-
-Error ResourceFormatSaverXML::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {
-
- ResourceFormatSaverXMLInstance saver;
- return saver.save(p_path,p_resource,p_flags);
-
-}
-
-bool ResourceFormatSaverXML::recognize(const RES& p_resource) const {
-
-
- return true; // all recognized!
-}
-void ResourceFormatSaverXML::get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const {
-
-
- //here comes the sun, lalalala
- String base = p_resource->get_base_extension().to_lower();
- p_extensions->push_back("xml");
- if (base!="res") {
-
- p_extensions->push_back("x"+base);
- }
-
-}
-
-ResourceFormatSaverXML* ResourceFormatSaverXML::singleton=NULL;
-ResourceFormatSaverXML::ResourceFormatSaverXML() {
- singleton=this;
-}
diff --git a/core/io/resource_format_xml.h b/core/io/resource_format_xml.h
deleted file mode 100644
index 94c81a4111..0000000000
--- a/core/io/resource_format_xml.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/*************************************************************************/
-/* resource_format_xml.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef RESOURCE_FORMAT_XML_H
-#define RESOURCE_FORMAT_XML_H
-
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
-
-
-
-class ResourceInteractiveLoaderXML : public ResourceInteractiveLoader {
-
- String local_path;
- String res_path;
-
- FileAccess *f;
-
- struct Tag {
-
- String name;
- HashMap<String,String> args;
-
- };
-
- _FORCE_INLINE_ Error _parse_array_element(Vector<char> &buff,bool p_number_only,FileAccess *f,bool *end);
-
-
- struct ExtResource {
- String path;
- String type;
- };
-
-
- Map<String,String> remaps;
-
- Map<int,ExtResource> ext_resources;
-
- int resources_total;
- int resource_current;
- String resource_type;
-
- mutable int lines;
- uint8_t get_char() const;
- int get_current_line() const;
-
-friend class ResourceFormatLoaderXML;
- List<Tag> tag_stack;
-
- List<RES> resource_cache;
- Tag* parse_tag(bool* r_exit=NULL,bool p_printerr=true,List<String> *r_order=NULL);
- Error close_tag(const String& p_name);
- _FORCE_INLINE_ void unquote(String& p_str);
- Error goto_end_of_tag();
- Error parse_property_data(String &r_data);
- Error parse_property(Variant& r_v, String &r_name);
-
- Error error;
-
- RES resource;
-
-public:
-
- virtual void set_local_path(const String& p_local_path);
- virtual Ref<Resource> get_resource();
- virtual Error poll();
- virtual int get_stage() const;
- virtual int get_stage_count() const;
-
- void open(FileAccess *p_f);
- String recognize(FileAccess *p_f);
- void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types);
- Error rename_dependencies(FileAccess *p_f, const String &p_path,const Map<String,String>& p_map);
-
-
- ~ResourceInteractiveLoaderXML();
-
-};
-
-class ResourceFormatLoaderXML : public ResourceFormatLoader {
-public:
-
- virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,Error *r_error=NULL);
- virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
- virtual void get_recognized_extensions(List<String> *p_extensions) 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 Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
-
-
-};
-
-
-////////////////////////////////////////////////////////////////////////////////////////////
-
-
-class ResourceFormatSaverXMLInstance {
-
- String local_path;
-
-
-
- bool takeover_paths;
- bool relative_paths;
- bool bundle_resources;
- bool skip_editor;
- FileAccess *f;
- int depth;
- Set<RES> resource_set;
- List<RES> saved_resources;
- Map<RES,int> external_resources;
-
- void enter_tag(const char* p_tag,const String& p_args=String());
- void exit_tag(const char* p_tag);
-
- void _find_resources(const Variant& p_variant,bool p_main=false);
- void write_property(const String& p_name,const Variant& p_property,bool *r_ok=NULL);
-
-
- void escape(String& p_str);
- void write_tabs(int p_diff=0);
- void write_string(String p_str,bool p_escape=true);
-
-
-public:
-
- Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
-
-
-};
-
-class ResourceFormatSaverXML : public ResourceFormatSaver {
-public:
- static ResourceFormatSaverXML* singleton;
- virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0);
- virtual bool recognize(const RES& p_resource) const;
- virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const;
-
- ResourceFormatSaverXML();
-};
-
-
-#endif // RESOURCE_FORMAT_XML_H
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 08b4139047..354efaa83f 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -55,7 +55,7 @@ bool ResourceFormatLoader::recognize(const String& p_extension) const {
get_recognized_extensions(&extensions);
for (List<String>::Element *E=extensions.front();E;E=E->next()) {
- if (E->get().nocasecmp_to(p_extension.extension())==0)
+ if (E->get().nocasecmp_to(p_extension.get_extension())==0)
return true;
}
@@ -78,16 +78,16 @@ void ResourceLoader::get_recognized_extensions_for_type(const String& p_type,Lis
void ResourceInteractiveLoader::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("get_resource"),&ResourceInteractiveLoader::get_resource);
- ObjectTypeDB::bind_method(_MD("poll"),&ResourceInteractiveLoader::poll);
- ObjectTypeDB::bind_method(_MD("wait"),&ResourceInteractiveLoader::wait);
- ObjectTypeDB::bind_method(_MD("get_stage"),&ResourceInteractiveLoader::get_stage);
- ObjectTypeDB::bind_method(_MD("get_stage_count"),&ResourceInteractiveLoader::get_stage_count);
+ ClassDB::bind_method(_MD("get_resource"),&ResourceInteractiveLoader::get_resource);
+ ClassDB::bind_method(_MD("poll"),&ResourceInteractiveLoader::poll);
+ ClassDB::bind_method(_MD("wait"),&ResourceInteractiveLoader::wait);
+ ClassDB::bind_method(_MD("get_stage"),&ResourceInteractiveLoader::get_stage);
+ ClassDB::bind_method(_MD("get_stage_count"),&ResourceInteractiveLoader::get_stage_count);
}
class ResourceInteractiveLoaderDefault : public ResourceInteractiveLoader {
- OBJ_TYPE( ResourceInteractiveLoaderDefault, ResourceInteractiveLoader );
+ GDCLASS( ResourceInteractiveLoaderDefault, ResourceInteractiveLoader );
public:
Ref<Resource> resource;
@@ -164,7 +164,7 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
if (p_path.is_rel_path())
local_path="res://"+p_path;
else
- local_path = Globals::get_singleton()->localize_path(p_path);
+ 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());
@@ -182,7 +182,7 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
if (OS::get_singleton()->is_stdout_verbose())
print_line("load resource: "+remapped_path);
- String extension=remapped_path.extension();
+ String extension=remapped_path.get_extension();
bool found=false;
for (int i=0;i<loader_count;i++) {
@@ -228,9 +228,9 @@ Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p
if (p_path.is_rel_path())
local_path="res://"+p_path;
else
- local_path = Globals::get_singleton()->localize_path(p_path);
+ local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- String extension=p_path.extension();
+ String extension=p_path.get_extension();
Ref<ResourceImportMetadata> ret;
for (int i=0;i<loader_count;i++) {
@@ -285,7 +285,7 @@ String ResourceLoader::find_complete_path(const String& p_path,const String& p_t
for(List<String>::Element *E=candidates.front();E;E=E->next()) {
String rt = get_resource_type(E->get());
- if (ObjectTypeDB::is_type(rt,p_type)) {
+ if (ClassDB::is_parent_class(rt,p_type)) {
return E->get();
}
}
@@ -307,7 +307,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
if (p_path.is_rel_path())
local_path="res://"+p_path;
else
- local_path = Globals::get_singleton()->localize_path(p_path);
+ 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>());
@@ -331,7 +331,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
- String extension=remapped_path.extension();
+ String extension=remapped_path.get_extension();
bool found=false;
for (int i=0;i<loader_count;i++) {
@@ -381,18 +381,20 @@ void ResourceLoader::get_dependencies(const String& p_path, List<String> *p_depe
if (p_path.is_rel_path())
local_path="res://"+p_path;
else
- local_path = Globals::get_singleton()->localize_path(p_path);
+ local_path = GlobalConfig::get_singleton()->localize_path(p_path);
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
- String extension=remapped_path.extension();
+ String extension=remapped_path.get_extension();
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))
- // continue;
+ /*
+ if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
+ continue;
+ */
loader[i]->get_dependencies(remapped_path,p_dependencies,p_add_types);
@@ -406,18 +408,20 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String,
if (p_path.is_rel_path())
local_path="res://"+p_path;
else
- local_path = Globals::get_singleton()->localize_path(p_path);
+ local_path = GlobalConfig::get_singleton()->localize_path(p_path);
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
- String extension=remapped_path.extension();
+ String extension=remapped_path.get_extension();
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))
- // continue;
+ /*
+ if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
+ continue;
+ */
return loader[i]->rename_dependencies(p_path,p_map);
@@ -434,7 +438,7 @@ String ResourceLoader::guess_full_filename(const String &p_path,const String& p_
if (p_path.is_rel_path())
local_path="res://"+p_path;
else
- local_path = Globals::get_singleton()->localize_path(p_path);
+ local_path = GlobalConfig::get_singleton()->localize_path(p_path);
return find_complete_path(local_path,p_type);
@@ -446,10 +450,10 @@ String ResourceLoader::get_resource_type(const String &p_path) {
if (p_path.is_rel_path())
local_path="res://"+p_path;
else
- local_path = Globals::get_singleton()->localize_path(p_path);
+ local_path = GlobalConfig::get_singleton()->localize_path(p_path);
String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
- String extension=remapped_path.extension();
+ 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 f976a43d91..7979bd02a7 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,7 +37,7 @@
class ResourceInteractiveLoader : public Reference {
- OBJ_TYPE(ResourceInteractiveLoader,Reference);
+ GDCLASS(ResourceInteractiveLoader,Reference);
protected:
static void _bind_methods();
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 2ead405440..222d3e6bc0 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -40,7 +40,7 @@ ResourceSavedCallback ResourceSaver::save_callback=0;
Error ResourceSaver::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {
- String extension=p_path.extension();
+ String extension=p_path.get_extension();
Error err=ERR_FILE_UNRECOGNIZED;
for (int i=0;i<saver_count;i++) {
@@ -54,7 +54,7 @@ Error ResourceSaver::save(const String &p_path,const RES& p_resource,uint32_t p_
for (List<String>::Element *E=extensions.front();E;E=E->next()) {
- if (E->get().nocasecmp_to(extension.extension())==0)
+ if (E->get().nocasecmp_to(extension.get_extension())==0)
recognized=true;
}
@@ -64,7 +64,7 @@ Error ResourceSaver::save(const String &p_path,const RES& p_resource,uint32_t p_
String old_path=p_resource->get_path();
- String local_path=Globals::get_singleton()->localize_path(p_path);
+ String local_path=GlobalConfig::get_singleton()->localize_path(p_path);
RES rwcopy = p_resource;
if (p_flags&FLAG_CHANGE_PATH)
diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h
index b05ae23afc..f00f074090 100644
--- a/core/io/resource_saver.h
+++ b/core/io/resource_saver.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index baaeacaf18..a2812edb81 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,16 +29,16 @@
#include "stream_peer.h"
#include "io/marshalls.h"
-Error StreamPeer::_put_data(const DVector<uint8_t>& p_data) {
+Error StreamPeer::_put_data(const PoolVector<uint8_t>& p_data) {
int len = p_data.size();
if (len==0)
return OK;
- DVector<uint8_t>::Read r = p_data.read();
+ PoolVector<uint8_t>::Read r = p_data.read();
return put_data(&r[0],len);
}
-Array StreamPeer::_put_partial_data(const DVector<uint8_t>& p_data) {
+Array StreamPeer::_put_partial_data(const PoolVector<uint8_t>& p_data) {
Array ret;
@@ -49,7 +49,7 @@ Array StreamPeer::_put_partial_data(const DVector<uint8_t>& p_data) {
return ret;
}
- DVector<uint8_t>::Read r = p_data.read();
+ PoolVector<uint8_t>::Read r = p_data.read();
int sent;
Error err = put_partial_data(&r[0],len,sent);
@@ -66,18 +66,18 @@ Array StreamPeer::_get_data(int p_bytes) {
Array ret;
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
data.resize(p_bytes);
if (data.size()!=p_bytes) {
ret.push_back(ERR_OUT_OF_MEMORY);
- ret.push_back(DVector<uint8_t>());
+ ret.push_back(PoolVector<uint8_t>());
return ret;
}
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
Error err = get_data(&w[0],p_bytes);
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
ret.push_back(err);
ret.push_back(data);
return ret;
@@ -88,19 +88,19 @@ Array StreamPeer::_get_partial_data(int p_bytes) {
Array ret;
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
data.resize(p_bytes);
if (data.size()!=p_bytes) {
ret.push_back(ERR_OUT_OF_MEMORY);
- ret.push_back(DVector<uint8_t>());
+ ret.push_back(PoolVector<uint8_t>());
return ret;
}
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
int received;
Error err = get_partial_data(&w[0],p_bytes,received);
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
if (err!=OK) {
data.resize(0);
@@ -389,57 +389,57 @@ Variant StreamPeer::get_var(){
void StreamPeer::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("put_data","data"),&StreamPeer::_put_data);
- ObjectTypeDB::bind_method(_MD("put_partial_data","data"),&StreamPeer::_put_partial_data);
-
- ObjectTypeDB::bind_method(_MD("get_data","bytes"),&StreamPeer::_get_data);
- ObjectTypeDB::bind_method(_MD("get_partial_data","bytes"),&StreamPeer::_get_partial_data);
-
- ObjectTypeDB::bind_method(_MD("get_available_bytes"),&StreamPeer::get_available_bytes);
-
- ObjectTypeDB::bind_method(_MD("set_big_endian","enable"),&StreamPeer::set_big_endian);
- ObjectTypeDB::bind_method(_MD("is_big_endian_enabled"),&StreamPeer::is_big_endian_enabled);
-
- ObjectTypeDB::bind_method(_MD("put_8","val"),&StreamPeer::put_8);
- ObjectTypeDB::bind_method(_MD("put_u8","val"),&StreamPeer::put_u8);
- ObjectTypeDB::bind_method(_MD("put_16","val"),&StreamPeer::put_16);
- ObjectTypeDB::bind_method(_MD("put_u16","val"),&StreamPeer::put_u16);
- ObjectTypeDB::bind_method(_MD("put_32","val"),&StreamPeer::put_32);
- ObjectTypeDB::bind_method(_MD("put_u32","val"),&StreamPeer::put_u32);
- ObjectTypeDB::bind_method(_MD("put_64","val"),&StreamPeer::put_64);
- ObjectTypeDB::bind_method(_MD("put_u64","val"),&StreamPeer::put_u64);
- ObjectTypeDB::bind_method(_MD("put_float","val"),&StreamPeer::put_float);
- ObjectTypeDB::bind_method(_MD("put_double","val"),&StreamPeer::put_double);
- ObjectTypeDB::bind_method(_MD("put_utf8_string","val"),&StreamPeer::put_utf8_string);
- ObjectTypeDB::bind_method(_MD("put_var","val:Variant"),&StreamPeer::put_var);
-
- ObjectTypeDB::bind_method(_MD("get_8"),&StreamPeer::get_8);
- ObjectTypeDB::bind_method(_MD("get_u8"),&StreamPeer::get_u8);
- ObjectTypeDB::bind_method(_MD("get_16"),&StreamPeer::get_16);
- ObjectTypeDB::bind_method(_MD("get_u16"),&StreamPeer::get_u16);
- ObjectTypeDB::bind_method(_MD("get_32"),&StreamPeer::get_32);
- ObjectTypeDB::bind_method(_MD("get_u32"),&StreamPeer::get_u32);
- ObjectTypeDB::bind_method(_MD("get_64"),&StreamPeer::get_64);
- ObjectTypeDB::bind_method(_MD("get_u64"),&StreamPeer::get_u64);
- ObjectTypeDB::bind_method(_MD("get_float"),&StreamPeer::get_float);
- ObjectTypeDB::bind_method(_MD("get_double"),&StreamPeer::get_double);
- ObjectTypeDB::bind_method(_MD("get_string","bytes"),&StreamPeer::get_string);
- ObjectTypeDB::bind_method(_MD("get_utf8_string","bytes"),&StreamPeer::get_utf8_string);
- ObjectTypeDB::bind_method(_MD("get_var:Variant"),&StreamPeer::get_var);
+ ClassDB::bind_method(_MD("put_data","data"),&StreamPeer::_put_data);
+ ClassDB::bind_method(_MD("put_partial_data","data"),&StreamPeer::_put_partial_data);
+
+ ClassDB::bind_method(_MD("get_data","bytes"),&StreamPeer::_get_data);
+ ClassDB::bind_method(_MD("get_partial_data","bytes"),&StreamPeer::_get_partial_data);
+
+ ClassDB::bind_method(_MD("get_available_bytes"),&StreamPeer::get_available_bytes);
+
+ ClassDB::bind_method(_MD("set_big_endian","enable"),&StreamPeer::set_big_endian);
+ ClassDB::bind_method(_MD("is_big_endian_enabled"),&StreamPeer::is_big_endian_enabled);
+
+ ClassDB::bind_method(_MD("put_8","val"),&StreamPeer::put_8);
+ ClassDB::bind_method(_MD("put_u8","val"),&StreamPeer::put_u8);
+ ClassDB::bind_method(_MD("put_16","val"),&StreamPeer::put_16);
+ ClassDB::bind_method(_MD("put_u16","val"),&StreamPeer::put_u16);
+ ClassDB::bind_method(_MD("put_32","val"),&StreamPeer::put_32);
+ ClassDB::bind_method(_MD("put_u32","val"),&StreamPeer::put_u32);
+ ClassDB::bind_method(_MD("put_64","val"),&StreamPeer::put_64);
+ ClassDB::bind_method(_MD("put_u64","val"),&StreamPeer::put_u64);
+ ClassDB::bind_method(_MD("put_float","val"),&StreamPeer::put_float);
+ ClassDB::bind_method(_MD("put_double","val"),&StreamPeer::put_double);
+ ClassDB::bind_method(_MD("put_utf8_string","val"),&StreamPeer::put_utf8_string);
+ ClassDB::bind_method(_MD("put_var","val:Variant"),&StreamPeer::put_var);
+
+ ClassDB::bind_method(_MD("get_8"),&StreamPeer::get_8);
+ ClassDB::bind_method(_MD("get_u8"),&StreamPeer::get_u8);
+ ClassDB::bind_method(_MD("get_16"),&StreamPeer::get_16);
+ ClassDB::bind_method(_MD("get_u16"),&StreamPeer::get_u16);
+ ClassDB::bind_method(_MD("get_32"),&StreamPeer::get_32);
+ ClassDB::bind_method(_MD("get_u32"),&StreamPeer::get_u32);
+ ClassDB::bind_method(_MD("get_64"),&StreamPeer::get_64);
+ ClassDB::bind_method(_MD("get_u64"),&StreamPeer::get_u64);
+ ClassDB::bind_method(_MD("get_float"),&StreamPeer::get_float);
+ ClassDB::bind_method(_MD("get_double"),&StreamPeer::get_double);
+ ClassDB::bind_method(_MD("get_string","bytes"),&StreamPeer::get_string);
+ ClassDB::bind_method(_MD("get_utf8_string","bytes"),&StreamPeer::get_utf8_string);
+ ClassDB::bind_method(_MD("get_var:Variant"),&StreamPeer::get_var);
}
////////////////////////////////
void StreamPeerBuffer::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("seek","pos"),&StreamPeerBuffer::seek);
- ObjectTypeDB::bind_method(_MD("get_size"),&StreamPeerBuffer::get_size);
- ObjectTypeDB::bind_method(_MD("get_pos"),&StreamPeerBuffer::get_pos);
- ObjectTypeDB::bind_method(_MD("resize","size"),&StreamPeerBuffer::resize);
- ObjectTypeDB::bind_method(_MD("set_data_array","data"),&StreamPeerBuffer::set_data_array);
- ObjectTypeDB::bind_method(_MD("get_data_array"),&StreamPeerBuffer::get_data_array);
- ObjectTypeDB::bind_method(_MD("clear"),&StreamPeerBuffer::clear);
- ObjectTypeDB::bind_method(_MD("duplicate:StreamPeerBuffer"),&StreamPeerBuffer::duplicate);
+ ClassDB::bind_method(_MD("seek","pos"),&StreamPeerBuffer::seek);
+ ClassDB::bind_method(_MD("get_size"),&StreamPeerBuffer::get_size);
+ ClassDB::bind_method(_MD("get_pos"),&StreamPeerBuffer::get_pos);
+ ClassDB::bind_method(_MD("resize","size"),&StreamPeerBuffer::resize);
+ ClassDB::bind_method(_MD("set_data_array","data"),&StreamPeerBuffer::set_data_array);
+ ClassDB::bind_method(_MD("get_data_array"),&StreamPeerBuffer::get_data_array);
+ ClassDB::bind_method(_MD("clear"),&StreamPeerBuffer::clear);
+ ClassDB::bind_method(_MD("duplicate:StreamPeerBuffer"),&StreamPeerBuffer::duplicate);
}
@@ -454,7 +454,7 @@ Error StreamPeerBuffer::put_data(const uint8_t* p_data,int p_bytes) {
}
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
copymem(&w[pointer],p_data,p_bytes);
pointer+=p_bytes;
@@ -490,7 +490,7 @@ Error StreamPeerBuffer::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_r
r_received=p_bytes;
}
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
copymem(p_buffer,r.ptr(),r_received);
}
@@ -520,13 +520,13 @@ void StreamPeerBuffer::resize(int p_size){
data.resize(p_size);
}
-void StreamPeerBuffer::set_data_array(const DVector<uint8_t> & p_data){
+void StreamPeerBuffer::set_data_array(const PoolVector<uint8_t> & p_data){
data=p_data;
pointer=0;
}
-DVector<uint8_t> StreamPeerBuffer::get_data_array() const{
+PoolVector<uint8_t> StreamPeerBuffer::get_data_array() const{
return data;
}
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index f28e6f594d..eb0f90ba50 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,14 +32,14 @@
#include "reference.h"
class StreamPeer : public Reference {
- OBJ_TYPE( StreamPeer, Reference );
+ GDCLASS( StreamPeer, Reference );
OBJ_CATEGORY("Networking");
protected:
static void _bind_methods();
//bind helpers
- Error _put_data(const DVector<uint8_t>& p_data);
- Array _put_partial_data(const DVector<uint8_t>& p_data);
+ Error _put_data(const PoolVector<uint8_t>& p_data);
+ Array _put_partial_data(const PoolVector<uint8_t>& p_data);
Array _get_data(int p_bytes);
Array _get_partial_data(int p_bytes);
@@ -94,9 +94,9 @@ public:
class StreamPeerBuffer : public StreamPeer {
- OBJ_TYPE(StreamPeerBuffer,StreamPeer);
+ GDCLASS(StreamPeerBuffer,StreamPeer);
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
int pointer;
protected:
@@ -116,8 +116,8 @@ public:
void resize(int p_size);
- void set_data_array(const DVector<uint8_t> & p_data);
- DVector<uint8_t> get_data_array() const;
+ void set_data_array(const PoolVector<uint8_t> & p_data);
+ PoolVector<uint8_t> get_data_array() const;
void clear();
diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp
index a58be84225..fc535e94b0 100644
--- a/core/io/stream_peer_ssl.cpp
+++ b/core/io/stream_peer_ssl.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -45,7 +45,7 @@ StreamPeerSSL::LoadCertsFromMemory StreamPeerSSL::load_certs_func=NULL;
bool StreamPeerSSL::available=false;
bool StreamPeerSSL::initialize_certs=true;
-void StreamPeerSSL::load_certs_from_memory(const ByteArray& p_memory) {
+void StreamPeerSSL::load_certs_from_memory(const PoolByteArray& p_memory) {
if (load_certs_func)
load_certs_func(p_memory);
}
@@ -57,10 +57,10 @@ bool StreamPeerSSL::is_available() {
void StreamPeerSSL::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("accept:Error","stream:StreamPeer"),&StreamPeerSSL::accept);
- ObjectTypeDB::bind_method(_MD("connect:Error","stream:StreamPeer","validate_certs","for_hostname"),&StreamPeerSSL::connect,DEFVAL(false),DEFVAL(String()));
- ObjectTypeDB::bind_method(_MD("get_status"),&StreamPeerSSL::get_status);
- ObjectTypeDB::bind_method(_MD("disconnect"),&StreamPeerSSL::disconnect);
+ ClassDB::bind_method(_MD("accept_stream:Error","stream:StreamPeer"),&StreamPeerSSL::accept_stream);
+ ClassDB::bind_method(_MD("connect_to_stream:Error","stream:StreamPeer","validate_certs","for_hostname"),&StreamPeerSSL::connect_to_stream,DEFVAL(false),DEFVAL(String()));
+ ClassDB::bind_method(_MD("get_status"),&StreamPeerSSL::get_status);
+ ClassDB::bind_method(_MD("disconnect_from_stream"),&StreamPeerSSL::disconnect_from_stream);
BIND_CONSTANT( STATUS_DISCONNECTED );
BIND_CONSTANT( STATUS_CONNECTED );
BIND_CONSTANT( STATUS_ERROR_NO_CERTIFICATE );
diff --git a/core/io/stream_peer_ssl.h b/core/io/stream_peer_ssl.h
index 3435a9a445..9aafac874d 100644
--- a/core/io/stream_peer_ssl.h
+++ b/core/io/stream_peer_ssl.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,10 +32,10 @@
#include "io/stream_peer.h"
class StreamPeerSSL : public StreamPeer {
- OBJ_TYPE(StreamPeerSSL,StreamPeer);
+ GDCLASS(StreamPeerSSL,StreamPeer);
public:
- typedef void (*LoadCertsFromMemory)(const ByteArray& p_certs);
+ typedef void (*LoadCertsFromMemory)(const PoolByteArray& p_certs);
protected:
static StreamPeerSSL* (*_create)();
static void _bind_methods();
@@ -57,15 +57,15 @@ public:
STATUS_ERROR_HOSTNAME_MISMATCH
};
- virtual Error accept(Ref<StreamPeer> p_base)=0;
- virtual Error connect(Ref<StreamPeer> p_base,bool p_validate_certs=false,const String& p_for_hostname=String())=0;
+ virtual Error accept_stream(Ref<StreamPeer> p_base)=0;
+ virtual Error connect_to_stream(Ref<StreamPeer> p_base,bool p_validate_certs=false,const String& p_for_hostname=String())=0;
virtual Status get_status() const=0;
- virtual void disconnect()=0;
+ virtual void disconnect_from_stream()=0;
static StreamPeerSSL* create();
- static void load_certs_from_memory(const ByteArray& p_memory);
+ static void load_certs_from_memory(const PoolByteArray& p_memory);
static bool is_available();
StreamPeerSSL();
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index fbb0c69cb7..0a59c32995 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,14 +30,35 @@
StreamPeerTCP* (*StreamPeerTCP::_create)()=NULL;
+Error StreamPeerTCP::_connect(const String& p_address,int p_port) {
+
+ IP_Address ip;
+ if (p_address.is_valid_ip_address()) {
+ ip=p_address;
+ } else {
+ ip=IP::get_singleton()->resolve_hostname(p_address, ip_type);
+ if (ip==IP_Address())
+ return ERR_CANT_RESOLVE;
+ }
+
+ connect_to_host(ip,p_port);
+ return OK;
+}
+
+void StreamPeerTCP::set_ip_type(IP::Type p_type) {
+ disconnect_from_host();
+ ip_type = p_type;
+}
+
void StreamPeerTCP::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("connect","host","port"),&StreamPeerTCP::connect);
- ObjectTypeDB::bind_method(_MD("is_connected"),&StreamPeerTCP::is_connected);
- ObjectTypeDB::bind_method(_MD("get_status"),&StreamPeerTCP::get_status);
- ObjectTypeDB::bind_method(_MD("get_connected_host"),&StreamPeerTCP::get_connected_host);
- ObjectTypeDB::bind_method(_MD("get_connected_port"),&StreamPeerTCP::get_connected_port);
- ObjectTypeDB::bind_method(_MD("disconnect"),&StreamPeerTCP::disconnect);
+ ClassDB::bind_method(_MD("set_ip_type","ip_type"),&StreamPeerTCP::set_ip_type);
+ ClassDB::bind_method(_MD("connect_to_host","host","port"),&StreamPeerTCP::_connect);
+ ClassDB::bind_method(_MD("is_connected_to_host"),&StreamPeerTCP::is_connected_to_host);
+ ClassDB::bind_method(_MD("get_status"),&StreamPeerTCP::get_status);
+ ClassDB::bind_method(_MD("get_connected_host"),&StreamPeerTCP::get_connected_host);
+ ClassDB::bind_method(_MD("get_connected_port"),&StreamPeerTCP::get_connected_port);
+ ClassDB::bind_method(_MD("disconnect_from_host"),&StreamPeerTCP::disconnect_from_host);
BIND_CONSTANT( STATUS_NONE );
BIND_CONSTANT( STATUS_CONNECTING );
@@ -62,6 +83,7 @@ StreamPeerTCP* StreamPeerTCP::create() {
StreamPeerTCP::StreamPeerTCP() {
+ ip_type = IP::TYPE_ANY;
}
StreamPeerTCP::~StreamPeerTCP() {
diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h
index 4c58e7e149..2b25f31739 100644
--- a/core/io/stream_peer_tcp.h
+++ b/core/io/stream_peer_tcp.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,10 +32,11 @@
#include "stream_peer.h"
#include "ip_address.h"
+#include "io/ip.h"
class StreamPeerTCP : public StreamPeer {
- OBJ_TYPE( StreamPeerTCP, StreamPeer );
+ GDCLASS( StreamPeerTCP, StreamPeer );
OBJ_CATEGORY("Networking");
public:
@@ -50,18 +51,22 @@ public:
protected:
+ IP::Type ip_type;
+
+ virtual Error _connect(const String& p_address, int p_port);
static StreamPeerTCP* (*_create)();
static void _bind_methods();
public:
- virtual Error connect(const IP_Address& p_host, uint16_t p_port)=0;
+ virtual void set_ip_type(IP::Type p_type);
+ virtual Error connect_to_host(const IP_Address& p_host, uint16_t p_port)=0;
//read/write from streampeer
- virtual bool is_connected() const=0;
+ virtual bool is_connected_to_host() const=0;
virtual Status get_status() const=0;
- virtual void disconnect()=0;
+ virtual void disconnect_from_host()=0;
virtual IP_Address get_connected_host() const=0;
virtual uint16_t get_connected_port() const=0;
virtual void set_nodelay(bool p_enabled)=0;
diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp
index 274d20a48a..bfa5dce58f 100644
--- a/core/io/tcp_server.cpp
+++ b/core/io/tcp_server.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -44,26 +44,33 @@ TCP_Server* TCP_Server::create() {
return _create();
}
-Error TCP_Server::_listen(uint16_t p_port,DVector<String> p_accepted_hosts) {
+Error TCP_Server::_listen(uint16_t p_port, PoolVector<String> p_accepted_hosts) {
List<String> hosts;
for(int i=0;i<p_accepted_hosts.size();i++)
hosts.push_back(p_accepted_hosts.get(i));
- return listen(p_port,hosts.size()?&hosts:NULL);
+ return listen(p_port, hosts.size()?&hosts:NULL);
}
+void TCP_Server::set_ip_type(IP::Type p_type) {
+ stop();
+ ip_type = p_type;
+}
+
void TCP_Server::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("listen","port","accepted_hosts"),&TCP_Server::_listen,DEFVAL(DVector<String>()));
- ObjectTypeDB::bind_method(_MD("is_connection_available"),&TCP_Server::is_connection_available);
- ObjectTypeDB::bind_method(_MD("take_connection"),&TCP_Server::take_connection);
- ObjectTypeDB::bind_method(_MD("stop"),&TCP_Server::stop);
+ ClassDB::bind_method(_MD("set_ip_type","ip_type"),&TCP_Server::set_ip_type);
+ ClassDB::bind_method(_MD("listen","port","accepted_hosts"),&TCP_Server::_listen,DEFVAL(PoolVector<String>()));
+ ClassDB::bind_method(_MD("is_connection_available"),&TCP_Server::is_connection_available);
+ ClassDB::bind_method(_MD("take_connection"),&TCP_Server::take_connection);
+ ClassDB::bind_method(_MD("stop"),&TCP_Server::stop);
}
TCP_Server::TCP_Server()
{
+ ip_type = IP::TYPE_ANY;
}
diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h
index 512a7e640a..3d7b3ddd8d 100644
--- a/core/io/tcp_server.h
+++ b/core/io/tcp_server.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -35,17 +35,20 @@
class TCP_Server : public Reference {
- OBJ_TYPE( TCP_Server, Reference );
+ GDCLASS( TCP_Server, Reference );
protected:
+ IP::Type ip_type;
+
static TCP_Server* (*_create)();
//bind helper
- Error _listen(uint16_t p_port,DVector<String> p_accepted_hosts=DVector<String>());
+ Error _listen(uint16_t p_port, PoolVector<String> p_accepted_hosts=PoolVector<String>());
static void _bind_methods();
public:
- virtual Error listen(uint16_t p_port,const List<String> *p_accepted_hosts=NULL)=0;
+ virtual void set_ip_type(IP::Type p_type);
+ virtual Error listen(uint16_t p_port, const List<String> *p_accepted_hosts=NULL)=0;
virtual bool is_connection_available() const=0;
virtual Ref<StreamPeerTCP> take_connection()=0;
diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp
index a22c57b941..bee38e037f 100644
--- a/core/io/translation_loader_po.cpp
+++ b/core/io/translation_loader_po.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,8 +33,6 @@
RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const String &p_path) {
- String l = f->get_line();
-
enum Status {
STATUS_NONE,
@@ -206,7 +204,7 @@ bool TranslationLoaderPO::handles_type(const String& p_type) const{
String TranslationLoaderPO::get_resource_type(const String &p_path) const {
- if (p_path.extension().to_lower()=="po")
+ if (p_path.get_extension().to_lower()=="po")
return "Translation";
return "";
}
diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h
index b0c4e42682..127c8dafab 100644
--- a/core/io/translation_loader_po.h
+++ b/core/io/translation_loader_po.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp
index e6a90412c1..0322f23056 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -379,23 +379,23 @@ Error XMLParser::seek(uint64_t p_pos) {
void XMLParser::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("read"),&XMLParser::read);
- ObjectTypeDB::bind_method(_MD("get_node_type"),&XMLParser::get_node_type);
- ObjectTypeDB::bind_method(_MD("get_node_name"),&XMLParser::get_node_name);
- ObjectTypeDB::bind_method(_MD("get_node_data"),&XMLParser::get_node_data);
- ObjectTypeDB::bind_method(_MD("get_node_offset"),&XMLParser::get_node_offset);
- ObjectTypeDB::bind_method(_MD("get_attribute_count"),&XMLParser::get_attribute_count);
- ObjectTypeDB::bind_method(_MD("get_attribute_name","idx"),&XMLParser::get_attribute_name);
- ObjectTypeDB::bind_method(_MD("get_attribute_value","idx"),(String (XMLParser::*)(int) const) &XMLParser::get_attribute_value);
- ObjectTypeDB::bind_method(_MD("has_attribute","name"),&XMLParser::has_attribute);
- ObjectTypeDB::bind_method(_MD("get_named_attribute_value","name"), (String (XMLParser::*)(const String&) const) &XMLParser::get_attribute_value);
- ObjectTypeDB::bind_method(_MD("get_named_attribute_value_safe","name"), &XMLParser::get_attribute_value_safe);
- ObjectTypeDB::bind_method(_MD("is_empty"),&XMLParser::is_empty);
- ObjectTypeDB::bind_method(_MD("get_current_line"),&XMLParser::get_current_line);
- ObjectTypeDB::bind_method(_MD("skip_section"),&XMLParser::skip_section);
- ObjectTypeDB::bind_method(_MD("seek","pos"),&XMLParser::seek);
- ObjectTypeDB::bind_method(_MD("open","file"),&XMLParser::open);
- ObjectTypeDB::bind_method(_MD("open_buffer","buffer"),&XMLParser::open_buffer);
+ ClassDB::bind_method(_MD("read"),&XMLParser::read);
+ ClassDB::bind_method(_MD("get_node_type"),&XMLParser::get_node_type);
+ ClassDB::bind_method(_MD("get_node_name"),&XMLParser::get_node_name);
+ ClassDB::bind_method(_MD("get_node_data"),&XMLParser::get_node_data);
+ ClassDB::bind_method(_MD("get_node_offset"),&XMLParser::get_node_offset);
+ ClassDB::bind_method(_MD("get_attribute_count"),&XMLParser::get_attribute_count);
+ ClassDB::bind_method(_MD("get_attribute_name","idx"),&XMLParser::get_attribute_name);
+ ClassDB::bind_method(_MD("get_attribute_value","idx"),(String (XMLParser::*)(int) const) &XMLParser::get_attribute_value);
+ ClassDB::bind_method(_MD("has_attribute","name"),&XMLParser::has_attribute);
+ ClassDB::bind_method(_MD("get_named_attribute_value","name"), (String (XMLParser::*)(const String&) const) &XMLParser::get_attribute_value);
+ ClassDB::bind_method(_MD("get_named_attribute_value_safe","name"), &XMLParser::get_attribute_value_safe);
+ ClassDB::bind_method(_MD("is_empty"),&XMLParser::is_empty);
+ ClassDB::bind_method(_MD("get_current_line"),&XMLParser::get_current_line);
+ ClassDB::bind_method(_MD("skip_section"),&XMLParser::skip_section);
+ ClassDB::bind_method(_MD("seek","pos"),&XMLParser::seek);
+ ClassDB::bind_method(_MD("open","file"),&XMLParser::open);
+ ClassDB::bind_method(_MD("open_buffer","buffer"),&XMLParser::open_buffer);
BIND_CONSTANT( NODE_NONE );
BIND_CONSTANT( NODE_ELEMENT );
diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h
index e0ec3ec770..7f80751156 100644
--- a/core/io/xml_parser.h
+++ b/core/io/xml_parser.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -40,7 +40,7 @@
class XMLParser : public Reference {
- OBJ_TYPE( XMLParser, Reference );
+ GDCLASS( XMLParser, Reference );
public:
//! Enumeration of all supported source text file formats
enum SourceFormat {
diff --git a/core/io/zip.c b/core/io/zip.c
index 44c79195d9..27a3d3cdc1 100644
--- a/core/io/zip.c
+++ b/core/io/zip.c
@@ -855,7 +855,7 @@ extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* gl
ziinit.z_filefunc.zseek32_file = NULL;
ziinit.z_filefunc.ztell32_file = NULL;
if (pzlib_filefunc64_32_def==NULL) {
-// fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
+ //fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
} else
ziinit.z_filefunc = *pzlib_filefunc64_32_def;
diff --git a/core/io/zip_io.h b/core/io/zip_io.h
index 0668c47d97..c994593518 100644
--- a/core/io/zip_io.h
+++ b/core/io/zip_io.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/list.h b/core/list.h
index b989f009a9..c464af7475 100644
--- a/core/list.h
+++ b/core/list.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/make_binders.py b/core/make_binders.py
index 7584722965..74b5e9fda3 100644
--- a/core/make_binders.py
+++ b/core/make_binders.py
@@ -1,7 +1,7 @@
# -*- coding: ibm850 -*-
-template_typed="""
+template_typed = """
#ifdef TYPED_METHOD_BIND
template<class T $ifret ,class R$ $ifargs ,$ $arg, class P@$>
class MethodBind$argc$$ifret R$$ifconst C$ : public MethodBind {
@@ -17,8 +17,8 @@ public:
return Variant::NIL;
}
#endif
- virtual String get_instance_type() const {
- return T::get_type_static();
+ virtual String get_instance_class() const {
+ return T::get_class_static();
}
virtual Variant call(Object* p_object,const Variant** p_args,int p_arg_count, Variant::CallError& r_error) {
@@ -77,7 +77,7 @@ MethodBind* create_method_bind($ifret R$ $ifnoret void$ (T::*p_method)($arg, P@$
#endif
"""
-template="""
+template = """
#ifndef TYPED_METHOD_BIND
$iftempl template<$ $ifret class R$ $ifretargs ,$ $arg, class P@$ $iftempl >$
class MethodBind$argc$$ifret R$$ifconst C$ : public MethodBind {
@@ -97,7 +97,7 @@ public:
return Variant::NIL;
}
#endif
- virtual String get_instance_type() const {
+ virtual String get_instance_class() const {
return type_name;
}
@@ -159,103 +159,102 @@ MethodBind* create_method_bind($ifret R$ $ifnoret void$ (T::*p_method)($arg, P@$
} u;
u.sm=p_method;
a->method=u.dm;
- a->type_name=T::get_type_static();
+ a->type_name=T::get_class_static();
return a;
}
#endif
"""
-def make_version(template,nargs,argmax,const,ret):
-
- intext=template
- from_pos=0
- outtext=""
-
- while(True):
- to_pos=intext.find("$",from_pos)
- if (to_pos==-1):
- outtext+=intext[from_pos:]
- break
- else:
- outtext+=intext[from_pos:to_pos]
- end=intext.find("$",to_pos+1)
- if (end==-1):
- break # ignore
- macro=intext[to_pos+1:end]
- cmd=""
- data=""
-
- if (macro.find(" ")!=-1):
- cmd=macro[0:macro.find(" ")]
- data=macro[macro.find(" ")+1:]
- else:
- cmd=macro
-
- if (cmd=="argc"):
- outtext+=str(nargs)
- if (cmd=="ifret" and ret):
- outtext+=data
- if (cmd=="ifargs" and nargs):
- outtext+=data
- if (cmd=="ifretargs" and nargs and ret):
- outtext+=data
- if (cmd=="ifconst" and const):
- outtext+=data
- elif (cmd=="ifnoconst" and not const):
- outtext+=data
- elif (cmd=="ifnoret" and not ret):
- outtext+=data
- elif (cmd=="iftempl" and (nargs>0 or ret)):
- outtext+=data
- elif (cmd=="arg,"):
- for i in range(1,nargs+1):
- if (i>1):
- outtext+=", "
- outtext+=data.replace("@",str(i))
- elif (cmd=="arg"):
- for i in range(1,nargs+1):
- outtext+=data.replace("@",str(i))
- elif (cmd=="noarg"):
- for i in range(nargs+1,argmax+1):
- outtext+=data.replace("@",str(i))
- elif (cmd=="noarg"):
- for i in range(nargs+1,argmax+1):
- outtext+=data.replace("@",str(i))
-
- from_pos=end+1
-
- return outtext
+def make_version(template, nargs, argmax, const, ret):
+
+ intext = template
+ from_pos = 0
+ outtext = ""
+
+ while(True):
+ to_pos = intext.find("$", from_pos)
+ if (to_pos == -1):
+ outtext += intext[from_pos:]
+ break
+ else:
+ outtext += intext[from_pos:to_pos]
+ end = intext.find("$", to_pos + 1)
+ if (end == -1):
+ break # ignore
+ macro = intext[to_pos + 1:end]
+ cmd = ""
+ data = ""
+
+ if (macro.find(" ") != -1):
+ cmd = macro[0:macro.find(" ")]
+ data = macro[macro.find(" ") + 1:]
+ else:
+ cmd = macro
+
+ if (cmd == "argc"):
+ outtext += str(nargs)
+ if (cmd == "ifret" and ret):
+ outtext += data
+ if (cmd == "ifargs" and nargs):
+ outtext += data
+ if (cmd == "ifretargs" and nargs and ret):
+ outtext += data
+ if (cmd == "ifconst" and const):
+ outtext += data
+ elif (cmd == "ifnoconst" and not const):
+ outtext += data
+ elif (cmd == "ifnoret" and not ret):
+ outtext += data
+ elif (cmd == "iftempl" and (nargs > 0 or ret)):
+ outtext += data
+ elif (cmd == "arg,"):
+ for i in range(1, nargs + 1):
+ if (i > 1):
+ outtext += ", "
+ outtext += data.replace("@", str(i))
+ elif (cmd == "arg"):
+ for i in range(1, nargs + 1):
+ outtext += data.replace("@", str(i))
+ elif (cmd == "noarg"):
+ for i in range(nargs + 1, argmax + 1):
+ outtext += data.replace("@", str(i))
+ elif (cmd == "noarg"):
+ for i in range(nargs + 1, argmax + 1):
+ outtext += data.replace("@", str(i))
+
+ from_pos = end + 1
+
+ return outtext
def run(target, source, env):
- versions=10
- versions_ext=6
- text=""
- text_ext=""
-
- for i in range(0,versions+1):
-
- t=""
- t+=make_version(template,i,versions,False,False)
- t+=make_version(template_typed,i,versions,False,False)
- t+=make_version(template,i,versions,False,True)
- t+=make_version(template_typed,i,versions,False,True)
- t+=make_version(template,i,versions,True,False)
- t+=make_version(template_typed,i,versions,True,False)
- t+=make_version(template,i,versions,True,True)
- t+=make_version(template_typed,i,versions,True,True)
- if (i>=versions_ext):
- text_ext+=t
- else:
- text+=t
-
-
- f=open(target[0].path,"w")
- f.write(text)
- f.close()
-
- f=open(target[1].path,"w")
- f.write(text_ext)
- f.close()
+ versions = 10
+ versions_ext = 6
+ text = ""
+ text_ext = ""
+
+ for i in range(0, versions + 1):
+
+ t = ""
+ t += make_version(template, i, versions, False, False)
+ t += make_version(template_typed, i, versions, False, False)
+ t += make_version(template, i, versions, False, True)
+ t += make_version(template_typed, i, versions, False, True)
+ t += make_version(template, i, versions, True, False)
+ t += make_version(template_typed, i, versions, True, False)
+ t += make_version(template, i, versions, True, True)
+ t += make_version(template_typed, i, versions, True, True)
+ if (i >= versions_ext):
+ text_ext += t
+ else:
+ text += t
+
+ f = open(target[0].path, "w")
+ f.write(text)
+ f.close()
+
+ f = open(target[1].path, "w")
+ f.write(text_ext)
+ f.close()
diff --git a/core/map.h b/core/map.h
index 81cda1ece2..9448389169 100644
--- a/core/map.h
+++ b/core/map.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -149,7 +149,7 @@ private:
#ifdef GLOBALNIL_DISABLED
memdelete_allocator<Element,A>(_nil);
#endif
-// memdelete_allocator<Element,A>(_root);
+ //memdelete_allocator<Element,A>(_root);
}
};
diff --git a/core/math/SCsub b/core/math/SCsub
index 7b4a6acbc0..4efc902717 100644
--- a/core/math/SCsub
+++ b/core/math/SCsub
@@ -1,5 +1,7 @@
+#!/usr/bin/env python
+
Import('env')
-env.add_source_files(env.core_sources,"*.cpp")
+env.add_source_files(env.core_sources, "*.cpp")
Export('env')
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 5bbbbdaa5a..0d6997183f 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -1,3 +1,31 @@
+/*************************************************************************/
+/* a_star.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
#include "a_star.h"
#include "geometry.h"
@@ -267,10 +295,10 @@ bool AStar::_solve(Point* begin_point, Point* end_point) {
}
-DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
+PoolVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
- ERR_FAIL_COND_V(!points.has(p_from_id),DVector<Vector3>());
- ERR_FAIL_COND_V(!points.has(p_to_id),DVector<Vector3>());
+ ERR_FAIL_COND_V(!points.has(p_from_id),PoolVector<Vector3>());
+ ERR_FAIL_COND_V(!points.has(p_to_id),PoolVector<Vector3>());
pass++;
@@ -279,7 +307,7 @@ DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
Point* b = points[p_to_id];
if (a==b) {
- DVector<Vector3> ret;
+ PoolVector<Vector3> ret;
ret.push_back(a->pos);
return ret;
}
@@ -291,7 +319,7 @@ DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
bool found_route=_solve(begin_point,end_point);
if (!found_route)
- return DVector<Vector3>();
+ return PoolVector<Vector3>();
//midpoints
Point *p=end_point;
@@ -301,11 +329,11 @@ DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
p=p->prev_point;
}
- DVector<Vector3> path;
+ PoolVector<Vector3> path;
path.resize(pc);
{
- DVector<Vector3>::Write w = path.write();
+ PoolVector<Vector3>::Write w = path.write();
Point *p=end_point;
int idx=pc-1;
@@ -323,10 +351,10 @@ DVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
}
-DVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
+PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
- ERR_FAIL_COND_V(!points.has(p_from_id),DVector<int>());
- ERR_FAIL_COND_V(!points.has(p_to_id),DVector<int>());
+ ERR_FAIL_COND_V(!points.has(p_from_id),PoolVector<int>());
+ ERR_FAIL_COND_V(!points.has(p_to_id),PoolVector<int>());
pass++;
@@ -335,7 +363,7 @@ DVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
Point* b = points[p_to_id];
if (a==b) {
- DVector<int> ret;
+ PoolVector<int> ret;
ret.push_back(a->id);
return ret;
}
@@ -347,7 +375,7 @@ DVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
bool found_route=_solve(begin_point,end_point);
if (!found_route)
- return DVector<int>();
+ return PoolVector<int>();
//midpoints
Point *p=end_point;
@@ -357,11 +385,11 @@ DVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
p=p->prev_point;
}
- DVector<int> path;
+ PoolVector<int> path;
path.resize(pc);
{
- DVector<int>::Write w = path.write();
+ PoolVector<int>::Write w = path.write();
p=end_point;
int idx=pc-1;
@@ -379,23 +407,23 @@ DVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
void AStar::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("get_available_point_id"),&AStar::get_available_point_id);
- ObjectTypeDB::bind_method(_MD("add_point","id","pos","weight_scale"),&AStar::add_point,DEFVAL(1.0));
- ObjectTypeDB::bind_method(_MD("get_point_pos","id"),&AStar::get_point_pos);
- ObjectTypeDB::bind_method(_MD("get_point_weight_scale","id"),&AStar::get_point_weight_scale);
- ObjectTypeDB::bind_method(_MD("remove_point","id"),&AStar::remove_point);
+ ClassDB::bind_method(_MD("get_available_point_id"),&AStar::get_available_point_id);
+ ClassDB::bind_method(_MD("add_point","id","pos","weight_scale"),&AStar::add_point,DEFVAL(1.0));
+ ClassDB::bind_method(_MD("get_point_pos","id"),&AStar::get_point_pos);
+ ClassDB::bind_method(_MD("get_point_weight_scale","id"),&AStar::get_point_weight_scale);
+ ClassDB::bind_method(_MD("remove_point","id"),&AStar::remove_point);
- ObjectTypeDB::bind_method(_MD("connect_points","id","to_id"),&AStar::connect_points);
- ObjectTypeDB::bind_method(_MD("disconnect_points","id","to_id"),&AStar::disconnect_points);
- ObjectTypeDB::bind_method(_MD("are_points_connected","id","to_id"),&AStar::are_points_connected);
+ ClassDB::bind_method(_MD("connect_points","id","to_id"),&AStar::connect_points);
+ ClassDB::bind_method(_MD("disconnect_points","id","to_id"),&AStar::disconnect_points);
+ ClassDB::bind_method(_MD("are_points_connected","id","to_id"),&AStar::are_points_connected);
- ObjectTypeDB::bind_method(_MD("clear"),&AStar::clear);
+ ClassDB::bind_method(_MD("clear"),&AStar::clear);
- ObjectTypeDB::bind_method(_MD("get_closest_point","to_pos"),&AStar::get_closest_point);
- ObjectTypeDB::bind_method(_MD("get_closest_pos_in_segment","to_pos"),&AStar::get_closest_pos_in_segment);
+ ClassDB::bind_method(_MD("get_closest_point","to_pos"),&AStar::get_closest_point);
+ ClassDB::bind_method(_MD("get_closest_pos_in_segment","to_pos"),&AStar::get_closest_pos_in_segment);
- ObjectTypeDB::bind_method(_MD("get_point_path","from_id","to_id"),&AStar::get_point_path);
- ObjectTypeDB::bind_method(_MD("get_id_path","from_id","to_id"),&AStar::get_id_path);
+ ClassDB::bind_method(_MD("get_point_path","from_id","to_id"),&AStar::get_point_path);
+ ClassDB::bind_method(_MD("get_id_path","from_id","to_id"),&AStar::get_id_path);
}
diff --git a/core/math/a_star.h b/core/math/a_star.h
index a0517b5941..35e6ead226 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -1,12 +1,43 @@
+/*************************************************************************/
+/* a_star.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
#ifndef ASTAR_H
#define ASTAR_H
#include "reference.h"
#include "self_list.h"
+/**
+ @author Juan Linietsky <reduzio@gmail.com>
+*/
class AStar: public Reference {
- OBJ_TYPE(AStar,Reference)
+ GDCLASS(AStar,Reference)
uint64_t pass;
@@ -82,8 +113,8 @@ public:
int get_closest_point(const Vector3& p_point) const;
Vector3 get_closest_pos_in_segment(const Vector3& p_point) const;
- DVector<Vector3> get_point_path(int p_from_id, int p_to_id);
- DVector<int> get_id_path(int p_from_id, int p_to_id);
+ PoolVector<Vector3> get_point_path(int p_from_id, int p_to_id);
+ PoolVector<int> get_id_path(int p_from_id, int p_to_id);
AStar();
~AStar();
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp
index 6d8a5a72f0..3518eea7ac 100644
--- a/core/math/aabb.cpp
+++ b/core/math/aabb.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,24 +30,24 @@
#include "print_string.h"
-float AABB::get_area() const {
+float Rect3::get_area() const {
return size.x*size.y*size.z;
}
-bool AABB::operator==(const AABB& p_rval) const {
+bool Rect3::operator==(const Rect3& p_rval) const {
return ((pos==p_rval.pos) && (size==p_rval.size));
}
-bool AABB::operator!=(const AABB& p_rval) const {
+bool Rect3::operator!=(const Rect3& p_rval) const {
return ((pos!=p_rval.pos) || (size!=p_rval.size));
}
-void AABB::merge_with(const AABB& p_aabb) {
+void Rect3::merge_with(const Rect3& p_aabb) {
Vector3 beg_1,beg_2;
Vector3 end_1,end_2;
@@ -70,7 +70,7 @@ void AABB::merge_with(const AABB& p_aabb) {
size=max-min;
}
-AABB AABB::intersection(const AABB& p_aabb) const {
+Rect3 Rect3::intersection(const Rect3& p_aabb) const {
Vector3 src_min=pos;
Vector3 src_max=pos+size;
@@ -80,7 +80,7 @@ AABB AABB::intersection(const AABB& p_aabb) const {
Vector3 min,max;
if (src_min.x > dst_max.x || src_max.x < dst_min.x )
- return AABB();
+ return Rect3();
else {
min.x= ( src_min.x > dst_min.x ) ? src_min.x :dst_min.x;
@@ -89,7 +89,7 @@ AABB AABB::intersection(const AABB& p_aabb) const {
}
if (src_min.y > dst_max.y || src_max.y < dst_min.y )
- return AABB();
+ return Rect3();
else {
min.y= ( src_min.y > dst_min.y ) ? src_min.y :dst_min.y;
@@ -98,7 +98,7 @@ AABB AABB::intersection(const AABB& p_aabb) const {
}
if (src_min.z > dst_max.z || src_max.z < dst_min.z )
- return AABB();
+ return Rect3();
else {
min.z= ( src_min.z > dst_min.z ) ? src_min.z :dst_min.z;
@@ -107,10 +107,10 @@ AABB AABB::intersection(const AABB& p_aabb) const {
}
- return AABB( min, max-min );
+ return Rect3( min, max-min );
}
-bool AABB::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip,Vector3* r_normal) const {
+bool Rect3::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip,Vector3* r_normal) const {
Vector3 c1, c2;
Vector3 end = pos+size;
@@ -155,7 +155,7 @@ bool AABB::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r
}
-bool AABB::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip,Vector3* r_normal) const {
+bool Rect3::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip,Vector3* r_normal) const {
real_t min=0,max=1;
int axis=0;
@@ -216,7 +216,7 @@ bool AABB::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3
}
-bool AABB::intersects_plane(const Plane &p_plane) const {
+bool Rect3::intersects_plane(const Plane &p_plane) const {
Vector3 points[8] = {
Vector3( pos.x , pos.y , pos.z ),
@@ -246,7 +246,7 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
-Vector3 AABB::get_longest_axis() const {
+Vector3 Rect3::get_longest_axis() const {
Vector3 axis(1,0,0);
real_t max_size=size.x;
@@ -263,7 +263,7 @@ Vector3 AABB::get_longest_axis() const {
return axis;
}
-int AABB::get_longest_axis_index() const {
+int Rect3::get_longest_axis_index() const {
int axis=0;
real_t max_size=size.x;
@@ -282,7 +282,7 @@ int AABB::get_longest_axis_index() const {
}
-Vector3 AABB::get_shortest_axis() const {
+Vector3 Rect3::get_shortest_axis() const {
Vector3 axis(1,0,0);
real_t max_size=size.x;
@@ -299,7 +299,7 @@ Vector3 AABB::get_shortest_axis() const {
return axis;
}
-int AABB::get_shortest_axis_index() const {
+int Rect3::get_shortest_axis_index() const {
int axis=0;
real_t max_size=size.x;
@@ -317,26 +317,26 @@ int AABB::get_shortest_axis_index() const {
return axis;
}
-AABB AABB::merge(const AABB& p_with) const {
+Rect3 Rect3::merge(const Rect3& p_with) const {
- AABB aabb=*this;
+ Rect3 aabb=*this;
aabb.merge_with(p_with);
return aabb;
}
-AABB AABB::expand(const Vector3& p_vector) const {
- AABB aabb=*this;
+Rect3 Rect3::expand(const Vector3& p_vector) const {
+ Rect3 aabb=*this;
aabb.expand_to(p_vector);
return aabb;
}
-AABB AABB::grow(real_t p_by) const {
+Rect3 Rect3::grow(real_t p_by) const {
- AABB aabb=*this;
+ Rect3 aabb=*this;
aabb.grow_by(p_by);
return aabb;
}
-void AABB::get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const {
+void Rect3::get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const {
ERR_FAIL_INDEX(p_edge,12);
switch(p_edge) {
@@ -412,7 +412,7 @@ void AABB::get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const {
}
-AABB::operator String() const {
+Rect3::operator String() const {
return String()+pos +" - "+ size;
}
diff --git a/core/math/aabb.h b/core/math/aabb.h
index 57fe1b32f5..2816d1f012 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -40,7 +40,7 @@
-class AABB {
+class Rect3 {
public:
Vector3 pos;
Vector3 size;
@@ -62,16 +62,16 @@ public:
void set_size(const Vector3& p_size) { size=p_size; }
- bool operator==(const AABB& p_rval) const;
- bool operator!=(const AABB& p_rval) const;
+ bool operator==(const Rect3& p_rval) const;
+ bool operator!=(const Rect3& p_rval) const;
- _FORCE_INLINE_ bool intersects(const AABB& p_aabb) const; /// Both AABBs overlap
- _FORCE_INLINE_ bool intersects_inclusive(const AABB& p_aabb) const; /// Both AABBs (or their faces) overlap
- _FORCE_INLINE_ bool encloses(const AABB & p_aabb) const; /// p_aabb is completely inside this
+ _FORCE_INLINE_ bool intersects(const Rect3& p_aabb) const; /// Both AABBs overlap
+ _FORCE_INLINE_ bool intersects_inclusive(const Rect3& p_aabb) const; /// Both AABBs (or their faces) overlap
+ _FORCE_INLINE_ bool encloses(const Rect3 & p_aabb) const; /// p_aabb is completely inside this
- AABB merge(const AABB& p_with) const;
- void merge_with(const AABB& p_aabb); ///merge with another AABB
- AABB intersection(const AABB& p_aabb) const; ///get box where two intersect, empty if no intersection occurs
+ Rect3 merge(const Rect3& p_with) const;
+ void merge_with(const Rect3& p_aabb); ///merge with another AABB
+ 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;
@@ -91,25 +91,25 @@ public:
int get_shortest_axis_index() const;
_FORCE_INLINE_ real_t get_shortest_axis_size() const;
- AABB grow(real_t p_by) const;
+ Rect3 grow(real_t p_by) const;
_FORCE_INLINE_ void grow_by(real_t p_amount);
void get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const;
_FORCE_INLINE_ Vector3 get_endpoint(int p_point) const;
- AABB expand(const Vector3& p_vector) 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 expand_to(const Vector3& p_vector); /** expand to contain a point if necesary */
operator String() const;
- _FORCE_INLINE_ AABB() {}
- inline AABB(const Vector3 &p_pos,const Vector3& p_size) { pos=p_pos; size=p_size; }
+ _FORCE_INLINE_ Rect3() {}
+ inline Rect3(const Vector3 &p_pos,const Vector3& p_size) { pos=p_pos; size=p_size; }
};
-inline bool AABB::intersects(const AABB& p_aabb) const {
+inline bool Rect3::intersects(const Rect3& p_aabb) const {
if ( pos.x >= (p_aabb.pos.x + p_aabb.size.x) )
return false;
@@ -127,7 +127,7 @@ inline bool AABB::intersects(const AABB& p_aabb) const {
return true;
}
-inline bool AABB::intersects_inclusive(const AABB& p_aabb) const {
+inline bool Rect3::intersects_inclusive(const Rect3& p_aabb) const {
if ( pos.x > (p_aabb.pos.x + p_aabb.size.x) )
return false;
@@ -145,7 +145,7 @@ inline bool AABB::intersects_inclusive(const AABB& p_aabb) const {
return true;
}
-inline bool AABB::encloses(const AABB & p_aabb) const {
+inline bool Rect3::encloses(const Rect3 & p_aabb) const {
Vector3 src_min=pos;
Vector3 src_max=pos+size;
@@ -162,7 +162,7 @@ inline bool AABB::encloses(const AABB & p_aabb) const {
}
-Vector3 AABB::get_support(const Vector3& p_normal) const {
+Vector3 Rect3::get_support(const Vector3& p_normal) const {
Vector3 half_extents = size * 0.5;
Vector3 ofs = pos + half_extents;
@@ -175,7 +175,7 @@ Vector3 AABB::get_support(const Vector3& p_normal) const {
}
-Vector3 AABB::get_endpoint(int p_point) const {
+Vector3 Rect3::get_endpoint(int p_point) const {
switch(p_point) {
case 0: return Vector3( pos.x , pos.y , pos.z );
@@ -191,7 +191,7 @@ Vector3 AABB::get_endpoint(int p_point) const {
ERR_FAIL_V(Vector3());
}
-bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const {
+bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const {
#if 1
@@ -251,7 +251,7 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) con
#endif
}
-bool AABB::has_point(const Vector3& p_point) const {
+bool Rect3::has_point(const Vector3& p_point) const {
if (p_point.x<pos.x)
return false;
@@ -270,7 +270,7 @@ bool AABB::has_point(const Vector3& p_point) const {
}
-inline void AABB::expand_to(const Vector3& p_vector) {
+inline void Rect3::expand_to(const Vector3& p_vector) {
Vector3 begin=pos;
Vector3 end=pos+size;
@@ -293,7 +293,7 @@ inline void AABB::expand_to(const Vector3& p_vector) {
size=end-begin;
}
-void AABB::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,float &r_min,float& 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 );
@@ -304,7 +304,7 @@ void AABB::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max
r_max = distance + length;
}
-inline real_t AABB::get_longest_axis_size() const {
+inline real_t Rect3::get_longest_axis_size() const {
real_t max_size=size.x;
@@ -319,7 +319,7 @@ inline real_t AABB::get_longest_axis_size() const {
return max_size;
}
-inline real_t AABB::get_shortest_axis_size() const {
+inline real_t Rect3::get_shortest_axis_size() const {
real_t max_size=size.x;
@@ -334,7 +334,7 @@ inline real_t AABB::get_shortest_axis_size() const {
return max_size;
}
-bool AABB::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, float t0, float t1) const {
float divx=1.0/dir.x;
float divy=1.0/dir.y;
@@ -381,7 +381,7 @@ bool AABB::smits_intersect_ray(const Vector3 &from,const Vector3& dir, float t0,
return ( (tmin < t1) && (tmax > t0) );
}
-void AABB::grow_by(real_t p_amount) {
+void Rect3::grow_by(real_t p_amount) {
pos.x-=p_amount;
pos.y-=p_amount;
@@ -391,6 +391,5 @@ void AABB::grow_by(real_t p_amount) {
size.z+=2.0*p_amount;
}
-typedef AABB Rect3;
#endif // AABB_H
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index d16495217c..e2526f5134 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,7 +31,7 @@
#include "print_string.h"
-void BSP_Tree::from_aabb(const AABB& p_aabb) {
+void BSP_Tree::from_aabb(const Rect3& p_aabb) {
planes.clear();
@@ -67,7 +67,7 @@ Vector<Plane> BSP_Tree::get_planes() const {
return planes;
}
-AABB BSP_Tree::get_aabb() const {
+Rect3 BSP_Tree::get_aabb() const {
return aabb;
}
@@ -390,8 +390,10 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
const Face3& f=p_faces[ indices[i] ];
- //if (f.get_plane().is_almost_like(divisor_plane))
- // continue;
+ /*
+ if (f.get_plane().is_almost_like(divisor_plane))
+ continue;
+ */
int over_count=0;
int under_count=0;
@@ -484,7 +486,7 @@ BSP_Tree::operator Variant() const {
d["planes"]=plane_values;
- DVector<int> dst_nodes;
+ PoolVector<int> dst_nodes;
dst_nodes.resize(nodes.size()*3);
for(int i=0;i<nodes.size();i++) {
@@ -514,19 +516,19 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
ERR_FAIL_COND(!d.has("aabb"));
ERR_FAIL_COND(!d.has("error_radius"));
- DVector<int> src_nodes = d["nodes"];
+ PoolVector<int> src_nodes = d["nodes"];
ERR_FAIL_COND(src_nodes.size()%3);
- if (d["planes"].get_type()==Variant::REAL_ARRAY) {
+ if (d["planes"].get_type()==Variant::POOL_REAL_ARRAY) {
- DVector<float> src_planes=d["planes"];
+ PoolVector<float> src_planes=d["planes"];
int plane_count=src_planes.size();
ERR_FAIL_COND(plane_count%4);
planes.resize(plane_count/4);
if (plane_count) {
- DVector<float>::Read r = src_planes.read();
+ PoolVector<float>::Read r = src_planes.read();
for(int i=0;i<plane_count/4;i++) {
planes[i].normal.x=r[i*4+0];
@@ -546,10 +548,10 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
error_radius = d["error"];
aabb = d["aabb"];
-// int node_count = src_nodes.size();
+ //int node_count = src_nodes.size();
nodes.resize(src_nodes.size()/3);
- DVector<int>::Read r = src_nodes.read();
+ PoolVector<int>::Read r = src_nodes.read();
for(int i=0;i<nodes.size();i++) {
@@ -560,12 +562,12 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
}
-BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) {
+BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) {
// compute aabb
int face_count=p_faces.size();
- DVector<Face3>::Read faces_r=p_faces.read();
+ PoolVector<Face3>::Read faces_r=p_faces.read();
const Face3 *facesptr = faces_r.ptr();
@@ -613,7 +615,7 @@ BSP_Tree::BSP_Tree(const DVector<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 AABB& p_aabb,float 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) {
nodes=p_nodes;
planes=p_planes;
diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h
index 6c36d80e3e..e01df96555 100644
--- a/core/math/bsp_tree.h
+++ b/core/math/bsp_tree.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -65,7 +65,7 @@ private:
Vector<Node> nodes;
Vector<Plane> planes;
- AABB aabb;
+ Rect3 aabb;
float 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;
@@ -78,7 +78,7 @@ public:
bool is_empty() const { return nodes.size()==0; }
Vector<Node> get_nodes() const;
Vector<Plane> get_planes() const;
- AABB get_aabb() const;
+ Rect3 get_aabb() const;
bool point_is_inside(const Vector3& p_point) const;
int get_points_inside(const Vector3* p_points, int p_point_count) const;
@@ -87,12 +87,12 @@ public:
operator Variant() const;
- void from_aabb(const AABB& p_aabb);
+ void from_aabb(const Rect3& p_aabb);
BSP_Tree();
BSP_Tree(const Variant& p_variant);
- BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius=0);
- BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB& p_aabb,float p_error_radius=0);
+ 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();
};
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index f7dd8839b8..c44ff4682a 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -54,7 +54,7 @@ void CameraMatrix::set_zero() {
}
-Plane CameraMatrix::xform4(const Plane& p_vec4) {
+Plane CameraMatrix::xform4(const Plane& p_vec4) const {
Plane ret;
@@ -495,6 +495,28 @@ void CameraMatrix::set_light_bias() {
}
+void CameraMatrix::set_light_atlas_rect(const Rect2& p_rect) {
+
+ float *m=&matrix[0][0];
+
+ m[0]=p_rect.size.width,
+ m[1]=0.0,
+ m[2]=0.0,
+ m[3]=0.0,
+ m[4]=0.0,
+ m[5]=p_rect.size.height,
+ m[6]=0.0,
+ m[7]=0.0,
+ m[8]=0.0,
+ m[9]=0.0,
+ m[10]=1.0,
+ m[11]=0.0,
+ m[12]=p_rect.pos.x,
+ m[13]=p_rect.pos.y,
+ m[14]=0.0,
+ m[15]=1.0;
+}
+
CameraMatrix::operator String() const {
String str;
@@ -512,6 +534,15 @@ float CameraMatrix::get_aspect() const {
return w/h;
}
+int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const {
+
+
+ Vector3 result = xform(Vector3(1,0,-1));
+
+ return int((result.x * 0.5 + 0.5) * p_for_pixel_width);
+
+}
+
float CameraMatrix::get_fov() const {
const float * matrix = (const float*)this->matrix;
@@ -533,7 +564,7 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) {
}
-void CameraMatrix::scale_translate_to_fit(const AABB& p_aabb) {
+void CameraMatrix::scale_translate_to_fit(const Rect3& p_aabb) {
Vector3 min = p_aabb.pos;
Vector3 max = p_aabb.pos+p_aabb.size;
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index d192b1fef1..952f1e8fb2 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,6 +30,7 @@
#define CAMERA_MATRIX_H
#include "transform.h"
+#include "math_2d.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -53,6 +54,7 @@ struct CameraMatrix {
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);
@@ -78,13 +80,14 @@ struct CameraMatrix {
CameraMatrix operator*(const CameraMatrix& p_matrix) const;
- Plane xform4(const Plane& p_vec4);
+ Plane xform4(const Plane& p_vec4) const;
_FORCE_INLINE_ Vector3 xform(const Vector3& p_vec3) const;
operator String() const;
- void scale_translate_to_fit(const AABB& p_aabb);
+ void scale_translate_to_fit(const Rect3& p_aabb);
void make_scale(const Vector3 &p_scale);
+ int get_pixels_per_meter(int p_for_pixel_width) const;
operator Transform() const;
CameraMatrix();
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index e1af91f28e..faf124593e 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -205,7 +205,7 @@ ClockDirection Face3::get_clock_dir() const {
}
-bool Face3::intersects_aabb(const AABB& p_aabb) const {
+bool Face3::intersects_aabb(const Rect3& p_aabb) const {
/** TEST PLANE **/
if (!p_aabb.intersects_plane( get_plane() ))
diff --git a/core/math/face3.h b/core/math/face3.h
index 3a81da74db..f08eb227b1 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -78,16 +78,16 @@ public:
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;
- AABB get_aabb() const {
+ Rect3 get_aabb() const {
- AABB aabb( vertex[0], Vector3() );
+ Rect3 aabb( vertex[0], Vector3() );
aabb.expand_to( vertex[1] );
aabb.expand_to( vertex[2] );
return aabb;
}
- bool intersects_aabb(const AABB& p_aabb) const;
- _FORCE_INLINE_ bool intersects_aabb2(const AABB& p_aabb) const;
+ bool intersects_aabb(const Rect3& p_aabb) const;
+ _FORCE_INLINE_ bool intersects_aabb2(const Rect3& p_aabb) const;
operator String() const;
inline Face3() {}
@@ -96,7 +96,7 @@ public:
};
-bool Face3::intersects_aabb2(const AABB& p_aabb) const {
+bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
Vector3 perp = (vertex[0]-vertex[2]).cross(vertex[0]-vertex[1]);
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index 790903eff5..bf3364a052 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -204,21 +204,21 @@ static bool _group_face(_FaceClassify *p_faces, int len, int p_index,int p_group
}
-DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array ) {
+PoolVector< PoolVector< Face3 > > Geometry::separate_objects( PoolVector< Face3 > p_array ) {
- DVector< DVector< Face3 > > objects;
+ PoolVector< PoolVector< Face3 > > objects;
int len = p_array.size();
- DVector<Face3>::Read r=p_array.read();
+ PoolVector<Face3>::Read r=p_array.read();
const Face3* arrayptr = r.ptr();
- DVector< _FaceClassify> fc;
+ PoolVector< _FaceClassify> fc;
fc.resize( len );
- DVector< _FaceClassify >::Write fcw=fc.write();
+ PoolVector< _FaceClassify >::Write fcw=fc.write();
_FaceClassify * _fcptr = fcw.ptr();
@@ -231,7 +231,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array
if (error) {
- ERR_FAIL_COND_V(error, DVector< DVector< Face3 > >() ); // invalid geometry
+ ERR_FAIL_COND_V(error, PoolVector< PoolVector< Face3 > >() ); // invalid geometry
}
/* group connected faces in separate objects */
@@ -257,8 +257,8 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array
if (group>=0) {
objects.resize(group);
- DVector< DVector<Face3> >::Write obw=objects.write();
- DVector< Face3 > *group_faces = obw.ptr();
+ PoolVector< PoolVector<Face3> >::Write obw=objects.write();
+ PoolVector< Face3 > *group_faces = obw.ptr();
for (int i=0;i<len;i++) {
if (!_fcptr[i].valid)
@@ -304,7 +304,7 @@ enum _CellFlags {
static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,const Vector3& voxelsize,const Face3& p_face) {
- AABB aabb( Vector3(x,y,z),Vector3(len_x,len_y,len_z));
+ Rect3 aabb( Vector3(x,y,z),Vector3(len_x,len_y,len_z));
aabb.pos=aabb.pos*voxelsize;
aabb.size=aabb.size*voxelsize;
@@ -487,7 +487,7 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int
}
}
-static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,DVector<Face3>& p_faces) {
+static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,PoolVector<Face3>& p_faces) {
ERR_FAIL_INDEX(x,len_x);
ERR_FAIL_INDEX(y,len_y);
@@ -580,16 +580,16 @@ static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int l
}
-DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_error ) {
+PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,float *p_error ) {
#define _MIN_SIZE 1.0
#define _MAX_LENGTH 20
int face_count=p_array.size();
- DVector<Face3>::Read facesr=p_array.read();
+ PoolVector<Face3>::Read facesr=p_array.read();
const Face3 *faces = facesr.ptr();
- AABB global_aabb;
+ Rect3 global_aabb;
for(int i=0;i<face_count;i++) {
@@ -696,7 +696,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
//print_line("Wrapper (3/6): Building Faces");
- DVector<Face3> wrapped_faces;
+ PoolVector<Face3> wrapped_faces;
for (int i=0;i<div_x;i++) {
@@ -714,7 +714,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
// transform face vertices to global coords
int wrapped_faces_count=wrapped_faces.size();
- DVector<Face3>::Write wrapped_facesw=wrapped_faces.write();
+ PoolVector<Face3>::Write wrapped_facesw=wrapped_faces.write();
Face3* wrapped_faces_ptr=wrapped_facesw.ptr();
for(int i=0;i<wrapped_faces_count;i++) {
@@ -748,7 +748,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
return wrapped_faces;
}
-Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
+Geometry::MeshData Geometry::build_convex_mesh(const PoolVector<Plane> &p_planes) {
MeshData mesh;
@@ -896,9 +896,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
}
-DVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) {
+PoolVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) {
- DVector<Plane> planes;
+ PoolVector<Plane> planes;
planes.push_back( Plane( Vector3(1,0,0), p_extents.x ) );
planes.push_back( Plane( Vector3(-1,0,0), p_extents.x ) );
@@ -910,9 +910,9 @@ DVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) {
return planes;
}
-DVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
+PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
- DVector<Plane> planes;
+ PoolVector<Plane> planes;
for (int i=0;i<p_sides;i++) {
@@ -933,10 +933,10 @@ DVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, i
}
-DVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) {
+PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) {
- DVector<Plane> planes;
+ PoolVector<Plane> planes;
Vector3 axis;
axis[p_axis]=1.0;
@@ -969,9 +969,9 @@ DVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lo
}
-DVector<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(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
- DVector<Plane> planes;
+ PoolVector<Plane> planes;
Vector3 axis;
axis[p_axis]=1.0;
diff --git a/core/math/geometry.h b/core/math/geometry.h
index b353423851..d5b3a3068c 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -750,9 +750,7 @@ public:
return Vector<Vector3>(); //empty
}
-// long count = 0;
long previous = polygon.size() - 1;
-
Vector<Vector3> clipped;
for (int index = 0; index < polygon.size(); index++) {
@@ -808,9 +806,9 @@ public:
}
- static DVector< DVector< Face3 > > separate_objects( DVector< Face3 > p_array );
+ static PoolVector< PoolVector< Face3 > > separate_objects( PoolVector< Face3 > p_array );
- static DVector< Face3 > wrap_geometry( DVector< Face3 > p_array, float *p_error=NULL ); ///< create a "wrap" that encloses the given geometry
+ static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, float *p_error=NULL ); ///< create a "wrap" that encloses the given geometry
struct MeshData {
@@ -919,11 +917,11 @@ public:
return H;
}
- static MeshData build_convex_mesh(const DVector<Plane> &p_planes);
- static DVector<Plane> build_sphere_planes(float p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z);
- static DVector<Plane> build_box_planes(const Vector3& p_extents);
- static DVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
- static DVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
+ 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_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 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 2cc11aa738..c6860ba2e8 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,22 +31,22 @@
real_t Vector2::angle() const {
- return Math::atan2(x,y);
+ return Math::atan2(y,x);
}
-float Vector2::length() const {
+real_t Vector2::length() const {
return Math::sqrt( x*x + y*y );
}
-float Vector2::length_squared() const {
+real_t Vector2::length_squared() const {
return x*x + y*y;
}
void Vector2::normalize() {
- float l = x*x + y*y;
+ real_t l = x*x + y*y;
if (l!=0) {
l=Math::sqrt(l);
@@ -62,32 +62,32 @@ Vector2 Vector2::normalized() const {
return v;
}
-float Vector2::distance_to(const Vector2& p_vector2) const {
+real_t Vector2::distance_to(const Vector2& p_vector2) const {
return Math::sqrt( (x-p_vector2.x)*(x-p_vector2.x) + (y-p_vector2.y)*(y-p_vector2.y));
}
-float Vector2::distance_squared_to(const Vector2& p_vector2) const {
+real_t Vector2::distance_squared_to(const Vector2& p_vector2) const {
return (x-p_vector2.x)*(x-p_vector2.x) + (y-p_vector2.y)*(y-p_vector2.y);
}
-float Vector2::angle_to(const Vector2& p_vector2) const {
+real_t Vector2::angle_to(const Vector2& p_vector2) const {
- return Math::atan2( tangent().dot(p_vector2), dot(p_vector2) );
+ return Math::atan2( cross(p_vector2), dot(p_vector2) );
}
-float Vector2::angle_to_point(const Vector2& p_vector2) const {
+real_t Vector2::angle_to_point(const Vector2& p_vector2) const {
- return Math::atan2( x-p_vector2.x, y - p_vector2.y );
+ return Math::atan2( y - p_vector2.y, x-p_vector2.x );
}
-float Vector2::dot(const Vector2& p_other) const {
+real_t Vector2::dot(const Vector2& p_other) const {
return x*p_other.x + y*p_other.y;
}
-float Vector2::cross(const Vector2& p_other) const {
+real_t Vector2::cross(const Vector2& p_other) const {
return x*p_other.y - y*p_other.x;
}
@@ -120,11 +120,11 @@ Vector2 Vector2::operator*(const Vector2 &p_v1) const {
return Vector2(x * p_v1.x, y * p_v1.y);
};
-Vector2 Vector2::operator*(const float &rvalue) const {
+Vector2 Vector2::operator*(const real_t &rvalue) const {
return Vector2(x * rvalue, y * rvalue);
};
-void Vector2::operator*=(const float &rvalue) {
+void Vector2::operator*=(const real_t &rvalue) {
x *= rvalue; y *= rvalue;
};
@@ -134,12 +134,12 @@ Vector2 Vector2::operator/(const Vector2 &p_v1) const {
return Vector2(x / p_v1.x, y / p_v1.y);
};
-Vector2 Vector2::operator/(const float &rvalue) const {
+Vector2 Vector2::operator/(const real_t &rvalue) const {
return Vector2(x / rvalue, y / rvalue);
};
-void Vector2::operator/=(const float &rvalue) {
+void Vector2::operator/=(const real_t &rvalue) {
x /= rvalue; y /= rvalue;
};
@@ -162,7 +162,7 @@ Vector2 Vector2::floor() const {
return Vector2( Math::floor(x), Math::floor(y) );
}
-Vector2 Vector2::rotated(float p_by) const {
+Vector2 Vector2::rotated(real_t p_by) const {
Vector2 v;
v.set_rotation(angle()+p_by);
@@ -198,7 +198,7 @@ Vector2 Vector2::clamped(real_t p_len) const {
return v;
}
-Vector2 Vector2::cubic_interpolate_soft(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,float p_t) const {
+Vector2 Vector2::cubic_interpolate_soft(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,real_t p_t) const {
#if 0
k[0] = ((*this) (vi[0] + 1, vi[1], vi[2])) - ((*this) (vi[0],
vi[1],vi[2])); //fk = a0
@@ -219,13 +219,13 @@ Vector2 Vector2::cubic_interpolate_soft(const Vector2& p_b,const Vector2& p_pre_
//dk = (fk+1 - fk-1)*0.5
//Dk = (fk+1 - fk)
- float dk =
+ real_t dk =
#endif
return Vector2();
}
-Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,float p_t) const {
+Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,real_t p_t) const {
@@ -234,9 +234,9 @@ Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, co
Vector2 p2=p_b;
Vector2 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;
Vector2 out;
out = 0.5f * ( ( p1 * 2.0f) +
@@ -246,8 +246,8 @@ Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, co
return out;
/*
- float mu = p_t;
- float mu2 = mu*mu;
+ real_t mu = p_t;
+ real_t mu2 = mu*mu;
Vector2 a0 = p_post_b - p_b - p_pre_a + *this;
Vector2 a1 = p_pre_a - *this - a0;
@@ -257,7 +257,7 @@ Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, co
return ( a0*mu*mu2 + a1*mu2 + a2*mu + a3 );
*/
/*
- float t = p_t;
+ real_t t = p_t;
real_t t2 = t*t;
real_t t3 = t2*t;
@@ -291,7 +291,7 @@ bool Rect2::intersects_segment(const Point2& p_from, const Point2& p_to, Point2*
real_t min=0,max=1;
int axis=0;
- float sign=0;
+ real_t sign=0;
for(int i=0;i<2;i++) {
real_t seg_from=p_from[i];
@@ -299,7 +299,7 @@ bool Rect2::intersects_segment(const Point2& p_from, const Point2& p_to, Point2*
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) {
@@ -408,25 +408,26 @@ bool Point2i::operator!=(const Point2i& p_vec2) const {
return x!=p_vec2.x || y!=p_vec2.y;
}
-void Matrix32::invert() {
-
+void Transform2D::invert() {
+ // FIXME: this function assumes the basis is a rotation matrix, with no scaling.
+ // Transform2D::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
SWAP(elements[0][1],elements[1][0]);
elements[2] = basis_xform(-elements[2]);
}
-Matrix32 Matrix32::inverse() const {
+Transform2D Transform2D::inverse() const {
- Matrix32 inv=*this;
+ Transform2D inv=*this;
inv.invert();
return inv;
}
-void Matrix32::affine_invert() {
+void Transform2D::affine_invert() {
- float det = elements[0][0]*elements[1][1] - elements[1][0]*elements[0][1];
+ real_t det = basis_determinant();
ERR_FAIL_COND(det==0);
- float idet = 1.0 / det;
+ real_t idet = 1.0 / det;
SWAP( elements[0][0],elements[1][1] );
elements[0]*=Vector2(idet,-idet);
@@ -436,72 +437,74 @@ void Matrix32::affine_invert() {
}
-Matrix32 Matrix32::affine_inverse() const {
+Transform2D Transform2D::affine_inverse() const {
- Matrix32 inv=*this;
+ Transform2D inv=*this;
inv.affine_invert();
return inv;
}
-void Matrix32::rotate(real_t p_phi) {
-
- Matrix32 rot(p_phi,Vector2());
- *this *= rot;
+void Transform2D::rotate(real_t p_phi) {
+ *this = Transform2D(p_phi,Vector2()) * (*this);
}
-real_t Matrix32::get_rotation() const {
-
- return Math::atan2(elements[1].x,elements[1].y);
+real_t Transform2D::get_rotation() const {
+ real_t det = basis_determinant();
+ Transform2D m = orthonormalized();
+ if (det < 0) {
+ m.scale_basis(Size2(-1,-1));
+ }
+ return Math::atan2(m[0].y,m[0].x);
}
-void Matrix32::set_rotation(real_t p_rot) {
+void Transform2D::set_rotation(real_t p_rot) {
real_t cr = Math::cos(p_rot);
real_t sr = Math::sin(p_rot);
elements[0][0]=cr;
+ elements[0][1]=sr;
+ elements[1][0]=-sr;
elements[1][1]=cr;
- elements[0][1]=-sr;
- elements[1][0]=sr;
}
-Matrix32::Matrix32(real_t p_rot, const Vector2& p_pos) {
+Transform2D::Transform2D(real_t p_rot, const Vector2& p_pos) {
real_t cr = Math::cos(p_rot);
real_t sr = Math::sin(p_rot);
elements[0][0]=cr;
+ elements[0][1]=sr;
+ elements[1][0]=-sr;
elements[1][1]=cr;
- elements[0][1]=-sr;
- elements[1][0]=sr;
elements[2]=p_pos;
}
-Size2 Matrix32::get_scale() const {
-
- return Size2( elements[0].length(), elements[1].length() );
+Size2 Transform2D::get_scale() const {
+ real_t det_sign = basis_determinant() > 0 ? 1 : -1;
+ return det_sign * Size2( elements[0].length(), elements[1].length() );
}
-void Matrix32::scale(const Size2& p_scale) {
-
- elements[0]*=p_scale;
- elements[1]*=p_scale;
+void Transform2D::scale(const Size2& p_scale) {
+ scale_basis(p_scale);
elements[2]*=p_scale;
}
-void Matrix32::scale_basis(const Size2& p_scale) {
+void Transform2D::scale_basis(const Size2& p_scale) {
- elements[0]*=p_scale;
- elements[1]*=p_scale;
+ elements[0][0]*=p_scale.x;
+ elements[0][1]*=p_scale.y;
+ elements[1][0]*=p_scale.x;
+ elements[1][1]*=p_scale.y;
}
-void Matrix32::translate( real_t p_tx, real_t p_ty) {
+void Transform2D::translate( real_t p_tx, real_t p_ty) {
translate(Vector2(p_tx,p_ty));
}
-void Matrix32::translate( const Vector2& p_translation ) {
+void Transform2D::translate( const Vector2& p_translation ) {
elements[2]+=basis_xform(p_translation);
}
-void Matrix32::orthonormalize() {
+void Transform2D::orthonormalize() {
// Gram-Schmidt Process
@@ -515,15 +518,15 @@ void Matrix32::orthonormalize() {
elements[0]=x;
elements[1]=y;
}
-Matrix32 Matrix32::orthonormalized() const {
+Transform2D Transform2D::orthonormalized() const {
- Matrix32 on=*this;
+ Transform2D on=*this;
on.orthonormalize();
return on;
}
-bool Matrix32::operator==(const Matrix32& p_transform) const {
+bool Transform2D::operator==(const Transform2D& p_transform) const {
for(int i=0;i<3;i++) {
if (elements[i]!=p_transform.elements[i])
@@ -533,7 +536,7 @@ bool Matrix32::operator==(const Matrix32& p_transform) const {
return true;
}
-bool Matrix32::operator!=(const Matrix32& p_transform) const {
+bool Transform2D::operator!=(const Transform2D& p_transform) const {
for(int i=0;i<3;i++) {
if (elements[i]!=p_transform.elements[i])
@@ -544,11 +547,11 @@ bool Matrix32::operator!=(const Matrix32& p_transform) const {
}
-void Matrix32::operator*=(const Matrix32& p_transform) {
+void Transform2D::operator*=(const Transform2D& p_transform) {
elements[2] = xform(p_transform.elements[2]);
- float x0,x1,y0,y1;
+ real_t x0,x1,y0,y1;
x0 = tdotx(p_transform.elements[0]);
x1 = tdoty(p_transform.elements[0]);
@@ -562,59 +565,59 @@ void Matrix32::operator*=(const Matrix32& p_transform) {
}
-Matrix32 Matrix32::operator*(const Matrix32& p_transform) const {
+Transform2D Transform2D::operator*(const Transform2D& p_transform) const {
- Matrix32 t = *this;
+ Transform2D t = *this;
t*=p_transform;
return t;
}
-Matrix32 Matrix32::scaled(const Size2& p_scale) const {
+Transform2D Transform2D::scaled(const Size2& p_scale) const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.scale(p_scale);
return copy;
}
-Matrix32 Matrix32::basis_scaled(const Size2& p_scale) const {
+Transform2D Transform2D::basis_scaled(const Size2& p_scale) const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.scale_basis(p_scale);
return copy;
}
-Matrix32 Matrix32::untranslated() const {
+Transform2D Transform2D::untranslated() const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.elements[2]=Vector2();
return copy;
}
-Matrix32 Matrix32::translated(const Vector2& p_offset) const {
+Transform2D Transform2D::translated(const Vector2& p_offset) const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.translate(p_offset);
return copy;
}
-Matrix32 Matrix32::rotated(float p_phi) const {
+Transform2D Transform2D::rotated(real_t p_phi) const {
- Matrix32 copy=*this;
+ Transform2D copy=*this;
copy.rotate(p_phi);
return copy;
}
-float Matrix32::basis_determinant() const {
+real_t Transform2D::basis_determinant() const {
return elements[0].x * elements[1].y - elements[0].y * elements[1].x;
}
-Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) const {
+Transform2D Transform2D::interpolate_with(const Transform2D& p_transform, real_t p_c) const {
//extract parameters
Vector2 p1 = get_origin();
@@ -645,12 +648,12 @@ Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) cons
}
//construct matrix
- Matrix32 res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c));
+ Transform2D res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c));
res.scale_basis(Vector2::linear_interpolate(s1, s2, p_c));
return res;
}
-Matrix32::operator String() const {
+Transform2D::operator String() const {
return String(String()+elements[0]+", "+elements[1]+", "+elements[2]);
}
diff --git a/core/math/math_2d.h b/core/math/math_2d.h
index 38c1ac9656..a24c4266ee 100644
--- a/core/math/math_2d.h
+++ b/core/math/math_2d.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -65,35 +65,35 @@ enum VAlign {
struct Vector2 {
union {
- float x;
- float width;
+ real_t x;
+ real_t width;
};
union {
- float y;
- float height;
+ real_t y;
+ real_t height;
};
- _FORCE_INLINE_ float& operator[](int p_idx) {
+ _FORCE_INLINE_ real_t& operator[](int p_idx) {
return p_idx?y:x;
}
- _FORCE_INLINE_ const float& operator[](int p_idx) const {
+ _FORCE_INLINE_ const real_t& operator[](int p_idx) const {
return p_idx?y:x;
}
void normalize();
Vector2 normalized() const;
- float length() const;
- float length_squared() const;
+ real_t length() const;
+ real_t length_squared() const;
- float distance_to(const Vector2& p_vector2) const;
- float distance_squared_to(const Vector2& p_vector2) const;
- float angle_to(const Vector2& p_vector2) const;
- float angle_to_point(const Vector2& p_vector2) const;
+ real_t distance_to(const Vector2& p_vector2) const;
+ real_t distance_squared_to(const Vector2& p_vector2) const;
+ real_t angle_to(const Vector2& p_vector2) const;
+ real_t angle_to_point(const Vector2& p_vector2) const;
- float dot(const Vector2& p_other) const;
- float cross(const Vector2& p_other) const;
+ real_t dot(const Vector2& p_other) const;
+ real_t cross(const Vector2& p_other) const;
Vector2 cross(real_t p_other) const;
Vector2 project(const Vector2& p_vec) const;
@@ -101,10 +101,10 @@ struct Vector2 {
Vector2 clamped(real_t p_len) const;
- _FORCE_INLINE_ static Vector2 linear_interpolate(const Vector2& p_a, const Vector2& p_b,float p_t);
- _FORCE_INLINE_ Vector2 linear_interpolate(const Vector2& p_b,float p_t) const;
- Vector2 cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,float p_t) const;
- Vector2 cubic_interpolate_soft(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,float p_t) const;
+ _FORCE_INLINE_ static Vector2 linear_interpolate(const Vector2& p_a, const Vector2& p_b,real_t p_t);
+ _FORCE_INLINE_ Vector2 linear_interpolate(const Vector2& p_b,real_t p_t) const;
+ Vector2 cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,real_t p_t) const;
+ Vector2 cubic_interpolate_soft(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,real_t p_t) const;
Vector2 slide(const Vector2& p_vec) const;
Vector2 reflect(const Vector2& p_vec) const;
@@ -115,15 +115,15 @@ struct Vector2 {
void operator-=(const Vector2& p_v);
Vector2 operator*(const Vector2 &p_v1) const;
- Vector2 operator*(const float &rvalue) const;
- void operator*=(const float &rvalue);
+ Vector2 operator*(const real_t &rvalue) const;
+ void operator*=(const real_t &rvalue);
void operator*=(const Vector2 &rvalue) { *this = *this * rvalue; }
Vector2 operator/(const Vector2 &p_v1) const;
- Vector2 operator/(const float &rvalue) const;
+ Vector2 operator/(const real_t &rvalue) const;
- void operator/=(const float &rvalue);
+ void operator/=(const real_t &rvalue);
Vector2 operator-() const;
@@ -135,10 +135,10 @@ struct Vector2 {
real_t angle() const;
- void set_rotation(float p_radians) {
+ void set_rotation(real_t p_radians) {
- x=Math::sin(p_radians);
- y=Math::cos(p_radians);
+ x=Math::cos(p_radians);
+ y=Math::sin(p_radians);
}
_FORCE_INLINE_ Vector2 abs() const {
@@ -146,7 +146,7 @@ struct Vector2 {
return Vector2( Math::abs(x), Math::abs(y) );
}
- Vector2 rotated(float p_by) const;
+ Vector2 rotated(real_t p_by) const;
Vector2 tangent() const {
return Vector2(y,-x);
@@ -154,12 +154,12 @@ struct Vector2 {
Vector2 floor() const;
Vector2 snapped(const Vector2& p_by) const;
- float get_aspect() const { return width/height; }
+ real_t aspect() const { return width/height; }
operator String() const { return String::num(x)+", "+String::num(y); }
- _FORCE_INLINE_ Vector2(float p_x,float p_y) { x=p_x; y=p_y; }
+ _FORCE_INLINE_ Vector2(real_t p_x,real_t p_y) { x=p_x; y=p_y; }
_FORCE_INLINE_ Vector2() { x=0; y=0; }
};
@@ -169,12 +169,12 @@ _FORCE_INLINE_ Vector2 Vector2::plane_project(real_t p_d, const Vector2& p_vec)
}
-_FORCE_INLINE_ Vector2 operator*(float p_scalar, const Vector2& p_vec) {
+_FORCE_INLINE_ Vector2 operator*(real_t p_scalar, const Vector2& p_vec) {
return p_vec*p_scalar;
}
-Vector2 Vector2::linear_interpolate(const Vector2& p_b,float p_t) const {
+Vector2 Vector2::linear_interpolate(const Vector2& p_b,real_t p_t) const {
Vector2 res=*this;
@@ -185,7 +185,7 @@ Vector2 Vector2::linear_interpolate(const Vector2& p_b,float p_t) const {
}
-Vector2 Vector2::linear_interpolate(const Vector2& p_a, const Vector2& p_b,float p_t) {
+Vector2 Vector2::linear_interpolate(const Vector2& p_a, const Vector2& p_b,real_t p_t) {
Vector2 res=p_a;
@@ -198,7 +198,7 @@ Vector2 Vector2::linear_interpolate(const Vector2& p_a, const Vector2& p_b,float
typedef Vector2 Size2;
typedef Vector2 Point2;
-struct Matrix32;
+struct Transform2D;
struct Rect2 {
@@ -211,7 +211,7 @@ struct Rect2 {
const Vector2& get_size() const { return size; }
void set_size(const Vector2& p_size) { size=p_size; }
- float get_area() const { return size.width*size.height; }
+ real_t get_area() const { return size.width*size.height; }
inline bool intersects(const Rect2& p_rect) const {
if ( pos.x >= (p_rect.pos.x + p_rect.size.width) )
@@ -226,9 +226,9 @@ struct Rect2 {
return true;
}
- inline float distance_to(const Vector2& p_point) const {
+ inline real_t distance_to(const Vector2& p_point) const {
- float dist = 1e20;
+ real_t dist = 1e20;
if (p_point.x < pos.x) {
dist=MIN(dist,pos.x-p_point.x);
@@ -249,7 +249,7 @@ struct Rect2 {
return dist;
}
- _FORCE_INLINE_ bool intersects_transformed(const Matrix32& p_xform, const Rect2& p_rect) const;
+ _FORCE_INLINE_ bool intersects_transformed(const Transform2D& p_xform, const Rect2& p_rect) const;
bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=NULL, Point2* r_normal=NULL) const;
@@ -359,7 +359,7 @@ struct Rect2 {
operator String() const { return String(pos)+", "+String(size); }
Rect2() {}
- Rect2( float p_x, float p_y, float p_width, float p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); }
+ Rect2( real_t p_x, real_t p_y, real_t p_width, real_t p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); }
Rect2( const Point2& p_pos, const Size2& p_size ) { pos=p_pos; size=p_size; }
};
@@ -407,7 +407,7 @@ struct Point2i {
bool operator==(const Point2i& p_vec2) const;
bool operator!=(const Point2i& p_vec2) const;
- float get_aspect() const { return width/(float)height; }
+ real_t get_aspect() const { return width/(real_t)height; }
operator String() const { return String::num(x)+", "+String::num(y); }
@@ -551,12 +551,22 @@ struct Rect2i {
-struct Matrix32 {
+struct Transform2D {
+ // Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper":
+ // M = (elements[0][0] elements[1][0])
+ // (elements[0][1] elements[1][1])
+ // This is such that the columns, which can be interpreted as basis vectors of the coordinate system "painted" on the object, can be accessed as elements[i].
+ // Note that this is the opposite of the indices in mathematical texts, meaning: $M_{12}$ in a math book corresponds to elements[1][0] here.
+ // This requires additional care when working with explicit indices.
+ // See https://en.wikipedia.org/wiki/Row-_and_column-major_order for further reading.
+
+ // Warning #2: 2D be aware that unlike 3D code, 2D code uses a left-handed coordinate system: Y-axis points down,
+ // and angle is measure from +X to +Y in a clockwise-fashion.
Vector2 elements[3];
- _FORCE_INLINE_ float tdotx(const Vector2& v) const { return elements[0][0] * v.x + elements[1][0] * v.y; }
- _FORCE_INLINE_ float tdoty(const Vector2& v) const { return elements[0][1] * v.x + elements[1][1] * v.y; }
+ _FORCE_INLINE_ real_t tdotx(const Vector2& v) const { return elements[0][0] * v.x + elements[1][0] * v.y; }
+ _FORCE_INLINE_ real_t tdoty(const Vector2& v) const { return elements[0][1] * v.x + elements[1][1] * v.y; }
const Vector2& operator[](int p_idx) const { return elements[p_idx]; }
Vector2& operator[](int p_idx) { return elements[p_idx]; }
@@ -565,10 +575,10 @@ struct Matrix32 {
_FORCE_INLINE_ void set_axis(int p_axis,const Vector2& p_vec) { ERR_FAIL_INDEX(p_axis,3); elements[p_axis]=p_vec; }
void invert();
- Matrix32 inverse() const;
+ Transform2D inverse() const;
void affine_invert();
- Matrix32 affine_inverse() const;
+ Transform2D affine_inverse() const;
void set_rotation(real_t p_phi);
real_t get_rotation() const;
@@ -580,30 +590,30 @@ struct Matrix32 {
void translate( real_t p_tx, real_t p_ty);
void translate( const Vector2& p_translation );
- float basis_determinant() const;
+ real_t basis_determinant() const;
Size2 get_scale() const;
_FORCE_INLINE_ const Vector2& get_origin() const { return elements[2]; }
_FORCE_INLINE_ void set_origin(const Vector2& p_origin) { elements[2]=p_origin; }
- Matrix32 scaled(const Size2& p_scale) const;
- Matrix32 basis_scaled(const Size2& p_scale) const;
- Matrix32 translated(const Vector2& p_offset) const;
- Matrix32 rotated(float p_phi) const;
+ Transform2D scaled(const Size2& p_scale) const;
+ Transform2D basis_scaled(const Size2& p_scale) const;
+ Transform2D translated(const Vector2& p_offset) const;
+ Transform2D rotated(real_t p_phi) const;
- Matrix32 untranslated() const;
+ Transform2D untranslated() const;
void orthonormalize();
- Matrix32 orthonormalized() const;
+ Transform2D orthonormalized() const;
- bool operator==(const Matrix32& p_transform) const;
- bool operator!=(const Matrix32& p_transform) const;
+ bool operator==(const Transform2D& p_transform) const;
+ bool operator!=(const Transform2D& p_transform) const;
- void operator*=(const Matrix32& p_transform);
- Matrix32 operator*(const Matrix32& p_transform) const;
+ void operator*=(const Transform2D& p_transform);
+ Transform2D operator*(const Transform2D& p_transform) const;
- Matrix32 interpolate_with(const Matrix32& p_transform, float p_c) const;
+ Transform2D interpolate_with(const Transform2D& p_transform, real_t p_c) const;
_FORCE_INLINE_ Vector2 basis_xform(const Vector2& p_vec) const;
_FORCE_INLINE_ Vector2 basis_xform_inv(const Vector2& p_vec) const;
@@ -614,7 +624,7 @@ struct Matrix32 {
operator String() const;
- Matrix32(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) {
+ Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) {
elements[0][0] = xx;
elements[0][1] = xy;
@@ -624,11 +634,11 @@ struct Matrix32 {
elements[2][1] = oy;
}
- Matrix32(real_t p_rot, const Vector2& p_pos);
- Matrix32() { elements[0][0]=1.0; elements[1][1]=1.0; }
+ Transform2D(real_t p_rot, const Vector2& p_pos);
+ Transform2D() { elements[0][0]=1.0; elements[1][1]=1.0; }
};
-bool Rect2::intersects_transformed(const Matrix32& p_xform, const Rect2& p_rect) const {
+bool Rect2::intersects_transformed(const Transform2D& p_xform, const Rect2& p_rect) const {
//SAT intersection between local and transformed rect2
@@ -783,7 +793,7 @@ bool Rect2::intersects_transformed(const Matrix32& p_xform, const Rect2& p_rect)
}
-Vector2 Matrix32::basis_xform(const Vector2& v) const {
+Vector2 Transform2D::basis_xform(const Vector2& v) const {
return Vector2(
tdotx(v),
@@ -791,7 +801,7 @@ Vector2 Matrix32::basis_xform(const Vector2& v) const {
);
}
-Vector2 Matrix32::basis_xform_inv(const Vector2& v) const{
+Vector2 Transform2D::basis_xform_inv(const Vector2& v) const{
return Vector2(
elements[0].dot(v),
@@ -799,14 +809,14 @@ Vector2 Matrix32::basis_xform_inv(const Vector2& v) const{
);
}
-Vector2 Matrix32::xform(const Vector2& v) const {
+Vector2 Transform2D::xform(const Vector2& v) const {
return Vector2(
tdotx(v),
tdoty(v)
) + elements[2];
}
-Vector2 Matrix32::xform_inv(const Vector2& p_vec) const {
+Vector2 Transform2D::xform_inv(const Vector2& p_vec) const {
Vector2 v = p_vec - elements[2];
@@ -816,7 +826,7 @@ Vector2 Matrix32::xform_inv(const Vector2& p_vec) const {
);
}
-Rect2 Matrix32::xform(const Rect2& p_rect) const {
+Rect2 Transform2D::xform(const Rect2& p_rect) const {
Vector2 x=elements[0]*p_rect.size.x;
Vector2 y=elements[1]*p_rect.size.y;
@@ -830,16 +840,16 @@ Rect2 Matrix32::xform(const Rect2& p_rect) const {
return new_rect;
}
-void Matrix32::set_rotation_and_scale(real_t p_rot,const Size2& p_scale) {
+void Transform2D::set_rotation_and_scale(real_t p_rot,const Size2& p_scale) {
elements[0][0]=Math::cos(p_rot)*p_scale.x;
elements[1][1]=Math::cos(p_rot)*p_scale.y;
- elements[0][1]=-Math::sin(p_rot)*p_scale.x;
- elements[1][0]=Math::sin(p_rot)*p_scale.y;
+ elements[1][0]=-Math::sin(p_rot)*p_scale.y;
+ elements[0][1]=Math::sin(p_rot)*p_scale.x;
}
-Rect2 Matrix32::xform_inv(const Rect2& p_rect) const {
+Rect2 Transform2D::xform_inv(const Rect2& p_rect) const {
Vector2 ends[4]={
xform_inv( p_rect.pos ),
diff --git a/core/math/math_defs.h b/core/math/math_defs.h
index e6a56c5e45..feaff38a44 100644
--- a/core/math/math_defs.h
+++ b/core/math/math_defs.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 64615fe6b4..8353aa0ebe 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,7 +29,7 @@
#include "math_funcs.h"
#include "core/os/os.h"
-#include <math.h>
+
#include "float.h"
uint32_t Math::default_seed=1;
@@ -41,37 +41,16 @@ static uint32_t Q[4096];
#endif
uint32_t Math::rand_from_seed(uint32_t *seed) {
-
-#if 1
- uint32_t k;
- uint32_t s = (*seed);
- if (s == 0)
- s = 0x12345987;
- k = s / 127773;
- s = 16807 * (s - k * 127773) - 2836 * k;
-// if (s < 0)
-// s += 2147483647;
- (*seed) = s;
- return (s & Math::RANDOM_MAX);
-#else
- *seed = *seed * 1103515245 + 12345;
- return (*seed % ((unsigned int)RANDOM_MAX + 1));
-#endif
+ // Xorshift31 PRNG
+ if ( *seed == 0 ) *seed = Math::RANDOM_MAX;
+ (*seed) ^= (*seed) << 13;
+ (*seed) ^= (*seed) >> 17;
+ (*seed) ^= (*seed) << 5;
+ return (*seed) & Math::RANDOM_MAX;
}
void Math::seed(uint32_t x) {
-#if 0
- int i;
-
- Q[0] = x;
- Q[1] = x + PHI;
- Q[2] = x + PHI + PHI;
-
- for (i = 3; i < 4096; i++)
- Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
-#else
default_seed=x;
-#endif
}
void Math::randomize() {
@@ -82,57 +61,15 @@ void Math::randomize() {
uint32_t Math::rand() {
- return rand_from_seed(&default_seed)&0x7FFFFFFF;
+ return rand_from_seed(&default_seed);
}
double Math::randf() {
- return (double)rand() / (double)RANDOM_MAX;
-}
-
-double Math::sin(double p_x) {
-
- return ::sin(p_x);
-
-}
-
-double Math::cos(double p_x) {
-
- return ::cos(p_x);
-
-}
-
-double Math::tan(double p_x) {
-
- return ::tan(p_x);
-
-}
-double Math::sinh(double p_x) {
-
- return ::sinh(p_x);
-}
-
-double Math::cosh(double p_x) {
-
- return ::cosh(p_x);
-}
-
-double Math::tanh(double p_x) {
-
- return ::tanh(p_x);
+ return (double)rand() / (double)Math::RANDOM_MAX;
}
-double Math::deg2rad(double p_y) {
-
- return p_y*Math_PI/180.0;
-}
-
-double Math::rad2deg(double p_y) {
-
- return p_y*180.0/Math_PI;
-}
-
double Math::round(double p_val) {
if (p_val>=0) {
@@ -143,22 +80,6 @@ double Math::round(double p_val) {
}
}
-double Math::asin(double p_x) {
-
- return ::asin(p_x);
-
-}
-
-double Math::acos(double p_x) {
-
- return ::acos(p_x);
-}
-
-double Math::atan(double p_x) {
-
- return ::atan(p_x);
-}
-
double Math::dectime(double p_value,double p_amount, double p_step) {
float sgn = p_value < 0 ? -1.0 : 1.0;
@@ -169,42 +90,6 @@ double Math::dectime(double p_value,double p_amount, double p_step) {
return val*sgn;
}
-double Math::atan2(double p_y, double p_x) {
-
- return ::atan2(p_y,p_x);
-
-}
-double Math::sqrt(double p_x) {
-
- return ::sqrt(p_x);
-}
-
-double Math::fmod(double p_x,double p_y) {
-
- return ::fmod(p_x,p_y);
-}
-
-double Math::fposmod(double p_x,double p_y) {
-
- if (p_x>=0) {
-
- return Math::fmod(p_x,p_y);
-
- } else {
-
- return p_y-Math::fmod(-p_x,p_y);
- }
-
-}
-double Math::floor(double p_x) {
-
- return ::floor(p_x);
-}
-
-double Math::ceil(double p_x) {
-
- return ::ceil(p_x);
-}
int Math::step_decimals(double p_step) {
@@ -265,20 +150,7 @@ double Math::stepify(double p_value,double p_step) {
return p_value;
}
-bool Math::is_nan(double p_val) {
-
- return (p_val!=p_val);
-}
-
-bool Math::is_inf(double p_val) {
-
-#ifdef _MSC_VER
- return !_finite(p_val);
-#else
- return isinf(p_val);
-#endif
-}
uint32_t Math::larger_prime(uint32_t p_val) {
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index fc76d96b2e..8ce59224ff 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,38 +33,125 @@
#include "math_defs.h"
#ifndef NO_MATH_H
-#include "math.h"
+#include <math.h>
#endif
+#define Math_PI 3.14159265358979323846
+#define Math_SQRT12 0.7071067811865475244008443621048490
+
class Math {
static uint32_t default_seed;
public:
- Math() {}; // useless to instance
+ Math() {} // useless to instance
enum {
RANDOM_MAX=2147483647L
};
- static double sin(double p_x);
- static double cos(double p_x);
- static double tan(double p_x);
- static double sinh(double p_x);
- static double cosh(double p_x);
- static double tanh(double p_x);
- static double asin(double p_x);
- static double acos(double p_x);
- static double atan(double p_x);
- static double atan2(double p_y, double p_x);
- static double deg2rad(double p_y);
- static double rad2deg(double p_y);
- static double sqrt(double p_x);
- static double fmod(double p_x,double p_y);
- static double fposmod(double p_x,double p_y);
+
+ 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 asin(double p_x) {
+
+ return ::asin(p_x);
+
+ }
+
+ static _ALWAYS_INLINE_ double acos(double p_x) {
+
+ return ::acos(p_x);
+ }
+
+ static _ALWAYS_INLINE_ double atan(double p_x) {
+
+ return ::atan(p_x);
+ }
+
+ static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) {
+
+ return ::atan2(p_y,p_x);
+
+ }
+
+ static _ALWAYS_INLINE_ double deg2rad(double p_y) {
+
+ return p_y*Math_PI/180.0;
+ }
+
+ static _ALWAYS_INLINE_ double rad2deg(double p_y) {
+
+ return p_y*180.0/Math_PI;
+ }
+
+
+ static _ALWAYS_INLINE_ double sqrt(double p_x) {
+
+ return ::sqrt(p_x);
+ }
+
+ static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) {
+
+ return ::fmod(p_x,p_y);
+ }
+
+ static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) {
+
+ if (p_x>=0) {
+
+ return fmod(p_x,p_y);
+
+ } else {
+
+ return p_y-fmod(-p_x,p_y);
+ }
+
+ }
+ static _ALWAYS_INLINE_ double floor(double p_x) {
+
+ return ::floor(p_x);
+ }
+
+ static _ALWAYS_INLINE_ double ceil(double p_x) {
+
+ return ::ceil(p_x);
+ }
+
+
static uint32_t rand_from_seed(uint32_t *seed);
- static double floor(double p_x);
- static double ceil(double p_x);
+
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);
@@ -84,10 +171,20 @@ public:
return Math::exp( p_db * 0.11512925464970228420089957273422 );
}
- static bool is_nan(double p_val);
- static bool is_inf(double p_val);
+ 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 uint32_t rand();
static double randf();
@@ -96,6 +193,15 @@ public:
static double random(double from, double to);
+ static _FORCE_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.
+ // See https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ for details.
+
+ return abs(a-b) < CMP_EPSILON;
+ }
+
static _FORCE_INLINE_ real_t abs(real_t g) {
@@ -175,10 +281,110 @@ public:
static double log(double x);
static double exp(double x);
+
+ static _FORCE_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h)
+ {
+ uint16_t h_exp, h_sig;
+ uint32_t f_sgn, f_exp, f_sig;
+
+ h_exp = (h&0x7c00u);
+ f_sgn = ((uint32_t)h&0x8000u) << 16;
+ switch (h_exp) {
+ case 0x0000u: /* 0 or subnormal */
+ h_sig = (h&0x03ffu);
+ /* Signed zero */
+ if (h_sig == 0) {
+ return f_sgn;
+ }
+ /* Subnormal */
+ h_sig <<= 1;
+ while ((h_sig&0x0400u) == 0) {
+ h_sig <<= 1;
+ h_exp++;
+ }
+ f_exp = ((uint32_t)(127 - 15 - h_exp)) << 23;
+ f_sig = ((uint32_t)(h_sig&0x03ffu)) << 13;
+ return f_sgn + f_exp + f_sig;
+ case 0x7c00u: /* inf or NaN */
+ /* All-ones exponent and a copy of the significand */
+ return f_sgn + 0x7f800000u + (((uint32_t)(h&0x03ffu)) << 13);
+ default: /* normalized */
+ /* Just need to adjust the exponent and shift */
+ return f_sgn + (((uint32_t)(h&0x7fffu) + 0x1c000u) << 13);
+ }
+ }
+
+ static _FORCE_INLINE_ float halfptr_to_float(const uint16_t *h) {
+
+ union {
+ uint32_t u32;
+ float f32;
+ } u;
+
+ u.u32=halfbits_to_floatbits(*h);
+ return u.f32;
+ }
+
+ static _FORCE_INLINE_ uint16_t make_half_float(float f) {
+
+ union {
+ float fv;
+ uint32_t ui;
+ } ci;
+ ci.fv=f;
+
+ uint32_t x = ci.ui;
+ uint32_t sign = (unsigned short)(x >> 31);
+ uint32_t mantissa;
+ uint32_t exp;
+ uint16_t hf;
+
+ // get mantissa
+ mantissa = x & ((1 << 23) - 1);
+ // get exponent bits
+ exp = x & (0xFF << 23);
+ if (exp >= 0x47800000)
+ {
+ // check if the original single precision float number is a NaN
+ if (mantissa && (exp == (0xFF << 23)))
+ {
+ // we have a single precision NaN
+ mantissa = (1 << 23) - 1;
+ }
+ else
+ {
+ // 16-bit half-float representation stores number as Inf
+ mantissa = 0;
+ }
+ hf = (((uint16_t)sign) << 15) | (uint16_t)((0x1F << 10)) |
+ (uint16_t)(mantissa >> 13);
+ }
+ // check if exponent is <= -15
+ else if (exp <= 0x38000000)
+ {
+
+ /*// store a denorm half-float value or zero
+ exp = (0x38000000 - exp) >> 23;
+ mantissa >>= (14 + exp);
+
+ hf = (((uint16_t)sign) << 15) | (uint16_t)(mantissa);
+ */
+ hf=0; //denormals do not work for 3D, convert to zero
+ }
+ else
+ {
+ hf = (((uint16_t)sign) << 15) |
+ (uint16_t)((exp - 0x38000000) >> 13) |
+ (uint16_t)(mantissa >> 13);
+ }
+
+ return hf;
+ }
+
+
+
};
-#define Math_PI 3.14159265358979323846
-#define Math_SQRT12 0.7071067811865475244008443621048490
#endif // MATH_FUNCS_H
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index 71e6b62212..e9c3442582 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,7 +33,7 @@
#define cofac(row1,col1, row2, col2)\
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1])
-void Matrix3::from_z(const Vector3& p_z) {
+void Basis::from_z(const Vector3& p_z) {
if (Math::abs(p_z.z) > Math_SQRT12 ) {
@@ -53,7 +53,7 @@ void Matrix3::from_z(const Vector3& p_z) {
elements[2]=p_z;
}
-void Matrix3::invert() {
+void Basis::invert() {
real_t co[3]={
@@ -72,7 +72,8 @@ void Matrix3::invert() {
}
-void Matrix3::orthonormalize() {
+void Basis::orthonormalize() {
+ ERR_FAIL_COND(determinant() == 0);
// Gram-Schmidt Process
@@ -92,100 +93,230 @@ void Matrix3::orthonormalize() {
}
-Matrix3 Matrix3::orthonormalized() const {
+Basis Basis::orthonormalized() const {
- Matrix3 c = *this;
+ Basis c = *this;
c.orthonormalize();
return c;
}
+bool Basis::is_orthogonal() const {
+ Basis id;
+ Basis m = (*this)*transposed();
-Matrix3 Matrix3::inverse() const {
+ return isequal_approx(id,m);
+}
+
+bool Basis::is_rotation() const {
+ return Math::isequal_approx(determinant(), 1) && is_orthogonal();
+}
+
+
+bool Basis::is_symmetric() const {
+
+ if (Math::abs(elements[0][1] - elements[1][0]) > CMP_EPSILON)
+ return false;
+ if (Math::abs(elements[0][2] - elements[2][0]) > CMP_EPSILON)
+ return false;
+ if (Math::abs(elements[1][2] - elements[2][1]) > CMP_EPSILON)
+ return false;
+
+ return true;
+}
+
+
+Basis Basis::diagonalize() {
+
+ //NOTE: only implemented for symmetric matrices
+ //with the Jacobi iterative method method
+
+ ERR_FAIL_COND_V(!is_symmetric(), Basis());
+
+ const int ite_max = 1024;
+
+ real_t off_matrix_norm_2 = elements[0][1] * elements[0][1] + elements[0][2] * elements[0][2] + elements[1][2] * elements[1][2];
+
+ int ite = 0;
+ Basis acc_rot;
+ while (off_matrix_norm_2 > CMP_EPSILON2 && ite++ < ite_max ) {
+ real_t el01_2 = elements[0][1] * elements[0][1];
+ real_t el02_2 = elements[0][2] * elements[0][2];
+ real_t el12_2 = elements[1][2] * elements[1][2];
+ // Find the pivot element
+ int i, j;
+ if (el01_2 > el02_2) {
+ if (el12_2 > el01_2) {
+ i = 1;
+ j = 2;
+ } else {
+ i = 0;
+ j = 1;
+ }
+ } else {
+ if (el12_2 > el02_2) {
+ i = 1;
+ j = 2;
+ } else {
+ i = 0;
+ j = 2;
+ }
+ }
+
+ // Compute the rotation angle
+ real_t angle;
+ if (Math::abs(elements[j][j] - elements[i][i]) < CMP_EPSILON) {
+ angle = Math_PI / 4;
+ } else {
+ angle = 0.5 * Math::atan(2 * elements[i][j] / (elements[j][j] - elements[i][i]));
+ }
- Matrix3 inv=*this;
+ // Compute the rotation matrix
+ Basis rot;
+ rot.elements[i][i] = rot.elements[j][j] = Math::cos(angle);
+ rot.elements[i][j] = - (rot.elements[j][i] = Math::sin(angle));
+
+ // Update the off matrix norm
+ off_matrix_norm_2 -= elements[i][j] * elements[i][j];
+
+ // Apply the rotation
+ *this = rot * *this * rot.transposed();
+ acc_rot = rot * acc_rot;
+ }
+
+ return acc_rot;
+}
+
+Basis Basis::inverse() const {
+
+ Basis inv=*this;
inv.invert();
return inv;
}
-void Matrix3::transpose() {
+void Basis::transpose() {
SWAP(elements[0][1],elements[1][0]);
SWAP(elements[0][2],elements[2][0]);
SWAP(elements[1][2],elements[2][1]);
}
-Matrix3 Matrix3::transposed() const {
+Basis Basis::transposed() const {
- Matrix3 tr=*this;
+ Basis tr=*this;
tr.transpose();
return tr;
}
-void Matrix3::scale(const Vector3& p_scale) {
+// Multiplies the matrix from left by the scaling matrix: M -> S.M
+// See the comment for Basis::rotated for further explanation.
+void Basis::scale(const Vector3& p_scale) {
elements[0][0]*=p_scale.x;
- elements[1][0]*=p_scale.x;
- elements[2][0]*=p_scale.x;
- elements[0][1]*=p_scale.y;
+ elements[0][1]*=p_scale.x;
+ elements[0][2]*=p_scale.x;
+ elements[1][0]*=p_scale.y;
elements[1][1]*=p_scale.y;
- elements[2][1]*=p_scale.y;
- elements[0][2]*=p_scale.z;
- elements[1][2]*=p_scale.z;
+ elements[1][2]*=p_scale.y;
+ elements[2][0]*=p_scale.z;
+ elements[2][1]*=p_scale.z;
elements[2][2]*=p_scale.z;
}
-Matrix3 Matrix3::scaled( const Vector3& p_scale ) const {
+Basis Basis::scaled( const Vector3& p_scale ) const {
- Matrix3 m = *this;
+ Basis m = *this;
m.scale(p_scale);
return m;
}
-Vector3 Matrix3::get_scale() const {
-
- return Vector3(
+Vector3 Basis::get_scale() const {
+ // We are assuming M = R.S, and performing a polar decomposition to extract R and S.
+ // FIXME: We eventually need a proper polar decomposition.
+ // As a cheap workaround until then, to ensure that R is a proper rotation matrix with determinant +1
+ // (such that it can be represented by a Quat or Euler angles), we absorb the sign flip into the scaling matrix.
+ // As such, it works in conjuction with get_rotation().
+ real_t det_sign = determinant() > 0 ? 1 : -1;
+ return det_sign*Vector3(
Vector3(elements[0][0],elements[1][0],elements[2][0]).length(),
Vector3(elements[0][1],elements[1][1],elements[2][1]).length(),
Vector3(elements[0][2],elements[1][2],elements[2][2]).length()
);
}
-void Matrix3::rotate(const Vector3& p_axis, real_t p_phi) {
- *this = *this * Matrix3(p_axis, p_phi);
+// Multiplies the matrix from left by the rotation matrix: M -> R.M
+// Note that this does *not* rotate the matrix itself.
+//
+// The main use of Basis is as Transform.basis, which is used a the transformation matrix
+// of 3D object. Rotate here refers to rotation of the object (which is R * (*this)),
+// not the matrix itself (which is R * (*this) * R.transposed()).
+Basis Basis::rotated(const Vector3& p_axis, real_t p_phi) const {
+ return Basis(p_axis, p_phi) * (*this);
}
-Matrix3 Matrix3::rotated(const Vector3& p_axis, real_t p_phi) const {
+void Basis::rotate(const Vector3& p_axis, real_t p_phi) {
+ *this = rotated(p_axis, p_phi);
+}
- return *this * Matrix3(p_axis, p_phi);
+Basis Basis::rotated(const Vector3& p_euler) const {
+ return Basis(p_euler) * (*this);
+}
+void Basis::rotate(const Vector3& p_euler) {
+ *this = rotated(p_euler);
}
-Vector3 Matrix3::get_euler() const {
+Vector3 Basis::get_rotation() const {
+ // Assumes that the matrix can be decomposed into a proper rotation and scaling matrix as M = R.S,
+ // and returns the Euler angles corresponding to the rotation part, complementing get_scale().
+ // See the comment in get_scale() for further information.
+ Basis m = orthonormalized();
+ real_t det = m.determinant();
+ if (det < 0) {
+ // Ensure that the determinant is 1, such that result is a proper rotation matrix which can be represented by Euler angles.
+ m.scale(Vector3(-1,-1,-1));
+ }
+
+ return m.get_euler();
+}
+// get_euler returns a vector containing the Euler angles in the format
+// (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last
+// (following the convention they are commonly defined in the literature).
+//
+// The current implementation uses XYZ convention (Z is the first rotation),
+// so euler.z is the angle of the (first) rotation around Z axis and so on,
+//
+// And thus, assuming the matrix is a rotation matrix, this function returns
+// the angles in the decomposition R = X(a1).Y(a2).Z(a3) where Z(a) rotates
+// around the z-axis by a and so on.
+Vector3 Basis::get_euler() const {
+
+ // Euler angles in XYZ convention.
+ // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
+ //
// rot = cy*cz -cy*sz sy
- // cz*sx*sy+cx*sz cx*cz-sx*sy*sz -cy*sx
- // -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy
-
- Matrix3 m = *this;
- m.orthonormalize();
+ // cz*sx*sy+cx*sz cx*cz-sx*sy*sz -cy*sx
+ // -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy
Vector3 euler;
- euler.y = Math::asin(m[0][2]);
+ ERR_FAIL_COND_V(is_rotation() == false, euler);
+
+ euler.y = Math::asin(elements[0][2]);
if ( euler.y < Math_PI*0.5) {
if ( euler.y > -Math_PI*0.5) {
- euler.x = Math::atan2(-m[1][2],m[2][2]);
- euler.z = Math::atan2(-m[0][1],m[0][0]);
+ euler.x = Math::atan2(-elements[1][2],elements[2][2]);
+ euler.z = Math::atan2(-elements[0][1],elements[0][0]);
} else {
- real_t r = Math::atan2(m[1][0],m[1][1]);
+ real_t r = Math::atan2(elements[1][0],elements[1][1]);
euler.z = 0.0;
euler.x = euler.z - r;
}
} else {
- real_t r = Math::atan2(m[0][1],m[1][1]);
+ real_t r = Math::atan2(elements[0][1],elements[1][1]);
euler.z = 0;
euler.x = r - euler.z;
}
@@ -195,43 +326,59 @@ Vector3 Matrix3::get_euler() const {
}
-void Matrix3::set_euler(const Vector3& p_euler) {
+// set_euler expects a vector containing the Euler angles in the format
+// (c,b,a), where a is the angle of the first rotation, and c is the last.
+// The current implementation uses XYZ convention (Z is the first rotation).
+void Basis::set_euler(const Vector3& p_euler) {
real_t c, s;
c = Math::cos(p_euler.x);
s = Math::sin(p_euler.x);
- Matrix3 xmat(1.0,0.0,0.0,0.0,c,-s,0.0,s,c);
+ Basis xmat(1.0,0.0,0.0,0.0,c,-s,0.0,s,c);
c = Math::cos(p_euler.y);
s = Math::sin(p_euler.y);
- Matrix3 ymat(c,0.0,s,0.0,1.0,0.0,-s,0.0,c);
+ Basis ymat(c,0.0,s,0.0,1.0,0.0,-s,0.0,c);
c = Math::cos(p_euler.z);
s = Math::sin(p_euler.z);
- Matrix3 zmat(c,-s,0.0,s,c,0.0,0.0,0.0,1.0);
+ Basis zmat(c,-s,0.0,s,c,0.0,0.0,0.0,1.0);
//optimizer will optimize away all this anyway
*this = xmat*(ymat*zmat);
}
-bool Matrix3::operator==(const Matrix3& p_matrix) const {
+bool Basis::isequal_approx(const Basis& a, const Basis& b) const {
+
+ for (int i=0;i<3;i++) {
+ for (int j=0;j<3;j++) {
+ if (Math::isequal_approx(a.elements[i][j],b.elements[i][j]) == false)
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool Basis::operator==(const Basis& p_matrix) const {
for (int i=0;i<3;i++) {
for (int j=0;j<3;j++) {
- if (elements[i][j]!=p_matrix.elements[i][j])
+ if (elements[i][j] != p_matrix.elements[i][j])
return false;
}
}
return true;
}
-bool Matrix3::operator!=(const Matrix3& p_matrix) const {
+
+bool Basis::operator!=(const Basis& p_matrix) const {
return (!(*this==p_matrix));
}
-Matrix3::operator String() const {
+Basis::operator String() const {
String mtx;
for (int i=0;i<3;i++) {
@@ -248,12 +395,10 @@ Matrix3::operator String() const {
return mtx;
}
-Matrix3::operator Quat() const {
+Basis::operator Quat() const {
+ ERR_FAIL_COND_V(is_rotation() == false, Quat());
- Matrix3 m=*this;
- m.orthonormalize();
-
- real_t trace = m.elements[0][0] + m.elements[1][1] + m.elements[2][2];
+ real_t trace = elements[0][0] + elements[1][1] + elements[2][2];
real_t temp[4];
if (trace > 0.0)
@@ -262,66 +407,66 @@ Matrix3::operator Quat() const {
temp[3]=(s * 0.5);
s = 0.5 / s;
- temp[0]=((m.elements[2][1] - m.elements[1][2]) * s);
- temp[1]=((m.elements[0][2] - m.elements[2][0]) * s);
- temp[2]=((m.elements[1][0] - m.elements[0][1]) * s);
+ temp[0]=((elements[2][1] - elements[1][2]) * s);
+ temp[1]=((elements[0][2] - elements[2][0]) * s);
+ temp[2]=((elements[1][0] - elements[0][1]) * s);
}
else
{
- int i = m.elements[0][0] < m.elements[1][1] ?
- (m.elements[1][1] < m.elements[2][2] ? 2 : 1) :
- (m.elements[0][0] < m.elements[2][2] ? 2 : 0);
+ int i = elements[0][0] < elements[1][1] ?
+ (elements[1][1] < elements[2][2] ? 2 : 1) :
+ (elements[0][0] < elements[2][2] ? 2 : 0);
int j = (i + 1) % 3;
int k = (i + 2) % 3;
- real_t s = Math::sqrt(m.elements[i][i] - m.elements[j][j] - m.elements[k][k] + 1.0);
+ real_t s = Math::sqrt(elements[i][i] - elements[j][j] - elements[k][k] + 1.0);
temp[i] = s * 0.5;
s = 0.5 / s;
- temp[3] = (m.elements[k][j] - m.elements[j][k]) * s;
- temp[j] = (m.elements[j][i] + m.elements[i][j]) * s;
- temp[k] = (m.elements[k][i] + m.elements[i][k]) * s;
+ temp[3] = (elements[k][j] - elements[j][k]) * s;
+ temp[j] = (elements[j][i] + elements[i][j]) * s;
+ temp[k] = (elements[k][i] + elements[i][k]) * s;
}
return Quat(temp[0],temp[1],temp[2],temp[3]);
}
-static const Matrix3 _ortho_bases[24]={
- Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1),
- Matrix3(0, -1, 0, 1, 0, 0, 0, 0, 1),
- Matrix3(-1, 0, 0, 0, -1, 0, 0, 0, 1),
- Matrix3(0, 1, 0, -1, 0, 0, 0, 0, 1),
- Matrix3(1, 0, 0, 0, 0, -1, 0, 1, 0),
- Matrix3(0, 0, 1, 1, 0, 0, 0, 1, 0),
- Matrix3(-1, 0, 0, 0, 0, 1, 0, 1, 0),
- Matrix3(0, 0, -1, -1, 0, 0, 0, 1, 0),
- Matrix3(1, 0, 0, 0, -1, 0, 0, 0, -1),
- Matrix3(0, 1, 0, 1, 0, 0, 0, 0, -1),
- Matrix3(-1, 0, 0, 0, 1, 0, 0, 0, -1),
- Matrix3(0, -1, 0, -1, 0, 0, 0, 0, -1),
- Matrix3(1, 0, 0, 0, 0, 1, 0, -1, 0),
- Matrix3(0, 0, -1, 1, 0, 0, 0, -1, 0),
- Matrix3(-1, 0, 0, 0, 0, -1, 0, -1, 0),
- Matrix3(0, 0, 1, -1, 0, 0, 0, -1, 0),
- Matrix3(0, 0, 1, 0, 1, 0, -1, 0, 0),
- Matrix3(0, -1, 0, 0, 0, 1, -1, 0, 0),
- Matrix3(0, 0, -1, 0, -1, 0, -1, 0, 0),
- Matrix3(0, 1, 0, 0, 0, -1, -1, 0, 0),
- Matrix3(0, 0, 1, 0, -1, 0, 1, 0, 0),
- Matrix3(0, 1, 0, 0, 0, 1, 1, 0, 0),
- Matrix3(0, 0, -1, 0, 1, 0, 1, 0, 0),
- Matrix3(0, -1, 0, 0, 0, -1, 1, 0, 0)
+static const Basis _ortho_bases[24]={
+ Basis(1, 0, 0, 0, 1, 0, 0, 0, 1),
+ Basis(0, -1, 0, 1, 0, 0, 0, 0, 1),
+ Basis(-1, 0, 0, 0, -1, 0, 0, 0, 1),
+ Basis(0, 1, 0, -1, 0, 0, 0, 0, 1),
+ Basis(1, 0, 0, 0, 0, -1, 0, 1, 0),
+ Basis(0, 0, 1, 1, 0, 0, 0, 1, 0),
+ Basis(-1, 0, 0, 0, 0, 1, 0, 1, 0),
+ Basis(0, 0, -1, -1, 0, 0, 0, 1, 0),
+ Basis(1, 0, 0, 0, -1, 0, 0, 0, -1),
+ Basis(0, 1, 0, 1, 0, 0, 0, 0, -1),
+ Basis(-1, 0, 0, 0, 1, 0, 0, 0, -1),
+ Basis(0, -1, 0, -1, 0, 0, 0, 0, -1),
+ Basis(1, 0, 0, 0, 0, 1, 0, -1, 0),
+ Basis(0, 0, -1, 1, 0, 0, 0, -1, 0),
+ Basis(-1, 0, 0, 0, 0, -1, 0, -1, 0),
+ Basis(0, 0, 1, -1, 0, 0, 0, -1, 0),
+ Basis(0, 0, 1, 0, 1, 0, -1, 0, 0),
+ Basis(0, -1, 0, 0, 0, 1, -1, 0, 0),
+ Basis(0, 0, -1, 0, -1, 0, -1, 0, 0),
+ Basis(0, 1, 0, 0, 0, -1, -1, 0, 0),
+ Basis(0, 0, 1, 0, -1, 0, 1, 0, 0),
+ Basis(0, 1, 0, 0, 0, 1, 1, 0, 0),
+ Basis(0, 0, -1, 0, 1, 0, 1, 0, 0),
+ Basis(0, -1, 0, 0, 0, -1, 1, 0, 0)
};
-int Matrix3::get_orthogonal_index() const {
+int Basis::get_orthogonal_index() const {
//could be sped up if i come up with a way
- Matrix3 orth=*this;
+ Basis orth=*this;
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
- float v = orth[i][j];
+ real_t v = orth[i][j];
if (v>0.5)
v=1.0;
else if (v<-0.5)
@@ -344,7 +489,7 @@ int Matrix3::get_orthogonal_index() const {
return 0;
}
-void Matrix3::set_orthogonal_index(int p_index){
+void Basis::set_orthogonal_index(int p_index){
//there only exist 24 orthogonal bases in r3
ERR_FAIL_INDEX(p_index,24);
@@ -355,7 +500,8 @@ void Matrix3::set_orthogonal_index(int p_index){
}
-void Matrix3::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
+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
@@ -423,26 +569,25 @@ void Matrix3::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
// 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])
+(elements[2][0] - elements[0][2])*(elements[2][0] - elements[0][2])
- +(elements[0][1] - elements[1][0])*(elements[0][1] - elements[1][0])); // used to normalise
- if (Math::abs(s) < 0.001) s=1;
- // prevent divide by zero, should not happen if matrix is orthogonal and should be
- // caught by singularity test above, but I've left it in just in case
+ +(elements[0][1] - elements[1][0])*(elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise
+
angle = Math::acos(( elements[0][0] + elements[1][1] + elements[2][2] - 1)/2);
- x = (elements[1][2] - elements[2][1])/s;
- y = (elements[2][0] - elements[0][2])/s;
- z = (elements[0][1] - elements[1][0])/s;
+ if (angle < 0) s = -s;
+ x = (elements[2][1] - elements[1][2])/s;
+ y = (elements[0][2] - elements[2][0])/s;
+ z = (elements[1][0] - elements[0][1])/s;
r_axis=Vector3(x,y,z);
r_angle=angle;
}
-Matrix3::Matrix3(const Vector3& p_euler) {
+Basis::Basis(const Vector3& p_euler) {
set_euler( p_euler );
}
-Matrix3::Matrix3(const Quat& p_quat) {
+Basis::Basis(const Quat& p_quat) {
real_t d = p_quat.length_squared();
real_t s = 2.0 / d;
@@ -456,7 +601,8 @@ Matrix3::Matrix3(const Quat& p_quat) {
}
-Matrix3::Matrix3(const Vector3& p_axis, real_t p_phi) {
+Basis::Basis(const Vector3& p_axis, real_t p_phi) {
+ // Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle
Vector3 axis_sq(p_axis.x*p_axis.x,p_axis.y*p_axis.y,p_axis.z*p_axis.z);
@@ -464,15 +610,15 @@ Matrix3::Matrix3(const Vector3& p_axis, real_t p_phi) {
real_t sine= Math::sin(p_phi);
elements[0][0] = axis_sq.x + cosine * ( 1.0 - axis_sq.x );
- elements[0][1] = p_axis.x * p_axis.y * ( 1.0 - cosine ) + p_axis.z * sine;
- elements[0][2] = p_axis.z * p_axis.x * ( 1.0 - cosine ) - p_axis.y * sine;
+ elements[0][1] = p_axis.x * p_axis.y * ( 1.0 - cosine ) - p_axis.z * sine;
+ elements[0][2] = p_axis.z * p_axis.x * ( 1.0 - cosine ) + p_axis.y * sine;
- elements[1][0] = p_axis.x * p_axis.y * ( 1.0 - cosine ) - p_axis.z * sine;
+ elements[1][0] = p_axis.x * p_axis.y * ( 1.0 - cosine ) + p_axis.z * sine;
elements[1][1] = axis_sq.y + cosine * ( 1.0 - axis_sq.y );
- elements[1][2] = p_axis.y * p_axis.z * ( 1.0 - cosine ) + p_axis.x * sine;
+ elements[1][2] = p_axis.y * p_axis.z * ( 1.0 - cosine ) - p_axis.x * sine;
- elements[2][0] = p_axis.z * p_axis.x * ( 1.0 - cosine ) + p_axis.y * sine;
- elements[2][1] = p_axis.y * p_axis.z * ( 1.0 - cosine ) - p_axis.x * sine;
+ elements[2][0] = p_axis.z * p_axis.x * ( 1.0 - cosine ) - p_axis.y * sine;
+ elements[2][1] = p_axis.y * p_axis.z * ( 1.0 - cosine ) + p_axis.x * sine;
elements[2][2] = axis_sq.z + cosine * ( 1.0 - axis_sq.z );
}
diff --git a/core/math/matrix3.h b/core/math/matrix3.h
index e514f490f7..abce1ee45d 100644
--- a/core/math/matrix3.h
+++ b/core/math/matrix3.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -26,16 +26,18 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
+#include "vector3.h"
+
#ifndef MATRIX3_H
#define MATRIX3_H
-#include "vector3.h"
#include "quat.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-class Matrix3 {
+class Basis {
public:
Vector3 elements[3];
@@ -52,10 +54,10 @@ public:
void invert();
void transpose();
- Matrix3 inverse() const;
- Matrix3 transposed() const;
+ Basis inverse() const;
+ Basis transposed() const;
- _FORCE_INLINE_ float determinant() const;
+ _FORCE_INLINE_ real_t determinant() const;
void from_z(const Vector3& p_z);
@@ -71,10 +73,14 @@ public:
}
void rotate(const Vector3& p_axis, real_t p_phi);
- Matrix3 rotated(const Vector3& p_axis, real_t p_phi) const;
+ Basis rotated(const Vector3& p_axis, real_t p_phi) const;
+
+ void rotate(const Vector3& p_euler);
+ Basis rotated(const Vector3& p_euler) const;
+ Vector3 get_rotation() const;
void scale( const Vector3& p_scale );
- Matrix3 scaled( const Vector3& p_scale ) const;
+ Basis scaled( const Vector3& p_scale ) const;
Vector3 get_scale() const;
Vector3 get_euler() const;
@@ -91,17 +97,28 @@ public:
return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2];
}
- bool operator==(const Matrix3& p_matrix) const;
- bool operator!=(const Matrix3& p_matrix) const;
+ bool isequal_approx(const Basis& a, const Basis& b) const;
+
+ bool operator==(const Basis& p_matrix) const;
+ bool operator!=(const Basis& p_matrix) const;
_FORCE_INLINE_ Vector3 xform(const Vector3& p_vector) const;
_FORCE_INLINE_ Vector3 xform_inv(const Vector3& p_vector) const;
- _FORCE_INLINE_ void operator*=(const Matrix3& p_matrix);
- _FORCE_INLINE_ Matrix3 operator*(const Matrix3& p_matrix) const;
+ _FORCE_INLINE_ void operator*=(const Basis& p_matrix);
+ _FORCE_INLINE_ Basis operator*(const Basis& p_matrix) const;
+ _FORCE_INLINE_ void operator+=(const Basis& p_matrix);
+ _FORCE_INLINE_ Basis operator+(const Basis& p_matrix) const;
+ _FORCE_INLINE_ void operator-=(const Basis& p_matrix);
+ _FORCE_INLINE_ Basis operator-(const Basis& p_matrix) const;
+ _FORCE_INLINE_ void operator*=(real_t p_val);
+ _FORCE_INLINE_ Basis operator*(real_t p_val) const;
int get_orthogonal_index() const;
void set_orthogonal_index(int p_index);
+ bool is_orthogonal() const;
+ bool is_rotation() const;
+
operator String() const;
void get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const;
@@ -130,6 +147,10 @@ public:
return Vector3(elements[i][0],elements[i][1],elements[i][2]);
}
+ _FORCE_INLINE_ Vector3 get_main_diagonal() const {
+ return Vector3(elements[0][0],elements[1][1],elements[2][2]);
+ }
+
_FORCE_INLINE_ void set_row(int i, const Vector3& p_row) {
elements[i][0]=p_row.x;
elements[i][1]=p_row.y;
@@ -142,9 +163,9 @@ public:
elements[2].zero();
}
- _FORCE_INLINE_ Matrix3 transpose_xform(const Matrix3& m) const
+ _FORCE_INLINE_ Basis transpose_xform(const Basis& m) const
{
- return Matrix3(
+ return Basis(
elements[0].x * m[0].x + elements[1].x * m[1].x + elements[2].x * m[2].x,
elements[0].x * m[0].y + elements[1].x * m[1].y + elements[2].x * m[2].y,
elements[0].x * m[0].z + elements[1].x * m[1].z + elements[2].x * m[2].z,
@@ -155,21 +176,31 @@ public:
elements[0].z * m[0].y + elements[1].z * m[1].y + elements[2].z * m[2].y,
elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z);
}
- Matrix3(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
+ Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
set(xx, xy, xz, yx, yy, yz, zx, zy, zz);
}
void orthonormalize();
- Matrix3 orthonormalized() const;
+ Basis orthonormalized() const;
+
+ bool is_symmetric() const;
+ Basis diagonalize();
operator Quat() const;
- Matrix3(const Quat& p_quat); // euler
- Matrix3(const Vector3& p_euler); // euler
- Matrix3(const Vector3& p_axis, real_t p_phi);
+ Basis(const Quat& p_quat); // euler
+ Basis(const Vector3& p_euler); // euler
+ Basis(const Vector3& p_axis, real_t p_phi);
- _FORCE_INLINE_ Matrix3() {
+ _FORCE_INLINE_ Basis(const Vector3& row0, const Vector3& row1, const Vector3& row2)
+ {
+ elements[0]=row0;
+ elements[1]=row1;
+ elements[2]=row2;
+ }
+
+ _FORCE_INLINE_ Basis() {
elements[0][0]=1;
elements[0][1]=0;
@@ -185,7 +216,7 @@ public:
};
-_FORCE_INLINE_ void Matrix3::operator*=(const Matrix3& p_matrix) {
+_FORCE_INLINE_ void Basis::operator*=(const Basis& p_matrix) {
set(
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
@@ -194,16 +225,59 @@ _FORCE_INLINE_ void Matrix3::operator*=(const Matrix3& p_matrix) {
}
-_FORCE_INLINE_ Matrix3 Matrix3::operator*(const Matrix3& p_matrix) const {
+_FORCE_INLINE_ Basis Basis::operator*(const Basis& p_matrix) const {
- return Matrix3(
+ return Basis(
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2]) );
}
-Vector3 Matrix3::xform(const Vector3& p_vector) const {
+
+_FORCE_INLINE_ void Basis::operator+=(const Basis& p_matrix) {
+
+ elements[0] += p_matrix.elements[0];
+ elements[1] += p_matrix.elements[1];
+ elements[2] += p_matrix.elements[2];
+}
+
+_FORCE_INLINE_ Basis Basis::operator+(const Basis& p_matrix) const {
+
+ Basis ret(*this);
+ ret += p_matrix;
+ return ret;
+}
+
+_FORCE_INLINE_ void Basis::operator-=(const Basis& p_matrix) {
+
+ elements[0] -= p_matrix.elements[0];
+ elements[1] -= p_matrix.elements[1];
+ elements[2] -= p_matrix.elements[2];
+}
+
+_FORCE_INLINE_ Basis Basis::operator-(const Basis& p_matrix) const {
+
+ Basis ret(*this);
+ ret -= p_matrix;
+ return ret;
+}
+
+_FORCE_INLINE_ void Basis::operator*=(real_t p_val) {
+
+ elements[0]*=p_val;
+ elements[1]*=p_val;
+ elements[2]*=p_val;
+}
+
+_FORCE_INLINE_ Basis Basis::operator*(real_t p_val) const {
+
+ Basis ret(*this);
+ ret *= p_val;
+ return ret;
+}
+
+Vector3 Basis::xform(const Vector3& p_vector) const {
return Vector3(
elements[0].dot(p_vector),
@@ -212,7 +286,7 @@ Vector3 Matrix3::xform(const Vector3& p_vector) const {
);
}
-Vector3 Matrix3::xform_inv(const Vector3& p_vector) const {
+Vector3 Basis::xform_inv(const Vector3& p_vector) const {
return Vector3(
(elements[0][0]*p_vector.x ) + ( elements[1][0]*p_vector.y ) + ( elements[2][0]*p_vector.z ),
@@ -221,7 +295,7 @@ Vector3 Matrix3::xform_inv(const Vector3& p_vector) const {
);
}
-float Matrix3::determinant() const {
+real_t Basis::determinant() const {
return elements[0][0]*(elements[1][1]*elements[2][2] - elements[2][1]*elements[1][2]) -
elements[1][0]*(elements[0][1]*elements[2][2] - elements[2][1]*elements[0][2]) +
diff --git a/core/math/octree.h b/core/math/octree.h
index 6080b21680..483ba1d510 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -107,7 +107,7 @@ private:
struct Octant {
// cached for FAST plane check
- AABB aabb;
+ Rect3 aabb;
uint64_t last_pass;
Octant *parent;
@@ -130,8 +130,10 @@ private:
~Octant() {
- //for (int i=0;i<8;i++)
- // memdelete_notnull(children[i]);
+ /*
+ for (int i=0;i<8;i++)
+ memdelete_notnull(children[i]);
+ */
}
};
@@ -152,8 +154,8 @@ private:
OctreeElementID _id;
Octant *common_parent;
- AABB aabb;
- AABB container_aabb;
+ Rect3 aabb;
+ Rect3 container_aabb;
List<PairData*,AL> pair_list;
@@ -250,8 +252,10 @@ private:
E->get().eA=p_A->pair_list.push_back(&E->get());
E->get().eB=p_B->pair_list.push_back(&E->get());
-// if (pair_callback)
-// pair_callback(pair_callback_userdata,p_A->userdata,p_B->userdata);
+ /*
+ if (pair_callback)
+ pair_callback(pair_callback_userdata,p_A->userdata,p_B->userdata);
+ */
} else {
E->get().refcount++;
@@ -338,7 +342,7 @@ private:
void _insert_element(Element *p_element,Octant *p_octant);
- void _ensure_valid_root(const AABB& p_aabb);
+ void _ensure_valid_root(const Rect3& p_aabb);
bool _remove_element_from_octant(Element *p_element,Octant *p_octant,Octant *p_limit=NULL);
void _remove_element(Element *p_element);
void _pair_element(Element *p_element,Octant *p_octant);
@@ -356,7 +360,7 @@ private:
};
void _cull_convex(Octant *p_octant,_CullConvexData *p_cull);
- void _cull_AABB(Octant *p_octant,const AABB& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask);
+ void _cull_AABB(Octant *p_octant,const Rect3& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask);
void _cull_segment(Octant *p_octant,const Vector3& p_from, const Vector3& p_to,T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask);
void _cull_point(Octant *p_octant,const Vector3& p_point,T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask);
@@ -375,8 +379,8 @@ private:
}
public:
- OctreeElementID create(T* p_userdata, const AABB& p_aabb=AABB(), int p_subindex=0, bool p_pairable=false,uint32_t p_pairable_type=0,uint32_t pairable_mask=1);
- void move(OctreeElementID p_id, const AABB& p_aabb);
+ OctreeElementID create(T* p_userdata, const Rect3& p_aabb=Rect3(), int p_subindex=0, bool p_pairable=false,uint32_t p_pairable_type=0,uint32_t pairable_mask=1);
+ void move(OctreeElementID p_id, const Rect3& p_aabb);
void set_pairable(OctreeElementID p_id,bool p_pairable=false,uint32_t p_pairable_type=0,uint32_t pairable_mask=1);
void erase(OctreeElementID p_id);
@@ -385,7 +389,7 @@ public:
int get_subindex(OctreeElementID p_id) const;
int cull_convex(const Vector<Plane>& p_convex,T** p_result_array,int p_result_max,uint32_t p_mask=0xFFFFFFFF);
- int cull_AABB(const AABB& p_aabb,T** p_result_array,int p_result_max,int *p_subindex_array=NULL,uint32_t p_mask=0xFFFFFFFF);
+ int cull_AABB(const Rect3& p_aabb,T** p_result_array,int p_result_max,int *p_subindex_array=NULL,uint32_t p_mask=0xFFFFFFFF);
int cull_segment(const Vector3& p_from, const Vector3& p_to,T** p_result_array,int p_result_max,int *p_subindex_array=NULL,uint32_t p_mask=0xFFFFFFFF);
int cull_point(const Vector3& p_point,T** p_result_array,int p_result_max,int *p_subindex_array=NULL,uint32_t p_mask=0xFFFFFFFF);
@@ -487,7 +491,7 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
} else {
/* check againt AABB where child should be */
- AABB aabb=p_octant->aabb;
+ Rect3 aabb=p_octant->aabb;
aabb.size*=0.5;
if (i&1)
@@ -549,12 +553,12 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
template<class T,bool use_pairs,class AL>
-void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) {
+void Octree<T,use_pairs,AL>::_ensure_valid_root(const Rect3& p_aabb) {
if (!root) {
// octre is empty
- AABB base( Vector3(), Vector3(1.0,1.0,1.0) * unit_size);
+ Rect3 base( Vector3(), Vector3(1.0,1.0,1.0) * unit_size);
while ( !base.encloses(p_aabb) ) {
@@ -578,7 +582,7 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) {
} else {
- AABB base=root->aabb;
+ Rect3 base=root->aabb;
while( !base.encloses( p_aabb ) ) {
@@ -814,7 +818,7 @@ void Octree<T,use_pairs,AL>::_remove_element(Element *p_element) {
}
template<class T,bool use_pairs,class AL>
-OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb, int p_subindex,bool p_pairable,uint32_t p_pairable_type,uint32_t p_pairable_mask) {
+OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const Rect3& p_aabb, int p_subindex,bool p_pairable,uint32_t p_pairable_type,uint32_t p_pairable_mask) {
// check for AABB validity
#ifdef DEBUG_ENABLED
@@ -857,7 +861,7 @@ OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb
template<class T,bool use_pairs,class AL>
-void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) {
+void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const Rect3& p_aabb) {
#ifdef DEBUG_ENABLED
// check for AABB validity
@@ -906,7 +910,7 @@ void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) {
if (old_has_surf) {
_remove_element(&e); // removing
e.common_parent=NULL;
- e.aabb=AABB();
+ e.aabb=Rect3();
_optimize();
} else {
_ensure_valid_root(p_aabb); // inserting
@@ -935,7 +939,7 @@ void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) {
return;
}
- AABB combined=e.aabb;
+ Rect3 combined=e.aabb;
combined.merge_with(p_aabb);
_ensure_valid_root(combined);
@@ -970,8 +974,10 @@ void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) {
Octant *o=E->get().octant;
typename List<typename Element::OctantOwner,AL>::Element *N=E->next();
-// if (!use_pairs)
-// o->elements.erase( E->get().E );
+ /*
+ if (!use_pairs)
+ o->elements.erase( E->get().E );
+ */
if (use_pairs && e.pairable)
o->pairable_elements.erase( E->get().E );
@@ -1129,7 +1135,7 @@ void Octree<T,use_pairs,AL>::_cull_convex(Octant *p_octant,_CullConvexData *p_cu
template<class T,bool use_pairs,class AL>
-void Octree<T,use_pairs,AL>::_cull_AABB(Octant *p_octant,const AABB& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask) {
+void Octree<T,use_pairs,AL>::_cull_AABB(Octant *p_octant,const Rect3& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask) {
if (*p_result_idx==p_result_max)
return; //pointless
@@ -1376,7 +1382,7 @@ int Octree<T,use_pairs,AL>::cull_convex(const Vector<Plane>& p_convex,T** p_resu
template<class T,bool use_pairs,class AL>
-int Octree<T,use_pairs,AL>::cull_AABB(const AABB& p_aabb,T** p_result_array,int p_result_max,int *p_subindex_array,uint32_t p_mask) {
+int Octree<T,use_pairs,AL>::cull_AABB(const Rect3& p_aabb,T** p_result_array,int p_result_max,int *p_subindex_array,uint32_t p_mask) {
if (!root)
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index b29350fe3c..2a97932049 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/math/plane.h b/core/math/plane.h
index 81a968682e..f746ea2067 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index 73124e5e8e..055e2b7c35 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -27,22 +27,40 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "quat.h"
+#include "matrix3.h"
#include "print_string.h"
+// set_euler expects a vector containing the Euler angles in the format
+// (c,b,a), where a is the angle of the first rotation, and c is the last.
+// The current implementation uses XYZ convention (Z is the first rotation).
void Quat::set_euler(const Vector3& p_euler) {
- real_t half_yaw = p_euler.x * 0.5;
- real_t half_pitch = p_euler.y * 0.5;
- real_t half_roll = p_euler.z * 0.5;
- real_t cos_yaw = Math::cos(half_yaw);
- real_t sin_yaw = Math::sin(half_yaw);
- real_t cos_pitch = Math::cos(half_pitch);
- real_t sin_pitch = Math::sin(half_pitch);
- real_t cos_roll = Math::cos(half_roll);
- real_t sin_roll = Math::sin(half_roll);
- set(cos_roll * sin_pitch * cos_yaw+sin_roll * cos_pitch * sin_yaw,
- cos_roll * cos_pitch * sin_yaw - sin_roll * sin_pitch * cos_yaw,
- sin_roll * cos_pitch * cos_yaw - cos_roll * sin_pitch * sin_yaw,
- cos_roll * cos_pitch * cos_yaw+sin_roll * sin_pitch * sin_yaw);
+ real_t half_a1 = p_euler.x * 0.5;
+ real_t half_a2 = p_euler.y * 0.5;
+ real_t half_a3 = p_euler.z * 0.5;
+
+ // R = X(a1).Y(a2).Z(a3) convention for Euler angles.
+ // Conversion to quaternion as listed in https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19770024290.pdf (page A-2)
+ // a3 is the angle of the first rotation, following the notation in this reference.
+
+ real_t cos_a1 = Math::cos(half_a1);
+ real_t sin_a1 = Math::sin(half_a1);
+ real_t cos_a2 = Math::cos(half_a2);
+ real_t sin_a2 = Math::sin(half_a2);
+ real_t cos_a3 = Math::cos(half_a3);
+ real_t sin_a3 = Math::sin(half_a3);
+
+ set(sin_a1*cos_a2*cos_a3 + sin_a2*sin_a3*cos_a1,
+ -sin_a1*sin_a3*cos_a2 + sin_a2*cos_a1*cos_a3,
+ sin_a1*sin_a2*cos_a3 + sin_a3*cos_a1*cos_a2,
+ -sin_a1*sin_a2*sin_a3 + cos_a1*cos_a2*cos_a3);
+}
+
+// get_euler returns a vector containing the Euler angles in the format
+// (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last.
+// The current implementation uses XYZ convention (Z is the first rotation).
+Vector3 Quat::get_euler() const {
+ Basis m(*this);
+ return m.get_euler();
}
void Quat::operator*=(const Quat& q) {
@@ -126,26 +144,25 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
}
#else
- real_t to1[4];
+ Quat to1;
real_t omega, cosom, sinom, scale0, scale1;
// calc cosine
- cosom = x * q.x + y * q.y + z * q.z
- + w * q.w;
-
+ cosom = dot(q);
// adjust signs (if necessary)
if ( cosom <0.0 ) {
- cosom = -cosom; to1[0] = - q.x;
- to1[1] = - q.y;
- to1[2] = - q.z;
- to1[3] = - q.w;
+ cosom = -cosom;
+ to1.x = - q.x;
+ to1.y = - q.y;
+ to1.z = - q.z;
+ to1.w = - q.w;
} else {
- to1[0] = q.x;
- to1[1] = q.y;
- to1[2] = q.z;
- to1[3] = q.w;
+ to1.x = q.x;
+ to1.y = q.y;
+ to1.z = q.z;
+ to1.w = q.w;
}
@@ -165,10 +182,10 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
}
// calculate final values
return Quat(
- scale0 * x + scale1 * to1[0],
- scale0 * y + scale1 * to1[1],
- scale0 * z + scale1 * to1[2],
- scale0 * w + scale1 * to1[3]
+ scale0 * x + scale1 * to1.x,
+ scale0 * y + scale1 * to1.y,
+ scale0 * z + scale1 * to1.z,
+ scale0 * w + scale1 * to1.w
);
#endif
}
@@ -186,10 +203,10 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
newFactor = Math::sin(t * theta) * sinT,
invFactor = Math::sin((1.0f - t) * theta) * sinT;
- return Quat( invFactor * from.x + newFactor * q.x,
- invFactor * from.y + newFactor * q.y,
- invFactor * from.z + newFactor * q.z,
- invFactor * from.w + newFactor * q.w );
+ return Quat(invFactor * from.x + newFactor * q.x,
+ invFactor * from.y + newFactor * q.y,
+ invFactor * from.z + newFactor * q.z,
+ invFactor * from.w + newFactor * q.w);
#if 0
real_t to1[4];
@@ -203,7 +220,7 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
// adjust signs (if necessary)
if ( cosom <0.0 && false) {
- cosom = -cosom; to1[0] = - q.x;
+ cosom = -cosom;to1[0] = - q.x;
to1[1] = - q.y;
to1[2] = - q.z;
to1[3] = - q.w;
@@ -260,8 +277,10 @@ Quat::Quat(const Vector3& axis, const real_t& angle) {
if (d==0)
set(0,0,0,0);
else {
- real_t s = Math::sin(-angle * 0.5) / d;
+ real_t sin_angle = Math::sin(angle * 0.5);
+ real_t cos_angle = Math::cos(angle * 0.5);
+ real_t s = sin_angle / d;
set(axis.x * s, axis.y * s, axis.z * s,
- Math::cos(-angle * 0.5));
+ cos_angle);
}
}
diff --git a/core/math/quat.h b/core/math/quat.h
index 0d206bb3b7..43c2cab9e6 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -26,13 +26,15 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
+#include "vector3.h"
+
#ifndef QUAT_H
#define QUAT_H
#include "math_defs.h"
#include "math_funcs.h"
#include "ustring.h"
-#include "vector3.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
@@ -49,15 +51,16 @@ public:
Quat inverse() const;
_FORCE_INLINE_ real_t dot(const Quat& q) const;
void set_euler(const Vector3& p_euler);
+ Vector3 get_euler() const;
Quat slerp(const Quat& q, const real_t& t) const;
Quat slerpni(const Quat& q, const real_t& t) const;
Quat cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const;
_FORCE_INLINE_ void get_axis_and_angle(Vector3& r_axis, real_t &r_angle) const {
r_angle = 2 * Math::acos(w);
- r_axis.x = -x / Math::sqrt(1-w*w);
- r_axis.y = -y / Math::sqrt(1-w*w);
- r_axis.z = -z / Math::sqrt(1-w*w);
+ r_axis.x = x / Math::sqrt(1-w*w);
+ r_axis.y = y / Math::sqrt(1-w*w);
+ r_axis.z = z / Math::sqrt(1-w*w);
}
void operator*=(const Quat& q);
@@ -183,12 +186,10 @@ Quat Quat::operator/(const real_t& s) const {
bool Quat::operator==(const Quat& p_quat) const {
-
return x==p_quat.x && y==p_quat.y && z==p_quat.z && w==p_quat.w;
}
bool Quat::operator!=(const Quat& p_quat) const {
-
return x!=p_quat.x || y!=p_quat.y || z!=p_quat.z || w!=p_quat.w;
}
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index 956824d3d0..756e48d0b4 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -38,7 +38,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
/* CREATE AABB VOLUME */
- AABB aabb;
+ Rect3 aabb;
for(int i=0;i<p_points.size();i++) {
if (i==0) {
@@ -483,7 +483,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
//fill mesh
r_mesh.faces.clear();
r_mesh.faces.resize(ret_faces.size());
-// print_line("FACECOUNT: "+itos(r_mesh.faces.size()));
+ //print_line("FACECOUNT: "+itos(r_mesh.faces.size()));
int idx=0;
for (List<Geometry::MeshData::Face>::Element *E=ret_faces.front();E;E=E->next()) {
diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h
index 8c009b907d..04d25fef18 100644
--- a/core/math/quick_hull.h
+++ b/core/math/quick_hull.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index 22eb6c4fdd..6d9324c176 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -54,7 +54,8 @@ void Transform::invert() {
}
Transform Transform::inverse() const {
-
+ // FIXME: this function assumes the basis is a rotation matrix, with no scaling.
+ // Transform::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
Transform ret=*this;
ret.invert();
return ret;
@@ -63,12 +64,12 @@ Transform Transform::inverse() const {
void Transform::rotate(const Vector3& p_axis,real_t p_phi) {
- *this = *this * Transform( Matrix3( p_axis, p_phi ), Vector3() );
+ *this = rotated(p_axis, p_phi);
}
Transform Transform::rotated(const Vector3& p_axis,real_t p_phi) const{
- return *this * Transform( Matrix3( p_axis, p_phi ), Vector3() );
+ return Transform(Basis( p_axis, p_phi ), Vector3()) * (*this);
}
void Transform::rotate_basis(const Vector3& p_axis,real_t p_phi) {
@@ -113,7 +114,7 @@ void Transform::set_look_at( const Vector3& p_eye, const Vector3& p_target, cons
}
-Transform Transform::interpolate_with(const Transform& p_transform, float p_c) const {
+Transform Transform::interpolate_with(const Transform& p_transform, real_t p_c) const {
/* not sure if very "efficient" but good enough? */
@@ -209,7 +210,7 @@ Transform::operator String() const {
}
-Transform::Transform(const Matrix3& p_basis, const Vector3& p_origin) {
+Transform::Transform(const Basis& p_basis, const Vector3& p_origin) {
basis=p_basis;
origin=p_origin;
diff --git a/core/math/transform.h b/core/math/transform.h
index f948a4c919..d65e87cc6a 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -38,7 +38,7 @@
class Transform {
public:
- Matrix3 basis;
+ Basis basis;
Vector3 origin;
void invert();
@@ -62,8 +62,8 @@ public:
void translate( const Vector3& p_translation );
Transform translated( const Vector3& p_translation ) const;
- const Matrix3& get_basis() const { return basis; }
- void set_basis(const Matrix3& p_basis) { basis=p_basis; }
+ const Basis& get_basis() const { return basis; }
+ void set_basis(const Basis& p_basis) { basis=p_basis; }
const Vector3& get_origin() const { return origin; }
void set_origin(const Vector3& p_origin) { origin=p_origin; }
@@ -80,13 +80,13 @@ public:
_FORCE_INLINE_ Plane xform(const Plane& p_plane) const;
_FORCE_INLINE_ Plane xform_inv(const Plane& p_plane) const;
- _FORCE_INLINE_ AABB xform(const AABB& p_aabb) const;
- _FORCE_INLINE_ AABB xform_inv(const AABB& p_aabb) const;
+ _FORCE_INLINE_ Rect3 xform(const Rect3& p_aabb) const;
+ _FORCE_INLINE_ Rect3 xform_inv(const Rect3& p_aabb) const;
void operator*=(const Transform& p_transform);
Transform operator*(const Transform& p_transform) const;
- Transform interpolate_with(const Transform& p_transform, float p_c) const;
+ Transform interpolate_with(const Transform& p_transform, real_t p_c) const;
_FORCE_INLINE_ Transform inverse_xform(const Transform& t) const {
@@ -113,7 +113,7 @@ public:
operator String() const;
- Transform(const Matrix3& p_basis, const Vector3& p_origin=Vector3());
+ Transform(const Basis& p_basis, const Vector3& p_origin=Vector3());
Transform() {}
};
@@ -168,7 +168,7 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane& p_plane) const {
}
-_FORCE_INLINE_ AABB Transform::xform(const AABB& p_aabb) const {
+_FORCE_INLINE_ Rect3 Transform::xform(const Rect3& p_aabb) const {
/* define vertices */
#if 1
Vector3 x=basis.get_axis(0)*p_aabb.size.x;
@@ -176,7 +176,7 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB& p_aabb) const {
Vector3 z=basis.get_axis(2)*p_aabb.size.z;
Vector3 pos = xform( p_aabb.pos );
//could be even further optimized
- AABB new_aabb;
+ Rect3 new_aabb;
new_aabb.pos=pos;
new_aabb.expand_to( pos+x );
new_aabb.expand_to( pos+y );
@@ -214,7 +214,7 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB& p_aabb) const {
#endif
}
-_FORCE_INLINE_ AABB Transform::xform_inv(const AABB& p_aabb) const {
+_FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3& p_aabb) const {
/* define vertices */
Vector3 vertices[8]={
@@ -229,7 +229,7 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB& p_aabb) const {
};
- AABB ret;
+ Rect3 ret;
ret.pos=xform_inv(vertices[0]);
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index 7aea32a8a0..74c4656771 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -48,7 +48,7 @@ int TriangleMesh::_create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_d
}
- AABB aabb;
+ Rect3 aabb;
aabb=p_bb[p_from]->aabb;
for(int i=1;i<p_size;i++) {
@@ -94,7 +94,7 @@ int TriangleMesh::_create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_d
}
-void TriangleMesh::create(const DVector<Vector3>& p_faces) {
+void TriangleMesh::create(const PoolVector<Vector3>& p_faces) {
valid=false;
@@ -104,7 +104,7 @@ void TriangleMesh::create(const DVector<Vector3>& p_faces) {
triangles.resize(fc);
bvh.resize(fc*3); //will never be larger than this (todo make better)
- DVector<BVH>::Write bw = bvh.write();
+ PoolVector<BVH>::Write bw = bvh.write();
{
@@ -112,8 +112,8 @@ void TriangleMesh::create(const DVector<Vector3>& p_faces) {
//except for the Set for repeated triangles, everything
//goes in-place.
- DVector<Vector3>::Read r = p_faces.read();
- DVector<Triangle>::Write w = triangles.write();
+ PoolVector<Vector3>::Read r = p_faces.read();
+ PoolVector<Triangle>::Write w = triangles.write();
Map<Vector3,int> db;
for(int i=0;i<fc;i++) {
@@ -149,16 +149,16 @@ void TriangleMesh::create(const DVector<Vector3>& p_faces) {
}
vertices.resize(db.size());
- DVector<Vector3>::Write vw = vertices.write();
+ PoolVector<Vector3>::Write vw = vertices.write();
for (Map<Vector3,int>::Element *E=db.front();E;E=E->next()) {
vw[E->get()]=E->key();
}
}
- DVector<BVH*> bwptrs;
+ PoolVector<BVH*> bwptrs;
bwptrs.resize(fc);
- DVector<BVH*>::Write bwp = bwptrs.write();
+ PoolVector<BVH*>::Write bwp = bwptrs.write();
for(int i=0;i<fc;i++) {
bwp[i]=&bw[i];
@@ -168,7 +168,7 @@ void TriangleMesh::create(const DVector<Vector3>& p_faces) {
int max_alloc=fc;
int max=_create_bvh(bw.ptr(),bwp.ptr(),0,fc,1,max_depth,max_alloc);
- bw=DVector<BVH>::Write(); //clearup
+ bw=PoolVector<BVH>::Write(); //clearup
bvh.resize(max_alloc); //resize back
valid=true;
@@ -176,7 +176,7 @@ void TriangleMesh::create(const DVector<Vector3>& p_faces) {
}
-Vector3 TriangleMesh::get_area_normal(const AABB& p_aabb) const {
+Vector3 TriangleMesh::get_area_normal(const Rect3& p_aabb) const {
uint32_t* stack = (uint32_t*)alloca(sizeof(int)*max_depth);
@@ -197,9 +197,9 @@ Vector3 TriangleMesh::get_area_normal(const AABB& p_aabb) const {
int level=0;
- DVector<Triangle>::Read trianglesr = triangles.read();
- DVector<Vector3>::Read verticesr=vertices.read();
- DVector<BVH>::Read bvhr=bvh.read();
+ PoolVector<Triangle>::Read trianglesr = triangles.read();
+ PoolVector<Vector3>::Read verticesr=vertices.read();
+ PoolVector<BVH>::Read bvhr=bvh.read();
const Triangle *triangleptr=trianglesr.ptr();
int pos=bvh.size()-1;
@@ -299,9 +299,9 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end
int level=0;
- DVector<Triangle>::Read trianglesr = triangles.read();
- DVector<Vector3>::Read verticesr=vertices.read();
- DVector<BVH>::Read bvhr=bvh.read();
+ PoolVector<Triangle>::Read trianglesr = triangles.read();
+ PoolVector<Vector3>::Read verticesr=vertices.read();
+ PoolVector<BVH>::Read bvhr=bvh.read();
const Triangle *triangleptr=trianglesr.ptr();
const Vector3 *vertexptr=verticesr.ptr();
@@ -320,7 +320,7 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end
bool valid = b.aabb.intersects_segment(p_begin,p_end);
-// bool valid = b.aabb.intersects(ray_aabb);
+ //bool valid = b.aabb.intersects(ray_aabb);
if (!valid) {
@@ -422,9 +422,9 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec
int level=0;
- DVector<Triangle>::Read trianglesr = triangles.read();
- DVector<Vector3>::Read verticesr=vertices.read();
- DVector<BVH>::Read bvhr=bvh.read();
+ PoolVector<Triangle>::Read trianglesr = triangles.read();
+ PoolVector<Vector3>::Read verticesr=vertices.read();
+ PoolVector<BVH>::Read bvhr=bvh.read();
const Triangle *triangleptr=trianglesr.ptr();
const Vector3 *vertexptr=verticesr.ptr();
@@ -524,18 +524,18 @@ bool TriangleMesh::is_valid() const {
return valid;
}
-DVector<Face3> TriangleMesh::get_faces() const {
+PoolVector<Face3> TriangleMesh::get_faces() const {
if (!valid)
- return DVector<Face3>();
+ return PoolVector<Face3>();
- DVector<Face3> faces;
+ PoolVector<Face3> faces;
int ts = triangles.size();
faces.resize(triangles.size());
- DVector<Face3>::Write w=faces.write();
- DVector<Triangle>::Read r = triangles.read();
- DVector<Vector3>::Read rv = vertices.read();
+ PoolVector<Face3>::Write w=faces.write();
+ PoolVector<Triangle>::Read r = triangles.read();
+ PoolVector<Vector3>::Read rv = vertices.read();
for(int i=0;i<ts;i++) {
for(int j=0;j<3;j++) {
@@ -543,7 +543,7 @@ DVector<Face3> TriangleMesh::get_faces() const {
}
}
- w = DVector<Face3>::Write();
+ w = PoolVector<Face3>::Write();
return faces;
}
diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h
index b5e8f79cde..65250c023d 100644
--- a/core/math/triangle_mesh.h
+++ b/core/math/triangle_mesh.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,7 +33,7 @@
#include "face3.h"
class TriangleMesh : public Reference {
- OBJ_TYPE( TriangleMesh, Reference);
+ GDCLASS( TriangleMesh, Reference);
struct Triangle {
@@ -41,12 +41,12 @@ class TriangleMesh : public Reference {
int indices[3];
};
- DVector<Triangle> triangles;
- DVector<Vector3> vertices;
+ PoolVector<Triangle> triangles;
+ PoolVector<Vector3> vertices;
struct BVH {
- AABB aabb;
+ Rect3 aabb;
Vector3 center; //used for sorting
int left;
int right;
@@ -79,7 +79,7 @@ class TriangleMesh : public Reference {
int _create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_depth,int&max_depth,int&max_alloc);
- DVector<BVH> bvh;
+ PoolVector<BVH> bvh;
int max_depth;
bool valid;
@@ -88,11 +88,11 @@ public:
bool is_valid() const;
bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_point, Vector3 &r_normal) const;
bool intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vector3 &r_point, Vector3 &r_normal) const;
- Vector3 get_area_normal(const AABB& p_aabb) const;
- DVector<Face3> get_faces() const;
+ Vector3 get_area_normal(const Rect3& p_aabb) const;
+ PoolVector<Face3> get_faces() const;
- void create(const DVector<Vector3>& p_faces);
+ void create(const PoolVector<Vector3>& p_faces);
TriangleMesh();
};
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index 1f5d5ed6b3..82b49be7f3 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -71,7 +71,7 @@ bool Triangulate::is_inside_triangle(float Ax, float Ay,
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
};
-bool Triangulate::snip(const Vector<Vector2> &p_contour,int u,int v,int w,int n,int *V)
+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;
@@ -107,8 +107,8 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result
if ( n < 3 ) return false;
-
- int *V = (int*)alloca(sizeof(int)*n);
+ Vector<int> V;
+ V.resize(n);
/* we want a counter-clockwise polygon in V */
@@ -122,7 +122,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result
/* remove nv-2 Vertices, creating 1 triangle every time */
int count = 2*nv; /* error detection */
- for(int m=0, v=nv-1; nv>2; )
+ for(int v=nv-1; nv>2; )
{
/* if we loop, it is probably a non-simple polygon */
if (0 >= (count--))
@@ -144,18 +144,10 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result
a = V[u]; b = V[v]; c = V[w];
/* output Triangle */
- /*
- result.push_back( contour[a] );
- result.push_back( contour[b] );
- result.push_back( contour[c] );
-*/
-
result.push_back( a );
result.push_back( b );
result.push_back( c );
- m++;
-
/* remove v from remaining polygon */
for(s=v,t=v+1;t<nv;s++,t++)
V[s] = V[t];
diff --git a/core/math/triangulate.h b/core/math/triangulate.h
index 7dcc91b2fd..d22677a8b8 100644
--- a/core/math/triangulate.h
+++ b/core/math/triangulate.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -56,7 +56,7 @@ public:
private:
- static bool snip(const Vector<Vector2> &p_contour,int u,int v,int w,int n,int *V);
+ static bool snip(const Vector<Vector2> &p_contour,int u,int v,int w,int n,const Vector<int>& V);
};
diff --git a/core/math/triangulator.cpp b/core/math/triangulator.cpp
index 8f82d76823..75b2b064c4 100644
--- a/core/math/triangulator.cpp
+++ b/core/math/triangulator.cpp
@@ -1128,7 +1128,7 @@ int TriangulatorPartition::MonotonePartition(List<TriangulatorPoly> *inpolys, Li
//this makes deleting existing edges much faster
Set<ScanLineEdge>::Element **edgeTreeIterators,*edgeIter;
edgeTreeIterators = new Set<ScanLineEdge>::Element*[maxnumvertices];
-// Pair<Set<ScanLineEdge>::Element*,bool> edgeTreeRet;
+ //Pair<Set<ScanLineEdge>::Element*,bool> edgeTreeRet;
for(i = 0; i<numvertices; i++) edgeTreeIterators[i] = NULL;
//for each vertex
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index b4a13d8f6d..3eb978333d 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,7 +32,7 @@
void Vector3::rotate(const Vector3& p_axis,float p_phi) {
- *this=Matrix3(p_axis,p_phi).xform(*this);
+ *this=Basis(p_axis,p_phi).xform(*this);
}
Vector3 Vector3::rotated(const Vector3& p_axis,float p_phi) const {
@@ -49,13 +49,13 @@ void Vector3::set_axis(int p_axis,real_t p_value) {
}
real_t Vector3::get_axis(int p_axis) const {
- ERR_FAIL_INDEX_V(p_axis,3,0);
- return operator[](p_axis);
+ ERR_FAIL_INDEX_V(p_axis,3,0);
+ return operator[](p_axis);
}
int Vector3::min_axis() const {
- return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2);
+ return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2);
}
int Vector3::max_axis() const {
@@ -71,9 +71,9 @@ void Vector3::snap(float p_val) {
}
Vector3 Vector3::snapped(float p_val) const {
- Vector3 v=*this;
- v.snap(p_val);
- return v;
+ Vector3 v=*this;
+ v.snap(p_val);
+ return v;
}
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 910446023a..9ae9b69dfa 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,6 +34,7 @@
#include "math_funcs.h"
#include "ustring.h"
+class Basis;
struct Vector3 {
@@ -63,77 +64,80 @@ struct Vector3 {
return coord[p_axis];
}
- void set_axis(int p_axis,real_t p_value);
- real_t get_axis(int p_axis) const;
+ void set_axis(int p_axis,real_t p_value);
+ real_t get_axis(int p_axis) const;
- int min_axis() const;
- int max_axis() const;
+ int min_axis() const;
+ int max_axis() const;
- _FORCE_INLINE_ real_t length() const;
- _FORCE_INLINE_ real_t length_squared() const;
+ _FORCE_INLINE_ real_t length() const;
+ _FORCE_INLINE_ real_t length_squared() const;
- _FORCE_INLINE_ void normalize();
- _FORCE_INLINE_ Vector3 normalized() const;
- _FORCE_INLINE_ Vector3 inverse() const;
+ _FORCE_INLINE_ void normalize();
+ _FORCE_INLINE_ Vector3 normalized() const;
+ _FORCE_INLINE_ Vector3 inverse() const;
_FORCE_INLINE_ void zero();
- void snap(float p_val);
- Vector3 snapped(float p_val) const;
+ void snap(float p_val);
+ Vector3 snapped(float p_val) const;
void rotate(const Vector3& p_axis,float p_phi);
Vector3 rotated(const Vector3& p_axis,float p_phi) const;
- /* Static Methods between 2 vector3s */
+ /* Static Methods between 2 vector3s */
- _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,float p_t) const;
+ _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 cross(const Vector3& p_b) const;
- _FORCE_INLINE_ real_t dot(const Vector3& p_b) const;
+ _FORCE_INLINE_ Vector3 cross(const Vector3& p_b) const;
+ _FORCE_INLINE_ real_t dot(const Vector3& p_b) const;
+ _FORCE_INLINE_ Basis outer(const Vector3& p_b) const;
+ _FORCE_INLINE_ Basis to_diagonal_matrix() const;
- _FORCE_INLINE_ Vector3 abs() const;
- _FORCE_INLINE_ Vector3 floor() const;
- _FORCE_INLINE_ Vector3 ceil() const;
+ _FORCE_INLINE_ Vector3 abs() const;
+ _FORCE_INLINE_ Vector3 floor() const;
+ _FORCE_INLINE_ Vector3 ceil() const;
- _FORCE_INLINE_ real_t distance_to(const Vector3& p_b) const;
- _FORCE_INLINE_ real_t distance_squared_to(const Vector3& p_b) const;
+ _FORCE_INLINE_ real_t distance_to(const Vector3& p_b) const;
+ _FORCE_INLINE_ real_t distance_squared_to(const Vector3& p_b) const;
+ _FORCE_INLINE_ real_t angle_to(const Vector3& p_b) const;
_FORCE_INLINE_ Vector3 slide(const Vector3& p_vec) const;
_FORCE_INLINE_ Vector3 reflect(const Vector3& p_vec) const;
- /* Operators */
+ /* Operators */
- _FORCE_INLINE_ Vector3& operator+=(const Vector3& p_v);
- _FORCE_INLINE_ Vector3 operator+(const Vector3& p_v) const;
- _FORCE_INLINE_ Vector3& operator-=(const Vector3& p_v);
- _FORCE_INLINE_ Vector3 operator-(const Vector3& p_v) const;
- _FORCE_INLINE_ Vector3& operator*=(const Vector3& p_v);
- _FORCE_INLINE_ Vector3 operator*(const Vector3& p_v) const;
- _FORCE_INLINE_ Vector3& operator/=(const Vector3& p_v);
- _FORCE_INLINE_ Vector3 operator/(const Vector3& p_v) const;
+ _FORCE_INLINE_ Vector3& operator+=(const Vector3& p_v);
+ _FORCE_INLINE_ Vector3 operator+(const Vector3& p_v) const;
+ _FORCE_INLINE_ Vector3& operator-=(const Vector3& p_v);
+ _FORCE_INLINE_ Vector3 operator-(const Vector3& p_v) const;
+ _FORCE_INLINE_ Vector3& operator*=(const Vector3& p_v);
+ _FORCE_INLINE_ Vector3 operator*(const Vector3& p_v) const;
+ _FORCE_INLINE_ Vector3& operator/=(const Vector3& p_v);
+ _FORCE_INLINE_ Vector3 operator/(const Vector3& p_v) const;
- _FORCE_INLINE_ Vector3& operator*=(real_t p_scalar);
- _FORCE_INLINE_ Vector3 operator*(real_t p_scalar) const;
- _FORCE_INLINE_ Vector3& operator/=(real_t p_scalar);
- _FORCE_INLINE_ Vector3 operator/(real_t p_scalar) const;
+ _FORCE_INLINE_ Vector3& operator*=(real_t p_scalar);
+ _FORCE_INLINE_ Vector3 operator*(real_t p_scalar) const;
+ _FORCE_INLINE_ Vector3& operator/=(real_t p_scalar);
+ _FORCE_INLINE_ Vector3 operator/(real_t p_scalar) const;
- _FORCE_INLINE_ Vector3 operator-() const;
+ _FORCE_INLINE_ Vector3 operator-() const;
- _FORCE_INLINE_ bool operator==(const Vector3& p_v) const;
- _FORCE_INLINE_ bool operator!=(const Vector3& p_v) const;
- _FORCE_INLINE_ bool operator<(const Vector3& p_v) const;
+ _FORCE_INLINE_ bool operator==(const Vector3& p_v) const;
+ _FORCE_INLINE_ bool operator!=(const Vector3& p_v) const;
+ _FORCE_INLINE_ bool operator<(const Vector3& p_v) const;
_FORCE_INLINE_ bool operator<=(const Vector3& p_v) const;
operator String() const;
- _FORCE_INLINE_ Vector3() { x=y=z=0; }
- _FORCE_INLINE_ Vector3(real_t p_x,real_t p_y,real_t p_z) { x=p_x; y=p_y; z=p_z; }
+ _FORCE_INLINE_ Vector3() { x=y=z=0; }
+ _FORCE_INLINE_ Vector3(real_t p_x,real_t p_y,real_t p_z) { x=p_x; y=p_y; z=p_z; }
};
@@ -143,6 +147,8 @@ struct Vector3 {
#else
+#include "matrix3.h"
+
Vector3 Vector3::cross(const Vector3& p_b) const {
Vector3 ret (
@@ -151,11 +157,27 @@ Vector3 Vector3::cross(const Vector3& p_b) const {
(x * p_b.y) - (y * p_b.x)
);
- return ret;
+ return ret;
}
+
real_t Vector3::dot(const Vector3& p_b) const {
- return x*p_b.x + y*p_b.y + z*p_b.z;
+ return x*p_b.x + y*p_b.y + z*p_b.z;
+}
+
+Basis Vector3::outer(const Vector3& p_b) const {
+
+ Vector3 row0(x*p_b.x, x*p_b.y, x*p_b.z);
+ Vector3 row1(y*p_b.x, y*p_b.y, y*p_b.z);
+ Vector3 row2(z*p_b.x, z*p_b.y, z*p_b.z);
+
+ return Basis(row0, row1, row2);
+}
+
+Basis Vector3::to_diagonal_matrix() const {
+ return Basis(x, 0, 0,
+ 0, y, 0,
+ 0, 0, z);
}
Vector3 Vector3::abs() const {
@@ -180,115 +202,118 @@ Vector3 Vector3::linear_interpolate(const Vector3& p_b,float p_t) const {
y+(p_t * (p_b.y-y)),
z+(p_t * (p_b.z-z))
);
-
}
-
-
real_t Vector3::distance_to(const Vector3& p_b) const {
+
return (p_b-*this).length();
}
+
real_t Vector3::distance_squared_to(const Vector3& p_b) const {
- return (p_b-*this).length_squared();
+ return (p_b-*this).length_squared();
+}
+
+real_t Vector3::angle_to(const Vector3& p_b) const {
+
+ return Math::acos(this->dot(p_b) / Math::sqrt(this->length_squared() * p_b.length_squared()));
}
/* Operators */
Vector3& Vector3::operator+=(const Vector3& p_v) {
- x+=p_v.x;
- y+=p_v.y;
- z+=p_v.z;
- return *this;
+ x+=p_v.x;
+ y+=p_v.y;
+ z+=p_v.z;
+ return *this;
}
+
Vector3 Vector3::operator+(const Vector3& p_v) const {
- return Vector3(x+p_v.x, y+p_v.y, z+ p_v.z);
+ return Vector3(x+p_v.x, y+p_v.y, z+ p_v.z);
}
Vector3& Vector3::operator-=(const Vector3& p_v) {
- x-=p_v.x;
- y-=p_v.y;
- z-=p_v.z;
- return *this;
+ x-=p_v.x;
+ y-=p_v.y;
+ z-=p_v.z;
+ return *this;
}
Vector3 Vector3::operator-(const Vector3& p_v) const {
- return Vector3(x-p_v.x, y-p_v.y, z- p_v.z);
+ return Vector3(x-p_v.x, y-p_v.y, z- p_v.z);
}
-
-
Vector3& Vector3::operator*=(const Vector3& p_v) {
- x*=p_v.x;
- y*=p_v.y;
- z*=p_v.z;
- return *this;
+ x*=p_v.x;
+ y*=p_v.y;
+ z*=p_v.z;
+ return *this;
}
Vector3 Vector3::operator*(const Vector3& p_v) const {
- return Vector3(x*p_v.x, y*p_v.y, z* p_v.z);
+ return Vector3(x*p_v.x, y*p_v.y, z* p_v.z);
}
Vector3& Vector3::operator/=(const Vector3& p_v) {
- x/=p_v.x;
- y/=p_v.y;
- z/=p_v.z;
- return *this;
+ x/=p_v.x;
+ y/=p_v.y;
+ z/=p_v.z;
+ return *this;
}
+
Vector3 Vector3::operator/(const Vector3& p_v) const {
- return Vector3(x/p_v.x, y/p_v.y, z/ p_v.z);
+ return Vector3(x/p_v.x, y/p_v.y, z/ p_v.z);
}
Vector3& Vector3::operator*=(real_t p_scalar) {
- x*=p_scalar;
- y*=p_scalar;
- z*=p_scalar;
- return *this;
+ x*=p_scalar;
+ y*=p_scalar;
+ z*=p_scalar;
+ return *this;
}
_FORCE_INLINE_ Vector3 operator*(real_t p_scalar, const Vector3& p_vec) {
+
return p_vec * p_scalar;
}
Vector3 Vector3::operator*(real_t p_scalar) const {
- return Vector3( x*p_scalar, y*p_scalar, z*p_scalar);
+ return Vector3( x*p_scalar, y*p_scalar, z*p_scalar);
}
Vector3& Vector3::operator/=(real_t p_scalar) {
- x/=p_scalar;
- y/=p_scalar;
- z/=p_scalar;
- return *this;
+ x/=p_scalar;
+ y/=p_scalar;
+ z/=p_scalar;
+ return *this;
}
Vector3 Vector3::operator/(real_t p_scalar) const {
- return Vector3( x/p_scalar, y/p_scalar, z/p_scalar);
+ return Vector3( x/p_scalar, y/p_scalar, z/p_scalar);
}
Vector3 Vector3::operator-() const {
- return Vector3( -x, -y, -z );
+ return Vector3( -x, -y, -z );
}
-
bool Vector3::operator==(const Vector3& p_v) const {
- return (x==p_v.x && y==p_v.y && z==p_v.z);
+ return (x==p_v.x && y==p_v.y && z==p_v.z);
}
bool Vector3::operator!=(const Vector3& p_v) const {
-
- return (x!=p_v.x || y!=p_v.y || z!=p_v.z);
+ return (x!=p_v.x || y!=p_v.y || z!=p_v.z);
}
bool Vector3::operator<(const Vector3& p_v) const {
@@ -298,9 +323,9 @@ bool Vector3::operator<(const Vector3& p_v) const {
return z<p_v.z;
else
return y<p_v.y;
- } else
+ } else {
return x<p_v.x;
-
+ }
}
bool Vector3::operator<=(const Vector3& p_v) const {
@@ -310,9 +335,9 @@ bool Vector3::operator<=(const Vector3& p_v) const {
return z<=p_v.z;
else
return y<p_v.y;
- } else
+ } else {
return x<p_v.x;
-
+ }
}
_FORCE_INLINE_ Vector3 vec3_cross(const Vector3& p_a, const Vector3& p_b) {
@@ -333,6 +358,7 @@ real_t Vector3::length() const {
return Math::sqrt(x2+y2+z2);
}
+
real_t Vector3::length_squared() const {
real_t x2=x*x;
@@ -340,27 +366,25 @@ real_t Vector3::length_squared() const {
real_t z2=z*z;
return x2+y2+z2;
-
}
void Vector3::normalize() {
- real_t l=length();
- if (l==0) {
-
+ real_t l=length();
+ if (l==0) {
x=y=z=0;
- } else {
-
+ } else {
x/=l;
y/=l;
z/=l;
- }
+ }
}
+
Vector3 Vector3::normalized() const {
- Vector3 v=*this;
- v.normalize();
- return v;
+ Vector3 v=*this;
+ v.normalize();
+ return v;
}
Vector3 Vector3::inverse() const {
@@ -377,10 +401,10 @@ Vector3 Vector3::slide(const Vector3& p_vec) const {
return p_vec - *this * this->dot(p_vec);
}
+
Vector3 Vector3::reflect(const Vector3& p_vec) const {
return p_vec - *this * this->dot(p_vec) * 2.0;
-
}
#endif
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index f3daa46c3d..fe46e1671c 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -45,7 +45,7 @@ Error MessageQueue::push_call(ObjectID p_id,const StringName& p_method,const Var
if ((buffer_end+room_needed) >= buffer_size) {
String type;
if (ObjectDB::get_instance(p_id))
- type=ObjectDB::get_instance(p_id)->get_type();
+ type=ObjectDB::get_instance(p_id)->get_class();
print_line("failed method: "+type+":"+p_method+" target ID: "+itos(p_id));
statistics();
@@ -98,7 +98,7 @@ Error MessageQueue::push_set(ObjectID p_id, const StringName& p_prop, const Vari
if ((buffer_end+room_needed) >= buffer_size) {
String type;
if (ObjectDB::get_instance(p_id))
- type=ObjectDB::get_instance(p_id)->get_type();
+ type=ObjectDB::get_instance(p_id)->get_class();
print_line("failed set: "+type+":"+p_prop+" target ID: "+itos(p_id));
statistics();
@@ -133,7 +133,7 @@ Error MessageQueue::push_notification(ObjectID p_id, int p_notification) {
if ((buffer_end+room_needed) >= buffer_size) {
String type;
if (ObjectDB::get_instance(p_id))
- type=ObjectDB::get_instance(p_id)->get_type();
+ type=ObjectDB::get_instance(p_id)->get_class();
print_line("failed notification: "+itos(p_notification)+" target ID: "+itos(p_id));
statistics();
@@ -398,7 +398,7 @@ MessageQueue::MessageQueue() {
buffer_end=0;
buffer_max_used=0;
- buffer_size=GLOBAL_DEF( "core/message_queue_size_kb", DEFAULT_QUEUE_SIZE_KB );
+ buffer_size=GLOBAL_DEF( "memory/buffers/message_queue_max_size_kb", DEFAULT_QUEUE_SIZE_KB );
buffer_size*=1024;
buffer = memnew_arr( uint8_t, buffer_size );
}
diff --git a/core/message_queue.h b/core/message_queue.h
index 6a3ec79732..1b1a20ba9a 100644
--- a/core/message_queue.h
+++ b/core/message_queue.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/method_bind.cpp b/core/method_bind.cpp
index a99d0af636..f323f3bc24 100644
--- a/core/method_bind.cpp
+++ b/core/method_bind.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/method_bind.h b/core/method_bind.h
index 04ff5c22c6..7b59e6a6b0 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -231,7 +231,7 @@ public:
#endif
void set_hint_flags(uint32_t p_hint) { hint_flags=p_hint; }
uint32_t get_hint_flags() const { return hint_flags|(is_const()?METHOD_FLAG_CONST:0)|(is_vararg()?METHOD_FLAG_VARARG:0); }
- virtual String get_instance_type() const=0;
+ virtual String get_instance_class() const=0;
_FORCE_INLINE_ int get_argument_count() const { return argument_count; };
@@ -328,7 +328,7 @@ public:
void set_method(NativeCall p_method) { call_method=p_method; }
virtual bool is_const() const { return false; }
- virtual String get_instance_type() const { return T::get_type_static(); }
+ virtual String get_instance_class() const { return T::get_class_static(); }
virtual bool is_vararg() const { return true; }
diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h
index e38d59fd8f..36b42c84f3 100644
--- a/core/method_ptrcall.h
+++ b/core/method_ptrcall.h
@@ -71,11 +71,11 @@ MAKE_PTRARG(String);
MAKE_PTRARG(Vector2);
MAKE_PTRARG(Rect2);
MAKE_PTRARG(Vector3);
-MAKE_PTRARG(Matrix32);
+MAKE_PTRARG(Transform2D);
MAKE_PTRARG(Plane);
MAKE_PTRARG(Quat);
MAKE_PTRARG(AABB);
-MAKE_PTRARG(Matrix3);
+MAKE_PTRARG(Basis);
MAKE_PTRARG(Transform);
MAKE_PTRARG(Color);
MAKE_PTRARG(Image);
@@ -133,12 +133,12 @@ struct PtrToArg< const T* > {
template<>\
struct PtrToArg<Vector<m_type> > {\
_FORCE_INLINE_ static Vector<m_type> convert(const void* p_ptr) {\
- const DVector<m_type> *dvs = reinterpret_cast<const DVector<m_type> *>(p_ptr);\
+ const PoolVector<m_type> *dvs = reinterpret_cast<const PoolVector<m_type> *>(p_ptr);\
Vector<m_type> ret;\
int len = dvs->size();\
ret.resize(len);\
{\
- DVector<m_type>::Read r=dvs->read();\
+ PoolVector<m_type>::Read r=dvs->read();\
for(int i=0;i<len;i++) {\
ret[i]=r[i];\
}\
@@ -146,11 +146,11 @@ struct PtrToArg<Vector<m_type> > {\
return ret;\
}\
_FORCE_INLINE_ static void encode(Vector<m_type> p_vec, void* p_ptr) {\
- DVector<m_type> *dv = reinterpret_cast<DVector<m_type> *>(p_ptr);\
+ PoolVector<m_type> *dv = reinterpret_cast<PoolVector<m_type> *>(p_ptr);\
int len=p_vec.size();\
dv->resize(len);\
{\
- DVector<m_type>::Write w=dv->write();\
+ PoolVector<m_type>::Write w=dv->write();\
for(int i=0;i<len;i++) {\
w[i]=p_vec[i];\
}\
@@ -160,12 +160,12 @@ struct PtrToArg<Vector<m_type> > {\
template<>\
struct PtrToArg<const Vector<m_type>& > {\
_FORCE_INLINE_ static Vector<m_type> convert(const void* p_ptr) {\
- const DVector<m_type> *dvs = reinterpret_cast<const DVector<m_type> *>(p_ptr);\
+ const PoolVector<m_type> *dvs = reinterpret_cast<const PoolVector<m_type> *>(p_ptr);\
Vector<m_type> ret;\
int len = dvs->size();\
ret.resize(len);\
{\
- DVector<m_type>::Read r=dvs->read();\
+ PoolVector<m_type>::Read r=dvs->read();\
for(int i=0;i<len;i++) {\
ret[i]=r[i];\
}\
@@ -226,26 +226,26 @@ MAKE_VECARR(Plane);
#define MAKE_DVECARR(m_type) \
template<>\
-struct PtrToArg<DVector<m_type> > {\
- _FORCE_INLINE_ static DVector<m_type> convert(const void* p_ptr) {\
+struct PtrToArg<PoolVector<m_type> > {\
+ _FORCE_INLINE_ static PoolVector<m_type> convert(const void* p_ptr) {\
const Array *arr = reinterpret_cast<const Array *>(p_ptr);\
- DVector<m_type> ret;\
+ PoolVector<m_type> ret;\
int len = arr->size();\
ret.resize(len);\
{\
- DVector<m_type>::Write w=ret.write();\
+ PoolVector<m_type>::Write w=ret.write();\
for(int i=0;i<len;i++) {\
w[i]=(*arr)[i];\
}\
}\
return ret;\
}\
- _FORCE_INLINE_ static void encode(DVector<m_type> p_vec, void* p_ptr) {\
+ _FORCE_INLINE_ static void encode(PoolVector<m_type> p_vec, void* p_ptr) {\
Array *arr = reinterpret_cast<Array *>(p_ptr);\
int len = p_vec.size();\
arr->resize(len);\
{\
- DVector<m_type>::Read r=p_vec.read();\
+ PoolVector<m_type>::Read r=p_vec.read();\
for(int i=0;i<len;i++) {\
(*arr)[i]=r[i];\
}\
@@ -253,14 +253,14 @@ struct PtrToArg<DVector<m_type> > {\
} \
};\
template<>\
-struct PtrToArg<const DVector<m_type>& > {\
- _FORCE_INLINE_ static DVector<m_type> convert(const void* p_ptr) {\
+struct PtrToArg<const PoolVector<m_type>& > {\
+ _FORCE_INLINE_ static PoolVector<m_type> convert(const void* p_ptr) {\
const Array *arr = reinterpret_cast<const Array *>(p_ptr);\
- DVector<m_type> ret;\
+ PoolVector<m_type> ret;\
int len = arr->size();\
ret.resize(len);\
{\
- DVector<m_type>::Write w=ret.write();\
+ PoolVector<m_type>::Write w=ret.write();\
for(int i=0;i<len;i++) {\
w[i]=(*arr)[i];\
}\
@@ -297,15 +297,15 @@ MAKE_STRINGCONV(StringName);
MAKE_STRINGCONV(IP_Address);
template<>
-struct PtrToArg<DVector<Face3> > {
- _FORCE_INLINE_ static DVector<Face3> convert(const void* p_ptr) {
- const DVector<Vector3> *dvs = reinterpret_cast<const DVector<Vector3> *>(p_ptr);
- DVector<Face3> ret;
+struct PtrToArg<PoolVector<Face3> > {
+ _FORCE_INLINE_ static PoolVector<Face3> convert(const void* p_ptr) {
+ const PoolVector<Vector3> *dvs = reinterpret_cast<const PoolVector<Vector3> *>(p_ptr);
+ PoolVector<Face3> ret;
int len = dvs->size()/3;
ret.resize(len);
{
- DVector<Vector3>::Read r=dvs->read();
- DVector<Face3>::Write w=ret.write();
+ PoolVector<Vector3>::Read r=dvs->read();
+ PoolVector<Face3>::Write w=ret.write();
for(int i=0;i<len;i++) {
w[i].vertex[0]=r[i*3+0];
w[i].vertex[1]=r[i*3+1];
@@ -314,13 +314,13 @@ struct PtrToArg<DVector<Face3> > {
}
return ret;
}
- _FORCE_INLINE_ static void encode(DVector<Face3> p_vec, void* p_ptr) {\
- DVector<Vector3> *arr = reinterpret_cast<DVector<Vector3> *>(p_ptr);\
+ _FORCE_INLINE_ static void encode(PoolVector<Face3> p_vec, void* p_ptr) {\
+ PoolVector<Vector3> *arr = reinterpret_cast<PoolVector<Vector3> *>(p_ptr);\
int len = p_vec.size();\
arr->resize(len*3);\
{\
- DVector<Face3>::Read r=p_vec.read();\
- DVector<Vector3>::Write w=arr->write();\
+ PoolVector<Face3>::Read r=p_vec.read();\
+ PoolVector<Vector3>::Write w=arr->write();\
for(int i=0;i<len;i++) {\
w[i*3+0]=r[i].vertex[0];\
w[i*3+1]=r[i].vertex[1];\
@@ -330,15 +330,15 @@ struct PtrToArg<DVector<Face3> > {
} \
};
template<>
-struct PtrToArg<const DVector<Face3>& > {
- _FORCE_INLINE_ static DVector<Face3> convert(const void* p_ptr) {
- const DVector<Vector3> *dvs = reinterpret_cast<const DVector<Vector3> *>(p_ptr);
- DVector<Face3> ret;
+struct PtrToArg<const PoolVector<Face3>& > {
+ _FORCE_INLINE_ static PoolVector<Face3> convert(const void* p_ptr) {
+ const PoolVector<Vector3> *dvs = reinterpret_cast<const PoolVector<Vector3> *>(p_ptr);
+ PoolVector<Face3> ret;
int len = dvs->size()/3;
ret.resize(len);
{
- DVector<Vector3>::Read r=dvs->read();
- DVector<Face3>::Write w=ret.write();
+ PoolVector<Vector3>::Read r=dvs->read();
+ PoolVector<Face3>::Write w=ret.write();
for(int i=0;i<len;i++) {
w[i].vertex[0]=r[i*3+0];
w[i].vertex[1]=r[i*3+1];
diff --git a/core/object.cpp b/core/object.cpp
index 8cd4e07097..8af088122e 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -341,15 +341,15 @@ bool Object::_predelete() {
_predelete_ok=1;
notification(NOTIFICATION_PREDELETE,true);
if (_predelete_ok) {
- _type_ptr=NULL; //must restore so destructors can access type ptr correctly
+ _class_ptr=NULL; //must restore so destructors can access class ptr correctly
}
return _predelete_ok;
}
void Object::_postinitialize() {
- _type_ptr=_get_type_namev();
- _initialize_typev();
+ _class_ptr=_get_class_namev();
+ _initialize_classv();
notification(NOTIFICATION_POSTINITIALIZE);
}
@@ -369,11 +369,13 @@ void Object::set(const String& p_name, const Variant& p_value) {
_setv(p_name,p_value);
- //if (!_use_builtin_script())
-// return;
+ /*
+ if (!_use_builtin_script())
+ return;
+ */
bool success;
- ObjectTypeDB::set_property(this,p_name,p_value,success);
+ ClassDB::set_property(this,p_name,p_value,success);
if (success) {
return;
}
@@ -409,9 +411,11 @@ void Object::set(const StringName& p_name, const Variant& p_value, bool *r_valid
//try built-in setgetter
{
- if (ObjectTypeDB::set_property(this,p_name,p_value,r_valid)) {
- //if (r_valid)
- // *r_valid=true;
+ if (ClassDB::set_property(this,p_name,p_value,r_valid)) {
+ /*
+ if (r_valid)
+ *r_valid=true;
+ */
return;
}
}
@@ -460,7 +464,7 @@ Variant Object::get(const StringName& p_name, bool *r_valid) const{
//try built-in setgetter
{
- if (ObjectTypeDB::get_property(const_cast<Object*>(this),p_name,ret)) {
+ if (ClassDB::get_property(const_cast<Object*>(this),p_name,ret)) {
if (r_valid)
*r_valid=true;
return ret;
@@ -504,7 +508,7 @@ Variant Object::get(const String& p_name) const {
return ret;
bool success;
- ObjectTypeDB::get_property(const_cast<Object*>(this),p_name,ret,success);
+ ClassDB::get_property(const_cast<Object*>(this),p_name,ret,success);
if (success) {
return ret;
}
@@ -532,10 +536,8 @@ void Object::get_property_list(List<PropertyInfo> *p_list,bool p_reversed) const
_get_property_listv(p_list,p_reversed);
- if (!_use_builtin_script())
- return;
- if (!is_type("Script")) // can still be set, but this is for userfriendlyness
+ if (!is_class("Script")) // can still be set, but this is for userfriendlyness
p_list->push_back( PropertyInfo( Variant::OBJECT, "script/script", PROPERTY_HINT_RESOURCE_TYPE, "Script",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_STORE_IF_NONZERO));
if (!metadata.empty())
p_list->push_back( PropertyInfo( Variant::DICTIONARY, "__meta__", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_STORE_IF_NONZERO));
@@ -552,7 +554,7 @@ void Object::_validate_property(PropertyInfo& property) const {
void Object::get_method_list(List<MethodInfo> *p_list) const {
- ObjectTypeDB::get_method_list(get_type_name(),p_list);
+ ClassDB::get_method_list(get_class_name(),p_list);
if (script_instance) {
script_instance->get_method_list(p_list);
}
@@ -697,7 +699,7 @@ void Object::call_multilevel(const StringName& p_method,const Variant** p_args,i
}
- MethodBind *method=ObjectTypeDB::get_method(get_type_name(),p_method);
+ MethodBind *method=ClassDB::get_method(get_class_name(),p_method);
if (method) {
@@ -710,7 +712,7 @@ void Object::call_multilevel(const StringName& p_method,const Variant** p_args,i
void Object::call_multilevel_reversed(const StringName& p_method,const Variant** p_args,int p_argcount) {
- MethodBind *method=ObjectTypeDB::get_method(get_type_name(),p_method);
+ MethodBind *method=ClassDB::get_method(get_class_name(),p_method);
Variant::CallError error;
OBJ_DEBUG_LOCK
@@ -744,7 +746,7 @@ bool Object::has_method(const StringName& p_method) const {
return true;
}
- MethodBind *method=ObjectTypeDB::get_method(get_type_name(),p_method);
+ MethodBind *method=ClassDB::get_method(get_class_name(),p_method);
if (method) {
return true;
@@ -821,7 +823,7 @@ Variant Object::call(const StringName& p_name, VARIANT_ARG_DECLARE) {
return ret;
}
- MethodBind *method=ObjectTypeDB::get_method(get_type_name(),p_name);
+ MethodBind *method=ClassDB::get_method(get_type_name(),p_name);
if (method) {
@@ -888,7 +890,7 @@ void Object::call_multilevel(const StringName& p_name, VARIANT_ARG_DECLARE) {
}
- MethodBind *method=ObjectTypeDB::get_method(get_type_name(),p_name);
+ MethodBind *method=ClassDB::get_method(get_type_name(),p_name);
if (method) {
@@ -971,7 +973,7 @@ Variant Object::call(const StringName& p_method,const Variant** p_args,int p_arg
}
}
- MethodBind *method=ObjectTypeDB::get_method(get_type_name(),p_method);
+ MethodBind *method=ClassDB::get_method(get_class_name(),p_method);
if (method) {
@@ -1112,9 +1114,9 @@ Array Object::_get_method_list_bind() const {
}
-DVector<String> Object::_get_meta_list_bind() const {
+PoolVector<String> Object::_get_meta_list_bind() const {
- DVector<String> _metaret;
+ PoolVector<String> _metaret;
List<Variant> keys;
metadata.get_key_list(&keys);
@@ -1138,7 +1140,7 @@ void Object::get_meta_list(List<String> *p_list) const {
void Object::add_user_signal(const MethodInfo& p_signal) {
ERR_FAIL_COND(p_signal.name=="");
- ERR_FAIL_COND( ObjectTypeDB::has_signal(get_type_name(),p_signal.name ) );
+ ERR_FAIL_COND( ClassDB::has_signal(get_class_name(),p_signal.name ) );
ERR_FAIL_COND(signal_map.has(p_signal.name));
Signal s;
s.user=p_signal;
@@ -1215,6 +1217,15 @@ void Object::emit_signal(const StringName& p_name,const Variant** p_args,int p_a
Signal *s = signal_map.getptr(p_name);
if (!s) {
+#ifdef DEBUG_ENABLED
+ bool signal_is_valid = ClassDB::has_signal(get_class_name(),p_name);
+ //check in script
+ if (!signal_is_valid && !script.is_null() && !Ref<Script>(script)->has_script_signal(p_name)) {
+ ERR_EXPLAIN("Can't emit non-existing signal " + String("\"")+p_name+"\".");
+ ERR_FAIL();
+ }
+#endif
+ //not connected? just return
return;
}
@@ -1272,7 +1283,7 @@ void Object::emit_signal(const StringName& p_name,const Variant** p_args,int p_a
target->call( c.method, args, argc,ce );
if (ce.error!=Variant::CallError::CALL_OK) {
- if (ce.error==Variant::CallError::CALL_ERROR_INVALID_METHOD && !ObjectTypeDB::type_exists( target->get_type_name() ) ) {
+ if (ce.error==Variant::CallError::CALL_ERROR_INVALID_METHOD && !ClassDB::class_exists( target->get_class_name() ) ) {
//most likely object is not initialized yet, do not throw error.
} else {
ERR_PRINTS("Error calling method from signal '"+String(p_name)+"': "+Variant::get_call_error_text(target,c.method,args,argc,ce));
@@ -1406,7 +1417,7 @@ void Object::get_signal_list(List<MethodInfo> *p_signals ) const {
Ref<Script>(script)->get_script_signal_list(p_signals);
}
- ObjectTypeDB::get_signal_list(get_type_name(),p_signals);
+ ClassDB::get_signal_list(get_class_name(),p_signals);
//find maybe usersignals?
const StringName *S=NULL;
@@ -1480,13 +1491,13 @@ Error Object::connect(const StringName& p_signal, Object *p_to_object, const Str
Signal *s = signal_map.getptr(p_signal);
if (!s) {
- bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal);
+ bool signal_is_valid = ClassDB::has_signal(get_class_name(),p_signal);
//check in script
if (!signal_is_valid && !script.is_null() && Ref<Script>(script)->has_script_signal(p_signal))
signal_is_valid=true;
if (!signal_is_valid) {
- ERR_EXPLAIN("In Object of type '"+String(get_type())+"': Attempt to connect nonexistent signal '"+p_signal+"' to method '"+p_to_object->get_type()+"."+p_to_method+"'");
+ ERR_EXPLAIN("In Object of type '"+String(get_class())+"': Attempt to connect nonexistent signal '"+p_signal+"' to method '"+p_to_object->get_class()+"."+p_to_method+"'");
ERR_FAIL_COND_V(!signal_is_valid,ERR_INVALID_PARAMETER);
}
signal_map[p_signal]=Signal();
@@ -1520,7 +1531,7 @@ bool Object::is_connected(const StringName& p_signal, Object *p_to_object, const
ERR_FAIL_NULL_V(p_to_object,false);
const Signal *s = signal_map.getptr(p_signal);
if (!s) {
- bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal);
+ bool signal_is_valid = ClassDB::has_signal(get_class_name(),p_signal);
if (signal_is_valid)
return false;
@@ -1562,7 +1573,7 @@ void Object::disconnect(const StringName& p_signal, Object *p_to_object, const S
p_to_object->connections.erase(s->slot_map[target].cE);
s->slot_map.erase(target);
- if (s->slot_map.empty() && ObjectTypeDB::has_signal(get_type_name(),p_signal )) {
+ if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(),p_signal )) {
//not user signal, delete
signal_map.erase(p_signal);
}
@@ -1579,12 +1590,12 @@ Variant Object::_get_bind(const String& p_name) const {
return get(p_name);
}
-void Object::initialize_type() {
+void Object::initialize_class() {
static bool initialized=false;
if (initialized)
return;
- ObjectTypeDB::_add_type<Object>();
+ ClassDB::_add_class<Object>();
_bind_methods();
initialized=true;
}
@@ -1663,31 +1674,31 @@ void Object::clear_internal_resource_paths() {
void Object::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("get_type"),&Object::get_type);
- ObjectTypeDB::bind_method(_MD("is_type","type"),&Object::is_type);
- ObjectTypeDB::bind_method(_MD("set","property","value"),&Object::_set_bind);
- ObjectTypeDB::bind_method(_MD("get","property"),&Object::_get_bind);
- ObjectTypeDB::bind_method(_MD("get_property_list"),&Object::_get_property_list_bind);
- ObjectTypeDB::bind_method(_MD("get_method_list"),&Object::_get_method_list_bind);
- ObjectTypeDB::bind_method(_MD("notification","what","reversed"),&Object::notification,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("get_instance_ID"),&Object::get_instance_ID);
+ ClassDB::bind_method(_MD("get_class"),&Object::get_class);
+ ClassDB::bind_method(_MD("is_class","type"),&Object::is_class);
+ ClassDB::bind_method(_MD("set","property","value"),&Object::_set_bind);
+ ClassDB::bind_method(_MD("get","property"),&Object::_get_bind);
+ ClassDB::bind_method(_MD("get_property_list"),&Object::_get_property_list_bind);
+ ClassDB::bind_method(_MD("get_method_list"),&Object::_get_method_list_bind);
+ ClassDB::bind_method(_MD("notification","what","reversed"),&Object::notification,DEFVAL(false));
+ ClassDB::bind_method(_MD("get_instance_ID"),&Object::get_instance_ID);
- ObjectTypeDB::bind_method(_MD("set_script","script:Script"),&Object::set_script);
- ObjectTypeDB::bind_method(_MD("get_script:Script"),&Object::get_script);
+ ClassDB::bind_method(_MD("set_script","script:Script"),&Object::set_script);
+ ClassDB::bind_method(_MD("get_script:Script"),&Object::get_script);
- ObjectTypeDB::bind_method(_MD("set_meta","name","value"),&Object::set_meta);
- ObjectTypeDB::bind_method(_MD("get_meta","name","value"),&Object::get_meta);
- ObjectTypeDB::bind_method(_MD("has_meta","name"),&Object::has_meta);
- ObjectTypeDB::bind_method(_MD("get_meta_list"),&Object::_get_meta_list_bind);
+ ClassDB::bind_method(_MD("set_meta","name","value"),&Object::set_meta);
+ ClassDB::bind_method(_MD("get_meta","name","value"),&Object::get_meta);
+ ClassDB::bind_method(_MD("has_meta","name"),&Object::has_meta);
+ ClassDB::bind_method(_MD("get_meta_list"),&Object::_get_meta_list_bind);
//todo reimplement this per language so all 5 arguments can be called
-// ObjectTypeDB::bind_method(_MD("call","method","arg1","arg2","arg3","arg4"),&Object::_call_bind,DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()));
-// ObjectTypeDB::bind_method(_MD("call_deferred","method","arg1","arg2","arg3","arg4"),&Object::_call_deferred_bind,DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()));
+ //ClassDB::bind_method(_MD("call","method","arg1","arg2","arg3","arg4"),&Object::_call_bind,DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()));
+ //ClassDB::bind_method(_MD("call_deferred","method","arg1","arg2","arg3","arg4"),&Object::_call_deferred_bind,DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()));
- ObjectTypeDB::bind_method(_MD("add_user_signal","signal","arguments"),&Object::_add_user_signal,DEFVAL(Array()));
- ObjectTypeDB::bind_method(_MD("has_user_signal","signal"),&Object::_has_user_signal);
-// ObjectTypeDB::bind_method(_MD("emit_signal","signal","arguments"),&Object::_emit_signal,DEFVAL(Array()));
+ ClassDB::bind_method(_MD("add_user_signal","signal","arguments"),&Object::_add_user_signal,DEFVAL(Array()));
+ ClassDB::bind_method(_MD("has_user_signal","signal"),&Object::_has_user_signal);
+ //ClassDB::bind_method(_MD("emit_signal","signal","arguments"),&Object::_emit_signal,DEFVAL(Array()));
{
@@ -1695,7 +1706,7 @@ void Object::_bind_methods() {
mi.name="emit_signal";
mi.arguments.push_back( PropertyInfo( Variant::STRING, "signal"));
- ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"emit_signal",&Object::_emit_signal,mi);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"emit_signal",&Object::_emit_signal,mi);
}
{
@@ -1705,7 +1716,7 @@ void Object::_bind_methods() {
- ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call:Variant",&Object::_call_bind,mi);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call:Variant",&Object::_call_bind,mi);
}
{
@@ -1713,32 +1724,32 @@ void Object::_bind_methods() {
mi.name="call_deferred";
mi.arguments.push_back( PropertyInfo( Variant::STRING, "method"));
- ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call_deferred",&Object::_call_deferred_bind,mi);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call_deferred",&Object::_call_deferred_bind,mi);
}
- ObjectTypeDB::bind_method(_MD("callv:Variant","method","arg_array"),&Object::callv);
+ ClassDB::bind_method(_MD("callv:Variant","method","arg_array"),&Object::callv);
- ObjectTypeDB::bind_method(_MD("has_method","method"),&Object::has_method);
+ ClassDB::bind_method(_MD("has_method","method"),&Object::has_method);
- ObjectTypeDB::bind_method(_MD("get_signal_list"),&Object::_get_signal_list);
- ObjectTypeDB::bind_method(_MD("get_signal_connection_list","signal"),&Object::_get_signal_connection_list);
+ ClassDB::bind_method(_MD("get_signal_list"),&Object::_get_signal_list);
+ ClassDB::bind_method(_MD("get_signal_connection_list","signal"),&Object::_get_signal_connection_list);
- ObjectTypeDB::bind_method(_MD("connect","signal","target:Object","method","binds","flags"),&Object::connect,DEFVAL(Array()),DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("disconnect","signal","target:Object","method"),&Object::disconnect);
- ObjectTypeDB::bind_method(_MD("is_connected","signal","target:Object","method"),&Object::is_connected);
+ ClassDB::bind_method(_MD("connect","signal","target:Object","method","binds","flags"),&Object::connect,DEFVAL(Array()),DEFVAL(0));
+ ClassDB::bind_method(_MD("disconnect","signal","target:Object","method"),&Object::disconnect);
+ ClassDB::bind_method(_MD("is_connected","signal","target:Object","method"),&Object::is_connected);
- ObjectTypeDB::bind_method(_MD("set_block_signals","enable"),&Object::set_block_signals);
- ObjectTypeDB::bind_method(_MD("is_blocking_signals"),&Object::is_blocking_signals);
- ObjectTypeDB::bind_method(_MD("set_message_translation","enable"),&Object::set_message_translation);
- ObjectTypeDB::bind_method(_MD("can_translate_messages"),&Object::can_translate_messages);
- ObjectTypeDB::bind_method(_MD("property_list_changed_notify"),&Object::property_list_changed_notify);
+ ClassDB::bind_method(_MD("set_block_signals","enable"),&Object::set_block_signals);
+ ClassDB::bind_method(_MD("is_blocking_signals"),&Object::is_blocking_signals);
+ ClassDB::bind_method(_MD("set_message_translation","enable"),&Object::set_message_translation);
+ ClassDB::bind_method(_MD("can_translate_messages"),&Object::can_translate_messages);
+ ClassDB::bind_method(_MD("property_list_changed_notify"),&Object::property_list_changed_notify);
- ObjectTypeDB::bind_method(_MD("XL_MESSAGE","message"),&Object::XL_MESSAGE);
- ObjectTypeDB::bind_method(_MD("tr","message"),&Object::tr);
+ ClassDB::bind_method(_MD("XL_MESSAGE","message"),&Object::XL_MESSAGE);
+ ClassDB::bind_method(_MD("tr","message"),&Object::tr);
- ObjectTypeDB::bind_method(_MD("is_queued_for_deletion"),&Object::is_queued_for_deletion);
+ ClassDB::bind_method(_MD("is_queued_for_deletion"),&Object::is_queued_for_deletion);
- ObjectTypeDB::add_virtual_method("Object",MethodInfo("free"),false);
+ ClassDB::add_virtual_method("Object",MethodInfo("free"),false);
ADD_SIGNAL( MethodInfo("script_changed"));
@@ -1806,7 +1817,7 @@ void Object::get_translatable_strings(List<String> *p_strings) const {
Variant::Type Object::get_static_property_type(const StringName& p_property, bool *r_valid) const {
bool valid;
- Variant::Type t = ObjectTypeDB::get_property_type(get_type_name(),p_property,&valid);
+ Variant::Type t = ClassDB::get_property_type(get_class_name(),p_property,&valid);
if (valid) {
if (r_valid)
*r_valid=true;
@@ -1848,7 +1859,7 @@ uint32_t Object::get_edited_version() const {
Object::Object() {
- _type_ptr=NULL;
+ _class_ptr=NULL;
_block_signals=false;
_predelete_ok=0;
_instance_ID=0;
@@ -1933,27 +1944,37 @@ uint32_t ObjectDB::instance_counter=1;
HashMap<Object*,ObjectID,ObjectDB::ObjectPtrHash> ObjectDB::instance_checks;
uint32_t ObjectDB::add_instance(Object *p_object) {
- GLOBAL_LOCK_FUNCTION;
+
ERR_FAIL_COND_V( p_object->get_instance_ID()!=0, 0 );
+
+ rw_lock->write_lock();
instances[++instance_counter]=p_object;
#ifdef DEBUG_ENABLED
instance_checks[p_object]=instance_counter;
#endif
+ rw_lock->write_unlock();
+
return instance_counter;
}
void ObjectDB::remove_instance(Object *p_object) {
- GLOBAL_LOCK_FUNCTION;
+
+ rw_lock->write_lock();
+
instances.erase( p_object->get_instance_ID() );
#ifdef DEBUG_ENABLED
instance_checks.erase(p_object);
#endif
+
+ rw_lock->write_unlock();
}
Object *ObjectDB::get_instance(uint32_t p_instance_ID) {
- GLOBAL_LOCK_FUNCTION;
+ rw_lock->read_lock();
Object**obj=instances.getptr(p_instance_ID);
+ rw_lock->read_unlock();
+
if (!obj)
return NULL;
return *obj;
@@ -1961,13 +1982,16 @@ Object *ObjectDB::get_instance(uint32_t p_instance_ID) {
void ObjectDB::debug_objects(DebugFunc p_func) {
- GLOBAL_LOCK_FUNCTION;
+ rw_lock->read_lock();
const uint32_t *K=NULL;
while((K=instances.next(K))) {
p_func(instances[*K]);
}
+
+ rw_lock->read_unlock();
+
}
@@ -1978,15 +2002,26 @@ void Object::get_argument_options(const StringName& p_function,int p_idx,List<St
int ObjectDB::get_object_count() {
- GLOBAL_LOCK_FUNCTION;
- return instances.size();
+ rw_lock->read_lock();
+ int count =instances.size();
+ rw_lock->read_unlock();
+
+ return count;
}
+RWLock *ObjectDB::rw_lock=NULL;
+
+
+void ObjectDB::setup() {
+
+ rw_lock = RWLock::create();
+}
+
void ObjectDB::cleanup() {
- GLOBAL_LOCK_FUNCTION;
+ rw_lock->write_lock();
if (instances.size()) {
WARN_PRINT("ObjectDB Instances still exist!");
@@ -1995,14 +2030,17 @@ void ObjectDB::cleanup() {
while((K=instances.next(K))) {
String node_name;
- if (instances[*K]->is_type("Node"))
+ if (instances[*K]->is_class("Node"))
node_name=" - Node Name: "+String(instances[*K]->call("get_name"));
- if (instances[*K]->is_type("Resoucre"))
+ if (instances[*K]->is_class("Resoucre"))
node_name=" - Resource Name: "+String(instances[*K]->call("get_name"))+" Path: "+String(instances[*K]->call("get_path"));
- print_line("Leaked Instance: "+String(instances[*K]->get_type())+":"+itos(*K)+node_name);
+ print_line("Leaked Instance: "+String(instances[*K]->get_class())+":"+itos(*K)+node_name);
}
}
}
instances.clear();
instance_checks.clear();
+ rw_lock->write_unlock();
+
+ memdelete(rw_lock);
}
diff --git a/core/object.h b/core/object.h
index ac3fc51b3e..6ce579ea99 100644
--- a/core/object.h
+++ b/core/object.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,6 +34,7 @@
#include "set.h"
#include "map.h"
#include "vmap.h"
+#include "os/rw_lock.h"
#define VARIANT_ARG_LIST const Variant& p_arg1=Variant(),const Variant& p_arg2=Variant(),const Variant& p_arg3=Variant(),const Variant& p_arg4=Variant(),const Variant& p_arg5=Variant()
#define VARIANT_ARG_PASS p_arg1,p_arg2,p_arg3,p_arg4,p_arg5
@@ -57,7 +58,10 @@ enum PropertyHint {
PROPERTY_HINT_SPRITE_FRAME,
PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer)
PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags)
- PROPERTY_HINT_ALL_FLAGS,
+ PROPERTY_HINT_LAYERS_2D_RENDER,
+ PROPERTY_HINT_LAYERS_2D_PHYSICS,
+ PROPERTY_HINT_LAYERS_3D_RENDER,
+ PROPERTY_HINT_LAYERS_3D_PHYSICS,
PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
PROPERTY_HINT_DIR, ///< a directort path must be passed
PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
@@ -90,7 +94,7 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_CHECKABLE=16, //used for editing global variables
PROPERTY_USAGE_CHECKED=32, //used for editing global variables
PROPERTY_USAGE_INTERNATIONALIZED=64, //hint for internationalized strings
- PROPERTY_USAGE_BUNDLE=128, //used for optimized bundles
+ PROPERTY_USAGE_GROUP=128, //used for grouping props in the editor
PROPERTY_USAGE_CATEGORY=256,
PROPERTY_USAGE_STORE_IF_NONZERO=512, //only store if nonzero
PROPERTY_USAGE_STORE_IF_NONONE=1024, //only store if false
@@ -108,13 +112,14 @@ enum PropertyUsageFlags {
-#define ADD_SIGNAL( m_signal ) ObjectTypeDB::add_signal( get_type_static(), m_signal )
-#define ADD_PROPERTY( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), m_property, m_setter, m_getter )
-#define ADD_PROPERTYI( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), m_property, m_setter, m_getter, m_index )
-#define ADD_PROPERTYNZ( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter )
-#define ADD_PROPERTYINZ( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter, m_index )
-#define ADD_PROPERTYNO( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter )
-#define ADD_PROPERTYINO( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter, m_index )
+#define ADD_SIGNAL( m_signal ) ClassDB::add_signal( get_class_static(), m_signal )
+#define ADD_PROPERTY( m_property, m_setter, m_getter ) ClassDB::add_property( get_class_static(), m_property, m_setter, m_getter )
+#define ADD_PROPERTYI( m_property, m_setter, m_getter, m_index ) ClassDB::add_property( get_class_static(), m_property, m_setter, m_getter, m_index )
+#define ADD_PROPERTYNZ( m_property, m_setter, m_getter ) ClassDB::add_property( get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter )
+#define ADD_PROPERTYINZ( m_property, m_setter, m_getter, m_index ) ClassDB::add_property( get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter, m_index )
+#define ADD_PROPERTYNO( m_property, m_setter, m_getter ) ClassDB::add_property( get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter )
+#define ADD_PROPERTYINO( m_property, m_setter, m_getter, m_index ) ClassDB::add_property( get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter, m_index )
+#define ADD_GROUP( m_name, m_prefix ) ClassDB::add_property_group( get_class_static(), m_name, m_prefix )
struct PropertyInfo {
@@ -175,7 +180,7 @@ struct MethodInfo {
};
// old cast_to
-//if ( is_type(T::get_type_static()) )
+//if ( is_type(T::get_class_static()) )
//return static_cast<T*>(this);
////else
//return NULL;
@@ -196,33 +201,33 @@ private:
-#define OBJ_TYPE( m_type, m_inherits )\
+#define GDCLASS( m_class, m_inherits )\
private:\
- void operator=(const m_type& p_rval) {}\
- mutable StringName _type_name;\
- friend class ObjectTypeDB;\
+ void operator=(const m_class& p_rval) {}\
+ mutable StringName _class_name;\
+ friend class ClassDB;\
public:\
-virtual String get_type() const { \
- return String(#m_type);\
+virtual String get_class() const { \
+ return String(#m_class);\
}\
-virtual const StringName* _get_type_namev() const { \
- if (!_type_name)\
- _type_name=get_type_static();\
- return &_type_name;\
+virtual const StringName* _get_class_namev() const { \
+ if (!_class_name)\
+ _class_name=get_class_static();\
+ return &_class_name;\
}\
-static _FORCE_INLINE_ void* get_type_ptr_static() { \
+static _FORCE_INLINE_ void* get_class_ptr_static() { \
static int ptr;\
return &ptr;\
}\
-static _FORCE_INLINE_ String get_type_static() { \
- return String(#m_type);\
+static _FORCE_INLINE_ String get_class_static() { \
+ return String(#m_class);\
}\
-static _FORCE_INLINE_ String get_parent_type_static() { \
- return m_inherits::get_type_static();\
+static _FORCE_INLINE_ String get_parent_class_static() { \
+ return m_inherits::get_class_static();\
}\
static void get_inheritance_list_static(List<String>* p_inheritance_list) { \
m_inherits::get_inheritance_list_static(p_inheritance_list);\
- p_inheritance_list->push_back(String(#m_type));\
+ p_inheritance_list->push_back(String(#m_class));\
}\
static String get_category_static() { \
String category = m_inherits::get_category_static();\
@@ -236,85 +241,85 @@ static String get_category_static() { \
static String inherits_static() {\
return String(#m_inherits);\
}\
-virtual bool is_type(const String& p_type) const { return (p_type==(#m_type))?true:m_inherits::is_type(p_type); }\
-virtual bool is_type_ptr(void *p_ptr) const { return (p_ptr==get_type_ptr_static())?true:m_inherits::is_type_ptr(p_ptr); }\
+virtual bool is_class(const String& p_class) const { return (p_class==(#m_class))?true:m_inherits::is_class(p_class); }\
+virtual bool is_class_ptr(void *p_ptr) const { return (p_ptr==get_class_ptr_static())?true:m_inherits::is_class_ptr(p_ptr); }\
\
\
static void get_valid_parents_static(List<String> *p_parents) {\
\
- if (m_type::_get_valid_parents_static!=m_inherits::_get_valid_parents_static) { \
- m_type::_get_valid_parents_static(p_parents);\
+ if (m_class::_get_valid_parents_static!=m_inherits::_get_valid_parents_static) { \
+ m_class::_get_valid_parents_static(p_parents);\
}\
\
m_inherits::get_valid_parents_static(p_parents);\
}\
protected:\
_FORCE_INLINE_ static void (*_get_bind_methods())() {\
- return &m_type::_bind_methods;\
+ return &m_class::_bind_methods;\
}\
public:\
-static void initialize_type() {\
+static void initialize_class() {\
static bool initialized=false;\
if (initialized)\
return;\
- m_inherits::initialize_type();\
- ObjectTypeDB::_add_type<m_type>();\
- if (m_type::_get_bind_methods() != m_inherits::_get_bind_methods())\
+ m_inherits::initialize_class();\
+ ClassDB::_add_class<m_class>();\
+ if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods())\
_bind_methods();\
initialized=true;\
}\
protected:\
-virtual void _initialize_typev() {\
- initialize_type();\
+virtual void _initialize_classv() {\
+ initialize_class();\
}\
_FORCE_INLINE_ bool (Object::* (_get_get() const))(const StringName& p_name,Variant&) const {\
- return (bool (Object::*)(const StringName&,Variant&)const) &m_type::_get;\
+ return (bool (Object::*)(const StringName&,Variant&)const) &m_class::_get;\
}\
virtual bool _getv(const StringName& p_name, Variant& r_ret) const { \
- if (m_type::_get_get() != m_inherits::_get_get()) {\
+ if (m_class::_get_get() != m_inherits::_get_get()) {\
if (_get(p_name,r_ret))\
return true;\
}\
return m_inherits::_getv(p_name,r_ret);\
}\
_FORCE_INLINE_ bool (Object::* (_get_set() const))(const StringName& p_name,const Variant &p_property) {\
- return (bool (Object::*)(const StringName&, const Variant&))&m_type::_set;\
+ return (bool (Object::*)(const StringName&, const Variant&))&m_class::_set;\
}\
virtual bool _setv(const StringName& p_name,const Variant &p_property) { \
if (m_inherits::_setv(p_name,p_property)) return true;\
- if (m_type::_get_set() != m_inherits::_get_set()) {\
+ if (m_class::_get_set() != m_inherits::_get_set()) {\
return _set(p_name,p_property);\
\
}\
return false;\
}\
_FORCE_INLINE_ void (Object::* (_get_get_property_list() const))(List<PropertyInfo> *p_list) const{\
- return (void (Object::*)(List<PropertyInfo>*)const)&m_type::_get_property_list;\
+ return (void (Object::*)(List<PropertyInfo>*)const)&m_class::_get_property_list;\
}\
virtual void _get_property_listv(List<PropertyInfo> *p_list,bool p_reversed) const { \
if (!p_reversed) {\
m_inherits::_get_property_listv(p_list,p_reversed);\
}\
- p_list->push_back( PropertyInfo(Variant::NIL,get_type_static(),PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_CATEGORY));\
+ p_list->push_back( PropertyInfo(Variant::NIL,get_class_static(),PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_CATEGORY));\
if (!_is_gpl_reversed())\
- ObjectTypeDB::get_property_list(#m_type,p_list,true,this);\
- if (m_type::_get_get_property_list() != m_inherits::_get_get_property_list()) {\
+ ClassDB::get_property_list(#m_class,p_list,true,this);\
+ if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) {\
_get_property_list(p_list);\
}\
if (_is_gpl_reversed())\
- ObjectTypeDB::get_property_list(#m_type,p_list,true,this);\
+ ClassDB::get_property_list(#m_class,p_list,true,this);\
if (p_reversed) {\
m_inherits::_get_property_listv(p_list,p_reversed);\
}\
\
}\
_FORCE_INLINE_ void (Object::* (_get_notification() const))(int){\
- return (void (Object::*)(int)) &m_type::_notification;\
+ return (void (Object::*)(int)) &m_class::_notification;\
}\
virtual void _notificationv(int p_notification,bool p_reversed) { \
if (!p_reversed) \
m_inherits::_notificationv(p_notification,p_reversed);\
- if (m_type::_get_notification() != m_inherits::_get_notification()) {\
+ if (m_class::_get_notification() != m_inherits::_get_notification()) {\
_notification(p_notification);\
}\
if (p_reversed)\
@@ -329,9 +334,9 @@ protected:\
_FORCE_INLINE_ static String _get_category() { return m_category; }\
private:
-#define OBJ_SAVE_TYPE(m_type) \
+#define OBJ_SAVE_TYPE(m_class) \
public: \
-virtual String get_save_type() const { return #m_type; }\
+virtual String get_save_class() const { return #m_class; }\
private:
class ScriptInstance;
@@ -415,8 +420,8 @@ friend void postinitialize_handler(Object*);
ScriptInstance *script_instance;
RefPtr script;
Dictionary metadata;
- mutable StringName _type_name;
- mutable const StringName* _type_ptr;
+ mutable StringName _class_name;
+ mutable const StringName* _class_ptr;
void _add_user_signal(const String& p_name, const Array& p_pargs=Array());
bool _has_user_signal(const StringName& p_name) const;
@@ -430,8 +435,8 @@ friend void postinitialize_handler(Object*);
protected:
- virtual bool _use_builtin_script() const { return false; }
- virtual void _initialize_typev() { initialize_type(); }
+
+ virtual void _initialize_classv() { initialize_class(); }
virtual bool _setv(const StringName& p_name,const Variant &p_property) { return false; };
virtual bool _getv(const StringName& p_name,Variant &r_property) const { return false; };
virtual void _get_property_listv(List<PropertyInfo> *p_list,bool p_reversed) const {};
@@ -474,23 +479,23 @@ protected:
Variant _call_deferred_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
- virtual const StringName* _get_type_namev() const {
- if (!_type_name)
- _type_name=get_type_static();
- return &_type_name;
+ virtual const StringName* _get_class_namev() const {
+ if (!_class_name)
+ _class_name=get_class_static();
+ return &_class_name;
}
- DVector<String> _get_meta_list_bind() const;
+ PoolVector<String> _get_meta_list_bind() const;
Array _get_property_list_bind() const;
Array _get_method_list_bind() const;
void _clear_internal_resource_paths(const Variant &p_var);
-friend class ObjectTypeDB;
+friend class ClassDB;
virtual void _validate_property(PropertyInfo& property) const;
public: //should be protected, but bug in clang++
- static void initialize_type();
+ static void initialize_class();
_FORCE_INLINE_ static void register_custom_data_to_otdb() {};
public:
@@ -500,7 +505,7 @@ public:
#else
_FORCE_INLINE_ void _change_notify(const char *p_what="") { }
#endif
- static void* get_type_ptr_static() {
+ static void* get_class_ptr_static() {
static int ptr;
return &ptr;
}
@@ -521,7 +526,7 @@ public:
#else
if (!this)
return NULL;
- if (is_type_ptr(T::get_type_ptr_static()))
+ if (is_class_ptr(T::get_class_ptr_static()))
return static_cast<T*>(this);
else
return NULL;
@@ -536,7 +541,7 @@ public:
#else
if (!this)
return NULL;
- if (is_type_ptr(T::get_type_ptr_static()))
+ if (is_class_ptr(T::get_class_ptr_static()))
return static_cast<const T*>(this);
else
return NULL;
@@ -552,30 +557,30 @@ public:
/* TYPE API */
static void get_inheritance_list_static(List<String>* p_inheritance_list) { p_inheritance_list->push_back("Object"); }
- static String get_type_static() { return "Object"; }
- static String get_parent_type_static() { return String(); }
+ static String get_class_static() { return "Object"; }
+ static String get_parent_class_static() { return String(); }
static String get_category_static() { return String(); }
- virtual String get_type() const { return "Object"; }
- virtual String get_save_type() const { return get_type(); } //type stored when saving
+ virtual String get_class() const { return "Object"; }
+ virtual String get_save_class() const { return get_class(); } //class stored when saving
- virtual bool is_type(const String& p_type) const { return (p_type=="Object"); }
- virtual bool is_type_ptr(void *p_ptr) const { return get_type_ptr_static()==p_ptr; }
+ virtual bool is_class(const String& p_class) const { return (p_class=="Object"); }
+ virtual bool is_class_ptr(void *p_ptr) const { return get_class_ptr_static()==p_ptr; }
- _FORCE_INLINE_ const StringName& get_type_name() const {
- if (!_type_ptr) {
- return *_get_type_namev();
+ _FORCE_INLINE_ const StringName& get_class_name() const {
+ if (!_class_ptr) {
+ return *_get_class_namev();
} else {
- return *_type_ptr;
+ return *_class_ptr;
}
}
/* IAPI */
-// void set(const String& p_name, const Variant& p_value);
-// Variant get(const String& p_name) const;
+ //void set(const String& p_name, const Variant& p_value);
+ //Variant get(const String& p_name) const;
void set(const StringName& p_name, const Variant& p_value, bool *r_valid=NULL);
Variant get(const StringName& p_name, bool *r_valid=NULL) const;
@@ -685,9 +690,14 @@ class ObjectDB {
friend class Object;
friend void unregister_core_types();
+
+ static RWLock *rw_lock;
static void cleanup();
static uint32_t add_instance(Object *p_object);
static void remove_instance(Object *p_object);
+friend void register_core_types();
+ static void setup();
+
public:
typedef void (*DebugFunc)(Object *p_obj);
diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp
index e121dc9e98..24b9c26e71 100644
--- a/core/object_type_db.cpp
+++ b/core/object_type_db.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,11 +31,12 @@
#ifdef NO_THREADS
-#define OBJTYPE_LOCK
+#define OBJTYPE_RLOCK
#else
-#define OBJTYPE_LOCK MutexLock _mutex_lock_(lock);
+#define OBJTYPE_RLOCK RWLockRead _rw_lockr_(lock);
+#define OBJTYPE_WLOCK RWLockWrite _rw_lockw_(lock);
#endif
@@ -190,93 +191,106 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
#endif
-ObjectTypeDB::APIType ObjectTypeDB::current_api=API_CORE;
+ClassDB::APIType ClassDB::current_api=API_CORE;
-void ObjectTypeDB::set_current_api(APIType p_api) {
+void ClassDB::set_current_api(APIType p_api) {
current_api=p_api;
}
-HashMap<StringName,ObjectTypeDB::TypeInfo,StringNameHasher> ObjectTypeDB::types;
-HashMap<StringName,StringName,StringNameHasher> ObjectTypeDB::resource_base_extensions;
-HashMap<StringName,StringName,StringNameHasher> ObjectTypeDB::compat_types;
+HashMap<StringName,ClassDB::ClassInfo,StringNameHasher> ClassDB::classes;
+HashMap<StringName,StringName,StringNameHasher> ClassDB::resource_base_extensions;
+HashMap<StringName,StringName,StringNameHasher> ClassDB::compat_classes;
-ObjectTypeDB::TypeInfo::TypeInfo() {
+ClassDB::ClassInfo::ClassInfo() {
creation_func=NULL;
inherits_ptr=NULL;
disabled=false;
}
-ObjectTypeDB::TypeInfo::~TypeInfo() {
+ClassDB::ClassInfo::~ClassInfo() {
}
-bool ObjectTypeDB::is_type(const StringName &p_type,const StringName& p_inherits) {
+bool ClassDB::is_parent_class(const StringName &p_class,const StringName& p_inherits) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
- StringName inherits=p_type;
+ StringName inherits=p_class;
while (inherits.operator String().length()) {
if (inherits==p_inherits)
return true;
- inherits=type_inherits_from(inherits);
+ inherits=get_parent_class(inherits);
}
return false;
}
-void ObjectTypeDB::get_type_list( List<StringName> *p_types) {
+void ClassDB::get_class_list( List<StringName> *p_classes) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
const StringName *k=NULL;
- while((k=types.next(k))) {
+ while((k=classes.next(k))) {
- p_types->push_back(*k);
+ p_classes->push_back(*k);
}
- p_types->sort();
+ p_classes->sort();
}
-void ObjectTypeDB::get_inheriters_from( const StringName& p_type,List<StringName> *p_types) {
+void ClassDB::get_inheriters_from_class( const StringName& p_class,List<StringName> *p_classes) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
const StringName *k=NULL;
- while((k=types.next(k))) {
+ while((k=classes.next(k))) {
- if (*k!=p_type && is_type(*k,p_type))
- p_types->push_back(*k);
+ if (*k!=p_class && is_parent_class(*k,p_class))
+ p_classes->push_back(*k);
}
}
-StringName ObjectTypeDB::type_inherits_from(const StringName& p_type) {
+StringName ClassDB::get_parent_class_nocheck(const StringName& p_class) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
- TypeInfo *ti = types.getptr(p_type);
- ERR_FAIL_COND_V(!ti,"");
+ ClassInfo *ti = classes.getptr(p_class);
+ if (!ti)
+ return StringName();
+ return ti->inherits;
+
+}
+
+StringName ClassDB::get_parent_class(const StringName& p_class) {
+
+ OBJTYPE_RLOCK;
+
+ ClassInfo *ti = classes.getptr(p_class);
+ ERR_FAIL_COND_V(!ti,StringName());
return ti->inherits;
}
-ObjectTypeDB::APIType ObjectTypeDB::get_api_type(const StringName &p_type) {
+ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
+
+ ClassInfo *ti = classes.getptr(p_class);
- TypeInfo *ti = types.getptr(p_type);
ERR_FAIL_COND_V(!ti,API_NONE);
return ti->api;
}
-uint64_t ObjectTypeDB::get_api_hash(APIType p_api) {
+uint64_t ClassDB::get_api_hash(APIType p_api) {
+ OBJTYPE_RLOCK;
#ifdef DEBUG_METHODS_ENABLED
uint64_t hash = hash_djb2_one_64(HashMapHahserDefault::hash(VERSION_FULL_NAME));
@@ -285,7 +299,7 @@ uint64_t ObjectTypeDB::get_api_hash(APIType p_api) {
const StringName *k=NULL;
- while((k=types.next(k))) {
+ while((k=classes.next(k))) {
names.push_back(*k);
}
@@ -294,7 +308,7 @@ uint64_t ObjectTypeDB::get_api_hash(APIType p_api) {
for (List<StringName>::Element *E=names.front();E;E=E->next()) {
- TypeInfo *t = types.getptr(E->get());
+ ClassInfo *t = classes.getptr(E->get());
ERR_FAIL_COND_V(!t,0);
if (t->api!=p_api)
continue;
@@ -431,26 +445,27 @@ uint64_t ObjectTypeDB::get_api_hash(APIType p_api) {
}
-bool ObjectTypeDB::type_exists(const StringName &p_type) {
+bool ClassDB::class_exists(const StringName &p_class) {
- OBJTYPE_LOCK;
- return types.has(p_type);
+ OBJTYPE_RLOCK;
+ return classes.has(p_class);
}
-void ObjectTypeDB::add_compatibility_type(const StringName& p_type,const StringName& p_fallback) {
+void ClassDB::add_compatibility_class(const StringName& p_class,const StringName& p_fallback) {
- compat_types[p_type]=p_fallback;
+ OBJTYPE_WLOCK;
+ compat_classes[p_class]=p_fallback;
}
-Object *ObjectTypeDB::instance(const StringName &p_type) {
+Object *ClassDB::instance(const StringName &p_class) {
- TypeInfo *ti;
+ ClassInfo *ti;
{
- OBJTYPE_LOCK;
- ti=types.getptr(p_type);
+ OBJTYPE_RLOCK;
+ ti=classes.getptr(p_class);
if (!ti || ti->disabled || !ti->creation_func) {
- if (compat_types.has(p_type)) {
- ti=types.getptr(compat_types[p_type]);
+ if (compat_classes.has(p_class)) {
+ ti=classes.getptr(compat_classes[p_class]);
}
}
ERR_FAIL_COND_V(!ti,NULL);
@@ -460,34 +475,34 @@ Object *ObjectTypeDB::instance(const StringName &p_type) {
return ti->creation_func();
}
-bool ObjectTypeDB::can_instance(const StringName &p_type) {
+bool ClassDB::can_instance(const StringName &p_class) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
- TypeInfo *ti = types.getptr(p_type);
+ ClassInfo *ti = classes.getptr(p_class);
ERR_FAIL_COND_V(!ti,false);
return (!ti->disabled && ti->creation_func!=NULL);
}
-void ObjectTypeDB::_add_type2(const StringName& p_type, const StringName& p_inherits) {
+void ClassDB::_add_class2(const StringName& p_class, const StringName& p_inherits) {
- OBJTYPE_LOCK;
+ OBJTYPE_WLOCK;
- StringName name = p_type;
+ StringName name = p_class;
- ERR_FAIL_COND(types.has(name));
+ ERR_FAIL_COND(classes.has(name));
- types[name]=TypeInfo();
- TypeInfo &ti=types[name];
+ classes[name]=ClassInfo();
+ ClassInfo &ti=classes[name];
ti.name=name;
ti.inherits=p_inherits;
ti.api=current_api;
if (ti.inherits) {
- ERR_FAIL_COND( !types.has(ti.inherits) ); //it MUST be registered.
- ti.inherits_ptr = &types[ti.inherits];
+ ERR_FAIL_COND( !classes.has(ti.inherits) ); //it MUST be registered.
+ ti.inherits_ptr = &classes[ti.inherits];
} else {
ti.inherits_ptr=NULL;
@@ -496,12 +511,12 @@ void ObjectTypeDB::_add_type2(const StringName& p_type, const StringName& p_inhe
}
-void ObjectTypeDB::get_method_list(StringName p_type,List<MethodInfo> *p_methods,bool p_no_inheritance) {
+void ClassDB::get_method_list(StringName p_class,List<MethodInfo> *p_methods,bool p_no_inheritance) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
- TypeInfo *type=types.getptr(p_type);
+ ClassInfo *type=classes.getptr(p_class);
while(type) {
@@ -570,11 +585,11 @@ void ObjectTypeDB::get_method_list(StringName p_type,List<MethodInfo> *p_methods
}
-MethodBind *ObjectTypeDB::get_method(StringName p_type, StringName p_name) {
+MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
- TypeInfo *type=types.getptr(p_type);
+ ClassInfo *type=classes.getptr(p_class);
while(type) {
@@ -587,11 +602,11 @@ MethodBind *ObjectTypeDB::get_method(StringName p_type, StringName p_name) {
}
-void ObjectTypeDB::bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant) {
+void ClassDB::bind_integer_constant(const StringName& p_class, const StringName &p_name, int p_constant) {
- OBJTYPE_LOCK;
+ OBJTYPE_WLOCK;
- TypeInfo *type=types.getptr(p_type);
+ ClassInfo *type=classes.getptr(p_class);
if (!type) {
ERR_FAIL_COND(!type);
@@ -609,11 +624,11 @@ void ObjectTypeDB::bind_integer_constant(const StringName& p_type, const StringN
}
-void ObjectTypeDB::get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance) {
+void ClassDB::get_integer_constant_list(const StringName& p_class, List<String> *p_constants, bool p_no_inheritance) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
- TypeInfo *type=types.getptr(p_type);
+ ClassInfo *type=classes.getptr(p_class);
while(type) {
@@ -637,12 +652,12 @@ void ObjectTypeDB::get_integer_constant_list(const StringName& p_type, List<Stri
}
-int ObjectTypeDB::get_integer_constant(const StringName& p_type, const StringName &p_name, bool *p_success) {
+int ClassDB::get_integer_constant(const StringName& p_class, const StringName &p_name, bool *p_success) {
- OBJTYPE_LOCK;
+ OBJTYPE_RLOCK;
- TypeInfo *type=types.getptr(p_type);
+ ClassInfo *type=classes.getptr(p_class);
while(type) {
@@ -664,18 +679,20 @@ int ObjectTypeDB::get_integer_constant(const StringName& p_type, const StringNam
return 0;
}
-void ObjectTypeDB::add_signal(StringName p_type,const MethodInfo& p_signal) {
+void ClassDB::add_signal(StringName p_class,const MethodInfo& p_signal) {
+
+ OBJTYPE_WLOCK;
- TypeInfo *type=types.getptr(p_type);
+ ClassInfo *type=classes.getptr(p_class);
ERR_FAIL_COND(!type);
- TypeInfo *check=type;
+ ClassInfo *check=type;
StringName sname = p_signal.name;
#ifdef DEBUG_METHODS_ENABLED
while(check) {
if (check->signal_map.has(sname)) {
- ERR_EXPLAIN("Type "+String(p_type)+" already has signal: "+String(sname));
+ ERR_EXPLAIN("Type "+String(p_class)+" already has signal: "+String(sname));
ERR_FAIL();
}
check=check->inherits_ptr;
@@ -686,12 +703,14 @@ void ObjectTypeDB::add_signal(StringName p_type,const MethodInfo& p_signal) {
}
-void ObjectTypeDB::get_signal_list(StringName p_type,List<MethodInfo> *p_signals,bool p_no_inheritance) {
+void ClassDB::get_signal_list(StringName p_class,List<MethodInfo> *p_signals,bool p_no_inheritance) {
+
+ OBJTYPE_RLOCK;
- TypeInfo *type=types.getptr(p_type);
+ ClassInfo *type=classes.getptr(p_class);
ERR_FAIL_COND(!type);
- TypeInfo *check=type;
+ ClassInfo *check=type;
while(check) {
@@ -710,10 +729,11 @@ void ObjectTypeDB::get_signal_list(StringName p_type,List<MethodInfo> *p_signals
}
-bool ObjectTypeDB::has_signal(StringName p_type,StringName p_signal) {
+bool ClassDB::has_signal(StringName p_class,StringName p_signal) {
- TypeInfo *type=types.getptr(p_type);
- TypeInfo *check=type;
+ OBJTYPE_RLOCK;
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
while(check) {
if (check->signal_map.has(p_signal))
return true;
@@ -723,10 +743,11 @@ bool ObjectTypeDB::has_signal(StringName p_type,StringName p_signal) {
return false;
}
-bool ObjectTypeDB::get_signal(StringName p_type,StringName p_signal,MethodInfo *r_signal) {
+bool ClassDB::get_signal(StringName p_class,StringName p_signal,MethodInfo *r_signal) {
- TypeInfo *type=types.getptr(p_type);
- TypeInfo *check=type;
+ OBJTYPE_RLOCK;
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
while(check) {
if (check->signal_map.has(p_signal)) {
if (r_signal) {
@@ -740,23 +761,39 @@ bool ObjectTypeDB::get_signal(StringName p_type,StringName p_signal,MethodInfo *
return false;
}
-void ObjectTypeDB::add_property(StringName p_type,const PropertyInfo& p_pinfo, const StringName& p_setter, const StringName& p_getter, int p_index) {
+void ClassDB::add_property_group(StringName p_class,const String& p_name,const String& p_prefix) {
+
+ OBJTYPE_WLOCK;
+ ClassInfo *type=classes.getptr(p_class);
+ ERR_FAIL_COND(!type);
+
+ type->property_list.push_back(PropertyInfo(Variant::NIL,p_name,PROPERTY_HINT_NONE,p_prefix,PROPERTY_USAGE_GROUP));
+}
+
+void ClassDB::add_property(StringName p_class,const PropertyInfo& p_pinfo, const StringName& p_setter, const StringName& p_getter, int p_index) {
+
+
+
+ lock->read_lock();
+
+ ClassInfo *type=classes.getptr(p_class);
+
+ lock->read_unlock();
- TypeInfo *type=types.getptr(p_type);
ERR_FAIL_COND(!type);
MethodBind *mb_set=NULL;
if (p_setter) {
- mb_set = get_method(p_type,p_setter);
+ mb_set = get_method(p_class,p_setter);
#ifdef DEBUG_METHODS_ENABLED
if (!mb_set) {
- ERR_EXPLAIN("Invalid Setter: "+p_type+"::"+p_setter+" for property: "+p_pinfo.name);
+ ERR_EXPLAIN("Invalid Setter: "+p_class+"::"+p_setter+" for property: "+p_pinfo.name);
ERR_FAIL_COND(!mb_set);
} else {
int exp_args=1+(p_index>=0?1:0);
if (mb_set->get_argument_count()!=exp_args) {
- ERR_EXPLAIN("Invalid Function for Setter: "+p_type+"::"+p_setter+" for property: "+p_pinfo.name);
+ ERR_EXPLAIN("Invalid Function for Setter: "+p_class+"::"+p_setter+" for property: "+p_pinfo.name);
ERR_FAIL();
}
@@ -767,17 +804,17 @@ void ObjectTypeDB::add_property(StringName p_type,const PropertyInfo& p_pinfo, c
MethodBind *mb_get=NULL;
if (p_getter) {
- MethodBind *mb_get = get_method(p_type,p_getter);
+ MethodBind *mb_get = get_method(p_class,p_getter);
#ifdef DEBUG_METHODS_ENABLED
if (!mb_get) {
- ERR_EXPLAIN("Invalid Getter: "+p_type+"::"+p_getter+" for property: "+p_pinfo.name);
+ ERR_EXPLAIN("Invalid Getter: "+p_class+"::"+p_getter+" for property: "+p_pinfo.name);
ERR_FAIL_COND(!mb_get);
} else {
int exp_args=0+(p_index>=0?1:0);
if (mb_get->get_argument_count()!=exp_args) {
- ERR_EXPLAIN("Invalid Function for Getter: "+p_type+"::"+p_getter+" for property: "+p_pinfo.name);
+ ERR_EXPLAIN("Invalid Function for Getter: "+p_class+"::"+p_getter+" for property: "+p_pinfo.name);
ERR_FAIL();
}
@@ -791,10 +828,13 @@ void ObjectTypeDB::add_property(StringName p_type,const PropertyInfo& p_pinfo, c
#ifdef DEBUG_METHODS_ENABLED
if (type->property_setget.has(p_pinfo.name)) {
- ERR_EXPLAIN("Object already has property: "+p_type);
+ ERR_EXPLAIN("Object already has property: "+p_class);
ERR_FAIL();
}
#endif
+
+ OBJTYPE_WLOCK
+
type->property_list.push_back(p_pinfo);
PropertySetGet psg;
@@ -810,10 +850,12 @@ void ObjectTypeDB::add_property(StringName p_type,const PropertyInfo& p_pinfo, c
}
-void ObjectTypeDB::get_property_list(StringName p_type, List<PropertyInfo> *p_list, bool p_no_inheritance,const Object *p_validator) {
+void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance,const Object *p_validator) {
- TypeInfo *type=types.getptr(p_type);
- TypeInfo *check=type;
+ OBJTYPE_RLOCK;
+
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
while(check) {
for(List<PropertyInfo>::Element *E=check->property_list.front();E;E=E->next()) {
@@ -834,11 +876,12 @@ void ObjectTypeDB::get_property_list(StringName p_type, List<PropertyInfo> *p_li
}
}
-bool ObjectTypeDB::set_property(Object* p_object,const StringName& p_property, const Variant& p_value,bool *r_valid) {
+bool ClassDB::set_property(Object* p_object,const StringName& p_property, const Variant& p_value,bool *r_valid) {
+
- TypeInfo *type=types.getptr(p_object->get_type_name());
- TypeInfo *check=type;
+ ClassInfo *type=classes.getptr(p_object->get_class_name());
+ ClassInfo *check=type;
while(check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
@@ -854,7 +897,7 @@ bool ObjectTypeDB::set_property(Object* p_object,const StringName& p_property, c
if (psg->index>=0) {
Variant index=psg->index;
const Variant* arg[2]={&index,&p_value};
-// p_object->call(psg->setter,arg,2,ce);
+ //p_object->call(psg->setter,arg,2,ce);
if (psg->_setptr) {
psg->_setptr->call(p_object,arg,2,ce);
} else {
@@ -882,10 +925,10 @@ bool ObjectTypeDB::set_property(Object* p_object,const StringName& p_property, c
return false;
}
-bool ObjectTypeDB::get_property(Object* p_object,const StringName& p_property, Variant& r_value) {
+bool ClassDB::get_property(Object* p_object,const StringName& p_property, Variant& r_value) {
- TypeInfo *type=types.getptr(p_object->get_type_name());
- TypeInfo *check=type;
+ ClassInfo *type=classes.getptr(p_object->get_class_name());
+ ClassInfo *check=type;
while(check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
@@ -925,10 +968,10 @@ bool ObjectTypeDB::get_property(Object* p_object,const StringName& p_property, V
return false;
}
-Variant::Type ObjectTypeDB::get_property_type(const StringName& p_type, const StringName& p_property,bool *r_is_valid) {
+Variant::Type ClassDB::get_property_type(const StringName& p_class, const StringName& p_property,bool *r_is_valid) {
- TypeInfo *type=types.getptr(p_type);
- TypeInfo *check=type;
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
while(check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
@@ -948,11 +991,62 @@ Variant::Type ObjectTypeDB::get_property_type(const StringName& p_type, const St
}
+StringName ClassDB::get_property_setter(StringName p_class,const StringName p_property) {
+
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
+ while(check) {
+ const PropertySetGet *psg = check->property_setget.getptr(p_property);
+ if (psg) {
+
+ return psg->setter;
+ }
+
+ check=check->inherits_ptr;
+ }
+
+ return StringName();
+}
+
+StringName ClassDB::get_property_getter(StringName p_class,const StringName p_property) {
-void ObjectTypeDB::set_method_flags(StringName p_type,StringName p_method,int p_flags) {
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
+ while(check) {
+ const PropertySetGet *psg = check->property_setget.getptr(p_property);
+ if (psg) {
+
+ return psg->getter;
+ }
- TypeInfo *type=types.getptr(p_type);
- TypeInfo *check=type;
+ check=check->inherits_ptr;
+ }
+
+ return StringName();
+}
+
+bool ClassDB::has_property(const StringName& p_class, const StringName& p_property, bool p_no_inheritance) {
+
+
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
+ while(check) {
+ if (check->property_setget.has(p_property))
+ return true;
+
+ if (p_no_inheritance)
+ break;
+ check=check->inherits_ptr;
+ }
+
+ return false;
+}
+
+void ClassDB::set_method_flags(StringName p_class,StringName p_method,int p_flags) {
+
+ OBJTYPE_WLOCK;
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
ERR_FAIL_COND(!check);
ERR_FAIL_COND(!check->method_map.has(p_method));
check->method_map[p_method]->set_hint_flags(p_flags);
@@ -960,10 +1054,10 @@ void ObjectTypeDB::set_method_flags(StringName p_type,StringName p_method,int p_
}
-bool ObjectTypeDB::has_method(StringName p_type,StringName p_method,bool p_no_inheritance) {
+bool ClassDB::has_method(StringName p_class,StringName p_method,bool p_no_inheritance) {
- TypeInfo *type=types.getptr(p_type);
- TypeInfo *check=type;
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
while(check) {
if (check->method_map.has(p_method))
return true;
@@ -976,10 +1070,10 @@ bool ObjectTypeDB::has_method(StringName p_type,StringName p_method,bool p_no_in
}
-bool ObjectTypeDB::get_setter_and_type_for_property(const StringName& p_class, const StringName& p_prop, StringName& r_class, StringName& r_setter) {
+bool ClassDB::get_setter_and_type_for_property(const StringName& p_class, const StringName& p_prop, StringName& r_class, StringName& r_setter) {
- TypeInfo *type=types.getptr(p_class);
- TypeInfo *check=type;
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
while(check) {
if (check->property_setget.has(p_prop)) {
@@ -996,10 +1090,10 @@ bool ObjectTypeDB::get_setter_and_type_for_property(const StringName& p_class, c
}
#ifdef DEBUG_METHODS_ENABLED
-MethodBind* ObjectTypeDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const MethodDefinition &method_name, const Variant **p_defs, int p_defcount) {
+MethodBind* ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const MethodDefinition &method_name, const Variant **p_defs, int p_defcount) {
StringName mdname=method_name.name;
#else
-MethodBind* ObjectTypeDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const char *method_name, const Variant **p_defs, int p_defcount) {
+MethodBind* ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const char *method_name, const Variant **p_defs, int p_defcount) {
StringName mdname=StaticCString::create(method_name);
#endif
@@ -1011,13 +1105,22 @@ MethodBind* ObjectTypeDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , c
}
- OBJTYPE_LOCK;
+ OBJTYPE_WLOCK;
ERR_FAIL_COND_V(!p_bind,NULL);
p_bind->set_name(mdname);
- String instance_type=p_bind->get_instance_type();
+ String instance_type=p_bind->get_instance_class();
- TypeInfo *type=types.getptr(instance_type);
+#ifdef DEBUG_ENABLED
+
+ if (has_method(instance_type,mdname)) {
+ ERR_EXPLAIN("Class "+String(instance_type)+" already has a method "+String(mdname));
+ ERR_FAIL_V(NULL);
+ }
+#endif
+
+
+ ClassInfo *type=classes.getptr(instance_type);
if (!type) {
ERR_PRINTS("Couldn't bind method '"+mdname+"' for instance: "+instance_type);
memdelete(p_bind);
@@ -1052,27 +1155,29 @@ MethodBind* ObjectTypeDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , c
}
-void ObjectTypeDB::add_virtual_method(const StringName& p_type, const MethodInfo& p_method , bool p_virtual) {
- ERR_FAIL_COND(!types.has(p_type));
+void ClassDB::add_virtual_method(const StringName& p_class, const MethodInfo& p_method , bool p_virtual) {
+ ERR_FAIL_COND(!classes.has(p_class));
+
+ OBJTYPE_WLOCK;
#ifdef DEBUG_METHODS_ENABLED
MethodInfo mi=p_method;
if (p_virtual)
mi.flags|=METHOD_FLAG_VIRTUAL;
- types[p_type].virtual_methods.push_back(mi);
+ classes[p_class].virtual_methods.push_back(mi);
#endif
}
-void ObjectTypeDB::get_virtual_methods(const StringName& p_type, List<MethodInfo> * p_methods , bool p_no_inheritance) {
+void ClassDB::get_virtual_methods(const StringName& p_class, List<MethodInfo> * p_methods , bool p_no_inheritance) {
- ERR_FAIL_COND(!types.has(p_type));
+ ERR_FAIL_COND(!classes.has(p_class));
#ifdef DEBUG_METHODS_ENABLED
- TypeInfo *type=types.getptr(p_type);
- TypeInfo *check=type;
+ ClassInfo *type=classes.getptr(p_class);
+ ClassInfo *check=type;
while(check) {
for(List<MethodInfo>::Element *E=check->virtual_methods.front();E;E=E->next()) {
@@ -1088,18 +1193,22 @@ void ObjectTypeDB::get_virtual_methods(const StringName& p_type, List<MethodInfo
}
-void ObjectTypeDB::set_type_enabled(StringName p_type,bool p_enable) {
+void ClassDB::set_class_enabled(StringName p_class,bool p_enable) {
- ERR_FAIL_COND(!types.has(p_type));
- types[p_type].disabled=!p_enable;
+ OBJTYPE_WLOCK;
+
+ ERR_FAIL_COND(!classes.has(p_class));
+ classes[p_class].disabled=!p_enable;
}
-bool ObjectTypeDB::is_type_enabled(StringName p_type) {
+bool ClassDB::is_class_enabled(StringName p_class) {
+
+ OBJTYPE_RLOCK;
- TypeInfo *ti=types.getptr(p_type);
+ ClassInfo *ti=classes.getptr(p_class);
if (!ti || !ti->creation_func) {
- if (compat_types.has(p_type)) {
- ti=types.getptr(compat_types[p_type]);
+ if (compat_classes.has(p_class)) {
+ ti=classes.getptr(compat_classes[p_class]);
}
}
@@ -1107,25 +1216,25 @@ bool ObjectTypeDB::is_type_enabled(StringName p_type) {
return !ti->disabled;
}
-StringName ObjectTypeDB::get_category(const StringName& p_node) {
+StringName ClassDB::get_category(const StringName& p_node) {
- ERR_FAIL_COND_V(!types.has(p_node),StringName());
+ ERR_FAIL_COND_V(!classes.has(p_node),StringName());
#ifdef DEBUG_ENABLED
- return types[p_node].category;
+ return classes[p_node].category;
#else
return StringName();
#endif
}
-void ObjectTypeDB::add_resource_base_extension(const StringName& p_extension,const StringName& p_type) {
+void ClassDB::add_resource_base_extension(const StringName& p_extension,const StringName& p_class) {
if (resource_base_extensions.has(p_extension))
return;
- resource_base_extensions[p_extension]=p_type;
+ resource_base_extensions[p_extension]=p_class;
}
-void ObjectTypeDB::get_resource_base_extensions(List<String> *p_extensions) {
+void ClassDB::get_resource_base_extensions(List<String> *p_extensions) {
const StringName *K=NULL;
@@ -1135,43 +1244,39 @@ void ObjectTypeDB::get_resource_base_extensions(List<String> *p_extensions) {
}
}
-void ObjectTypeDB::get_extensions_for_type(const StringName& p_type,List<String> *p_extensions) {
+void ClassDB::get_extensions_for_type(const StringName& p_class,List<String> *p_extensions) {
const StringName *K=NULL;
while((K=resource_base_extensions.next(K))) {
StringName cmp = resource_base_extensions[*K];
- if (is_type(cmp,p_type))
+ if (is_parent_class(cmp,p_class))
p_extensions->push_back(*K);
}
}
-Mutex *ObjectTypeDB::lock=NULL;
+RWLock *ClassDB::lock=NULL;
-void ObjectTypeDB::init() {
+void ClassDB::init() {
#ifndef NO_THREADS
- lock = Mutex::create();
+ lock = RWLock::create();
#endif
}
-void ObjectTypeDB::cleanup() {
+void ClassDB::cleanup() {
-#ifndef NO_THREADS
-
- memdelete(lock);
-#endif
//OBJTYPE_LOCK; hah not here
const StringName *k=NULL;
- while((k=types.next(k))) {
+ while((k=classes.next(k))) {
- TypeInfo &ti=types[*k];
+ ClassInfo &ti=classes[*k];
const StringName *m=NULL;
while((m=ti.method_map.next(m))) {
@@ -1179,9 +1284,15 @@ void ObjectTypeDB::cleanup() {
memdelete( ti.method_map[*m] );
}
}
- types.clear();
+ classes.clear();
resource_base_extensions.clear();
- compat_types.clear();
+ compat_classes.clear();
+
+#ifndef NO_THREADS
+
+ memdelete(lock);
+#endif
+
}
//
diff --git a/core/object_type_db.h b/core/object_type_db.h
index 9e9029ff2f..f745e3d5fd 100644
--- a/core/object_type_db.h
+++ b/core/object_type_db.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -108,7 +108,7 @@ static _FORCE_INLINE_ const char* _MD(const char* m_name, ...) { return m_name;
#endif
-class ObjectTypeDB {
+class ClassDB {
public:
enum APIType {
API_CORE,
@@ -126,10 +126,10 @@ public:
Variant::Type type;
};
- struct TypeInfo {
+ struct ClassInfo {
APIType api;
- TypeInfo *inherits_ptr;
+ ClassInfo *inherits_ptr;
HashMap<StringName,MethodBind*,StringNameHasher> method_map;
HashMap<StringName,int,StringNameHasher> constant_map;
HashMap<StringName,MethodInfo,StringNameHasher> signal_map;
@@ -147,8 +147,8 @@ public:
StringName name;
bool disabled;
Object* (*creation_func)();
- TypeInfo();
- ~TypeInfo();
+ ClassInfo();
+ ~ClassInfo();
};
template<class T>
@@ -156,10 +156,10 @@ public:
return memnew( T );
}
- static Mutex *lock;
- static HashMap<StringName,TypeInfo,StringNameHasher> types;
+ static RWLock *lock;
+ static HashMap<StringName,ClassInfo,StringNameHasher> classes;
static HashMap<StringName,StringName,StringNameHasher> resource_base_extensions;
- static HashMap<StringName,StringName,StringNameHasher> compat_types;
+ static HashMap<StringName,StringName,StringNameHasher> compat_classes;
#ifdef DEBUG_METHODS_ENABLED
static MethodBind* bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const MethodDefinition &method_name, const Variant **p_defs, int p_defcount);
@@ -170,25 +170,25 @@ public:
static APIType current_api;
- static void _add_type2(const StringName& p_type, const StringName& p_inherits);
+ static void _add_class2(const StringName& p_class, const StringName& p_inherits);
public:
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
template<class T>
- static void _add_type() {
+ static void _add_class() {
- _add_type2(T::get_type_static(),T::get_parent_type_static());
+ _add_class2(T::get_class_static(),T::get_parent_class_static());
#if 0
GLOBAL_LOCK_FUNCTION;
- StringName name = T::get_type_static();
+ StringName name = T::get_class_static();
ERR_FAIL_COND(types.has(name));
types[name]=TypeInfo();
TypeInfo &ti=types[name];
ti.name=name;
- ti.inherits=T::get_parent_type_static();
+ ti.inherits=T::get_parent_class_static();
if (ti.inherits) {
@@ -202,21 +202,21 @@ public:
}
template<class T>
- static void register_type() {
+ static void register_class() {
GLOBAL_LOCK_FUNCTION;
- T::initialize_type();
- TypeInfo *t=types.getptr(T::get_type_static());
+ T::initialize_class();
+ ClassInfo *t=classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
t->creation_func=&creator<T>;
T::register_custom_data_to_otdb();
}
template<class T>
- static void register_virtual_type() {
+ static void register_virtual_class() {
GLOBAL_LOCK_FUNCTION;
- T::initialize_type();
+ T::initialize_class();
//nothing
}
@@ -227,24 +227,25 @@ public:
}
template<class T>
- static void register_create_type() {
+ static void register_custom_instance_class() {
GLOBAL_LOCK_FUNCTION;
- T::initialize_type();
- TypeInfo *t=types.getptr(T::get_type_static());
+ T::initialize_class();
+ ClassInfo *t=classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
t->creation_func=&_create_ptr_func<T>;
T::register_custom_data_to_otdb();
}
- static void get_type_list( List<StringName> *p_types);
- static void get_inheriters_from( const StringName& p_type,List<StringName> *p_types);
- static StringName type_inherits_from(const StringName& p_type);
- static bool type_exists(const StringName &p_type);
- static bool is_type(const StringName &p_type,const StringName& p_inherits);
- static bool can_instance(const StringName &p_type);
- static Object *instance(const StringName &p_type);
- static APIType get_api_type(const StringName &p_type);
+ static void get_class_list( List<StringName> *p_classes);
+ static void get_inheriters_from_class( const StringName& p_class,List<StringName> *p_classes);
+ static StringName get_parent_class_nocheck(const StringName& p_class);
+ static StringName get_parent_class(const StringName& p_class);
+ static bool class_exists(const StringName &p_class);
+ static bool is_parent_class(const StringName &p_class,const StringName& p_inherits);
+ static bool can_instance(const StringName &p_class);
+ static Object *instance(const StringName &p_class);
+ static APIType get_api_type(const StringName &p_class);
static uint64_t get_api_hash(APIType p_api);
@@ -444,9 +445,9 @@ public:
bind->set_name(p_name);
bind->set_default_arguments(p_default_args);
- String instance_type=bind->get_instance_type();
+ String instance_type=bind->get_instance_class();
- TypeInfo *type=types.getptr(instance_type);
+ ClassInfo *type=classes.getptr(instance_type);
if (!type) {
memdelete(bind);
ERR_FAIL_COND_V(!type,NULL);
@@ -471,44 +472,48 @@ public:
}
- static void add_signal(StringName p_type,const MethodInfo& p_signal);
- static bool has_signal(StringName p_type,StringName p_signal);
- static bool get_signal(StringName p_type,StringName p_signal,MethodInfo *r_signal);
- static void get_signal_list(StringName p_type,List<MethodInfo> *p_signals,bool p_no_inheritance=false);
+ static void add_signal(StringName p_class,const MethodInfo& p_signal);
+ static bool has_signal(StringName p_class,StringName p_signal);
+ static bool get_signal(StringName p_class,StringName p_signal,MethodInfo *r_signal);
+ static void get_signal_list(StringName p_class,List<MethodInfo> *p_signals,bool p_no_inheritance=false);
- static void add_property(StringName p_type,const PropertyInfo& p_pinfo, const StringName& p_setter, const StringName& p_getter, int p_index=-1);
- static void get_property_list(StringName p_type, List<PropertyInfo> *p_list, bool p_no_inheritance=false, const Object *p_validator=NULL);
+ static void add_property_group(StringName p_class,const String& p_name,const String& p_prefix="");
+ static void add_property(StringName p_class,const PropertyInfo& p_pinfo, const StringName& p_setter, const StringName& p_getter, int p_index=-1);
+ static void get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance=false, const Object *p_validator=NULL);
static bool set_property(Object* p_object, const StringName& p_property, const Variant& p_value, bool *r_valid=NULL);
static bool get_property(Object* p_object,const StringName& p_property, Variant& r_value);
- static Variant::Type get_property_type(const StringName& p_type, const StringName& p_property,bool *r_is_valid=NULL);
+ static bool has_property(const StringName& p_class,const StringName& p_property,bool p_no_inheritance=false);
+ static Variant::Type get_property_type(const StringName& p_class, const StringName& p_property,bool *r_is_valid=NULL);
+ static StringName get_property_setter(StringName p_class,const StringName p_property);
+ static StringName get_property_getter(StringName p_class,const StringName p_property);
- static bool has_method(StringName p_type,StringName p_method,bool p_no_inheritance=false);
- static void set_method_flags(StringName p_type,StringName p_method,int p_flags);
+ static bool has_method(StringName p_class,StringName p_method,bool p_no_inheritance=false);
+ static void set_method_flags(StringName p_class,StringName p_method,int p_flags);
- static void get_method_list(StringName p_type,List<MethodInfo> *p_methods,bool p_no_inheritance=false);
- static MethodBind *get_method(StringName p_type, StringName p_name);
+ static void get_method_list(StringName p_class,List<MethodInfo> *p_methods,bool p_no_inheritance=false);
+ static MethodBind *get_method(StringName p_class, StringName p_name);
- static void add_virtual_method(const StringName& p_type,const MethodInfo& p_method,bool p_virtual=true );
- static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods,bool p_no_inheritance=false );
+ static void add_virtual_method(const StringName& p_class,const MethodInfo& p_method,bool p_virtual=true );
+ static void get_virtual_methods(const StringName& p_class,List<MethodInfo> * p_methods,bool p_no_inheritance=false );
- static void bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant);
- static void get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance=false);
- static int get_integer_constant(const StringName& p_type, const StringName &p_name, bool *p_success=NULL);
+ static void bind_integer_constant(const StringName& p_class, const StringName &p_name, int p_constant);
+ static void get_integer_constant_list(const StringName& p_class, List<String> *p_constants, bool p_no_inheritance=false);
+ static int get_integer_constant(const StringName& p_class, const StringName &p_name, bool *p_success=NULL);
static StringName get_category(const StringName& p_node);
static bool get_setter_and_type_for_property(const StringName& p_class, const StringName& p_prop, StringName& r_class, StringName& r_setter);
- static void set_type_enabled(StringName p_type,bool p_enable);
- static bool is_type_enabled(StringName p_type);
+ static void set_class_enabled(StringName p_class,bool p_enable);
+ static bool is_class_enabled(StringName p_class);
- static void add_resource_base_extension(const StringName& p_extension,const StringName& p_type);
+ static void add_resource_base_extension(const StringName& p_extension,const StringName& p_class);
static void get_resource_base_extensions(List<String> *p_extensions);
- static void get_extensions_for_type(const StringName& p_type,List<String> *p_extensions);
+ static void get_extensions_for_type(const StringName& p_class,List<String> *p_extensions);
- static void add_compatibility_type(const StringName& p_type,const StringName& p_fallback);
+ static void add_compatibility_class(const StringName& p_class,const StringName& p_fallback);
static void init();
static void set_current_api(APIType p_api);
@@ -517,12 +522,12 @@ public:
#define BIND_CONSTANT(m_constant)\
- ObjectTypeDB::bind_integer_constant( get_type_static() , #m_constant, m_constant);
+ ClassDB::bind_integer_constant( get_class_static() , #m_constant, m_constant);
#ifdef TOOLS_ENABLED
#define BIND_VMETHOD(m_method)\
- ObjectTypeDB::add_virtual_method( get_type_static() , m_method );
+ ClassDB::add_virtual_method( get_class_static() , m_method );
#else
diff --git a/core/os/SCsub b/core/os/SCsub
index 7b4a6acbc0..4efc902717 100644
--- a/core/os/SCsub
+++ b/core/os/SCsub
@@ -1,5 +1,7 @@
+#!/usr/bin/env python
+
Import('env')
-env.add_source_files(env.core_sources,"*.cpp")
+env.add_source_files(env.core_sources, "*.cpp")
Export('env')
diff --git a/core/os/copymem.cpp b/core/os/copymem.cpp
deleted file mode 100644
index 49f53f1a51..0000000000
--- a/core/os/copymem.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*************************************************************************/
-/* copymem.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "copymem.h"
-
-#include <string.h>
-
-void movemem_system(void *to, void *from,int amount) {
-
- memmove(to,from,amount);
-
-}
-
-void zeromem(void* p_mem,size_t p_bytes) {
-
- memset(p_mem,0,p_bytes);
-}
diff --git a/core/os/copymem.h b/core/os/copymem.h
index d7fc46aae4..0452b1a36c 100644
--- a/core/os/copymem.h
+++ b/core/os/copymem.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,89 +31,18 @@
#include "typedefs.h"
-///@TODO use optimized routines for this, depending on platform. these are just the standard ones
+#ifdef PLATFORM_COPYMEM
-#define copymem(m_to,m_from,m_count) \
- do { \
- unsigned char * _from=(unsigned char*)m_from; \
- unsigned char * _to=(unsigned char*)m_to; \
- int _count=m_count; \
- for (int _i=0;_i<_count;_i++) \
- _to[_i]=_from[_i]; \
- } while (0);
- /*
- case 0: *_dto++ = *_dfrom++; \
- case 7: *_dto++ = *_dfrom++; \
- case 6: *_dto++ = *_dfrom++; \
- case 5: *_dto++ = *_dfrom++; \
- case 4: *_dto++ = *_dfrom++; \
- case 3: *_dto++ = *_dfrom++; \
- case 2: *_dto++ = *_dfrom++; \
- case 1: *_dto++ = *_dfrom++; \
- */
-#define movemem_duff(m_to, m_from, m_count) \
- do { \
- if (m_to<m_from) { \
- unsigned char* _dto = (unsigned char*)m_to; \
- unsigned char* _dfrom = (unsigned char*)m_from; \
- int n = (m_count + 7) / 8; \
- switch (m_count % 8) { \
- do { \
- case 0: *_dto++ = *_dfrom++; \
- case 7: *_dto++ = *_dfrom++; \
- case 6: *_dto++ = *_dfrom++; \
- case 5: *_dto++ = *_dfrom++; \
- case 4: *_dto++ = *_dfrom++; \
- case 3: *_dto++ = *_dfrom++; \
- case 2: *_dto++ = *_dfrom++; \
- case 1: *_dto++ = *_dfrom++; \
- } while (--n > 0); \
- }; \
- } else if (m_to>m_from) { \
- unsigned char* _dto = &((unsigned char*)m_to)[m_count-1]; \
- unsigned char* _dfrom = &((unsigned char*)m_from)[m_count-1]; \
- int n = (m_count + 7) / 8; \
- switch (m_count % 8) { \
- do { \
- case 0: *_dto-- = *_dfrom--; \
- case 7: *_dto-- = *_dfrom--; \
- case 6: *_dto-- = *_dfrom--; \
- case 5: *_dto-- = *_dfrom--; \
- case 4: *_dto-- = *_dfrom--; \
- case 3: *_dto-- = *_dfrom--; \
- case 2: *_dto-- = *_dfrom--; \
- case 1: *_dto-- = *_dfrom--; \
- } while (--n > 0); \
- }; \
- } \
- } while(0) \
+#include "platform_copymem.h" // included from platform/<current_platform>/platform_copymem.h"
-#define movemem_conventional(m_to,m_from,m_count) \
- do { \
- if (m_to<m_from) { \
- unsigned char * _from=(unsigned char*)m_from; \
- unsigned char * _to=(unsigned char*)m_to; \
- int _count=m_count; \
- for (int _i=0;_i<_count;_i++) \
- _to[_i]=_from[_i]; \
- \
- } else if (m_to>m_from) { \
- unsigned char * _from=(unsigned char*)m_from; \
- unsigned char * _to=(unsigned char*)m_to; \
- int _count=m_count; \
- while (_count--) \
- _to[_count]=_from[_count]; \
- \
- \
- } \
- } while (0); \
+#else
-void movemem_system(void*,void*,int);
+#include <string.h>
-#define movemem movemem_system
-
-
-void zeromem(void* p_mem,size_t p_bytes);
+#define copymem(to,from,count) memcpy(to,from,count)
+#define zeromem(to, count) memset(to, 0, count)
+#define movemem(to, from, count) memmove(to, from, count)
#endif
+#endif
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index c2402183fd..804fe15c39 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,7 +37,7 @@ String DirAccess::_get_root_path() const {
switch(_access_type) {
- case ACCESS_RESOURCES: return Globals::get_singleton()->get_resource_path();
+ case ACCESS_RESOURCES: return GlobalConfig::get_singleton()->get_resource_path();
case ACCESS_USERDATA: return OS::get_singleton()->get_data_dir();
default: return "";
}
@@ -204,10 +204,10 @@ String DirAccess::fix_path(String p_path) const {
case ACCESS_RESOURCES: {
- if (Globals::get_singleton()) {
+ if (GlobalConfig::get_singleton()) {
if (p_path.begins_with("res://")) {
- String resource_path = Globals::get_singleton()->get_resource_path();
+ String resource_path = GlobalConfig::get_singleton()->get_resource_path();
if (resource_path != "") {
return p_path.replace_first("res:/",resource_path);
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index 83288b7c91..7c173fc780 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -72,7 +72,7 @@ protected:
public:
- virtual bool list_dir_begin()=0; ///< This starts dir listing
+ virtual Error list_dir_begin()=0; ///< This starts dir listing
virtual String get_next(bool* p_is_dir); // compatibility
virtual String get_next()=0;
virtual bool current_is_dir() const=0;
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 2f1693c044..06723c5131 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -139,10 +139,10 @@ String FileAccess::fix_path(const String& p_path) const {
case ACCESS_RESOURCES: {
- if (Globals::get_singleton()) {
+ if (GlobalConfig::get_singleton()) {
if (r_path.begins_with("res://")) {
- String resource_path = Globals::get_singleton()->get_resource_path();
+ String resource_path = GlobalConfig::get_singleton()->get_resource_path();
if (resource_path != "") {
return r_path.replace("res:/",resource_path);
diff --git a/core/os/file_access.h b/core/os/file_access.h
index 5178c469bc..7d61099bc2 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/input.cpp b/core/os/input.cpp
index 401ab7ffe2..acfd5ba540 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -49,35 +49,39 @@ Input::MouseMode Input::get_mouse_mode() const {
void Input::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("is_key_pressed","scancode"),&Input::is_key_pressed);
- ObjectTypeDB::bind_method(_MD("is_mouse_button_pressed","button"),&Input::is_mouse_button_pressed);
- ObjectTypeDB::bind_method(_MD("is_joy_button_pressed","device","button"),&Input::is_joy_button_pressed);
- ObjectTypeDB::bind_method(_MD("is_action_pressed","action"),&Input::is_action_pressed);
- ObjectTypeDB::bind_method(_MD("is_action_just_pressed","action"),&Input::is_action_just_pressed);
- ObjectTypeDB::bind_method(_MD("is_action_just_released","action"),&Input::is_action_just_released);
- ObjectTypeDB::bind_method(_MD("add_joy_mapping","mapping", "update_existing"),&Input::add_joy_mapping, DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("remove_joy_mapping","guid"),&Input::remove_joy_mapping);
- ObjectTypeDB::bind_method(_MD("is_joy_known","device"),&Input::is_joy_known);
- ObjectTypeDB::bind_method(_MD("get_joy_axis","device","axis"),&Input::get_joy_axis);
- ObjectTypeDB::bind_method(_MD("get_joy_name","device"),&Input::get_joy_name);
- ObjectTypeDB::bind_method(_MD("get_joy_guid","device"),&Input::get_joy_guid);
- ObjectTypeDB::bind_method(_MD("get_connected_joysticks"),&Input::get_connected_joysticks);
- ObjectTypeDB::bind_method(_MD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength);
- ObjectTypeDB::bind_method(_MD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration);
- ObjectTypeDB::bind_method(_MD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0));
- ObjectTypeDB::bind_method(_MD("stop_joy_vibration", "device"), &Input::stop_joy_vibration);
- ObjectTypeDB::bind_method(_MD("get_accelerometer"),&Input::get_accelerometer);
- ObjectTypeDB::bind_method(_MD("get_magnetometer"),&Input::get_magnetometer);
- ObjectTypeDB::bind_method(_MD("get_gyroscope"),&Input::get_gyroscope);
- //ObjectTypeDB::bind_method(_MD("get_mouse_pos"),&Input::get_mouse_pos); - this is not the function you want
- ObjectTypeDB::bind_method(_MD("get_mouse_speed"),&Input::get_mouse_speed);
- ObjectTypeDB::bind_method(_MD("get_mouse_button_mask"),&Input::get_mouse_button_mask);
- ObjectTypeDB::bind_method(_MD("set_mouse_mode","mode"),&Input::set_mouse_mode);
- ObjectTypeDB::bind_method(_MD("get_mouse_mode"),&Input::get_mouse_mode);
- ObjectTypeDB::bind_method(_MD("warp_mouse_pos","to"),&Input::warp_mouse_pos);
- ObjectTypeDB::bind_method(_MD("action_press","action"),&Input::action_press);
- ObjectTypeDB::bind_method(_MD("action_release","action"),&Input::action_release);
- ObjectTypeDB::bind_method(_MD("set_custom_mouse_cursor","image:Texture","hotspot"),&Input::set_custom_mouse_cursor,DEFVAL(Vector2()));
+ ClassDB::bind_method(_MD("is_key_pressed","scancode"),&Input::is_key_pressed);
+ ClassDB::bind_method(_MD("is_mouse_button_pressed","button"),&Input::is_mouse_button_pressed);
+ ClassDB::bind_method(_MD("is_joy_button_pressed","device","button"),&Input::is_joy_button_pressed);
+ ClassDB::bind_method(_MD("is_action_pressed","action"),&Input::is_action_pressed);
+ ClassDB::bind_method(_MD("is_action_just_pressed","action"),&Input::is_action_just_pressed);
+ ClassDB::bind_method(_MD("is_action_just_released","action"),&Input::is_action_just_released);
+ ClassDB::bind_method(_MD("add_joy_mapping","mapping", "update_existing"),&Input::add_joy_mapping, DEFVAL(false));
+ ClassDB::bind_method(_MD("remove_joy_mapping","guid"),&Input::remove_joy_mapping);
+ ClassDB::bind_method(_MD("is_joy_known","device"),&Input::is_joy_known);
+ ClassDB::bind_method(_MD("get_joy_axis","device","axis"),&Input::get_joy_axis);
+ ClassDB::bind_method(_MD("get_joy_name","device"),&Input::get_joy_name);
+ ClassDB::bind_method(_MD("get_joy_guid","device"),&Input::get_joy_guid);
+ ClassDB::bind_method(_MD("get_connected_joypads"),&Input::get_connected_joypads);
+ ClassDB::bind_method(_MD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength);
+ ClassDB::bind_method(_MD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration);
+ ClassDB::bind_method(_MD("get_joy_button_string", "button_index"), &Input::get_joy_button_string);
+ ClassDB::bind_method(_MD("get_joy_button_index_from_string", "button"), &Input::get_joy_button_index_from_string);
+ ClassDB::bind_method(_MD("get_joy_axis_string", "axis_index"), &Input::get_joy_axis_string);
+ ClassDB::bind_method(_MD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string);
+ ClassDB::bind_method(_MD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0));
+ ClassDB::bind_method(_MD("stop_joy_vibration", "device"), &Input::stop_joy_vibration);
+ ClassDB::bind_method(_MD("get_accelerometer"),&Input::get_accelerometer);
+ ClassDB::bind_method(_MD("get_magnetometer"),&Input::get_magnetometer);
+ ClassDB::bind_method(_MD("get_gyroscope"),&Input::get_gyroscope);
+ //ClassDB::bind_method(_MD("get_mouse_pos"),&Input::get_mouse_pos); - this is not the function you want
+ ClassDB::bind_method(_MD("get_last_mouse_speed"),&Input::get_last_mouse_speed);
+ ClassDB::bind_method(_MD("get_mouse_button_mask"),&Input::get_mouse_button_mask);
+ ClassDB::bind_method(_MD("set_mouse_mode","mode"),&Input::set_mouse_mode);
+ ClassDB::bind_method(_MD("get_mouse_mode"),&Input::get_mouse_mode);
+ ClassDB::bind_method(_MD("warp_mouse_pos","to"),&Input::warp_mouse_pos);
+ ClassDB::bind_method(_MD("action_press","action"),&Input::action_press);
+ ClassDB::bind_method(_MD("action_release","action"),&Input::action_release);
+ ClassDB::bind_method(_MD("set_custom_mouse_cursor","image:Texture","hotspot"),&Input::set_custom_mouse_cursor,DEFVAL(Vector2()));
BIND_CONSTANT( MOUSE_MODE_VISIBLE );
BIND_CONSTANT( MOUSE_MODE_HIDDEN );
@@ -90,10 +94,10 @@ void Input::get_argument_options(const StringName& p_function,int p_idx,List<Str
#ifdef TOOLS_ENABLED
String pf=p_function;
- if (p_idx==0 && (pf=="is_action_pressed" || pf=="action_press" || pf=="action_release")) {
+ if (p_idx==0 && (pf=="is_action_pressed" || pf=="action_press" || pf=="action_release" || pf=="is_action_just_pressed" || pf=="is_action_just_released")) {
List<PropertyInfo> pinfo;
- Globals::get_singleton()->get_property_list(&pinfo);
+ GlobalConfig::get_singleton()->get_property_list(&pinfo);
for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
const PropertyInfo &pi=E->get();
diff --git a/core/os/input.h b/core/os/input.h
index 665fb4ad99..a1b60ba0c8 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -35,7 +35,7 @@
class Input : public Object {
- OBJ_TYPE( Input, Object );
+ GDCLASS( Input, Object );
static Input *singleton;
@@ -64,7 +64,7 @@ public:
virtual float get_joy_axis(int p_device,int p_axis) const=0;
virtual String get_joy_name(int p_idx)=0;
- virtual Array get_connected_joysticks()=0;
+ virtual Array get_connected_joypads()=0;
virtual void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid)=0;
virtual void add_joy_mapping(String p_mapping, bool p_update_existing=false)=0;
virtual void remove_joy_mapping(String p_guid)=0;
@@ -77,7 +77,7 @@ public:
virtual void stop_joy_vibration(int p_device)=0;
virtual Point2 get_mouse_pos() const=0;
- virtual Point2 get_mouse_speed() const=0;
+ virtual Point2 get_last_mouse_speed() const=0;
virtual int get_mouse_button_mask() const=0;
virtual void warp_mouse_pos(const Vector2& p_to)=0;
@@ -96,6 +96,11 @@ public:
virtual void set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_hotspot=Vector2())=0;
virtual void set_mouse_in_window(bool p_in_window)=0;
+ virtual String get_joy_button_string(int p_button)=0;
+ virtual String get_joy_axis_string(int p_axis)=0;
+ virtual int get_joy_button_index_from_string(String p_button)=0;
+ virtual int get_joy_axis_index_from_string(String p_axis)=0;
+
Input();
};
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 9982767be1..3cc595208f 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -50,7 +50,8 @@ bool InputEvent::operator==(const InputEvent &p_event) const {
case MOUSE_MOTION:
return mouse_motion.x == p_event.mouse_motion.x
&& mouse_motion.y == p_event.mouse_motion.y
- && mouse_motion.relative_x == p_event.mouse_motion.relative_y
+ && mouse_motion.relative_x == p_event.mouse_motion.relative_x
+ && mouse_motion.relative_y == p_event.mouse_motion.relative_y
&& mouse_motion.button_mask == p_event.mouse_motion.button_mask
&& key.mod == p_event.key.mod;
case MOUSE_BUTTON:
@@ -60,10 +61,10 @@ bool InputEvent::operator==(const InputEvent &p_event) const {
&& mouse_button.button_index == p_event.mouse_button.button_index
&& mouse_button.button_mask == p_event.mouse_button.button_mask
&& key.mod == p_event.key.mod;
- case JOYSTICK_MOTION:
+ case JOYPAD_MOTION:
return joy_motion.axis == p_event.joy_motion.axis
&& joy_motion.axis_value == p_event.joy_motion.axis_value;
- case JOYSTICK_BUTTON:
+ case JOYPAD_BUTTON:
return joy_button.pressed == p_event.joy_button.pressed
&& joy_button.button_index == p_event.joy_button.button_index
&& joy_button.pressure == p_event.joy_button.pressure;
@@ -154,14 +155,14 @@ InputEvent::operator String() const {
return str;
} break;
- case JOYSTICK_MOTION: {
- str+= "Event: JoystickMotion ";
+ case JOYPAD_MOTION: {
+ str+= "Event: JoypadMotion ";
str=str+"Axis: "+itos(joy_motion.axis)+" Value: " +rtos(joy_motion.axis_value);
return str;
} break;
- case JOYSTICK_BUTTON: {
- str+= "Event: JoystickButton ";
+ case JOYPAD_BUTTON: {
+ str+= "Event: JoypadButton ";
str=str+"Pressed: "+itos(joy_button.pressed)+" Index: " +itos(joy_button.button_index)+" pressure "+rtos(joy_button.pressure);
return str;
@@ -202,9 +203,9 @@ bool InputEvent::is_pressed() const {
case KEY: return key.pressed;
case MOUSE_BUTTON: return mouse_button.pressed;
- case JOYSTICK_BUTTON: return joy_button.pressed;
+ case JOYPAD_BUTTON: return joy_button.pressed;
case SCREEN_TOUCH: return screen_touch.pressed;
- case JOYSTICK_MOTION: return ABS(joy_motion.axis_value) > 0.5;
+ case JOYPAD_MOTION: return ABS(joy_motion.axis_value) > 0.5;
case ACTION: return action.pressed;
default: {}
}
@@ -248,7 +249,7 @@ uint32_t InputEventKey::get_scancode_with_modifiers() const {
}
-InputEvent InputEvent::xform_by(const Matrix32& p_xform) const {
+InputEvent InputEvent::xform_by(const Transform2D& p_xform) const {
InputEvent ev=*this;
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 1c4f1dcf96..1af4ef20c2 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -205,8 +205,8 @@ struct InputEventMouse {
InputModifierState mod;
int button_mask;
- int x,y;
- int global_x,global_y;
+ float x,y;
+ float global_x,global_y;
int pointer_index;
};
@@ -221,17 +221,17 @@ struct InputEventMouseButton : public InputEventMouse {
struct InputEventMouseMotion : public InputEventMouse {
- int relative_x,relative_y;
+ float relative_x,relative_y;
float speed_x,speed_y;
};
-struct InputEventJoystickMotion {
+struct InputEventJoypadMotion {
- int axis; ///< Joystick axis
+ int axis; ///< Joypad axis
float axis_value; ///< -1 to 1
};
-struct InputEventJoystickButton {
+struct InputEventJoypadButton {
int button_index;
bool pressed;
@@ -241,14 +241,14 @@ struct InputEventJoystickButton {
struct InputEventScreenTouch {
int index;
- int x,y;
+ float x,y;
bool pressed;
};
struct InputEventScreenDrag {
int index;
- int x,y;
- int relative_x,relative_y;
+ float x,y;
+ float relative_x,relative_y;
float speed_x,speed_y;
};
@@ -267,8 +267,8 @@ struct InputEvent {
KEY,
MOUSE_MOTION,
MOUSE_BUTTON,
- JOYSTICK_MOTION,
- JOYSTICK_BUTTON,
+ JOYPAD_MOTION,
+ JOYPAD_BUTTON,
SCREEN_TOUCH,
SCREEN_DRAG,
ACTION,
@@ -282,8 +282,8 @@ struct InputEvent {
union {
InputEventMouseMotion mouse_motion;
InputEventMouseButton mouse_button;
- InputEventJoystickMotion joy_motion;
- InputEventJoystickButton joy_button;
+ InputEventJoypadMotion joy_motion;
+ InputEventJoypadButton joy_button;
InputEventKey key;
InputEventScreenTouch screen_touch;
InputEventScreenDrag screen_drag;
@@ -298,7 +298,7 @@ struct InputEvent {
void set_as_action(const String& p_action, bool p_pressed);
- InputEvent xform_by(const Matrix32& p_xform) const;
+ InputEvent xform_by(const Transform2D& p_xform) const;
bool operator==(const InputEvent &p_event) const;
operator String() const;
InputEvent() { zeromem(this,sizeof(InputEvent)); }
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index 9710638234..309348ea31 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index fd52d331c8..1357cc8b8e 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index e5feebfbfc..11396666d2 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,19 +31,19 @@
void MainLoop::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("input_event","ev"),&MainLoop::input_event);
- ObjectTypeDB::bind_method(_MD("input_text","text"),&MainLoop::input_text);
- ObjectTypeDB::bind_method(_MD("init"),&MainLoop::init);
- ObjectTypeDB::bind_method(_MD("iteration","delta"),&MainLoop::iteration);
- ObjectTypeDB::bind_method(_MD("idle","delta"),&MainLoop::idle);
- ObjectTypeDB::bind_method(_MD("finish"),&MainLoop::finish);
+ ClassDB::bind_method(_MD("input_event","ev"),&MainLoop::input_event);
+ ClassDB::bind_method(_MD("input_text","text"),&MainLoop::input_text);
+ ClassDB::bind_method(_MD("init"),&MainLoop::init);
+ ClassDB::bind_method(_MD("iteration","delta"),&MainLoop::iteration);
+ ClassDB::bind_method(_MD("idle","delta"),&MainLoop::idle);
+ ClassDB::bind_method(_MD("finish"),&MainLoop::finish);
BIND_VMETHOD( MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"ev")) );
BIND_VMETHOD( MethodInfo("_input_text",PropertyInfo(Variant::STRING,"text")) );
BIND_VMETHOD( MethodInfo("_initialize") );
BIND_VMETHOD( MethodInfo("_iteration",PropertyInfo(Variant::REAL,"delta")) );
BIND_VMETHOD( MethodInfo("_idle",PropertyInfo(Variant::REAL,"delta")) );
- BIND_VMETHOD( MethodInfo("_drop_files",PropertyInfo(Variant::STRING_ARRAY,"files"),PropertyInfo(Variant::INT,"screen")) );
+ BIND_VMETHOD( MethodInfo("_drop_files",PropertyInfo(Variant::POOL_STRING_ARRAY,"files"),PropertyInfo(Variant::INT,"screen")) );
BIND_VMETHOD( MethodInfo("_finalize") );
BIND_CONSTANT(NOTIFICATION_WM_MOUSE_ENTER);
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index 57185d9d3d..456a6be4d3 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,7 +37,7 @@
*/
class MainLoop : public Object {
- OBJ_TYPE( MainLoop, Object );
+ GDCLASS( MainLoop, Object );
OBJ_CATEGORY("Main Loop");
Ref<Script> init_script;
@@ -47,13 +47,15 @@ protected:
public:
enum {
- NOTIFICATION_WM_MOUSE_ENTER = 3,
- NOTIFICATION_WM_MOUSE_EXIT = 4,
- NOTIFICATION_WM_FOCUS_IN = 5,
- NOTIFICATION_WM_FOCUS_OUT = 6,
- NOTIFICATION_WM_QUIT_REQUEST = 7,
+ NOTIFICATION_WM_MOUSE_ENTER = 2,
+ NOTIFICATION_WM_MOUSE_EXIT = 3,
+ NOTIFICATION_WM_FOCUS_IN = 4,
+ NOTIFICATION_WM_FOCUS_OUT = 5,
+ NOTIFICATION_WM_QUIT_REQUEST = 6,
+ NOTIFICATION_WM_GO_BACK_REQUEST = 7,
NOTIFICATION_WM_UNFOCUS_REQUEST = 8,
NOTIFICATION_OS_MEMORY_WARNING = 9,
+ NOTIFICATION_TRANSLATION_CHANGED = 10,
};
virtual void input_event( const InputEvent& p_event );
diff --git a/core/os/memory.cpp b/core/os/memory.cpp
index c2ff2aa781..37a523b763 100644
--- a/core/os/memory.cpp
+++ b/core/os/memory.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,9 +30,13 @@
#include "error_macros.h"
#include "copymem.h"
#include <stdio.h>
+#include <stdlib.h>
+
+
+
void * operator new(size_t p_size,const char *p_description) {
- return Memory::alloc_static( p_size, p_description );
+ return Memory::alloc_static( p_size, false );
}
void * operator new(size_t p_size,void* (*p_allocfunc)(size_t p_size)) {
@@ -42,74 +46,144 @@ void * operator new(size_t p_size,void* (*p_allocfunc)(size_t p_size)) {
#include <stdio.h>
-void * Memory::alloc_static(size_t p_bytes,const char *p_alloc_from) {
+#ifdef DEBUG_ENABLED
+size_t Memory::mem_usage=0;
+size_t Memory::max_usage=0;
+#endif
- ERR_FAIL_COND_V( !MemoryPoolStatic::get_singleton(), NULL );
- return MemoryPoolStatic::get_singleton()->alloc(p_bytes,p_alloc_from);
-}
-void * Memory::realloc_static(void *p_memory,size_t p_bytes) {
+size_t Memory::alloc_count=0;
- ERR_FAIL_COND_V( !MemoryPoolStatic::get_singleton(), NULL );
- return MemoryPoolStatic::get_singleton()->realloc(p_memory,p_bytes);
-}
-void Memory::free_static(void *p_ptr) {
+void * Memory::alloc_static(size_t p_bytes,bool p_pad_align) {
- ERR_FAIL_COND( !MemoryPoolStatic::get_singleton());
- MemoryPoolStatic::get_singleton()->free(p_ptr);
-}
+#ifdef DEBUG_ENABLED
+ bool prepad=true;
+#else
+ bool prepad=p_pad_align;
+#endif
-size_t Memory::get_static_mem_available() {
+ void * mem = malloc( p_bytes + (prepad?PAD_ALIGN:0));
- ERR_FAIL_COND_V( !MemoryPoolStatic::get_singleton(), 0);
- return MemoryPoolStatic::get_singleton()->get_available_mem();
+ alloc_count++;
-}
+ ERR_FAIL_COND_V(!mem,NULL);
-size_t Memory::get_static_mem_max_usage() {
+ if (prepad) {
+ uint64_t *s = (uint64_t*)mem;
+ *s=p_bytes;
- ERR_FAIL_COND_V( !MemoryPoolStatic::get_singleton(), 0);
- return MemoryPoolStatic::get_singleton()->get_max_usage();
+ uint8_t *s8 = (uint8_t*)mem;
+
+#ifdef DEBUG_ENABLED
+ mem_usage+=p_bytes;
+ if (mem_usage>max_usage) {
+ max_usage=mem_usage;
+ }
+#endif
+ return s8 + PAD_ALIGN;
+ } else {
+ return mem;
+ }
}
-size_t Memory::get_static_mem_usage() {
+void * Memory::realloc_static(void *p_memory,size_t p_bytes,bool p_pad_align) {
- ERR_FAIL_COND_V( !MemoryPoolStatic::get_singleton(), 0);
- return MemoryPoolStatic::get_singleton()->get_total_usage();
+ if (p_memory==NULL) {
+ return alloc_static(p_bytes,p_pad_align);
+ }
-}
+ uint8_t *mem = (uint8_t*)p_memory;
-void Memory::dump_static_mem_to_file(const char* p_file) {
+#ifdef DEBUG_ENABLED
+ bool prepad=true;
+#else
+ bool prepad=p_pad_align;
+#endif
- MemoryPoolStatic::get_singleton()->dump_mem_to_file(p_file);
-}
+ if (prepad) {
+ mem-=PAD_ALIGN;
+ uint64_t *s = (uint64_t*)mem;
-MID Memory::alloc_dynamic(size_t p_bytes, const char *p_descr) {
+#ifdef DEBUG_ENABLED
+ mem_usage-=*s;
+ mem_usage+=p_bytes;
+#endif
- MemoryPoolDynamic::ID id = MemoryPoolDynamic::get_singleton()->alloc(p_bytes,p_descr);
+ if (p_bytes==0) {
+ free(mem);
+ return NULL;
+ } else {
+ *s=p_bytes;
- return MID(id);
-}
-Error Memory::realloc_dynamic(MID p_mid,size_t p_bytes) {
+ mem = (uint8_t*)realloc(mem,p_bytes+PAD_ALIGN);
+ ERR_FAIL_COND_V(!mem,NULL);
+
+ s = (uint64_t*)mem;
+
+ *s=p_bytes;
- MemoryPoolDynamic::ID id = p_mid.data?p_mid.data->id:MemoryPoolDynamic::INVALID_ID;
+ return mem+PAD_ALIGN;
+ }
+ } else {
- if (id==MemoryPoolDynamic::INVALID_ID)
- return ERR_INVALID_PARAMETER;
+ mem = (uint8_t*)realloc(mem,p_bytes);
- return MemoryPoolDynamic::get_singleton()->realloc(p_mid, p_bytes);
+ ERR_FAIL_COND_V(mem==NULL && p_bytes>0,NULL);
+ return mem;
+ }
}
-size_t Memory::get_dynamic_mem_available() {
+void Memory::free_static(void *p_ptr,bool p_pad_align) {
+
+ ERR_FAIL_COND(p_ptr==NULL);
+
+ uint8_t *mem = (uint8_t*)p_ptr;
+
+#ifdef DEBUG_ENABLED
+ bool prepad=true;
+#else
+ bool prepad=p_pad_align;
+#endif
+
+ alloc_count--;
+
+ if (prepad) {
+ mem-=PAD_ALIGN;
+ uint64_t *s = (uint64_t*)mem;
+
+#ifdef DEBUG_ENABLED
+ mem_usage-=*s;
+#endif
+
+ free(mem);
+ } else {
+
+ free(mem);
+ }
- return MemoryPoolDynamic::get_singleton()->get_available_mem();
}
-size_t Memory::get_dynamic_mem_usage() {
+size_t Memory::get_mem_available() {
+
+ return 0xFFFFFFFFFFFFF;
- return MemoryPoolDynamic::get_singleton()->get_total_usage();
+}
+
+size_t Memory::get_mem_usage(){
+#ifdef DEBUG_ENABLED
+ return mem_usage;
+#else
+ return 0;
+#endif
+}
+size_t Memory::get_mem_max_usage(){
+#ifdef DEBUG_ENABLED
+ return max_usage;
+#else
+ return 0;
+#endif
}
diff --git a/core/os/memory.h b/core/os/memory.h
index 5f4c6f929c..49424037ff 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,175 +31,45 @@
#include <stddef.h>
#include "safe_refcount.h"
-#include "os/memory_pool_dynamic.h"
-#include "os/memory_pool_static.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-class MID {
-
- struct Data {
-
- SafeRefCount refcount;
- MemoryPoolDynamic::ID id;
- };
-
- mutable Data *data;
-
- void unref() {
-
- if (!data)
- return;
- if (data->refcount.unref()) {
-
- if (data->id!=MemoryPoolDynamic::INVALID_ID)
- MemoryPoolDynamic::get_singleton()->free(data->id);
- MemoryPoolStatic::get_singleton()->free(data);
- }
-
- data=NULL;
- }
-
- void ref(Data *p_data) {
-
- if (data==p_data)
- return;
- unref();
-
- if (p_data && p_data->refcount.ref())
- data=p_data;
- }
-
-friend class MID_Lock;
-
- inline void lock() {
-
- if (data && data->id!=MemoryPoolDynamic::INVALID_ID)
- MemoryPoolDynamic::get_singleton()->lock(data->id);
- }
- inline void unlock() {
-
- if (data && data->id!=MemoryPoolDynamic::INVALID_ID)
- MemoryPoolDynamic::get_singleton()->unlock(data->id);
-
- }
-
- inline void * get() {
-
- if (data && data->id!=MemoryPoolDynamic::INVALID_ID)
- return MemoryPoolDynamic::get_singleton()->get(data->id);
-
- return NULL;
- }
-
- Error _resize(size_t p_size) {
-
- if (p_size==0 && (!data || data->id==MemoryPoolDynamic::INVALID_ID))
- return OK;
- if (p_size && !data) {
- // create data because we'll need it
- data = (Data*)MemoryPoolStatic::get_singleton()->alloc(sizeof(Data),"MID::Data");
- ERR_FAIL_COND_V( !data,ERR_OUT_OF_MEMORY );
- data->refcount.init();
- data->id=MemoryPoolDynamic::INVALID_ID;
- }
-
- if (p_size==0 && data && data->id==MemoryPoolDynamic::INVALID_ID) {
-
- MemoryPoolDynamic::get_singleton()->free(data->id);
- data->id=MemoryPoolDynamic::INVALID_ID;
- }
-
- if (p_size>0) {
-
- if (data->id==MemoryPoolDynamic::INVALID_ID) {
-
- data->id=MemoryPoolDynamic::get_singleton()->alloc(p_size,"Unnamed MID");
- ERR_FAIL_COND_V( data->id==MemoryPoolDynamic::INVALID_ID, ERR_OUT_OF_MEMORY );
-
- } else {
-
- MemoryPoolDynamic::get_singleton()->realloc(data->id,p_size);
- ERR_FAIL_COND_V( data->id==MemoryPoolDynamic::INVALID_ID, ERR_OUT_OF_MEMORY );
-
- }
- }
-
- return OK;
- }
-friend class Memory;
-
- MID(MemoryPoolDynamic::ID p_id) {
-
- data = (Data*)MemoryPoolStatic::get_singleton()->alloc(sizeof(Data),"MID::Data");
- data->refcount.init();
- data->id=p_id;
- }
-public:
-
- bool is_valid() const { return data; }
- operator bool() const { return data; }
-
-
- size_t get_size() const { return (data && data->id!=MemoryPoolDynamic::INVALID_ID) ? MemoryPoolDynamic::get_singleton()->get_size(data->id) : 0; }
- Error resize(size_t p_size) { return _resize(p_size); }
- inline void operator=(const MID& p_mid) { ref( p_mid.data ); }
- inline bool is_locked() const { return (data && data->id!=MemoryPoolDynamic::INVALID_ID) ? MemoryPoolDynamic::get_singleton()->is_locked(data->id) : false; }
- inline MID(const MID& p_mid) { data=NULL; ref( p_mid.data ); }
- inline MID() { data = NULL; }
- ~MID() { unref(); }
-};
-
-
-class MID_Lock {
-
- MID mid;
-
-public:
-
- void *data() { return mid.get(); }
+#ifndef PAD_ALIGN
+#define PAD_ALIGN 16 //must always be greater than this at much
+#endif
- void operator=(const MID_Lock& p_lock ) { mid.unlock(); mid = p_lock.mid; mid.lock(); }
- inline MID_Lock(const MID& p_mid) { mid=p_mid; mid.lock(); }
- inline MID_Lock(const MID_Lock& p_lock) { mid=p_lock.mid; mid.lock(); }
- MID_Lock() {}
- ~MID_Lock() { mid.unlock(); }
-};
class Memory{
Memory();
-public:
+#ifdef DEBUG_ENABLED
+ static size_t mem_usage;
+ static size_t max_usage;
+#endif
+
+ static size_t alloc_count;
- static void * alloc_static(size_t p_bytes,const char *p_descr="");
- static void * realloc_static(void *p_memory,size_t p_bytes);
- static void free_static(void *p_ptr);
- static size_t get_static_mem_available();
- static size_t get_static_mem_usage();
- static size_t get_static_mem_max_usage();
- static void dump_static_mem_to_file(const char* p_file);
+public:
- static MID alloc_dynamic(size_t p_bytes, const char *p_descr="");
- static Error realloc_dynamic(MID p_mid,size_t p_bytes);
+ static void * alloc_static(size_t p_bytes,bool p_pad_align=false);
+ static void * realloc_static(void *p_memory,size_t p_bytes,bool p_pad_align=false);
+ static void free_static(void *p_ptr,bool p_pad_align=false);
- static size_t get_dynamic_mem_available();
- static size_t get_dynamic_mem_usage();
+ static size_t get_mem_available();
+ static size_t get_mem_usage();
+ static size_t get_mem_max_usage();
-};
-template<class T>
-struct MemAalign {
- static _FORCE_INLINE_ int get_align() { return DEFAULT_ALIGNMENT; }
};
class DefaultAllocator {
public:
- _FORCE_INLINE_ static void *alloc(size_t p_memory) { return Memory::alloc_static(p_memory, ""); }
- _FORCE_INLINE_ static void free(void *p_ptr) { return Memory::free_static(p_ptr); }
+ _FORCE_INLINE_ static void *alloc(size_t p_memory) { return Memory::alloc_static(p_memory, false); }
+ _FORCE_INLINE_ static void free(void *p_ptr) { return Memory::free_static(p_ptr,false); }
};
@@ -209,31 +79,10 @@ void * operator new(size_t p_size,void* (*p_allocfunc)(size_t p_size)); ///< ope
void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_description); ///< operator new that takes a description and uses a pointer to the preallocated memory
-#ifdef DEBUG_MEMORY_ENABLED
-
-#define memalloc(m_size) Memory::alloc_static(m_size, __FILE__ ":" __STR(__LINE__) ", memalloc.")
-#define memrealloc(m_mem,m_size) Memory::realloc_static(m_mem,m_size)
-#define memfree(m_size) Memory::free_static(m_size)
-
-#else
-
#define memalloc(m_size) Memory::alloc_static(m_size)
#define memrealloc(m_mem,m_size) Memory::realloc_static(m_mem,m_size)
#define memfree(m_size) Memory::free_static(m_size)
-#endif
-
-#ifdef DEBUG_MEMORY_ENABLED
-#define dynalloc(m_size) Memory::alloc_dynamic(m_size, __FILE__ ":" __STR(__LINE__) ", type: DYNAMIC")
-#define dynrealloc(m_mem,m_size) m_mem.resize(m_size)
-
-#else
-
-#define dynalloc(m_size) Memory::alloc_dynamic(m_size)
-#define dynrealloc(m_mem,m_size) m_mem.resize(m_size)
-
-#endif
-
_ALWAYS_INLINE_ void postinitialize_handler(void *) {}
@@ -245,19 +94,11 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
return p_obj;
}
-#ifdef DEBUG_MEMORY_ENABLED
-
-#define memnew(m_class) _post_initialize(new(__FILE__ ":" __STR(__LINE__) ", memnew type: " __STR(m_class)) m_class)
-
-#else
-
#define memnew(m_class) _post_initialize(new("") m_class)
-#endif
-
_ALWAYS_INLINE_ void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_description) {
-// void *failptr=0;
-// ERR_FAIL_COND_V( check < p_size , failptr); /** bug, or strange compiler, most likely */
+ //void *failptr=0;
+ //ERR_FAIL_COND_V( check < p_size , failptr); /** bug, or strange compiler, most likely */
return p_pointer;
}
@@ -275,7 +116,7 @@ void memdelete(T *p_class) {
if (!predelete_handler(p_class))
return; // doesn't want to be deleted
p_class->~T();
- Memory::free_static(p_class);
+ Memory::free_static(p_class,false);
}
template<class T,class A>
@@ -288,15 +129,9 @@ void memdelete_allocator(T *p_class) {
}
#define memdelete_notnull(m_v) { if (m_v) memdelete(m_v); }
-#ifdef DEBUG_MEMORY_ENABLED
-
-#define memnew_arr( m_class, m_count ) memnew_arr_template<m_class>(m_count,__FILE__ ":" __STR(__LINE__) ", memnew_arr type: " _STR(m_class))
-
-#else
#define memnew_arr( m_class, m_count ) memnew_arr_template<m_class>(m_count)
-#endif
template<typename T>
T* memnew_arr_template(size_t p_elements,const char *p_descr="") {
@@ -304,14 +139,14 @@ T* memnew_arr_template(size_t p_elements,const char *p_descr="") {
if (p_elements==0)
return 0;
/** overloading operator new[] cannot be done , because it may not return the real allocated address (it may pad the 'element count' before the actual array). Because of that, it must be done by hand. This is the
- same strategy used by std::vector, and the DVector class, so it should be safe.*/
+ same strategy used by std::vector, and the PoolVector class, so it should be safe.*/
size_t len = sizeof(T) * p_elements;
- unsigned int *mem = (unsigned int*)Memory::alloc_static( len + MAX(sizeof(size_t), DEFAULT_ALIGNMENT), p_descr );
+ uint64_t *mem = (uint64_t*)Memory::alloc_static( len , true );
T *failptr=0; //get rid of a warning
ERR_FAIL_COND_V( !mem, failptr );
- *mem=p_elements;
- mem = (unsigned int *)( ((uint8_t*)mem) + MAX(sizeof(size_t), DEFAULT_ALIGNMENT));
+ *(mem-1)=p_elements;
+
T* elems = (T*)mem;
/* call operator new */
@@ -330,20 +165,22 @@ T* memnew_arr_template(size_t p_elements,const char *p_descr="") {
template<typename T>
size_t memarr_len(const T *p_class) {
- uint8_t* ptr = ((uint8_t*)p_class) - MAX(sizeof(size_t), DEFAULT_ALIGNMENT);
- return *(size_t*)ptr;
+ uint64_t* ptr = (uint64_t*)p_class;
+ return *(ptr-1);
}
template<typename T>
void memdelete_arr(T *p_class) {
- unsigned int * elems = (unsigned int*)(((uint8_t*)p_class) - MAX(sizeof(size_t), DEFAULT_ALIGNMENT));
+ uint64_t* ptr = (uint64_t*)p_class;
+
+ uint64_t elem_count = *(ptr-1);
- for (unsigned int i=0;i<*elems;i++) {
+ for (uint64_t i=0;i<elem_count;i++) {
p_class[i].~T();
};
- Memory::free_static(elems);
+ Memory::free_static(ptr,true);
}
diff --git a/core/os/memory_pool_dynamic_prealloc.cpp b/core/os/memory_pool_dynamic_prealloc.cpp
deleted file mode 100644
index f76c2a12b4..0000000000
--- a/core/os/memory_pool_dynamic_prealloc.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*************************************************************************/
-/* memory_pool_dynamic_prealloc.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "memory_pool_dynamic_prealloc.h"
-#include "os/memory.h"
-
-#include "print_string.h"
-MemoryPoolDynamicPrealloc::ID MemoryPoolDynamicPrealloc::alloc(size_t p_amount,const char* p_description) {
-
-
-// print_line("dynpool - allocating: "+itos(p_amount));
- ID id = pool_alloc->alloc(p_amount);
-// print_line("dynpool - free: "+itos(pool_alloc->get_free_mem()));
- return id;
-
-}
-
-void MemoryPoolDynamicPrealloc::free(ID p_id) {
-
- pool_alloc->free(p_id);
-}
-
-Error MemoryPoolDynamicPrealloc::realloc(ID p_id, size_t p_amount) {
-
- return pool_alloc->resize(p_id,p_amount);
-}
-
-bool MemoryPoolDynamicPrealloc::is_valid(ID p_id) {
-
- return true;
-}
-
-size_t MemoryPoolDynamicPrealloc::get_size(ID p_id) const {
-
- return pool_alloc->get_size(p_id);
-}
-
-const char* MemoryPoolDynamicPrealloc::get_description(ID p_id) const {
-
- return "";
-}
-
-Error MemoryPoolDynamicPrealloc::lock(ID p_id) {
-
-// print_line("lock: "+itos(p_id));
- return pool_alloc->lock(p_id);
-}
-
-void * MemoryPoolDynamicPrealloc::get(ID p_ID) {
-
-// print_line("get: "+itos(p_ID));
- return pool_alloc->get(p_ID);
-}
-
-Error MemoryPoolDynamicPrealloc::unlock(ID p_id) {
-
-// print_line("unlock: "+itos(p_id));
- pool_alloc->unlock(p_id);
- return OK;
-}
-
-bool MemoryPoolDynamicPrealloc::is_locked(ID p_id) const {
-
- return pool_alloc->is_locked(p_id);
-}
-
-
-size_t MemoryPoolDynamicPrealloc::get_available_mem() const {
-
- return pool_alloc->get_free_mem();
-}
-
-size_t MemoryPoolDynamicPrealloc::get_total_usage() const {
-
- return pool_alloc->get_used_mem();
-}
-
-
-
-MemoryPoolDynamicPrealloc::MemoryPoolDynamicPrealloc(void * p_mem,int p_size, int p_align, int p_max_entries) {
-
- pool_alloc = memnew( PoolAllocator(p_mem,p_size,p_align,true,p_max_entries));
-
-}
-
-MemoryPoolDynamicPrealloc::~MemoryPoolDynamicPrealloc() {
-
-
- memdelete( pool_alloc );
-}
-
diff --git a/core/os/memory_pool_dynamic_prealloc.h b/core/os/memory_pool_dynamic_prealloc.h
deleted file mode 100644
index d2256c0c98..0000000000
--- a/core/os/memory_pool_dynamic_prealloc.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*************************************************************************/
-/* memory_pool_dynamic_prealloc.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef MEMORY_POOL_DYNAMIC_PREALLOC_H
-#define MEMORY_POOL_DYNAMIC_PREALLOC_H
-
-#include "pool_allocator.h"
-#include "core/os/memory_pool_dynamic.h"
-
-class MemoryPoolDynamicPrealloc : public MemoryPoolDynamic {
-
- PoolAllocator *pool_alloc;
-
-public:
-
- virtual ID alloc(size_t p_amount,const char* p_description);
- virtual void free(ID p_id);
- virtual Error realloc(ID p_id, size_t p_amount);
- virtual bool is_valid(ID p_id);
- virtual size_t get_size(ID p_id) const;
- virtual const char* get_description(ID p_id) const;
-
- virtual Error lock(ID p_id);
- virtual void * get(ID p_ID);
- virtual Error unlock(ID p_id);
- virtual bool is_locked(ID p_id) const;
-
- virtual size_t get_available_mem() const;
- virtual size_t get_total_usage() const;
-
- MemoryPoolDynamicPrealloc(void * p_mem,int p_size, int p_align = 16, int p_max_entries=PoolAllocator::DEFAULT_MAX_ALLOCS);
- ~MemoryPoolDynamicPrealloc();
-};
-
-#endif // MEMORY_POOL_DYNAMIC_PREALLOC_H
diff --git a/core/os/memory_pool_dynamic_static.cpp b/core/os/memory_pool_dynamic_static.cpp
deleted file mode 100644
index c047c931ec..0000000000
--- a/core/os/memory_pool_dynamic_static.cpp
+++ /dev/null
@@ -1,272 +0,0 @@
-/*************************************************************************/
-/* memory_pool_dynamic_static.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "memory_pool_dynamic_static.h"
-#include "os/memory.h"
-#include "os/os.h"
-#include "ustring.h"
-#include "print_string.h"
-#include <stdio.h>
-
-MemoryPoolDynamicStatic::Chunk *MemoryPoolDynamicStatic::get_chunk(ID p_id) {
-
- uint64_t check = p_id/MAX_CHUNKS;
- uint64_t idx = p_id%MAX_CHUNKS;
-
- if (!chunk[idx].mem || chunk[idx].check!=check)
- return NULL;
-
- return &chunk[idx];
-}
-
-
-const MemoryPoolDynamicStatic::Chunk *MemoryPoolDynamicStatic::get_chunk(ID p_id) const {
-
- uint64_t check = p_id/MAX_CHUNKS;
- uint64_t idx = p_id%MAX_CHUNKS;
-
- if (!chunk[idx].mem || chunk[idx].check!=check)
- return NULL;
-
- return &chunk[idx];
-}
-
-MemoryPoolDynamic::ID MemoryPoolDynamicStatic::alloc(size_t p_amount,const char* p_description) {
-
- _THREAD_SAFE_METHOD_
-
- int idx=-1;
-
- for (int i=0;i<MAX_CHUNKS;i++) {
-
- last_alloc++;
- if (last_alloc>=MAX_CHUNKS)
- last_alloc=0;
-
- if ( !chunk[last_alloc].mem ) {
-
- idx=last_alloc;
- break;
- }
- }
-
-
- if (idx==-1) {
- ERR_EXPLAIN("Out of dynamic Memory IDs");
- ERR_FAIL_V(INVALID_ID);
- //return INVALID_ID;
- }
-
- //chunk[idx].mem = Memory::alloc_static(p_amount,p_description);
- chunk[idx].mem = memalloc(p_amount);
- if (!chunk[idx].mem)
- return INVALID_ID;
-
- chunk[idx].size=p_amount;
- chunk[idx].check=++last_check;
- chunk[idx].descr=p_description;
- chunk[idx].lock=0;
-
- total_usage+=p_amount;
- if (total_usage>max_usage)
- max_usage=total_usage;
-
- ID id = chunk[idx].check*MAX_CHUNKS + (uint64_t)idx;
-
- return id;
-
-}
-void MemoryPoolDynamicStatic::free(ID p_id) {
-
- _THREAD_SAFE_METHOD_
-
- Chunk *c = get_chunk(p_id);
- ERR_FAIL_COND(!c);
-
-
- total_usage-=c->size;
- memfree(c->mem);
-
- c->mem=0;
-
- if (c->lock>0) {
-
- ERR_PRINT("Freed ID Still locked");
- }
-}
-
-Error MemoryPoolDynamicStatic::realloc(ID p_id, size_t p_amount) {
-
- _THREAD_SAFE_METHOD_
-
- Chunk *c = get_chunk(p_id);
- ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(c->lock > 0 , ERR_LOCKED );
-
-
- void * new_mem = memrealloc(c->mem,p_amount);
-
- ERR_FAIL_COND_V(!new_mem,ERR_OUT_OF_MEMORY);
- total_usage-=c->size;
- c->mem=new_mem;
- c->size=p_amount;
- total_usage+=c->size;
- if (total_usage>max_usage)
- max_usage=total_usage;
-
-
- return OK;
-}
-bool MemoryPoolDynamicStatic::is_valid(ID p_id) {
-
- _THREAD_SAFE_METHOD_
-
- Chunk *c = get_chunk(p_id);
-
- return c!=NULL;
-
-}
-size_t MemoryPoolDynamicStatic::get_size(ID p_id) const {
-
- _THREAD_SAFE_METHOD_
-
- const Chunk *c = get_chunk(p_id);
- ERR_FAIL_COND_V(!c,0);
-
- return c->size;
-
-
-}
-const char* MemoryPoolDynamicStatic::get_description(ID p_id) const {
-
- _THREAD_SAFE_METHOD_
-
- const Chunk *c = get_chunk(p_id);
- ERR_FAIL_COND_V(!c,"");
-
- return c->descr;
-
-}
-
-
-bool MemoryPoolDynamicStatic::is_locked(ID p_id) const {
-
- _THREAD_SAFE_METHOD_
-
- const Chunk *c = get_chunk(p_id);
- ERR_FAIL_COND_V(!c,false);
-
- return c->lock>0;
-
-}
-
-Error MemoryPoolDynamicStatic::lock(ID p_id) {
-
- _THREAD_SAFE_METHOD_
-
- Chunk *c = get_chunk(p_id);
- ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER);
-
- c->lock++;
-
- return OK;
-}
-void * MemoryPoolDynamicStatic::get(ID p_id) {
-
- _THREAD_SAFE_METHOD_
-
- const Chunk *c = get_chunk(p_id);
- ERR_FAIL_COND_V(!c,NULL);
- ERR_FAIL_COND_V( c->lock==0, NULL );
-
- return c->mem;
-}
-Error MemoryPoolDynamicStatic::unlock(ID p_id) {
-
- _THREAD_SAFE_METHOD_
-
- Chunk *c = get_chunk(p_id);
- ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER);
-
- ERR_FAIL_COND_V( c->lock<=0, ERR_INVALID_PARAMETER );
- c->lock--;
-
- return OK;
-}
-
-size_t MemoryPoolDynamicStatic::get_available_mem() const {
-
- return Memory::get_static_mem_available();
-}
-
-size_t MemoryPoolDynamicStatic::get_total_usage() const {
- _THREAD_SAFE_METHOD_
-
- return total_usage;
-}
-
-MemoryPoolDynamicStatic::MemoryPoolDynamicStatic() {
-
- last_check=1;
- last_alloc=0;
- total_usage=0;
- max_usage=0;
-}
-
-MemoryPoolDynamicStatic::~MemoryPoolDynamicStatic() {
-
-#ifdef DEBUG_MEMORY_ENABLED
-
- if (OS::get_singleton()->is_stdout_verbose()) {
-
- if (total_usage>0) {
-
- ERR_PRINT("DYNAMIC ALLOC: ** MEMORY LEAKS DETECTED **");
- ERR_PRINT(String("DYNAMIC ALLOC: "+String::num(total_usage)+" bytes of memory in use at exit.").ascii().get_data());
-
- ERR_PRINT("DYNAMIC ALLOC: Following is the list of leaked allocations:");
-
- for (int i=0;i<MAX_CHUNKS;i++) {
-
- if (chunk[i].mem) {
-
- ERR_PRINT(String("\t"+String::num(chunk[i].size)+" bytes - "+String(chunk[i].descr)).ascii().get_data());
- }
- }
-
- ERR_PRINT("DYNAMIC ALLOC: End of Report.");
-
- print_line("INFO: dynmem - max: "+itos(max_usage)+", "+itos(total_usage)+" leaked.");
- } else {
-
- print_line("INFO: dynmem - max: "+itos(max_usage)+", no leaks.");
- }
- }
-
-#endif
-}
diff --git a/core/os/memory_pool_dynamic_static.h b/core/os/memory_pool_dynamic_static.h
deleted file mode 100644
index a72d39355c..0000000000
--- a/core/os/memory_pool_dynamic_static.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*************************************************************************/
-/* memory_pool_dynamic_static.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef MEMORY_POOL_DYNAMIC_STATIC_H
-#define MEMORY_POOL_DYNAMIC_STATIC_H
-
-#include "os/memory_pool_dynamic.h"
-#include "typedefs.h"
-#include "os/thread_safe.h"
-
-class MemoryPoolDynamicStatic : public MemoryPoolDynamic {
-
- _THREAD_SAFE_CLASS_
-
- enum {
- MAX_CHUNKS=65536
- };
-
-
- struct Chunk {
-
- uint64_t lock;
- uint64_t check;
- void *mem;
- size_t size;
- const char *descr;
-
- Chunk() { mem=NULL; lock=0; check=0; }
- };
-
- Chunk chunk[MAX_CHUNKS];
- uint64_t last_check;
- int last_alloc;
- size_t total_usage;
- size_t max_usage;
-
- Chunk *get_chunk(ID p_id);
- const Chunk *get_chunk(ID p_id) const;
-public:
-
- virtual ID alloc(size_t p_amount,const char* p_description);
- virtual void free(ID p_id);
- virtual Error realloc(ID p_id, size_t p_amount);
- virtual bool is_valid(ID p_id);
- virtual size_t get_size(ID p_id) const;
- virtual const char* get_description(ID p_id) const;
-
- virtual bool is_locked(ID p_id) const;
- virtual Error lock(ID p_id);
- virtual void * get(ID p_ID);
- virtual Error unlock(ID p_id);
-
- virtual size_t get_available_mem() const;
- virtual size_t get_total_usage() const;
-
- MemoryPoolDynamicStatic();
- virtual ~MemoryPoolDynamicStatic();
-
-};
-
-#endif
diff --git a/core/os/memory_pool_static.h b/core/os/memory_pool_static.h
deleted file mode 100644
index f7f60b8df8..0000000000
--- a/core/os/memory_pool_static.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*************************************************************************/
-/* memory_pool_static.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef MEMORY_POOL_STATIC_H
-#define MEMORY_POOL_STATIC_H
-
-#include <stddef.h>
-
-#include "core/typedefs.h"
-
-/**
- @author Juan Linietsky <red@lunatea>
-*/
-class MemoryPoolStatic {
-private:
-
- static MemoryPoolStatic *singleton;
-
-public:
-
- static MemoryPoolStatic *get_singleton();
-
- virtual void* alloc(size_t p_bytes,const char *p_description)=0; ///< Pointer in p_description shold be to a const char const like "hello"
- virtual void* realloc(void * p_memory,size_t p_bytes)=0; ///< Pointer in p_description shold be to a const char const like "hello"
- virtual void free(void *p_ptr)=0; ///< Pointer in p_description shold be to a const char const
-
- virtual size_t get_available_mem() const=0;
- virtual size_t get_total_usage()=0;
- virtual size_t get_max_usage()=0;
-
- /* Most likely available only if memory debugger was compiled in */
- virtual int get_alloc_count()=0;
- virtual void * get_alloc_ptr(int p_alloc_idx)=0;
- virtual const char* get_alloc_description(int p_alloc_idx)=0;
- virtual size_t get_alloc_size(int p_alloc_idx)=0;
-
- virtual void dump_mem_to_file(const char* p_file)=0;
-
- MemoryPoolStatic();
- virtual ~MemoryPoolStatic();
-
-};
-
-#endif
diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp
index 21400d2ccf..f5f7f757c3 100644
--- a/core/os/mutex.cpp
+++ b/core/os/mutex.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/mutex.h b/core/os/mutex.h
index 5870171dc7..a1004965bb 100644
--- a/core/os/mutex.h
+++ b/core/os/mutex.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/os.cpp b/core/os/os.cpp
index ee32476234..3a8e15a692 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -27,13 +27,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "os.h"
-#include "os/file_access.h"
-#include <stdarg.h>
+
#include "dir_access.h"
#include "globals.h"
#include "input.h"
-// For get_engine_version, could be removed if it's moved to a new Engine singleton
-#include "version.h"
+#include "os/file_access.h"
+
+#include <stdarg.h>
OS* OS::singleton=NULL;
@@ -68,6 +68,7 @@ void OS::print_error(const char* p_function,const char* p_file,int p_line,const
case ERR_ERROR: err_type="**ERROR**"; break;
case ERR_WARNING: err_type="**WARNING**"; break;
case ERR_SCRIPT: err_type="**SCRIPT ERROR**"; break;
+ case ERR_SHADER: err_type="**SHADER ERROR**"; break;
}
if (p_rationale && *p_rationale)
@@ -97,23 +98,6 @@ void OS::printerr(const char* p_format, ...) {
};
-void OS::set_iterations_per_second(int p_ips) {
-
- ips=p_ips;
-}
-int OS::get_iterations_per_second() const {
-
- return ips;
-}
-
-void OS::set_target_fps(int p_fps) {
- _target_fps=p_fps>0? p_fps : 0;
-}
-
-float OS::get_target_fps() const {
- return _target_fps;
-}
-
void OS::set_keep_screen_on(bool p_enabled) {
_keep_screen_on=p_enabled;
}
@@ -151,10 +135,6 @@ int OS::get_process_ID() const {
return -1;
};
-uint64_t OS::get_frames_drawn() {
-
- return frames_drawn;
-}
bool OS::is_stdout_verbose() const {
@@ -186,7 +166,7 @@ const char *OS::get_last_error() const {
void OS::dump_memory_to_file(const char* p_file) {
- Memory::dump_static_mem_to_file(p_file);
+ //Memory::dump_static_mem_to_file(p_file);
}
static FileAccess *_OSPRF=NULL;
@@ -197,7 +177,7 @@ static void _OS_printres(Object *p_obj) {
if (!res)
return;
- String str = itos(res->get_instance_ID())+String(res->get_type())+":"+String(res->get_name())+" - "+res->get_path();
+ String str = itos(res->get_instance_ID())+String(res->get_class())+":"+String(res->get_name())+" - "+res->get_path();
if (_OSPRF)
_OSPRF->store_line(str);
else
@@ -260,15 +240,7 @@ void OS::clear_last_error() {
memfree(last_error);
last_error=NULL;
}
-void OS::set_frame_delay(uint32_t p_msec) {
- _frame_delay=p_msec;
-}
-
-uint32_t OS::get_frame_delay() const {
-
- return _frame_delay;
-}
void OS::set_no_window_mode(bool p_enable) {
@@ -296,7 +268,7 @@ String OS::get_locale() const {
String OS::get_resource_dir() const {
- return Globals::get_singleton()->get_resource_path();
+ return GlobalConfig::get_singleton()->get_resource_path();
}
@@ -306,7 +278,7 @@ String OS::get_system_dir(SystemDir p_dir) const {
}
String OS::get_safe_application_name() const {
- String an = Globals::get_singleton()->get("application/name");
+ String an = GlobalConfig::get_singleton()->get("application/name");
Vector<String> invalid_char = String("\\ / : * ? \" < > |").split(" ");
for (int i=0;i<invalid_char.size();i++) {
an = an.replace(invalid_char[i],"-");
@@ -366,16 +338,16 @@ Error OS::dialog_input_text(String p_title, String p_description, String p_parti
int OS::get_static_memory_usage() const {
- return Memory::get_static_mem_usage();
+ return Memory::get_mem_usage();
}
int OS::get_dynamic_memory_usage() const{
- return Memory::get_dynamic_mem_usage();
+ return MemoryPool::total_memory;
}
int OS::get_static_memory_peak_usage() const {
- return Memory::get_static_mem_max_usage();
+ return Memory::get_mem_max_usage();
}
Error OS::set_cwd(const String& p_cwd) {
@@ -391,7 +363,7 @@ bool OS::has_touchscreen_ui_hint() const {
int OS::get_free_static_memory() const {
- return Memory::get_static_mem_available();
+ return Memory::get_mem_available();
}
void OS::yield() {
@@ -512,27 +484,20 @@ OS::MouseMode OS::get_mouse_mode() const{
return MOUSE_MODE_VISIBLE;
}
-void OS::set_time_scale(float p_scale) {
-
- _time_scale=p_scale;
-}
OS::LatinKeyboardVariant OS::get_latin_keyboard_variant() const {
return LATIN_KEYBOARD_QWERTY;
}
-float OS::get_time_scale() const {
- return _time_scale;
-}
bool OS::is_joy_known(int p_device) {
return true;
}
String OS::get_joy_guid(int p_device) const {
- return "Default Joystick";
+ return "Default Joypad";
}
void OS::set_context(int p_context) {
@@ -542,54 +507,26 @@ void OS::set_use_vsync(bool p_enable) {
}
-bool OS::is_vsnc_enabled() const{
+bool OS::is_vsync_enabled() const{
return true;
}
-Dictionary OS::get_engine_version() const {
-
- Dictionary dict;
- dict["major"] = _MKSTR(VERSION_MAJOR);
- dict["minor"] = _MKSTR(VERSION_MINOR);
-#ifdef VERSION_PATCH
- dict["patch"] = _MKSTR(VERSION_PATCH);
-#else
- dict["patch"] = "";
-#endif
- dict["status"] = _MKSTR(VERSION_STATUS);
- dict["revision"] = _MKSTR(VERSION_REVISION);
-
- String stringver = String(dict["major"]) + "." + String(dict["minor"]);
- if (dict["patch"] != "")
- stringver += "." + String(dict["patch"]);
- stringver += "-" + String(dict["status"]) + " (" + String(dict["revision"]) + ")";
- dict["string"] = stringver;
-
- return dict;
-}
OS::OS() {
last_error=NULL;
- frames_drawn=0;
singleton=this;
- ips=60;
_keep_screen_on=true; // set default value to true, because this had been true before godot 2.0.
low_processor_usage_mode=false;
_verbose_stdout=false;
- _frame_delay=0;
_no_window=false;
_exit_code=0;
_orientation=SCREEN_LANDSCAPE;
- _fps=1;
- _target_fps=0;
+
_render_thread_mode=RENDER_THREAD_SAFE;
- _time_scale=1.0;
- _pixel_snap=false;
+
+
_allow_hidpi=true;
- _fixed_frames=0;
- _idle_frames=0;
- _in_fixed=false;
Math::seed(1234567);
}
diff --git a/core/os/os.h b/core/os/os.h
index 8e9293b3c8..ea03481a92 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,6 +32,7 @@
#include "ustring.h"
#include "list.h"
#include "vector.h"
+#include "engine.h"
#include "os/main_loop.h"
#include <stdarg.h>
@@ -43,28 +44,17 @@ class OS {
static OS* singleton;
String _execpath;
- String _custom_level;
List<String> _cmdline;
- int ips;
bool _keep_screen_on;
bool low_processor_usage_mode;
bool _verbose_stdout;
String _local_clipboard;
- uint64_t frames_drawn;
- uint32_t _frame_delay;
uint64_t _msec_splash;
bool _no_window;
int _exit_code;
int _orientation;
- float _fps;
- int _target_fps;
- float _time_scale;
- bool _pixel_snap;
bool _allow_hidpi;
- uint64_t _fixed_frames;
- uint64_t _idle_frames;
- bool _in_fixed;
char *last_error;
@@ -120,7 +110,8 @@ public:
enum ErrorType {
ERR_ERROR,
ERR_WARNING,
- ERR_SCRIPT
+ ERR_SCRIPT,
+ ERR_SHADER
};
virtual void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type=ERR_ERROR);
@@ -184,15 +175,6 @@ public:
virtual bool get_borderless_window() { return 0; }
-
- virtual void set_iterations_per_second(int p_ips);
- virtual int get_iterations_per_second() const;
-
- virtual void set_target_fps(int p_fps);
- virtual float get_target_fps() const;
-
- virtual float get_frames_per_second() const { return _fps; }
-
virtual void set_keep_screen_on(bool p_enabled);
virtual bool is_keep_screen_on() const;
virtual void set_low_processor_usage_mode(bool p_enabled);
@@ -216,7 +198,6 @@ public:
virtual MainLoop *get_main_loop() const=0;
- String get_custom_level() const { return _custom_level; }
virtual void yield();
@@ -279,17 +260,9 @@ public:
uint32_t get_ticks_msec() const;
uint64_t get_splash_tick_msec() const;
- void set_frame_delay(uint32_t p_msec);
- uint32_t get_frame_delay() const;
virtual bool can_draw() const = 0;
- uint64_t get_frames_drawn();
-
- uint64_t get_fixed_frames() const { return _fixed_frames; }
- uint64_t get_idle_frames() const { return _idle_frames; }
- bool is_in_fixed_frame() const { return _in_fixed; }
-
bool is_stdout_verbose() const;
enum CursorShape {
@@ -372,6 +345,7 @@ public:
virtual void set_screen_orientation(ScreenOrientation p_orientation);
ScreenOrientation get_screen_orientation() const;
+ virtual void enable_for_stealing_focus(ProcessID pid) {}
virtual void move_window_to_foreground() {}
virtual void debug_break();
@@ -414,10 +388,6 @@ public:
virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
- void set_time_scale(float p_scale);
- float get_time_scale() const;
-
- _FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; }
virtual bool is_joy_known(int p_device);
virtual String get_joy_guid(int p_device)const;
@@ -430,9 +400,7 @@ public:
virtual void set_context(int p_context);
virtual void set_use_vsync(bool p_enable);
- virtual bool is_vsnc_enabled() const;
-
- Dictionary get_engine_version() const;
+ virtual bool is_vsync_enabled() const;
bool is_hidpi_allowed() const { return _allow_hidpi; }
OS();
diff --git a/core/os/rw_lock.cpp b/core/os/rw_lock.cpp
new file mode 100644
index 0000000000..9b2d1f8a46
--- /dev/null
+++ b/core/os/rw_lock.cpp
@@ -0,0 +1,21 @@
+#include "rw_lock.h"
+#include "error_macros.h"
+#include <stddef.h>
+
+
+
+RWLock* (*RWLock::create_func)()=0;
+
+RWLock *RWLock::create() {
+
+ ERR_FAIL_COND_V( !create_func, 0 );
+
+ return create_func();
+}
+
+
+RWLock::~RWLock() {
+
+
+}
+
diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h
new file mode 100644
index 0000000000..c513e6d636
--- /dev/null
+++ b/core/os/rw_lock.h
@@ -0,0 +1,46 @@
+#ifndef RWLOCK_H
+#define RWLOCK_H
+
+#include "error_list.h"
+
+class RWLock {
+protected:
+ static RWLock* (*create_func)();
+
+public:
+
+ virtual void read_lock()=0; ///< Lock the rwlock, block if locked by someone else
+ virtual void read_unlock()=0; ///< Unlock the rwlock, let other threads continue
+ virtual Error read_try_lock()=0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock.
+
+ virtual void write_lock()=0; ///< Lock the rwlock, block if locked by someone else
+ virtual void write_unlock()=0; ///< Unlock the rwlock, let other thwrites continue
+ virtual Error write_try_lock()=0; ///< Attempt to lock the rwlock, OK on success, ERROR means it can't lock.
+
+ static RWLock * create(); ///< Create a rwlock
+
+ virtual ~RWLock();
+};
+
+
+class RWLockRead {
+
+ RWLock *lock;
+public:
+
+ RWLockRead(RWLock* p_lock) { lock=p_lock; if (lock) lock->read_lock(); }
+ ~RWLockRead() { if (lock) lock->read_unlock(); }
+
+};
+
+class RWLockWrite {
+
+ RWLock *lock;
+public:
+
+ RWLockWrite(RWLock* p_lock) { lock=p_lock; if (lock) lock->write_lock(); }
+ ~RWLockWrite() { if (lock) lock->write_unlock(); }
+
+};
+
+#endif // RWLOCK_H
diff --git a/core/os/semaphore.cpp b/core/os/semaphore.cpp
index 5fa2d339dc..fe476c5888 100644
--- a/core/os/semaphore.cpp
+++ b/core/os/semaphore.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/semaphore.h b/core/os/semaphore.h
index 8469408e65..e0b4460b22 100644
--- a/core/os/semaphore.h
+++ b/core/os/semaphore.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/shell.cpp b/core/os/shell.cpp
index 8737d97fa0..60f4203dbe 100644
--- a/core/os/shell.cpp
+++ b/core/os/shell.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/shell.h b/core/os/shell.h
index 8b0c286d73..f26f01846e 100644
--- a/core/os/shell.h
+++ b/core/os/shell.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/thread.cpp b/core/os/thread.cpp
index c1ae53074b..689fed7537 100644
--- a/core/os/thread.cpp
+++ b/core/os/thread.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/thread.h b/core/os/thread.h
index 5f0ec707f2..23ed76d486 100644
--- a/core/os/thread.h
+++ b/core/os/thread.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/thread_dummy.cpp b/core/os/thread_dummy.cpp
index 30a0e2696c..93a020b7a8 100644
--- a/core/os/thread_dummy.cpp
+++ b/core/os/thread_dummy.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h
index 800eef9ef9..01e366e2fa 100644
--- a/core/os/thread_dummy.h
+++ b/core/os/thread_dummy.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/thread_safe.cpp b/core/os/thread_safe.cpp
index a742b1144e..a0bfb86c82 100644
--- a/core/os/thread_safe.cpp
+++ b/core/os/thread_safe.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/os/thread_safe.h b/core/os/thread_safe.h
index 1c82cbe704..c9a832b41b 100644
--- a/core/os/thread_safe.h
+++ b/core/os/thread_safe.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index 91f886ff4b..5f3b877822 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -82,7 +82,7 @@ Variant PackedDataContainer::_iter_get_ofs(const Variant& p_iter,uint32_t p_offs
if (pos<0 || pos>=size)
return Variant();
- DVector<uint8_t>::Read rd=data.read();
+ PoolVector<uint8_t>::Read rd=data.read();
const uint8_t *r=&rd[p_offset];
uint32_t type = decode_uint32(r);
@@ -131,7 +131,7 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs,const uint8_t *p_buf,boo
uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
- DVector<uint8_t>::Read rd=data.read();
+ PoolVector<uint8_t>::Read rd=data.read();
const uint8_t *r=&rd[p_ofs];
uint32_t type = decode_uint32(r);
@@ -140,7 +140,7 @@ uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
int PackedDataContainer::_size(uint32_t p_ofs) const {
- DVector<uint8_t>::Read rd=data.read();
+ PoolVector<uint8_t>::Read rd=data.read();
const uint8_t *r=&rd[p_ofs];
uint32_t type = decode_uint32(r);
@@ -160,7 +160,7 @@ int PackedDataContainer::_size(uint32_t p_ofs) const {
Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs,const Variant& p_key,bool &err) const {
- DVector<uint8_t>::Read rd=data.read();
+ PoolVector<uint8_t>::Read rd=data.read();
const uint8_t *r=&rd[p_ofs];
uint32_t type = decode_uint32(r);
@@ -239,21 +239,21 @@ uint32_t PackedDataContainer::_pack(const Variant& p_data, Vector<uint8_t>& tmpd
case Variant::VECTOR2:
case Variant::RECT2:
case Variant::VECTOR3:
- case Variant::MATRIX32:
+ case Variant::TRANSFORM2D:
case Variant::PLANE:
case Variant::QUAT:
- case Variant::_AABB:
- case Variant::MATRIX3:
+ case Variant::RECT3:
+ case Variant::BASIS:
case Variant::TRANSFORM:
case Variant::IMAGE:
case Variant::INPUT_EVENT:
- case Variant::RAW_ARRAY:
- case Variant::INT_ARRAY:
- case Variant::REAL_ARRAY:
- case Variant::STRING_ARRAY:
- case Variant::VECTOR2_ARRAY:
- case Variant::VECTOR3_ARRAY:
- case Variant::COLOR_ARRAY:
+ case Variant::POOL_BYTE_ARRAY:
+ case Variant::POOL_INT_ARRAY:
+ case Variant::POOL_REAL_ARRAY:
+ case Variant::POOL_STRING_ARRAY:
+ case Variant::POOL_VECTOR2_ARRAY:
+ case Variant::POOL_VECTOR3_ARRAY:
+ case Variant::POOL_COLOR_ARRAY:
case Variant::NODE_PATH: {
uint32_t pos = tmpdata.size();
@@ -344,21 +344,21 @@ Error PackedDataContainer::pack(const Variant& p_data) {
_pack(p_data,tmpdata,string_cache);
datalen=tmpdata.size();
data.resize(tmpdata.size());
- DVector<uint8_t>::Write w = data.write();
+ PoolVector<uint8_t>::Write w = data.write();
copymem(w.ptr(),tmpdata.ptr(),tmpdata.size());
return OK;
}
-void PackedDataContainer::_set_data(const DVector<uint8_t>& p_data) {
+void PackedDataContainer::_set_data(const PoolVector<uint8_t>& p_data) {
data=p_data;
datalen=data.size();
}
-DVector<uint8_t> PackedDataContainer::_get_data() const {
+PoolVector<uint8_t> PackedDataContainer::_get_data() const {
return data;
}
@@ -382,15 +382,15 @@ Variant PackedDataContainer::_iter_get(const Variant& p_iter){
void PackedDataContainer::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("_set_data"),&PackedDataContainer::_set_data);
- ObjectTypeDB::bind_method(_MD("_get_data"),&PackedDataContainer::_get_data);
- ObjectTypeDB::bind_method(_MD("_iter_init"),&PackedDataContainer::_iter_init);
- ObjectTypeDB::bind_method(_MD("_iter_get"),&PackedDataContainer::_iter_get);
- ObjectTypeDB::bind_method(_MD("_iter_next"),&PackedDataContainer::_iter_next);
- ObjectTypeDB::bind_method(_MD("pack:Error","value"),&PackedDataContainer::pack);
- ObjectTypeDB::bind_method(_MD("size"),&PackedDataContainer::size);
+ ClassDB::bind_method(_MD("_set_data"),&PackedDataContainer::_set_data);
+ ClassDB::bind_method(_MD("_get_data"),&PackedDataContainer::_get_data);
+ ClassDB::bind_method(_MD("_iter_init"),&PackedDataContainer::_iter_init);
+ ClassDB::bind_method(_MD("_iter_get"),&PackedDataContainer::_iter_get);
+ ClassDB::bind_method(_MD("_iter_next"),&PackedDataContainer::_iter_next);
+ ClassDB::bind_method(_MD("pack:Error","value"),&PackedDataContainer::pack);
+ ClassDB::bind_method(_MD("size"),&PackedDataContainer::size);
- ADD_PROPERTY( PropertyInfo(Variant::RAW_ARRAY,"__data__"),_SCS("_set_data"),_SCS("_get_data"));
+ ADD_PROPERTY( PropertyInfo(Variant::POOL_BYTE_ARRAY,"__data__"),_SCS("_set_data"),_SCS("_get_data"));
}
@@ -426,11 +426,11 @@ bool PackedDataContainerRef::_is_dictionary() const {
void PackedDataContainerRef::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("size"),&PackedDataContainerRef::size);
- ObjectTypeDB::bind_method(_MD("_iter_init"),&PackedDataContainerRef::_iter_init);
- ObjectTypeDB::bind_method(_MD("_iter_get"),&PackedDataContainerRef::_iter_get);
- ObjectTypeDB::bind_method(_MD("_iter_next"),&PackedDataContainerRef::_iter_next);
- ObjectTypeDB::bind_method(_MD("_is_dictionary"),&PackedDataContainerRef::_is_dictionary);
+ ClassDB::bind_method(_MD("size"),&PackedDataContainerRef::size);
+ ClassDB::bind_method(_MD("_iter_init"),&PackedDataContainerRef::_iter_init);
+ ClassDB::bind_method(_MD("_iter_get"),&PackedDataContainerRef::_iter_get);
+ ClassDB::bind_method(_MD("_iter_next"),&PackedDataContainerRef::_iter_next);
+ ClassDB::bind_method(_MD("_is_dictionary"),&PackedDataContainerRef::_is_dictionary);
}
diff --git a/core/packed_data_container.h b/core/packed_data_container.h
index 9183dcb90e..f8ff43f9b0 100644
--- a/core/packed_data_container.h
+++ b/core/packed_data_container.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,7 +36,7 @@
class PackedDataContainer : public Resource {
- OBJ_TYPE(PackedDataContainer,Resource);
+ GDCLASS(PackedDataContainer,Resource);
enum {
TYPE_DICT=0xFFFFFFFF,
@@ -50,7 +50,7 @@ class PackedDataContainer : public Resource {
};
- DVector<uint8_t> data;
+ PoolVector<uint8_t> data;
int datalen;
@@ -73,8 +73,8 @@ friend class PackedDataContainerRef;
protected:
- void _set_data(const DVector<uint8_t>& p_data);
- DVector<uint8_t> _get_data() const;
+ void _set_data(const PoolVector<uint8_t>& p_data);
+ PoolVector<uint8_t> _get_data() const;
static void _bind_methods();
public:
@@ -87,7 +87,7 @@ public:
};
class PackedDataContainerRef : public Reference {
- OBJ_TYPE(PackedDataContainerRef,Reference);
+ GDCLASS(PackedDataContainerRef,Reference);
friend class PackedDataContainer;
uint32_t offset;
diff --git a/core/pair.h b/core/pair.h
index 9bffc37f49..d75cbed642 100644
--- a/core/pair.h
+++ b/core/pair.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,6 +34,9 @@ struct Pair {
F first;
S second;
+
+ Pair() {}
+ Pair( F p_first, S p_second) { first=p_first; second=p_second; }
};
#endif // PAIR_H
diff --git a/core/path_db.cpp b/core/path_db.cpp
index 132cc83a35..25f62ed951 100644
--- a/core/path_db.cpp
+++ b/core/path_db.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/path_db.h b/core/path_db.h
index 3a550fe1d0..db756c3420 100644
--- a/core/path_db.h
+++ b/core/path_db.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/path_remap.cpp b/core/path_remap.cpp
index 8f189187f2..42383e212d 100644
--- a/core/path_remap.cpp
+++ b/core/path_remap.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -124,13 +124,13 @@ void PathRemap::clear_remaps() {
void PathRemap::load_remaps() {
// default remaps first
- DVector<String> remaps = Globals::get_singleton()->get("remap/all");
+ PoolVector<String> remaps = GlobalConfig::get_singleton()->get("remap/all");
{
int rlen = remaps.size();
ERR_FAIL_COND( rlen%2 );
- DVector<String>::Read r = remaps.read();
+ PoolVector<String>::Read r = remaps.read();
for(int i=0;i<rlen/2;i++) {
String from = r[i*2+0];
@@ -141,18 +141,18 @@ void PathRemap::load_remaps() {
// platform remaps second, so override
- remaps = Globals::get_singleton()->get("remap/"+OS::get_singleton()->get_name());
-// remaps = Globals::get_singleton()->get("remap/PSP");
+ remaps = GlobalConfig::get_singleton()->get("remap/"+OS::get_singleton()->get_name());
+ //remaps = Globals::get_singleton()->get("remap/PSP");
{
int rlen = remaps.size();
ERR_FAIL_COND( rlen%2 );
- DVector<String>::Read r = remaps.read();
+ 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);
+ //print_line("add remap: "+from+" -> "+to);
add_remap(from,to);
}
}
@@ -160,17 +160,17 @@ void PathRemap::load_remaps() {
//locale based remaps
- if (Globals::get_singleton()->has("locale/translation_remaps")) {
+ if (GlobalConfig::get_singleton()->has("locale/translation_remaps")) {
- Dictionary remaps = Globals::get_singleton()->get("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();
- StringArray sa = remaps[E->get()];
+ PoolStringArray sa = remaps[E->get()];
int sas = sa.size();
- StringArray::Read r = sa.read();
+ PoolStringArray::Read r = sa.read();
for(int i=0;i<sas;i++) {
@@ -190,11 +190,11 @@ void PathRemap::load_remaps() {
void PathRemap::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("add_remap","from","to","locale"),&PathRemap::add_remap,DEFVAL(String()));
- ObjectTypeDB::bind_method(_MD("has_remap","path"),&PathRemap::has_remap);
- ObjectTypeDB::bind_method(_MD("get_remap","path"),&PathRemap::get_remap);
- ObjectTypeDB::bind_method(_MD("erase_remap","path"),&PathRemap::erase_remap);
- ObjectTypeDB::bind_method(_MD("clear_remaps"),&PathRemap::clear_remaps);
+ 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() {
diff --git a/core/path_remap.h b/core/path_remap.h
index 66ebe7987b..a106030f95 100644
--- a/core/path_remap.h
+++ b/core/path_remap.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,7 +36,7 @@
class PathRemap : public Object {
- OBJ_TYPE(PathRemap,Object);
+ GDCLASS(PathRemap,Object);
static PathRemap* singleton;
struct RemapData {
diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp
index 9f5fcf5f50..e425218060 100644
--- a/core/pool_allocator.cpp
+++ b/core/pool_allocator.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -604,7 +604,7 @@ void PoolAllocator::create_pool(void * p_mem,int p_size,int p_max_entries) {
PoolAllocator::PoolAllocator(int p_size,bool p_needs_locking,int p_max_entries) {
- mem_ptr=Memory::alloc_static( p_size,"PoolAllocator()");
+ mem_ptr=memalloc( p_size);
ERR_FAIL_COND(!mem_ptr);
align=1;
create_pool(mem_ptr,p_size,p_max_entries);
@@ -648,7 +648,7 @@ PoolAllocator::PoolAllocator(int p_align,int p_size,bool p_needs_locking,int p_m
PoolAllocator::~PoolAllocator() {
if (mem_ptr)
- Memory::free_static( mem_ptr );
+ memfree( mem_ptr );
memdelete_arr( entry_array );
memdelete_arr( entry_indices );
diff --git a/core/pool_allocator.h b/core/pool_allocator.h
index 438548bfe4..a5911688f7 100644
--- a/core/pool_allocator.h
+++ b/core/pool_allocator.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/print_string.cpp b/core/print_string.cpp
index b6154f1cf6..3faed62bb4 100644
--- a/core/print_string.cpp
+++ b/core/print_string.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/print_string.h b/core/print_string.h
index 0aa5b4c8e9..a13abd4e38 100644
--- a/core/print_string.h
+++ b/core/print_string.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/ref_ptr.cpp b/core/ref_ptr.cpp
index dee2b9a164..e781bae496 100644
--- a/core/ref_ptr.cpp
+++ b/core/ref_ptr.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/ref_ptr.h b/core/ref_ptr.h
index 68788b73cd..c9824639dc 100644
--- a/core/ref_ptr.h
+++ b/core/ref_ptr.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/reference.cpp b/core/reference.cpp
index 34f36a5735..69e053cc1a 100644
--- a/core/reference.cpp
+++ b/core/reference.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -54,9 +54,9 @@ bool Reference::init_ref() {
void Reference::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("init_ref"),&Reference::init_ref);
- ObjectTypeDB::bind_method(_MD("reference"),&Reference::reference);
- ObjectTypeDB::bind_method(_MD("unreference"),&Reference::unreference);
+ ClassDB::bind_method(_MD("init_ref"),&Reference::init_ref);
+ ClassDB::bind_method(_MD("reference"),&Reference::reference);
+ ClassDB::bind_method(_MD("unreference"),&Reference::unreference);
}
int Reference::reference_get_count() const {
@@ -126,7 +126,7 @@ WeakRef::WeakRef() {
void WeakRef::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("get_ref:Object"),&WeakRef::get_ref);
+ ClassDB::bind_method(_MD("get_ref:Object"),&WeakRef::get_ref);
}
#if 0
diff --git a/core/reference.h b/core/reference.h
index 89e9627b77..ce196801bb 100644
--- a/core/reference.h
+++ b/core/reference.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -39,7 +39,7 @@
*/
class Reference : public Object{
- OBJ_TYPE( Reference, Object );
+ GDCLASS( Reference, Object );
friend class RefBase;
SafeRefCount refcount;
SafeRefCount refcount_init;
@@ -315,7 +315,7 @@ typedef Ref<Reference> REF;
class WeakRef : public Reference {
- OBJ_TYPE(WeakRef,Reference);
+ GDCLASS(WeakRef,Reference);
ObjectID ref;
protected:
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 7e4ba039c5..85fa5d27c0 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,6 +34,7 @@
#include "os/main_loop.h"
#include "io/packet_peer.h"
#include "math/a_star.h"
+#include "math/triangle_mesh.h"
#include "globals.h"
#include "object_type_db.h"
#include "geometry.h"
@@ -43,21 +44,17 @@
#include "translation.h"
#include "compressed_translation.h"
#include "io/translation_loader_po.h"
-#include "io/resource_format_xml.h"
#include "io/resource_format_binary.h"
#include "io/stream_peer_ssl.h"
#include "os/input.h"
#include "core/io/xml_parser.h"
#include "io/http_client.h"
+#include "io/pck_packer.h"
#include "packed_data_container.h"
#include "func_ref.h"
#include "input_map.h"
#include "undo_redo.h"
-#ifdef XML_ENABLED
-static ResourceFormatSaverXML *resource_saver_xml=NULL;
-static ResourceFormatLoaderXML *resource_loader_xml=NULL;
-#endif
static ResourceFormatSaverBinary *resource_saver_binary=NULL;
static ResourceFormatLoaderBinary *resource_loader_binary=NULL;
@@ -65,6 +62,8 @@ static ResourceFormatLoaderBinary *resource_loader_binary=NULL;
static _ResourceLoader *_resource_loader=NULL;
static _ResourceSaver *_resource_saver=NULL;
static _OS *_os=NULL;
+static _Engine *_engine=NULL;
+static _ClassDB *_classdb=NULL;
static _Marshalls *_marshalls = NULL;
static TranslationLoaderPO *resource_format_po=NULL;
@@ -82,6 +81,9 @@ extern void unregister_variant_methods();
void register_core_types() {
+ ObjectDB::setup();
+ ResourceCache::setup();
+ MemoryPool::setup();
_global_mutex=Mutex::create();
@@ -103,52 +105,48 @@ void register_core_types() {
resource_loader_binary = memnew( ResourceFormatLoaderBinary );
ResourceLoader::add_resource_format_loader(resource_loader_binary);
-#ifdef XML_ENABLED
- resource_saver_xml = memnew( ResourceFormatSaverXML );
- ResourceSaver::add_resource_format_saver(resource_saver_xml);
- resource_loader_xml = memnew( ResourceFormatLoaderXML );
- ResourceLoader::add_resource_format_loader(resource_loader_xml);
-#endif
-
- ObjectTypeDB::register_type<Object>();
-
-
- ObjectTypeDB::register_type<Reference>();
- ObjectTypeDB::register_type<WeakRef>();
- ObjectTypeDB::register_type<ResourceImportMetadata>();
- ObjectTypeDB::register_type<Resource>();
- ObjectTypeDB::register_type<FuncRef>();
- ObjectTypeDB::register_virtual_type<StreamPeer>();
- ObjectTypeDB::register_type<StreamPeerBuffer>();
- ObjectTypeDB::register_create_type<StreamPeerTCP>();
- ObjectTypeDB::register_create_type<TCP_Server>();
- ObjectTypeDB::register_create_type<PacketPeerUDP>();
- ObjectTypeDB::register_create_type<StreamPeerSSL>();
- ObjectTypeDB::register_virtual_type<IP>();
- ObjectTypeDB::register_virtual_type<PacketPeer>();
- ObjectTypeDB::register_type<PacketPeerStream>();
- ObjectTypeDB::register_type<MainLoop>();
-// ObjectTypeDB::register_type<OptimizedSaver>();
- ObjectTypeDB::register_type<Translation>();
- ObjectTypeDB::register_type<PHashTranslation>();
- ObjectTypeDB::register_type<UndoRedo>();
- ObjectTypeDB::register_type<HTTPClient>();
-
- ObjectTypeDB::register_virtual_type<ResourceInteractiveLoader>();
-
- ObjectTypeDB::register_type<_File>();
- ObjectTypeDB::register_type<_Directory>();
- ObjectTypeDB::register_type<_Thread>();
- ObjectTypeDB::register_type<_Mutex>();
- ObjectTypeDB::register_type<_Semaphore>();
-
- ObjectTypeDB::register_type<XMLParser>();
-
- ObjectTypeDB::register_type<ConfigFile>();
-
- ObjectTypeDB::register_type<PackedDataContainer>();
- ObjectTypeDB::register_virtual_type<PackedDataContainerRef>();
- ObjectTypeDB::register_type<AStar>();
+ 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>();
+ ClassDB::register_class<StreamPeerBuffer>();
+ ClassDB::register_custom_instance_class<StreamPeerTCP>();
+ ClassDB::register_custom_instance_class<TCP_Server>();
+ ClassDB::register_custom_instance_class<PacketPeerUDP>();
+ ClassDB::register_custom_instance_class<StreamPeerSSL>();
+ ClassDB::register_virtual_class<IP>();
+ ClassDB::register_virtual_class<PacketPeer>();
+ ClassDB::register_class<PacketPeerStream>();
+ ClassDB::register_class<MainLoop>();
+ //ClassDB::register_type<OptimizedSaver>();
+ ClassDB::register_class<Translation>();
+ ClassDB::register_class<PHashTranslation>();
+ ClassDB::register_class<UndoRedo>();
+ ClassDB::register_class<HTTPClient>();
+ ClassDB::register_class<TriangleMesh>();
+
+ ClassDB::register_virtual_class<ResourceInteractiveLoader>();
+
+ ClassDB::register_class<_File>();
+ ClassDB::register_class<_Directory>();
+ ClassDB::register_class<_Thread>();
+ ClassDB::register_class<_Mutex>();
+ ClassDB::register_class<_Semaphore>();
+
+ ClassDB::register_class<XMLParser>();
+
+ ClassDB::register_class<ConfigFile>();
+
+ ClassDB::register_class<PCKPacker>();
+
+ ClassDB::register_class<PackedDataContainer>();
+ ClassDB::register_virtual_class<PackedDataContainerRef>();
+ ClassDB::register_class<AStar>();
ip = IP::create();
@@ -159,26 +157,37 @@ void register_core_types() {
_resource_loader=memnew(_ResourceLoader);
_resource_saver=memnew(_ResourceSaver);
_os=memnew(_OS);
+ _engine=memnew(_Engine);
+ _classdb=memnew(_ClassDB);
_marshalls = memnew(_Marshalls);
}
+void register_core_settings() {
+ //since in register core types, globals may not e present
+ GLOBAL_DEF( "network/packets/packet_stream_peer_max_buffer_po2",(16));
+
+}
+
void register_core_singletons() {
- Globals::get_singleton()->add_singleton( Globals::Singleton("Globals",Globals::get_singleton()) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("IP",IP::get_singleton()) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("Geometry",_Geometry::get_singleton()) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("ResourceLoader",_ResourceLoader::get_singleton()) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("ResourceSaver",_ResourceSaver::get_singleton()) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("PathRemap",PathRemap::get_singleton() ) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("OS",_OS::get_singleton() ) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("Marshalls",_marshalls ) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("TranslationServer",TranslationServer::get_singleton() ) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("TS",TranslationServer::get_singleton() ) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("Input",Input::get_singleton() ) );
- Globals::get_singleton()->add_singleton( Globals::Singleton("InputMap",InputMap::get_singleton() ) );
+
+ GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("GlobalConfig",GlobalConfig::get_singleton()) );
+ GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("IP",IP::get_singleton()) );
+ 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() ) );
}
@@ -190,15 +199,11 @@ void unregister_core_types() {
memdelete( _resource_loader );
memdelete( _resource_saver );
memdelete( _os);
+ memdelete( _engine );
+ memdelete( _classdb );
memdelete( _marshalls );
memdelete( _geometry );
-#ifdef XML_ENABLED
- if (resource_saver_xml)
- memdelete(resource_saver_xml);
- if (resource_loader_xml)
- memdelete(resource_loader_xml);
-#endif
if (resource_saver_binary)
memdelete(resource_saver_binary);
@@ -216,7 +221,7 @@ void unregister_core_types() {
unregister_variant_methods();
- ObjectTypeDB::cleanup();
+ ClassDB::cleanup();
ResourceCache::clear();
CoreStringNames::free();
StringName::cleanup();
@@ -225,4 +230,7 @@ void unregister_core_types() {
memdelete(_global_mutex);
_global_mutex=NULL; //still needed at a few places
};
+
+ MemoryPool::cleanup();
+
}
diff --git a/core/register_core_types.h b/core/register_core_types.h
index 239d67f1ec..c664d0ebf4 100644
--- a/core/register_core_types.h
+++ b/core/register_core_types.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,6 +34,7 @@
*/
void register_core_types();
+void register_core_settings();
void register_core_singletons();
void unregister_core_types();
diff --git a/core/resource.cpp b/core/resource.cpp
index e8d4069779..3369e4a5a2 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,6 +31,7 @@
#include <stdio.h>
#include "os/file_access.h"
#include "io/resource_loader.h"
+#include "script_language.h"
void ResourceImportMetadata::set_editor(const String& p_editor) {
@@ -112,9 +113,9 @@ void ResourceImportMetadata::get_options(List<String> *r_options) const {
}
-StringArray ResourceImportMetadata::_get_options() const {
+PoolStringArray ResourceImportMetadata::_get_options() const {
- StringArray option_names;
+ PoolStringArray option_names;
option_names.resize(options.size());
int i=0;
for(Map<String,Variant>::Element *E=options.front();E;E=E->next()) {
@@ -127,17 +128,17 @@ StringArray ResourceImportMetadata::_get_options() const {
void ResourceImportMetadata::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_editor","name"),&ResourceImportMetadata::set_editor);
- ObjectTypeDB::bind_method(_MD("get_editor"),&ResourceImportMetadata::get_editor);
- ObjectTypeDB::bind_method(_MD("add_source","path","md5"),&ResourceImportMetadata::add_source, "");
- ObjectTypeDB::bind_method(_MD("get_source_path","idx"),&ResourceImportMetadata::get_source_path);
- ObjectTypeDB::bind_method(_MD("get_source_md5","idx"),&ResourceImportMetadata::get_source_md5);
- ObjectTypeDB::bind_method(_MD("set_source_md5","idx", "md5"),&ResourceImportMetadata::set_source_md5);
- ObjectTypeDB::bind_method(_MD("remove_source","idx"),&ResourceImportMetadata::remove_source);
- ObjectTypeDB::bind_method(_MD("get_source_count"),&ResourceImportMetadata::get_source_count);
- ObjectTypeDB::bind_method(_MD("set_option","key","value"),&ResourceImportMetadata::set_option);
- ObjectTypeDB::bind_method(_MD("get_option","key"),&ResourceImportMetadata::get_option);
- ObjectTypeDB::bind_method(_MD("get_options"),&ResourceImportMetadata::_get_options);
+ 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() {
@@ -164,17 +165,31 @@ void Resource::set_path(const String& p_path, bool p_take_over) {
if (path_cache!="") {
+ ResourceCache::lock->write_lock();
ResourceCache::resources.erase(path_cache);
+ ResourceCache::lock->write_unlock();
}
path_cache="";
- if (ResourceCache::resources.has( p_path )) {
+
+ ResourceCache::lock->read_lock();
+ bool has_path = ResourceCache::resources.has( p_path );
+ ResourceCache::lock->read_unlock();
+
+ if (has_path) {
if (p_take_over) {
+ ResourceCache::lock->write_lock();
ResourceCache::resources.get(p_path)->set_name("");
+ ResourceCache::lock->write_unlock();
} else {
ERR_EXPLAIN("Another resource is loaded from path: "+p_path);
- ERR_FAIL_COND( ResourceCache::resources.has( p_path ) );
+
+ ResourceCache::lock->read_lock();
+ bool exists = ResourceCache::resources.has( p_path );
+ ResourceCache::lock->read_unlock();
+
+ ERR_FAIL_COND( exists );
}
}
@@ -182,10 +197,12 @@ void Resource::set_path(const String& p_path, bool p_take_over) {
if (path_cache!="") {
+ ResourceCache::lock->write_lock();
ResourceCache::resources[path_cache]=this;;
+ ResourceCache::lock->write_unlock();
}
- _change_notify("resource/path");
+ _change_notify("resource_path");
_resource_path_changed();
}
@@ -209,7 +226,7 @@ int Resource::get_subindex() const{
void Resource::set_name(const String& p_name) {
name=p_name;
- _change_notify("resource/name");
+ _change_notify("resource_name");
}
String Resource::get_name() const {
@@ -229,7 +246,7 @@ void Resource::reload_from_file() {
if (!path.is_resource_file())
return;
- Ref<Resource> s = ResourceLoader::load(path,get_type(),true);
+ Ref<Resource> s = ResourceLoader::load(path,get_class(),true);
if (!s.is_valid())
return;
@@ -241,7 +258,7 @@ void Resource::reload_from_file() {
if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
continue;
- if (E->get().name=="resource/path")
+ if (E->get().name=="resource_path")
continue; //do not change path
set(E->get().name,s->get(E->get().name));
@@ -250,13 +267,56 @@ void Resource::reload_from_file() {
}
+Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) {
+
+
+ List<PropertyInfo> plist;
+ get_property_list(&plist);
+
+
+ Resource *r = (Resource*)ClassDB::instance(get_class());
+ ERR_FAIL_COND_V(!r,Ref<Resource>());
+
+ r->local_scene=p_for_scene;
+
+ for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
+
+ if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
+ continue;
+ Variant p = get(E->get().name);
+ if (p.get_type()==Variant::OBJECT) {
+
+ RES sr = p;
+ if (sr.is_valid()) {
+
+ if (sr->is_local_to_scene()) {
+ if (remap_cache.has(sr)) {
+ p=remap_cache[sr];
+ } else {
+
+
+ RES dupe = sr->duplicate_for_local_scene(p_for_scene,remap_cache);
+ p=dupe;
+ remap_cache[sr]=dupe;
+ }
+ }
+ }
+ }
+
+ r->set(E->get().name,p);
+ }
+
+ return Ref<Resource>(r);
+}
+
Ref<Resource> Resource::duplicate(bool p_subresources) {
+
List<PropertyInfo> plist;
get_property_list(&plist);
- Resource *r = (Resource*)ObjectTypeDB::instance(get_type());
+ Resource *r = (Resource*)ClassDB::instance(get_class());
ERR_FAIL_COND_V(!r,Ref<Resource>());
for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
@@ -289,23 +349,6 @@ void Resource::_take_over_path(const String& p_path) {
}
-void Resource::_bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("set_path","path"),&Resource::_set_path);
- ObjectTypeDB::bind_method(_MD("take_over_path","path"),&Resource::_take_over_path);
- ObjectTypeDB::bind_method(_MD("get_path"),&Resource::get_path);
- ObjectTypeDB::bind_method(_MD("set_name","name"),&Resource::set_name);
- ObjectTypeDB::bind_method(_MD("get_name"),&Resource::get_name);
- ObjectTypeDB::bind_method(_MD("get_rid"),&Resource::get_rid);
- ObjectTypeDB::bind_method(_MD("set_import_metadata","metadata"),&Resource::set_import_metadata);
- ObjectTypeDB::bind_method(_MD("get_import_metadata"),&Resource::get_import_metadata);
-
- ObjectTypeDB::bind_method(_MD("duplicate","subresources"),&Resource::duplicate,DEFVAL(false));
- ADD_SIGNAL( MethodInfo("changed") );
- ADD_PROPERTY( PropertyInfo(Variant::STRING,"resource/path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR ), _SCS("set_path"),_SCS("get_path"));
- ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"resource/name"), _SCS("set_name"),_SCS("get_name"));
-}
-
RID Resource::get_rid() const {
return RID();
@@ -377,6 +420,62 @@ uint32_t Resource::hash_edited_version() const {
#endif
+void Resource::set_local_to_scene(bool p_enable) {
+
+ local_to_scene=p_enable;
+}
+
+bool Resource::is_local_to_scene() const {
+
+ return local_to_scene;
+}
+
+Node* Resource::get_local_scene() const {
+
+ if (local_scene)
+ return local_scene;
+
+ if (_get_local_scene_func) {
+ return _get_local_scene_func();
+ }
+
+ return NULL;
+}
+
+void Resource::setup_local_to_scene() {
+
+ if (get_script_instance())
+ get_script_instance()->call("_setup_local_to_scene");
+}
+
+Node* (*Resource::_get_local_scene_func)()=NULL;
+
+
+void Resource::_bind_methods() {
+
+ ClassDB::bind_method(_MD("set_path","path"),&Resource::_set_path);
+ ClassDB::bind_method(_MD("take_over_path","path"),&Resource::_take_over_path);
+ ClassDB::bind_method(_MD("get_path"),&Resource::get_path);
+ 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);
+ ClassDB::bind_method(_MD("setup_local_to_scene"),&Resource::setup_local_to_scene);
+
+ ClassDB::bind_method(_MD("duplicate","subresources"),&Resource::duplicate,DEFVAL(false));
+ ADD_SIGNAL( MethodInfo("changed") );
+ ADD_GROUP("Resource","resource_");
+ ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"resource_local_to_scene" ), _SCS("set_local_to_scene"),_SCS("is_local_to_scene"));
+ ADD_PROPERTY( PropertyInfo(Variant::STRING,"resource_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR ), _SCS("set_path"),_SCS("get_path"));
+ ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"resource_name"), _SCS("set_name"),_SCS("get_name"));
+
+ BIND_VMETHOD( MethodInfo("_setup_local_to_scene") );
+
+}
Resource::Resource() {
@@ -385,6 +484,7 @@ Resource::Resource() {
#endif
subindex=0;
+ local_scene=NULL;
}
@@ -392,8 +492,11 @@ Resource::Resource() {
Resource::~Resource() {
- if (path_cache!="")
+ if (path_cache!="") {
+ ResourceCache::lock->write_lock();
ResourceCache::resources.erase(path_cache);
+ ResourceCache::lock->write_unlock();
+ }
if (owners.size()) {
WARN_PRINT("Resource is still owned");
}
@@ -401,36 +504,49 @@ Resource::~Resource() {
HashMap<String,Resource*> ResourceCache::resources;
+RWLock *ResourceCache::lock=NULL;
+
+void ResourceCache::setup() {
+
+ lock = RWLock::create();
+}
+
void ResourceCache::clear() {
if (resources.size())
ERR_PRINT("Resources Still in use at Exit!");
resources.clear();
+ memdelete(lock);
}
void ResourceCache::reload_externals() {
- GLOBAL_LOCK_FUNCTION
-
- //const String *K=NULL;
- //while ((K=resources.next(K))) {
-// resources[*K]->reload_external_data();
-// }
-
+ /*
+ const String *K=NULL;
+ while ((K=resources.next(K))) {
+ resources[*K]->reload_external_data();
+ }
+ */
}
bool ResourceCache::has(const String& p_path) {
- GLOBAL_LOCK_FUNCTION
+ lock->read_lock();;
+ bool b = resources.has(p_path);
+ lock->read_unlock();;
+
- return resources.has(p_path);
+ return b;
}
Resource *ResourceCache::get(const String& p_path) {
- GLOBAL_LOCK_FUNCTION
+ lock->read_lock();
Resource **res = resources.getptr(p_path);
+
+ lock->read_unlock();
+
if (!res) {
return NULL;
}
@@ -442,6 +558,7 @@ Resource *ResourceCache::get(const String& p_path) {
void ResourceCache::get_cached_resources(List<Ref<Resource> > *p_resources) {
+ lock->read_lock();
const String* K=NULL;
while((K=resources.next(K))) {
@@ -449,17 +566,22 @@ void ResourceCache::get_cached_resources(List<Ref<Resource> > *p_resources) {
p_resources->push_back( Ref<Resource>( r ));
}
+ lock->read_unlock();
}
int ResourceCache::get_cached_resource_count() {
- return resources.size();
+ lock->read_lock();
+ int rc = resources.size();
+ lock->read_unlock();
+
+ return rc;
}
void ResourceCache::dump(const char* p_file,bool p_short) {
#ifdef DEBUG_ENABLED
- GLOBAL_LOCK_FUNCTION
+ lock->read_lock();
Map<String,int> type_count;
@@ -476,16 +598,16 @@ void ResourceCache::dump(const char* p_file,bool p_short) {
Resource *r = resources[*K];
- if (!type_count.has(r->get_type())) {
- type_count[r->get_type()]=0;
+ if (!type_count.has(r->get_class())) {
+ type_count[r->get_class()]=0;
}
- type_count[r->get_type()]++;
+ type_count[r->get_class()]++;
if (!p_short) {
if (f)
- f->store_line(r->get_type()+": "+r->get_path());
+ f->store_line(r->get_class()+": "+r->get_path());
}
}
@@ -499,5 +621,7 @@ void ResourceCache::dump(const char* p_file,bool p_short) {
memdelete(f);
}
+ lock->read_unlock();
+
#endif
}
diff --git a/core/resource.h b/core/resource.h
index 0673a4e89d..284c59e1a8 100644
--- a/core/resource.h
+++ b/core/resource.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -41,14 +41,14 @@
#define RES_BASE_EXTENSION(m_ext)\
public:\
-static void register_custom_data_to_otdb() { ObjectTypeDB::add_resource_base_extension(m_ext,get_type_static()); }\
+static void register_custom_data_to_otdb() { ClassDB::add_resource_base_extension(m_ext,get_class_static()); }\
virtual String get_base_extension() const { return m_ext; }\
private:
class ResourceImportMetadata : public Reference {
- OBJ_TYPE( ResourceImportMetadata, Reference );
+ GDCLASS( ResourceImportMetadata, Reference );
struct Source {
String path;
@@ -60,9 +60,10 @@ class ResourceImportMetadata : public Reference {
Map<String,Variant> options;
- StringArray _get_options() const;
+ PoolStringArray _get_options() const;
+
protected:
- virtual bool _use_builtin_script() const { return false; }
+
static void _bind_methods();
public:
@@ -82,13 +83,14 @@ public:
void get_options(List<String> *r_options) const;
+
ResourceImportMetadata();
};
class Resource : public Reference {
- OBJ_TYPE( Resource, Reference );
+ GDCLASS( Resource, Reference );
OBJ_CATEGORY("Resources");
RES_BASE_EXTENSION("res");
@@ -108,6 +110,10 @@ friend class ResourceCache;
uint64_t last_modified_time;
#endif
+ bool local_to_scene;
+friend class SceneState;
+ Node* local_scene;
+
protected:
void emit_changed();
@@ -121,6 +127,8 @@ protected:
void _take_over_path(const String& p_path);
public:
+ static Node* (*_get_local_scene_func)(); //used by editor
+
virtual bool editor_can_reload_from_file();
virtual void reload_from_file();
@@ -137,12 +145,17 @@ public:
int get_subindex() const;
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();
-
+ Node* get_local_scene() const;
#ifdef TOOLS_ENABLED
@@ -165,9 +178,12 @@ typedef Ref<Resource> RES;
class ResourceCache {
friend class Resource;
+ static RWLock *lock;
static HashMap<String,Resource*> resources;
friend void unregister_core_types();
static void clear();
+friend void register_core_types();
+ static void setup();
public:
static void reload_externals();
diff --git a/core/rid.cpp b/core/rid.cpp
index 219c2f0e69..c7e487f91a 100644
--- a/core/rid.cpp
+++ b/core/rid.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -28,18 +28,16 @@
/*************************************************************************/
#include "rid.h"
-static SafeRefCount current_id;
-void RID_OwnerBase::init_rid() {
+RID_Data::~RID_Data() {
- current_id.init(1);
}
-ID RID_OwnerBase::new_ID() {
+SafeRefCount RID_OwnerBase::refcount;
- ID id = current_id.refval();
- return id;
-}
+void RID_OwnerBase::init_rid() {
+ refcount.init();
+}
diff --git a/core/rid.h b/core/rid.h
index 2de6956096..8dc535c9c1 100644
--- a/core/rid.h
+++ b/core/rid.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,183 +33,197 @@
#include "safe_refcount.h"
#include "typedefs.h"
#include "os/memory.h"
-#include "hash_map.h"
+#include "set.h"
#include "list.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class RID_OwnerBase;
-typedef uint32_t ID;
+class RID_Data {
+
+friend class RID_OwnerBase;
+
+#ifndef DEBUG_ENABLED
+ RID_OwnerBase *_owner;
+#endif
+ uint32_t _id;
+public:
+ _FORCE_INLINE_ uint32_t get_id() const { return _id; }
+
+ virtual ~RID_Data();
+};
+
class RID {
friend class RID_OwnerBase;
- ID _id;
- RID_OwnerBase *owner;
+
+ mutable RID_Data *_data;
+
public:
- _FORCE_INLINE_ ID get_id() const { return _id; }
- bool operator==(const RID& p_rid) const {
+ _FORCE_INLINE_ RID_Data *get_data() const { return _data; }
+
+ _FORCE_INLINE_ bool operator==(const RID& p_rid) const {
- return _id==p_rid._id;
+ return _data==p_rid._data;
}
_FORCE_INLINE_ bool operator<(const RID& p_rid) const {
- return _id < p_rid._id;
+ return _data < p_rid._data;
}
_FORCE_INLINE_ bool operator<=(const RID& p_rid) const {
- return _id <= p_rid._id;
+ return _data <= p_rid._data;
}
_FORCE_INLINE_ bool operator>(const RID& p_rid) const {
- return _id > p_rid._id;
+ return _data > p_rid._data;
}
- bool operator!=(const RID& p_rid) const {
+ _FORCE_INLINE_ bool operator!=(const RID& p_rid) const {
- return _id!=p_rid._id;
+ return _data!=p_rid._data;
}
- _FORCE_INLINE_ bool is_valid() const { return _id>0; }
+ _FORCE_INLINE_ bool is_valid() const { return _data!=NULL; }
- operator const void*() const {
- return is_valid() ? this : 0;
- };
+ _FORCE_INLINE_ uint32_t get_id() const { return _data?_data->get_id():0; }
_FORCE_INLINE_ RID() {
- _id = 0;
- owner=0;
+ _data=NULL;
}
+
};
class RID_OwnerBase {
protected:
-friend class RID;
- void set_id(RID& p_rid, ID p_id) const { p_rid._id=p_id; }
- void set_ownage(RID& p_rid) const { p_rid.owner=const_cast<RID_OwnerBase*>(this); }
- ID new_ID();
+
+ static SafeRefCount refcount;
+ _FORCE_INLINE_ void _set_data(RID& p_rid, RID_Data* p_data) {
+ p_rid._data=p_data;
+ refcount.ref();
+ p_data->_id=refcount.get();
+#ifndef DEBUG_ENABLED
+ p_data->_owner=this;
+#endif
+ }
+
+#ifndef DEBUG_ENABLED
+
+ _FORCE_INLINE_ bool _is_owner(const RID& p_rid) const {
+
+ return this==p_rid._data->_owner;
+
+ }
+
+ _FORCE_INLINE_ void _remove_owner(RID& p_rid) {
+
+ p_rid._data->_owner=NULL;
+
+ }
+#
+#endif
+
+
public:
- virtual bool owns(const RID& p_rid) const=0;
- virtual void get_owned_list(List<RID> *p_owned) const=0;
- static void init_rid();
+ virtual void get_owned_list(List<RID> *p_owned)=0;
+ static void init_rid();
virtual ~RID_OwnerBase() {}
};
-template<class T,bool thread_safe=false>
+template<class T>
class RID_Owner : public RID_OwnerBase {
public:
-
- typedef void (*ReleaseNotifyFunc)(void*user,T *p_data);
-private:
-
- Mutex *mutex;
- mutable HashMap<ID,T*> id_map;
-
+#ifdef DEBUG_ENABLED
+ mutable Set<RID_Data*> id_map;
+#endif
public:
- RID make_rid(T * p_data) {
+ _FORCE_INLINE_ RID make_rid(T * p_data) {
- if (thread_safe) {
- mutex->lock();
- }
- ID id = new_ID();
- id_map[id]=p_data;
RID rid;
- set_id(rid,id);
- set_ownage(rid);
+ _set_data(rid,p_data);
- if (thread_safe) {
- mutex->unlock();
- }
+#ifdef DEBUG_ENABLED
+ id_map.insert(p_data) ;
+#endif
return rid;
}
_FORCE_INLINE_ T * get(const RID& p_rid) {
- if (thread_safe) {
- mutex->lock();
- }
-
- T**elem = id_map.getptr(p_rid.get_id());
+#ifdef DEBUG_ENABLED
- if (thread_safe) {
- mutex->unlock();
- }
-
- ERR_FAIL_COND_V(!elem,NULL);
-
- return *elem;
+ ERR_FAIL_COND_V(!p_rid.is_valid(),NULL);
+ ERR_FAIL_COND_V(!id_map.has(p_rid.get_data()),NULL);
+#endif
+ return static_cast<T*>(p_rid.get_data());
}
- virtual bool owns(const RID& p_rid) const {
+ _FORCE_INLINE_ T * getornull(const RID& p_rid) {
- if (thread_safe) {
- mutex->lock();
- }
-
- T**elem = id_map.getptr(p_rid.get_id());
+#ifdef DEBUG_ENABLED
- if (thread_safe) {
- mutex->lock();
+ if (p_rid.get_data()) {
+ ERR_FAIL_COND_V(!id_map.has(p_rid.get_data()),NULL);
}
+#endif
+ return static_cast<T*>(p_rid.get_data());
- return elem!=NULL;
}
- virtual void free(RID p_rid) {
- if (thread_safe) {
- mutex->lock();
- }
- ERR_FAIL_COND(!owns(p_rid));
- id_map.erase(p_rid.get_id());
- }
- virtual void get_owned_list(List<RID> *p_owned) const {
-
- if (thread_safe) {
- mutex->lock();
- }
+ _FORCE_INLINE_ T * getptr(const RID& p_rid) {
- const ID*id=NULL;
- while((id=id_map.next(id))) {
+ return static_cast<T*>(p_rid.get_data());
- RID rid;
- set_id(rid,*id);
- set_ownage(rid);
- p_owned->push_back(rid);
+ }
- }
- if (thread_safe) {
- mutex->lock();
- }
+ _FORCE_INLINE_ bool owns(const RID& p_rid) const {
+ if (p_rid.get_data()==NULL)
+ return false;
+#ifdef DEBUG_ENABLED
+ return id_map.has(p_rid.get_data());
+#else
+ return _is_owner(p_rid);
+#endif
}
- RID_Owner() {
- if (thread_safe) {
-
- mutex = Mutex::create();
- }
+ void free(RID p_rid) {
+#ifdef DEBUG_ENABLED
+ id_map.erase(p_rid.get_data());
+#else
+ _remove_owner(p_rid);
+#endif
}
+ void get_owned_list(List<RID> *p_owned) {
+
- ~RID_Owner() {
- if (thread_safe) {
+#ifdef DEBUG_ENABLED
- memdelete(mutex);
+ for (typename Set<RID_Data*>::Element *E=id_map.front();E;E=E->next()) {
+ RID r;
+ _set_data(r,static_cast<T*>(E->get()));
+ p_owned->push_back(r);
}
+#endif
+
}
+
};
diff --git a/core/ring_buffer.h b/core/ring_buffer.h
index 7d78fac660..a4da0086e0 100644
--- a/core/ring_buffer.h
+++ b/core/ring_buffer.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp
index 9736f96f34..ede37bbe8a 100644
--- a/core/safe_refcount.cpp
+++ b/core/safe_refcount.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,27 +29,85 @@
#include "safe_refcount.h"
+// Atomic functions, these are used for multithread safe reference counters!
+
+#ifdef NO_THREADS
+
+
+uint32_t atomic_conditional_increment( register uint32_t * pw ) {
+
+ if (*pw==0)
+ return 0;
+
+ (*pw)++;
+
+ return *pw;
+}
+
+uint32_t atomic_decrement( register uint32_t * pw ) {
+
+ (*pw)--;
+
+ return *pw;
+
+}
+
+#else
+
#ifdef _MSC_VER
// don't pollute my namespace!
#include <windows.h>
-long atomic_conditional_increment( register long * pw ) {
+uint32_t atomic_conditional_increment( register uint32_t * pw ) {
/* try to increment until it actually works */
// taken from boost
while (true) {
- long tmp = static_cast< long const volatile& >( *pw );
+ uint32_t tmp = static_cast< uint32_t const volatile& >( *pw );
if( tmp == 0 )
- return 0; // if zero, can't add to it anymore
- if( InterlockedCompareExchange( pw, tmp + 1, tmp ) == tmp )
+ return 0; // if zero, can't add to it anymore
+ if( InterlockedCompareExchange( (LONG volatile*)pw, tmp + 1, tmp ) == tmp )
return tmp+1;
}
+}
+uint32_t atomic_decrement( register uint32_t * pw ) {
+ return InterlockedDecrement( (LONG volatile*)pw );
}
-long atomic_decrement( register long * pw ) {
- return InterlockedDecrement( pw );
+uint32_t atomic_increment( register uint32_t * pw ) {
+ return InterlockedIncrement( (LONG volatile*)pw );
}
+#elif defined(__GNUC__)
+
+uint32_t atomic_conditional_increment( register uint32_t * pw ) {
+
+ while (true) {
+ uint32_t tmp = static_cast< uint32_t const volatile& >( *pw );
+ if( tmp == 0 )
+ return 0; // if zero, can't add to it anymore
+ if( __sync_val_compare_and_swap( pw, tmp, tmp + 1 ) == tmp )
+ return tmp+1;
+ }
+}
+
+uint32_t atomic_decrement( register uint32_t * pw ) {
+
+ return __sync_sub_and_fetch(pw,1);
+
+}
+
+uint32_t atomic_increment( register uint32_t * pw ) {
+
+ return __sync_add_and_fetch(pw,1);
+
+}
+
+#else
+ //no threads supported?
+#error Must provide atomic functions for this platform or compiler!
+
+#endif
#endif
diff --git a/core/safe_refcount.h b/core/safe_refcount.h
index d976458c1d..6e349d89d8 100644
--- a/core/safe_refcount.h
+++ b/core/safe_refcount.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,309 +33,18 @@
/* x86/x86_64 GCC */
#include "platform_config.h"
+#include "typedefs.h"
-#ifdef NO_THREADS
-
-struct SafeRefCount {
-
- int count;
-
-public:
-
- // destroy() is called when weak_count_ drops to zero.
-
- bool ref() { //true on success
-
- if (count==0)
- return false;
- count++;
-
- return true;
- }
-
- int refval() { //true on success
-
- if (count==0)
- return 0;
- count++;
- return count;
- }
-
- bool unref() { // true if must be disposed of
-
- if (count>0)
- count--;
-
- return count==0;
- }
-
- long get() const { // nothrow
-
- return static_cast<int const volatile &>( count );
- }
-
- void init(int p_value=1) {
-
- count=p_value;
- };
-
-};
-
-
-
-
-
-
-
-
-#else
-
-#if defined( PLATFORM_REFCOUNT )
-
-#include "platform_refcount.h"
-
-
-#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
-
-#define REFCOUNT_T volatile int
-#define REFCOUNT_GET_T int const volatile&
-
-static inline int atomic_conditional_increment( volatile int * pw ) {
- // int rv = *pw;
- // if( rv != 0 ) ++*pw;
- // return rv;
-
- int rv, tmp;
-
- __asm__
- (
- "movl %0, %%eax\n\t"
- "0:\n\t"
- "test %%eax, %%eax\n\t"
- "je 1f\n\t"
- "movl %%eax, %2\n\t"
- "incl %2\n\t"
- "lock\n\t"
- "cmpxchgl %2, %0\n\t"
- "jne 0b\n\t"
- "1:":
- "=m"( *pw ), "=&a"( rv ), "=&r"( tmp ): // outputs (%0, %1, %2)
- "m"( *pw ): // input (%3)
- "cc" // clobbers
- );
-
- return rv;
-}
-
-static inline int atomic_decrement( volatile int *pw) {
-
- // return --(*pw);
-
- unsigned char rv;
-
- __asm__
- (
- "lock\n\t"
- "decl %0\n\t"
- "setne %1":
- "=m" (*pw), "=qm" (rv):
- "m" (*pw):
- "memory"
- );
- return static_cast<int>(rv);
-}
-
-/* PowerPC32/64 GCC */
-
-#elif ( defined( __GNUC__ ) ) && ( defined( __powerpc__ ) || defined( __ppc__ ) )
-
-#define REFCOUNT_T int
-#define REFCOUNT_GET_T int const volatile&
-
-inline int atomic_conditional_increment( int * pw )
-{
- // if( *pw != 0 ) ++*pw;
- // return *pw;
-
- int rv;
-
- __asm__
- (
- "0:\n\t"
- "lwarx %1, 0, %2\n\t"
- "cmpwi %1, 0\n\t"
- "beq 1f\n\t"
- "addi %1, %1, 1\n\t"
- "1:\n\t"
- "stwcx. %1, 0, %2\n\t"
- "bne- 0b":
-
- "=m"( *pw ), "=&b"( rv ):
- "r"( pw ), "m"( *pw ):
- "cc"
- );
-
- return rv;
-}
-
-
-inline int atomic_decrement( int * pw )
-{
- // return --*pw;
-
- int rv;
-
- __asm__ __volatile__
- (
- "sync\n\t"
- "0:\n\t"
- "lwarx %1, 0, %2\n\t"
- "addi %1, %1, -1\n\t"
- "stwcx. %1, 0, %2\n\t"
- "bne- 0b\n\t"
- "isync":
-
- "=m"( *pw ), "=&b"( rv ):
- "r"( pw ), "m"( *pw ):
- "memory", "cc"
- );
-
- return rv;
-}
-
-/* CW ARM */
-
-#elif defined( __GNUC__ ) && ( defined( __arm__ ) )
-
-#define REFCOUNT_T int
-#define REFCOUNT_GET_T int const volatile&
-
-inline int atomic_conditional_increment(volatile int* v)
-{
- int t;
- int tmp;
-
- __asm__ __volatile__(
- "1: ldrex %0, [%2] \n"
- " cmp %0, #0 \n"
- " beq 2f \n"
- " add %0, %0, #1 \n"
- "2: \n"
- " strex %1, %0, [%2] \n"
- " cmp %1, #0 \n"
- " bne 1b \n"
-
- : "=&r" (t), "=&r" (tmp)
- : "r" (v)
- : "cc", "memory");
-
- return t;
-}
-
-
-inline int atomic_decrement(volatile int* v)
-{
- int t;
- int tmp;
-
- __asm__ __volatile__(
- "1: ldrex %0, [%2] \n"
- " add %0, %0, #-1 \n"
- " strex %1, %0, [%2] \n"
- " cmp %1, #0 \n"
- " bne 1b \n"
-
- : "=&r" (t), "=&r" (tmp)
- : "r" (v)
- : "cc", "memory");
-
- return t;
-}
-
-
-
-/* CW PPC */
-
-#elif ( defined( __MWERKS__ ) ) && defined( __POWERPC__ )
-
-inline long atomic_conditional_increment( register long * pw )
-{
- register int a;
-
- asm
- {
- loop:
-
- lwarx a, 0, pw
- cmpwi a, 0
- beq store
-
- addi a, a, 1
-
- store:
-
- stwcx. a, 0, pw
- bne- loop
- }
-
- return a;
-}
-
-
-inline long atomic_decrement( register long * pw )
-{
- register int a;
-
- asm {
-
- sync
-
- loop:
-
- lwarx a, 0, pw
- addi a, a, -1
- stwcx. a, 0, pw
- bne- loop
-
- isync
- }
-
- return a;
-}
-
-/* Any Windows (MSVC) */
-
-#elif defined( _MSC_VER )
-
-// made functions to not pollute namespace..
-
-#define REFCOUNT_T long
-#define REFCOUNT_GET_T long const volatile&
-
-long atomic_conditional_increment( register long * pw );
-long atomic_decrement( register long * pw );
-
-#if 0
-#elif defined( __GNUC__ ) && defined( ARMV6_ENABLED)
-
-
-#endif
-
-
-
-
-#else
-
-#error This platform cannot use safe refcount, compile with NO_THREADS or implement it.
-
-#endif
+uint32_t atomic_conditional_increment( register uint32_t * counter );
+uint32_t atomic_decrement( register uint32_t * pw );
+uint32_t atomic_increment( register uint32_t * pw );
struct SafeRefCount {
- REFCOUNT_T count;
+ uint32_t count;
public:
@@ -346,7 +55,7 @@ public:
return atomic_conditional_increment( &count ) != 0;
}
- int refval() { //true on success
+ uint32_t refval() { //true on success
return atomic_conditional_increment( &count );
}
@@ -360,20 +69,18 @@ public:
return false;
}
- long get() const { // nothrow
+ uint32_t get() const { // nothrow
- return static_cast<REFCOUNT_GET_T>( count );
+ return count;
}
- void init(int p_value=1) {
+ void init(uint32_t p_value=1) {
count=p_value;
- };
+ }
};
-#endif // no thread safe
-
#endif
diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp
index dfff54378a..a8d77668f5 100644
--- a/core/script_debugger_local.cpp
+++ b/core/script_debugger_local.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/script_debugger_local.h b/core/script_debugger_local.h
index ffe8dce445..6e2057ef45 100644
--- a/core/script_debugger_local.h
+++ b/core/script_debugger_local.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp
index 1ac0907967..bb0109467e 100644
--- a/core/script_debugger_remote.cpp
+++ b/core/script_debugger_remote.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -66,7 +66,7 @@ Error ScriptDebuggerRemote::connect_to_host(const String& p_host,uint16_t p_port
int port = p_port;
int tries = 3;
- tcp_client->connect(ip, port);
+ tcp_client->connect_to_host(ip, port);
while (tries--) {
@@ -129,11 +129,13 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script,bool p_can_continue) {
//or when execution is paused from editor
- if (!tcp_client->is_connected()) {
+ if (!tcp_client->is_connected_to_host()) {
ERR_EXPLAIN("Script Debugger failed to connect, but being used anyway.");
ERR_FAIL();
}
+ OS::get_singleton()->enable_for_stealing_focus(GlobalConfig::get_singleton()->get("editor_pid"));
+
packet_peer_stream->put_var("debug_enter");
packet_peer_stream->put_var(2);
packet_peer_stream->put_var(p_can_continue);
@@ -273,6 +275,7 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script,bool p_can_continue) {
set_depth(-1);
set_lines_left(-1);
+ OS::get_singleton()->move_window_to_foreground();
break;
} else if (command=="break") {
ERR_PRINT("Got break when already broke!");
@@ -443,7 +446,7 @@ void ScriptDebuggerRemote::_err_handler(void* ud,const char* p_func,const char*p
sdr->mutex->lock();
- if (!sdr->locking && sdr->tcp_client->is_connected()) {
+ if (!sdr->locking && sdr->tcp_client->is_connected_to_host()) {
sdr->errors.push_back(oe);
}
@@ -572,8 +575,8 @@ void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) {
packet_peer_stream->put_var("message:inspect_object");
packet_peer_stream->put_var(props_to_send*5+4);
packet_peer_stream->put_var(p_id);
- packet_peer_stream->put_var(obj->get_type());
- if (obj->is_type("Resource") || obj->is_type("Node"))
+ packet_peer_stream->put_var(obj->get_class());
+ if (obj->is_class("Resource") || obj->is_class("Node"))
packet_peer_stream->put_var(obj->call("get_path"));
else
packet_peer_stream->put_var("");
@@ -775,7 +778,7 @@ void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) {
}
- packet_peer_stream->put_var(OS::get_singleton()->get_frames_drawn()); //total frame time
+ packet_peer_stream->put_var(Engine::get_singleton()->get_frames_drawn()); //total frame time
packet_peer_stream->put_var(frame_time); //total frame time
packet_peer_stream->put_var(idle_time); //idle frame time
packet_peer_stream->put_var(fixed_time); //fixed frame time
@@ -884,7 +887,7 @@ void ScriptDebuggerRemote::idle_poll() {
void ScriptDebuggerRemote::send_message(const String& p_message, const Array &p_args) {
mutex->lock();
- if (!locking && tcp_client->is_connected()) {
+ if (!locking && tcp_client->is_connected_to_host()) {
Message msg;
msg.message=p_message;
@@ -925,7 +928,7 @@ void ScriptDebuggerRemote::_print_handler(void *p_this,const String& p_string) {
}
sdr->mutex->lock();
- if (!sdr->locking && sdr->tcp_client->is_connected()) {
+ if (!sdr->locking && sdr->tcp_client->is_connected_to_host()) {
sdr->output_strings.push_back(s);
}
@@ -1006,12 +1009,12 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() {
phl.userdata=this;
add_print_handler(&phl);
requested_quit=false;
- performance = Globals::get_singleton()->get_singleton_object("Performance");
+ performance = GlobalConfig::get_singleton()->get_singleton_object("Performance");
last_perf_time=0;
poll_every=0;
request_scene_tree=NULL;
live_edit_funcs=NULL;
- max_cps = GLOBAL_DEF("debug/max_remote_stdout_chars_per_second",2048);
+ max_cps = GLOBAL_DEF("network/debug/max_remote_stdout_chars_per_second",2048);
char_count=0;
msec_count=0;
last_msec=0;
@@ -1021,7 +1024,7 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() {
eh.userdata=this;
add_error_handler(&eh);
- profile_info.resize(CLAMP(int(Globals::get_singleton()->get("debug/profiler_max_functions")),128,65535));
+ profile_info.resize(CLAMP(int(GlobalConfig::get_singleton()->get("debug/profiler/max_functions")),128,65535));
profile_info_ptrs.resize(profile_info.size());
profiling=false;
max_frame_functions=16;
diff --git a/core/script_debugger_remote.h b/core/script_debugger_remote.h
index c6a00e189f..4b991e2f0c 100644
--- a/core/script_debugger_remote.h
+++ b/core/script_debugger_remote.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/script_language.cpp b/core/script_language.cpp
index fa1d01d3eb..52ae181c32 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -46,13 +46,13 @@ void Script::_notification( int p_what) {
void Script::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("can_instance"),&Script::can_instance);
- //ObjectTypeDB::bind_method(_MD("instance_create","base_object"),&Script::instance_create);
- ObjectTypeDB::bind_method(_MD("instance_has","base_object"),&Script::instance_has);
- ObjectTypeDB::bind_method(_MD("has_source_code"),&Script::has_source_code);
- ObjectTypeDB::bind_method(_MD("get_source_code"),&Script::get_source_code);
- ObjectTypeDB::bind_method(_MD("set_source_code","source"),&Script::set_source_code);
- ObjectTypeDB::bind_method(_MD("reload","keep_state"),&Script::reload,DEFVAL(false));
+ ClassDB::bind_method(_MD("can_instance"),&Script::can_instance);
+ //ClassDB::bind_method(_MD("instance_create","base_object"),&Script::instance_create);
+ ClassDB::bind_method(_MD("instance_has","base_object"),&Script::instance_has);
+ ClassDB::bind_method(_MD("has_source_code"),&Script::has_source_code);
+ ClassDB::bind_method(_MD("get_source_code"),&Script::get_source_code);
+ ClassDB::bind_method(_MD("set_source_code","source"),&Script::set_source_code);
+ ClassDB::bind_method(_MD("reload","keep_state"),&Script::reload,DEFVAL(false));
}
diff --git a/core/script_language.h b/core/script_language.h
index 53af4c74d1..fd96541b18 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -77,7 +77,7 @@ class PlaceHolderScriptInstance;
class Script : public Resource {
- OBJ_TYPE( Script, Resource );
+ GDCLASS( Script, Resource );
OBJ_SAVE_TYPE( Script );
protected:
@@ -207,7 +207,7 @@ public:
virtual Script *create_script() const=0;
virtual bool has_named_classes() const=0;
virtual int find_function(const String& p_function,const String& p_code) const=0;
- virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const=0;
+ virtual String make_function(const String& p_class,const String& p_name,const PoolStringArray& p_args) const=0;
virtual Error complete_code(const String& p_code, const String& p_base_path, Object*p_owner,List<String>* r_options,String& r_call_hint) { return ERR_UNAVAILABLE; }
diff --git a/core/self_list.h b/core/self_list.h
index bfdcfbfbc2..aec3c33adc 100644
--- a/core/self_list.h
+++ b/core/self_list.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/set.h b/core/set.h
index d4d19129d4..13c2b3a4f6 100644
--- a/core/set.h
+++ b/core/set.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -141,7 +141,7 @@ private:
#ifdef GLOBALNIL_DISABLED
memdelete_allocator<Element,A>(_nil);
#endif
-// memdelete_allocator<Element,A>(_root);
+ //memdelete_allocator<Element,A>(_root);
}
};
@@ -307,7 +307,7 @@ private:
new_node->right=_data._nil;
new_node->left=_data._nil;
new_node->value=p_value;
-// new_node->data=_data;
+ //new_node->data=_data;
if (new_parent==_data._root || less(p_value,new_parent->value)) {
new_parent->left=new_node;
diff --git a/core/simple_type.h b/core/simple_type.h
index 1754deec71..6d4a1ba455 100644
--- a/core/simple_type.h
+++ b/core/simple_type.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/sort.h b/core/sort.h
index 2070065a0d..fd3b57251a 100644
--- a/core/sort.h
+++ b/core/sort.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/string_db.cpp b/core/string_db.cpp
index bf92c4eac4..be35a44ed1 100644
--- a/core/string_db.cpp
+++ b/core/string_db.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -41,9 +41,12 @@ StringName _scs_create(const char *p_chr) {
}
bool StringName::configured=false;
+Mutex* StringName::lock=NULL;
void StringName::setup() {
+ lock = Mutex::create();
+
ERR_FAIL_COND(configured);
for(int i=0;i<STRING_TABLE_LEN;i++) {
@@ -54,7 +57,8 @@ void StringName::setup() {
void StringName::cleanup() {
- _global_lock();
+ lock->lock();
+
int lost_strings=0;
for(int i=0;i<STRING_TABLE_LEN;i++) {
@@ -78,7 +82,9 @@ void StringName::cleanup() {
if (OS::get_singleton()->is_stdout_verbose() && lost_strings) {
print_line("StringName: "+itos(lost_strings)+" unclaimed string names at exit.");
}
- _global_unlock();
+ lock->unlock();
+
+ memdelete(lock);
}
void StringName::unref() {
@@ -87,7 +93,7 @@ void StringName::unref() {
if (_data && _data->refcount.unref()) {
- _global_lock();
+ lock->lock();
if (_data->prev) {
_data->prev->next=_data->next;
@@ -103,7 +109,7 @@ void StringName::unref() {
}
memdelete(_data);
- _global_unlock();
+ lock->unlock();
}
_data=NULL;
@@ -186,7 +192,7 @@ StringName::StringName(const char *p_name) {
if (!p_name || p_name[0]==0)
return; //empty, ignore
- _global_lock();
+ lock->lock();
uint32_t hash = String::hash(p_name);
@@ -206,7 +212,7 @@ StringName::StringName(const char *p_name) {
if (_data) {
if (_data->refcount.ref()) {
// exists
- _global_unlock();
+ lock->unlock();
return;
} else {
@@ -226,8 +232,7 @@ StringName::StringName(const char *p_name) {
_table[idx]=_data;
- _global_unlock();
-
+ lock->unlock();
}
StringName::StringName(const StaticCString& p_static_string) {
@@ -238,7 +243,7 @@ StringName::StringName(const StaticCString& p_static_string) {
ERR_FAIL_COND( !p_static_string.ptr || !p_static_string.ptr[0]);
- _global_lock();
+ lock->lock();
uint32_t hash = String::hash(p_static_string.ptr);
@@ -258,7 +263,7 @@ StringName::StringName(const StaticCString& p_static_string) {
if (_data) {
if (_data->refcount.ref()) {
// exists
- _global_unlock();
+ lock->unlock();
return;
} else {
@@ -278,7 +283,8 @@ StringName::StringName(const StaticCString& p_static_string) {
_table[idx]=_data;
- _global_unlock();
+ lock->unlock();
+
}
@@ -292,7 +298,7 @@ StringName::StringName(const String& p_name) {
if (p_name==String())
return;
- _global_lock();
+ lock->lock();
uint32_t hash = p_name.hash();
@@ -311,7 +317,7 @@ StringName::StringName(const String& p_name) {
if (_data) {
if (_data->refcount.ref()) {
// exists
- _global_unlock();
+ lock->unlock();
return;
} else {
@@ -332,7 +338,7 @@ StringName::StringName(const String& p_name) {
_table[idx]->prev=_data;
_table[idx]=_data;
- _global_unlock();
+ lock->unlock();
}
@@ -344,7 +350,7 @@ StringName StringName::search(const char *p_name) {
if (!p_name[0])
return StringName();
- _global_lock();
+ lock->lock();
uint32_t hash = String::hash(p_name);
@@ -361,12 +367,13 @@ StringName StringName::search(const char *p_name) {
}
if (_data && _data->refcount.ref()) {
- _global_unlock();
+ lock->unlock();
+
return StringName(_data);
}
- _global_unlock();
+ lock->unlock();
return StringName(); //does not exist
@@ -380,7 +387,7 @@ StringName StringName::search(const CharType *p_name) {
if (!p_name[0])
return StringName();
- _global_lock();
+ lock->lock();
uint32_t hash = String::hash(p_name);
@@ -397,12 +404,12 @@ StringName StringName::search(const CharType *p_name) {
}
if (_data && _data->refcount.ref()) {
- _global_unlock();
+ lock->unlock();
return StringName(_data);
}
- _global_unlock();
+ lock->unlock();
return StringName(); //does not exist
}
@@ -410,7 +417,7 @@ StringName StringName::search(const String &p_name) {
ERR_FAIL_COND_V( p_name=="", StringName() );
- _global_lock();
+ lock->lock();
uint32_t hash = p_name.hash();
@@ -427,12 +434,12 @@ StringName StringName::search(const String &p_name) {
}
if (_data && _data->refcount.ref()) {
- _global_unlock();
+ lock->unlock();
return StringName(_data);
}
- _global_unlock();
+ lock->unlock();
return StringName(); //does not exist
}
diff --git a/core/string_db.h b/core/string_db.h
index 43bcccc902..a14cdbc7ba 100644
--- a/core/string_db.h
+++ b/core/string_db.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,7 +32,7 @@
#include "hash_map.h"
#include "ustring.h"
#include "safe_refcount.h"
-
+#include "os/mutex.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -83,6 +83,7 @@ class StringName {
friend void register_core_types();
friend void unregister_core_types();
+ static Mutex *lock;
static void setup();
static void cleanup();
static bool configured;
diff --git a/core/translation.cpp b/core/translation.cpp
index 4592d00598..5215e5f6d1 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -292,6 +292,7 @@ static const char* locale_list[]={
"pa_PK", // Panjabi (Pakistan)
"pl", // Polish
"pl_PL", // Polish (Poland)
+"pr", // Pirate
"ps_AF", // Pushto (Afghanistan)
"pt", // Portuguese
"pt_BR", // Portuguese (Brazil)
@@ -308,6 +309,7 @@ static const char* locale_list[]={
"sa_IN", // Sanskrit (India)
"sat_IN", // Santali (India)
"sc_IT", // Sardinian (Italy)
+"sco", // Scots
"sd_IN", // Sindhi (India)
"se_NO", // Northern Sami (Norway)
"sgs_LT", // Samogitian (Lithuania)
@@ -650,6 +652,7 @@ static const char* locale_names[]={
"Panjabi (Pakistan)",
"Polish",
"Polish (Poland)",
+"Pirate",
"Pushto (Afghanistan)",
"Portuguese",
"Portuguese (Brazil)",
@@ -779,6 +782,11 @@ Vector<String> TranslationServer::get_all_locale_names(){
}
+static String get_trimmed_locale(const String& p_locale) {
+
+ return p_locale.substr(0,2);
+}
+
static bool is_valid_locale(const String& p_locale) {
const char **ptr=locale_list;
@@ -792,9 +800,9 @@ static bool is_valid_locale(const String& p_locale) {
return false;
}
-DVector<String> Translation::_get_messages() const {
+PoolVector<String> Translation::_get_messages() const {
- DVector<String> msgs;
+ PoolVector<String> msgs;
msgs.resize(translation_map.size()*2);
int idx=0;
for (const Map<StringName, StringName>::Element *E=translation_map.front();E;E=E->next()) {
@@ -807,9 +815,9 @@ DVector<String> Translation::_get_messages() const {
return msgs;
}
-DVector<String> Translation::_get_message_list() const {
+PoolVector<String> Translation::_get_message_list() const {
- DVector<String> msgs;
+ PoolVector<String> msgs;
msgs.resize(translation_map.size());
int idx=0;
for (const Map<StringName, StringName>::Element *E=translation_map.front();E;E=E->next()) {
@@ -822,12 +830,12 @@ DVector<String> Translation::_get_message_list() const {
}
-void Translation::_set_messages(const DVector<String>& p_messages){
+void Translation::_set_messages(const PoolVector<String>& p_messages){
int msg_count=p_messages.size();
ERR_FAIL_COND(msg_count%2);
- DVector<String>::Read r = p_messages.read();
+ PoolVector<String>::Read r = p_messages.read();
for(int i=0;i<msg_count;i+=2) {
@@ -839,9 +847,20 @@ void Translation::_set_messages(const DVector<String>& p_messages){
void Translation::set_locale(const String& p_locale) {
- ERR_EXPLAIN("Invalid Locale: "+p_locale);
- ERR_FAIL_COND(!is_valid_locale(p_locale));
- locale=p_locale;
+ // replaces '-' with '_' for macOS Sierra-style locales
+ String univ_locale = p_locale.replace("-", "_");
+
+ if(!is_valid_locale(univ_locale)) {
+ String trimmed_locale = get_trimmed_locale(univ_locale);
+
+ ERR_EXPLAIN("Invalid Locale: "+trimmed_locale);
+ ERR_FAIL_COND(!is_valid_locale(trimmed_locale));
+
+ locale=trimmed_locale;
+ }
+ else {
+ locale=univ_locale;
+ }
}
void Translation::add_message( const StringName& p_src_text, const StringName& p_xlated_text ) {
@@ -880,17 +899,17 @@ int Translation::get_message_count() const {
void Translation::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_locale","locale"),&Translation::set_locale);
- ObjectTypeDB::bind_method(_MD("get_locale"),&Translation::get_locale);
- ObjectTypeDB::bind_method(_MD("add_message","src_message","xlated_message"),&Translation::add_message);
- ObjectTypeDB::bind_method(_MD("get_message","src_message"),&Translation::get_message);
- ObjectTypeDB::bind_method(_MD("erase_message","src_message"),&Translation::erase_message);
- ObjectTypeDB::bind_method(_MD("get_message_list"),&Translation::_get_message_list);
- ObjectTypeDB::bind_method(_MD("get_message_count"),&Translation::get_message_count);
- ObjectTypeDB::bind_method(_MD("_set_messages"),&Translation::_set_messages);
- ObjectTypeDB::bind_method(_MD("_get_messages"),&Translation::_get_messages);
-
- ADD_PROPERTY( PropertyInfo(Variant::STRING_ARRAY,"messages",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_messages"), _SCS("_get_messages") );
+ ClassDB::bind_method(_MD("set_locale","locale"),&Translation::set_locale);
+ ClassDB::bind_method(_MD("get_locale"),&Translation::get_locale);
+ ClassDB::bind_method(_MD("add_message","src_message","xlated_message"),&Translation::add_message);
+ ClassDB::bind_method(_MD("get_message","src_message"),&Translation::get_message);
+ ClassDB::bind_method(_MD("erase_message","src_message"),&Translation::erase_message);
+ ClassDB::bind_method(_MD("get_message_list"),&Translation::_get_message_list);
+ ClassDB::bind_method(_MD("get_message_count"),&Translation::get_message_count);
+ ClassDB::bind_method(_MD("_set_messages"),&Translation::_set_messages);
+ ClassDB::bind_method(_MD("_get_messages"),&Translation::_get_messages);
+
+ ADD_PROPERTY( PropertyInfo(Variant::POOL_STRING_ARRAY,"messages",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_messages"), _SCS("_get_messages") );
ADD_PROPERTY( PropertyInfo(Variant::STRING,"locale"), _SCS("set_locale"), _SCS("get_locale") );
}
@@ -906,9 +925,24 @@ Translation::Translation() {
void TranslationServer::set_locale(const String& p_locale) {
- ERR_EXPLAIN("Invalid Locale: "+p_locale);
- ERR_FAIL_COND(!is_valid_locale(p_locale));
- locale=p_locale;
+ // replaces '-' with '_' for macOS Sierra-style locales
+ String univ_locale = p_locale.replace("-", "_");
+
+ if(!is_valid_locale(univ_locale)) {
+ String trimmed_locale = get_trimmed_locale(univ_locale);
+
+ ERR_EXPLAIN("Invalid Locale: "+trimmed_locale);
+ ERR_FAIL_COND(!is_valid_locale(trimmed_locale));
+
+ locale=trimmed_locale;
+ }
+ else {
+ locale=univ_locale;
+ }
+
+ if (OS::get_singleton()->get_main_loop()) {
+ OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
+ }
}
String TranslationServer::get_locale() const {
@@ -1018,13 +1052,13 @@ TranslationServer *TranslationServer::singleton=NULL;
bool TranslationServer::_load_translations(const String& p_from) {
- if (Globals::get_singleton()->has(p_from)) {
- DVector<String> translations=Globals::get_singleton()->get(p_from);
+ if (GlobalConfig::get_singleton()->has(p_from)) {
+ PoolVector<String> translations=GlobalConfig::get_singleton()->get(p_from);
int tcount=translations.size();
if (tcount) {
- DVector<String>::Read r = translations.read();
+ PoolVector<String>::Read r = translations.read();
for(int i=0;i<tcount;i++) {
@@ -1060,7 +1094,7 @@ void TranslationServer::setup() {
options+=locale_list[idx];
idx++;
}
- Globals::get_singleton()->set_custom_property_info("locale/fallback",PropertyInfo(Variant::STRING,"locale/fallback",PROPERTY_HINT_ENUM,options));
+ GlobalConfig::get_singleton()->set_custom_property_info("locale/fallback",PropertyInfo(Variant::STRING,"locale/fallback",PROPERTY_HINT_ENUM,options));
}
#endif
//load translations
@@ -1087,15 +1121,15 @@ StringName TranslationServer::tool_translate(const StringName& p_message) const
void TranslationServer::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_locale","locale"),&TranslationServer::set_locale);
- ObjectTypeDB::bind_method(_MD("get_locale"),&TranslationServer::get_locale);
+ ClassDB::bind_method(_MD("set_locale","locale"),&TranslationServer::set_locale);
+ ClassDB::bind_method(_MD("get_locale"),&TranslationServer::get_locale);
- ObjectTypeDB::bind_method(_MD("translate","message"),&TranslationServer::translate);
+ ClassDB::bind_method(_MD("translate","message"),&TranslationServer::translate);
- ObjectTypeDB::bind_method(_MD("add_translation","translation:Translation"),&TranslationServer::add_translation);
- ObjectTypeDB::bind_method(_MD("remove_translation","translation:Translation"),&TranslationServer::remove_translation);
+ ClassDB::bind_method(_MD("add_translation","translation:Translation"),&TranslationServer::add_translation);
+ ClassDB::bind_method(_MD("remove_translation","translation:Translation"),&TranslationServer::remove_translation);
- ObjectTypeDB::bind_method(_MD("clear"),&TranslationServer::clear);
+ ClassDB::bind_method(_MD("clear"),&TranslationServer::clear);
}
diff --git a/core/translation.h b/core/translation.h
index cdb22bfeca..85ab4a229d 100644
--- a/core/translation.h
+++ b/core/translation.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -35,17 +35,17 @@
class Translation : public Resource {
- OBJ_TYPE( Translation, Resource );
+ GDCLASS( Translation, Resource );
OBJ_SAVE_TYPE( Translation );
RES_BASE_EXTENSION("xl");
String locale;
Map<StringName, StringName> translation_map;
- DVector<String> _get_message_list() const;
+ PoolVector<String> _get_message_list() const;
- DVector<String> _get_messages() const;
- void _set_messages(const DVector<String>& p_messages);
+ PoolVector<String> _get_messages() const;
+ void _set_messages(const PoolVector<String>& p_messages);
protected:
static void _bind_methods();
@@ -68,7 +68,7 @@ public:
class TranslationServer : public Object {
- OBJ_TYPE(TranslationServer, Object);
+ GDCLASS(TranslationServer, Object);
String locale;
String fallback;
diff --git a/core/typedefs.h b/core/typedefs.h
index 30a75e66da..176c77570d 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -77,10 +77,6 @@
#endif
-#ifndef DEFAULT_ALIGNMENT
-#define DEFAULT_ALIGNMENT 1
-#endif
-
//custom, gcc-safe offsetof, because gcc complains a lot.
template<class T>
diff --git a/core/ucaps.h b/core/ucaps.h
index cf42e96b4f..55b6509269 100644
--- a/core/ucaps.h
+++ b/core/ucaps.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index e8a71d4991..acb262d400 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "undo_redo.h"
-
+#include "os/os.h"
void UndoRedo::_discard_redo() {
@@ -54,12 +54,14 @@ void UndoRedo::_discard_redo() {
void UndoRedo::create_action(const String& p_name,MergeMode p_mode) {
+ uint32_t ticks = OS::get_singleton()->get_ticks_msec();
+
if (action_level==0) {
_discard_redo();
// Check if the merge operation is valid
- if (p_mode!=MERGE_DISABLE && actions.size() && actions[actions.size()-1].name==p_name) {
+ if (p_mode!=MERGE_DISABLE && actions.size() && actions[actions.size()-1].name==p_name && actions[actions.size()-1].last_tick+800 > ticks) {
current_action=actions.size()-2;
@@ -83,12 +85,15 @@ void UndoRedo::create_action(const String& p_name,MergeMode p_mode) {
}
}
+ actions[actions.size()-1].last_tick=ticks;
+
merge_mode=p_mode;
} else {
Action new_action;
new_action.name=p_name;
+ new_action.last_tick=ticks;
actions.push_back(new_action);
merge_mode=MERGE_DISABLE;
@@ -479,11 +484,11 @@ Variant UndoRedo::_add_undo_method(const Variant** p_args, int p_argcount, Varia
void UndoRedo::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("create_action","name","merge_mode"),&UndoRedo::create_action, DEFVAL(MERGE_DISABLE) );
- ObjectTypeDB::bind_method(_MD("commit_action"),&UndoRedo::commit_action);
+ ClassDB::bind_method(_MD("create_action","name","merge_mode"),&UndoRedo::create_action, DEFVAL(MERGE_DISABLE) );
+ ClassDB::bind_method(_MD("commit_action"),&UndoRedo::commit_action);
- //ObjectTypeDB::bind_method(_MD("add_do_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_do_method);
- //ObjectTypeDB::bind_method(_MD("add_undo_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_undo_method);
+ //ClassDB::bind_method(_MD("add_do_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_do_method);
+ //ClassDB::bind_method(_MD("add_undo_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_undo_method);
{
MethodInfo mi;
@@ -492,7 +497,7 @@ void UndoRedo::_bind_methods() {
mi.arguments.push_back( PropertyInfo( Variant::STRING, "method"));
- ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"add_do_method",&UndoRedo::_add_do_method,mi);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"add_do_method",&UndoRedo::_add_do_method,mi);
}
{
@@ -502,16 +507,16 @@ void UndoRedo::_bind_methods() {
mi.arguments.push_back( PropertyInfo( Variant::STRING, "method"));
- ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"add_undo_method",&UndoRedo::_add_undo_method,mi);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"add_undo_method",&UndoRedo::_add_undo_method,mi);
}
- ObjectTypeDB::bind_method(_MD("add_do_property","object", "property", "value:Variant"),&UndoRedo::add_do_property);
- ObjectTypeDB::bind_method(_MD("add_undo_property","object", "property", "value:Variant"),&UndoRedo::add_undo_property);
- ObjectTypeDB::bind_method(_MD("add_do_reference","object"),&UndoRedo::add_do_reference);
- ObjectTypeDB::bind_method(_MD("add_undo_reference","object"),&UndoRedo::add_undo_reference);
- ObjectTypeDB::bind_method(_MD("clear_history"),&UndoRedo::clear_history);
- ObjectTypeDB::bind_method(_MD("get_current_action_name"),&UndoRedo::get_current_action_name);
- ObjectTypeDB::bind_method(_MD("get_version"),&UndoRedo::get_version);
+ ClassDB::bind_method(_MD("add_do_property","object", "property", "value:Variant"),&UndoRedo::add_do_property);
+ ClassDB::bind_method(_MD("add_undo_property","object", "property", "value:Variant"),&UndoRedo::add_undo_property);
+ ClassDB::bind_method(_MD("add_do_reference","object"),&UndoRedo::add_do_reference);
+ ClassDB::bind_method(_MD("add_undo_reference","object"),&UndoRedo::add_undo_reference);
+ ClassDB::bind_method(_MD("clear_history"),&UndoRedo::clear_history);
+ ClassDB::bind_method(_MD("get_current_action_name"),&UndoRedo::get_current_action_name);
+ ClassDB::bind_method(_MD("get_version"),&UndoRedo::get_version);
BIND_CONSTANT(MERGE_DISABLE);
BIND_CONSTANT(MERGE_ENDS);
diff --git a/core/undo_redo.h b/core/undo_redo.h
index 208eb6ed5e..7664cf7cb5 100644
--- a/core/undo_redo.h
+++ b/core/undo_redo.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,7 +37,7 @@
class UndoRedo : public Object {
- OBJ_TYPE(UndoRedo,Object);
+ GDCLASS(UndoRedo,Object);
OBJ_SAVE_TYPE( UndoRedo );
public:
@@ -76,6 +76,7 @@ private:
String name;
List<Operation> do_ops;
List<Operation> undo_ops;
+ uint64_t last_tick;
};
Vector<Action> actions;
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 0d887210c3..66608379be 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -560,7 +560,7 @@ String String::get_slice(String p_splitter, int p_slice) const {
int pos=0;
int prev_pos=0;
-// int slices=1;
+ //int slices=1;
if (p_slice<0)
return "";
if (find(p_splitter)==-1)
@@ -574,7 +574,7 @@ String String::get_slice(String p_splitter, int p_slice) const {
pos=length(); //reached end
int from=prev_pos;
- // int to=pos;
+ //int to=pos;
if (p_slice==i) {
@@ -612,6 +612,8 @@ String String::get_slicec(CharType p_splitter, int p_slice) const {
if (p_slice==count) {
return substr(prev,i-prev);
+ } else if (c[i]==0) {
+ return String();
} else {
count++;
prev=i+1;
@@ -1418,7 +1420,7 @@ bool String::parse_utf8(const char* p_utf8,int p_len) {
}
}
-// printf("char %i, len %i\n",unichar,len);
+ //printf("char %i, len %i\n",unichar,len);
if (sizeof(wchar_t)==2 && unichar>0xFFFF) {
unichar=' '; //too long for windows
@@ -1543,49 +1545,98 @@ String::String(const StrRange& p_range) {
copy_from(p_range.c_str,p_range.len);
}
-int String::hex_to_int() const {
+int String::hex_to_int(bool p_with_prefix) const {
- int l = length();
- if (l<3)
- return 0;
+ int l = length();
+ if (p_with_prefix && l<3)
+ return 0;
- const CharType *s=ptr();
+ const CharType *s=ptr();
- int sign = s[0]=='-' ? -1 : 1;
+ int sign = s[0]=='-' ? -1 : 1;
- if (sign<0) {
- s++;
- l--;
- if (l<2)
- return 0;
- }
+ if (sign<0) {
+ s++;
+ l--;
+ if (p_with_prefix && l<2)
+ return 0;
+ }
- if (s[0]!='0' || s[1]!='x')
- return 0;
+ if (p_with_prefix) {
+ if (s[0]!='0' || s[1]!='x')
+ return 0;
+ s+=2;
+ l-=2;
+ };
- s+=2;
- l-=2;
+ int hex=0;
- int hex=0;
+ while(*s) {
- while(*s) {
+ CharType c = LOWERCASE(*s);
+ int n;
+ if (c>='0' && c<='9') {
+ n=c-'0';
+ } else if (c>='a' && c<='f') {
+ n=(c-'a')+10;
+ } else {
+ return 0;
+ }
- CharType c = LOWERCASE(*s);
- int n;
- if (c>='0' && c<='9') {
- n=c-'0';
- } else if (c>='a' && c<='f') {
- n=(c-'a')+10;
- } else {
- return 0;
- }
+ hex*=16;
+ hex+=n;
+ s++;
+ }
- hex*=16;
- hex+=n;
- s++;
- }
+ return hex*sign;
+
+}
+
+
+int64_t String::hex_to_int64(bool p_with_prefix) const {
+
+ int l = length();
+ if (p_with_prefix && l<3)
+ return 0;
+
+ const CharType *s=ptr();
+
+ int64_t sign = s[0]=='-' ? -1 : 1;
+
+ if (sign<0) {
+ s++;
+ l--;
+ if (p_with_prefix && l<2)
+ return 0;
+ }
+
+ if (p_with_prefix) {
+ if (s[0]!='0' || s[1]!='x')
+ return 0;
+ s+=2;
+ l-=2;
+ };
+
+ int64_t hex=0;
- return hex*sign;
+ while(*s) {
+
+ CharType c = LOWERCASE(*s);
+ int64_t n;
+ if (c>='0' && c<='9') {
+ n=c-'0';
+ } else if (c>='a' && c<='f') {
+ n=(c-'a')+10;
+ } else {
+ return 0;
+ }
+
+ hex*=16;
+ hex+=n;
+ s++;
+ }
+
+ return hex*sign;
}
@@ -2900,6 +2951,78 @@ bool String::matchn(const String& p_wildcard) const {
}
+String String::format(const Variant& values,String placeholder) const {
+
+ String new_string = String( this->ptr() );
+
+ if( values.get_type() == Variant::ARRAY ) {
+ Array values_arr = values;
+
+ for(int i=0;i<values_arr.size();i++) {
+ String i_as_str = String::num_int64( i );
+
+ if( values_arr[i].get_type() == Variant::ARRAY ) {//Array in Array structure [["name","RobotGuy"],[0,"godot"],["strength",9000.91]]
+ Array value_arr = values_arr[i];
+
+ if( value_arr.size()==2 ) {
+ Variant v_key = value_arr[0];
+ String key;
+
+ key = v_key.get_construct_string();
+ if( key.left(1)=="\"" && key.right(key.length()-1)=="\"" ) {
+ key = key.substr(1,key.length()-2);
+ }
+
+ Variant v_val = value_arr[1];
+ String val;
+ val = v_val.get_construct_string();
+
+ if( val.left(1)=="\"" && val.right(val.length()-1)=="\"" ) {
+ val = val.substr(1,val.length()-2);
+ }
+
+ new_string = new_string.replacen( placeholder.replace("_", key ), val );
+ }else {
+ ERR_PRINT(String("STRING.format Inner Array size != 2 ").ascii().get_data());
+ }
+ } else {//Array structure ["RobotGuy","Logis","rookie"]
+ Variant v_val = values_arr[i];
+ String val;
+ val = v_val.get_construct_string();
+
+ if( val.left(1)=="\"" && val.right(val.length()-1)=="\"" ) {
+ val = val.substr(1,val.length()-2);
+ }
+
+ new_string = new_string.replacen( placeholder.replace("_", i_as_str ), val );
+ }
+ }
+ }else if( values.get_type() == Variant::DICTIONARY ) {
+ Dictionary d = values;
+ List<Variant> keys;
+ d.get_key_list(&keys);
+
+ for (List<Variant>::Element *E=keys.front();E;E=E->next()) {
+ String key = E->get().get_construct_string();
+ String val = d[E->get()].get_construct_string();
+
+ if( key.left(1)=="\"" && key.right(key.length()-1)=="\"" ) {
+ key = key.substr(1,key.length()-2);
+ }
+
+ if( val.left(1)=="\"" && val.right(val.length()-1)=="\"" ) {
+ val = val.substr(1,val.length()-2);
+ }
+
+ new_string = new_string.replacen( placeholder.replace("_", key ), val );
+ }
+ }else{
+ ERR_PRINT(String("Invalid type: use Array or Dictionary.").ascii().get_data());
+ }
+
+ return new_string;
+}
+
String String::replace(String p_key,String p_with) const {
String new_string;
@@ -3073,6 +3196,11 @@ String String::simplify_path() const {
}
s =s.replace("\\","/");
+ while(true){ // in case of using 2 or more slash
+ String compare = s.replace("//","/");
+ if (s==compare) break;
+ else s=compare;
+ }
Vector<String> dirs = s.split("/",false);
for(int i=0;i<dirs.size();i++) {
@@ -3173,7 +3301,7 @@ bool String::is_valid_identifier() const {
//kind of poor should be rewritten properly
-String String::world_wrap(int p_chars_per_line) const {
+String String::word_wrap(int p_chars_per_line) const {
int from=0;
int last_space=0;
@@ -3505,6 +3633,36 @@ bool String::is_valid_integer() const {
}
+bool String::is_valid_hex_number(bool p_with_prefix) const {
+
+ int from = 0;
+ int len = length();
+
+ if (len!=1 && (operator[](0)=='+' || operator[](0)=='-'))
+ from++;
+
+ if (p_with_prefix) {
+
+ if (len < 2)
+ return false;
+ if (operator[](from) != '0' || operator[](from+1) != 'x') {
+ return false;
+ };
+ from += 2;
+ };
+
+ for (int i=from; i<len; i++) {
+
+ CharType c = operator[](i);
+ if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
+ continue;
+ return false;
+ };
+
+ return true;
+};
+
+
bool String::is_valid_float() const {
int len = length();
@@ -3641,20 +3799,41 @@ bool String::is_valid_html_color() const {
}
+
bool String::is_valid_ip_address() const {
- Vector<String> ip = split(".");
- if (ip.size()!=4)
- return false;
- for(int i=0;i<ip.size();i++) {
+ if (find(":") >= 0) {
- String n = ip[i];
- if (!n.is_valid_integer())
- return false;
- int val = n.to_int();
- if (val<0 || val>255)
+ Vector<String> ip = split(":");
+ for (int i=0; i<ip.size(); i++) {
+
+ String n = ip[i];
+ if (n.empty())
+ continue;
+ if (n.is_valid_hex_number(false)) {
+ int nint = n.hex_to_int(false);
+ if (nint < 0 || nint > 0xffff)
+ return false;
+ continue;
+ };
+ if (!n.is_valid_ip_address())
+ return false;
+ };
+
+ } else {
+ Vector<String> ip = split(".");
+ if (ip.size()!=4)
return false;
- }
+ for(int i=0;i<ip.size();i++) {
+
+ String n = ip[i];
+ if (!n.is_valid_integer())
+ return false;
+ int val = n.to_int();
+ if (val<0 || val>255)
+ return false;
+ }
+ };
return true;
}
@@ -3705,7 +3884,7 @@ String String::get_file() const {
return substr(sep+1,length());
}
-String String::extension() const {
+String String::get_extension() const {
int pos = find_last(".");
if (pos<0)
@@ -3715,8 +3894,9 @@ String String::extension() const {
}
String String::plus_file(const String& p_file) const {
-
- if (length()>0 && operator [](length()-1)=='/')
+ if (empty())
+ return p_file;
+ if (operator [](length()-1)=='/' || p_file.operator [](0)=='/')
return *this+p_file;
else
return *this+"/"+p_file;
@@ -3784,7 +3964,7 @@ String String::percent_decode() const {
return String::utf8(pe.ptr());
}
-String String::basename() const {
+String String::get_basename() const {
int pos = find_last(".");
if (pos<0)
@@ -4104,4 +4284,3 @@ String RTR(const String& p_text) {
return p_text;
}
-
diff --git a/core/ustring.h b/core/ustring.h
index bb57b11d88..426762a9e1 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -125,6 +125,7 @@ public:
bool is_subsequence_ofi(const String& p_string) const;
Vector<String> bigrams() const;
float similarity(const String& p_string) const;
+ String format(const Variant& values,String placeholder="{_}") const;
String replace_first(String p_key,String p_with) const;
String replace(String p_key,String p_with) const;
String replacen(String p_key,String p_with) const;
@@ -144,9 +145,10 @@ public:
bool is_numeric() const;
double to_double() const;
float to_float() const;
- int hex_to_int() const;
+ int hex_to_int(bool p_with_prefix = true) const;
int to_int() const;
+ int64_t hex_to_int64(bool p_with_prefix = true) const;
int64_t to_int64() const;
static int to_int(const char* p_str, int p_len=-1);
static double to_double(const char* p_str);
@@ -175,8 +177,8 @@ public:
String right(int p_pos) const;
String strip_edges(bool left = true, bool right = true) const;
String strip_escapes() const;
- String extension() const;
- String basename() const;
+ String get_extension() const;
+ String get_basename() const;
String plus_file(const String& p_file) const;
CharType ord_at(int p_idx) const;
@@ -218,7 +220,7 @@ public:
String c_escape() const;
String c_unescape() const;
String json_escape() const;
- String world_wrap(int p_chars_per_line) const;
+ String word_wrap(int p_chars_per_line) const;
String percent_encode() const;
String percent_decode() const;
@@ -226,6 +228,7 @@ public:
bool is_valid_identifier() const;
bool is_valid_integer() const;
bool is_valid_float() const;
+ bool is_valid_hex_number(bool p_with_prefix) const;
bool is_valid_html_color() const;
bool is_valid_ip_address() const;
diff --git a/core/variant.cpp b/core/variant.cpp
index a78c07d819..5a670a2786 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -74,9 +74,9 @@ String Variant::get_type_name(Variant::Type p_type) {
return "Rect2";
} break;
- case MATRIX32: {
+ case TRANSFORM2D: {
- return "Matrix32";
+ return "Transform2D";
} break;
case VECTOR3: {
@@ -92,18 +92,18 @@ String Variant::get_type_name(Variant::Type p_type) {
} break;*/
- case _AABB: {
+ case RECT3: {
- return "AABB";
+ return "Rect3";
} break;
case QUAT: {
return "Quat";
} break;
- case MATRIX3: {
+ case BASIS: {
- return "Matrix3";
+ return "Basis";
} break;
case TRANSFORM: {
@@ -153,38 +153,38 @@ String Variant::get_type_name(Variant::Type p_type) {
} break;
// arrays
- case RAW_ARRAY: {
+ case POOL_BYTE_ARRAY: {
- return "RawArray";
+ return "PoolByteArray";
} break;
- case INT_ARRAY: {
+ case POOL_INT_ARRAY: {
- return "IntArray";
+ return "PoolIntArray";
} break;
- case REAL_ARRAY: {
+ case POOL_REAL_ARRAY: {
- return "RealArray";
+ return "PoolFloatArray";
} break;
- case STRING_ARRAY: {
+ case POOL_STRING_ARRAY: {
- return "StringArray";
+ return "PoolStringArray";
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
- return "Vector2Array";
+ return "PoolVector2Array";
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
- return "Vector3Array";
+ return "PoolVector3Array";
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
- return "ColorArray";
+ return "PoolColorArray";
} break;
default: {}
@@ -255,7 +255,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
invalid_types=invalid;
} break;
- case MATRIX32: {
+ case TRANSFORM2D: {
static const Type valid[]={
@@ -268,14 +268,14 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
case QUAT: {
static const Type valid[]={
- MATRIX3,
+ BASIS,
NIL
};
valid_types=valid;
} break;
- case MATRIX3: {
+ case BASIS: {
static const Type valid[]={
QUAT,
@@ -289,9 +289,9 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
case TRANSFORM: {
static const Type valid[]={
- MATRIX32,
+ TRANSFORM2D,
QUAT,
- MATRIX3,
+ BASIS,
NIL
};
@@ -341,20 +341,20 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
static const Type valid[]={
- RAW_ARRAY,
- INT_ARRAY,
- STRING_ARRAY,
- REAL_ARRAY,
- COLOR_ARRAY,
- VECTOR2_ARRAY,
- VECTOR3_ARRAY,
+ POOL_BYTE_ARRAY,
+ POOL_INT_ARRAY,
+ POOL_STRING_ARRAY,
+ POOL_REAL_ARRAY,
+ POOL_COLOR_ARRAY,
+ POOL_VECTOR2_ARRAY,
+ POOL_VECTOR3_ARRAY,
NIL
};
valid_types=valid;
} break;
// arrays
- case RAW_ARRAY: {
+ case POOL_BYTE_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -363,7 +363,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
valid_types=valid;
} break;
- case INT_ARRAY: {
+ case POOL_INT_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -371,7 +371,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
};
valid_types=valid;
} break;
- case REAL_ARRAY: {
+ case POOL_REAL_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -380,7 +380,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
valid_types=valid;
} break;
- case STRING_ARRAY: {
+ case POOL_STRING_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -388,7 +388,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
};
valid_types=valid;
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -397,7 +397,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
valid_types=valid;
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -406,7 +406,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
valid_types=valid;
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -429,6 +429,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
return true;
i++;
}
+
} else if (invalid_types) {
@@ -439,6 +440,8 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) {
return false;
i++;
}
+
+ return true;
}
return false;
@@ -457,7 +460,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
};
const Type *valid_types=NULL;
- const Type *invalid_types=NULL;
switch(p_type_to) {
case BOOL: {
@@ -505,7 +507,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
valid_types=valid;
} break;
- case MATRIX32: {
+ case TRANSFORM2D: {
static const Type valid[]={
@@ -518,14 +520,14 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
case QUAT: {
static const Type valid[]={
- MATRIX3,
+ BASIS,
NIL
};
valid_types=valid;
} break;
- case MATRIX3: {
+ case BASIS: {
static const Type valid[]={
QUAT,
@@ -539,9 +541,9 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
case TRANSFORM: {
static const Type valid[]={
- MATRIX32,
+ TRANSFORM2D,
QUAT,
- MATRIX3,
+ BASIS,
NIL
};
@@ -591,20 +593,20 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
static const Type valid[]={
- RAW_ARRAY,
- INT_ARRAY,
- STRING_ARRAY,
- REAL_ARRAY,
- COLOR_ARRAY,
- VECTOR2_ARRAY,
- VECTOR3_ARRAY,
+ POOL_BYTE_ARRAY,
+ POOL_INT_ARRAY,
+ POOL_STRING_ARRAY,
+ POOL_REAL_ARRAY,
+ POOL_COLOR_ARRAY,
+ POOL_VECTOR2_ARRAY,
+ POOL_VECTOR3_ARRAY,
NIL
};
valid_types=valid;
} break;
// arrays
- case RAW_ARRAY: {
+ case POOL_BYTE_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -613,7 +615,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
valid_types=valid;
} break;
- case INT_ARRAY: {
+ case POOL_INT_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -621,7 +623,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
};
valid_types=valid;
} break;
- case REAL_ARRAY: {
+ case POOL_REAL_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -630,7 +632,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
valid_types=valid;
} break;
- case STRING_ARRAY: {
+ case POOL_STRING_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -638,7 +640,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
};
valid_types=valid;
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -647,7 +649,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
valid_types=valid;
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -656,7 +658,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
valid_types=valid;
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
static const Type valid[]={
ARRAY,
@@ -679,16 +681,6 @@ bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_
return true;
i++;
}
- } else if (invalid_types) {
-
-
- int i=0;
- while(invalid_types[i]!=NIL) {
-
- if (p_type_from==invalid_types[i])
- return false;
- i++;
- }
}
return false;
@@ -767,9 +759,9 @@ bool Variant::is_zero() const {
return *reinterpret_cast<const Rect2*>(_data._mem)==Rect2();
} break;
- case MATRIX32: {
+ case TRANSFORM2D: {
- return *_data._matrix32==Matrix32();
+ return *_data._transform2d==Transform2D();
} break;
case VECTOR3: {
@@ -787,18 +779,18 @@ bool Variant::is_zero() const {
} break;*/
- case _AABB: {
+ case RECT3: {
- return *_data._aabb==AABB();
+ return *_data._rect3==Rect3();
} break;
case QUAT: {
return *reinterpret_cast<const Quat*>(_data._mem)==Quat();
} break;
- case MATRIX3: {
+ case BASIS: {
- return *_data._matrix3==Matrix3();
+ return *_data._basis==Basis();
} break;
case TRANSFORM: {
@@ -848,39 +840,39 @@ bool Variant::is_zero() const {
} break;
// arrays
- case RAW_ARRAY: {
+ case POOL_BYTE_ARRAY: {
- return reinterpret_cast<const DVector<uint8_t>*>(_data._mem)->size()==0;
+ return reinterpret_cast<const PoolVector<uint8_t>*>(_data._mem)->size()==0;
} break;
- case INT_ARRAY: {
+ case POOL_INT_ARRAY: {
- return reinterpret_cast<const DVector<int>*>(_data._mem)->size()==0;
+ return reinterpret_cast<const PoolVector<int>*>(_data._mem)->size()==0;
} break;
- case REAL_ARRAY: {
+ case POOL_REAL_ARRAY: {
- return reinterpret_cast<const DVector<real_t>*>(_data._mem)->size()==0;
+ return reinterpret_cast<const PoolVector<real_t>*>(_data._mem)->size()==0;
} break;
- case STRING_ARRAY: {
+ case POOL_STRING_ARRAY: {
- return reinterpret_cast<const DVector<String>*>(_data._mem)->size()==0;
+ return reinterpret_cast<const PoolVector<String>*>(_data._mem)->size()==0;
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
- return reinterpret_cast<const DVector<Vector2>*>(_data._mem)->size()==0;
+ return reinterpret_cast<const PoolVector<Vector2>*>(_data._mem)->size()==0;
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
- return reinterpret_cast<const DVector<Vector3>*>(_data._mem)->size()==0;
+ return reinterpret_cast<const PoolVector<Vector3>*>(_data._mem)->size()==0;
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
- return reinterpret_cast<const DVector<Color>*>(_data._mem)->size()==0;
+ return reinterpret_cast<const PoolVector<Color>*>(_data._mem)->size()==0;
} break;
default: {}
@@ -995,9 +987,9 @@ void Variant::reference(const Variant& p_variant) {
memnew_placement( _data._mem, Rect2( *reinterpret_cast<const Rect2*>(p_variant._data._mem) ) );
} break;
- case MATRIX32: {
+ case TRANSFORM2D: {
- _data._matrix32 = memnew( Matrix32( *p_variant._data._matrix32 ) );
+ _data._transform2d = memnew( Transform2D( *p_variant._data._transform2d ) );
} break;
case VECTOR3: {
@@ -1015,18 +1007,18 @@ void Variant::reference(const Variant& p_variant) {
} break;*/
- case _AABB: {
+ case RECT3: {
- _data._aabb = memnew( AABB( *p_variant._data._aabb ) );
+ _data._rect3 = memnew( Rect3( *p_variant._data._rect3 ) );
} break;
case QUAT: {
memnew_placement( _data._mem, Quat( *reinterpret_cast<const Quat*>(p_variant._data._mem) ) );
} break;
- case MATRIX3: {
+ case BASIS: {
- _data._matrix3 = memnew( Matrix3( *p_variant._data._matrix3 ) );
+ _data._basis = memnew( Basis( *p_variant._data._basis ) );
} break;
case TRANSFORM: {
@@ -1076,39 +1068,39 @@ void Variant::reference(const Variant& p_variant) {
} break;
// arrays
- case RAW_ARRAY: {
+ case POOL_BYTE_ARRAY: {
- memnew_placement( _data._mem, DVector<uint8_t> ( *reinterpret_cast<const DVector<uint8_t>*>(p_variant._data._mem) ) );
+ memnew_placement( _data._mem, PoolVector<uint8_t> ( *reinterpret_cast<const PoolVector<uint8_t>*>(p_variant._data._mem) ) );
} break;
- case INT_ARRAY: {
+ case POOL_INT_ARRAY: {
- memnew_placement( _data._mem, DVector<int> ( *reinterpret_cast<const DVector<int>*>(p_variant._data._mem) ) );
+ memnew_placement( _data._mem, PoolVector<int> ( *reinterpret_cast<const PoolVector<int>*>(p_variant._data._mem) ) );
} break;
- case REAL_ARRAY: {
+ case POOL_REAL_ARRAY: {
- memnew_placement( _data._mem, DVector<real_t> ( *reinterpret_cast<const DVector<real_t>*>(p_variant._data._mem) ) );
+ memnew_placement( _data._mem, PoolVector<real_t> ( *reinterpret_cast<const PoolVector<real_t>*>(p_variant._data._mem) ) );
} break;
- case STRING_ARRAY: {
+ case POOL_STRING_ARRAY: {
- memnew_placement( _data._mem, DVector<String> ( *reinterpret_cast<const DVector<String>*>(p_variant._data._mem) ) );
+ memnew_placement( _data._mem, PoolVector<String> ( *reinterpret_cast<const PoolVector<String>*>(p_variant._data._mem) ) );
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
- memnew_placement( _data._mem, DVector<Vector2> ( *reinterpret_cast<const DVector<Vector2>*>(p_variant._data._mem) ) );
+ memnew_placement( _data._mem, PoolVector<Vector2> ( *reinterpret_cast<const PoolVector<Vector2>*>(p_variant._data._mem) ) );
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
- memnew_placement( _data._mem, DVector<Vector3> ( *reinterpret_cast<const DVector<Vector3>*>(p_variant._data._mem) ) );
+ memnew_placement( _data._mem, PoolVector<Vector3> ( *reinterpret_cast<const PoolVector<Vector3>*>(p_variant._data._mem) ) );
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
- memnew_placement( _data._mem, DVector<Color> ( *reinterpret_cast<const DVector<Color>*>(p_variant._data._mem) ) );
+ memnew_placement( _data._mem, PoolVector<Color> ( *reinterpret_cast<const PoolVector<Color>*>(p_variant._data._mem) ) );
} break;
default: {}
@@ -1147,19 +1139,19 @@ void Variant::clear() {
VECTOR2,
RECT2
*/
- case MATRIX32: {
+ case TRANSFORM2D: {
- memdelete( _data._matrix32 );
+ memdelete( _data._transform2d );
} break;
- case _AABB: {
+ case RECT3: {
- memdelete( _data._aabb );
+ memdelete( _data._rect3 );
} break;
- case MATRIX3: {
+ case BASIS: {
- memdelete( _data._matrix3 );
+ memdelete( _data._basis );
} break;
case TRANSFORM: {
@@ -1204,39 +1196,39 @@ void Variant::clear() {
} break;
// arrays
- case RAW_ARRAY: {
+ case POOL_BYTE_ARRAY: {
- reinterpret_cast< DVector<uint8_t>* >(_data._mem)->~DVector<uint8_t>();
+ reinterpret_cast< PoolVector<uint8_t>* >(_data._mem)->~PoolVector<uint8_t>();
} break;
- case INT_ARRAY: {
+ case POOL_INT_ARRAY: {
- reinterpret_cast< DVector<int>* >(_data._mem)->~DVector<int>();
+ reinterpret_cast< PoolVector<int>* >(_data._mem)->~PoolVector<int>();
} break;
- case REAL_ARRAY: {
+ case POOL_REAL_ARRAY: {
- reinterpret_cast< DVector<real_t>* >(_data._mem)->~DVector<real_t>();
+ reinterpret_cast< PoolVector<real_t>* >(_data._mem)->~PoolVector<real_t>();
} break;
- case STRING_ARRAY: {
+ case POOL_STRING_ARRAY: {
- reinterpret_cast< DVector<String>* >(_data._mem)->~DVector<String>();
+ reinterpret_cast< PoolVector<String>* >(_data._mem)->~PoolVector<String>();
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
- reinterpret_cast< DVector<Vector2>* >(_data._mem)->~DVector<Vector2>();
+ reinterpret_cast< PoolVector<Vector2>* >(_data._mem)->~PoolVector<Vector2>();
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
- reinterpret_cast< DVector<Vector3>* >(_data._mem)->~DVector<Vector3>();
+ reinterpret_cast< PoolVector<Vector3>* >(_data._mem)->~PoolVector<Vector3>();
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
- reinterpret_cast< DVector<Color>* >(_data._mem)->~DVector<Color>();
+ reinterpret_cast< PoolVector<Color>* >(_data._mem)->~PoolVector<Color>();
} break;
default: {} /* not needed */
@@ -1475,7 +1467,7 @@ Variant::operator double() const {
case NIL: return 0;
case BOOL: return _data._bool ? 1.0 : 0.0;
- case INT: return (float)_data._int;
+ case INT: return (double)_data._int;
case REAL: return _data._real;
case STRING: return operator String().to_double();
default: {
@@ -1510,26 +1502,26 @@ Variant::operator String() const {
switch( type ) {
- case NIL: return "";
+ case NIL: return "Null";
case BOOL: return _data._bool ? "True" : "False";
- case INT: return String::num(_data._int);
- case REAL: return String::num(_data._real);
+ case INT: return itos(_data._int);
+ case REAL: return rtos(_data._real);
case STRING: return *reinterpret_cast<const String*>(_data._mem);
case VECTOR2: return "("+operator Vector2()+")";
case RECT2: return "("+operator Rect2()+")";
- case MATRIX32: {
+ case TRANSFORM2D: {
- Matrix32 mat32 = operator Matrix32();
+ Transform2D mat32 = operator Transform2D();
return "("+Variant(mat32.elements[0]).operator String()+", "+Variant(mat32.elements[1]).operator String()+", "+Variant(mat32.elements[2]).operator String()+")";
} break;
case VECTOR3: return "("+operator Vector3()+")";
case PLANE: return operator Plane();
//case QUAT:
- case _AABB: return operator AABB();
+ case RECT3: return operator Rect3();
case QUAT: return "("+operator Quat()+")";
- case MATRIX3: {
+ case BASIS: {
- Matrix3 mat3 = operator Matrix3();
+ Basis mat3 = operator Basis();
String mtx("(");
for (int i=0;i<3;i++) {
@@ -1584,9 +1576,9 @@ Variant::operator String() const {
return str;
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
- DVector<Vector2> vec = operator DVector<Vector2>();
+ PoolVector<Vector2> vec = operator PoolVector<Vector2>();
String str("[");
for(int i=0;i<vec.size();i++) {
@@ -1597,9 +1589,9 @@ Variant::operator String() const {
str += "]";
return str;
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
- DVector<Vector3> vec = operator DVector<Vector3>();
+ PoolVector<Vector3> vec = operator PoolVector<Vector3>();
String str("[");
for(int i=0;i<vec.size();i++) {
@@ -1610,9 +1602,9 @@ Variant::operator String() const {
str += "]";
return str;
} break;
- case STRING_ARRAY: {
+ case POOL_STRING_ARRAY: {
- DVector<String> vec = operator DVector<String>();
+ PoolVector<String> vec = operator PoolVector<String>();
String str("[");
for(int i=0;i<vec.size();i++) {
@@ -1623,9 +1615,9 @@ Variant::operator String() const {
str += "]";
return str;
} break;
- case INT_ARRAY: {
+ case POOL_INT_ARRAY: {
- DVector<int> vec = operator DVector<int>();
+ PoolVector<int> vec = operator PoolVector<int>();
String str("[");
for(int i=0;i<vec.size();i++) {
@@ -1636,9 +1628,9 @@ Variant::operator String() const {
str += "]";
return str;
} break;
- case REAL_ARRAY: {
+ case POOL_REAL_ARRAY: {
- DVector<real_t> vec = operator DVector<real_t>();
+ PoolVector<real_t> vec = operator PoolVector<real_t>();
String str("[");
for(int i=0;i<vec.size();i++) {
@@ -1673,7 +1665,7 @@ Variant::operator String() const {
};
};
#endif
- return "["+_get_obj().obj->get_type()+":"+itos(_get_obj().obj->get_instance_ID())+"]";
+ return "["+_get_obj().obj->get_class()+":"+itos(_get_obj().obj->get_instance_ID())+"]";
} else
return "[Object:null]";
@@ -1721,32 +1713,32 @@ Variant::operator Plane() const {
return Plane();
}
-Variant::operator AABB() const {
+Variant::operator Rect3() const {
- if (type==_AABB)
- return *_data._aabb;
+ if (type==RECT3)
+ return *_data._rect3;
else
- return AABB();
+ return Rect3();
}
-Variant::operator Matrix3() const {
+Variant::operator Basis() const {
- if (type==MATRIX3)
- return *_data._matrix3;
+ if (type==BASIS)
+ return *_data._basis;
else if (type==QUAT)
return *reinterpret_cast<const Quat*>(_data._mem);
else if (type==TRANSFORM)
return _data._transform->basis;
else
- return Matrix3();
+ return Basis();
}
Variant::operator Quat() const {
if (type==QUAT)
return *reinterpret_cast<const Quat*>(_data._mem);
- else if (type==MATRIX3)
- return *_data._matrix3;
+ else if (type==BASIS)
+ return *_data._basis;
else if (type==TRANSFORM)
return _data._transform->basis;
else
@@ -1759,21 +1751,21 @@ Variant::operator Transform() const {
if (type==TRANSFORM)
return *_data._transform;
- else if (type==MATRIX3)
- return Transform(*_data._matrix3,Vector3());
+ else if (type==BASIS)
+ return Transform(*_data._basis,Vector3());
else if (type==QUAT)
- return Transform(Matrix3(*reinterpret_cast<const Quat*>(_data._mem)),Vector3());
+ return Transform(Basis(*reinterpret_cast<const Quat*>(_data._mem)),Vector3());
else
return Transform();
}
- Variant::operator Matrix32() const {
+ Variant::operator Transform2D() const {
- if (type==MATRIX32) {
- return *_data._matrix32;
+ if (type==TRANSFORM2D) {
+ return *_data._transform2d;
} else if (type==TRANSFORM) {
const Transform& t = *_data._transform;;
- Matrix32 m;
+ Transform2D m;
m.elements[0][0]=t.basis.elements[0][0];
m.elements[0][1]=t.basis.elements[1][0];
m.elements[1][0]=t.basis.elements[0][1];
@@ -1782,7 +1774,7 @@ Variant::operator Transform() const {
m.elements[2][1]=t.origin[1];
return m;
} else
- return Matrix32();
+ return Transform2D();
}
@@ -1901,13 +1893,13 @@ inline DA _convert_array_from_variant(const Variant& p_variant) {
case Variant::ARRAY: { return _convert_array<DA,Array >( p_variant.operator Array () ); }
- case Variant::RAW_ARRAY: { return _convert_array<DA,DVector<uint8_t> >( p_variant.operator DVector<uint8_t> () ); }
- case Variant::INT_ARRAY: { return _convert_array<DA,DVector<int> >( p_variant.operator DVector<int> () ); }
- case Variant::REAL_ARRAY: { return _convert_array<DA,DVector<real_t> >( p_variant.operator DVector<real_t> () ); }
- case Variant::STRING_ARRAY: { return _convert_array<DA,DVector<String> >( p_variant.operator DVector<String> () ); }
- case Variant::VECTOR2_ARRAY: { return _convert_array<DA,DVector<Vector2> >( p_variant.operator DVector<Vector2> () ); }
- case Variant::VECTOR3_ARRAY: { return _convert_array<DA,DVector<Vector3> >( p_variant.operator DVector<Vector3> () ); }
- case Variant::COLOR_ARRAY: { return _convert_array<DA,DVector<Color> >( p_variant.operator DVector<Color>() ); }
+ case Variant::POOL_BYTE_ARRAY: { return _convert_array<DA,PoolVector<uint8_t> >( p_variant.operator PoolVector<uint8_t> () ); }
+ case Variant::POOL_INT_ARRAY: { return _convert_array<DA,PoolVector<int> >( p_variant.operator PoolVector<int> () ); }
+ case Variant::POOL_REAL_ARRAY: { return _convert_array<DA,PoolVector<real_t> >( p_variant.operator PoolVector<real_t> () ); }
+ case Variant::POOL_STRING_ARRAY: { return _convert_array<DA,PoolVector<String> >( p_variant.operator PoolVector<String> () ); }
+ case Variant::POOL_VECTOR2_ARRAY: { return _convert_array<DA,PoolVector<Vector2> >( p_variant.operator PoolVector<Vector2> () ); }
+ case Variant::POOL_VECTOR3_ARRAY: { return _convert_array<DA,PoolVector<Vector3> >( p_variant.operator PoolVector<Vector3> () ); }
+ case Variant::POOL_COLOR_ARRAY: { return _convert_array<DA,PoolVector<Color> >( p_variant.operator PoolVector<Color>() ); }
default: { return DA(); }
}
@@ -1922,64 +1914,64 @@ Variant::operator Array() const {
return _convert_array_from_variant<Array >(*this);
}
-Variant::operator DVector<uint8_t>() const {
+Variant::operator PoolVector<uint8_t>() const {
- if (type==RAW_ARRAY)
- return *reinterpret_cast<const DVector<uint8_t>* >(_data._mem);
+ if (type==POOL_BYTE_ARRAY)
+ return *reinterpret_cast<const PoolVector<uint8_t>* >(_data._mem);
else
- return _convert_array_from_variant<DVector<uint8_t> >(*this);
+ return _convert_array_from_variant<PoolVector<uint8_t> >(*this);
}
-Variant::operator DVector<int>() const {
+Variant::operator PoolVector<int>() const {
- if (type==INT_ARRAY)
- return *reinterpret_cast<const DVector<int>* >(_data._mem);
+ if (type==POOL_INT_ARRAY)
+ return *reinterpret_cast<const PoolVector<int>* >(_data._mem);
else
- return _convert_array_from_variant<DVector<int> >(*this);
+ return _convert_array_from_variant<PoolVector<int> >(*this);
}
-Variant::operator DVector<real_t>() const {
+Variant::operator PoolVector<real_t>() const {
- if (type==REAL_ARRAY)
- return *reinterpret_cast<const DVector<real_t>* >(_data._mem);
+ if (type==POOL_REAL_ARRAY)
+ return *reinterpret_cast<const PoolVector<real_t>* >(_data._mem);
else
- return _convert_array_from_variant<DVector<real_t> >(*this);
+ return _convert_array_from_variant<PoolVector<real_t> >(*this);
}
-Variant::operator DVector<String>() const {
+Variant::operator PoolVector<String>() const {
- if (type==STRING_ARRAY)
- return *reinterpret_cast<const DVector<String>* >(_data._mem);
+ if (type==POOL_STRING_ARRAY)
+ return *reinterpret_cast<const PoolVector<String>* >(_data._mem);
else
- return _convert_array_from_variant<DVector<String> >(*this);
+ return _convert_array_from_variant<PoolVector<String> >(*this);
}
-Variant::operator DVector<Vector3>() const {
+Variant::operator PoolVector<Vector3>() const {
- if (type==VECTOR3_ARRAY)
- return *reinterpret_cast<const DVector<Vector3>* >(_data._mem);
+ if (type==POOL_VECTOR3_ARRAY)
+ return *reinterpret_cast<const PoolVector<Vector3>* >(_data._mem);
else
- return _convert_array_from_variant<DVector<Vector3> >(*this);
+ return _convert_array_from_variant<PoolVector<Vector3> >(*this);
}
-Variant::operator DVector<Vector2>() const {
+Variant::operator PoolVector<Vector2>() const {
- if (type==VECTOR2_ARRAY)
- return *reinterpret_cast<const DVector<Vector2>* >(_data._mem);
+ if (type==POOL_VECTOR2_ARRAY)
+ return *reinterpret_cast<const PoolVector<Vector2>* >(_data._mem);
else
- return _convert_array_from_variant<DVector<Vector2> >(*this);
+ return _convert_array_from_variant<PoolVector<Vector2> >(*this);
}
-Variant::operator DVector<Color>() const {
+Variant::operator PoolVector<Color>() const {
- if (type==COLOR_ARRAY)
- return *reinterpret_cast<const DVector<Color>* >(_data._mem);
+ if (type==POOL_COLOR_ARRAY)
+ return *reinterpret_cast<const PoolVector<Color>* >(_data._mem);
else
- return _convert_array_from_variant<DVector<Color> >(*this);
+ return _convert_array_from_variant<PoolVector<Color> >(*this);
}
@@ -1998,13 +1990,13 @@ Variant::operator Vector<RID>() const {
Variant::operator Vector<Vector2>() const {
- DVector<Vector2> from=operator DVector<Vector2>();
+ PoolVector<Vector2> from=operator PoolVector<Vector2>();
Vector<Vector2> to;
int len=from.size();
if (len==0)
return Vector<Vector2>();
to.resize(len);
- DVector<Vector2>::Read r = from.read();
+ PoolVector<Vector2>::Read r = from.read();
Vector2 *w = &to[0];
for (int i=0;i<len;i++) {
@@ -2013,16 +2005,16 @@ Variant::operator Vector<Vector2>() const {
return to;
}
-Variant::operator DVector<Plane>() const {
+Variant::operator PoolVector<Plane>() const {
Array va= operator Array();
- DVector<Plane> planes;
+ PoolVector<Plane> planes;
int va_size=va.size();
if (va_size==0)
return planes;
planes.resize(va_size);
- DVector<Plane>::Write w = planes.write();
+ PoolVector<Plane>::Write w = planes.write();
for(int i=0;i<va_size;i++)
w[i]=va[i];
@@ -2030,17 +2022,17 @@ Variant::operator DVector<Plane>() const {
return planes;
}
-Variant::operator DVector<Face3>() const {
+Variant::operator PoolVector<Face3>() const {
- DVector<Vector3> va= operator DVector<Vector3>();
- DVector<Face3> faces;
+ PoolVector<Vector3> va= operator PoolVector<Vector3>();
+ PoolVector<Face3> faces;
int va_size=va.size();
if (va_size==0)
return faces;
faces.resize(va_size/3);
- DVector<Face3>::Write w = faces.write();
- DVector<Vector3>::Read r = va.read();
+ PoolVector<Face3>::Write w = faces.write();
+ PoolVector<Vector3>::Read r = va.read();
for(int i=0;i<va_size;i++)
w[i/3].vertex[i%3]=r[i];
@@ -2080,7 +2072,7 @@ Variant::operator Vector<Variant>() const {
Variant::operator Vector<uint8_t>() const {
- DVector<uint8_t> from=operator DVector<uint8_t>();
+ PoolVector<uint8_t> from=operator PoolVector<uint8_t>();
Vector<uint8_t> to;
int len=from.size();
to.resize(len);
@@ -2092,7 +2084,7 @@ Variant::operator Vector<uint8_t>() const {
}
Variant::operator Vector<int>() const {
- DVector<int> from=operator DVector<int>();
+ PoolVector<int> from=operator PoolVector<int>();
Vector<int> to;
int len=from.size();
to.resize(len);
@@ -2104,7 +2096,7 @@ Variant::operator Vector<int>() const {
}
Variant::operator Vector<real_t>() const {
- DVector<real_t> from=operator DVector<real_t>();
+ PoolVector<real_t> from=operator PoolVector<real_t>();
Vector<real_t> to;
int len=from.size();
to.resize(len);
@@ -2117,7 +2109,7 @@ Variant::operator Vector<real_t>() const {
Variant::operator Vector<String>() const {
- DVector<String> from=operator DVector<String>();
+ PoolVector<String> from=operator PoolVector<String>();
Vector<String> to;
int len=from.size();
to.resize(len);
@@ -2130,13 +2122,13 @@ Variant::operator Vector<String>() const {
}
Variant::operator Vector<Vector3>() const {
- DVector<Vector3> from=operator DVector<Vector3>();
+ PoolVector<Vector3> from=operator PoolVector<Vector3>();
Vector<Vector3> to;
int len=from.size();
if (len==0)
return Vector<Vector3>();
to.resize(len);
- DVector<Vector3>::Read r = from.read();
+ PoolVector<Vector3>::Read r = from.read();
Vector3 *w = &to[0];
for (int i=0;i<len;i++) {
@@ -2147,13 +2139,13 @@ Variant::operator Vector<Vector3>() const {
}
Variant::operator Vector<Color>() const {
- DVector<Color> from=operator DVector<Color>();
+ PoolVector<Color> from=operator PoolVector<Color>();
Vector<Color> to;
int len=from.size();
if (len==0)
return Vector<Color>();
to.resize(len);
- DVector<Color>::Read r = from.read();
+ PoolVector<Color>::Read r = from.read();
Color *w = &to[0];
for (int i=0;i<len;i++) {
@@ -2173,9 +2165,9 @@ Variant::operator Orientation() const {
Variant::operator IP_Address() const {
- if (type==REAL_ARRAY || type==INT_ARRAY || type==RAW_ARRAY) {
+ if (type==POOL_REAL_ARRAY || type==POOL_INT_ARRAY || type==POOL_BYTE_ARRAY) {
- DVector<int> addr=operator DVector<int>();
+ PoolVector<int> addr=operator PoolVector<int>();
if (addr.size()==4) {
return IP_Address(addr.get(0),addr.get(1),addr.get(2),addr.get(3));
}
@@ -2328,16 +2320,16 @@ Variant::Variant(const Plane& p_plane) {
memnew_placement( _data._mem, Plane( p_plane ) );
}
-Variant::Variant(const AABB& p_aabb) {
+Variant::Variant(const Rect3& p_aabb) {
- type=_AABB;
- _data._aabb = memnew( AABB( p_aabb ) );
+ type=RECT3;
+ _data._rect3 = memnew( Rect3( p_aabb ) );
}
-Variant::Variant(const Matrix3& p_matrix) {
+Variant::Variant(const Basis& p_matrix) {
- type=MATRIX3;
- _data._matrix3= memnew( Matrix3( p_matrix ) );
+ type=BASIS;
+ _data._basis= memnew( Basis( p_matrix ) );
}
@@ -2354,10 +2346,10 @@ Variant::Variant(const Transform& p_transform) {
}
-Variant::Variant(const Matrix32& p_transform) {
+Variant::Variant(const Transform2D& p_transform) {
- type=MATRIX32;
- _data._matrix32 = memnew( Matrix32( p_transform ) );
+ type=TRANSFORM2D;
+ _data._transform2d = memnew( Transform2D( p_transform ) );
}
Variant::Variant(const Color& p_color) {
@@ -2426,7 +2418,7 @@ Variant::Variant(const Array& p_array) {
}
-Variant::Variant(const DVector<Plane>& p_array) {
+Variant::Variant(const PoolVector<Plane>& p_array) {
type=ARRAY;
@@ -2475,11 +2467,11 @@ Variant::Variant(const Vector<Vector2>& p_array) {
type=NIL;
- DVector<Vector2> v;
+ PoolVector<Vector2> v;
int len=p_array.size();
if (len>0) {
v.resize(len);
- DVector<Vector2>::Write w = v.write();
+ PoolVector<Vector2>::Write w = v.write();
const Vector2 *r = p_array.ptr();
for (int i=0;i<len;i++)
@@ -2489,59 +2481,59 @@ Variant::Variant(const Vector<Vector2>& p_array) {
}
-Variant::Variant(const DVector<uint8_t>& p_raw_array) {
+Variant::Variant(const PoolVector<uint8_t>& p_raw_array) {
- type=RAW_ARRAY;
- memnew_placement( _data._mem, DVector<uint8_t>(p_raw_array) );
+ type=POOL_BYTE_ARRAY;
+ memnew_placement( _data._mem, PoolVector<uint8_t>(p_raw_array) );
}
-Variant::Variant(const DVector<int>& p_int_array) {
+Variant::Variant(const PoolVector<int>& p_int_array) {
- type=INT_ARRAY;
- memnew_placement( _data._mem, DVector<int>(p_int_array) );
+ type=POOL_INT_ARRAY;
+ memnew_placement( _data._mem, PoolVector<int>(p_int_array) );
}
-Variant::Variant(const DVector<real_t>& p_real_array) {
+Variant::Variant(const PoolVector<real_t>& p_real_array) {
- type=REAL_ARRAY;
- memnew_placement( _data._mem, DVector<real_t>(p_real_array) );
+ type=POOL_REAL_ARRAY;
+ memnew_placement( _data._mem, PoolVector<real_t>(p_real_array) );
}
-Variant::Variant(const DVector<String>& p_string_array) {
+Variant::Variant(const PoolVector<String>& p_string_array) {
- type=STRING_ARRAY;
- memnew_placement( _data._mem, DVector<String>(p_string_array) );
+ type=POOL_STRING_ARRAY;
+ memnew_placement( _data._mem, PoolVector<String>(p_string_array) );
}
-Variant::Variant(const DVector<Vector3>& p_vector3_array) {
+Variant::Variant(const PoolVector<Vector3>& p_vector3_array) {
- type=VECTOR3_ARRAY;
- memnew_placement( _data._mem, DVector<Vector3>(p_vector3_array) );
+ type=POOL_VECTOR3_ARRAY;
+ memnew_placement( _data._mem, PoolVector<Vector3>(p_vector3_array) );
}
-Variant::Variant(const DVector<Vector2>& p_vector2_array) {
+Variant::Variant(const PoolVector<Vector2>& p_vector2_array) {
- type=VECTOR2_ARRAY;
- memnew_placement( _data._mem, DVector<Vector2>(p_vector2_array) );
+ type=POOL_VECTOR2_ARRAY;
+ memnew_placement( _data._mem, PoolVector<Vector2>(p_vector2_array) );
}
-Variant::Variant(const DVector<Color>& p_color_array) {
+Variant::Variant(const PoolVector<Color>& p_color_array) {
- type=COLOR_ARRAY;
- memnew_placement( _data._mem, DVector<Color>(p_color_array) );
+ type=POOL_COLOR_ARRAY;
+ memnew_placement( _data._mem, PoolVector<Color>(p_color_array) );
}
-Variant::Variant(const DVector<Face3>& p_face_array) {
+Variant::Variant(const PoolVector<Face3>& p_face_array) {
- DVector<Vector3> vertices;
+ PoolVector<Vector3> vertices;
int face_count=p_face_array.size();
vertices.resize(face_count*3);
if (face_count) {
- DVector<Face3>::Read r = p_face_array.read();
- DVector<Vector3>::Write w = vertices.write();
+ PoolVector<Face3>::Read r = p_face_array.read();
+ PoolVector<Vector3>::Write w = vertices.write();
for(int i=0;i<face_count;i++) {
@@ -2549,8 +2541,8 @@ Variant::Variant(const DVector<Face3>& p_face_array) {
w[i*3+j]=r[i].vertex[j];
}
- r=DVector<Face3>::Read();
- w=DVector<Vector3>::Write();
+ r=PoolVector<Face3>::Read();
+ w=PoolVector<Vector3>::Write();
}
@@ -2575,7 +2567,7 @@ Variant::Variant(const Vector<Variant>& p_array) {
Variant::Variant(const Vector<uint8_t>& p_array) {
type=NIL;
- DVector<uint8_t> v;
+ PoolVector<uint8_t> v;
int len=p_array.size();
v.resize(len);
for (int i=0;i<len;i++)
@@ -2586,7 +2578,7 @@ Variant::Variant(const Vector<uint8_t>& p_array) {
Variant::Variant(const Vector<int>& p_array) {
type=NIL;
- DVector<int> v;
+ PoolVector<int> v;
int len=p_array.size();
v.resize(len);
for (int i=0;i<len;i++)
@@ -2597,7 +2589,7 @@ Variant::Variant(const Vector<int>& p_array) {
Variant::Variant(const Vector<real_t>& p_array) {
type=NIL;
- DVector<real_t> v;
+ PoolVector<real_t> v;
int len=p_array.size();
v.resize(len);
for (int i=0;i<len;i++)
@@ -2608,7 +2600,7 @@ Variant::Variant(const Vector<real_t>& p_array) {
Variant::Variant(const Vector<String>& p_array) {
type=NIL;
- DVector<String> v;
+ PoolVector<String> v;
int len=p_array.size();
v.resize(len);
for (int i=0;i<len;i++)
@@ -2619,11 +2611,11 @@ Variant::Variant(const Vector<String>& p_array) {
Variant::Variant(const Vector<Vector3>& p_array) {
type=NIL;
- DVector<Vector3> v;
+ PoolVector<Vector3> v;
int len=p_array.size();
if (len>0) {
v.resize(len);
- DVector<Vector3>::Write w = v.write();
+ PoolVector<Vector3>::Write w = v.write();
const Vector3 *r = p_array.ptr();
for (int i=0;i<len;i++)
@@ -2635,7 +2627,7 @@ Variant::Variant(const Vector<Vector3>& p_array) {
Variant::Variant(const Vector<Color>& p_array) {
type=NIL;
- DVector<Color> v;
+ PoolVector<Color> v;
int len=p_array.size();
v.resize(len);
for (int i=0;i<len;i++)
@@ -2708,13 +2700,13 @@ uint32_t Variant::hash() const {
hash = hash_djb2_one_float(reinterpret_cast<const Rect2*>(_data._mem)->size.x,hash);
return hash_djb2_one_float(reinterpret_cast<const Rect2*>(_data._mem)->size.y,hash);
} break;
- case MATRIX32: {
+ case TRANSFORM2D: {
uint32_t hash = 5831;
for(int i=0;i<3;i++) {
for(int j=0;j<2;j++) {
- hash = hash_djb2_one_float(_data._matrix32->elements[i][j],hash);
+ hash = hash_djb2_one_float(_data._transform2d->elements[i][j],hash);
}
}
@@ -2739,13 +2731,13 @@ uint32_t Variant::hash() const {
} break;*/
- case _AABB: {
+ case RECT3: {
uint32_t hash = 5831;
for(int i=0;i<3;i++) {
- hash = hash_djb2_one_float(_data._aabb->pos[i],hash);
- hash = hash_djb2_one_float(_data._aabb->size[i],hash);
+ hash = hash_djb2_one_float(_data._rect3->pos[i],hash);
+ hash = hash_djb2_one_float(_data._rect3->size[i],hash);
}
@@ -2760,13 +2752,13 @@ uint32_t Variant::hash() const {
return hash_djb2_one_float(reinterpret_cast<const Quat*>(_data._mem)->w,hash);
} break;
- case MATRIX3: {
+ case BASIS: {
uint32_t hash = 5831;
for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
- hash = hash_djb2_one_float(_data._matrix3->elements[i][j],hash);
+ hash = hash_djb2_one_float(_data._basis->elements[i][j],hash);
}
}
@@ -2832,39 +2824,39 @@ uint32_t Variant::hash() const {
return arr.hash();
} break;
- case RAW_ARRAY: {
+ case POOL_BYTE_ARRAY: {
- const DVector<uint8_t>& arr = *reinterpret_cast<const DVector<uint8_t>* >(_data._mem);
+ const PoolVector<uint8_t>& arr = *reinterpret_cast<const PoolVector<uint8_t>* >(_data._mem);
int len = arr.size();
- DVector<uint8_t>::Read r = arr.read();
+ PoolVector<uint8_t>::Read r = arr.read();
return hash_djb2_buffer((uint8_t*)&r[0],len);
} break;
- case INT_ARRAY: {
+ case POOL_INT_ARRAY: {
- const DVector<int>& arr = *reinterpret_cast<const DVector<int>* >(_data._mem);
+ const PoolVector<int>& arr = *reinterpret_cast<const PoolVector<int>* >(_data._mem);
int len = arr.size();
- DVector<int>::Read r = arr.read();
+ PoolVector<int>::Read r = arr.read();
return hash_djb2_buffer((uint8_t*)&r[0],len*sizeof(int));
} break;
- case REAL_ARRAY: {
+ case POOL_REAL_ARRAY: {
- const DVector<real_t>& arr = *reinterpret_cast<const DVector<real_t>* >(_data._mem);
+ const PoolVector<real_t>& arr = *reinterpret_cast<const PoolVector<real_t>* >(_data._mem);
int len = arr.size();
- DVector<real_t>::Read r = arr.read();
+ PoolVector<real_t>::Read r = arr.read();
return hash_djb2_buffer((uint8_t*)&r[0],len*sizeof(real_t));
} break;
- case STRING_ARRAY: {
+ case POOL_STRING_ARRAY: {
uint32_t hash=5831;
- const DVector<String>& arr = *reinterpret_cast<const DVector<String>* >(_data._mem);
+ const PoolVector<String>& arr = *reinterpret_cast<const PoolVector<String>* >(_data._mem);
int len = arr.size();
- DVector<String>::Read r = arr.read();
+ PoolVector<String>::Read r = arr.read();
for(int i=0;i<len;i++) {
hash = hash_djb2_one_32(r[i].hash(),hash);
@@ -2872,12 +2864,12 @@ uint32_t Variant::hash() const {
return hash;
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
uint32_t hash=5831;
- const DVector<Vector2>& arr = *reinterpret_cast<const DVector<Vector2>* >(_data._mem);
+ const PoolVector<Vector2>& arr = *reinterpret_cast<const PoolVector<Vector2>* >(_data._mem);
int len = arr.size();
- DVector<Vector2>::Read r = arr.read();
+ PoolVector<Vector2>::Read r = arr.read();
for(int i=0;i<len;i++) {
hash = hash_djb2_one_float(r[i].x,hash);
@@ -2887,12 +2879,12 @@ uint32_t Variant::hash() const {
return hash;
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
uint32_t hash=5831;
- const DVector<Vector3>& arr = *reinterpret_cast<const DVector<Vector3>* >(_data._mem);
+ const PoolVector<Vector3>& arr = *reinterpret_cast<const PoolVector<Vector3>* >(_data._mem);
int len = arr.size();
- DVector<Vector3>::Read r = arr.read();
+ PoolVector<Vector3>::Read r = arr.read();
for(int i=0;i<len;i++) {
hash = hash_djb2_one_float(r[i].x,hash);
@@ -2903,12 +2895,12 @@ uint32_t Variant::hash() const {
return hash;
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
uint32_t hash=5831;
- const DVector<Color>& arr = *reinterpret_cast<const DVector<Color>* >(_data._mem);
+ const PoolVector<Color>& arr = *reinterpret_cast<const PoolVector<Color>* >(_data._mem);
int len = arr.size();
- DVector<Color>::Read r = arr.read();
+ PoolVector<Color>::Read r = arr.read();
for(int i=0;i<len;i++) {
hash = hash_djb2_one_float(r[i].r,hash);
@@ -2993,8 +2985,8 @@ bool Variant::is_shared() const {
switch(type) {
case OBJECT: return true;
- case ARRAY: return reinterpret_cast<const Array*>(_data._mem)->is_shared();
- case DICTIONARY: return reinterpret_cast<const Dictionary*>(_data._mem)->is_shared();
+ case ARRAY: return true;
+ case DICTIONARY: return true;
default: {}
}
@@ -3074,7 +3066,7 @@ String Variant::get_call_error_text(Object* p_base, const StringName& p_method,c
return "Call OK";
}
- String class_name = p_base->get_type();
+ String class_name = p_base->get_class();
Ref<Script> script = p_base->get_script();
if (script.is_valid() && script->get_path().is_resource_file()) {
diff --git a/core/variant.h b/core/variant.h
index 90be593bd9..9d29fd64c3 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -63,13 +63,13 @@ struct PropertyInfo;
struct MethodInfo;
-typedef DVector<uint8_t> ByteArray;
-typedef DVector<int> IntArray;
-typedef DVector<real_t> RealArray;
-typedef DVector<String> StringArray;
-typedef DVector<Vector2> Vector2Array;
-typedef DVector<Vector3> Vector3Array;
-typedef DVector<Color> ColorArray;
+typedef PoolVector<uint8_t> PoolByteArray;
+typedef PoolVector<int> PoolIntArray;
+typedef PoolVector<real_t> PoolRealArray;
+typedef PoolVector<String> PoolStringArray;
+typedef PoolVector<Vector2> PoolVector2Array;
+typedef PoolVector<Vector3> PoolVector3Array;
+typedef PoolVector<Color> PoolColorArray;
class Variant {
public:
@@ -89,11 +89,11 @@ public:
VECTOR2, // 5
RECT2,
VECTOR3,
- MATRIX32,
+ TRANSFORM2D,
PLANE,
QUAT, // 10
- _AABB, //sorry naming convention fail :( not like it's used often
- MATRIX3,
+ RECT3, //sorry naming convention fail :( not like it's used often
+ BASIS,
TRANSFORM,
// misc types
@@ -107,13 +107,13 @@ public:
ARRAY,
// arrays
- RAW_ARRAY,
- INT_ARRAY,
- REAL_ARRAY,
- STRING_ARRAY, // 25
- VECTOR2_ARRAY,
- VECTOR3_ARRAY,
- COLOR_ARRAY,
+ POOL_BYTE_ARRAY,
+ POOL_INT_ARRAY,
+ POOL_REAL_ARRAY,
+ POOL_STRING_ARRAY, // 25
+ POOL_VECTOR2_ARRAY,
+ POOL_VECTOR3_ARRAY,
+ POOL_COLOR_ARRAY,
VARIANT_MAX
@@ -141,11 +141,11 @@ private:
union {
bool _bool;
- int _int;
+ int64_t _int;
double _real;
- Matrix32 *_matrix32;
- AABB* _aabb;
- Matrix3 *_matrix3;
+ Transform2D *_transform2d;
+ Rect3* _rect3;
+ Basis *_basis;
Transform *_transform;
RefPtr *_resource;
InputEvent *_input_event;
@@ -208,11 +208,11 @@ public:
operator Rect2() const;
operator Vector3() const;
operator Plane() const;
- operator AABB() const;
+ operator Rect3() const;
operator Quat() const;
- operator Matrix3() const;
+ operator Basis() const;
operator Transform() const;
- operator Matrix32() const;
+ operator Transform2D() const;
operator Color() const;
operator Image() const;
@@ -227,14 +227,14 @@ public:
operator Dictionary() const;
operator Array() const;
- operator DVector<uint8_t>() const;
- operator DVector<int>() const;
- operator DVector<real_t>() const;
- operator DVector<String>() const;
- operator DVector<Vector3>() const;
- operator DVector<Color>() const;
- operator DVector<Plane>() const;
- operator DVector<Face3>() const;
+ operator PoolVector<uint8_t>() const;
+ operator PoolVector<int>() const;
+ operator PoolVector<real_t>() const;
+ operator PoolVector<String>() const;
+ operator PoolVector<Vector3>() const;
+ operator PoolVector<Color>() const;
+ operator PoolVector<Plane>() const;
+ operator PoolVector<Face3>() const;
operator Vector<Variant>() const;
@@ -246,7 +246,7 @@ public:
operator Vector<Color>() const;
operator Vector<RID>() const;
operator Vector<Vector2>() const;
- operator DVector<Vector2>() const;
+ operator PoolVector<Vector2>() const;
operator Vector<Plane>() const;
// some core type enums to convert to
@@ -280,10 +280,10 @@ public:
Variant(const Rect2& p_rect2);
Variant(const Vector3& p_vector3);
Variant(const Plane& p_plane);
- Variant(const AABB& p_aabb);
+ Variant(const Rect3& p_aabb);
Variant(const Quat& p_quat);
- Variant(const Matrix3& p_transform);
- Variant(const Matrix32& p_transform);
+ Variant(const Basis& p_transform);
+ Variant(const Transform2D& p_transform);
Variant(const Transform& p_transform);
Variant(const Color& p_color);
Variant(const Image& p_image);
@@ -295,14 +295,14 @@ public:
Variant(const Dictionary& p_dictionary);
Variant(const Array& p_array);
- Variant(const DVector<Plane>& p_array); // helper
- Variant(const DVector<uint8_t>& p_raw_array);
- Variant(const DVector<int>& p_int_array);
- Variant(const DVector<real_t>& p_real_array);
- Variant(const DVector<String>& p_string_array);
- Variant(const DVector<Vector3>& p_vector3_array);
- Variant(const DVector<Color>& p_color_array);
- Variant(const DVector<Face3>& p_face_array);
+ Variant(const PoolVector<Plane>& p_array); // helper
+ Variant(const PoolVector<uint8_t>& p_raw_array);
+ Variant(const PoolVector<int>& p_int_array);
+ Variant(const PoolVector<real_t>& p_real_array);
+ Variant(const PoolVector<String>& p_string_array);
+ Variant(const PoolVector<Vector3>& p_vector3_array);
+ Variant(const PoolVector<Color>& p_color_array);
+ Variant(const PoolVector<Face3>& p_face_array);
Variant(const Vector<Variant>& p_array);
@@ -315,7 +315,7 @@ public:
Variant(const Vector<Plane>& p_array); // helper
Variant(const Vector<RID>& p_array); // helper
Variant(const Vector<Vector2>& p_array); // helper
- Variant(const DVector<Vector2>& p_array); // helper
+ Variant(const PoolVector<Vector2>& p_array); // helper
Variant(const IP_Address& p_address);
@@ -336,6 +336,7 @@ public:
OP_MULTIPLY,
OP_DIVIDE,
OP_NEGATE,
+ OP_POSITIVE,
OP_MODULE,
OP_STRING_CONCAT,
//bitwise
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 5f052bce8e..51ad115d46 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,6 +32,7 @@
#include "core_string_names.h"
#include "script_language.h"
+
typedef void (*VariantFunc)(Variant& r_ret,Variant& p_self,const Variant** p_args);
typedef void (*VariantConstructFunc)(Variant& r_ret,const Variant** p_args);
@@ -145,7 +146,16 @@ struct _VariantCall {
Arg(Variant::Type p_type,const StringName &p_name) { name=p_name; type=p_type; }
};
-// void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func);
+ //void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func);
+
+ static void make_func_return_variant(Variant::Type p_type,const StringName& p_name) {
+
+#ifdef DEBUG_ENABLED
+ type_funcs[p_type].functions[p_name].returns=true;
+#endif
+ }
+
+
static void addfunc(Variant::Type p_type, Variant::Type p_return,const StringName& p_name,VariantFunc p_func, const Vector<Variant>& p_defaultarg,const Arg& p_argtype1=Arg(),const Arg& p_argtype2=Arg(),const Arg& p_argtype3=Arg(),const Arg& p_argtype4=Arg(),const Arg& p_argtype5=Arg()) {
FuncData funcdata;
@@ -251,6 +261,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM1R(String,is_subsequence_ofi);
VCALL_LOCALMEM0R(String,bigrams);
VCALL_LOCALMEM1R(String,similarity);
+ VCALL_LOCALMEM2R(String,format);
VCALL_LOCALMEM2R(String,replace);
VCALL_LOCALMEM2R(String,replacen);
VCALL_LOCALMEM2R(String,insert);
@@ -262,8 +273,8 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM1R(String,left);
VCALL_LOCALMEM1R(String,right);
VCALL_LOCALMEM2R(String,strip_edges);
- VCALL_LOCALMEM0R(String,extension);
- VCALL_LOCALMEM0R(String,basename);
+ VCALL_LOCALMEM0R(String,get_extension);
+ VCALL_LOCALMEM0R(String,get_basename);
VCALL_LOCALMEM1R(String,plus_file);
VCALL_LOCALMEM1R(String,ord_at);
VCALL_LOCALMEM2(String,erase);
@@ -300,12 +311,12 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
String *s = reinterpret_cast<String*>(p_self._data._mem);
CharString charstr = s->ascii();
- ByteArray retval;
+ PoolByteArray retval;
size_t len = charstr.length();
retval.resize(len);
- ByteArray::Write w = retval.write();
+ PoolByteArray::Write w = retval.write();
copymem(w.ptr(), charstr.ptr(), len);
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
r_ret = retval;
}
@@ -315,12 +326,12 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
String *s = reinterpret_cast<String*>(p_self._data._mem);
CharString charstr = s->utf8();
- ByteArray retval;
+ PoolByteArray retval;
size_t len = charstr.length();
retval.resize(len);
- ByteArray::Write w = retval.write();
+ PoolByteArray::Write w = retval.write();
copymem(w.ptr(), charstr.ptr(), len);
- w = DVector<uint8_t>::Write();
+ w = PoolVector<uint8_t>::Write();
r_ret = retval;
}
@@ -339,12 +350,12 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM0R(Vector2,tangent);
VCALL_LOCALMEM0R(Vector2,floor);
VCALL_LOCALMEM1R(Vector2,snapped);
- VCALL_LOCALMEM0R(Vector2,get_aspect);
+ VCALL_LOCALMEM0R(Vector2,aspect);
VCALL_LOCALMEM1R(Vector2,dot);
VCALL_LOCALMEM1R(Vector2,slide);
VCALL_LOCALMEM1R(Vector2,reflect);
VCALL_LOCALMEM0R(Vector2,angle);
-// VCALL_LOCALMEM1R(Vector2,cross);
+ //VCALL_LOCALMEM1R(Vector2,cross);
VCALL_LOCALMEM0R(Vector2,abs);
VCALL_LOCALMEM1R(Vector2,clamped);
@@ -370,11 +381,14 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM4R(Vector3, cubic_interpolate);
VCALL_LOCALMEM1R(Vector3, dot);
VCALL_LOCALMEM1R(Vector3, cross);
+ VCALL_LOCALMEM1R(Vector3, outer);
+ VCALL_LOCALMEM0R(Vector3, to_diagonal_matrix);
VCALL_LOCALMEM0R(Vector3, abs);
VCALL_LOCALMEM0R(Vector3, floor);
VCALL_LOCALMEM0R(Vector3, ceil);
VCALL_LOCALMEM1R(Vector3, distance_to);
VCALL_LOCALMEM1R(Vector3, distance_squared_to);
+ VCALL_LOCALMEM1R(Vector3, angle_to);
VCALL_LOCALMEM1R(Vector3, slide);
VCALL_LOCALMEM1R(Vector3, reflect);
@@ -412,10 +426,6 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
r_ret=Variant();
}
- static void _call_Vector2_floorf(Variant& r_ret,Variant& p_self,const Variant** p_args) {
- r_ret = reinterpret_cast<Vector2*>(p_self._data._mem)->floor();
- };
-
VCALL_LOCALMEM0R(Quat,length);
VCALL_LOCALMEM0R(Quat,length_squared);
VCALL_LOCALMEM0R(Quat,normalized);
@@ -454,8 +464,6 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM0R(Dictionary,hash);
VCALL_LOCALMEM0R(Dictionary,keys);
VCALL_LOCALMEM0R(Dictionary,values);
- VCALL_LOCALMEM1R(Dictionary,parse_json);
- VCALL_LOCALMEM0R(Dictionary,to_json);
VCALL_LOCALMEM2(Array,set);
VCALL_LOCALMEM1R(Array,get);
@@ -465,12 +473,14 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM0R(Array,hash);
VCALL_LOCALMEM1(Array,push_back);
VCALL_LOCALMEM1(Array,push_front);
- VCALL_LOCALMEM0(Array,pop_back);
- VCALL_LOCALMEM0(Array,pop_front);
+ VCALL_LOCALMEM0R(Array,pop_back);
+ VCALL_LOCALMEM0R(Array,pop_front);
VCALL_LOCALMEM1(Array,append);
VCALL_LOCALMEM1(Array,resize);
VCALL_LOCALMEM2(Array,insert);
VCALL_LOCALMEM1(Array,remove);
+ VCALL_LOCALMEM0R(Array,front);
+ VCALL_LOCALMEM0R(Array,back);
VCALL_LOCALMEM2R(Array,find);
VCALL_LOCALMEM2R(Array,rfind);
VCALL_LOCALMEM1R(Array,find_last);
@@ -480,14 +490,14 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM0(Array,sort);
VCALL_LOCALMEM2(Array,sort_custom);
VCALL_LOCALMEM0(Array,invert);
- VCALL_LOCALMEM0R(Array,is_shared);
- static void _call_ByteArray_get_string_from_ascii(Variant& r_ret,Variant& p_self,const Variant** p_args) {
- ByteArray* ba = reinterpret_cast<ByteArray*>(p_self._data._mem);
+ static void _call_PoolByteArray_get_string_from_ascii(Variant& r_ret,Variant& p_self,const Variant** p_args) {
+
+ PoolByteArray* ba = reinterpret_cast<PoolByteArray*>(p_self._data._mem);
String s;
if (ba->size()>=0) {
- ByteArray::Read r = ba->read();
+ PoolByteArray::Read r = ba->read();
CharString cs;
cs.resize(ba->size()+1);
copymem(cs.ptr(),r.ptr(),ba->size());
@@ -498,94 +508,94 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
r_ret=s;
}
- static void _call_ByteArray_get_string_from_utf8(Variant& r_ret,Variant& p_self,const Variant** p_args) {
+ static void _call_PoolByteArray_get_string_from_utf8(Variant& r_ret,Variant& p_self,const Variant** p_args) {
- ByteArray* ba = reinterpret_cast<ByteArray*>(p_self._data._mem);
+ PoolByteArray* ba = reinterpret_cast<PoolByteArray*>(p_self._data._mem);
String s;
if (ba->size()>=0) {
- ByteArray::Read r = ba->read();
+ PoolByteArray::Read r = ba->read();
s.parse_utf8((const char*)r.ptr(),ba->size());
}
r_ret=s;
}
- VCALL_LOCALMEM0R(ByteArray,size);
- VCALL_LOCALMEM2(ByteArray,set);
- VCALL_LOCALMEM1R(ByteArray,get);
- VCALL_LOCALMEM1(ByteArray,push_back);
- VCALL_LOCALMEM1(ByteArray,resize);
- VCALL_LOCALMEM2R(ByteArray,insert);
- VCALL_LOCALMEM1(ByteArray,remove);
- VCALL_LOCALMEM1(ByteArray,append);
- VCALL_LOCALMEM1(ByteArray,append_array);
- VCALL_LOCALMEM0(ByteArray,invert);
- VCALL_LOCALMEM2R(ByteArray,subarray);
-
- VCALL_LOCALMEM0R(IntArray,size);
- VCALL_LOCALMEM2(IntArray,set);
- VCALL_LOCALMEM1R(IntArray,get);
- VCALL_LOCALMEM1(IntArray,push_back);
- VCALL_LOCALMEM1(IntArray,resize);
- VCALL_LOCALMEM2R(IntArray,insert);
- VCALL_LOCALMEM1(IntArray,remove);
- VCALL_LOCALMEM1(IntArray,append);
- VCALL_LOCALMEM1(IntArray,append_array);
- VCALL_LOCALMEM0(IntArray,invert);
-
- VCALL_LOCALMEM0R(RealArray,size);
- VCALL_LOCALMEM2(RealArray,set);
- VCALL_LOCALMEM1R(RealArray,get);
- VCALL_LOCALMEM1(RealArray,push_back);
- VCALL_LOCALMEM1(RealArray,resize);
- VCALL_LOCALMEM2R(RealArray,insert);
- VCALL_LOCALMEM1(RealArray,remove);
- VCALL_LOCALMEM1(RealArray,append);
- VCALL_LOCALMEM1(RealArray,append_array);
- VCALL_LOCALMEM0(RealArray,invert);
-
- VCALL_LOCALMEM0R(StringArray,size);
- VCALL_LOCALMEM2(StringArray,set);
- VCALL_LOCALMEM1R(StringArray,get);
- VCALL_LOCALMEM1(StringArray,push_back);
- VCALL_LOCALMEM1(StringArray,resize);
- VCALL_LOCALMEM2R(StringArray,insert);
- VCALL_LOCALMEM1(StringArray,remove);
- VCALL_LOCALMEM1(StringArray,append);
- VCALL_LOCALMEM1(StringArray,append_array);
- VCALL_LOCALMEM0(StringArray,invert);
-
- VCALL_LOCALMEM0R(Vector2Array,size);
- VCALL_LOCALMEM2(Vector2Array,set);
- VCALL_LOCALMEM1R(Vector2Array,get);
- VCALL_LOCALMEM1(Vector2Array,push_back);
- VCALL_LOCALMEM1(Vector2Array,resize);
- VCALL_LOCALMEM2R(Vector2Array,insert);
- VCALL_LOCALMEM1(Vector2Array,remove);
- VCALL_LOCALMEM1(Vector2Array,append);
- VCALL_LOCALMEM1(Vector2Array,append_array);
- VCALL_LOCALMEM0(Vector2Array,invert);
-
- VCALL_LOCALMEM0R(Vector3Array,size);
- VCALL_LOCALMEM2(Vector3Array,set);
- VCALL_LOCALMEM1R(Vector3Array,get);
- VCALL_LOCALMEM1(Vector3Array,push_back);
- VCALL_LOCALMEM1(Vector3Array,resize);
- VCALL_LOCALMEM2R(Vector3Array,insert);
- VCALL_LOCALMEM1(Vector3Array,remove);
- VCALL_LOCALMEM1(Vector3Array,append);
- VCALL_LOCALMEM1(Vector3Array,append_array);
- VCALL_LOCALMEM0(Vector3Array,invert);
-
- VCALL_LOCALMEM0R(ColorArray,size);
- VCALL_LOCALMEM2(ColorArray,set);
- VCALL_LOCALMEM1R(ColorArray,get);
- VCALL_LOCALMEM1(ColorArray,push_back);
- VCALL_LOCALMEM1(ColorArray,resize);
- VCALL_LOCALMEM2R(ColorArray,insert);
- VCALL_LOCALMEM1(ColorArray,remove);
- VCALL_LOCALMEM1(ColorArray,append);
- VCALL_LOCALMEM1(ColorArray,append_array);
- VCALL_LOCALMEM0(ColorArray,invert);
+ VCALL_LOCALMEM0R(PoolByteArray,size);
+ VCALL_LOCALMEM2(PoolByteArray,set);
+ VCALL_LOCALMEM1R(PoolByteArray,get);
+ VCALL_LOCALMEM1(PoolByteArray,push_back);
+ VCALL_LOCALMEM1(PoolByteArray,resize);
+ VCALL_LOCALMEM2R(PoolByteArray,insert);
+ VCALL_LOCALMEM1(PoolByteArray,remove);
+ VCALL_LOCALMEM1(PoolByteArray,append);
+ VCALL_LOCALMEM1(PoolByteArray,append_array);
+ VCALL_LOCALMEM0(PoolByteArray,invert);
+ VCALL_LOCALMEM2R(PoolByteArray,subarray);
+
+ VCALL_LOCALMEM0R(PoolIntArray,size);
+ VCALL_LOCALMEM2(PoolIntArray,set);
+ VCALL_LOCALMEM1R(PoolIntArray,get);
+ VCALL_LOCALMEM1(PoolIntArray,push_back);
+ VCALL_LOCALMEM1(PoolIntArray,resize);
+ VCALL_LOCALMEM2R(PoolIntArray,insert);
+ VCALL_LOCALMEM1(PoolIntArray,remove);
+ VCALL_LOCALMEM1(PoolIntArray,append);
+ VCALL_LOCALMEM1(PoolIntArray,append_array);
+ VCALL_LOCALMEM0(PoolIntArray,invert);
+
+ VCALL_LOCALMEM0R(PoolRealArray,size);
+ VCALL_LOCALMEM2(PoolRealArray,set);
+ VCALL_LOCALMEM1R(PoolRealArray,get);
+ VCALL_LOCALMEM1(PoolRealArray,push_back);
+ VCALL_LOCALMEM1(PoolRealArray,resize);
+ VCALL_LOCALMEM2R(PoolRealArray,insert);
+ VCALL_LOCALMEM1(PoolRealArray,remove);
+ VCALL_LOCALMEM1(PoolRealArray,append);
+ VCALL_LOCALMEM1(PoolRealArray,append_array);
+ VCALL_LOCALMEM0(PoolRealArray,invert);
+
+ VCALL_LOCALMEM0R(PoolStringArray,size);
+ VCALL_LOCALMEM2(PoolStringArray,set);
+ VCALL_LOCALMEM1R(PoolStringArray,get);
+ VCALL_LOCALMEM1(PoolStringArray,push_back);
+ VCALL_LOCALMEM1(PoolStringArray,resize);
+ VCALL_LOCALMEM2R(PoolStringArray,insert);
+ VCALL_LOCALMEM1(PoolStringArray,remove);
+ VCALL_LOCALMEM1(PoolStringArray,append);
+ VCALL_LOCALMEM1(PoolStringArray,append_array);
+ VCALL_LOCALMEM0(PoolStringArray,invert);
+
+ VCALL_LOCALMEM0R(PoolVector2Array,size);
+ VCALL_LOCALMEM2(PoolVector2Array,set);
+ VCALL_LOCALMEM1R(PoolVector2Array,get);
+ VCALL_LOCALMEM1(PoolVector2Array,push_back);
+ VCALL_LOCALMEM1(PoolVector2Array,resize);
+ VCALL_LOCALMEM2R(PoolVector2Array,insert);
+ VCALL_LOCALMEM1(PoolVector2Array,remove);
+ VCALL_LOCALMEM1(PoolVector2Array,append);
+ VCALL_LOCALMEM1(PoolVector2Array,append_array);
+ VCALL_LOCALMEM0(PoolVector2Array,invert);
+
+ VCALL_LOCALMEM0R(PoolVector3Array,size);
+ VCALL_LOCALMEM2(PoolVector3Array,set);
+ VCALL_LOCALMEM1R(PoolVector3Array,get);
+ VCALL_LOCALMEM1(PoolVector3Array,push_back);
+ VCALL_LOCALMEM1(PoolVector3Array,resize);
+ VCALL_LOCALMEM2R(PoolVector3Array,insert);
+ VCALL_LOCALMEM1(PoolVector3Array,remove);
+ VCALL_LOCALMEM1(PoolVector3Array,append);
+ VCALL_LOCALMEM1(PoolVector3Array,append_array);
+ VCALL_LOCALMEM0(PoolVector3Array,invert);
+
+ VCALL_LOCALMEM0R(PoolColorArray,size);
+ VCALL_LOCALMEM2(PoolColorArray,set);
+ VCALL_LOCALMEM1R(PoolColorArray,get);
+ VCALL_LOCALMEM1(PoolColorArray,push_back);
+ VCALL_LOCALMEM1(PoolColorArray,resize);
+ VCALL_LOCALMEM2R(PoolColorArray,insert);
+ VCALL_LOCALMEM1(PoolColorArray,remove);
+ VCALL_LOCALMEM1(PoolColorArray,append);
+ VCALL_LOCALMEM1(PoolColorArray,append_array);
+ VCALL_LOCALMEM0(PoolColorArray,invert);
#define VCALL_PTR0(m_type,m_method)\
static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { reinterpret_cast<m_type*>(p_self._data._ptr)->m_method(); }
@@ -616,13 +626,9 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_PTR0R(Image,get_width);
VCALL_PTR0R(Image,get_height);
VCALL_PTR0R(Image,empty);
- VCALL_PTR3R(Image,get_pixel);
- VCALL_PTR4(Image, put_pixel);
VCALL_PTR0R(Image,get_used_rect);
- VCALL_PTR3R(Image,brushed);
VCALL_PTR1R(Image,load);
VCALL_PTR1R(Image,save_png);
- VCALL_PTR3(Image,brush_transfer);
VCALL_PTR1R(Image,get_rect);
VCALL_PTR1R(Image,compressed);
VCALL_PTR0R(Image,decompressed);
@@ -632,93 +638,93 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_PTR1R(Image, converted);
VCALL_PTR0(Image, fix_alpha_edges);
- VCALL_PTR0R( AABB, get_area );
- VCALL_PTR0R( AABB, has_no_area );
- VCALL_PTR0R( AABB, has_no_surface );
- VCALL_PTR1R( AABB, intersects );
- VCALL_PTR1R( AABB, encloses );
- VCALL_PTR1R( AABB, merge );
- VCALL_PTR1R( AABB, intersection );
- VCALL_PTR1R( AABB, intersects_plane );
- VCALL_PTR2R( AABB, intersects_segment );
- VCALL_PTR1R( AABB, has_point );
- VCALL_PTR1R( AABB, get_support );
- VCALL_PTR0R( AABB, get_longest_axis );
- VCALL_PTR0R( AABB, get_longest_axis_index );
- VCALL_PTR0R( AABB, get_longest_axis_size );
- VCALL_PTR0R( AABB, get_shortest_axis );
- VCALL_PTR0R( AABB, get_shortest_axis_index );
- VCALL_PTR0R( AABB, get_shortest_axis_size );
- VCALL_PTR1R( AABB, expand );
- VCALL_PTR1R( AABB, grow );
- VCALL_PTR1R( AABB, get_endpoint );
-
- VCALL_PTR0R( Matrix32, inverse );
- VCALL_PTR0R( Matrix32, affine_inverse );
- VCALL_PTR0R( Matrix32, get_rotation );
- VCALL_PTR0R( Matrix32, get_origin );
- VCALL_PTR0R( Matrix32, get_scale );
- VCALL_PTR0R( Matrix32, orthonormalized );
- VCALL_PTR1R( Matrix32, rotated );
- VCALL_PTR1R( Matrix32, scaled );
- VCALL_PTR1R( Matrix32, translated );
- VCALL_PTR2R( Matrix32, interpolate_with );
-
- static void _call_Matrix32_xform(Variant& r_ret,Variant& p_self,const Variant** p_args) {
+ VCALL_PTR0R( Rect3, get_area );
+ VCALL_PTR0R( Rect3, has_no_area );
+ VCALL_PTR0R( Rect3, has_no_surface );
+ VCALL_PTR1R( Rect3, intersects );
+ VCALL_PTR1R( Rect3, encloses );
+ VCALL_PTR1R( Rect3, merge );
+ VCALL_PTR1R( Rect3, intersection );
+ VCALL_PTR1R( Rect3, intersects_plane );
+ VCALL_PTR2R( Rect3, intersects_segment );
+ VCALL_PTR1R( Rect3, has_point );
+ VCALL_PTR1R( Rect3, get_support );
+ VCALL_PTR0R( Rect3, get_longest_axis );
+ VCALL_PTR0R( Rect3, get_longest_axis_index );
+ VCALL_PTR0R( Rect3, get_longest_axis_size );
+ VCALL_PTR0R( Rect3, get_shortest_axis );
+ VCALL_PTR0R( Rect3, get_shortest_axis_index );
+ VCALL_PTR0R( Rect3, get_shortest_axis_size );
+ VCALL_PTR1R( Rect3, expand );
+ VCALL_PTR1R( Rect3, grow );
+ VCALL_PTR1R( Rect3, get_endpoint );
+
+ VCALL_PTR0R( Transform2D, inverse );
+ VCALL_PTR0R( Transform2D, affine_inverse );
+ VCALL_PTR0R( Transform2D, get_rotation );
+ VCALL_PTR0R( Transform2D, get_origin );
+ VCALL_PTR0R( Transform2D, get_scale );
+ VCALL_PTR0R( Transform2D, orthonormalized );
+ VCALL_PTR1R( Transform2D, rotated );
+ VCALL_PTR1R( Transform2D, scaled );
+ VCALL_PTR1R( Transform2D, translated );
+ VCALL_PTR2R( Transform2D, interpolate_with );
+
+ static void _call_Transform2D_xform(Variant& r_ret,Variant& p_self,const Variant** p_args) {
switch(p_args[0]->type) {
- case Variant::VECTOR2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->xform( p_args[0]->operator Vector2()); return;
- case Variant::RECT2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->xform( p_args[0]->operator Rect2()); return;
+ case Variant::VECTOR2: r_ret=reinterpret_cast<Transform2D*>(p_self._data._ptr)->xform( p_args[0]->operator Vector2()); return;
+ case Variant::RECT2: r_ret=reinterpret_cast<Transform2D*>(p_self._data._ptr)->xform( p_args[0]->operator Rect2()); return;
default: r_ret=Variant();
}
}
- static void _call_Matrix32_xform_inv(Variant& r_ret,Variant& p_self,const Variant** p_args) {
+ static void _call_Transform2D_xform_inv(Variant& r_ret,Variant& p_self,const Variant** p_args) {
switch(p_args[0]->type) {
- case Variant::VECTOR2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Vector2()); return;
- case Variant::RECT2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Rect2()); return;
+ case Variant::VECTOR2: r_ret=reinterpret_cast<Transform2D*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Vector2()); return;
+ case Variant::RECT2: r_ret=reinterpret_cast<Transform2D*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Rect2()); return;
default: r_ret=Variant();
}
}
- static void _call_Matrix32_basis_xform(Variant& r_ret,Variant& p_self,const Variant** p_args) {
+ static void _call_Transform2D_basis_xform(Variant& r_ret,Variant& p_self,const Variant** p_args) {
switch(p_args[0]->type) {
- case Variant::VECTOR2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->basis_xform( p_args[0]->operator Vector2()); return;
+ case Variant::VECTOR2: r_ret=reinterpret_cast<Transform2D*>(p_self._data._ptr)->basis_xform( p_args[0]->operator Vector2()); return;
default: r_ret=Variant();
}
}
- static void _call_Matrix32_basis_xform_inv(Variant& r_ret,Variant& p_self,const Variant** p_args) {
+ static void _call_Transform2D_basis_xform_inv(Variant& r_ret,Variant& p_self,const Variant** p_args) {
switch(p_args[0]->type) {
- case Variant::VECTOR2: r_ret=reinterpret_cast<Matrix32*>(p_self._data._ptr)->basis_xform_inv( p_args[0]->operator Vector2()); return;
+ case Variant::VECTOR2: r_ret=reinterpret_cast<Transform2D*>(p_self._data._ptr)->basis_xform_inv( p_args[0]->operator Vector2()); return;
default: r_ret=Variant();
}
}
- VCALL_PTR0R( Matrix3, inverse );
- VCALL_PTR0R( Matrix3, transposed );
- VCALL_PTR0R( Matrix3, determinant );
- VCALL_PTR2R( Matrix3, rotated );
- VCALL_PTR1R( Matrix3, scaled );
- VCALL_PTR0R( Matrix3, get_scale );
- VCALL_PTR0R( Matrix3, get_euler );
- VCALL_PTR1R( Matrix3, tdotx );
- VCALL_PTR1R( Matrix3, tdoty );
- VCALL_PTR1R( Matrix3, tdotz );
- VCALL_PTR1R( Matrix3, xform );
- VCALL_PTR1R( Matrix3, xform_inv );
- VCALL_PTR0R( Matrix3, get_orthogonal_index );
- VCALL_PTR0R( Matrix3, orthonormalized );
+ VCALL_PTR0R( Basis, inverse );
+ VCALL_PTR0R( Basis, transposed );
+ VCALL_PTR0R( Basis, determinant );
+ VCALL_PTR2R( Basis, rotated );
+ VCALL_PTR1R( Basis, scaled );
+ VCALL_PTR0R( Basis, get_scale );
+ VCALL_PTR0R( Basis, get_euler );
+ VCALL_PTR1R( Basis, tdotx );
+ VCALL_PTR1R( Basis, tdoty );
+ VCALL_PTR1R( Basis, tdotz );
+ VCALL_PTR1R( Basis, xform );
+ VCALL_PTR1R( Basis, xform_inv );
+ VCALL_PTR0R( Basis, get_orthogonal_index );
+ VCALL_PTR0R( Basis, orthonormalized );
VCALL_PTR0R( Transform, inverse );
@@ -735,7 +741,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
case Variant::VECTOR3: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform( p_args[0]->operator Vector3()); return;
case Variant::PLANE: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform( p_args[0]->operator Plane()); return;
- case Variant::_AABB: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform( p_args[0]->operator AABB()); return;
+ case Variant::RECT3: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform( p_args[0]->operator Rect3()); return;
default: r_ret=Variant();
}
@@ -747,7 +753,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
case Variant::VECTOR3: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Vector3()); return;
case Variant::PLANE: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Plane()); return;
- case Variant::_AABB: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform_inv( p_args[0]->operator AABB()); return;
+ case Variant::RECT3: r_ret=reinterpret_cast<Transform*>(p_self._data._ptr)->xform_inv( p_args[0]->operator Rect3()); return;
default: r_ret=Variant();
}
}
@@ -799,15 +805,15 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
r_ret=Rect2(*p_args[0],*p_args[1],*p_args[2],*p_args[3]);
}
- static void Matrix32_init2(Variant& r_ret,const Variant** p_args) {
+ static void Transform2D_init2(Variant& r_ret,const Variant** p_args) {
- Matrix32 m(*p_args[0], *p_args[1]);
+ Transform2D m(*p_args[0], *p_args[1]);
r_ret=m;
}
- static void Matrix32_init3(Variant& r_ret,const Variant** p_args) {
+ static void Transform2D_init3(Variant& r_ret,const Variant** p_args) {
- Matrix32 m;
+ Transform2D m;
m[0]=*p_args[0];
m[1]=*p_args[1];
m[2]=*p_args[2];
@@ -868,23 +874,23 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
r_ret=Color::hex(*p_args[0]);
}
- static void AABB_init1(Variant& r_ret,const Variant** p_args) {
+ static void Rect3_init1(Variant& r_ret,const Variant** p_args) {
- r_ret=AABB(*p_args[0],*p_args[1]);
+ r_ret=Rect3(*p_args[0],*p_args[1]);
}
- static void Matrix3_init1(Variant& r_ret,const Variant** p_args) {
+ static void Basis_init1(Variant& r_ret,const Variant** p_args) {
- Matrix3 m;
+ Basis m;
m.set_axis(0,*p_args[0]);
m.set_axis(1,*p_args[1]);
m.set_axis(2,*p_args[2]);
r_ret=m;
}
- static void Matrix3_init2(Variant& r_ret,const Variant** p_args) {
+ static void Basis_init2(Variant& r_ret,const Variant** p_args) {
- r_ret=Matrix3(p_args[0]->operator Vector3(),p_args[1]->operator real_t());
+ r_ret=Basis(p_args[0]->operator Vector3(),p_args[1]->operator real_t());
}
static void Transform_init1(Variant& r_ret,const Variant** p_args) {
@@ -899,7 +905,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
static void Transform_init2(Variant& r_ret,const Variant** p_args) {
- r_ret=Transform(p_args[0]->operator Matrix3(),p_args[1]->operator Vector3());
+ r_ret=Transform(p_args[0]->operator Basis(),p_args[1]->operator Vector3());
}
static void Image_init1(Variant& r_ret, const Variant** p_args) {
@@ -1049,11 +1055,11 @@ Variant Variant::construct(const Variant::Type p_type, const Variant** p_args, i
case VECTOR2: return Vector2(); // 5
case RECT2: return Rect2();
case VECTOR3: return Vector3();
- case MATRIX32: return Matrix32();
+ case TRANSFORM2D: return Transform2D();
case PLANE: return Plane();
case QUAT: return Quat();
- case _AABB: return AABB(); //sorry naming convention fail :( not like it's used often // 10
- case MATRIX3: return Matrix3();
+ case RECT3: return Rect3(); //sorry naming convention fail :( not like it's used often // 10
+ case BASIS: return Basis();
case TRANSFORM: return Transform();
// misc types
@@ -1065,13 +1071,13 @@ Variant Variant::construct(const Variant::Type p_type, const Variant** p_args, i
case INPUT_EVENT: return InputEvent();;
case DICTIONARY: return Dictionary();;
case ARRAY: return Array();; // 20
- case RAW_ARRAY: return ByteArray();;
- case INT_ARRAY: return IntArray();;
- case REAL_ARRAY: return RealArray();;
- case STRING_ARRAY: return StringArray();;
- case VECTOR2_ARRAY: return Vector2Array();; // 25
- case VECTOR3_ARRAY: return Vector3Array();; // 25
- case COLOR_ARRAY: return ColorArray();;
+ case POOL_BYTE_ARRAY: return PoolByteArray();;
+ case POOL_INT_ARRAY: return PoolIntArray();;
+ case POOL_REAL_ARRAY: return PoolRealArray();;
+ case POOL_STRING_ARRAY: return PoolStringArray();;
+ case POOL_VECTOR2_ARRAY: return PoolVector2Array();; // 25
+ case POOL_VECTOR3_ARRAY: return PoolVector3Array();; // 25
+ case POOL_COLOR_ARRAY: return PoolColorArray();;
default: return Variant();
}
@@ -1120,8 +1126,8 @@ Variant Variant::construct(const Variant::Type p_type, const Variant** p_args, i
case VECTOR3: return (Vector3(*p_args[0]));
case PLANE: return (Plane(*p_args[0]));
case QUAT: return (Quat(*p_args[0]));
- case _AABB: return (AABB(*p_args[0])); //sorry naming convention fail :( not like it's used often // 10
- case MATRIX3: return (Matrix3(p_args[0]->operator Matrix3()));
+ case RECT3: return (Rect3(*p_args[0])); //sorry naming convention fail :( not like it's used often // 10
+ case BASIS: return (Basis(p_args[0]->operator Basis()));
case TRANSFORM: return (Transform(p_args[0]->operator Transform()));
// misc types
@@ -1135,13 +1141,13 @@ Variant Variant::construct(const Variant::Type p_type, const Variant** p_args, i
case ARRAY: return p_args[0]->operator Array();
// arrays
- case RAW_ARRAY: return (ByteArray(*p_args[0]));
- case INT_ARRAY: return (IntArray(*p_args[0]));
- case REAL_ARRAY: return (RealArray(*p_args[0]));
- case STRING_ARRAY: return (StringArray(*p_args[0]));
- case VECTOR2_ARRAY: return (Vector2Array(*p_args[0])); // 25
- case VECTOR3_ARRAY: return (Vector3Array(*p_args[0])); // 25
- case COLOR_ARRAY: return (ColorArray(*p_args[0]));
+ case POOL_BYTE_ARRAY: return (PoolByteArray(*p_args[0]));
+ case POOL_INT_ARRAY: return (PoolIntArray(*p_args[0]));
+ case POOL_REAL_ARRAY: return (PoolRealArray(*p_args[0]));
+ case POOL_STRING_ARRAY: return (PoolStringArray(*p_args[0]));
+ case POOL_VECTOR2_ARRAY: return (PoolVector2Array(*p_args[0])); // 25
+ case POOL_VECTOR3_ARRAY: return (PoolVector3Array(*p_args[0])); // 25
+ case POOL_COLOR_ARRAY: return (PoolColorArray(*p_args[0]));
default: return Variant();
}
}
@@ -1384,15 +1390,16 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC1(STRING,BOOL,String,ends_with,STRING,"text",varray());
ADDFUNC1(STRING,BOOL,String,is_subsequence_of,STRING,"text",varray());
ADDFUNC1(STRING,BOOL,String,is_subsequence_ofi,STRING,"text",varray());
- ADDFUNC0(STRING,STRING_ARRAY,String,bigrams,varray());
+ ADDFUNC0(STRING,POOL_STRING_ARRAY,String,bigrams,varray());
ADDFUNC1(STRING,REAL,String,similarity,STRING,"text",varray());
+ ADDFUNC2(STRING,STRING,String,format,NIL,"values",STRING,"placeholder",varray("{_}"));
ADDFUNC2(STRING,STRING,String,replace,STRING,"what",STRING,"forwhat",varray());
ADDFUNC2(STRING,STRING,String,replacen,STRING,"what",STRING,"forwhat",varray());
ADDFUNC2(STRING,STRING,String,insert,INT,"pos",STRING,"what",varray());
ADDFUNC0(STRING,STRING,String,capitalize,varray());
- ADDFUNC2(STRING,STRING_ARRAY,String,split,STRING,"divisor",BOOL,"allow_empty",varray(true));
- ADDFUNC2(STRING,REAL_ARRAY,String,split_floats,STRING,"divisor",BOOL,"allow_empty",varray(true));
+ ADDFUNC2(STRING,POOL_STRING_ARRAY,String,split,STRING,"divisor",BOOL,"allow_empty",varray(true));
+ ADDFUNC2(STRING,POOL_REAL_ARRAY,String,split_floats,STRING,"divisor",BOOL,"allow_empty",varray(true));
ADDFUNC0(STRING,STRING,String,to_upper,varray());
ADDFUNC0(STRING,STRING,String,to_lower,varray());
@@ -1400,16 +1407,16 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC1(STRING,STRING,String,left,INT,"pos",varray());
ADDFUNC1(STRING,STRING,String,right,INT,"pos",varray());
ADDFUNC2(STRING,STRING,String,strip_edges,BOOL,"left",BOOL,"right",varray(true,true));
- ADDFUNC0(STRING,STRING,String,extension,varray());
- ADDFUNC0(STRING,STRING,String,basename,varray());
+ ADDFUNC0(STRING,STRING,String,get_extension,varray());
+ ADDFUNC0(STRING,STRING,String,get_basename,varray());
ADDFUNC1(STRING,STRING,String,plus_file,STRING,"file",varray());
ADDFUNC1(STRING,INT,String,ord_at,INT,"at",varray());
ADDFUNC2(STRING,NIL,String,erase,INT,"pos",INT,"chars", varray());
ADDFUNC0(STRING,INT,String,hash,varray());
ADDFUNC0(STRING,STRING,String,md5_text,varray());
ADDFUNC0(STRING,STRING,String,sha256_text,varray());
- ADDFUNC0(STRING,RAW_ARRAY,String,md5_buffer,varray());
- ADDFUNC0(STRING,RAW_ARRAY,String,sha256_buffer,varray());
+ ADDFUNC0(STRING,POOL_BYTE_ARRAY,String,md5_buffer,varray());
+ ADDFUNC0(STRING,POOL_BYTE_ARRAY,String,sha256_buffer,varray());
ADDFUNC0(STRING,BOOL,String,empty,varray());
ADDFUNC0(STRING,BOOL,String,is_abs_path,varray());
ADDFUNC0(STRING,BOOL,String,is_rel_path,varray());
@@ -1433,8 +1440,9 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC1(STRING,STRING,String,pad_decimals,INT,"digits",varray());
ADDFUNC1(STRING,STRING,String,pad_zeros,INT,"digits",varray());
- ADDFUNC0(STRING,RAW_ARRAY,String,to_ascii,varray());
- ADDFUNC0(STRING,RAW_ARRAY,String,to_utf8,varray());
+ ADDFUNC0(STRING,POOL_BYTE_ARRAY,String,to_ascii,varray());
+ ADDFUNC0(STRING,POOL_BYTE_ARRAY,String,to_utf8,varray());
+
ADDFUNC0(VECTOR2,VECTOR2,Vector2,normalized,varray());
@@ -1450,9 +1458,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC1(VECTOR2,VECTOR2,Vector2,rotated,REAL,"phi",varray());
ADDFUNC0(VECTOR2,VECTOR2,Vector2,tangent,varray());
ADDFUNC0(VECTOR2,VECTOR2,Vector2,floor,varray());
- ADDFUNC0(VECTOR2,VECTOR2,Vector2,floorf,varray());
ADDFUNC1(VECTOR2,VECTOR2,Vector2,snapped,VECTOR2,"by",varray());
- ADDFUNC0(VECTOR2,REAL,Vector2,get_aspect,varray());
+ ADDFUNC0(VECTOR2,REAL,Vector2,aspect,varray());
ADDFUNC1(VECTOR2,REAL,Vector2,dot,VECTOR2,"with",varray());
ADDFUNC1(VECTOR2,VECTOR2,Vector2,slide,VECTOR2,"vec",varray());
ADDFUNC1(VECTOR2,VECTOR2,Vector2,reflect,VECTOR2,"vec",varray());
@@ -1482,11 +1489,15 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC4(VECTOR3,VECTOR3,Vector3,cubic_interpolate,VECTOR3,"b",VECTOR3,"pre_a",VECTOR3,"post_b",REAL,"t",varray());
ADDFUNC1(VECTOR3,REAL,Vector3,dot,VECTOR3,"b",varray());
ADDFUNC1(VECTOR3,VECTOR3,Vector3,cross,VECTOR3,"b",varray());
+ ADDFUNC1(VECTOR3,BASIS,Vector3,outer,VECTOR3,"b",varray());
+ ADDFUNC0(VECTOR3,BASIS,Vector3,to_diagonal_matrix,varray());
+ ADDFUNC0(VECTOR3,VECTOR3,Vector3,abs,varray());
ADDFUNC0(VECTOR3,VECTOR3,Vector3,abs,varray());
ADDFUNC0(VECTOR3,VECTOR3,Vector3,floor,varray());
ADDFUNC0(VECTOR3,VECTOR3,Vector3,ceil,varray());
ADDFUNC1(VECTOR3,REAL,Vector3,distance_to,VECTOR3,"b",varray());
ADDFUNC1(VECTOR3,REAL,Vector3,distance_squared_to,VECTOR3,"b",varray());
+ ADDFUNC1(VECTOR3,REAL,Vector3,angle_to,VECTOR3,"to",varray());
ADDFUNC1(VECTOR3,VECTOR3,Vector3,slide,VECTOR3,"by",varray());
ADDFUNC1(VECTOR3,VECTOR3,Vector3,reflect,VECTOR3,"by",varray());
@@ -1524,18 +1535,14 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC0(IMAGE, INT, Image, get_width, varray());
ADDFUNC0(IMAGE, INT, Image, get_height, varray());
ADDFUNC0(IMAGE, BOOL, Image, empty, varray());
- ADDFUNC3(IMAGE, COLOR, Image, get_pixel, INT, "x", INT, "y", INT, "mipmap_level", varray(0));
- ADDFUNC4(IMAGE, NIL, Image, put_pixel, INT, "x", INT, "y", COLOR, "color", INT, "mipmap_level", varray(0));
- ADDFUNC3(IMAGE, IMAGE, Image, brushed, IMAGE, "src", IMAGE, "brush", VECTOR2, "pos", varray(0));
ADDFUNC1(IMAGE, INT, Image, load, STRING, "path", varray(0));
ADDFUNC1(IMAGE, INT, Image, save_png, STRING, "path", varray(0));
- ADDFUNC3(IMAGE, NIL, Image, brush_transfer, IMAGE, "src", IMAGE, "brush", VECTOR2, "pos", varray(0));
ADDFUNC0(IMAGE, RECT2, Image, get_used_rect, varray(0));
ADDFUNC1(IMAGE, IMAGE, Image, get_rect, RECT2, "area", varray(0));
ADDFUNC1(IMAGE, IMAGE, Image, compressed, INT, "format", varray(0));
ADDFUNC0(IMAGE, IMAGE, Image, decompressed, varray(0));
ADDFUNC3(IMAGE, IMAGE, Image, resized, INT, "x", INT, "y", INT, "interpolation", varray(((int)Image::INTERPOLATE_BILINEAR)));
- ADDFUNC0(IMAGE, RAW_ARRAY, Image, get_data, varray());
+ ADDFUNC0(IMAGE, POOL_BYTE_ARRAY, Image, get_data, varray());
ADDFUNC3(IMAGE, NIL, Image, blit_rect, IMAGE, "src", RECT2, "src_rect", VECTOR2, "dest", varray(0));
ADDFUNC1(IMAGE, IMAGE, Image, converted, INT, "format", varray(0));
ADDFUNC0(IMAGE, NIL, Image, fix_alpha_edges, varray());
@@ -1560,9 +1567,6 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC0(DICTIONARY,ARRAY,Dictionary,keys,varray());
ADDFUNC0(DICTIONARY,ARRAY,Dictionary,values,varray());
- ADDFUNC1(DICTIONARY,INT,Dictionary,parse_json,STRING,"json",varray());
- ADDFUNC0(DICTIONARY,STRING,Dictionary,to_json,varray());
-
ADDFUNC0(ARRAY,INT,Array,size,varray());
ADDFUNC0(ARRAY,BOOL,Array,empty,varray());
ADDFUNC0(ARRAY,NIL,Array,clear,varray());
@@ -1574,6 +1578,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC2(ARRAY,NIL,Array,insert,INT,"pos",NIL,"value",varray());
ADDFUNC1(ARRAY,NIL,Array,remove,INT,"pos",varray());
ADDFUNC1(ARRAY,NIL,Array,erase,NIL,"value",varray());
+ ADDFUNC0(ARRAY,NIL,Array,front,varray());
+ ADDFUNC0(ARRAY,NIL,Array,back,varray());
ADDFUNC2(ARRAY,INT,Array,find,NIL,"what",INT,"from",varray(0));
ADDFUNC2(ARRAY,INT,Array,rfind,NIL,"what",INT,"from",varray(-1));
ADDFUNC1(ARRAY,INT,Array,find_last,NIL,"value",varray());
@@ -1584,135 +1590,135 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC0(ARRAY,NIL,Array,sort,varray());
ADDFUNC2(ARRAY,NIL,Array,sort_custom,OBJECT,"obj",STRING,"func",varray());
ADDFUNC0(ARRAY,NIL,Array,invert,varray());
- ADDFUNC0(ARRAY,BOOL,Array,is_shared,varray());
-
- ADDFUNC0(RAW_ARRAY,INT,ByteArray,size,varray());
- ADDFUNC2(RAW_ARRAY,NIL,ByteArray,set,INT,"idx",INT,"byte",varray());
- ADDFUNC1(RAW_ARRAY,NIL,ByteArray,push_back,INT,"byte",varray());
- ADDFUNC1(RAW_ARRAY,NIL,ByteArray,append,INT,"byte",varray());
- ADDFUNC1(RAW_ARRAY,NIL,ByteArray,append_array,RAW_ARRAY,"array",varray());
- ADDFUNC1(RAW_ARRAY,NIL,ByteArray,remove,INT,"idx",varray());
- ADDFUNC2(RAW_ARRAY,INT,ByteArray,insert,INT,"idx",INT,"byte",varray());
- ADDFUNC1(RAW_ARRAY,NIL,ByteArray,resize,INT,"idx",varray());
- ADDFUNC0(RAW_ARRAY,NIL,ByteArray,invert,varray());
- ADDFUNC2(RAW_ARRAY,RAW_ARRAY,ByteArray,subarray,INT,"from",INT,"to",varray());
-
- ADDFUNC0(RAW_ARRAY,STRING,ByteArray,get_string_from_ascii,varray());
- ADDFUNC0(RAW_ARRAY,STRING,ByteArray,get_string_from_utf8,varray());
-
-
- ADDFUNC0(INT_ARRAY,INT,IntArray,size,varray());
- ADDFUNC2(INT_ARRAY,NIL,IntArray,set,INT,"idx",INT,"integer",varray());
- ADDFUNC1(INT_ARRAY,NIL,IntArray,push_back,INT,"integer",varray());
- ADDFUNC1(INT_ARRAY,NIL,IntArray,append,INT,"integer",varray());
- ADDFUNC1(INT_ARRAY,NIL,IntArray,append_array,INT_ARRAY,"array",varray());
- ADDFUNC1(INT_ARRAY,NIL,IntArray,remove,INT,"idx",varray());
- ADDFUNC2(INT_ARRAY,INT,IntArray,insert,INT,"idx",INT,"integer",varray());
- ADDFUNC1(INT_ARRAY,NIL,IntArray,resize,INT,"idx",varray());
- ADDFUNC0(INT_ARRAY,NIL,IntArray,invert,varray());
-
- ADDFUNC0(REAL_ARRAY,INT,RealArray,size,varray());
- ADDFUNC2(REAL_ARRAY,NIL,RealArray,set,INT,"idx",REAL,"value",varray());
- ADDFUNC1(REAL_ARRAY,NIL,RealArray,push_back,REAL,"value",varray());
- ADDFUNC1(REAL_ARRAY,NIL,RealArray,append,REAL,"value",varray());
- ADDFUNC1(REAL_ARRAY,NIL,RealArray,append_array,REAL_ARRAY,"array",varray());
- ADDFUNC1(REAL_ARRAY,NIL,RealArray,remove,INT,"idx",varray());
- ADDFUNC2(REAL_ARRAY,INT,RealArray,insert,INT,"idx",REAL,"value",varray());
- ADDFUNC1(REAL_ARRAY,NIL,RealArray,resize,INT,"idx",varray());
- ADDFUNC0(REAL_ARRAY,NIL,RealArray,invert,varray());
-
- ADDFUNC0(STRING_ARRAY,INT,StringArray,size,varray());
- ADDFUNC2(STRING_ARRAY,NIL,StringArray,set,INT,"idx",STRING,"string",varray());
- ADDFUNC1(STRING_ARRAY,NIL,StringArray,push_back,STRING,"string",varray());
- ADDFUNC1(STRING_ARRAY,NIL,StringArray,append,STRING,"string",varray());
- ADDFUNC1(STRING_ARRAY,NIL,StringArray,append_array,STRING_ARRAY,"array",varray());
- ADDFUNC1(STRING_ARRAY,NIL,StringArray,remove,INT,"idx",varray());
- ADDFUNC2(STRING_ARRAY,INT,StringArray,insert,INT,"idx",STRING,"string",varray());
- ADDFUNC1(STRING_ARRAY,NIL,StringArray,resize,INT,"idx",varray());
- ADDFUNC0(STRING_ARRAY,NIL,StringArray,invert,varray());
-
- ADDFUNC0(VECTOR2_ARRAY,INT,Vector2Array,size,varray());
- ADDFUNC2(VECTOR2_ARRAY,NIL,Vector2Array,set,INT,"idx",VECTOR2,"vector2",varray());
- ADDFUNC1(VECTOR2_ARRAY,NIL,Vector2Array,push_back,VECTOR2,"vector2",varray());
- ADDFUNC1(VECTOR2_ARRAY,NIL,Vector2Array,append,VECTOR2,"vector2",varray());
- ADDFUNC1(VECTOR2_ARRAY,NIL,Vector2Array,append_array,VECTOR2_ARRAY,"array",varray());
- ADDFUNC1(VECTOR2_ARRAY,NIL,Vector2Array,remove,INT,"idx",varray());
- ADDFUNC2(VECTOR2_ARRAY,INT,Vector2Array,insert,INT,"idx",VECTOR2,"vector2",varray());
- ADDFUNC1(VECTOR2_ARRAY,NIL,Vector2Array,resize,INT,"idx",varray());
- ADDFUNC0(VECTOR2_ARRAY,NIL,Vector2Array,invert,varray());
-
- ADDFUNC0(VECTOR3_ARRAY,INT,Vector3Array,size,varray());
- ADDFUNC2(VECTOR3_ARRAY,NIL,Vector3Array,set,INT,"idx",VECTOR3,"vector3",varray());
- ADDFUNC1(VECTOR3_ARRAY,NIL,Vector3Array,push_back,VECTOR3,"vector3",varray());
- ADDFUNC1(VECTOR3_ARRAY,NIL,Vector3Array,append,VECTOR3,"vector3",varray());
- ADDFUNC1(VECTOR3_ARRAY,NIL,Vector3Array,append_array,VECTOR3_ARRAY,"array",varray());
- ADDFUNC1(VECTOR3_ARRAY,NIL,Vector3Array,remove,INT,"idx",varray());
- ADDFUNC2(VECTOR3_ARRAY,INT,Vector3Array,insert,INT,"idx",VECTOR3,"vector3",varray());
- ADDFUNC1(VECTOR3_ARRAY,NIL,Vector3Array,resize,INT,"idx",varray());
- ADDFUNC0(VECTOR3_ARRAY,NIL,Vector3Array,invert,varray());
-
- ADDFUNC0(COLOR_ARRAY,INT,ColorArray,size,varray());
- ADDFUNC2(COLOR_ARRAY,NIL,ColorArray,set,INT,"idx",COLOR,"color",varray());
- ADDFUNC1(COLOR_ARRAY,NIL,ColorArray,push_back,COLOR,"color",varray());
- ADDFUNC1(COLOR_ARRAY,NIL,ColorArray,append,COLOR,"color",varray());
- ADDFUNC1(COLOR_ARRAY,NIL,ColorArray,append_array,COLOR_ARRAY,"array",varray());
- ADDFUNC1(COLOR_ARRAY,NIL,ColorArray,remove,INT,"idx",varray());
- ADDFUNC2(COLOR_ARRAY,INT,ColorArray,insert,INT,"idx",COLOR,"color",varray());
- ADDFUNC1(COLOR_ARRAY,NIL,ColorArray,resize,INT,"idx",varray());
- ADDFUNC0(COLOR_ARRAY,NIL,ColorArray,invert,varray());
+
+
+ ADDFUNC0(POOL_BYTE_ARRAY,INT,PoolByteArray,size,varray());
+ ADDFUNC2(POOL_BYTE_ARRAY,NIL,PoolByteArray,set,INT,"idx",INT,"byte",varray());
+ ADDFUNC1(POOL_BYTE_ARRAY,NIL,PoolByteArray,push_back,INT,"byte",varray());
+ ADDFUNC1(POOL_BYTE_ARRAY,NIL,PoolByteArray,append,INT,"byte",varray());
+ ADDFUNC1(POOL_BYTE_ARRAY,NIL,PoolByteArray,append_array,POOL_BYTE_ARRAY,"array",varray());
+ ADDFUNC1(POOL_BYTE_ARRAY,NIL,PoolByteArray,remove,INT,"idx",varray());
+ ADDFUNC2(POOL_BYTE_ARRAY,INT,PoolByteArray,insert,INT,"idx",INT,"byte",varray());
+ ADDFUNC1(POOL_BYTE_ARRAY,NIL,PoolByteArray,resize,INT,"idx",varray());
+ ADDFUNC0(POOL_BYTE_ARRAY,NIL,PoolByteArray,invert,varray());
+ ADDFUNC2(POOL_BYTE_ARRAY,POOL_BYTE_ARRAY,PoolByteArray,subarray,INT,"from",INT,"to",varray());
+
+ ADDFUNC0(POOL_BYTE_ARRAY,STRING,PoolByteArray,get_string_from_ascii,varray());
+ ADDFUNC0(POOL_BYTE_ARRAY,STRING,PoolByteArray,get_string_from_utf8,varray());
+
+
+ ADDFUNC0(POOL_INT_ARRAY,INT,PoolIntArray,size,varray());
+ ADDFUNC2(POOL_INT_ARRAY,NIL,PoolIntArray,set,INT,"idx",INT,"integer",varray());
+ ADDFUNC1(POOL_INT_ARRAY,NIL,PoolIntArray,push_back,INT,"integer",varray());
+ ADDFUNC1(POOL_INT_ARRAY,NIL,PoolIntArray,append,INT,"integer",varray());
+ ADDFUNC1(POOL_INT_ARRAY,NIL,PoolIntArray,append_array,POOL_INT_ARRAY,"array",varray());
+ ADDFUNC1(POOL_INT_ARRAY,NIL,PoolIntArray,remove,INT,"idx",varray());
+ ADDFUNC2(POOL_INT_ARRAY,INT,PoolIntArray,insert,INT,"idx",INT,"integer",varray());
+ ADDFUNC1(POOL_INT_ARRAY,NIL,PoolIntArray,resize,INT,"idx",varray());
+ ADDFUNC0(POOL_INT_ARRAY,NIL,PoolIntArray,invert,varray());
+
+ ADDFUNC0(POOL_REAL_ARRAY,INT,PoolRealArray,size,varray());
+ ADDFUNC2(POOL_REAL_ARRAY,NIL,PoolRealArray,set,INT,"idx",REAL,"value",varray());
+ ADDFUNC1(POOL_REAL_ARRAY,NIL,PoolRealArray,push_back,REAL,"value",varray());
+ ADDFUNC1(POOL_REAL_ARRAY,NIL,PoolRealArray,append,REAL,"value",varray());
+ ADDFUNC1(POOL_REAL_ARRAY,NIL,PoolRealArray,append_array,POOL_REAL_ARRAY,"array",varray());
+ ADDFUNC1(POOL_REAL_ARRAY,NIL,PoolRealArray,remove,INT,"idx",varray());
+ ADDFUNC2(POOL_REAL_ARRAY,INT,PoolRealArray,insert,INT,"idx",REAL,"value",varray());
+ ADDFUNC1(POOL_REAL_ARRAY,NIL,PoolRealArray,resize,INT,"idx",varray());
+ ADDFUNC0(POOL_REAL_ARRAY,NIL,PoolRealArray,invert,varray());
+
+ ADDFUNC0(POOL_STRING_ARRAY,INT,PoolStringArray,size,varray());
+ ADDFUNC2(POOL_STRING_ARRAY,NIL,PoolStringArray,set,INT,"idx",STRING,"string",varray());
+ ADDFUNC1(POOL_STRING_ARRAY,NIL,PoolStringArray,push_back,STRING,"string",varray());
+ ADDFUNC1(POOL_STRING_ARRAY,NIL,PoolStringArray,append,STRING,"string",varray());
+ ADDFUNC1(POOL_STRING_ARRAY,NIL,PoolStringArray,append_array,POOL_STRING_ARRAY,"array",varray());
+ ADDFUNC1(POOL_STRING_ARRAY,NIL,PoolStringArray,remove,INT,"idx",varray());
+ ADDFUNC2(POOL_STRING_ARRAY,INT,PoolStringArray,insert,INT,"idx",STRING,"string",varray());
+ ADDFUNC1(POOL_STRING_ARRAY,NIL,PoolStringArray,resize,INT,"idx",varray());
+ ADDFUNC0(POOL_STRING_ARRAY,NIL,PoolStringArray,invert,varray());
+
+ ADDFUNC0(POOL_VECTOR2_ARRAY,INT,PoolVector2Array,size,varray());
+ ADDFUNC2(POOL_VECTOR2_ARRAY,NIL,PoolVector2Array,set,INT,"idx",VECTOR2,"vector2",varray());
+ ADDFUNC1(POOL_VECTOR2_ARRAY,NIL,PoolVector2Array,push_back,VECTOR2,"vector2",varray());
+ ADDFUNC1(POOL_VECTOR2_ARRAY,NIL,PoolVector2Array,append,VECTOR2,"vector2",varray());
+ ADDFUNC1(POOL_VECTOR2_ARRAY,NIL,PoolVector2Array,append_array,POOL_VECTOR2_ARRAY,"array",varray());
+ ADDFUNC1(POOL_VECTOR2_ARRAY,NIL,PoolVector2Array,remove,INT,"idx",varray());
+ ADDFUNC2(POOL_VECTOR2_ARRAY,INT,PoolVector2Array,insert,INT,"idx",VECTOR2,"vector2",varray());
+ ADDFUNC1(POOL_VECTOR2_ARRAY,NIL,PoolVector2Array,resize,INT,"idx",varray());
+ ADDFUNC0(POOL_VECTOR2_ARRAY,NIL,PoolVector2Array,invert,varray());
+
+ ADDFUNC0(POOL_VECTOR3_ARRAY,INT,PoolVector3Array,size,varray());
+ ADDFUNC2(POOL_VECTOR3_ARRAY,NIL,PoolVector3Array,set,INT,"idx",VECTOR3,"vector3",varray());
+ ADDFUNC1(POOL_VECTOR3_ARRAY,NIL,PoolVector3Array,push_back,VECTOR3,"vector3",varray());
+ ADDFUNC1(POOL_VECTOR3_ARRAY,NIL,PoolVector3Array,append,VECTOR3,"vector3",varray());
+ ADDFUNC1(POOL_VECTOR3_ARRAY,NIL,PoolVector3Array,append_array,POOL_VECTOR3_ARRAY,"array",varray());
+ ADDFUNC1(POOL_VECTOR3_ARRAY,NIL,PoolVector3Array,remove,INT,"idx",varray());
+ ADDFUNC2(POOL_VECTOR3_ARRAY,INT,PoolVector3Array,insert,INT,"idx",VECTOR3,"vector3",varray());
+ ADDFUNC1(POOL_VECTOR3_ARRAY,NIL,PoolVector3Array,resize,INT,"idx",varray());
+ ADDFUNC0(POOL_VECTOR3_ARRAY,NIL,PoolVector3Array,invert,varray());
+
+ ADDFUNC0(POOL_COLOR_ARRAY,INT,PoolColorArray,size,varray());
+ ADDFUNC2(POOL_COLOR_ARRAY,NIL,PoolColorArray,set,INT,"idx",COLOR,"color",varray());
+ ADDFUNC1(POOL_COLOR_ARRAY,NIL,PoolColorArray,push_back,COLOR,"color",varray());
+ ADDFUNC1(POOL_COLOR_ARRAY,NIL,PoolColorArray,append,COLOR,"color",varray());
+ ADDFUNC1(POOL_COLOR_ARRAY,NIL,PoolColorArray,append_array,POOL_COLOR_ARRAY,"array",varray());
+ ADDFUNC1(POOL_COLOR_ARRAY,NIL,PoolColorArray,remove,INT,"idx",varray());
+ ADDFUNC2(POOL_COLOR_ARRAY,INT,PoolColorArray,insert,INT,"idx",COLOR,"color",varray());
+ ADDFUNC1(POOL_COLOR_ARRAY,NIL,PoolColorArray,resize,INT,"idx",varray());
+ ADDFUNC0(POOL_COLOR_ARRAY,NIL,PoolColorArray,invert,varray());
//pointerbased
- ADDFUNC0(_AABB,REAL,AABB,get_area,varray());
- ADDFUNC0(_AABB,BOOL,AABB,has_no_area,varray());
- ADDFUNC0(_AABB,BOOL,AABB,has_no_surface,varray());
- ADDFUNC1(_AABB,BOOL,AABB,intersects,_AABB,"with",varray());
- ADDFUNC1(_AABB,BOOL,AABB,encloses,_AABB,"with",varray());
- ADDFUNC1(_AABB,_AABB,AABB,merge,_AABB,"with",varray());
- ADDFUNC1(_AABB,_AABB,AABB,intersection,_AABB,"with",varray());
- ADDFUNC1(_AABB,BOOL,AABB,intersects_plane,PLANE,"plane",varray());
- ADDFUNC2(_AABB,BOOL,AABB,intersects_segment,VECTOR3,"from",VECTOR3,"to",varray());
- ADDFUNC1(_AABB,BOOL,AABB,has_point,VECTOR3,"point",varray());
- ADDFUNC1(_AABB,VECTOR3,AABB,get_support,VECTOR3,"dir",varray());
- ADDFUNC0(_AABB,VECTOR3,AABB,get_longest_axis,varray());
- ADDFUNC0(_AABB,INT,AABB,get_longest_axis_index,varray());
- ADDFUNC0(_AABB,REAL,AABB,get_longest_axis_size,varray());
- ADDFUNC0(_AABB,VECTOR3,AABB,get_shortest_axis,varray());
- ADDFUNC0(_AABB,INT,AABB,get_shortest_axis_index,varray());
- ADDFUNC0(_AABB,REAL,AABB,get_shortest_axis_size,varray());
- ADDFUNC1(_AABB,_AABB,AABB,expand,VECTOR3,"to_point",varray());
- ADDFUNC1(_AABB,_AABB,AABB,grow,REAL,"by",varray());
- ADDFUNC1(_AABB,VECTOR3,AABB,get_endpoint,INT,"idx",varray());
-
- ADDFUNC0(MATRIX32,MATRIX32,Matrix32,inverse,varray());
- ADDFUNC0(MATRIX32,MATRIX32,Matrix32,affine_inverse,varray());
- ADDFUNC0(MATRIX32,REAL,Matrix32,get_rotation,varray());
- ADDFUNC0(MATRIX32,VECTOR2,Matrix32,get_origin,varray());
- ADDFUNC0(MATRIX32,VECTOR2,Matrix32,get_scale,varray());
- ADDFUNC0(MATRIX32,MATRIX32,Matrix32,orthonormalized,varray());
- ADDFUNC1(MATRIX32,MATRIX32,Matrix32,rotated,REAL,"phi",varray());
- ADDFUNC1(MATRIX32,MATRIX32,Matrix32,scaled,VECTOR2,"scale",varray());
- ADDFUNC1(MATRIX32,MATRIX32,Matrix32,translated,VECTOR2,"offset",varray());
- ADDFUNC1(MATRIX32,MATRIX32,Matrix32,xform,NIL,"v",varray());
- ADDFUNC1(MATRIX32,MATRIX32,Matrix32,xform_inv,NIL,"v",varray());
- ADDFUNC1(MATRIX32,MATRIX32,Matrix32,basis_xform,NIL,"v",varray());
- ADDFUNC1(MATRIX32,MATRIX32,Matrix32,basis_xform_inv,NIL,"v",varray());
- ADDFUNC2(MATRIX32,MATRIX32,Matrix32,interpolate_with,MATRIX32,"m",REAL,"c",varray());
-
- ADDFUNC0(MATRIX3,MATRIX3,Matrix3,inverse,varray());
- ADDFUNC0(MATRIX3,MATRIX3,Matrix3,transposed,varray());
- ADDFUNC0(MATRIX3,MATRIX3,Matrix3,orthonormalized,varray());
- ADDFUNC0(MATRIX3,REAL,Matrix3,determinant,varray());
- ADDFUNC2(MATRIX3,MATRIX3,Matrix3,rotated,VECTOR3,"axis",REAL,"phi",varray());
- ADDFUNC1(MATRIX3,MATRIX3,Matrix3,scaled,VECTOR3,"scale",varray());
- ADDFUNC0(MATRIX3,VECTOR3,Matrix3,get_scale,varray());
- ADDFUNC0(MATRIX3,VECTOR3,Matrix3,get_euler,varray());
- ADDFUNC1(MATRIX3,REAL,Matrix3,tdotx,VECTOR3,"with",varray());
- ADDFUNC1(MATRIX3,REAL,Matrix3,tdoty,VECTOR3,"with",varray());
- ADDFUNC1(MATRIX3,REAL,Matrix3,tdotz,VECTOR3,"with",varray());
- ADDFUNC1(MATRIX3,VECTOR3,Matrix3,xform,VECTOR3,"v",varray());
- ADDFUNC1(MATRIX3,VECTOR3,Matrix3,xform_inv,VECTOR3,"v",varray());
- ADDFUNC0(MATRIX3,INT,Matrix3,get_orthogonal_index,varray());
+ ADDFUNC0(RECT3,REAL,Rect3,get_area,varray());
+ ADDFUNC0(RECT3,BOOL,Rect3,has_no_area,varray());
+ ADDFUNC0(RECT3,BOOL,Rect3,has_no_surface,varray());
+ ADDFUNC1(RECT3,BOOL,Rect3,intersects,RECT3,"with",varray());
+ ADDFUNC1(RECT3,BOOL,Rect3,encloses,RECT3,"with",varray());
+ ADDFUNC1(RECT3,RECT3,Rect3,merge,RECT3,"with",varray());
+ ADDFUNC1(RECT3,RECT3,Rect3,intersection,RECT3,"with",varray());
+ ADDFUNC1(RECT3,BOOL,Rect3,intersects_plane,PLANE,"plane",varray());
+ ADDFUNC2(RECT3,BOOL,Rect3,intersects_segment,VECTOR3,"from",VECTOR3,"to",varray());
+ ADDFUNC1(RECT3,BOOL,Rect3,has_point,VECTOR3,"point",varray());
+ ADDFUNC1(RECT3,VECTOR3,Rect3,get_support,VECTOR3,"dir",varray());
+ ADDFUNC0(RECT3,VECTOR3,Rect3,get_longest_axis,varray());
+ ADDFUNC0(RECT3,INT,Rect3,get_longest_axis_index,varray());
+ ADDFUNC0(RECT3,REAL,Rect3,get_longest_axis_size,varray());
+ ADDFUNC0(RECT3,VECTOR3,Rect3,get_shortest_axis,varray());
+ ADDFUNC0(RECT3,INT,Rect3,get_shortest_axis_index,varray());
+ ADDFUNC0(RECT3,REAL,Rect3,get_shortest_axis_size,varray());
+ ADDFUNC1(RECT3,RECT3,Rect3,expand,VECTOR3,"to_point",varray());
+ ADDFUNC1(RECT3,RECT3,Rect3,grow,REAL,"by",varray());
+ ADDFUNC1(RECT3,VECTOR3,Rect3,get_endpoint,INT,"idx",varray());
+
+ ADDFUNC0(TRANSFORM2D,TRANSFORM2D,Transform2D,inverse,varray());
+ ADDFUNC0(TRANSFORM2D,TRANSFORM2D,Transform2D,affine_inverse,varray());
+ ADDFUNC0(TRANSFORM2D,REAL,Transform2D,get_rotation,varray());
+ ADDFUNC0(TRANSFORM2D,VECTOR2,Transform2D,get_origin,varray());
+ ADDFUNC0(TRANSFORM2D,VECTOR2,Transform2D,get_scale,varray());
+ ADDFUNC0(TRANSFORM2D,TRANSFORM2D,Transform2D,orthonormalized,varray());
+ ADDFUNC1(TRANSFORM2D,TRANSFORM2D,Transform2D,rotated,REAL,"phi",varray());
+ ADDFUNC1(TRANSFORM2D,TRANSFORM2D,Transform2D,scaled,VECTOR2,"scale",varray());
+ ADDFUNC1(TRANSFORM2D,TRANSFORM2D,Transform2D,translated,VECTOR2,"offset",varray());
+ ADDFUNC1(TRANSFORM2D,TRANSFORM2D,Transform2D,xform,NIL,"v",varray());
+ ADDFUNC1(TRANSFORM2D,TRANSFORM2D,Transform2D,xform_inv,NIL,"v",varray());
+ ADDFUNC1(TRANSFORM2D,TRANSFORM2D,Transform2D,basis_xform,NIL,"v",varray());
+ ADDFUNC1(TRANSFORM2D,TRANSFORM2D,Transform2D,basis_xform_inv,NIL,"v",varray());
+ ADDFUNC2(TRANSFORM2D,TRANSFORM2D,Transform2D,interpolate_with,TRANSFORM2D,"m",REAL,"c",varray());
+
+ ADDFUNC0(BASIS,BASIS,Basis,inverse,varray());
+ ADDFUNC0(BASIS,BASIS,Basis,transposed,varray());
+ ADDFUNC0(BASIS,BASIS,Basis,orthonormalized,varray());
+ ADDFUNC0(BASIS,REAL,Basis,determinant,varray());
+ ADDFUNC2(BASIS,BASIS,Basis,rotated,VECTOR3,"axis",REAL,"phi",varray());
+ ADDFUNC1(BASIS,BASIS,Basis,scaled,VECTOR3,"scale",varray());
+ ADDFUNC0(BASIS,VECTOR3,Basis,get_scale,varray());
+ ADDFUNC0(BASIS,VECTOR3,Basis,get_euler,varray());
+ ADDFUNC1(BASIS,REAL,Basis,tdotx,VECTOR3,"with",varray());
+ ADDFUNC1(BASIS,REAL,Basis,tdoty,VECTOR3,"with",varray());
+ ADDFUNC1(BASIS,REAL,Basis,tdotz,VECTOR3,"with",varray());
+ ADDFUNC1(BASIS,VECTOR3,Basis,xform,VECTOR3,"v",varray());
+ ADDFUNC1(BASIS,VECTOR3,Basis,xform_inv,VECTOR3,"v",varray());
+ ADDFUNC0(BASIS,INT,Basis,get_orthogonal_index,varray());
ADDFUNC0(TRANSFORM,TRANSFORM,Transform,inverse,varray());
ADDFUNC0(TRANSFORM,TRANSFORM,Transform,affine_inverse,varray());
@@ -1743,8 +1749,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
_VariantCall::add_constructor(_VariantCall::Rect2_init1,Variant::RECT2,"pos",Variant::VECTOR2,"size",Variant::VECTOR2);
_VariantCall::add_constructor(_VariantCall::Rect2_init2,Variant::RECT2,"x",Variant::REAL,"y",Variant::REAL,"width",Variant::REAL,"height",Variant::REAL);
- _VariantCall::add_constructor(_VariantCall::Matrix32_init2,Variant::MATRIX32,"rot",Variant::REAL,"pos",Variant::VECTOR2);
- _VariantCall::add_constructor(_VariantCall::Matrix32_init3,Variant::MATRIX32,"x_axis",Variant::VECTOR2,"y_axis",Variant::VECTOR2,"origin",Variant::VECTOR2);
+ _VariantCall::add_constructor(_VariantCall::Transform2D_init2,Variant::TRANSFORM2D,"rot",Variant::REAL,"pos",Variant::VECTOR2);
+ _VariantCall::add_constructor(_VariantCall::Transform2D_init3,Variant::TRANSFORM2D,"x_axis",Variant::VECTOR2,"y_axis",Variant::VECTOR2,"origin",Variant::VECTOR2);
_VariantCall::add_constructor(_VariantCall::Vector3_init1,Variant::VECTOR3,"x",Variant::REAL,"y",Variant::REAL,"z",Variant::REAL);
@@ -1758,13 +1764,13 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
_VariantCall::add_constructor(_VariantCall::Color_init1,Variant::COLOR,"r",Variant::REAL,"g",Variant::REAL,"b",Variant::REAL,"a",Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Color_init2,Variant::COLOR,"r",Variant::REAL,"g",Variant::REAL,"b",Variant::REAL);
- _VariantCall::add_constructor(_VariantCall::AABB_init1,Variant::_AABB,"pos",Variant::VECTOR3,"size",Variant::VECTOR3);
+ _VariantCall::add_constructor(_VariantCall::Rect3_init1,Variant::RECT3,"pos",Variant::VECTOR3,"size",Variant::VECTOR3);
- _VariantCall::add_constructor(_VariantCall::Matrix3_init1,Variant::MATRIX3,"x_axis",Variant::VECTOR3,"y_axis",Variant::VECTOR3,"z_axis",Variant::VECTOR3);
- _VariantCall::add_constructor(_VariantCall::Matrix3_init2,Variant::MATRIX3,"axis",Variant::VECTOR3,"phi",Variant::REAL);
+ _VariantCall::add_constructor(_VariantCall::Basis_init1,Variant::BASIS,"x_axis",Variant::VECTOR3,"y_axis",Variant::VECTOR3,"z_axis",Variant::VECTOR3);
+ _VariantCall::add_constructor(_VariantCall::Basis_init2,Variant::BASIS,"axis",Variant::VECTOR3,"phi",Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Transform_init1,Variant::TRANSFORM,"x_axis",Variant::VECTOR3,"y_axis",Variant::VECTOR3,"z_axis",Variant::VECTOR3,"origin",Variant::VECTOR3);
- _VariantCall::add_constructor(_VariantCall::Transform_init2,Variant::TRANSFORM,"basis",Variant::MATRIX3,"origin",Variant::VECTOR3);
+ _VariantCall::add_constructor(_VariantCall::Transform_init2,Variant::TRANSFORM,"basis",Variant::BASIS,"origin",Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Image_init1,Variant::IMAGE,"width",Variant::INT,"height",Variant::INT,"mipmaps",Variant::BOOL,"format",Variant::INT);
@@ -1779,45 +1785,65 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
_VariantCall::add_constant(Variant::INPUT_EVENT,"KEY",InputEvent::KEY);
_VariantCall::add_constant(Variant::INPUT_EVENT,"MOUSE_MOTION",InputEvent::MOUSE_MOTION);
_VariantCall::add_constant(Variant::INPUT_EVENT,"MOUSE_BUTTON",InputEvent::MOUSE_BUTTON);
- _VariantCall::add_constant(Variant::INPUT_EVENT,"JOYSTICK_MOTION",InputEvent::JOYSTICK_MOTION);
- _VariantCall::add_constant(Variant::INPUT_EVENT,"JOYSTICK_BUTTON",InputEvent::JOYSTICK_BUTTON);
+ _VariantCall::add_constant(Variant::INPUT_EVENT,"JOYPAD_MOTION",InputEvent::JOYPAD_MOTION);
+ _VariantCall::add_constant(Variant::INPUT_EVENT,"JOYPAD_BUTTON",InputEvent::JOYPAD_BUTTON);
_VariantCall::add_constant(Variant::INPUT_EVENT,"SCREEN_TOUCH",InputEvent::SCREEN_TOUCH);
_VariantCall::add_constant(Variant::INPUT_EVENT,"SCREEN_DRAG",InputEvent::SCREEN_DRAG);
_VariantCall::add_constant(Variant::INPUT_EVENT,"ACTION",InputEvent::ACTION);
- _VariantCall::add_constant(Variant::IMAGE,"COMPRESS_BC",Image::COMPRESS_BC);
+ _VariantCall::add_constant(Variant::IMAGE,"COMPRESS_16BIT",Image::COMPRESS_16BIT);
+ _VariantCall::add_constant(Variant::IMAGE,"COMPRESS_S3TC",Image::COMPRESS_S3TC);
_VariantCall::add_constant(Variant::IMAGE,"COMPRESS_PVRTC2",Image::COMPRESS_PVRTC2);
_VariantCall::add_constant(Variant::IMAGE,"COMPRESS_PVRTC4",Image::COMPRESS_PVRTC4);
_VariantCall::add_constant(Variant::IMAGE,"COMPRESS_ETC",Image::COMPRESS_ETC);
-
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_GRAYSCALE",Image::FORMAT_GRAYSCALE);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_INTENSITY",Image::FORMAT_INTENSITY);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_GRAYSCALE_ALPHA",Image::FORMAT_GRAYSCALE_ALPHA);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGB",Image::FORMAT_RGB);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBA",Image::FORMAT_RGBA);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_INDEXED",Image::FORMAT_INDEXED);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_INDEXED_ALPHA",Image::FORMAT_INDEXED_ALPHA);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_YUV_422",Image::FORMAT_YUV_422);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_YUV_444",Image::FORMAT_YUV_444);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC1",Image::FORMAT_BC1);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC2",Image::FORMAT_BC2);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC3",Image::FORMAT_BC3);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC4",Image::FORMAT_BC4);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BC5",Image::FORMAT_BC5);
+ _VariantCall::add_constant(Variant::IMAGE,"COMPRESS_ETC2",Image::COMPRESS_ETC2);
+
+
+
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_L8",Image::FORMAT_L8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_LA8",Image::FORMAT_LA8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_R8",Image::FORMAT_R8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RG8",Image::FORMAT_RG8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGB8",Image::FORMAT_RGB8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBA8",Image::FORMAT_RGBA8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGB565",Image::FORMAT_RGB565);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBA4444",Image::FORMAT_RGBA4444);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBA5551",Image::FORMAT_DXT1);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RF",Image::FORMAT_RF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGF",Image::FORMAT_RGF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBF",Image::FORMAT_RGBF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBAF",Image::FORMAT_RGBAF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RH",Image::FORMAT_RH);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGH",Image::FORMAT_RGH);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBH",Image::FORMAT_RGBH);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_RGBAH",Image::FORMAT_RGBAH);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_DXT1",Image::FORMAT_DXT1);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_DXT3",Image::FORMAT_DXT3);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_DXT5",Image::FORMAT_DXT5);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATI1",Image::FORMAT_ATI1);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATI2",Image::FORMAT_ATI2);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BPTC_RGBA",Image::FORMAT_BPTC_RGBA);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BPTC_RGBF",Image::FORMAT_BPTC_RGBF);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_BPTC_RGBFU",Image::FORMAT_BPTC_RGBFU);
_VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC2",Image::FORMAT_PVRTC2);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC2_ALPHA",Image::FORMAT_PVRTC2_ALPHA);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC2A",Image::FORMAT_PVRTC2A);
_VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC4",Image::FORMAT_PVRTC4);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC4_ALPHA",Image::FORMAT_PVRTC4_ALPHA);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_PVRTC4A",Image::FORMAT_PVRTC4A);
_VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC",Image::FORMAT_ETC);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATC",Image::FORMAT_ATC);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATC_ALPHA_EXPLICIT",Image::FORMAT_ATC_ALPHA_EXPLICIT);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ATC_ALPHA_INTERPOLATED",Image::FORMAT_ATC_ALPHA_INTERPOLATED);
- _VariantCall::add_constant(Variant::IMAGE,"FORMAT_CUSTOM",Image::FORMAT_CUSTOM);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_R11",Image::FORMAT_ETC2_R11);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_R11S",Image::FORMAT_ETC2_R11S);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RG11",Image::FORMAT_ETC2_RG11);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RG11S",Image::FORMAT_ETC2_RG11S);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RGB8",Image::FORMAT_ETC2_RGB8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RGBA8",Image::FORMAT_ETC2_RGBA8);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_ETC2_RGB8A1",Image::FORMAT_ETC2_RGB8A1);
+ _VariantCall::add_constant(Variant::IMAGE,"FORMAT_MAX",Image::FORMAT_MAX);
_VariantCall::add_constant(Variant::IMAGE,"INTERPOLATE_NEAREST",Image::INTERPOLATE_NEAREST);
_VariantCall::add_constant(Variant::IMAGE,"INTERPOLATE_BILINEAR",Image::INTERPOLATE_BILINEAR);
_VariantCall::add_constant(Variant::IMAGE,"INTERPOLATE_CUBIC",Image::INTERPOLATE_CUBIC);
+
}
void unregister_variant_methods() {
diff --git a/core/variant_construct_string.cpp b/core/variant_construct_string.cpp
index 6395501603..8db756aa79 100644
--- a/core/variant_construct_string.cpp
+++ b/core/variant_construct_string.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index fd64b58bd5..50f0b96715 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -47,12 +47,12 @@ bool Variant::booleanize(bool &r_valid) const {
case STRING: return (*reinterpret_cast<const String*>(_data._mem))!="";
case VECTOR2:
case RECT2:
- case MATRIX32:
+ case TRANSFORM2D:
case VECTOR3:
case PLANE:
- case _AABB:
+ case RECT3:
case QUAT:
- case MATRIX3:
+ case BASIS:
case TRANSFORM:
case COLOR:
case IMAGE: r_valid=false; return false;
@@ -62,13 +62,13 @@ bool Variant::booleanize(bool &r_valid) const {
case INPUT_EVENT:
case DICTIONARY:
case ARRAY:
- case RAW_ARRAY:
- case INT_ARRAY:
- case REAL_ARRAY:
- case STRING_ARRAY:
- case VECTOR2_ARRAY:
- case VECTOR3_ARRAY:
- case COLOR_ARRAY:
+ case POOL_BYTE_ARRAY:
+ case POOL_INT_ARRAY:
+ case POOL_REAL_ARRAY:
+ case POOL_STRING_ARRAY:
+ case POOL_VECTOR2_ARRAY:
+ case POOL_VECTOR3_ARRAY:
+ case POOL_COLOR_ARRAY:
r_valid=false;
return false;
default: {}
@@ -97,6 +97,12 @@ case m_name: {\
_RETURN( -p_a._data.m_type);\
};
+#define DEFAULT_OP_NUM_POS(m_name,m_type)\
+case m_name: {\
+\
+ _RETURN( p_a._data.m_type);\
+};
+
#define DEFAULT_OP_NUM_VEC(m_op,m_name,m_type)\
case m_name: {\
switch(p_b.type) {\
@@ -136,6 +142,10 @@ case m_name: {\
_RETURN( -*reinterpret_cast<const m_type*>(p_a._data._mem));\
}
+#define DEFAULT_OP_LOCALMEM_POS(m_name,m_type)\
+case m_name: {\
+ _RETURN( *reinterpret_cast<const m_type*>(p_a._data._mem));\
+}
#define DEFAULT_OP_LOCALMEM_NUM(m_op,m_name,m_type)\
case m_name: {switch(p_b.type) {\
@@ -176,16 +186,16 @@ case m_name: { \
r_valid=false;\
return;\
}\
- const DVector<m_type> &array_a=*reinterpret_cast<const DVector<m_type> *>(p_a._data._mem);\
- const DVector<m_type> &array_b=*reinterpret_cast<const DVector<m_type> *>(p_b._data._mem);\
+ const PoolVector<m_type> &array_a=*reinterpret_cast<const PoolVector<m_type> *>(p_a._data._mem);\
+ const PoolVector<m_type> &array_b=*reinterpret_cast<const PoolVector<m_type> *>(p_b._data._mem);\
\
int a_len = array_a.size();\
if (a_len m_opa array_b.size()){\
_RETURN( m_ret_s);\
}else {\
\
- DVector<m_type>::Read ra = array_a.read();\
- DVector<m_type>::Read rb = array_b.read();\
+ PoolVector<m_type>::Read ra = array_a.read();\
+ PoolVector<m_type>::Read rb = array_b.read();\
\
for(int i=0;i<a_len;i++) {\
if (ra[i] m_opb rb[i])\
@@ -202,9 +212,9 @@ case m_name: { \
r_valid=false;\
_RETURN( NIL);\
}\
- const DVector<m_type> &array_a=*reinterpret_cast<const DVector<m_type> *>(p_a._data._mem);\
- const DVector<m_type> &array_b=*reinterpret_cast<const DVector<m_type> *>(p_b._data._mem);\
- DVector<m_type> sum = array_a;\
+ const PoolVector<m_type> &array_a=*reinterpret_cast<const PoolVector<m_type> *>(p_a._data._mem);\
+ const PoolVector<m_type> &array_b=*reinterpret_cast<const PoolVector<m_type> *>(p_b._data._mem);\
+ PoolVector<m_type> sum = array_a;\
sum.append_array(array_b);\
_RETURN( sum );\
}
@@ -252,12 +262,12 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_STR(==,STRING,String);
DEFAULT_OP_LOCALMEM(==,VECTOR2,Vector2);
DEFAULT_OP_LOCALMEM(==,RECT2,Rect2);
- DEFAULT_OP_PTRREF(==,MATRIX32,_matrix32);
+ DEFAULT_OP_PTRREF(==,TRANSFORM2D,_transform2d);
DEFAULT_OP_LOCALMEM(==,VECTOR3,Vector3);
DEFAULT_OP_LOCALMEM(==,PLANE,Plane);
DEFAULT_OP_LOCALMEM(==,QUAT,Quat);
- DEFAULT_OP_PTRREF(==,_AABB,_aabb);
- DEFAULT_OP_PTRREF(==,MATRIX3,_matrix3);
+ DEFAULT_OP_PTRREF(==,RECT3,_rect3);
+ DEFAULT_OP_PTRREF(==,BASIS,_basis);
DEFAULT_OP_PTRREF(==,TRANSFORM,_transform);
DEFAULT_OP_LOCALMEM(==,COLOR,Color);
@@ -306,13 +316,13 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
} break;
- DEFAULT_OP_ARRAY_EQ(RAW_ARRAY,uint8_t);
- DEFAULT_OP_ARRAY_EQ(INT_ARRAY,int);
- DEFAULT_OP_ARRAY_EQ(REAL_ARRAY,real_t);
- DEFAULT_OP_ARRAY_EQ(STRING_ARRAY,String);
- DEFAULT_OP_ARRAY_EQ(VECTOR2_ARRAY,Vector3);
- DEFAULT_OP_ARRAY_EQ(VECTOR3_ARRAY,Vector3);
- DEFAULT_OP_ARRAY_EQ(COLOR_ARRAY,Color);
+ DEFAULT_OP_ARRAY_EQ(POOL_BYTE_ARRAY,uint8_t);
+ DEFAULT_OP_ARRAY_EQ(POOL_INT_ARRAY,int);
+ DEFAULT_OP_ARRAY_EQ(POOL_REAL_ARRAY,real_t);
+ DEFAULT_OP_ARRAY_EQ(POOL_STRING_ARRAY,String);
+ DEFAULT_OP_ARRAY_EQ(POOL_VECTOR2_ARRAY,Vector3);
+ DEFAULT_OP_ARRAY_EQ(POOL_VECTOR3_ARRAY,Vector3);
+ DEFAULT_OP_ARRAY_EQ(POOL_COLOR_ARRAY,Color);
case VARIANT_MAX: {
r_valid=false;
@@ -344,12 +354,12 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_STR(<,STRING,String);
DEFAULT_OP_LOCALMEM(<,VECTOR2,Vector2);
DEFAULT_OP_FAIL(RECT2);
- DEFAULT_OP_FAIL(MATRIX32);
+ DEFAULT_OP_FAIL(TRANSFORM2D);
DEFAULT_OP_LOCALMEM(<,VECTOR3,Vector3);
DEFAULT_OP_FAIL(PLANE);
DEFAULT_OP_FAIL(QUAT);
- DEFAULT_OP_FAIL(_AABB);
- DEFAULT_OP_FAIL(MATRIX3);
+ DEFAULT_OP_FAIL(RECT3);
+ DEFAULT_OP_FAIL(BASIS);
DEFAULT_OP_FAIL(TRANSFORM);
DEFAULT_OP_FAIL(COLOR);
@@ -383,13 +393,13 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
_RETURN( false );
} break;
- DEFAULT_OP_ARRAY_LT(RAW_ARRAY,uint8_t);
- DEFAULT_OP_ARRAY_LT(INT_ARRAY,int);
- DEFAULT_OP_ARRAY_LT(REAL_ARRAY,real_t);
- DEFAULT_OP_ARRAY_LT(STRING_ARRAY,String);
- DEFAULT_OP_ARRAY_LT(VECTOR2_ARRAY,Vector3);
- DEFAULT_OP_ARRAY_LT(VECTOR3_ARRAY,Vector3);
- DEFAULT_OP_ARRAY_LT(COLOR_ARRAY,Color);
+ DEFAULT_OP_ARRAY_LT(POOL_BYTE_ARRAY,uint8_t);
+ DEFAULT_OP_ARRAY_LT(POOL_INT_ARRAY,int);
+ DEFAULT_OP_ARRAY_LT(POOL_REAL_ARRAY,real_t);
+ DEFAULT_OP_ARRAY_LT(POOL_STRING_ARRAY,String);
+ DEFAULT_OP_ARRAY_LT(POOL_VECTOR2_ARRAY,Vector3);
+ DEFAULT_OP_ARRAY_LT(POOL_VECTOR3_ARRAY,Vector3);
+ DEFAULT_OP_ARRAY_LT(POOL_COLOR_ARRAY,Color);
case VARIANT_MAX: {
r_valid=false;
return;
@@ -410,12 +420,12 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_STR(<=,STRING,String);
DEFAULT_OP_LOCALMEM(<=,VECTOR2,Vector2);
DEFAULT_OP_FAIL(RECT2);
- DEFAULT_OP_FAIL(MATRIX32);
+ DEFAULT_OP_FAIL(TRANSFORM2D);
DEFAULT_OP_LOCALMEM(<=,VECTOR3,Vector3);
DEFAULT_OP_FAIL(PLANE);
DEFAULT_OP_FAIL(QUAT);
- DEFAULT_OP_FAIL(_AABB);
- DEFAULT_OP_FAIL(MATRIX3);
+ DEFAULT_OP_FAIL(RECT3);
+ DEFAULT_OP_FAIL(BASIS);
DEFAULT_OP_FAIL(TRANSFORM);
DEFAULT_OP_FAIL(COLOR);
@@ -430,13 +440,13 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
- DEFAULT_OP_FAIL(RAW_ARRAY);
- DEFAULT_OP_FAIL(INT_ARRAY);
- DEFAULT_OP_FAIL(REAL_ARRAY);
- DEFAULT_OP_FAIL(STRING_ARRAY);
- DEFAULT_OP_FAIL(VECTOR2_ARRAY);
- DEFAULT_OP_FAIL(VECTOR3_ARRAY);
- DEFAULT_OP_FAIL(COLOR_ARRAY);
+ DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
+ DEFAULT_OP_FAIL(POOL_INT_ARRAY);
+ DEFAULT_OP_FAIL(POOL_REAL_ARRAY);
+ DEFAULT_OP_FAIL(POOL_STRING_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR2_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR3_ARRAY);
+ DEFAULT_OP_FAIL(POOL_COLOR_ARRAY);
case VARIANT_MAX: {
r_valid=false;
return;
@@ -474,12 +484,12 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_STR(+,STRING,String);
DEFAULT_OP_LOCALMEM(+,VECTOR2,Vector2);
DEFAULT_OP_FAIL(RECT2);
- DEFAULT_OP_FAIL(MATRIX32);
+ DEFAULT_OP_FAIL(TRANSFORM2D);
DEFAULT_OP_LOCALMEM(+,VECTOR3,Vector3);
DEFAULT_OP_FAIL(PLANE);
DEFAULT_OP_LOCALMEM(+, QUAT, Quat);
- DEFAULT_OP_FAIL(_AABB);
- DEFAULT_OP_FAIL(MATRIX3);
+ DEFAULT_OP_FAIL(RECT3);
+ DEFAULT_OP_FAIL(BASIS);
DEFAULT_OP_FAIL(TRANSFORM);
DEFAULT_OP_FAIL(COLOR);
@@ -497,7 +507,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
}
const Array &array_a=*reinterpret_cast<const Array *>(p_a._data._mem);
const Array &array_b=*reinterpret_cast<const Array *>(p_b._data._mem);
- Array sum(array_a.is_shared() || array_b.is_shared());
+ Array sum;
int asize=array_a.size();
int bsize=array_b.size();
sum.resize(asize+bsize);
@@ -507,13 +517,13 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
sum[i+asize]=array_b[i];
_RETURN( sum );
}
- DEFAULT_OP_ARRAY_ADD(RAW_ARRAY,uint8_t);
- DEFAULT_OP_ARRAY_ADD(INT_ARRAY,int);
- DEFAULT_OP_ARRAY_ADD(REAL_ARRAY,real_t);
- DEFAULT_OP_ARRAY_ADD(STRING_ARRAY,String);
- DEFAULT_OP_ARRAY_ADD(VECTOR2_ARRAY,Vector2);
- DEFAULT_OP_ARRAY_ADD(VECTOR3_ARRAY,Vector3);
- DEFAULT_OP_ARRAY_ADD(COLOR_ARRAY,Color);
+ DEFAULT_OP_ARRAY_ADD(POOL_BYTE_ARRAY,uint8_t);
+ DEFAULT_OP_ARRAY_ADD(POOL_INT_ARRAY,int);
+ DEFAULT_OP_ARRAY_ADD(POOL_REAL_ARRAY,real_t);
+ DEFAULT_OP_ARRAY_ADD(POOL_STRING_ARRAY,String);
+ DEFAULT_OP_ARRAY_ADD(POOL_VECTOR2_ARRAY,Vector2);
+ DEFAULT_OP_ARRAY_ADD(POOL_VECTOR3_ARRAY,Vector3);
+ DEFAULT_OP_ARRAY_ADD(POOL_COLOR_ARRAY,Color);
case VARIANT_MAX: {
r_valid=false;
return;
@@ -532,12 +542,12 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_FAIL(STRING);
DEFAULT_OP_LOCALMEM(-,VECTOR2,Vector2);
DEFAULT_OP_FAIL(RECT2);
- DEFAULT_OP_FAIL(MATRIX32);
+ DEFAULT_OP_FAIL(TRANSFORM2D);
DEFAULT_OP_LOCALMEM(-,VECTOR3,Vector3);
DEFAULT_OP_FAIL(PLANE);
DEFAULT_OP_LOCALMEM(-, QUAT, Quat);
- DEFAULT_OP_FAIL(_AABB);
- DEFAULT_OP_FAIL(MATRIX3);
+ DEFAULT_OP_FAIL(RECT3);
+ DEFAULT_OP_FAIL(BASIS);
DEFAULT_OP_FAIL(TRANSFORM);
DEFAULT_OP_FAIL(COLOR);
@@ -548,13 +558,13 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
- DEFAULT_OP_FAIL(RAW_ARRAY);
- DEFAULT_OP_FAIL(INT_ARRAY);
- DEFAULT_OP_FAIL(REAL_ARRAY);
- DEFAULT_OP_FAIL(STRING_ARRAY);
- DEFAULT_OP_FAIL(VECTOR2_ARRAY);
- DEFAULT_OP_FAIL(VECTOR3_ARRAY);
- DEFAULT_OP_FAIL(COLOR_ARRAY);
+ DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
+ DEFAULT_OP_FAIL(POOL_INT_ARRAY);
+ DEFAULT_OP_FAIL(POOL_REAL_ARRAY);
+ DEFAULT_OP_FAIL(POOL_STRING_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR2_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR3_ARRAY);
+ DEFAULT_OP_FAIL(POOL_COLOR_ARRAY);
case VARIANT_MAX: {
r_valid=false;
return;
@@ -573,13 +583,13 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_FAIL(STRING);
DEFAULT_OP_LOCALMEM_NUM(*,VECTOR2,Vector2);
DEFAULT_OP_FAIL(RECT2);
- case MATRIX32: {
+ case TRANSFORM2D: {
- if (p_b.type==MATRIX32) {
- _RETURN( *p_a._data._matrix32 * *p_b._data._matrix32 );
+ if (p_b.type==TRANSFORM2D) {
+ _RETURN( *p_a._data._transform2d * *p_b._data._transform2d );
};
if (p_b.type==VECTOR2) {
- _RETURN( p_a._data._matrix32->xform( *(const Vector2*)p_b._data._mem) );
+ _RETURN( p_a._data._transform2d->xform( *(const Vector2*)p_b._data._mem) );
};
r_valid=false;
return;
@@ -605,18 +615,18 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
r_valid=false;
return;
} break;
- DEFAULT_OP_FAIL(_AABB);
- case MATRIX3: {
+ DEFAULT_OP_FAIL(RECT3);
+ case BASIS: {
switch(p_b.type) {
case VECTOR3: {
- _RETURN( p_a._data._matrix3->xform( *(const Vector3*)p_b._data._mem) );
+ _RETURN( p_a._data._basis->xform( *(const Vector3*)p_b._data._mem) );
} ;
- case MATRIX3: {
+ case BASIS: {
- _RETURN( *p_a._data._matrix3 * *p_b._data._matrix3 );
+ _RETURN( *p_a._data._basis * *p_b._data._basis );
};
default: {}
@@ -650,13 +660,13 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
- DEFAULT_OP_FAIL(RAW_ARRAY);
- DEFAULT_OP_FAIL(INT_ARRAY);
- DEFAULT_OP_FAIL(REAL_ARRAY);
- DEFAULT_OP_FAIL(STRING_ARRAY);
- DEFAULT_OP_FAIL(VECTOR2_ARRAY);
- DEFAULT_OP_FAIL(VECTOR3_ARRAY);
- DEFAULT_OP_FAIL(COLOR_ARRAY);
+ DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
+ DEFAULT_OP_FAIL(POOL_INT_ARRAY);
+ DEFAULT_OP_FAIL(POOL_REAL_ARRAY);
+ DEFAULT_OP_FAIL(POOL_STRING_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR2_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR3_ARRAY);
+ DEFAULT_OP_FAIL(POOL_COLOR_ARRAY);
case VARIANT_MAX: {
r_valid=false;
return;
@@ -673,7 +683,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
case INT: {
switch(p_b.type) {
case BOOL: {
- int b = p_b._data._bool;
+ int64_t b = p_b._data._bool;
if (b==0) {
r_valid=false;
@@ -683,7 +693,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
} break;
case INT: {
- int b = p_b._data._int;
+ int64_t b = p_b._data._int;
if (b==0) {
r_valid=false;
@@ -702,7 +712,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_FAIL(STRING);
DEFAULT_OP_LOCALMEM_NUM(/,VECTOR2,Vector2);
DEFAULT_OP_FAIL(RECT2);
- DEFAULT_OP_FAIL(MATRIX32);
+ DEFAULT_OP_FAIL(TRANSFORM2D);
DEFAULT_OP_LOCALMEM_NUM(/,VECTOR3,Vector3);
DEFAULT_OP_FAIL(PLANE);
case QUAT: {
@@ -712,8 +722,8 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
}
_RETURN( *reinterpret_cast<const Quat*>(p_a._data._mem) / p_b._data._real);
} break;
- DEFAULT_OP_FAIL(_AABB);
- DEFAULT_OP_FAIL(MATRIX3);
+ DEFAULT_OP_FAIL(RECT3);
+ DEFAULT_OP_FAIL(BASIS);
DEFAULT_OP_FAIL(TRANSFORM);
DEFAULT_OP_FAIL(COLOR);
@@ -724,13 +734,13 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
- DEFAULT_OP_FAIL(RAW_ARRAY);
- DEFAULT_OP_FAIL(INT_ARRAY);
- DEFAULT_OP_FAIL(REAL_ARRAY);
- DEFAULT_OP_FAIL(STRING_ARRAY);
- DEFAULT_OP_FAIL(VECTOR2_ARRAY);
- DEFAULT_OP_FAIL(VECTOR3_ARRAY);
- DEFAULT_OP_FAIL(COLOR_ARRAY);
+ DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
+ DEFAULT_OP_FAIL(POOL_INT_ARRAY);
+ DEFAULT_OP_FAIL(POOL_REAL_ARRAY);
+ DEFAULT_OP_FAIL(POOL_STRING_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR2_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR3_ARRAY);
+ DEFAULT_OP_FAIL(POOL_COLOR_ARRAY);
case VARIANT_MAX: {
r_valid=false;
return;
@@ -740,6 +750,48 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
}
} break;
+ case OP_POSITIVE: {
+ // Simple case when user defines variable as +value.
+ switch(p_a.type) {
+
+ DEFAULT_OP_FAIL(NIL);
+ DEFAULT_OP_FAIL(STRING);
+ DEFAULT_OP_FAIL(RECT2);
+ DEFAULT_OP_FAIL(TRANSFORM2D);
+ DEFAULT_OP_FAIL(RECT3);
+ DEFAULT_OP_FAIL(BASIS);
+ DEFAULT_OP_FAIL(TRANSFORM);
+ DEFAULT_OP_NUM_POS(BOOL,_bool);
+ DEFAULT_OP_NUM_POS(INT,_int);
+ DEFAULT_OP_NUM_POS(REAL,_real);
+ DEFAULT_OP_LOCALMEM_POS(VECTOR3,Vector3);
+ DEFAULT_OP_LOCALMEM_POS(PLANE,Plane);
+ DEFAULT_OP_LOCALMEM_POS(QUAT,Quat);
+ DEFAULT_OP_LOCALMEM_POS(VECTOR2,Vector2);
+
+ DEFAULT_OP_FAIL(COLOR);
+ DEFAULT_OP_FAIL(IMAGE);
+ DEFAULT_OP_FAIL(NODE_PATH);
+ DEFAULT_OP_FAIL(_RID);
+ DEFAULT_OP_FAIL(OBJECT);
+ DEFAULT_OP_FAIL(INPUT_EVENT);
+ DEFAULT_OP_FAIL(DICTIONARY);
+ DEFAULT_OP_FAIL(ARRAY);
+ DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
+ DEFAULT_OP_FAIL(POOL_INT_ARRAY);
+ DEFAULT_OP_FAIL(POOL_REAL_ARRAY);
+ DEFAULT_OP_FAIL(POOL_STRING_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR2_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR3_ARRAY);
+ DEFAULT_OP_FAIL(POOL_COLOR_ARRAY);
+ case VARIANT_MAX: {
+ r_valid=false;
+ return;
+
+ } break;
+
+ }
+ } break;
case OP_NEGATE: {
switch(p_a.type) {
@@ -750,12 +802,12 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_FAIL(STRING);
DEFAULT_OP_LOCALMEM_NEG(VECTOR2,Vector2);
DEFAULT_OP_FAIL(RECT2);
- DEFAULT_OP_FAIL(MATRIX32);
+ DEFAULT_OP_FAIL(TRANSFORM2D);
DEFAULT_OP_LOCALMEM_NEG(VECTOR3,Vector3);
DEFAULT_OP_LOCALMEM_NEG(PLANE,Plane);
DEFAULT_OP_LOCALMEM_NEG(QUAT,Quat);
- DEFAULT_OP_FAIL(_AABB);
- DEFAULT_OP_FAIL(MATRIX3);
+ DEFAULT_OP_FAIL(RECT3);
+ DEFAULT_OP_FAIL(BASIS);
DEFAULT_OP_FAIL(TRANSFORM);
DEFAULT_OP_FAIL(COLOR);
@@ -766,21 +818,19 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant&
DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
- DEFAULT_OP_FAIL(RAW_ARRAY);
- DEFAULT_OP_FAIL(INT_ARRAY);
- DEFAULT_OP_FAIL(REAL_ARRAY);
- DEFAULT_OP_FAIL(STRING_ARRAY);
- DEFAULT_OP_FAIL(VECTOR2_ARRAY);
- DEFAULT_OP_FAIL(VECTOR3_ARRAY);
- DEFAULT_OP_FAIL(COLOR_ARRAY);
+ DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
+ DEFAULT_OP_FAIL(POOL_INT_ARRAY);
+ DEFAULT_OP_FAIL(POOL_REAL_ARRAY);
+ DEFAULT_OP_FAIL(POOL_STRING_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR2_ARRAY);
+ DEFAULT_OP_FAIL(POOL_VECTOR3_ARRAY);
+ DEFAULT_OP_FAIL(POOL_COLOR_ARRAY);
case VARIANT_MAX: {
r_valid=false;
return;
} break;
-
}
-
} break;
case OP_MODULE: {
if (p_a.type==INT && p_b.type==INT) {
@@ -999,10 +1049,10 @@ Variant Variant::get_named(const StringName& p_index, bool *r_valid) const {
} break;
#define DEFAULT_OP_DVECTOR_SET(m_name, dv_type, skip_cond)\
- DEFAULT_OP_ARRAY_CMD(m_name, DVector<dv_type>, if(skip_cond) return;, arr->set(index, p_value);return)
+ DEFAULT_OP_ARRAY_CMD(m_name, PoolVector<dv_type>, if(skip_cond) return;, arr->set(index, p_value);return)
#define DEFAULT_OP_DVECTOR_GET(m_name, dv_type)\
- DEFAULT_OP_ARRAY_CMD(m_name, const DVector<dv_type>, ;, return arr->get(index))
+ DEFAULT_OP_ARRAY_CMD(m_name, const PoolVector<dv_type>, ;, return arr->get(index))
void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid) {
@@ -1107,7 +1157,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
}
}
} break;
- case MATRIX32: {
+ case TRANSFORM2D: {
if (p_value.type!=Variant::VECTOR2)
return;
@@ -1119,7 +1169,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
if (index<0)
index += 3;
if (index>=0 && index<3) {
- Matrix32 *v=_data._matrix32;
+ Transform2D *v=_data._transform2d;
valid=true;
v->elements[index]=p_value;
@@ -1129,7 +1179,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
//scalar name
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
- Matrix32 *v=_data._matrix32;
+ Transform2D *v=_data._transform2d;
if (*str=="x") {
valid=true;
v->elements[0]=p_value;
@@ -1255,7 +1305,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
}
} break;
- case _AABB: {
+ case RECT3: {
if (p_value.type!=Variant::VECTOR3)
return;
@@ -1265,7 +1315,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
//scalar name
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
- AABB *v=_data._aabb;
+ Rect3 *v=_data._rect3;
if (*str=="pos") {
valid=true;
v->pos=p_value;
@@ -1281,7 +1331,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
}
}
} break; //sorry naming convention fail :( not like it's used often // 10
- case MATRIX3: {
+ case BASIS: {
if (p_value.type!=Variant::VECTOR3)
return;
@@ -1293,7 +1343,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
if (index<0)
index += 3;
if (index>=0 && index<3) {
- Matrix3 *v=_data._matrix3;
+ Basis *v=_data._basis;
valid=true;
v->set_axis(index,p_value);
@@ -1302,7 +1352,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
} else if (p_index.get_type()==Variant::STRING) {
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
- Matrix3 *v=_data._matrix3;
+ Basis *v=_data._basis;
if (*str=="x") {
valid=true;
@@ -1348,7 +1398,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
if (*str=="basis") {
- if (p_value.type!=Variant::MATRIX3)
+ if (p_value.type!=Variant::BASIS)
return;
valid=true;
v->basis=p_value;
@@ -1694,7 +1744,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
}
- if (ie.type==InputEvent::JOYSTICK_BUTTON) {
+ if (ie.type==InputEvent::JOYPAD_BUTTON) {
if (str=="button_index") {
if (p_value.type!=Variant::REAL && p_value.type!=Variant::INT)
@@ -1719,7 +1769,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
}
- if (ie.type==InputEvent::JOYSTICK_MOTION) {
+ if (ie.type==InputEvent::JOYPAD_MOTION) {
if (str=="axis") {
if (p_value.type!=Variant::REAL && p_value.type!=Variant::INT)
@@ -1837,13 +1887,13 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
return;
} break; // 20
DEFAULT_OP_ARRAY_CMD(ARRAY, Array, ;, (*arr)[index]=p_value;return)
- DEFAULT_OP_DVECTOR_SET(RAW_ARRAY, uint8_t, p_value.type != Variant::REAL && p_value.type != Variant::INT)
- DEFAULT_OP_DVECTOR_SET(INT_ARRAY, int, p_value.type != Variant::REAL && p_value.type != Variant::INT)
- DEFAULT_OP_DVECTOR_SET(REAL_ARRAY, real_t, p_value.type != Variant::REAL && p_value.type != Variant::INT)
- DEFAULT_OP_DVECTOR_SET(STRING_ARRAY, String, p_value.type != Variant::STRING) // 25
- DEFAULT_OP_DVECTOR_SET(VECTOR2_ARRAY, Vector2, p_value.type != Variant::VECTOR2)
- DEFAULT_OP_DVECTOR_SET(VECTOR3_ARRAY, Vector3, p_value.type != Variant::VECTOR3)
- DEFAULT_OP_DVECTOR_SET(COLOR_ARRAY, Color, p_value.type != Variant::COLOR)
+ DEFAULT_OP_DVECTOR_SET(POOL_BYTE_ARRAY, uint8_t, p_value.type != Variant::REAL && p_value.type != Variant::INT)
+ DEFAULT_OP_DVECTOR_SET(POOL_INT_ARRAY, int, p_value.type != Variant::REAL && p_value.type != Variant::INT)
+ DEFAULT_OP_DVECTOR_SET(POOL_REAL_ARRAY, real_t, p_value.type != Variant::REAL && p_value.type != Variant::INT)
+ DEFAULT_OP_DVECTOR_SET(POOL_STRING_ARRAY, String, p_value.type != Variant::STRING) // 25
+ DEFAULT_OP_DVECTOR_SET(POOL_VECTOR2_ARRAY, Vector2, p_value.type != Variant::VECTOR2)
+ DEFAULT_OP_DVECTOR_SET(POOL_VECTOR3_ARRAY, Vector3, p_value.type != Variant::VECTOR3)
+ DEFAULT_OP_DVECTOR_SET(POOL_COLOR_ARRAY, Color, p_value.type != Variant::COLOR)
default: return;
}
@@ -1957,7 +2007,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
}
} break;
- case MATRIX32: {
+ case TRANSFORM2D: {
if (p_index.get_type()==Variant::INT || p_index.get_type()==Variant::REAL) {
@@ -1966,7 +2016,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
if (index<0)
index += 3;
if (index>=0 && index<3) {
- const Matrix32 *v=_data._matrix32;
+ const Transform2D *v=_data._transform2d;
valid=true;
return v->elements[index];
@@ -1975,7 +2025,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
//scalar name
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
- const Matrix32 *v=_data._matrix32;
+ const Transform2D *v=_data._transform2d;
if (*str=="x") {
valid=true;
return v->elements[0];
@@ -2036,13 +2086,13 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
}
} break;
- case _AABB: {
+ case RECT3: {
if (p_index.get_type()==Variant::STRING) {
//scalar name
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
- const AABB *v=_data._aabb;
+ const Rect3 *v=_data._rect3;
if (*str=="pos") {
valid=true;
return v->pos;
@@ -2055,7 +2105,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
}
}
} break; //sorry naming convention fail :( not like it's used often // 10
- case MATRIX3: {
+ case BASIS: {
if (p_index.get_type()==Variant::INT || p_index.get_type()==Variant::REAL) {
@@ -2063,7 +2113,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
if (index<0)
index += 3;
if (index>=0 && index<3) {
- const Matrix3 *v=_data._matrix3;
+ const Basis *v=_data._basis;
valid=true;
return v->get_axis(index);
@@ -2071,7 +2121,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
} else if (p_index.get_type()==Variant::STRING) {
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
- const Matrix3 *v=_data._matrix3;
+ const Basis *v=_data._basis;
if (*str=="x") {
valid=true;
@@ -2317,7 +2367,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
}
- if (ie.type==InputEvent::JOYSTICK_BUTTON) {
+ if (ie.type==InputEvent::JOYPAD_BUTTON) {
if (str=="button_index") {
valid=true;
@@ -2332,7 +2382,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
}
- if (ie.type==InputEvent::JOYSTICK_MOTION) {
+ if (ie.type==InputEvent::JOYPAD_MOTION) {
if (str=="axis") {
valid=true;
@@ -2421,13 +2471,13 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
}
} break; // 20
DEFAULT_OP_ARRAY_CMD(ARRAY, const Array, ;, return (*arr)[index])
- DEFAULT_OP_DVECTOR_GET(RAW_ARRAY, uint8_t)
- DEFAULT_OP_DVECTOR_GET(INT_ARRAY, int)
- DEFAULT_OP_DVECTOR_GET(REAL_ARRAY, real_t)
- DEFAULT_OP_DVECTOR_GET(STRING_ARRAY, String)
- DEFAULT_OP_DVECTOR_GET(VECTOR2_ARRAY, Vector2)
- DEFAULT_OP_DVECTOR_GET(VECTOR3_ARRAY, Vector3)
- DEFAULT_OP_DVECTOR_GET(COLOR_ARRAY, Color)
+ DEFAULT_OP_DVECTOR_GET(POOL_BYTE_ARRAY, uint8_t)
+ DEFAULT_OP_DVECTOR_GET(POOL_INT_ARRAY, int)
+ DEFAULT_OP_DVECTOR_GET(POOL_REAL_ARRAY, real_t)
+ DEFAULT_OP_DVECTOR_GET(POOL_STRING_ARRAY, String)
+ DEFAULT_OP_DVECTOR_GET(POOL_VECTOR2_ARRAY, Vector2)
+ DEFAULT_OP_DVECTOR_GET(POOL_VECTOR3_ARRAY, Vector3)
+ DEFAULT_OP_DVECTOR_GET(POOL_COLOR_ARRAY, Color)
default: return Variant();
}
@@ -2507,14 +2557,14 @@ bool Variant::in(const Variant& p_index, bool *r_valid) const {
return false;
} break;
- case RAW_ARRAY: {
+ case POOL_BYTE_ARRAY: {
if (p_index.get_type()==Variant::INT || p_index.get_type()==Variant::REAL) {
int index = p_index;
- const DVector<uint8_t> *arr=reinterpret_cast<const DVector<uint8_t>* >(_data._mem);
+ const PoolVector<uint8_t> *arr=reinterpret_cast<const PoolVector<uint8_t>* >(_data._mem);
int l=arr->size();
if (l) {
- DVector<uint8_t>::Read r = arr->read();
+ PoolVector<uint8_t>::Read r = arr->read();
for(int i=0;i<l;i++) {
if (r[i]==index)
return true;
@@ -2526,14 +2576,14 @@ bool Variant::in(const Variant& p_index, bool *r_valid) const {
}
} break;
- case INT_ARRAY: {
+ case POOL_INT_ARRAY: {
if (p_index.get_type()==Variant::INT || p_index.get_type()==Variant::REAL) {
int index = p_index;
- const DVector<int> *arr=reinterpret_cast<const DVector<int>* >(_data._mem);
+ const PoolVector<int> *arr=reinterpret_cast<const PoolVector<int>* >(_data._mem);
int l=arr->size();
if (l) {
- DVector<int>::Read r = arr->read();
+ PoolVector<int>::Read r = arr->read();
for(int i=0;i<l;i++) {
if (r[i]==index)
return true;
@@ -2544,15 +2594,15 @@ bool Variant::in(const Variant& p_index, bool *r_valid) const {
return false;
}
} break;
- case REAL_ARRAY: {
+ case POOL_REAL_ARRAY: {
if (p_index.get_type()==Variant::INT || p_index.get_type()==Variant::REAL) {
real_t index = p_index;
- const DVector<real_t> *arr=reinterpret_cast<const DVector<real_t>* >(_data._mem);
+ const PoolVector<real_t> *arr=reinterpret_cast<const PoolVector<real_t>* >(_data._mem);
int l=arr->size();
if (l) {
- DVector<real_t>::Read r = arr->read();
+ PoolVector<real_t>::Read r = arr->read();
for(int i=0;i<l;i++) {
if (r[i]==index)
return true;
@@ -2564,15 +2614,15 @@ bool Variant::in(const Variant& p_index, bool *r_valid) const {
}
} break;
- case STRING_ARRAY: {
+ case POOL_STRING_ARRAY: {
if (p_index.get_type()==Variant::STRING) {
String index = p_index;
- const DVector<String> *arr=reinterpret_cast<const DVector<String>* >(_data._mem);
+ const PoolVector<String> *arr=reinterpret_cast<const PoolVector<String>* >(_data._mem);
int l=arr->size();
if (l) {
- DVector<String>::Read r = arr->read();
+ PoolVector<String>::Read r = arr->read();
for(int i=0;i<l;i++) {
if (r[i]==index)
return true;
@@ -2584,15 +2634,15 @@ bool Variant::in(const Variant& p_index, bool *r_valid) const {
}
} break; //25
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
if (p_index.get_type()==Variant::VECTOR2) {
Vector2 index = p_index;
- const DVector<Vector2> *arr=reinterpret_cast<const DVector<Vector2>* >(_data._mem);
+ const PoolVector<Vector2> *arr=reinterpret_cast<const PoolVector<Vector2>* >(_data._mem);
int l=arr->size();
if (l) {
- DVector<Vector2>::Read r = arr->read();
+ PoolVector<Vector2>::Read r = arr->read();
for(int i=0;i<l;i++) {
if (r[i]==index)
return true;
@@ -2604,15 +2654,15 @@ bool Variant::in(const Variant& p_index, bool *r_valid) const {
}
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
if (p_index.get_type()==Variant::VECTOR3) {
Vector3 index = p_index;
- const DVector<Vector3> *arr=reinterpret_cast<const DVector<Vector3>* >(_data._mem);
+ const PoolVector<Vector3> *arr=reinterpret_cast<const PoolVector<Vector3>* >(_data._mem);
int l=arr->size();
if (l) {
- DVector<Vector3>::Read r = arr->read();
+ PoolVector<Vector3>::Read r = arr->read();
for(int i=0;i<l;i++) {
if (r[i]==index)
return true;
@@ -2624,17 +2674,17 @@ bool Variant::in(const Variant& p_index, bool *r_valid) const {
}
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
if (p_index.get_type()==Variant::COLOR) {
Color index = p_index;
- const DVector<Color> *arr=reinterpret_cast<const DVector<Color>* >(_data._mem);
+ const PoolVector<Color> *arr=reinterpret_cast<const PoolVector<Color>* >(_data._mem);
int l=arr->size();
if (l) {
- DVector<Color>::Read r = arr->read();
+ PoolVector<Color>::Read r = arr->read();
for(int i=0;i<l;i++) {
if (r[i]==index)
return true;
@@ -2679,7 +2729,7 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back( PropertyInfo(Variant::REAL,"z"));
} break;
- case MATRIX32: {
+ case TRANSFORM2D: {
p_list->push_back( PropertyInfo(Variant::VECTOR2,"x"));
p_list->push_back( PropertyInfo(Variant::VECTOR2,"y"));
@@ -2703,12 +2753,12 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back( PropertyInfo(Variant::REAL,"w"));
} break;
- case _AABB: {
+ case RECT3: {
p_list->push_back( PropertyInfo(Variant::VECTOR3,"pos"));
p_list->push_back( PropertyInfo(Variant::VECTOR3,"size"));
p_list->push_back( PropertyInfo(Variant::VECTOR3,"end"));
} break; //sorry naming convention fail :( not like it's used often // 10
- case MATRIX3: {
+ case BASIS: {
p_list->push_back( PropertyInfo(Variant::VECTOR3,"x"));
p_list->push_back( PropertyInfo(Variant::VECTOR3,"y"));
@@ -2717,7 +2767,7 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
} break;
case TRANSFORM: {
- p_list->push_back( PropertyInfo(Variant::MATRIX3,"basis"));
+ p_list->push_back( PropertyInfo(Variant::BASIS,"basis"));
p_list->push_back( PropertyInfo(Variant::VECTOR3,"origin"));
} break;
@@ -2786,18 +2836,18 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
if (ie.type==InputEvent::MOUSE_MOTION || ie.type==InputEvent::MOUSE_BUTTON) {
p_list->push_back( PropertyInfo(Variant::INT,"button_mask") );
- p_list->push_back( PropertyInfo(Variant::INT,"x") );
- p_list->push_back( PropertyInfo(Variant::INT,"y") );
+ p_list->push_back( PropertyInfo(Variant::REAL,"x") );
+ p_list->push_back( PropertyInfo(Variant::REAL,"y") );
p_list->push_back( PropertyInfo(Variant::VECTOR2,"pos") );
- p_list->push_back( PropertyInfo(Variant::INT,"global_x") );
- p_list->push_back( PropertyInfo(Variant::INT,"global_y") );
+ p_list->push_back( PropertyInfo(Variant::REAL,"global_x") );
+ p_list->push_back( PropertyInfo(Variant::REAL,"global_y") );
p_list->push_back( PropertyInfo(Variant::VECTOR2,"global_pos") );
if (ie.type==InputEvent::MOUSE_MOTION) {
- p_list->push_back( PropertyInfo(Variant::INT,"relative_x") );
- p_list->push_back( PropertyInfo(Variant::INT,"relative_y") );
+ p_list->push_back( PropertyInfo(Variant::REAL,"relative_x") );
+ p_list->push_back( PropertyInfo(Variant::REAL,"relative_y") );
p_list->push_back( PropertyInfo(Variant::VECTOR2,"relative_pos") );
p_list->push_back( PropertyInfo(Variant::REAL,"speed_x") );
p_list->push_back( PropertyInfo(Variant::REAL,"speed_y") );
@@ -2813,7 +2863,7 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
}
- if (ie.type==InputEvent::JOYSTICK_BUTTON) {
+ if (ie.type==InputEvent::JOYPAD_BUTTON) {
p_list->push_back( PropertyInfo(Variant::INT,"button_index") );
p_list->push_back( PropertyInfo(Variant::BOOL,"pressed") );
@@ -2821,7 +2871,7 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
}
- if (ie.type==InputEvent::JOYSTICK_MOTION) {
+ if (ie.type==InputEvent::JOYPAD_MOTION) {
p_list->push_back( PropertyInfo(Variant::INT,"axis") );
p_list->push_back( PropertyInfo(Variant::REAL,"value") );
@@ -2864,12 +2914,12 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
}
} break; // 20
case ARRAY:
- case RAW_ARRAY:
- case INT_ARRAY:
- case REAL_ARRAY:
- case STRING_ARRAY:
- case VECTOR3_ARRAY:
- case COLOR_ARRAY: {
+ case POOL_BYTE_ARRAY:
+ case POOL_INT_ARRAY:
+ case POOL_REAL_ARRAY:
+ case POOL_STRING_ARRAY:
+ case POOL_VECTOR3_ARRAY:
+ case POOL_COLOR_ARRAY: {
//nothing
} break;
@@ -2884,6 +2934,38 @@ bool Variant::iter_init(Variant& r_iter,bool &valid) const {
valid=true;
switch(type) {
+ case INT: {
+ r_iter=0;
+ return _data._int>0;
+ } break;
+ case REAL: {
+ r_iter=0.0;
+ return _data._real>0.0;
+ } break;
+ case VECTOR2: {
+ real_t from = reinterpret_cast<const Vector2*>(_data._mem)->x;
+ real_t to = reinterpret_cast<const Vector2*>(_data._mem)->y;
+
+ r_iter=from;
+
+ return from < to;
+ } break;
+ case VECTOR3: {
+ real_t from = reinterpret_cast<const Vector3*>(_data._mem)->x;
+ real_t to = reinterpret_cast<const Vector3*>(_data._mem)->y;
+ real_t step = reinterpret_cast<const Vector3*>(_data._mem)->z;
+
+ r_iter=from;
+
+ if (from == to ) {
+ return false;
+ } else if (from < to) {
+ return step>0.0;
+ } else {
+ return step<0.0;
+ }
+ //return true;
+ } break;
case OBJECT: {
#ifdef DEBUG_ENABLED
@@ -2899,7 +2981,7 @@ bool Variant::iter_init(Variant& r_iter,bool &valid) const {
#endif
Variant::CallError ce;
ce.error=Variant::CallError::CALL_OK;
- Array ref(true);
+ Array ref;
ref.push_back(r_iter);
Variant vref=ref;
const Variant *refp[]={&vref};
@@ -2941,56 +3023,56 @@ bool Variant::iter_init(Variant& r_iter,bool &valid) const {
r_iter=0;
return true;
} break;
- case RAW_ARRAY: {
- const DVector<uint8_t> *arr=reinterpret_cast<const DVector<uint8_t>*>(_data._mem);
+ case POOL_BYTE_ARRAY: {
+ const PoolVector<uint8_t> *arr=reinterpret_cast<const PoolVector<uint8_t>*>(_data._mem);
if (arr->size()==0)
return false;
r_iter=0;
return true;
} break;
- case INT_ARRAY: {
- const DVector<int> *arr=reinterpret_cast<const DVector<int>*>(_data._mem);
+ case POOL_INT_ARRAY: {
+ const PoolVector<int> *arr=reinterpret_cast<const PoolVector<int>*>(_data._mem);
if (arr->size()==0)
return false;
r_iter=0;
return true;
} break;
- case REAL_ARRAY: {
- const DVector<real_t> *arr=reinterpret_cast<const DVector<real_t>*>(_data._mem);
+ case POOL_REAL_ARRAY: {
+ const PoolVector<real_t> *arr=reinterpret_cast<const PoolVector<real_t>*>(_data._mem);
if (arr->size()==0)
return false;
r_iter=0;
return true;
} break;
- case STRING_ARRAY: {
- const DVector<String> *arr=reinterpret_cast<const DVector<String>*>(_data._mem);
+ case POOL_STRING_ARRAY: {
+ const PoolVector<String> *arr=reinterpret_cast<const PoolVector<String>*>(_data._mem);
if (arr->size()==0)
return false;
r_iter=0;
return true;
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
- const DVector<Vector2> *arr=reinterpret_cast<const DVector<Vector2>*>(_data._mem);
+ const PoolVector<Vector2> *arr=reinterpret_cast<const PoolVector<Vector2>*>(_data._mem);
if (arr->size()==0)
return false;
r_iter=0;
return true;
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
- const DVector<Vector3> *arr=reinterpret_cast<const DVector<Vector3>*>(_data._mem);
+ const PoolVector<Vector3> *arr=reinterpret_cast<const PoolVector<Vector3>*>(_data._mem);
if (arr->size()==0)
return false;
r_iter=0;
return true;
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
- const DVector<Color> *arr=reinterpret_cast<const DVector<Color>*>(_data._mem);
+ const PoolVector<Color> *arr=reinterpret_cast<const PoolVector<Color>*>(_data._mem);
if (arr->size()==0)
return false;
r_iter=0;
@@ -3009,7 +3091,48 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const {
valid=true;
switch(type) {
+ case INT: {
+
+ int64_t idx = r_iter;
+ idx++;
+ if (idx >= _data._int)
+ return false;
+ r_iter = idx;
+ return true;
+ } break;
+ case REAL: {
+
+ double idx = r_iter;
+ idx+=1.0;
+ if (idx >= _data._real)
+ return false;
+ r_iter = idx;
+ return true;
+ } break;
+ case VECTOR2: {
+ real_t idx = r_iter;
+ idx+=1.0;
+ if (idx>=reinterpret_cast<const Vector2*>(_data._mem)->y)
+ return false;
+ r_iter=idx;
+ return true;
+ } break;
+ case VECTOR3: {
+ real_t to = reinterpret_cast<const Vector3*>(_data._mem)->y;
+ real_t step = reinterpret_cast<const Vector3*>(_data._mem)->z;
+
+ real_t idx = r_iter;
+ idx+=step;
+
+ if (step<0.0 && idx <= to)
+ return false;
+ if (step>0.0 && idx >= to)
+ return false;
+
+ r_iter=idx;
+ return true;
+ } break;
case OBJECT: {
#ifdef DEBUG_ENABLED
@@ -3025,7 +3148,7 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const {
#endif
Variant::CallError ce;
ce.error=Variant::CallError::CALL_OK;
- Array ref(true);
+ Array ref;
ref.push_back(r_iter);
Variant vref=ref;
const Variant *refp[]={&vref};
@@ -3072,8 +3195,8 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const {
r_iter=idx;
return true;
} break;
- case RAW_ARRAY: {
- const DVector<uint8_t> *arr=reinterpret_cast<const DVector<uint8_t>*>(_data._mem);
+ case POOL_BYTE_ARRAY: {
+ const PoolVector<uint8_t> *arr=reinterpret_cast<const PoolVector<uint8_t>*>(_data._mem);
int idx=r_iter;
idx++;
if (idx>=arr->size())
@@ -3082,8 +3205,8 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const {
return true;
} break;
- case INT_ARRAY: {
- const DVector<int> *arr=reinterpret_cast<const DVector<int>*>(_data._mem);
+ case POOL_INT_ARRAY: {
+ const PoolVector<int> *arr=reinterpret_cast<const PoolVector<int>*>(_data._mem);
int idx=r_iter;
idx++;
if (idx>=arr->size())
@@ -3092,8 +3215,8 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const {
return true;
} break;
- case REAL_ARRAY: {
- const DVector<real_t> *arr=reinterpret_cast<const DVector<real_t>*>(_data._mem);
+ case POOL_REAL_ARRAY: {
+ const PoolVector<real_t> *arr=reinterpret_cast<const PoolVector<real_t>*>(_data._mem);
int idx=r_iter;
idx++;
if (idx>=arr->size())
@@ -3102,8 +3225,8 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const {
return true;
} break;
- case STRING_ARRAY: {
- const DVector<String> *arr=reinterpret_cast<const DVector<String>*>(_data._mem);
+ case POOL_STRING_ARRAY: {
+ const PoolVector<String> *arr=reinterpret_cast<const PoolVector<String>*>(_data._mem);
int idx=r_iter;
idx++;
if (idx>=arr->size())
@@ -3111,9 +3234,9 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const {
r_iter=idx;
return true;
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
- const DVector<Vector2> *arr=reinterpret_cast<const DVector<Vector2>*>(_data._mem);
+ const PoolVector<Vector2> *arr=reinterpret_cast<const PoolVector<Vector2>*>(_data._mem);
int idx=r_iter;
idx++;
if (idx>=arr->size())
@@ -3121,9 +3244,9 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const {
r_iter=idx;
return true;
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
- const DVector<Vector3> *arr=reinterpret_cast<const DVector<Vector3>*>(_data._mem);
+ const PoolVector<Vector3> *arr=reinterpret_cast<const PoolVector<Vector3>*>(_data._mem);
int idx=r_iter;
idx++;
if (idx>=arr->size())
@@ -3131,9 +3254,9 @@ bool Variant::iter_next(Variant& r_iter,bool &valid) const {
r_iter=idx;
return true;
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
- const DVector<Color> *arr=reinterpret_cast<const DVector<Color>*>(_data._mem);
+ const PoolVector<Color> *arr=reinterpret_cast<const PoolVector<Color>*>(_data._mem);
int idx=r_iter;
idx++;
if (idx>=arr->size())
@@ -3154,6 +3277,22 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const {
r_valid=true;
switch(type) {
+ case INT: {
+
+ return r_iter;
+ } break;
+ case REAL: {
+
+ return r_iter;
+ } break;
+ case VECTOR2: {
+
+ return r_iter;
+ } break;
+ case VECTOR3: {
+
+ return r_iter;
+ } break;
case OBJECT: {
#ifdef DEBUG_ENABLED
@@ -3204,8 +3343,8 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const {
#endif
return arr->get(idx);
} break;
- case RAW_ARRAY: {
- const DVector<uint8_t> *arr=reinterpret_cast<const DVector<uint8_t>*>(_data._mem);
+ case POOL_BYTE_ARRAY: {
+ const PoolVector<uint8_t> *arr=reinterpret_cast<const PoolVector<uint8_t>*>(_data._mem);
int idx=r_iter;
#ifdef DEBUG_ENABLED
if (idx<0 || idx>=arr->size()) {
@@ -3215,8 +3354,8 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const {
#endif
return arr->get(idx);
} break;
- case INT_ARRAY: {
- const DVector<int> *arr=reinterpret_cast<const DVector<int>*>(_data._mem);
+ case POOL_INT_ARRAY: {
+ const PoolVector<int> *arr=reinterpret_cast<const PoolVector<int>*>(_data._mem);
int idx=r_iter;
#ifdef DEBUG_ENABLED
if (idx<0 || idx>=arr->size()) {
@@ -3226,8 +3365,8 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const {
#endif
return arr->get(idx);
} break;
- case REAL_ARRAY: {
- const DVector<real_t> *arr=reinterpret_cast<const DVector<real_t>*>(_data._mem);
+ case POOL_REAL_ARRAY: {
+ const PoolVector<real_t> *arr=reinterpret_cast<const PoolVector<real_t>*>(_data._mem);
int idx=r_iter;
#ifdef DEBUG_ENABLED
if (idx<0 || idx>=arr->size()) {
@@ -3237,8 +3376,8 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const {
#endif
return arr->get(idx);
} break;
- case STRING_ARRAY: {
- const DVector<String> *arr=reinterpret_cast<const DVector<String>*>(_data._mem);
+ case POOL_STRING_ARRAY: {
+ const PoolVector<String> *arr=reinterpret_cast<const PoolVector<String>*>(_data._mem);
int idx=r_iter;
#ifdef DEBUG_ENABLED
if (idx<0 || idx>=arr->size()) {
@@ -3248,9 +3387,9 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const {
#endif
return arr->get(idx);
} break;
- case VECTOR2_ARRAY: {
+ case POOL_VECTOR2_ARRAY: {
- const DVector<Vector2> *arr=reinterpret_cast<const DVector<Vector2>*>(_data._mem);
+ const PoolVector<Vector2> *arr=reinterpret_cast<const PoolVector<Vector2>*>(_data._mem);
int idx=r_iter;
#ifdef DEBUG_ENABLED
if (idx<0 || idx>=arr->size()) {
@@ -3260,9 +3399,9 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const {
#endif
return arr->get(idx);
} break;
- case VECTOR3_ARRAY: {
+ case POOL_VECTOR3_ARRAY: {
- const DVector<Vector3> *arr=reinterpret_cast<const DVector<Vector3>*>(_data._mem);
+ const PoolVector<Vector3> *arr=reinterpret_cast<const PoolVector<Vector3>*>(_data._mem);
int idx=r_iter;
#ifdef DEBUG_ENABLED
if (idx<0 || idx>=arr->size()) {
@@ -3272,9 +3411,9 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const {
#endif
return arr->get(idx);
} break;
- case COLOR_ARRAY: {
+ case POOL_COLOR_ARRAY: {
- const DVector<Color> *arr=reinterpret_cast<const DVector<Color>*>(_data._mem);
+ const PoolVector<Color> *arr=reinterpret_cast<const PoolVector<Color>*>(_data._mem);
int idx=r_iter;
#ifdef DEBUG_ENABLED
if (idx<0 || idx>=arr->size()) {
@@ -3308,8 +3447,8 @@ void Variant::blend(const Variant& a, const Variant& b, float c, Variant &r_dst)
switch(a.type) {
case NIL: { r_dst=Variant(); } return;
case INT:{
- int va=a._data._int;
- int vb=b._data._int;
+ int64_t va=a._data._int;
+ int64_t vb=b._data._int;
r_dst=int(va + vb * c + 0.5);
} return;
case REAL:{
@@ -3324,10 +3463,10 @@ void Variant::blend(const Variant& a, const Variant& b, float c, Variant &r_dst)
r_dst=Rect2(ra->pos + rb->pos * c, ra->size + rb->size * c);
} return;
case VECTOR3:{ r_dst=*reinterpret_cast<const Vector3*>(a._data._mem)+*reinterpret_cast<const Vector3*>(b._data._mem)*c; } return;
- case _AABB:{
- const AABB *ra = reinterpret_cast<const AABB*>(a._data._mem);
- const AABB *rb = reinterpret_cast<const AABB*>(b._data._mem);
- r_dst=AABB(ra->pos + rb->pos * c, ra->size + rb->size * c);
+ case RECT3:{
+ const Rect3 *ra = reinterpret_cast<const Rect3*>(a._data._mem);
+ const Rect3 *rb = reinterpret_cast<const Rect3*>(b._data._mem);
+ r_dst=Rect3(ra->pos + rb->pos * c, ra->size + rb->size * c);
} return;
case QUAT:{
Quat empty_rot;
@@ -3373,8 +3512,8 @@ void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r
case NIL:{ r_dst=Variant(); } return;
case BOOL:{ r_dst=a; } return;
case INT:{
- int va=a._data._int;
- int vb=b._data._int;
+ int64_t va=a._data._int;
+ int64_t vb=b._data._int;
r_dst=int((1.0-c) * va + vb * c);
} return;
case REAL:{
@@ -3426,11 +3565,11 @@ void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r
case VECTOR2:{ r_dst=reinterpret_cast<const Vector2*>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector2*>(b._data._mem),c); } return;
case RECT2:{ r_dst = Rect2( reinterpret_cast<const Rect2*>(a._data._mem)->pos.linear_interpolate(reinterpret_cast<const Rect2*>(b._data._mem)->pos,c), reinterpret_cast<const Rect2*>(a._data._mem)->size.linear_interpolate(reinterpret_cast<const Rect2*>(b._data._mem)->size,c) ); } return;
case VECTOR3:{ r_dst=reinterpret_cast<const Vector3*>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector3*>(b._data._mem),c); } return;
- case MATRIX32:{ r_dst=a._data._matrix32->interpolate_with(*b._data._matrix32,c); } return;
+ case TRANSFORM2D:{ r_dst=a._data._transform2d->interpolate_with(*b._data._transform2d,c); } return;
case PLANE:{ r_dst=a; } return;
case QUAT:{ r_dst=reinterpret_cast<const Quat*>(a._data._mem)->slerp(*reinterpret_cast<const Quat*>(b._data._mem),c); } return;
- case _AABB:{ r_dst=AABB( a._data._aabb->pos.linear_interpolate(b._data._aabb->pos,c), a._data._aabb->size.linear_interpolate(b._data._aabb->size,c) ); } return;
- case MATRIX3:{ r_dst=Transform(*a._data._matrix3).interpolate_with(Transform(*b._data._matrix3),c).basis; } return;
+ case RECT3:{ r_dst=Rect3( a._data._rect3->pos.linear_interpolate(b._data._rect3->pos,c), a._data._rect3->size.linear_interpolate(b._data._rect3->size,c) ); } return;
+ case BASIS:{ r_dst=Transform(*a._data._basis).interpolate_with(Transform(*b._data._basis),c).basis; } return;
case TRANSFORM:{ r_dst=a._data._transform->interpolate_with(*b._data._transform,c); } return;
case COLOR:{ r_dst=reinterpret_cast<const Color*>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Color*>(b._data._mem),c); } return;
case IMAGE:{ r_dst=a; } return;
@@ -3440,25 +3579,25 @@ void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r
case INPUT_EVENT:{ r_dst=a; } return;
case DICTIONARY:{ } return;
case ARRAY:{ r_dst=a; } return;
- case RAW_ARRAY:{ r_dst=a; } return;
- case INT_ARRAY:{ r_dst=a; } return;
- case REAL_ARRAY:{ r_dst=a; } return;
- case STRING_ARRAY:{ r_dst=a; } return;
- case VECTOR2_ARRAY:{
- const DVector<Vector2> *arr_a=reinterpret_cast<const DVector<Vector2>* >(a._data._mem);
- const DVector<Vector2> *arr_b=reinterpret_cast<const DVector<Vector2>* >(b._data._mem);
+ case POOL_BYTE_ARRAY:{ r_dst=a; } return;
+ case POOL_INT_ARRAY:{ r_dst=a; } return;
+ case POOL_REAL_ARRAY:{ r_dst=a; } return;
+ case POOL_STRING_ARRAY:{ r_dst=a; } return;
+ case POOL_VECTOR2_ARRAY:{
+ const PoolVector<Vector2> *arr_a=reinterpret_cast<const PoolVector<Vector2>* >(a._data._mem);
+ const PoolVector<Vector2> *arr_b=reinterpret_cast<const PoolVector<Vector2>* >(b._data._mem);
int sz = arr_a->size();
if (sz==0 || arr_b->size()!=sz) {
r_dst=a;
} else {
- DVector<Vector2> v;
+ PoolVector<Vector2> v;
v.resize(sz);
{
- DVector<Vector2>::Write vw=v.write();
- DVector<Vector2>::Read ar=arr_a->read();
- DVector<Vector2>::Read br=arr_b->read();
+ PoolVector<Vector2>::Write vw=v.write();
+ PoolVector<Vector2>::Read ar=arr_a->read();
+ PoolVector<Vector2>::Read br=arr_b->read();
for(int i=0;i<sz;i++) {
vw[i]=ar[i].linear_interpolate(br[i],c);
@@ -3470,23 +3609,23 @@ void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r
} return;
- case VECTOR3_ARRAY:{
+ case POOL_VECTOR3_ARRAY:{
- const DVector<Vector3> *arr_a=reinterpret_cast<const DVector<Vector3>* >(a._data._mem);
- const DVector<Vector3> *arr_b=reinterpret_cast<const DVector<Vector3>* >(b._data._mem);
+ const PoolVector<Vector3> *arr_a=reinterpret_cast<const PoolVector<Vector3>* >(a._data._mem);
+ const PoolVector<Vector3> *arr_b=reinterpret_cast<const PoolVector<Vector3>* >(b._data._mem);
int sz = arr_a->size();
if (sz==0 || arr_b->size()!=sz) {
r_dst=a;
} else {
- DVector<Vector3> v;
+ PoolVector<Vector3> v;
v.resize(sz);
{
- DVector<Vector3>::Write vw=v.write();
- DVector<Vector3>::Read ar=arr_a->read();
- DVector<Vector3>::Read br=arr_b->read();
+ PoolVector<Vector3>::Write vw=v.write();
+ PoolVector<Vector3>::Read ar=arr_a->read();
+ PoolVector<Vector3>::Read br=arr_b->read();
for(int i=0;i<sz;i++) {
vw[i]=ar[i].linear_interpolate(br[i],c);
@@ -3497,7 +3636,7 @@ void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r
}
} return;
- case COLOR_ARRAY:{ r_dst=a; } return;
+ case POOL_COLOR_ARRAY:{ r_dst=a; } return;
default: {
r_dst=a;
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 023605a952..ca748b7fd3 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -614,7 +614,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value=Vector3(args[0],args[1],args[2]);
return OK;
- } else if (id=="Matrix32"){
+ } else if (id=="Transform2D" || id=="Matrix32"){ //compatibility
Vector<float> args;
Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
@@ -624,7 +624,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
if (args.size()!=6) {
r_err_str="Expected 6 arguments for constructor";
}
- Matrix32 m;
+ Transform2D m;
m[0]=Vector2(args[0],args[1]);
m[1]=Vector2(args[2],args[3]);
m[2]=Vector2(args[4],args[5]);
@@ -657,7 +657,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value=Quat(args[0],args[1],args[2],args[3]);
return OK;
- } else if (id=="AABB"){
+ } else if (id=="Rect3" || id=="AABB"){
Vector<float> args;
Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
@@ -668,10 +668,10 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
r_err_str="Expected 6 arguments for constructor";
}
- value=AABB(Vector3(args[0],args[1],args[2]),Vector3(args[3],args[4],args[5]));
+ value=Rect3(Vector3(args[0],args[1],args[2]),Vector3(args[3],args[4],args[5]));
return OK;
- } else if (id=="Matrix3"){
+ } else if (id=="Basis" || id=="Matrix3"){ //compatibility
Vector<float> args;
Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
@@ -682,7 +682,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
r_err_str="Expected 9 arguments for constructor";
}
- value=Matrix3(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]);
+ value=Basis(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]);
return OK;
} else if (id=="Transform"){
@@ -695,7 +695,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
r_err_str="Expected 12 arguments for constructor";
}
- value=Transform(Matrix3(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]),Vector3(args[9],args[10],args[11]));
+ value=Transform(Basis(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]),Vector3(args[9],args[10],args[11]));
return OK;
} else if (id=="Color") {
@@ -755,8 +755,17 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
}
get_token(p_stream,token,line,r_err_str);
- if (token.type!=TK_NUMBER) {
- r_err_str="Expected number (mipmaps)";
+
+ bool has_mipmaps=false;
+
+ if (token.type==TK_NUMBER) {
+ has_mipmaps=bool(token.value);
+ } else if (token.type==TK_IDENTIFIER && String(token.value)=="true") {
+ has_mipmaps=true;
+ } else if (token.type==TK_IDENTIFIER && String(token.value)=="false") {
+ has_mipmaps=false;
+ } else {
+ r_err_str="Expected number/true/false (mipmaps)";
return ERR_PARSE_ERROR;
}
@@ -778,36 +787,22 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
String sformat=token.value;
- Image::Format format;
-
- if (sformat=="GRAYSCALE") format=Image::FORMAT_GRAYSCALE;
- else if (sformat=="INTENSITY") format=Image::FORMAT_INTENSITY;
- else if (sformat=="GRAYSCALE_ALPHA") format=Image::FORMAT_GRAYSCALE_ALPHA;
- else if (sformat=="RGB") format=Image::FORMAT_RGB;
- else if (sformat=="RGBA") format=Image::FORMAT_RGBA;
- else if (sformat=="INDEXED") format=Image::FORMAT_INDEXED;
- else if (sformat=="INDEXED_ALPHA") format=Image::FORMAT_INDEXED_ALPHA;
- else if (sformat=="BC1") format=Image::FORMAT_BC1;
- else if (sformat=="BC2") format=Image::FORMAT_BC2;
- else if (sformat=="BC3") format=Image::FORMAT_BC3;
- else if (sformat=="BC4") format=Image::FORMAT_BC4;
- else if (sformat=="BC5") format=Image::FORMAT_BC5;
- else if (sformat=="PVRTC2") format=Image::FORMAT_PVRTC2;
- else if (sformat=="PVRTC2_ALPHA") format=Image::FORMAT_PVRTC2_ALPHA;
- else if (sformat=="PVRTC4") format=Image::FORMAT_PVRTC4;
- else if (sformat=="PVRTC4_ALPHA") format=Image::FORMAT_PVRTC4_ALPHA;
- else if (sformat=="ATC") format=Image::FORMAT_ATC;
- else if (sformat=="ATC_ALPHA_EXPLICIT") format=Image::FORMAT_ATC_ALPHA_EXPLICIT;
- else if (sformat=="ATC_ALPHA_INTERPOLATED") format=Image::FORMAT_ATC_ALPHA_INTERPOLATED;
- else if (sformat=="CUSTOM") format=Image::FORMAT_CUSTOM;
- else {
- r_err_str="Invalid image format: '"+sformat+"'";
+ Image::Format format=Image::FORMAT_MAX;
+
+ for(int i=0;i<Image::FORMAT_MAX;i++) {
+ if (Image::get_format_name(format)==sformat) {
+ format=Image::Format(i);
+ }
+ }
+
+ if (format==Image::FORMAT_MAX) {
+ r_err_str="Unknown image format: "+String(sformat);
return ERR_PARSE_ERROR;
- };
+ }
int len = Image::get_image_data_size(width,height,format,mipmaps);
- DVector<uint8_t> buffer;
+ PoolVector<uint8_t> buffer;
buffer.resize(len);
if (buffer.size()!=len) {
@@ -815,7 +810,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
}
{
- DVector<uint8_t>::Write w=buffer.write();
+ PoolVector<uint8_t>::Write w=buffer.write();
for(int i=0;i<len;i++) {
get_token(p_stream,token,line,r_err_str);
@@ -986,7 +981,18 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
InputEvent ie;
- if (id=="KEY") {
+ if (id=="NONE") {
+
+ ie.type=InputEvent::NONE;
+
+ get_token(p_stream,token,line,r_err_str);
+
+ if (token.type!=TK_PARENTHESIS_CLOSE) {
+ r_err_str="Expected ')'";
+ return ERR_PARSE_ERROR;
+ }
+
+ } else if (id=="KEY") {
get_token(p_stream,token,line,r_err_str);
if (token.type!=TK_COMMA) {
@@ -1077,7 +1083,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
return ERR_PARSE_ERROR;
}
- ie.type=InputEvent::JOYSTICK_BUTTON;
+ ie.type=InputEvent::JOYPAD_BUTTON;
get_token(p_stream,token,line,r_err_str);
if (token.type!=TK_NUMBER) {
@@ -1101,7 +1107,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
return ERR_PARSE_ERROR;
}
- ie.type=InputEvent::JOYSTICK_MOTION;
+ ie.type=InputEvent::JOYPAD_MOTION;
get_token(p_stream,token,line,r_err_str);
if (token.type!=TK_NUMBER) {
@@ -1143,18 +1149,18 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
return OK;
- } else if (id=="ByteArray") {
+ } else if (id=="PoolByteArray"|| id=="ByteArray") {
Vector<uint8_t> args;
Error err = _parse_construct<uint8_t>(p_stream,args,line,r_err_str);
if (err)
return err;
- DVector<uint8_t> arr;
+ PoolVector<uint8_t> arr;
{
int len=args.size();
arr.resize(len);
- DVector<uint8_t>::Write w = arr.write();
+ PoolVector<uint8_t>::Write w = arr.write();
for(int i=0;i<len;i++) {
w[i]=args[i];
}
@@ -1164,18 +1170,18 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
return OK;
- } else if (id=="IntArray") {
+ } else if (id=="PoolIntArray"|| id=="IntArray") {
- Vector<int32_t> args;
- Error err = _parse_construct<int32_t>(p_stream,args,line,r_err_str);
+ Vector<int> args;
+ Error err = _parse_construct<int>(p_stream,args,line,r_err_str);
if (err)
return err;
- DVector<int32_t> arr;
+ PoolVector<int> arr;
{
int len=args.size();
arr.resize(len);
- DVector<int32_t>::Write w = arr.write();
+ PoolVector<int>::Write w = arr.write();
for(int i=0;i<len;i++) {
w[i]=int(args[i]);
}
@@ -1185,18 +1191,18 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
return OK;
- } else if (id=="FloatArray") {
+ } else if (id=="PoolFloatArray"|| id=="FloatArray") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
if (err)
return err;
- DVector<float> arr;
+ PoolVector<float> arr;
{
int len=args.size();
arr.resize(len);
- DVector<float>::Write w = arr.write();
+ PoolVector<float>::Write w = arr.write();
for(int i=0;i<len;i++) {
w[i]=args[i];
}
@@ -1205,7 +1211,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value=arr;
return OK;
- } else if (id=="StringArray") {
+ } else if (id=="PoolStringArray"|| id=="StringArray") {
get_token(p_stream,token,line,r_err_str);
@@ -1245,11 +1251,11 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
}
- DVector<String> arr;
+ PoolVector<String> arr;
{
int len=cs.size();
arr.resize(len);
- DVector<String>::Write w = arr.write();
+ PoolVector<String>::Write w = arr.write();
for(int i=0;i<len;i++) {
w[i]=cs[i];
}
@@ -1260,18 +1266,18 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
return OK;
- } else if (id=="Vector2Array") {
+ } else if (id=="PoolVector2Array"|| id=="Vector2Array") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
if (err)
return err;
- DVector<Vector2> arr;
+ PoolVector<Vector2> arr;
{
int len=args.size()/2;
arr.resize(len);
- DVector<Vector2>::Write w = arr.write();
+ PoolVector<Vector2>::Write w = arr.write();
for(int i=0;i<len;i++) {
w[i]=Vector2(args[i*2+0],args[i*2+1]);
}
@@ -1281,18 +1287,18 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
return OK;
- } else if (id=="Vector3Array") {
+ } else if (id=="PoolVector3Array"|| id=="Vector3Array") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
if (err)
return err;
- DVector<Vector3> arr;
+ PoolVector<Vector3> arr;
{
int len=args.size()/3;
arr.resize(len);
- DVector<Vector3>::Write w = arr.write();
+ PoolVector<Vector3>::Write w = arr.write();
for(int i=0;i<len;i++) {
w[i]=Vector3(args[i*3+0],args[i*3+1],args[i*3+2]);
}
@@ -1302,18 +1308,18 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
return OK;
- } else if (id=="ColorArray") {
+ } else if (id=="PoolColorArray"|| id=="ColorArray") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
if (err)
return err;
- DVector<Color> arr;
+ PoolVector<Color> arr;
{
int len=args.size()/4;
arr.resize(len);
- DVector<Color>::Write w = arr.write();
+ PoolVector<Color>::Write w = arr.write();
for(int i=0;i<len;i++) {
w[i]=Color(args[i*4+0],args[i*4+1],args[i*4+2],args[i*4+3]);
}
@@ -1381,7 +1387,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
return err;
ERR_FAIL_COND_V(params.size()!=2,ERR_PARSE_ERROR);
InputEvent ie;
- ie.type=InputEvent::JOYSTICK_BUTTON;
+ ie.type=InputEvent::JOYPAD_BUTTON;
ie.device=params[0].to_int();
ie.joy_button.button_index=params[1].to_int();
@@ -1397,7 +1403,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
ERR_FAIL_COND_V(params.size()!=2,ERR_PARSE_ERROR);
InputEvent ie;
- ie.type=InputEvent::JOYSTICK_MOTION;
+ ie.type=InputEvent::JOYPAD_MOTION;
ie.device=params[0].to_int();
int axis=params[1].to_int();
ie.joy_motion.axis=axis>>1;
@@ -1892,10 +1898,10 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud,"Plane( "+rtosfix(p.normal.x) +", "+rtosfix(p.normal.y)+", "+rtosfix(p.normal.z)+", "+rtosfix(p.d)+" )" );
} break;
- case Variant::_AABB: {
+ case Variant::RECT3: {
- AABB aabb = p_variant;
- p_store_string_func(p_store_string_ud,"AABB( "+rtosfix(aabb.pos.x) +", "+rtosfix(aabb.pos.y) +", "+rtosfix(aabb.pos.z) +", "+rtosfix(aabb.size.x) +", "+rtosfix(aabb.size.y) +", "+rtosfix(aabb.size.z)+" )" );
+ Rect3 aabb = p_variant;
+ p_store_string_func(p_store_string_ud,"Rect3( "+rtosfix(aabb.pos.x) +", "+rtosfix(aabb.pos.y) +", "+rtosfix(aabb.pos.z) +", "+rtosfix(aabb.size.x) +", "+rtosfix(aabb.size.y) +", "+rtosfix(aabb.size.z)+" )" );
} break;
case Variant::QUAT: {
@@ -1904,10 +1910,10 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud,"Quat( "+rtosfix(quat.x)+", "+rtosfix(quat.y)+", "+rtosfix(quat.z)+", "+rtosfix(quat.w)+" )");
} break;
- case Variant::MATRIX32: {
+ case Variant::TRANSFORM2D: {
- String s="Matrix32( ";
- Matrix32 m3 = p_variant;
+ String s="Transform2D( ";
+ Transform2D m3 = p_variant;
for (int i=0;i<3;i++) {
for (int j=0;j<2;j++) {
@@ -1920,10 +1926,10 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud,s+" )");
} break;
- case Variant::MATRIX3: {
+ case Variant::BASIS: {
- String s="Matrix3( ";
- Matrix3 m3 = p_variant;
+ String s="Basis( ";
+ Basis m3 = p_variant;
for (int i=0;i<3;i++) {
for (int j=0;j<3;j++) {
@@ -1940,7 +1946,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
String s="Transform( ";
Transform t = p_variant;
- Matrix3 &m3 = t.basis;
+ Basis &m3 = t.basis;
for (int i=0;i<3;i++) {
for (int j=0;j<3;j++) {
@@ -1975,41 +1981,14 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
String imgstr="Image( ";
imgstr+=itos(img.get_width());
imgstr+=", "+itos(img.get_height());
- imgstr+=", "+itos(img.get_mipmaps());
- imgstr+=", ";
-
- switch(img.get_format()) {
-
- case Image::FORMAT_GRAYSCALE: imgstr+="GRAYSCALE"; break;
- case Image::FORMAT_INTENSITY: imgstr+="INTENSITY"; break;
- case Image::FORMAT_GRAYSCALE_ALPHA: imgstr+="GRAYSCALE_ALPHA"; break;
- case Image::FORMAT_RGB: imgstr+="RGB"; break;
- case Image::FORMAT_RGBA: imgstr+="RGBA"; break;
- case Image::FORMAT_INDEXED : imgstr+="INDEXED"; break;
- case Image::FORMAT_INDEXED_ALPHA: imgstr+="INDEXED_ALPHA"; break;
- case Image::FORMAT_BC1: imgstr+="BC1"; break;
- case Image::FORMAT_BC2: imgstr+="BC2"; break;
- case Image::FORMAT_BC3: imgstr+="BC3"; break;
- case Image::FORMAT_BC4: imgstr+="BC4"; break;
- case Image::FORMAT_BC5: imgstr+="BC5"; break;
- case Image::FORMAT_PVRTC2: imgstr+="PVRTC2"; break;
- case Image::FORMAT_PVRTC2_ALPHA: imgstr+="PVRTC2_ALPHA"; break;
- case Image::FORMAT_PVRTC4: imgstr+="PVRTC4"; break;
- case Image::FORMAT_PVRTC4_ALPHA: imgstr+="PVRTC4_ALPHA"; break;
- case Image::FORMAT_ETC: imgstr+="ETC"; break;
- case Image::FORMAT_ATC: imgstr+="ATC"; break;
- case Image::FORMAT_ATC_ALPHA_EXPLICIT: imgstr+="ATC_ALPHA_EXPLICIT"; break;
- case Image::FORMAT_ATC_ALPHA_INTERPOLATED: imgstr+="ATC_ALPHA_INTERPOLATED"; break;
- case Image::FORMAT_CUSTOM: imgstr+="CUSTOM"; break;
- default: {}
- }
-
+ imgstr+=", "+String(img.has_mipmaps()?"true":"false");
+ imgstr+=", "+Image::get_format_name(img.get_format());
String s;
- DVector<uint8_t> data = img.get_data();
+ PoolVector<uint8_t> data = img.get_data();
int len = data.size();
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
const uint8_t *ptr=r.ptr();;
for (int i=0;i<len;i++) {
@@ -2086,13 +2065,16 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
str+="MBUTTON,"+itos(ev.mouse_button.button_index);
} break;
- case InputEvent::JOYSTICK_BUTTON: {
+ case InputEvent::JOYPAD_BUTTON: {
str+="JBUTTON,"+itos(ev.joy_button.button_index);
} break;
- case InputEvent::JOYSTICK_MOTION: {
+ case InputEvent::JOYPAD_MOTION: {
str+="JAXIS,"+itos(ev.joy_motion.axis)+","+itos(ev.joy_motion.axis_value);
} break;
+ case InputEvent::NONE: {
+ str+="NONE";
+ } break;
default: {}
}
@@ -2112,8 +2094,10 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud,"{ ");
for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
- //if (!_check_type(dict[E->get()]))
- // continue;
+ /*
+ if (!_check_type(dict[E->get()]))
+ 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,":");
write(dict[E->get()],p_store_string_func,p_store_string_ud,p_encode_res_func,p_encode_res_ud);
@@ -2142,13 +2126,13 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
} break;
- case Variant::RAW_ARRAY: {
+ case Variant::POOL_BYTE_ARRAY: {
- p_store_string_func(p_store_string_ud,"ByteArray( ");
+ p_store_string_func(p_store_string_ud,"PoolByteArray( ");
String s;
- DVector<uint8_t> data = p_variant;
+ PoolVector<uint8_t> data = p_variant;
int len = data.size();
- DVector<uint8_t>::Read r = data.read();
+ PoolVector<uint8_t>::Read r = data.read();
const uint8_t *ptr=r.ptr();;
for (int i=0;i<len;i++) {
@@ -2162,12 +2146,12 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud," )");
} break;
- case Variant::INT_ARRAY: {
+ case Variant::POOL_INT_ARRAY: {
- p_store_string_func(p_store_string_ud,"IntArray( ");
- DVector<int> data = p_variant;
+ p_store_string_func(p_store_string_ud,"PoolIntArray( ");
+ PoolVector<int> data = p_variant;
int len = data.size();
- DVector<int>::Read r = data.read();
+ PoolVector<int>::Read r = data.read();
const int *ptr=r.ptr();;
for (int i=0;i<len;i++) {
@@ -2182,12 +2166,12 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud," )");
} break;
- case Variant::REAL_ARRAY: {
+ case Variant::POOL_REAL_ARRAY: {
- p_store_string_func(p_store_string_ud,"FloatArray( ");
- DVector<real_t> data = p_variant;
+ p_store_string_func(p_store_string_ud,"PoolFloatArray( ");
+ PoolVector<real_t> data = p_variant;
int len = data.size();
- DVector<real_t>::Read r = data.read();
+ PoolVector<real_t>::Read r = data.read();
const real_t *ptr=r.ptr();;
for (int i=0;i<len;i++) {
@@ -2200,12 +2184,12 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud," )");
} break;
- case Variant::STRING_ARRAY: {
+ case Variant::POOL_STRING_ARRAY: {
- p_store_string_func(p_store_string_ud,"StringArray( ");
- DVector<String> data = p_variant;
+ p_store_string_func(p_store_string_ud,"PoolStringArray( ");
+ PoolVector<String> data = p_variant;
int len = data.size();
- DVector<String>::Read r = data.read();
+ PoolVector<String>::Read r = data.read();
const String *ptr=r.ptr();;
String s;
//write_string("\n");
@@ -2223,12 +2207,12 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud," )");
} break;
- case Variant::VECTOR2_ARRAY: {
+ case Variant::POOL_VECTOR2_ARRAY: {
- p_store_string_func(p_store_string_ud,"Vector2Array( ");
- DVector<Vector2> data = p_variant;
+ p_store_string_func(p_store_string_ud,"PoolVector2Array( ");
+ PoolVector<Vector2> data = p_variant;
int len = data.size();
- DVector<Vector2>::Read r = data.read();
+ PoolVector<Vector2>::Read r = data.read();
const Vector2 *ptr=r.ptr();;
for (int i=0;i<len;i++) {
@@ -2241,12 +2225,12 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud," )");
} break;
- case Variant::VECTOR3_ARRAY: {
+ case Variant::POOL_VECTOR3_ARRAY: {
- p_store_string_func(p_store_string_ud,"Vector3Array( ");
- DVector<Vector3> data = p_variant;
+ p_store_string_func(p_store_string_ud,"PoolVector3Array( ");
+ PoolVector<Vector3> data = p_variant;
int len = data.size();
- DVector<Vector3>::Read r = data.read();
+ PoolVector<Vector3>::Read r = data.read();
const Vector3 *ptr=r.ptr();;
for (int i=0;i<len;i++) {
@@ -2259,13 +2243,13 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud," )");
} break;
- case Variant::COLOR_ARRAY: {
+ case Variant::POOL_COLOR_ARRAY: {
- p_store_string_func(p_store_string_ud,"ColorArray( ");
+ p_store_string_func(p_store_string_ud,"PoolColorArray( ");
- DVector<Color> data = p_variant;
+ PoolVector<Color> data = p_variant;
int len = data.size();
- DVector<Color>::Read r = data.read();
+ PoolVector<Color>::Read r = data.read();
const Color *ptr=r.ptr();;
for (int i=0;i<len;i++) {
diff --git a/core/variant_parser.h b/core/variant_parser.h
index 5857820efa..c69673b0e4 100644
--- a/core/variant_parser.h
+++ b/core/variant_parser.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/vector.h b/core/vector.h
index cafb4a4aa3..3119657cbb 100644
--- a/core/vector.h
+++ b/core/vector.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,7 +32,7 @@
/**
* @class Vector
* @author Juan Linietsky
- * Vector container. Regular Vector Container. Use with care and for smaller arrays when possible. Use DVector for large arrays.
+ * Vector container. Regular Vector Container. Use with care and for smaller arrays when possible. Use PoolVector for large arrays.
*/
#include "os/memory.h"
#include "error_macros.h"
@@ -46,19 +46,20 @@ class Vector {
// internal helpers
- _FORCE_INLINE_ SafeRefCount* _get_refcount() const {
+ _FORCE_INLINE_ uint32_t* _get_refcount() const {
if (!_ptr)
return NULL;
- return reinterpret_cast<SafeRefCount*>((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount));
+ return reinterpret_cast<uint32_t*>(_ptr)-2;
}
- _FORCE_INLINE_ int* _get_size() const {
+ _FORCE_INLINE_ uint32_t* _get_size() const {
if (!_ptr)
- return NULL;
- return reinterpret_cast<int*>((uint8_t*)_ptr-sizeof(int));
+ return NULL;
+
+ return reinterpret_cast<uint32_t*>(_ptr)-1;
}
_FORCE_INLINE_ T* _get_data() const {
@@ -71,7 +72,7 @@ class Vector {
_FORCE_INLINE_ size_t _get_alloc_size(size_t p_elements) const {
//return nearest_power_of_2_templated(p_elements*sizeof(T)+sizeof(SafeRefCount)+sizeof(int));
- return nearest_power_of_2(p_elements*sizeof(T)+sizeof(SafeRefCount)+sizeof(int));
+ return nearest_power_of_2(p_elements*sizeof(T));
}
_FORCE_INLINE_ bool _get_alloc_size_checked(size_t p_elements, size_t *out) const {
@@ -79,8 +80,8 @@ class Vector {
size_t o;
size_t p;
if (_mul_overflow(p_elements, sizeof(T), &o)) return false;
- if (_add_overflow(o, sizeof(SafeRefCount)+sizeof(int), &p)) return false;
- *out = nearest_power_of_2(p);
+ *out = nearest_power_of_2(o);
+ if (_add_overflow(o, 32, &p)) return false; //no longer allocated here
return true;
#else
// Speed is more important than correctness here, do the operations unchecked
@@ -104,7 +105,7 @@ public:
_FORCE_INLINE_ void clear() { resize(0); }
_FORCE_INLINE_ int size() const {
- int* size = _get_size();
+ uint32_t* size = (uint32_t*)_get_size();
if (size)
return *size;
else
@@ -190,22 +191,22 @@ void Vector<T>::_unref(void *p_data) {
if (!p_data)
return;
- SafeRefCount *src = reinterpret_cast<SafeRefCount*>((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount));
+ uint32_t *refc = _get_refcount();
- if (!src->unref())
+ if (atomic_decrement(refc)>0)
return; // still in use
// clean up
- int *count = (int*)(src+1);
+ uint32_t *count = _get_size();
T *data = (T*)(count+1);
- for (int i=0;i<*count;i++) {
+ for (uint32_t i=0;i<*count;i++) {
// call destructors
data[i].~T();
}
// free mem
- memfree((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount));
+ Memory::free_static((uint8_t*)p_data,true);
}
@@ -215,18 +216,22 @@ void Vector<T>::_copy_on_write() {
if (!_ptr)
return;
- if (_get_refcount()->get() > 1 ) {
+ uint32_t *refc = _get_refcount();
+
+ if (*refc > 1) {
/* in use by more than me */
- void* mem_new = memalloc(_get_alloc_size(*_get_size()));
- SafeRefCount *src_new=(SafeRefCount *)mem_new;
- src_new->init();
- int * _size = (int*)(src_new+1);
- *_size=*_get_size();
+ uint32_t current_size = *_get_size();
+
+ uint32_t* mem_new = (uint32_t*)Memory::alloc_static(_get_alloc_size(current_size),true);
- T*_data=(T*)(_size+1);
+
+ *(mem_new-2)=1; //refcount
+ *(mem_new-1)=current_size; //size
+
+ T*_data=(T*)(mem_new);
// initialize new elements
- for (int i=0;i<*_size;i++) {
+ for (uint32_t i=0;i<current_size;i++) {
memnew_placement(&_data[i], T( _get_data()[i] ) );
}
@@ -280,16 +285,17 @@ Error Vector<T>::resize(int p_size) {
if (size()==0) {
// alloc from scratch
- void* ptr=memalloc(alloc_size);
+ uint32_t *ptr=(uint32_t*)Memory::alloc_static(alloc_size,true);
ERR_FAIL_COND_V( !ptr ,ERR_OUT_OF_MEMORY);
- _ptr=(T*)((uint8_t*)ptr+sizeof(int)+sizeof(SafeRefCount));
- _get_refcount()->init(); // init refcount
- *_get_size()=0; // init size (currently, none)
+ *(ptr-1)=0; //size, currently none
+ *(ptr-2)=1; //refcount
+
+ _ptr=(T*)ptr;
} else {
- void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount), alloc_size);
+ void *_ptrnew = (T*)Memory::realloc_static(_ptr, alloc_size,true);
ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY);
- _ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount));
+ _ptr=(T*)(_ptrnew);
}
// construct the newly created elements
@@ -305,16 +311,16 @@ Error Vector<T>::resize(int p_size) {
} else if (p_size<size()) {
// deinitialize no longer needed elements
- for (int i=p_size;i<*_get_size();i++) {
+ for (uint32_t i=p_size;i<*_get_size();i++) {
T* t = &_get_data()[i];
t->~T();
}
- void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount), alloc_size);
+ void *_ptrnew = (T*)Memory::realloc_static(_ptr, alloc_size,true);
ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY);
- _ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount));
+ _ptr=(T*)(_ptrnew);
*_get_size()=p_size;
@@ -382,8 +388,9 @@ void Vector<T>::_copy_from(const Vector& p_from) {
if (!p_from._ptr)
return; //nothing to do
- if (p_from._get_refcount()->ref()) // could reference
+ if (atomic_conditional_increment(p_from._get_refcount())>0) { // could reference
_ptr=p_from._ptr;
+ }
}
diff --git a/core/vmap.h b/core/vmap.h
index 6880abf260..3708cbed5b 100644
--- a/core/vmap.h
+++ b/core/vmap.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/core/vset.h b/core/vset.h
index cafcb0bb2f..e0b5181263 100644
--- a/core/vset.h
+++ b/core/vset.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */