summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub5
-rw-r--r--core/array.cpp1
-rw-r--r--core/bind/core_bind.cpp700
-rw-r--r--core/bind/core_bind.h61
-rw-r--r--core/class_db.cpp (renamed from core/object_type_db.cpp)47
-rw-r--r--core/class_db.h (renamed from core/object_type_db.h)37
-rw-r--r--core/color.cpp1
-rw-r--r--core/color_names.inc2
-rw-r--r--core/command_queue_mt.cpp1
-rw-r--r--core/command_queue_mt.h34
-rw-r--r--core/compressed_translation.cpp15
-rw-r--r--core/core_string_names.cpp2
-rw-r--r--core/dictionary.cpp1
-rw-r--r--core/dvector.h13
-rw-r--r--core/engine.cpp119
-rw-r--r--core/engine.h88
-rw-r--r--core/error_list.h2
-rw-r--r--core/error_macros.cpp1
-rw-r--r--core/func_ref.cpp4
-rw-r--r--core/global_config.cpp (renamed from core/globals.cpp)209
-rw-r--r--core/global_config.h (renamed from core/globals.h)4
-rw-r--r--core/global_constants.cpp3
-rw-r--r--core/hash_map.h63
-rw-r--r--core/hashfuncs.h42
-rw-r--r--core/helper/SCsub7
-rw-r--r--core/helper/math_fieldwise.cpp171
-rw-r--r--core/helper/math_fieldwise.h40
-rw-r--r--core/image.cpp73
-rw-r--r--core/image.h2
-rw-r--r--core/input_map.cpp47
-rw-r--r--core/input_map.h2
-rw-r--r--core/io/aes256.cpp6
-rw-r--r--core/io/base64.c8
-rw-r--r--core/io/base64.h8
-rw-r--r--core/io/compression.cpp2
-rw-r--r--core/io/config_file.cpp21
-rw-r--r--core/io/config_file.h2
-rw-r--r--core/io/file_access_buffered_fa.h9
-rw-r--r--core/io/file_access_memory.cpp6
-rw-r--r--core/io/file_access_network.cpp8
-rw-r--r--core/io/file_access_pack.cpp10
-rw-r--r--core/io/file_access_pack.h2
-rw-r--r--core/io/file_access_zip.cpp2
-rw-r--r--core/io/http_client.cpp69
-rw-r--r--core/io/http_client.h4
-rw-r--r--core/io/image_loader.cpp4
-rw-r--r--core/io/ip.cpp16
-rw-r--r--core/io/ip_address.cpp27
-rw-r--r--core/io/ip_address.h9
-rw-r--r--core/io/json.cpp6
-rw-r--r--core/io/marshalls.cpp4
-rw-r--r--core/io/networked_multiplayer_peer.cpp44
-rw-r--r--core/io/networked_multiplayer_peer.h28
-rw-r--r--core/io/packet_peer.cpp16
-rw-r--r--core/io/packet_peer_udp.cpp32
-rw-r--r--core/io/packet_peer_udp.h9
-rw-r--r--core/io/pck_packer.cpp8
-rw-r--r--core/io/resource_format_binary.cpp169
-rw-r--r--core/io/resource_format_binary.h3
-rw-r--r--core/io/resource_import.cpp259
-rw-r--r--core/io/resource_import.h77
-rw-r--r--core/io/resource_loader.cpp175
-rw-r--r--core/io/resource_loader.h9
-rw-r--r--core/io/resource_saver.cpp6
-rw-r--r--core/io/stream_peer.cpp92
-rw-r--r--core/io/stream_peer_ssl.cpp8
-rw-r--r--core/io/stream_peer_ssl.h6
-rw-r--r--core/io/stream_peer_tcp.cpp25
-rw-r--r--core/io/stream_peer_tcp.h9
-rw-r--r--core/io/tcp_server.cpp26
-rw-r--r--core/io/tcp_server.h6
-rw-r--r--core/io/translation_loader_po.cpp2
-rw-r--r--core/io/xml_parser.cpp34
-rw-r--r--core/io/zip.c2
-rw-r--r--core/map.h4
-rw-r--r--core/math/a_star.cpp46
-rw-r--r--core/math/a_star.h8
-rw-r--r--core/math/audio_frame.cpp2
-rw-r--r--core/math/audio_frame.h61
-rw-r--r--core/math/bsp_tree.cpp38
-rw-r--r--core/math/bsp_tree.h10
-rw-r--r--core/math/camera_matrix.cpp113
-rw-r--r--core/math/camera_matrix.h24
-rw-r--r--core/math/face3.cpp56
-rw-r--r--core/math/face3.h24
-rw-r--r--core/math/geometry.cpp22
-rw-r--r--core/math/geometry.h152
-rw-r--r--core/math/math_2d.cpp6
-rw-r--r--core/math/math_2d.h2
-rw-r--r--core/math/math_funcs.cpp87
-rw-r--r--core/math/math_funcs.h236
-rw-r--r--core/math/matrix3.cpp20
-rw-r--r--core/math/octree.h22
-rw-r--r--core/math/pcg.cpp15
-rw-r--r--core/math/pcg.h14
-rw-r--r--core/math/plane.h2
-rw-r--r--core/math/quat.cpp18
-rw-r--r--core/math/quat.h4
-rw-r--r--core/math/quick_hull.cpp8
-rw-r--r--core/math/quick_hull.h2
-rw-r--r--core/math/rect3.cpp (renamed from core/math/aabb.cpp)14
-rw-r--r--core/math/rect3.h (renamed from core/math/aabb.h)26
-rw-r--r--core/math/transform.h2
-rw-r--r--core/math/triangle_mesh.cpp51
-rw-r--r--core/math/triangulate.cpp24
-rw-r--r--core/math/triangulate.h10
-rw-r--r--core/math/triangulator.cpp2
-rw-r--r--core/math/vector3.cpp74
-rw-r--r--core/math/vector3.h16
-rw-r--r--core/message_queue.cpp4
-rw-r--r--core/method_bind.cpp3
-rw-r--r--core/method_ptrcall.h16
-rw-r--r--core/object.cpp91
-rw-r--r--core/object.h21
-rw-r--r--core/os/dir_access.cpp2
-rw-r--r--core/os/dir_access.h2
-rw-r--r--core/os/file_access.cpp2
-rw-r--r--core/os/input.cpp72
-rw-r--r--core/os/input.h6
-rw-r--r--core/os/input_event.cpp3
-rw-r--r--core/os/keyboard.cpp7
-rw-r--r--core/os/main_loop.cpp12
-rw-r--r--core/os/memory.h4
-rw-r--r--core/os/mutex.cpp2
-rw-r--r--core/os/os.cpp82
-rw-r--r--core/os/os.h39
-rw-r--r--core/packed_data_container.cpp28
-rw-r--r--core/pair.h9
-rw-r--r--core/path_db.cpp4
-rw-r--r--core/path_remap.cpp173
-rw-r--r--core/path_remap.h35
-rw-r--r--core/pool_allocator.cpp7
-rw-r--r--core/print_string.cpp2
-rw-r--r--core/profile_clock.cpp3
-rw-r--r--core/profile_clock.h7
-rw-r--r--core/ref_ptr.cpp1
-rw-r--r--core/reference.cpp9
-rw-r--r--core/reference.h2
-rw-r--r--core/register_core_types.cpp21
-rw-r--r--core/resource.cpp181
-rw-r--r--core/resource.h56
-rw-r--r--core/safe_refcount.cpp8
-rw-r--r--core/script_debugger_local.cpp3
-rw-r--r--core/script_debugger_remote.cpp16
-rw-r--r--core/script_language.cpp14
-rw-r--r--core/set.h6
-rw-r--r--core/string_db.cpp2
-rw-r--r--core/string_db.h3
-rw-r--r--core/translation.cpp54
-rw-r--r--core/translation.h1
-rw-r--r--core/typedefs.h74
-rw-r--r--core/undo_redo.cpp23
-rw-r--r--core/ustring.cpp163
-rw-r--r--core/ustring.h8
-rw-r--r--core/variant.cpp190
-rw-r--r--core/variant.h7
-rw-r--r--core/variant_call.cpp71
-rw-r--r--core/variant_construct_string.cpp2
-rw-r--r--core/variant_op.cpp6
-rw-r--r--core/variant_parser.cpp54
-rw-r--r--core/vector.h2
161 files changed, 3334 insertions, 2559 deletions
diff --git a/core/SCsub b/core/SCsub
index 8d89f6427b..77c8288846 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -13,7 +13,7 @@ for x in env.global_defaults:
gd_inc += '#include "platform/' + x + '/globals/global_defaults.h"\n'
gd_call += "\tregister_" + x + "_global_defaults();\n"
-gd_cpp = '#include "globals.h"\n'
+gd_cpp = '#include "global_config.h"\n'
gd_cpp += gd_inc
gd_cpp += "void GlobalConfig::register_global_defaults() {\n" + gd_call + "\n}\n"
@@ -45,7 +45,7 @@ if ("SCRIPT_AES256_ENCRYPTION_KEY" in os.environ):
print("Invalid AES256 encryption key, not 64 bits hex: " + e)
f = open("script_encryption_key.cpp", "wb")
-f.write("#include \"globals.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
+f.write("#include \"global_config.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
f.close()
@@ -61,6 +61,7 @@ SConscript('os/SCsub')
SConscript('math/SCsub')
SConscript('io/SCsub')
SConscript('bind/SCsub')
+SConscript('helper/SCsub')
lib = env.Library("core", env.core_sources)
diff --git a/core/array.cpp b/core/array.cpp
index b9c8f543da..16598a044d 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "array.h"
+
#include "vector.h"
#include "hashfuncs.h"
#include "variant.h"
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 8f1c1779bd..79cfae0a3a 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -31,7 +31,7 @@
#include "geometry.h"
#include "io/marshalls.h"
#include "io/base64.h"
-#include "core/globals.h"
+#include "core/global_config.h"
#include "io/file_access_encrypted.h"
#include "os/keyboard.h"
@@ -106,21 +106,16 @@ bool _ResourceLoader::has(const String &p_path) {
return ResourceCache::has(local_path);
};
-Ref<ResourceImportMetadata> _ResourceLoader::load_import_metadata(const String& p_path) {
-
- return ResourceLoader::load_import_metadata(p_path);
-}
void _ResourceLoader::_bind_methods() {
- ClassDB::bind_method(_MD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL(""));
- ClassDB::bind_method(_MD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false));
- ClassDB::bind_method(_MD("load_import_metadata:ResourceImportMetadata","path"),&_ResourceLoader::load_import_metadata);
- ClassDB::bind_method(_MD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type);
- ClassDB::bind_method(_MD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources);
- ClassDB::bind_method(_MD("get_dependencies","path"),&_ResourceLoader::get_dependencies);
- ClassDB::bind_method(_MD("has","path"),&_ResourceLoader::has);
+ ClassDB::bind_method(D_METHOD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type);
+ ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources);
+ ClassDB::bind_method(D_METHOD("get_dependencies","path"),&_ResourceLoader::get_dependencies);
+ ClassDB::bind_method(D_METHOD("has","path"),&_ResourceLoader::has);
}
_ResourceLoader::_ResourceLoader() {
@@ -153,8 +148,8 @@ _ResourceSaver *_ResourceSaver::singleton=NULL;
void _ResourceSaver::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("save","path","resource:Resource","flags"),&_ResourceSaver::save,DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_recognized_extensions","type"),&_ResourceSaver::get_recognized_extensions);
BIND_CONSTANT(FLAG_RELATIVE_PATHS);
BIND_CONSTANT(FLAG_BUNDLE_RESOURCES);
@@ -340,24 +335,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 +426,10 @@ String _OS::get_latin_keyboard_variant() const {
String _OS::get_model_name() const {
- return OS::get_singleton()->get_model_name();
+ 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);
-}
-
-float _OS::get_time_scale() {
-
- return OS::get_singleton()->get_time_scale();
-}
bool _OS::is_ok_left_and_cancel_right() const {
@@ -622,28 +587,20 @@ uint64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
static const unsigned int SECONDS_PER_MINUTE = 60;
static const unsigned int MINUTES_PER_HOUR = 60;
static const unsigned int HOURS_PER_DAY = 24;
- static const unsigned int SECONDS_PER_HOUR = MINUTES_PER_HOUR *
- SECONDS_PER_MINUTE;
+ static const unsigned int SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE;
static const unsigned int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
// Get all time values from the dictionary, set to zero if it doesn't exist.
// Risk incorrect calculation over throwing errors
- unsigned int second = ((datetime.has(SECOND_KEY))?
- static_cast<unsigned int>(datetime[SECOND_KEY]): 0);
- unsigned int minute = ((datetime.has(MINUTE_KEY))?
- static_cast<unsigned int>(datetime[MINUTE_KEY]): 0);
- unsigned int hour = ((datetime.has(HOUR_KEY))?
- static_cast<unsigned int>(datetime[HOUR_KEY]): 0);
- unsigned int day = ((datetime.has(DAY_KEY))?
- static_cast<unsigned int>(datetime[DAY_KEY]): 0);
- unsigned int month = ((datetime.has(MONTH_KEY))?
- static_cast<unsigned int>(datetime[MONTH_KEY]) -1: 0);
- unsigned int year = ((datetime.has(YEAR_KEY))?
- static_cast<unsigned int>(datetime[YEAR_KEY]):0);
+ unsigned int second = ((datetime.has(SECOND_KEY)) ? static_cast<unsigned int>(datetime[SECOND_KEY]): 0);
+ unsigned int minute = ((datetime.has(MINUTE_KEY)) ? static_cast<unsigned int>(datetime[MINUTE_KEY]): 0);
+ unsigned int hour = ((datetime.has(HOUR_KEY)) ? static_cast<unsigned int>(datetime[HOUR_KEY]): 0);
+ unsigned int day = ((datetime.has(DAY_KEY)) ? static_cast<unsigned int>(datetime[DAY_KEY]): 0);
+ unsigned int month = ((datetime.has(MONTH_KEY)) ? static_cast<unsigned int>(datetime[MONTH_KEY]) -1: 0);
+ unsigned int year = ((datetime.has(YEAR_KEY)) ? static_cast<unsigned int>(datetime[YEAR_KEY]):0);
/// How many days come before each month (0-12)
- static const unsigned short int DAYS_PAST_THIS_YEAR_TABLE[2][13] =
- {
+ static const unsigned short int DAYS_PAST_THIS_YEAR_TABLE[2][13] = {
/* Normal years. */
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
/* Leap years. */
@@ -663,19 +620,16 @@ uint64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
ERR_FAIL_COND_V( month+1 > 12, 0);
// Do this check after month is tested as valid
- ERR_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger "
- "than "+ itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month]));
+ ERR_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger than "+ itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month]));
ERR_FAIL_COND_V( day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month], 0);
// Calculate all the seconds from months past in this year
- uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR =
- DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month] * SECONDS_PER_DAY;
+ uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month] * SECONDS_PER_DAY;
uint64_t SECONDS_FROM_YEARS_PAST = 0;
for(unsigned int iyear = EPOCH_YR; iyear < year; iyear++) {
- SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) *
- SECONDS_PER_DAY;
+ SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) * SECONDS_PER_DAY;
}
uint64_t epoch =
@@ -706,8 +660,7 @@ Dictionary _OS::get_datetime_from_unix_time( uint64_t unix_time_val) const {
// Just fail if unix time is negative (when interpreted as an int).
// This means the user passed in a negative value by accident
- ERR_EXPLAIN("unix_time_val was really huge!"+ itos(unix_time_val) +
- " You probably passed in a negative value!");
+ ERR_EXPLAIN("unix_time_val was really huge!"+ itos(unix_time_val) + " You probably passed in a negative value!");
ERR_FAIL_COND_V( (int64_t)unix_time_val < 0, Dictionary());
OS::Date date;
@@ -804,10 +757,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 {
@@ -936,11 +885,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);
@@ -1005,10 +949,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 {
@@ -1028,166 +969,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() {
- //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);
-
- 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("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second);
- ClassDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second);
- ClassDB::bind_method(_MD("set_target_fps","target_fps"),&_OS::set_target_fps);
- ClassDB::bind_method(_MD("get_target_fps"),&_OS::get_target_fps);
-
- ClassDB::bind_method(_MD("set_time_scale","time_scale"),&_OS::set_time_scale);
- ClassDB::bind_method(_MD("get_time_scale"),&_OS::get_time_scale);
-
- 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_main_loop"),&_OS::get_main_loop);
-
- 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"),
+ //ClassDB::bind_method(D_METHOD("get_mouse_pos"),&_OS::get_mouse_pos);
+ //ClassDB::bind_method(D_METHOD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_clipboard","clipboard"),&_OS::set_clipboard);
+ ClassDB::bind_method(D_METHOD("get_clipboard"),&_OS::get_clipboard);
+
+ //will not delete for now, just unexpose
+ //ClassDB::bind_method(D_METHOD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0));
+ //ClassDB::bind_method(D_METHOD("get_video_mode_size","screen"),&_OS::get_video_mode,DEFVAL(0));
+ //ClassDB::bind_method(D_METHOD("is_video_mode_fullscreen","screen"),&_OS::is_video_mode_fullscreen,DEFVAL(0));
+ //ClassDB::bind_method(D_METHOD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0));
+ //ClassDB::bind_method(D_METHOD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
+
+
+ ClassDB::bind_method(D_METHOD("get_screen_count"),&_OS::get_screen_count);
+ ClassDB::bind_method(D_METHOD("get_current_screen"),&_OS::get_current_screen);
+ ClassDB::bind_method(D_METHOD("set_current_screen","screen"),&_OS::set_current_screen);
+ ClassDB::bind_method(D_METHOD("get_screen_position","screen"),&_OS::get_screen_position,DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_screen_size","screen"),&_OS::get_screen_size,DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_screen_dpi","screen"),&_OS::get_screen_dpi,DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_window_position"),&_OS::get_window_position);
+ ClassDB::bind_method(D_METHOD("set_window_position","position"),&_OS::set_window_position);
+ ClassDB::bind_method(D_METHOD("get_window_size"),&_OS::get_window_size);
+ ClassDB::bind_method(D_METHOD("set_window_size","size"),&_OS::set_window_size);
+ ClassDB::bind_method(D_METHOD("set_window_fullscreen","enabled"),&_OS::set_window_fullscreen);
+ ClassDB::bind_method(D_METHOD("is_window_fullscreen"),&_OS::is_window_fullscreen);
+ ClassDB::bind_method(D_METHOD("set_window_resizable","enabled"),&_OS::set_window_resizable);
+ ClassDB::bind_method(D_METHOD("is_window_resizable"),&_OS::is_window_resizable);
+ ClassDB::bind_method(D_METHOD("set_window_minimized", "enabled"),&_OS::set_window_minimized);
+ ClassDB::bind_method(D_METHOD("is_window_minimized"),&_OS::is_window_minimized);
+ ClassDB::bind_method(D_METHOD("set_window_maximized", "enabled"),&_OS::set_window_maximized);
+ ClassDB::bind_method(D_METHOD("is_window_maximized"),&_OS::is_window_maximized);
+ ClassDB::bind_method(D_METHOD("request_attention"), &_OS::request_attention);
+
+ ClassDB::bind_method(D_METHOD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
+ ClassDB::bind_method(D_METHOD("get_borderless_window"), &_OS::get_borderless_window);
+
+ ClassDB::bind_method(D_METHOD("set_screen_orientation","orientation"),&_OS::set_screen_orientation);
+ ClassDB::bind_method(D_METHOD("get_screen_orientation"),&_OS::get_screen_orientation);
+
+ ClassDB::bind_method(D_METHOD("set_keep_screen_on","enabled"),&_OS::set_keep_screen_on);
+ ClassDB::bind_method(D_METHOD("is_keep_screen_on"),&_OS::is_keep_screen_on);
+
+
+ ClassDB::bind_method(D_METHOD("has_touchscreen_ui_hint"),&_OS::has_touchscreen_ui_hint);
+
+ ClassDB::bind_method(D_METHOD("set_window_title","title"),&_OS::set_window_title);
+
+ ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode","enable"),&_OS::set_low_processor_usage_mode);
+ ClassDB::bind_method(D_METHOD("is_in_low_processor_usage_mode"),&_OS::is_in_low_processor_usage_mode);
+
+ ClassDB::bind_method(D_METHOD("get_processor_count"),&_OS::get_processor_count);
+
+ ClassDB::bind_method(D_METHOD("get_executable_path"),&_OS::get_executable_path);
+ ClassDB::bind_method(D_METHOD("execute","path","arguments","blocking","output"),&_OS::execute,DEFVAL(Array()));
+ ClassDB::bind_method(D_METHOD("kill","pid"),&_OS::kill);
+ ClassDB::bind_method(D_METHOD("shell_open","uri"),&_OS::shell_open);
+ ClassDB::bind_method(D_METHOD("get_process_ID"),&_OS::get_process_ID);
+
+ ClassDB::bind_method(D_METHOD("get_environment","environment"),&_OS::get_environment);
+ ClassDB::bind_method(D_METHOD("has_environment","environment"),&_OS::has_environment);
+
+ ClassDB::bind_method(D_METHOD("get_name"),&_OS::get_name);
+ ClassDB::bind_method(D_METHOD("get_cmdline_args"),&_OS::get_cmdline_args);
+
+ ClassDB::bind_method(D_METHOD("get_datetime","utc"),&_OS::get_datetime,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_date","utc"),&_OS::get_date,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_time","utc"),&_OS::get_time,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_time_zone_info"),&_OS::get_time_zone_info);
+ ClassDB::bind_method(D_METHOD("get_unix_time"),&_OS::get_unix_time);
+ ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"),
&_OS::get_datetime_from_unix_time);
- ClassDB::bind_method(_MD("get_unix_time_from_datetime", "datetime"),
+ ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"),
&_OS::get_unix_time_from_datetime);
- ClassDB::bind_method(_MD("get_system_time_secs"), &_OS::get_system_time_secs);
+ ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs);
- ClassDB::bind_method(_MD("set_icon","icon"),&_OS::set_icon);
+ ClassDB::bind_method(D_METHOD("set_icon","icon"),&_OS::set_icon);
- ClassDB::bind_method(_MD("get_exit_code"),&_OS::get_exit_code);
- ClassDB::bind_method(_MD("set_exit_code","code"),&_OS::set_exit_code);
+ ClassDB::bind_method(D_METHOD("get_exit_code"),&_OS::get_exit_code);
+ ClassDB::bind_method(D_METHOD("set_exit_code","code"),&_OS::set_exit_code);
- 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);
+ ClassDB::bind_method(D_METHOD("delay_usec","usec"),&_OS::delay_usec);
+ ClassDB::bind_method(D_METHOD("delay_msec","msec"),&_OS::delay_msec);
+ ClassDB::bind_method(D_METHOD("get_ticks_msec"),&_OS::get_ticks_msec);
+ ClassDB::bind_method(D_METHOD("get_splash_tick_msec"),&_OS::get_splash_tick_msec);
+ ClassDB::bind_method(D_METHOD("get_locale"),&_OS::get_locale);
+ ClassDB::bind_method(D_METHOD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant);
+ ClassDB::bind_method(D_METHOD("get_model_name"),&_OS::get_model_name);
- ClassDB::bind_method(_MD("get_custom_level"),&_OS::get_custom_level);
- ClassDB::bind_method(_MD("can_draw"),&_OS::can_draw);
- ClassDB::bind_method(_MD("get_frames_drawn"),&_OS::get_frames_drawn);
- ClassDB::bind_method(_MD("is_stdout_verbose"),&_OS::is_stdout_verbose);
+ ClassDB::bind_method(D_METHOD("can_draw"),&_OS::can_draw);
+ ClassDB::bind_method(D_METHOD("is_stdout_verbose"),&_OS::is_stdout_verbose);
- ClassDB::bind_method(_MD("can_use_threads"),&_OS::can_use_threads);
+ ClassDB::bind_method(D_METHOD("can_use_threads"),&_OS::can_use_threads);
- ClassDB::bind_method(_MD("is_debug_build"),&_OS::is_debug_build);
+ ClassDB::bind_method(D_METHOD("is_debug_build"),&_OS::is_debug_build);
- //ClassDB::bind_method(_MD("get_mouse_button_state"),&_OS::get_mouse_button_state);
+ //ClassDB::bind_method(D_METHOD("get_mouse_button_state"),&_OS::get_mouse_button_state);
- 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(""));
+ ClassDB::bind_method(D_METHOD("dump_memory_to_file","file"),&_OS::dump_memory_to_file);
+ ClassDB::bind_method(D_METHOD("dump_resources_to_file","file"),&_OS::dump_resources_to_file);
+ ClassDB::bind_method(D_METHOD("has_virtual_keyboard"),&_OS::has_virtual_keyboard);
+ ClassDB::bind_method(D_METHOD("show_virtual_keyboard", "existing_text"),&_OS::show_virtual_keyboard,DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("hide_virtual_keyboard"),&_OS::hide_virtual_keyboard);
+ ClassDB::bind_method(D_METHOD("print_resources_in_use","short"),&_OS::print_resources_in_use,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("print_all_resources","tofile"),&_OS::print_all_resources,DEFVAL(""));
- 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);
+ ClassDB::bind_method(D_METHOD("get_static_memory_usage"),&_OS::get_static_memory_usage);
+ ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"),&_OS::get_static_memory_peak_usage);
+ ClassDB::bind_method(D_METHOD("get_dynamic_memory_usage"),&_OS::get_dynamic_memory_usage);
- 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);
+ ClassDB::bind_method(D_METHOD("get_data_dir"),&_OS::get_data_dir);
+ ClassDB::bind_method(D_METHOD("get_system_dir","dir"),&_OS::get_system_dir);
+ ClassDB::bind_method(D_METHOD("get_unique_ID"),&_OS::get_unique_ID);
- ClassDB::bind_method(_MD("is_ok_left_and_cancel_right"),&_OS::is_ok_left_and_cancel_right);
+ ClassDB::bind_method(D_METHOD("is_ok_left_and_cancel_right"),&_OS::is_ok_left_and_cancel_right);
- ClassDB::bind_method(_MD("get_frames_per_second"),&_OS::get_frames_per_second);
- 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);
+ ClassDB::bind_method(D_METHOD("print_all_textures_by_size"),&_OS::print_all_textures_by_size);
+ ClassDB::bind_method(D_METHOD("print_resources_by_type","types"),&_OS::print_resources_by_type);
- 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);
+ ClassDB::bind_method(D_METHOD("native_video_play","path","volume","audio_track","subtitle_track"),&_OS::native_video_play);
+ ClassDB::bind_method(D_METHOD("native_video_is_playing"),&_OS::native_video_is_playing);
+ ClassDB::bind_method(D_METHOD("native_video_stop"),&_OS::native_video_stop);
+ ClassDB::bind_method(D_METHOD("native_video_pause"),&_OS::native_video_pause);
+ ClassDB::bind_method(D_METHOD("native_video_unpause"),&_OS::native_video_unpause);
- 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);
+ ClassDB::bind_method(D_METHOD("get_scancode_string","code"),&_OS::get_scancode_string);
+ ClassDB::bind_method(D_METHOD("is_scancode_unicode","code"),&_OS::is_scancode_unicode);
+ ClassDB::bind_method(D_METHOD("find_scancode_from_string","string"),&_OS::find_scancode_from_string);
- ClassDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap);
+ ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap);
- ClassDB::bind_method(_MD("alert","text","title"),&_OS::alert,DEFVAL("Alert!"));
+ ClassDB::bind_method(D_METHOD("alert","text","title"),&_OS::alert,DEFVAL("Alert!"));
- ClassDB::bind_method(_MD("set_thread_name","name"),&_OS::set_thread_name);
+ ClassDB::bind_method(D_METHOD("set_thread_name","name"),&_OS::set_thread_name);
- ClassDB::bind_method(_MD("set_use_vsync","enable"),&_OS::set_use_vsync);
- ClassDB::bind_method(_MD("is_vsync_enabled"),&_OS::is_vsync_enabled);
-
- ClassDB::bind_method(_MD("get_engine_version"),&_OS::get_engine_version);
+ ClassDB::bind_method(D_METHOD("set_use_vsync","enable"),&_OS::set_use_vsync);
+ ClassDB::bind_method(D_METHOD("is_vsync_enabled"),&_OS::is_vsync_enabled);
BIND_CONSTANT( DAY_SUNDAY );
BIND_CONSTANT( DAY_MONDAY );
@@ -1297,6 +1221,11 @@ PoolVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3
return r;
}
+Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2& p_point, const Vector2& p_a,const Vector2& p_b) {
+
+ Vector2 s[2]={p_a,p_b};
+ return Geometry::get_closest_point_to_segment_2d(p_point,s);
+}
Vector3 _Geometry::get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b) {
Vector3 s[2]={p_a,p_b};
@@ -1409,29 +1338,30 @@ int _Geometry::get_uv84_normal_bit(const Vector3& p_vector) {
void _Geometry::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("build_box_planes","extents"),&_Geometry::build_box_planes);
+ ClassDB::bind_method(D_METHOD("build_cylinder_planes","radius","height","sides","axis"),&_Geometry::build_cylinder_planes,DEFVAL(Vector3::AXIS_Z));
+ ClassDB::bind_method(D_METHOD("build_capsule_planes","radius","height","sides","lats","axis"),&_Geometry::build_capsule_planes,DEFVAL(Vector3::AXIS_Z));
+ ClassDB::bind_method(D_METHOD("segment_intersects_circle","segment_from","segment_to","circle_pos","circle_radius"),&_Geometry::segment_intersects_circle);
+ ClassDB::bind_method(D_METHOD("segment_intersects_segment_2d","from_a","to_a","from_b","to_b"),&_Geometry::segment_intersects_segment_2d);
- 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);
+ ClassDB::bind_method(D_METHOD("get_closest_points_between_segments_2d","p1","q1","p2","q2"),&_Geometry::get_closest_points_between_segments_2d);
+ ClassDB::bind_method(D_METHOD("get_closest_points_between_segments","p1","p2","q1","q2"),&_Geometry::get_closest_points_between_segments);
- ClassDB::bind_method(_MD("get_closest_point_to_segment","point","s1","s2"),&_Geometry::get_closest_point_to_segment);
+ ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_2d","point","s1","s2"),&_Geometry::get_closest_point_to_segment_2d);
+ ClassDB::bind_method(D_METHOD("get_closest_point_to_segment","point","s1","s2"),&_Geometry::get_closest_point_to_segment);
- ClassDB::bind_method(_MD("get_uv84_normal_bit","normal"),&_Geometry::get_uv84_normal_bit);
+ ClassDB::bind_method(D_METHOD("get_uv84_normal_bit","normal"),&_Geometry::get_uv84_normal_bit);
- 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);
+ ClassDB::bind_method(D_METHOD("ray_intersects_triangle","from","dir","a","b","c"),&_Geometry::ray_intersects_triangle);
+ ClassDB::bind_method(D_METHOD("segment_intersects_triangle","from","to","a","b","c"),&_Geometry::segment_intersects_triangle);
+ ClassDB::bind_method(D_METHOD("segment_intersects_sphere","from","to","spos","sradius"),&_Geometry::segment_intersects_sphere);
+ ClassDB::bind_method(D_METHOD("segment_intersects_cylinder","from","to","height","radius"),&_Geometry::segment_intersects_cylinder);
+ ClassDB::bind_method(D_METHOD("segment_intersects_convex","from","to","planes"),&_Geometry::segment_intersects_convex);
+ ClassDB::bind_method(D_METHOD("point_is_inside_triangle","point","a","b","c"),&_Geometry::point_is_inside_triangle);
- ClassDB::bind_method(_MD("triangulate_polygon","polygon"),&_Geometry::triangulate_polygon);
+ ClassDB::bind_method(D_METHOD("triangulate_polygon","polygon"),&_Geometry::triangulate_polygon);
- ClassDB::bind_method(_MD("make_atlas","sizes"),&_Geometry::make_atlas);
+ ClassDB::bind_method(D_METHOD("make_atlas","sizes"),&_Geometry::make_atlas);
}
@@ -1803,54 +1733,60 @@ Variant _File::get_var() const {
return v;
}
+uint64_t _File::get_modified_time(const String &p_file) const {
+
+ return FileAccess::get_modified_time(p_file);
+}
+
void _File::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("open_encrypted","path","mode_flags","key"),&_File::open_encrypted);
+ ClassDB::bind_method(D_METHOD("open_encrypted_with_pass","path","mode_flags","pass"),&_File::open_encrypted_pass);
+
+ ClassDB::bind_method(D_METHOD("open","path","flags"),&_File::open);
+ ClassDB::bind_method(D_METHOD("close"),&_File::close);
+ ClassDB::bind_method(D_METHOD("is_open"),&_File::is_open);
+ ClassDB::bind_method(D_METHOD("seek","pos"),&_File::seek);
+ ClassDB::bind_method(D_METHOD("seek_end","pos"),&_File::seek_end,DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_pos"),&_File::get_pos);
+ ClassDB::bind_method(D_METHOD("get_len"),&_File::get_len);
+ ClassDB::bind_method(D_METHOD("eof_reached"),&_File::eof_reached);
+ ClassDB::bind_method(D_METHOD("get_8"),&_File::get_8);
+ ClassDB::bind_method(D_METHOD("get_16"),&_File::get_16);
+ ClassDB::bind_method(D_METHOD("get_32"),&_File::get_32);
+ ClassDB::bind_method(D_METHOD("get_64"),&_File::get_64);
+ ClassDB::bind_method(D_METHOD("get_float"),&_File::get_float);
+ ClassDB::bind_method(D_METHOD("get_double"),&_File::get_double);
+ ClassDB::bind_method(D_METHOD("get_real"),&_File::get_real);
+ ClassDB::bind_method(D_METHOD("get_buffer","len"),&_File::get_buffer);
+ ClassDB::bind_method(D_METHOD("get_line"),&_File::get_line);
+ ClassDB::bind_method(D_METHOD("get_as_text"),&_File::get_as_text);
+ ClassDB::bind_method(D_METHOD("get_md5","path"),&_File::get_md5);
+ ClassDB::bind_method(D_METHOD("get_sha256","path"),&_File::get_sha256);
+ ClassDB::bind_method(D_METHOD("get_endian_swap"),&_File::get_endian_swap);
+ ClassDB::bind_method(D_METHOD("set_endian_swap","enable"),&_File::set_endian_swap);
+ ClassDB::bind_method(D_METHOD("get_error:Error"),&_File::get_error);
+ ClassDB::bind_method(D_METHOD("get_var"),&_File::get_var);
+ ClassDB::bind_method(D_METHOD("get_csv_line","delim"),&_File::get_csv_line,DEFVAL(","));
+
+ ClassDB::bind_method(D_METHOD("store_8","value"),&_File::store_8);
+ ClassDB::bind_method(D_METHOD("store_16","value"),&_File::store_16);
+ ClassDB::bind_method(D_METHOD("store_32","value"),&_File::store_32);
+ ClassDB::bind_method(D_METHOD("store_64","value"),&_File::store_64);
+ ClassDB::bind_method(D_METHOD("store_float","value"),&_File::store_float);
+ ClassDB::bind_method(D_METHOD("store_double","value"),&_File::store_double);
+ ClassDB::bind_method(D_METHOD("store_real","value"),&_File::store_real);
+ ClassDB::bind_method(D_METHOD("store_buffer","buffer"),&_File::store_buffer);
+ ClassDB::bind_method(D_METHOD("store_line","line"),&_File::store_line);
+ ClassDB::bind_method(D_METHOD("store_string","string"),&_File::store_string);
+ ClassDB::bind_method(D_METHOD("store_var","value"),&_File::store_var);
+
+ ClassDB::bind_method(D_METHOD("store_pascal_string","string"),&_File::store_pascal_string);
+ ClassDB::bind_method(D_METHOD("get_pascal_string"),&_File::get_pascal_string);
+
+ ClassDB::bind_method(D_METHOD("file_exists","path"),&_File::file_exists);
+ ClassDB::bind_method(D_METHOD("get_modified_time", "file"),&_File::get_modified_time);
BIND_CONSTANT( READ );
BIND_CONSTANT( WRITE );
@@ -1890,16 +1826,28 @@ Error _Directory::open(const String& p_path) {
return OK;
}
-bool _Directory::list_dir_begin() {
+Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) {
+
+ ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
+
+ _list_skip_navigational = p_skip_navigational;
+ _list_skip_hidden = p_skip_hidden;
- ERR_FAIL_COND_V(!d,false);
return d->list_dir_begin();
}
String _Directory::get_next(){
ERR_FAIL_COND_V(!d,"");
- return d->get_next();
+
+ String next = d->get_next();
+ while (next != ""
+ && ((_list_skip_navigational && (next == "." || next == ".."))
+ || (_list_skip_hidden && d->current_is_hidden()))) {
+
+ next = d->get_next();
+ }
+ return next;
}
bool _Directory::current_is_dir() const{
@@ -1923,6 +1871,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){
@@ -2024,24 +1976,25 @@ Error _Directory::remove(String p_name){
void _Directory::_bind_methods() {
- ClassDB::bind_method(_MD("open:Error","path"),&_Directory::open);
- ClassDB::bind_method(_MD("list_dir_begin"),&_Directory::list_dir_begin);
- ClassDB::bind_method(_MD("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("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);
+ ClassDB::bind_method(D_METHOD("open:Error","path"),&_Directory::open);
+ ClassDB::bind_method(D_METHOD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_next"),&_Directory::get_next);
+ ClassDB::bind_method(D_METHOD("current_is_dir"),&_Directory::current_is_dir);
+ ClassDB::bind_method(D_METHOD("list_dir_end"),&_Directory::list_dir_end);
+ ClassDB::bind_method(D_METHOD("get_drive_count"),&_Directory::get_drive_count);
+ ClassDB::bind_method(D_METHOD("get_drive","idx"),&_Directory::get_drive);
+ ClassDB::bind_method(D_METHOD("get_current_drive"),&_Directory::get_current_drive);
+ ClassDB::bind_method(D_METHOD("change_dir:Error","todir"),&_Directory::change_dir);
+ ClassDB::bind_method(D_METHOD("get_current_dir"),&_Directory::get_current_dir);
+ ClassDB::bind_method(D_METHOD("make_dir:Error","path"),&_Directory::make_dir);
+ ClassDB::bind_method(D_METHOD("make_dir_recursive:Error","path"),&_Directory::make_dir_recursive);
+ ClassDB::bind_method(D_METHOD("file_exists","path"),&_Directory::file_exists);
+ ClassDB::bind_method(D_METHOD("dir_exists","path"),&_Directory::dir_exists);
+ //ClassDB::bind_method(D_METHOD("get_modified_time","file"),&_Directory::get_modified_time);
+ ClassDB::bind_method(D_METHOD("get_space_left"),&_Directory::get_space_left);
+ ClassDB::bind_method(D_METHOD("copy:Error","from","to"),&_Directory::copy);
+ ClassDB::bind_method(D_METHOD("rename:Error","from","to"),&_Directory::rename);
+ ClassDB::bind_method(D_METHOD("remove:Error","path"),&_Directory::remove);
}
@@ -2181,14 +2134,14 @@ String _Marshalls::base64_to_utf8(const String& p_str) {
void _Marshalls::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("variant_to_base64:String","variant"),&_Marshalls::variant_to_base64);
+ ClassDB::bind_method(D_METHOD("base64_to_variant:Variant","base64_str"),&_Marshalls::base64_to_variant);
- 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);
+ ClassDB::bind_method(D_METHOD("raw_to_base64:String","array"),&_Marshalls::raw_to_base64);
+ ClassDB::bind_method(D_METHOD("base64_to_raw:RawArray","base64_str"),&_Marshalls::base64_to_raw);
- 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);
+ ClassDB::bind_method(D_METHOD("utf8_to_base64:String","utf8_str"),&_Marshalls::utf8_to_base64);
+ ClassDB::bind_method(D_METHOD("base64_to_utf8:String","base64_str"),&_Marshalls::base64_to_utf8);
};
@@ -2212,8 +2165,8 @@ Error _Semaphore::post() {
void _Semaphore::_bind_methods() {
- ClassDB::bind_method(_MD("wait:Error"),&_Semaphore::wait);
- ClassDB::bind_method(_MD("post:Error"),&_Semaphore::post);
+ ClassDB::bind_method(D_METHOD("wait:Error"),&_Semaphore::wait);
+ ClassDB::bind_method(D_METHOD("post:Error"),&_Semaphore::post);
}
@@ -2249,9 +2202,9 @@ void _Mutex::unlock(){
void _Mutex::_bind_methods() {
- ClassDB::bind_method(_MD("lock"),&_Mutex::lock);
- ClassDB::bind_method(_MD("try_lock:Error"),&_Mutex::try_lock);
- ClassDB::bind_method(_MD("unlock"),&_Mutex::unlock);
+ ClassDB::bind_method(D_METHOD("lock"),&_Mutex::lock);
+ ClassDB::bind_method(D_METHOD("try_lock:Error"),&_Mutex::try_lock);
+ ClassDB::bind_method(D_METHOD("unlock"),&_Mutex::unlock);
}
@@ -2371,10 +2324,10 @@ Variant _Thread::wait_to_finish() {
void _Thread::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("start:Error","instance","method","userdata","priority"),&_Thread::start,DEFVAL(Variant()),DEFVAL(PRIORITY_NORMAL));
+ ClassDB::bind_method(D_METHOD("get_id"),&_Thread::get_id);
+ ClassDB::bind_method(D_METHOD("is_active"),&_Thread::is_active);
+ ClassDB::bind_method(D_METHOD("wait_to_finish:Variant"),&_Thread::wait_to_finish);
BIND_CONSTANT( PRIORITY_LOW );
BIND_CONSTANT( PRIORITY_NORMAL );
@@ -2559,31 +2512,31 @@ bool _ClassDB::is_class_enabled(StringName p_class) const {
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(D_METHOD("get_class_list"),&_ClassDB::get_class_list);
+ ClassDB::bind_method(D_METHOD("get_inheriters_from_class","class"),&_ClassDB::get_inheriters_from_class);
+ ClassDB::bind_method(D_METHOD("get_parent_class","class"),&_ClassDB::get_parent_class);
+ ClassDB::bind_method(D_METHOD("class_exists","class"),&_ClassDB::class_exists);
+ ClassDB::bind_method(D_METHOD("is_parent_class","class","inherits"),&_ClassDB::is_parent_class);
+ ClassDB::bind_method(D_METHOD("can_instance","class"),&_ClassDB::can_instance);
+ ClassDB::bind_method(D_METHOD("instance:Variant","class"),&_ClassDB::instance);
- ClassDB::bind_method(_MD("has_signal","class","signal"),&_ClassDB::has_signal);
- ClassDB::bind_method(_MD("get_signal","class","signal"),&_ClassDB::get_signal);
- ClassDB::bind_method(_MD("get_signal_list","class","no_inheritance"),&_ClassDB::get_signal_list,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("class_has_signal","class","signal"),&_ClassDB::has_signal);
+ ClassDB::bind_method(D_METHOD("class_get_signal","class","signal"),&_ClassDB::get_signal);
+ ClassDB::bind_method(D_METHOD("class_get_signal_list","class","no_inheritance"),&_ClassDB::get_signal_list,DEFVAL(false));
- ClassDB::bind_method(_MD("get_property_list","class","no_inheritance"),&_ClassDB::get_property_list,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("class_get_property_list","class","no_inheritance"),&_ClassDB::get_property_list,DEFVAL(false));
- ClassDB::bind_method(_MD("has_method","class","method","no_inheritance"),&_ClassDB::has_method,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("class_has_method","class","method","no_inheritance"),&_ClassDB::has_method,DEFVAL(false));
- ClassDB::bind_method(_MD("get_method_list","class","no_inheritance"),&_ClassDB::get_method_list,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("class_get_method_list","class","no_inheritance"),&_ClassDB::get_method_list,DEFVAL(false));
- ClassDB::bind_method(_MD("get_integer_constant_list","class","no_inheritance"),&_ClassDB::get_integer_constant_list,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("class_get_integer_constant_list","class","no_inheritance"),&_ClassDB::get_integer_constant_list,DEFVAL(false));
- ClassDB::bind_method(_MD("has_integer_constant","class","name"),&_ClassDB::has_integer_constant);
- ClassDB::bind_method(_MD("get_integer_constant","class","name"),&_ClassDB::get_integer_constant);
+ ClassDB::bind_method(D_METHOD("class_has_integer_constant","class","name"),&_ClassDB::has_integer_constant);
+ ClassDB::bind_method(D_METHOD("class_get_integer_constant","class","name"),&_ClassDB::get_integer_constant);
- ClassDB::bind_method(_MD("get_category","class"),&_ClassDB::get_category);
- ClassDB::bind_method(_MD("is_class_enabled","class"),&_ClassDB::is_class_enabled);
+ ClassDB::bind_method(D_METHOD("class_get_category","class"),&_ClassDB::get_category);
+ ClassDB::bind_method(D_METHOD("is_class_enabled","class"),&_ClassDB::is_class_enabled);
}
@@ -2596,3 +2549,88 @@ _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(D_METHOD("set_iterations_per_second","iterations_per_second"),&_Engine::set_iterations_per_second);
+ ClassDB::bind_method(D_METHOD("get_iterations_per_second"),&_Engine::get_iterations_per_second);
+ ClassDB::bind_method(D_METHOD("set_target_fps","target_fps"),&_Engine::set_target_fps);
+ ClassDB::bind_method(D_METHOD("get_target_fps"),&_Engine::get_target_fps);
+
+ ClassDB::bind_method(D_METHOD("set_time_scale","time_scale"),&_Engine::set_time_scale);
+ ClassDB::bind_method(D_METHOD("get_time_scale"),&_Engine::get_time_scale);
+
+ ClassDB::bind_method(D_METHOD("get_custom_level"),&_Engine::get_custom_level);
+
+ ClassDB::bind_method(D_METHOD("get_frames_drawn"),&_Engine::get_frames_drawn);
+ ClassDB::bind_method(D_METHOD("get_frames_per_second"),&_Engine::get_frames_per_second);
+
+ ClassDB::bind_method(D_METHOD("get_main_loop:MainLoop"),&_Engine::get_main_loop);
+
+ ClassDB::bind_method(D_METHOD("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 d491483d82..4241912ddd 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -54,7 +54,6 @@ public:
void set_abort_on_missing_resources(bool p_abort);
PoolStringArray get_dependencies(const String& p_path);
bool has(const String& p_path);
- Ref<ResourceImportMetadata> load_import_metadata(const String& p_path);
_ResourceLoader();
};
@@ -169,12 +168,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 +189,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);
@@ -271,8 +260,6 @@ public:
bool can_draw() const;
- int get_frames_drawn();
-
bool is_stdout_verbose() const;
int get_processor_count() const;
@@ -313,8 +300,6 @@ 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;
@@ -323,8 +308,6 @@ public:
void set_use_vsync(bool p_enable);
bool is_vsync_enabled() const;
- Dictionary get_engine_version() const;
-
static _OS *get_singleton() { return singleton; }
_OS();
@@ -351,6 +334,7 @@ public:
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);
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);
+ Vector2 get_closest_point_to_segment_2d(const Vector2& p_point, const Vector2& p_a,const Vector2& p_b);
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);
@@ -456,6 +440,8 @@ public:
bool file_exists(const String& p_name) const; ///< return true if a file exists
+ uint64_t get_modified_time(const String& p_file) const;
+
_File();
virtual ~_File();
@@ -472,7 +458,7 @@ public:
Error open(const String& p_path);
- bool list_dir_begin(); ///< This starts dir listing
+ Error list_dir_begin(bool p_skip_internal = false, bool p_skip_hidden = false); ///< This starts dir listing
String get_next();
bool current_is_dir() const;
@@ -480,6 +466,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
@@ -500,6 +487,9 @@ public:
_Directory();
virtual ~_Directory();
+private:
+ bool _list_skip_navigational;
+ bool _list_skip_hidden;
};
class _Marshalls : public Reference {
@@ -632,4 +622,39 @@ public:
~_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/object_type_db.cpp b/core/class_db.cpp
index f3bb37421f..4bdae45fb9 100644
--- a/core/object_type_db.cpp
+++ b/core/class_db.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* object_type_db.cpp */
+/* class_db.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -26,12 +26,14 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "object_type_db.h"
+#include "class_db.h"
+
#include "os/mutex.h"
#ifdef NO_THREADS
#define OBJTYPE_RLOCK
+#define OBJTYPE_WLOCK
#else
@@ -45,14 +47,14 @@
ParamDef::ParamDef(const Variant& p_variant) { used=true; val=p_variant; }
-MethodDefinition _MD(const char* p_name) {
+MethodDefinition D_METHOD(const char* p_name) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
return md;
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -60,7 +62,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1) {
return md;
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -70,7 +72,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2) {
return md;
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -81,7 +83,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
return md;
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -93,7 +95,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
return md;
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -107,7 +109,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -121,7 +123,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
return md;
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -136,7 +138,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
return md;
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -152,7 +154,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
return md;
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8,const char *p_arg9) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8,const char *p_arg9) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -169,7 +171,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
return md;
}
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8,const char *p_arg9,const char *p_arg10) {
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8,const char *p_arg9,const char *p_arg10) {
MethodDefinition md;
md.name=StaticCString::create(p_name);
@@ -293,7 +295,7 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
OBJTYPE_RLOCK;
#ifdef DEBUG_METHODS_ENABLED
- uint64_t hash = hash_djb2_one_64(HashMapHahserDefault::hash(VERSION_FULL_NAME));
+ uint64_t hash = hash_djb2_one_64(HashMapHasherDefault::hash(VERSION_FULL_NAME));
List<StringName> names;
@@ -775,11 +777,15 @@ void ClassDB::add_property(StringName p_class,const PropertyInfo& p_pinfo, const
+#ifndef NO_THREADS
lock->read_lock();
+#endif
ClassInfo *type=classes.getptr(p_class);
+#ifndef NO_THREADS
lock->read_unlock();
+#endif
ERR_FAIL_COND(!type);
@@ -897,7 +903,7 @@ bool ClassDB::set_property(Object* p_object,const StringName& p_property, const
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 {
@@ -1111,6 +1117,15 @@ MethodBind* ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const
String instance_type=p_bind->get_instance_class();
+#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);
@@ -1241,7 +1256,7 @@ void ClassDB::get_extensions_for_type(const StringName& p_class,List<String> *p_
while((K=resource_base_extensions.next(K))) {
StringName cmp = resource_base_extensions[*K];
- if (is_parent_class(cmp,p_class))
+ if (is_parent_class(p_class,cmp))
p_extensions->push_back(*K);
}
}
diff --git a/core/object_type_db.h b/core/class_db.h
index f745e3d5fd..6e02d0bf46 100644
--- a/core/object_type_db.h
+++ b/core/class_db.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* object_type_db.h */
+/* class_db.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -26,12 +26,13 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef OBJECT_TYPE_DB_H
-#define OBJECT_TYPE_DB_H
+#ifndef CLASS_DB_H
+#define CLASS_DB_H
#include "object.h"
#include "method_bind.h"
#include "print_string.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -80,17 +81,17 @@ struct MethodDefinition {
-MethodDefinition _MD(const char* p_name);
-MethodDefinition _MD(const char* p_name,const char *p_arg1);
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2);
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3);
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4);
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5);
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6);
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7);
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8);
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8,const char *p_arg9);
-MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8,const char *p_arg9,const char *p_arg10);
+MethodDefinition D_METHOD(const char* p_name);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8,const char *p_arg9);
+MethodDefinition D_METHOD(const char* p_name,const char *p_arg1,const char *p_arg2,const char *p_arg3,const char *p_arg4,const char *p_arg5,const char *p_arg6,const char *p_arg7,const char *p_arg8,const char *p_arg9,const char *p_arg10);
#else
@@ -98,11 +99,13 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
#ifdef NO_VARIADIC_MACROS
-static _FORCE_INLINE_ const char* _MD(const char* m_name, ...) { return m_name; }
+static _FORCE_INLINE_ const char* D_METHOD(const char* m_name, ...) { return m_name; }
#else
-#define _MD(m_c, ...) m_c
+// When DEBUG_METHODS_ENABLED is set this will let the engine know
+// the argument names for easier debugging.
+#define D_METHOD(m_c, ...) m_c
#endif
@@ -537,4 +540,4 @@ public:
-#endif
+#endif // CLASS_DB_H
diff --git a/core/color.cpp b/core/color.cpp
index 89accbb6d2..80a98da252 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "color.h"
+
#include "math_funcs.h"
#include "print_string.h"
#include "map.h"
diff --git a/core/color_names.inc b/core/color_names.inc
index 7b674bb289..b05684acc6 100644
--- a/core/color_names.inc
+++ b/core/color_names.inc
@@ -1,4 +1,6 @@
// 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
+#include "map.h"
+
static Map<String, Color> _named_colors;
static void _populate_named_colors() {
if(!_named_colors.empty()) return;
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index 9b1c052eb9..6d50ed8d9a 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "command_queue_mt.h"
+
#include "os/os.h"
void CommandQueueMT::lock() {
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index 779bbe1b58..3975df7658 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -179,7 +179,7 @@ class CommandQueueMT {
R* ret;
SyncSemaphore *sync;
- virtual void call() { *ret = (instance->*method)(); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { *ret = (instance->*method)(); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class R>
@@ -204,7 +204,7 @@ class CommandQueueMT {
R* ret;
SyncSemaphore *sync;
- virtual void call() { *ret = (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { *ret = (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class R>
@@ -218,7 +218,7 @@ class CommandQueueMT {
R* ret;
SyncSemaphore *sync;
- virtual void call() { *ret = (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { *ret = (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4,class R>
@@ -233,7 +233,7 @@ class CommandQueueMT {
R* ret;
SyncSemaphore *sync;
- virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class R>
@@ -249,7 +249,7 @@ class CommandQueueMT {
R* ret;
SyncSemaphore *sync;
- virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class R>
@@ -266,7 +266,7 @@ class CommandQueueMT {
R* ret;
SyncSemaphore *sync;
- virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class R>
@@ -284,7 +284,7 @@ class CommandQueueMT {
R* ret;
SyncSemaphore *sync;
- virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class P8,class R>
@@ -303,7 +303,7 @@ class CommandQueueMT {
R* ret;
SyncSemaphore *sync;
- virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; }
};
/** commands that don't return but sync */
@@ -318,7 +318,7 @@ class CommandQueueMT {
SyncSemaphore *sync;
- virtual void call() { (instance->*method)(); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { (instance->*method)(); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1>
@@ -330,7 +330,7 @@ class CommandQueueMT {
SyncSemaphore *sync;
- virtual void call() { (instance->*method)(p1); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { (instance->*method)(p1); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2>
@@ -343,7 +343,7 @@ class CommandQueueMT {
SyncSemaphore *sync;
- virtual void call() { (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3>
@@ -357,7 +357,7 @@ class CommandQueueMT {
SyncSemaphore *sync;
- virtual void call() { (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4>
@@ -372,7 +372,7 @@ class CommandQueueMT {
SyncSemaphore *sync;
- virtual void call() { (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5>
@@ -388,7 +388,7 @@ class CommandQueueMT {
SyncSemaphore *sync;
- virtual void call() { (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6>
@@ -405,7 +405,7 @@ class CommandQueueMT {
SyncSemaphore *sync;
- virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7>
@@ -423,7 +423,7 @@ class CommandQueueMT {
SyncSemaphore *sync;
- virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; }
};
template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class P8>
@@ -442,7 +442,7 @@ class CommandQueueMT {
SyncSemaphore *sync;
- virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; ; }
+ virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; }
};
/***** BASE *******/
diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp
index 71f810422a..570cf114f7 100644
--- a/core/compressed_translation.cpp
+++ b/core/compressed_translation.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "compressed_translation.h"
+
#include "pair.h"
#include <string.h>
@@ -467,7 +468,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 +490,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 +498,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 +509,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;
}
@@ -526,7 +527,7 @@ void PHashTranslation::_get_property_list( List<PropertyInfo> *p_list) const{
}
void PHashTranslation::_bind_methods() {
- ClassDB::bind_method(_MD("generate","from:Translation"),&PHashTranslation::generate);
+ ClassDB::bind_method(D_METHOD("generate","from:Translation"),&PHashTranslation::generate);
}
PHashTranslation::PHashTranslation()
diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp
index a173f98602..f8c6f47797 100644
--- a/core/core_string_names.cpp
+++ b/core/core_string_names.cpp
@@ -35,7 +35,7 @@ CoreStringNames::CoreStringNames() {
_free=StaticCString::create("free");
changed=StaticCString::create("changed");
_meta=StaticCString::create("__meta__");
- _script=StaticCString::create("script/script");
+ _script=StaticCString::create("script");
script_changed=StaticCString::create("script_changed");
___pdcdata=StaticCString::create("___pdcdata");
__getvar=StaticCString::create("__getvar");
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index 3b4d3b65d0..1176b9be3b 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "dictionary.h"
+
#include "safe_refcount.h"
#include "variant.h"
diff --git a/core/dvector.h b/core/dvector.h
index cac9e8ef85..456be41289 100644
--- a/core/dvector.h
+++ b/core/dvector.h
@@ -34,6 +34,7 @@
#include "pool_allocator.h"
#include "safe_refcount.h"
#include "os/rw_lock.h"
+#include "ustring.h"
struct MemoryPool {
@@ -89,7 +90,7 @@ class PoolVector {
if (!alloc)
return;
- ERR_FAIL_COND(alloc->lock>0);
+// ERR_FAIL_COND(alloc->lock>0); should not be illegal to lock this for copy on write, as it's a copy on write after all
if (alloc->refcount.get()==1)
return; //nothing to do
@@ -466,6 +467,16 @@ public:
return OK;
}
+ String join(String delimiter) {
+ String rs = "";
+ int s = size();
+ Read r = read();
+ for(int i=0;i<s;i++) {
+ rs += r[i] + delimiter;
+ }
+ rs.erase( rs.length()-delimiter.length(), delimiter.length());
+ return rs;
+ }
bool is_locked() const { return alloc && alloc->lock>0; }
diff --git a/core/engine.cpp b/core/engine.cpp
new file mode 100644
index 0000000000..b017e77275
--- /dev/null
+++ b/core/engine.cpp
@@ -0,0 +1,119 @@
+/*************************************************************************/
+/* engine.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 "engine.h"
+
+#include "version.h"
+
+void Engine::set_iterations_per_second(int p_ips) {
+
+ ips=p_ips;
+}
+int Engine::get_iterations_per_second() const {
+
+ return ips;
+}
+
+void Engine::set_target_fps(int p_fps) {
+ _target_fps=p_fps>0? p_fps : 0;
+}
+
+float Engine::get_target_fps() const {
+ return _target_fps;
+}
+
+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 {
+
+ 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/engine.h b/core/engine.h
new file mode 100644
index 0000000000..9af4219a68
--- /dev/null
+++ b/core/engine.h
@@ -0,0 +1,88 @@
+/*************************************************************************/
+/* engine.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 ENGINE_H
+#define ENGINE_H
+
+#include "ustring.h"
+#include "list.h"
+#include "vector.h"
+#include "os/main_loop.h"
+
+class Engine {
+
+friend class Main;
+
+ String _custom_level;
+ uint64_t frames_drawn;
+ uint32_t _frame_delay;
+
+ int ips;
+ float _fps;
+ int _target_fps;
+ float _time_scale;
+ bool _pixel_snap;
+ uint64_t _fixed_frames;
+ uint64_t _idle_frames;
+ bool _in_fixed;
+
+ static Engine *singleton;
+public:
+
+ static Engine *get_singleton();
+
+ 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; }
+
+ 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; }
+
+ 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 c3cd9b399d..f4063a9285 100644
--- a/core/error_list.h
+++ b/core/error_list.h
@@ -58,7 +58,7 @@ enum Error {
ERR_FILE_EOF,
ERR_CANT_OPEN, ///< Can't open a resource/socket/file
ERR_CANT_CREATE, // (20)
- ERROR_QUERY_FAILED,
+ ERR_QUERY_FAILED,
ERR_ALREADY_IN_USE,
ERR_LOCKED, ///< resource is locked
ERR_TIMEOUT,
diff --git a/core/error_macros.cpp b/core/error_macros.cpp
index 53a361fa3a..e963f6122b 100644
--- a/core/error_macros.cpp
+++ b/core/error_macros.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "error_macros.h"
+
#include "os/os.h"
diff --git a/core/func_ref.cpp b/core/func_ref.cpp
index 1e8c229810..2233615e25 100644
--- a/core/func_ref.cpp
+++ b/core/func_ref.cpp
@@ -65,8 +65,8 @@ void FuncRef::_bind_methods() {
}
- ClassDB::bind_method(_MD("set_instance","instance"),&FuncRef::set_instance);
- ClassDB::bind_method(_MD("set_function","name"),&FuncRef::set_function);
+ ClassDB::bind_method(D_METHOD("set_instance","instance"),&FuncRef::set_instance);
+ ClassDB::bind_method(D_METHOD("set_function","name"),&FuncRef::set_function);
}
diff --git a/core/globals.cpp b/core/global_config.cpp
index 28fabac302..b76991c04e 100644
--- a/core/globals.cpp
+++ b/core/global_config.cpp
@@ -26,10 +26,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "globals.h"
+#include "global_config.h"
+
#include "os/dir_access.h"
#include "os/file_access.h"
-
#include "os/keyboard.h"
#include "io/marshalls.h"
#include "bind/core_bind.h"
@@ -37,6 +37,9 @@
#include "io/file_access_pack.h"
#include "io/file_access_network.h"
#include "variant_parser.h"
+
+#define FORMAT_VERSION 3
+
GlobalConfig *GlobalConfig::singleton=NULL;
GlobalConfig *GlobalConfig::get_singleton() {
@@ -122,6 +125,7 @@ bool GlobalConfig::_set(const StringName& p_name, const Variant& p_value) {
_THREAD_SAFE_METHOD_
+
if (p_value.get_type()==Variant::NIL)
props.erase(p_name);
else {
@@ -166,8 +170,10 @@ bool GlobalConfig::_get(const StringName& p_name,Variant &r_ret) const {
_THREAD_SAFE_METHOD_
- if (!props.has(p_name))
+ if (!props.has(p_name)) {
+ print_line("WARNING: not found: "+String(p_name));
return false;
+ }
r_ret=props[p_name].variant;
return true;
@@ -241,76 +247,71 @@ bool GlobalConfig::_load_resource_pack(const String& p_pack) {
Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
- //an absolute mess of a function, must be cleaned up and reorganized somehow at some point
-
- //_load_settings(p_path+"/override.cfg");
+ //If looking for files in network, just use network!
- if (p_main_pack!="") {
-
- bool ok = _load_resource_pack(p_main_pack);
- ERR_FAIL_COND_V(!ok,ERR_CANT_OPEN);
+ if (FileAccessNetworkClient::get_singleton()) {
- if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {
+ if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
_load_settings("res://override.cfg");
}
return OK;
-
}
- if (OS::get_singleton()->get_executable_path()!="") {
+ String exec_path = OS::get_singleton()->get_executable_path();
+
+ //Attempt with a passed main pack first
- if (_load_resource_pack(OS::get_singleton()->get_executable_path())) {
+ if (p_main_pack!="") {
- if (p_path!="") {
- resource_path=p_path;
- } else {
- DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- resource_path=d->get_current_dir();
- memdelete(d);
+ bool ok = _load_resource_pack(p_main_pack);
+ ERR_FAIL_COND_V(!ok,ERR_CANT_OPEN);
- }
- if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {
+ if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
+ //load override from location of the main pack
+ _load_settings(p_main_pack.get_base_dir().plus_file("override.cfg"));
- _load_settings("res://override.cfg");
+ }
- }
+ return OK;
+ }
+ //Attempt with execname.pck
+ if (exec_path!="") {
- return OK;
- }
- }
+ if (_load_resource_pack(exec_path.get_basename()+".pck")) {
+ if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
+ //load override from location of executable
+ _load_settings(exec_path.get_base_dir().plus_file("override.cfg"));
- if (FileAccessNetworkClient::get_singleton()) {
+ }
- if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {
- _load_settings("res://override.cfg");
+ return OK;
}
- return OK;
}
+
+ //Try to use the filesystem for files, according to OS. (only Android -when reading from pck- and iOS use this)
if (OS::get_singleton()->get_resource_dir()!="") {
- //OS will call Globals->get_resource_path which will be empty if not overriden!
+ //OS will call Globals->get_resource_path which will be empty if not overriden!
//if the OS would rather use somewhere else, then it will not be empty.
+
resource_path=OS::get_singleton()->get_resource_dir().replace("\\","/");
if (resource_path.length() && resource_path[ resource_path.length()-1]=='/')
resource_path=resource_path.substr(0,resource_path.length()-1); // chop end
- print_line("has res dir: "+resource_path);
- if (!_load_resource_pack("res://data.pck"))
- _load_resource_pack("res://data.zip");
- // make sure this is load from the resource path
- print_line("exists engine cfg? "+itos(FileAccess::exists("/engine.cfg")));
- if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {
- print_line("loaded engine.cfg");
+ // data.pck and data.zip are deprecated and no longer supported, apologies.
+ // make sure this is loaded from the resource path
+
+ if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) {
_load_settings("res://override.cfg");
}
@@ -318,67 +319,41 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) {
return OK;
}
- DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- if (!d) {
-
- resource_path = p_path;
-
- } else {
+ //Nothing was found, try to find a godot.cfg somewhere!
- d->change_dir(p_path);
-
- String candidate = d->get_current_dir();
- String current_dir = d->get_current_dir();
- String exec_name = OS::get_singleton()->get_executable_path().get_file().basename();
- bool found = false;
- bool first_time=true;
-
- while(true) {
- //try to load settings in ascending through dirs shape!
-
- //tries to open pack, but only first time
- if (first_time && (_load_resource_pack(current_dir+"/"+exec_name+".pck") || _load_resource_pack(current_dir+"/"+exec_name+".zip") )) {
- if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {
-
- _load_settings("res://override.cfg");
- found=true;
-
-
- }
- break;
- } else if (first_time && (_load_resource_pack(current_dir+"/data.pck") || _load_resource_pack(current_dir+"/data.zip") )) {
- if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) {
+ DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ ERR_FAIL_COND_V(!d,ERR_CANT_CREATE);
- _load_settings("res://override.cfg");
- found=true;
+ d->change_dir(p_path);
+ String candidate = d->get_current_dir();
+ String current_dir = d->get_current_dir();
+ bool found = false;
- }
- break;
- } else if (_load_settings(current_dir+"/engine.cfg")==OK || _load_settings_binary(current_dir+"/engine.cfb")==OK) {
+ while(true) {
+ //try to load settings in ascending through dirs shape!
- _load_settings(current_dir+"/override.cfg");
- candidate=current_dir;
- found=true;
- break;
- }
+ if (_load_settings(current_dir+"/godot.cfg")==OK || _load_settings_binary(current_dir+"/godot.cfb")==OK) {
- d->change_dir("..");
- if (d->get_current_dir()==current_dir)
- break; //not doing anything useful
- current_dir=d->get_current_dir();
- first_time=false;
+ _load_settings(current_dir+"/override.cfg");
+ candidate=current_dir;
+ found=true;
+ break;
}
+ d->change_dir("..");
+ if (d->get_current_dir()==current_dir)
+ break; //not doing anything useful
+ current_dir=d->get_current_dir();
+ }
- resource_path=candidate;
- resource_path = resource_path.replace("\\","/"); // windows path to unix path just in case
- memdelete(d);
- if (!found)
- return ERR_FILE_NOT_FOUND;
- };
+ resource_path=candidate;
+ resource_path = resource_path.replace("\\","/"); // windows path to unix path just in case
+ memdelete(d);
+ if (!found)
+ return ERR_FILE_NOT_FOUND;
if (resource_path.length() && resource_path[ resource_path.length()-1]=='/')
resource_path=resource_path.substr(0,resource_path.length()-1); // chop end
@@ -413,7 +388,7 @@ Error GlobalConfig::_load_settings_binary(const String p_path) {
if (hdr[0]!='E'|| hdr[1]!='C' || hdr[2]!='F' || hdr[3]!='G') {
memdelete(f);
- ERR_EXPLAIN("Corrupted header in binary engine.cfb (not ECFG)");
+ ERR_EXPLAIN("Corrupted header in binary godot.cfb (not ECFG)");
ERR_FAIL_V(ERR_FILE_CORRUPT;)
}
@@ -488,6 +463,14 @@ Error GlobalConfig::_load_settings(const String p_path) {
}
if (assign!=String()) {
+ if (section==String() && assign=="config_version") {
+ int config_version = value;
+ if (config_version > FORMAT_VERSION) {
+ memdelete(f);
+ ERR_FAIL_COND_V(config_version > FORMAT_VERSION,ERR_FILE_CANT_OPEN);
+ }
+
+ }
set(section+"/"+assign,value);
} else if (next_tag.name!=String()) {
section=next_tag.name;
@@ -523,7 +506,7 @@ void GlobalConfig::clear(const String& p_name) {
Error GlobalConfig::save() {
- return save_custom(get_resource_path()+"/engine.cfg");
+ return save_custom(get_resource_path()+"/godot.cfg");
}
Error GlobalConfig::_save_settings_binary(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom) {
@@ -533,7 +516,7 @@ Error GlobalConfig::_save_settings_binary(const String& p_file,const Map<String,
FileAccess *file = FileAccess::open(p_file,FileAccess::WRITE,&err);
if (err!=OK) {
- ERR_EXPLAIN("Coudln't save engine.cfb at "+p_file);
+ ERR_EXPLAIN("Coudln't save godot.cfb at "+p_file);
ERR_FAIL_COND_V(err,err)
}
@@ -601,10 +584,13 @@ Error GlobalConfig::_save_settings_text(const String& p_file,const Map<String,Li
FileAccess *file = FileAccess::open(p_file,FileAccess::WRITE,&err);
if (err) {
- ERR_EXPLAIN("Coudln't save engine.cfg - "+p_file);
+ ERR_EXPLAIN("Coudln't save godot.cfg - "+p_file);
ERR_FAIL_COND_V(err,err)
}
+ file->store_string("config_version="+itos(FORMAT_VERSION)+"\n");
+
+
for(Map<String,List<String> >::Element *E=props.front();E;E=E->next()) {
if (E!=props.front())
@@ -731,7 +717,7 @@ Error GlobalConfig::save_custom(const String& p_path,const CustomMap& p_custom,c
Error err = file->open(dst_file,FileAccess::WRITE);
if (err) {
memdelete(file);
- ERR_EXPLAIN("Coudln't save engine.cfg");
+ ERR_EXPLAIN("Coudln't save godot.cfg");
ERR_FAIL_COND_V(err,err)
}
@@ -883,22 +869,22 @@ Variant GlobalConfig::property_get_revert(const String& p_name) {
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);
+ ClassDB::bind_method(D_METHOD("has","name"),&GlobalConfig::has);
+ ClassDB::bind_method(D_METHOD("set_order","name","pos"),&GlobalConfig::set_order);
+ ClassDB::bind_method(D_METHOD("get_order","name"),&GlobalConfig::get_order);
+ ClassDB::bind_method(D_METHOD("set_initial_value","name","value"),&GlobalConfig::set_initial_value);
+ ClassDB::bind_method(D_METHOD("add_property_info", "hint"),&GlobalConfig::_add_property_info_bind);
+ ClassDB::bind_method(D_METHOD("clear","name"),&GlobalConfig::clear);
+ ClassDB::bind_method(D_METHOD("localize_path","path"),&GlobalConfig::localize_path);
+ ClassDB::bind_method(D_METHOD("globalize_path","path"),&GlobalConfig::globalize_path);
+ ClassDB::bind_method(D_METHOD("save"),&GlobalConfig::save);
+ ClassDB::bind_method(D_METHOD("has_singleton","name"),&GlobalConfig::has_singleton);
+ ClassDB::bind_method(D_METHOD("get_singleton","name"),&GlobalConfig::get_singleton_object);
+ ClassDB::bind_method(D_METHOD("load_resource_pack","pack"),&GlobalConfig::_load_resource_pack);
+ ClassDB::bind_method(D_METHOD("property_can_revert","name"),&GlobalConfig::property_can_revert);
+ ClassDB::bind_method(D_METHOD("property_get_revert","name"),&GlobalConfig::property_get_revert);
+
+ ClassDB::bind_method(D_METHOD("save_custom","file"),&GlobalConfig::_save_custom_bnd);
}
@@ -922,6 +908,7 @@ GlobalConfig::GlobalConfig() {
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");
GLOBAL_DEF("application/disable_stdout",false);
+ GLOBAL_DEF("application/disable_stderr",false);
GLOBAL_DEF("application/use_shared_user_dir",true);
@@ -1011,7 +998,7 @@ GlobalConfig::GlobalConfig() {
GLOBAL_DEF("input/ui_page_down",va);
input_presets.push_back("input/ui_page_down");
-// GLOBAL_DEF("display/handheld/orientation", "landscape");
+ //GLOBAL_DEF("display/handheld/orientation", "landscape");
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");
diff --git a/core/globals.h b/core/global_config.h
index faf077f2a5..471f1ff885 100644
--- a/core/globals.h
+++ b/core/global_config.h
@@ -26,8 +26,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef GLOBALS_H
-#define GLOBALS_H
+#ifndef GLOBAL_CONFIG_H
+#define GLOBAL_CONFIG_H
#include "object.h"
#include "set.h"
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index 936facdd23..be811ccbd2 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "global_constants.h"
+
#include "variant.h"
#include "os/keyboard.h"
#include "object.h"
@@ -433,7 +434,7 @@ static _GlobalConstant _global_constants[]={
BIND_GLOBAL_CONSTANT( ERR_CANT_OPEN ), ///< Can't open a resource/socket/file
BIND_GLOBAL_CONSTANT( ERR_CANT_CREATE ),
BIND_GLOBAL_CONSTANT( ERR_PARSE_ERROR ),
- BIND_GLOBAL_CONSTANT( ERROR_QUERY_FAILED ),
+ BIND_GLOBAL_CONSTANT( ERR_QUERY_FAILED ),
BIND_GLOBAL_CONSTANT( ERR_ALREADY_IN_USE ),
BIND_GLOBAL_CONSTANT( ERR_LOCKED ), ///< resource is locked
BIND_GLOBAL_CONSTANT( ERR_TIMEOUT ),
diff --git a/core/hash_map.h b/core/hash_map.h
index fba12b55ec..515fc6c4fe 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -30,38 +30,43 @@
#define HASH_MAP_H
#include "hashfuncs.h"
+#include "math_funcs.h"
#include "error_macros.h"
#include "ustring.h"
#include "os/memory.h"
#include "list.h"
-
-class HashMapHahserDefault {
-public:
-
+struct HashMapHasherDefault {
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
- static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) {
- uint64_t v=p_int;
- v = (~v) + (v << 18); // v = (v << 18) - v - 1;
- v = v ^ (v >> 31);
- v = v * 21; // v = (v + (v << 2)) + (v << 4);
- v = v ^ (v >> 11);
- v = v + (v << 6);
- v = v ^ (v >> 22);
- return (int) v;
- }
- static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash(uint64_t(p_int)); }
+ static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }
-
- static _FORCE_INLINE_ uint32_t hash(const uint32_t p_int) { return p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash(uint64_t(p_int)); }
+ static _FORCE_INLINE_ uint32_t hash(const float p_float) { return hash_djb2_one_float(p_float); }
+ static _FORCE_INLINE_ uint32_t hash(const double p_double){ return hash_djb2_one_float(p_double); }
+ static _FORCE_INLINE_ uint32_t hash(const uint32_t p_int) { return p_int; }
static _FORCE_INLINE_ uint32_t hash(const int32_t p_int) { return (uint32_t)p_int; }
- static _FORCE_INLINE_ uint32_t hash(const uint16_t p_int) { return p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const uint16_t p_int) { return p_int; }
static _FORCE_INLINE_ uint32_t hash(const int16_t p_int) { return (uint32_t)p_int; }
static _FORCE_INLINE_ uint32_t hash(const uint8_t p_int) { return p_int; }
- static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; }
- static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar) { return (uint32_t)p_wchar; }
-// static _FORCE_INLINE_ uint32_t hash(const void* p_ptr) { return uint32_t(uint64_t(p_ptr))*(0x9e3779b1L); }
+ static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; }
+ static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar){ return (uint32_t)p_wchar; }
+ //static _FORCE_INLINE_ uint32_t hash(const void* p_ptr) { return uint32_t(uint64_t(p_ptr))*(0x9e3779b1L); }
+};
+
+template <typename T>
+struct HashMapComparatorDefault {
+ static bool compare(const T& p_lhs, const T& p_rhs) {
+ return p_lhs == p_rhs;
+ }
+
+ bool compare(const float& p_lhs, const float& p_rhs) {
+ return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
+ }
+
+ bool compare(const double& p_lhs, const double& p_rhs) {
+ return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs));
+ }
};
/**
@@ -74,13 +79,14 @@ public:
* @param TKey Key, search is based on it, needs to be hasheable. It is unique in this container.
* @param TData Data, data associated with the key
* @param Hasher Hasher object, needs to provide a valid static hash function for TKey
+ * @param Comparator comparator object, needs to be able to safely compare two TKey values. It needs to ensure that x == x for any items inserted in the map. Bear in mind that nan != nan when implementing an equality check.
* @param MIN_HASH_TABLE_POWER Miminum size of the hash table, as a power of two. You rarely need to change this parameter.
* @param RELATIONSHIP Relationship at which the hash table is resized. if amount of elements is RELATIONSHIP
* times bigger than the hash table, table is resized to solve this condition. if RELATIONSHIP is zero, table is always MIN_HASH_TABLE_POWER.
*
*/
-template<class TKey, class TData, class Hasher=HashMapHahserDefault,uint8_t MIN_HASH_TABLE_POWER=3,uint8_t RELATIONSHIP=8>
+template<class TKey, class TData, class Hasher=HashMapHasherDefault, class Comparator=HashMapComparatorDefault<TKey>, uint8_t MIN_HASH_TABLE_POWER=3,uint8_t RELATIONSHIP=8>
class HashMap {
public:
@@ -194,7 +200,6 @@ private:
}
-
/* I want to have only one function.. */
_FORCE_INLINE_ const Entry * get_entry( const TKey& p_key ) const {
@@ -206,7 +211,7 @@ private:
while (e) {
/* checking hash first avoids comparing key, which may take longer */
- if (e->hash == hash && e->pair.key == p_key ) {
+ if (e->hash == hash && Comparator::compare(e->pair.key,p_key) ) {
/* the pair exists in this hashtable, so just update data */
return e;
@@ -253,7 +258,6 @@ private:
for (int i=0;i<( 1<<p_t.hash_table_power );i++) {
hash_table[i]=NULL;
- /* elements will be in the reverse order, but it doesn't matter */
const Entry *e = p_t.hash_table[i];
@@ -385,7 +389,7 @@ public:
while (e) {
/* checking hash first avoids comparing key, which may take longer */
- if (e->hash == hash && e->pair.key == p_custom_key ) {
+ if (e->hash == hash && Comparator::compare(e->pair.key,p_custom_key) ) {
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
@@ -411,7 +415,7 @@ public:
while (e) {
/* checking hash first avoids comparing key, which may take longer */
- if (e->hash == hash && e->pair.key == p_custom_key ) {
+ if (e->hash == hash && Comparator::compare(e->pair.key,p_custom_key) ) {
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
@@ -442,7 +446,7 @@ public:
while (e) {
/* checking hash first avoids comparing key, which may take longer */
- if (e->hash == hash && e->pair.key == p_key ) {
+ if (e->hash == hash && Comparator::compare(e->pair.key,p_key) ) {
if (p) {
@@ -637,7 +641,8 @@ public:
clear();
}
-
};
+
+
#endif
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index e9e57d8b42..121d7e8c59 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -29,7 +29,8 @@
#ifndef HASHFUNCS_H
#define HASHFUNCS_H
-
+#include "math_funcs.h"
+#include "math_defs.h"
#include "typedefs.h"
/**
@@ -69,19 +70,52 @@ static inline uint32_t hash_djb2_one_32(uint32_t p_in,uint32_t p_prev=5381) {
return ((p_prev<<5)+p_prev)+p_in;
}
+static inline uint32_t hash_one_uint64(const uint64_t p_int) {
+ uint64_t v=p_int;
+ v = (~v) + (v << 18); // v = (v << 18) - v - 1;
+ v = v ^ (v >> 31);
+ v = v * 21; // v = (v + (v << 2)) + (v << 4);
+ v = v ^ (v >> 11);
+ v = v + (v << 6);
+ v = v ^ (v >> 22);
+ return (int) v;
+}
+
static inline uint32_t hash_djb2_one_float(float p_in,uint32_t p_prev=5381) {
union {
float f;
uint32_t i;
} u;
- // handle -0 case
- if (p_in==0.0f) u.f=0.0f;
- else u.f=p_in;
+ // Normalize +/- 0.0 and NaN values so they hash the same.
+ if (p_in==0.0f)
+ u.f=0.0;
+ else if (Math::is_nan(p_in))
+ u.f=Math_NAN;
+ else
+ u.f=p_in;
return ((p_prev<<5)+p_prev)+u.i;
}
+// Overload for real_t size changes
+static inline uint32_t hash_djb2_one_float(double p_in,uint32_t p_prev=5381) {
+ union {
+ double d;
+ uint64_t i;
+ } u;
+
+ // Normalize +/- 0.0 and NaN values so they hash the same.
+ if (p_in==0.0f)
+ u.d=0.0;
+ else if (Math::is_nan(p_in))
+ u.d=Math_NAN;
+ else
+ u.d=p_in;
+
+ return ((p_prev<<5)+p_prev) + hash_one_uint64(u.i);
+}
+
template<class T>
static inline uint32_t make_uint32_t(T p_in) {
diff --git a/core/helper/SCsub b/core/helper/SCsub
new file mode 100644
index 0000000000..4efc902717
--- /dev/null
+++ b/core/helper/SCsub
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+
+Import('env')
+
+env.add_source_files(env.core_sources, "*.cpp")
+
+Export('env')
diff --git a/core/helper/math_fieldwise.cpp b/core/helper/math_fieldwise.cpp
new file mode 100644
index 0000000000..204c431e1d
--- /dev/null
+++ b/core/helper/math_fieldwise.cpp
@@ -0,0 +1,171 @@
+/*************************************************************************/
+/* fieldwise.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. */
+/*************************************************************************/
+
+#ifdef TOOLS_ENABLED
+
+#include "core/helper/math_fieldwise.h"
+
+#define SETUP_TYPE(m_type) m_type source=p_source; m_type target=p_target;
+#define TRY_TRANSFER_FIELD(m_name,m_member) if (p_field==m_name) { target.m_member=source.m_member; }
+
+Variant fieldwise_assign(const Variant& p_target, const Variant& p_source, const String& p_field) {
+
+ ERR_FAIL_COND_V(p_target.get_type()!=p_source.get_type(),p_target);
+
+ switch (p_source.get_type()) {
+
+ case Variant::VECTOR2: {
+
+ SETUP_TYPE(Vector2)
+
+ /**/ TRY_TRANSFER_FIELD("x",x)
+ else TRY_TRANSFER_FIELD("y",y)
+
+ return target;
+ }
+
+ case Variant::RECT2: {
+
+ SETUP_TYPE(Rect2)
+
+ /**/ TRY_TRANSFER_FIELD("x",pos.x)
+ else TRY_TRANSFER_FIELD("y",pos.y)
+ else TRY_TRANSFER_FIELD("w",size.x)
+ else TRY_TRANSFER_FIELD("h",size.y)
+
+ return target;
+ }
+
+ case Variant::VECTOR3: {
+
+ SETUP_TYPE(Vector3)
+
+ /**/ TRY_TRANSFER_FIELD("x",x)
+ else TRY_TRANSFER_FIELD("y",y)
+ else TRY_TRANSFER_FIELD("z",z)
+
+ return target;
+ }
+
+ case Variant::PLANE: {
+
+ SETUP_TYPE(Plane)
+
+ /**/ TRY_TRANSFER_FIELD("x",normal.x)
+ else TRY_TRANSFER_FIELD("y",normal.y)
+ else TRY_TRANSFER_FIELD("z",normal.z)
+ else TRY_TRANSFER_FIELD("d",d)
+
+ return target;
+ }
+
+ case Variant::QUAT: {
+
+ SETUP_TYPE(Quat)
+
+ /**/ TRY_TRANSFER_FIELD("x",x)
+ else TRY_TRANSFER_FIELD("y",y)
+ else TRY_TRANSFER_FIELD("z",z)
+ else TRY_TRANSFER_FIELD("w",w)
+
+ return target;
+ }
+
+ case Variant::RECT3: {
+
+ SETUP_TYPE(Rect3)
+
+ /**/ TRY_TRANSFER_FIELD("px",pos.x)
+ else TRY_TRANSFER_FIELD("py",pos.y)
+ else TRY_TRANSFER_FIELD("pz",pos.z)
+ else TRY_TRANSFER_FIELD("sx",size.x)
+ else TRY_TRANSFER_FIELD("sy",size.y)
+ else TRY_TRANSFER_FIELD("sz",size.z)
+
+ return target;
+ }
+
+ case Variant::TRANSFORM2D: {
+
+ SETUP_TYPE(Transform2D)
+
+ /**/ TRY_TRANSFER_FIELD("xx",elements[0][0])
+ else TRY_TRANSFER_FIELD("xy",elements[0][1])
+ else TRY_TRANSFER_FIELD("yx",elements[1][0])
+ else TRY_TRANSFER_FIELD("yy",elements[1][1])
+ else TRY_TRANSFER_FIELD("ox",elements[2][0])
+ else TRY_TRANSFER_FIELD("oy",elements[2][1])
+
+ return target;
+ }
+
+ case Variant::BASIS: {
+
+ SETUP_TYPE(Basis)
+
+ /**/ TRY_TRANSFER_FIELD("xx",elements[0][0])
+ else TRY_TRANSFER_FIELD("xy",elements[0][1])
+ else TRY_TRANSFER_FIELD("xz",elements[0][2])
+ else TRY_TRANSFER_FIELD("yx",elements[1][0])
+ else TRY_TRANSFER_FIELD("yy",elements[1][1])
+ else TRY_TRANSFER_FIELD("yz",elements[1][2])
+ else TRY_TRANSFER_FIELD("zx",elements[2][0])
+ else TRY_TRANSFER_FIELD("zy",elements[2][1])
+ else TRY_TRANSFER_FIELD("zz",elements[2][2])
+
+ return target;
+ }
+
+ case Variant::TRANSFORM: {
+
+ SETUP_TYPE(Transform)
+
+ /**/ TRY_TRANSFER_FIELD("xx",basis.elements[0][0])
+ else TRY_TRANSFER_FIELD("xy",basis.elements[0][1])
+ else TRY_TRANSFER_FIELD("xz",basis.elements[0][2])
+ else TRY_TRANSFER_FIELD("yx",basis.elements[1][0])
+ else TRY_TRANSFER_FIELD("yy",basis.elements[1][1])
+ else TRY_TRANSFER_FIELD("yz",basis.elements[1][2])
+ else TRY_TRANSFER_FIELD("zx",basis.elements[2][0])
+ else TRY_TRANSFER_FIELD("zy",basis.elements[2][1])
+ else TRY_TRANSFER_FIELD("zz",basis.elements[2][2])
+ else TRY_TRANSFER_FIELD("xo",origin.x)
+ else TRY_TRANSFER_FIELD("yo",origin.y)
+ else TRY_TRANSFER_FIELD("zo",origin.z)
+
+ return target;
+ }
+
+ default: {
+ ERR_FAIL_V(p_target);
+ }
+ }
+}
+
+#endif // TOOLS_ENABLED
diff --git a/core/helper/math_fieldwise.h b/core/helper/math_fieldwise.h
new file mode 100644
index 0000000000..31f9af8d0b
--- /dev/null
+++ b/core/helper/math_fieldwise.h
@@ -0,0 +1,40 @@
+/*************************************************************************/
+/* fieldwise.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 MATH_FIELDWISE_H
+#define MATH_FIELDWISE_H
+
+#ifdef TOOLS_ENABLED
+
+#include "core/variant.h"
+
+Variant fieldwise_assign(const Variant& p_target, const Variant& p_source, const String& p_field);
+
+#endif // TOOLS_ENABLED
+
+#endif // MATH_FIELDWISE_H
diff --git a/core/image.cpp b/core/image.cpp
index 174c840c23..037ff82452 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -27,11 +27,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "image.h"
+
#include "hash_map.h"
#include "core/io/image_loader.h"
#include "core/os/copymem.h"
#include "hq2x.h"
#include "print_string.h"
+
#include <stdio.h>
@@ -243,7 +245,7 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width
}
int Image::get_mipmap_offset(int p_mipmap) const {
- ERR_FAIL_INDEX_V(p_mipmap,(mipmaps+1),-1);
+ ERR_FAIL_INDEX_V(p_mipmap,get_mipmap_count()+1,-1);
int ofs,w,h;
_get_mipmap_offset_and_size(p_mipmap,ofs,w,h);
@@ -363,7 +365,7 @@ void Image::convert( Format p_new_format ){
Image new_img(width,height,0,p_new_format);
-// int len=data.size();
+ //int len=data.size();
PoolVector<uint8_t>::Read r = data.read();
PoolVector<uint8_t>::Write w = new_img.data.write();
@@ -414,7 +416,7 @@ void Image::convert( Format p_new_format ){
bool gen_mipmaps=mipmaps;
-// mipmaps=false;
+ //mipmaps=false;
*this=new_img;
@@ -762,7 +764,7 @@ void Image::flip_y() {
bool gm=mipmaps;
if (gm)
- clear_mipmaps();;
+ clear_mipmaps();
@@ -789,7 +791,7 @@ void Image::flip_y() {
if (gm)
- generate_mipmaps();;
+ generate_mipmaps();
}
@@ -802,7 +804,7 @@ void Image::flip_x() {
bool gm=mipmaps;
if (gm)
- clear_mipmaps();;
+ clear_mipmaps();
{
@@ -827,7 +829,7 @@ void Image::flip_x() {
}
if (gm)
- generate_mipmaps();;
+ generate_mipmaps();
}
@@ -1009,7 +1011,7 @@ void Image::shrink_x2() {
}
}
-Error Image::generate_mipmaps(bool p_keep_existing) {
+Error Image::generate_mipmaps() {
if (!_can_modify(format)) {
ERR_EXPLAIN("Cannot generate mipmaps in indexed, compressed or custom image formats.");
@@ -1017,15 +1019,14 @@ Error Image::generate_mipmaps(bool p_keep_existing) {
}
- int mmcount = get_mipmap_count();
+ ERR_FAIL_COND_V(width==0 || height==0,ERR_UNCONFIGURED);
+
+ int mmcount;
- int from_mm=1;
- if (p_keep_existing) {
- from_mm=mmcount+1;
- }
int size = _get_dst_image_size(width,height,format,mmcount);
data.resize(size);
+ print_line("to gen mipmaps w "+itos(width)+" h "+itos(height) +" format "+get_format_name(format)+" mipmaps " +itos(mmcount)+" new size is: "+itos(size));
PoolVector<uint8_t>::Write wp=data.write();
@@ -1041,18 +1042,16 @@ Error Image::generate_mipmaps(bool p_keep_existing) {
int ofs,w,h;
_get_mipmap_offset_and_size(i,ofs, w,h);
- if (i>=from_mm) {
- switch(format) {
+ switch(format) {
- 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: {}
- }
+ 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: {}
}
prev_ofs=ofs;
@@ -1075,18 +1074,15 @@ Error Image::generate_mipmaps(bool p_keep_existing) {
int ofs,w,h;
_get_mipmap_offset_and_size(i,ofs, w,h);
- if (i>=from_mm) {
-
- switch(format) {
+ switch(format) {
- 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: {}
- }
+ 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: {}
}
prev_ofs=ofs;
@@ -1094,8 +1090,11 @@ Error Image::generate_mipmaps(bool p_keep_existing) {
prev_h=h;
}
+
+
}
+ mipmaps=true;
return OK;
}
@@ -1152,7 +1151,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
ERR_FAIL_INDEX(p_height-1,MAX_HEIGHT);
int mm;
- int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps);
+ int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps?-1:0);
if (size!=p_data.size()) {
ERR_EXPLAIN("Expected data size of "+itos(size)+" in Image::create()");
@@ -1240,7 +1239,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++) {
@@ -2153,7 +2152,7 @@ void Image::fix_alpha_edges() {
return; //not needed
PoolVector<uint8_t> dcopy = data;
- PoolVector<uint8_t>::Read rp = data.read();
+ PoolVector<uint8_t>::Read rp = dcopy.read();
const uint8_t *srcptr=rp.ptr();
PoolVector<uint8_t>::Write wp = data.write();
diff --git a/core/image.h b/core/image.h
index 620160147b..1a257f28a0 100644
--- a/core/image.h
+++ b/core/image.h
@@ -196,7 +196,7 @@ public:
/**
* Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
*/
- Error generate_mipmaps(bool p_keep_existing=false);
+ Error generate_mipmaps();
void clear_mipmaps();
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 0379131dd3..444c55cac6 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -27,26 +27,27 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "input_map.h"
-#include "globals.h"
+
+#include "global_config.h"
#include "os/keyboard.h"
InputMap *InputMap::singleton=NULL;
void InputMap::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("has_action","action"),&InputMap::has_action);
+ ClassDB::bind_method(D_METHOD("get_action_id","action"),&InputMap::get_action_id);
+ ClassDB::bind_method(D_METHOD("get_action_from_id","id"),&InputMap::get_action_from_id);
+ ClassDB::bind_method(D_METHOD("get_actions"),&InputMap::_get_actions);
+ ClassDB::bind_method(D_METHOD("add_action","action"),&InputMap::add_action);
+ ClassDB::bind_method(D_METHOD("erase_action","action"),&InputMap::erase_action);
- 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);
+ ClassDB::bind_method(D_METHOD("action_add_event","action","event"),&InputMap::action_add_event);
+ ClassDB::bind_method(D_METHOD("action_has_event","action","event"),&InputMap::action_has_event);
+ ClassDB::bind_method(D_METHOD("action_erase_event","action","event"),&InputMap::action_erase_event);
+ ClassDB::bind_method(D_METHOD("get_action_list","action"),&InputMap::_get_action_list);
+ ClassDB::bind_method(D_METHOD("event_is_action","event","action"),&InputMap::event_is_action);
+ ClassDB::bind_method(D_METHOD("load_from_globals"),&InputMap::load_from_globals);
}
@@ -106,7 +107,7 @@ List<StringName> InputMap::get_actions() const {
return actions;
}
-List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore=false) const {
+List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_action_test) const {
for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) {
@@ -122,7 +123,13 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const
case InputEvent::KEY: {
- same=(e.key.scancode==p_event.key.scancode && (p_mod_ignore || e.key.mod == p_event.key.mod));
+ if(p_action_test) {
+ uint32_t code = e.key.get_scancode_with_modifiers();
+ uint32_t event_code = p_event.key.get_scancode_with_modifiers();
+ same=(e.key.scancode==p_event.key.scancode && (!p_event.key.pressed || ((code & event_code) == code)));
+ } else {
+ same=(e.key.scancode==p_event.key.scancode && e.key.mod == p_event.key.mod);
+ }
} break;
case InputEvent::JOYPAD_BUTTON: {
@@ -198,7 +205,7 @@ Array InputMap::_get_action_list(const StringName& p_action) {
if (al) {
for(const List<InputEvent>::Element *E=al->front();E;E=E->next()) {
- ret.push_back(E->get());;
+ ret.push_back(E->get());
}
}
@@ -229,7 +236,7 @@ bool InputMap::event_is_action(const InputEvent& p_event, const StringName& p_ac
return p_event.action.action==E->get().id;
}
- return _find_event(E->get().inputs,p_event,!p_event.is_pressed())!=NULL;
+ return _find_event(E->get().inputs,p_event,true)!=NULL;
}
const Map<StringName, InputMap::Action>& InputMap::get_action_map() const {
@@ -238,7 +245,7 @@ const Map<StringName, InputMap::Action>& InputMap::get_action_map() const {
void InputMap::load_from_globals() {
- input_map.clear();;
+ input_map.clear();
List<PropertyInfo> pinfo;
GlobalConfig::get_singleton()->get_property_list(&pinfo);
@@ -253,7 +260,7 @@ void InputMap::load_from_globals() {
add_action(name);
- Array va = GlobalConfig::get_singleton()->get(pi.name);;
+ Array va = GlobalConfig::get_singleton()->get(pi.name);
for(int i=0;i<va.size();i++) {
@@ -324,7 +331,7 @@ void InputMap::load_default() {
key.key.scancode=KEY_PAGEDOWN;
action_add_event("ui_page_down",key);
-// set("display/handheld/orientation", "landscape");
+ //set("display/handheld/orientation", "landscape");
}
diff --git a/core/input_map.h b/core/input_map.h
index 306845fc89..6ccd24f29c 100644
--- a/core/input_map.h
+++ b/core/input_map.h
@@ -46,7 +46,7 @@ private:
mutable Map<StringName, Action> input_map;
mutable Map<int,StringName> input_id_map;
- List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore) const;
+ List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_action_test=false) const;
Array _get_action_list(const StringName& p_action);
Array _get_actions();
diff --git a/core/io/aes256.cpp b/core/io/aes256.cpp
index cfdac0214d..dc271928b4 100644
--- a/core/io/aes256.cpp
+++ b/core/io/aes256.cpp
@@ -44,8 +44,7 @@ static uint8_t rj_sbox_inv(uint8_t);
#ifdef BACK_TO_TABLES
-static const uint8_t sbox[256] =
-{
+static const uint8_t sbox[256] = {
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
@@ -79,8 +78,7 @@ static const uint8_t sbox[256] =
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
};
-static const uint8_t sboxinv[256] =
-{
+static const uint8_t sboxinv[256] = {
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38,
0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
diff --git a/core/io/base64.c b/core/io/base64.c
index 0c799e9f07..0929ae5db5 100644
--- a/core/io/base64.c
+++ b/core/io/base64.c
@@ -1,3 +1,11 @@
+/*
+ * File: base64.c
+ * Description: Simple BASE64 conversion methods
+ * Author: Ari Edelkind
+ * License: Public Domain
+ * Website: http://episec.com/people/edelkind/c.html
+ */
+
#include <string.h>
char b64string[] =
diff --git a/core/io/base64.h b/core/io/base64.h
index b70b387983..456ef1811b 100644
--- a/core/io/base64.h
+++ b/core/io/base64.h
@@ -1,3 +1,11 @@
+/*
+ * File: base64.h
+ * Description: Simple BASE64 conversion methods
+ * Author: Ari Edelkind
+ * License: Public Domain
+ * Website: http://episec.com/people/edelkind/c.html
+ */
+
#ifndef BASE64_H
#define BASE64_H
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index 0d3b494106..6fda7d52f3 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -59,7 +59,7 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,M
return -1;
strm.avail_in=p_src_size;
- int aout = deflateBound(&strm,p_src_size);;
+ int aout = deflateBound(&strm,p_src_size);
/*if (aout>p_src_size) {
deflateEnd(&strm);
return -1;
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index a9de740806..fdfcc3ae3a 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -119,7 +119,10 @@ void ConfigFile::get_section_keys(const String& p_section,List<String> *r_keys)
}
+void ConfigFile::erase_section(const String& p_section) {
+ values.erase(p_section);
+}
Error ConfigFile::save(const String& p_path){
@@ -206,17 +209,19 @@ Error ConfigFile::load(const String& p_path) {
void ConfigFile::_bind_methods(){
- 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()));
+ ClassDB::bind_method(D_METHOD("set_value","section","key","value"),&ConfigFile::set_value);
+ ClassDB::bind_method(D_METHOD("get_value:Variant","section","key","default"),&ConfigFile::get_value,DEFVAL(Variant()));
+
+ ClassDB::bind_method(D_METHOD("has_section","section"),&ConfigFile::has_section);
+ ClassDB::bind_method(D_METHOD("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);
+ ClassDB::bind_method(D_METHOD("get_sections"),&ConfigFile::_get_sections);
+ ClassDB::bind_method(D_METHOD("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);
+ ClassDB::bind_method(D_METHOD("erase_section","section"),&ConfigFile::erase_section);
- ClassDB::bind_method(_MD("load:Error","path"),&ConfigFile::load);
- ClassDB::bind_method(_MD("save:Error","path"),&ConfigFile::save);
+ ClassDB::bind_method(D_METHOD("load:Error","path"),&ConfigFile::load);
+ ClassDB::bind_method(D_METHOD("save:Error","path"),&ConfigFile::save);
}
diff --git a/core/io/config_file.h b/core/io/config_file.h
index 397342f90f..c9c4a9fbc0 100644
--- a/core/io/config_file.h
+++ b/core/io/config_file.h
@@ -54,6 +54,8 @@ public:
void get_sections(List<String> *r_sections) const;
void get_section_keys(const String& p_section,List<String> *r_keys) const;
+ void erase_section(const String& p_section);
+
Error save(const String& p_path);
Error load(const String& p_path);
diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h
index 884d40a266..000c2b45f3 100644
--- a/core/io/file_access_buffered_fa.h
+++ b/core/io/file_access_buffered_fa.h
@@ -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_memory.cpp b/core/io/file_access_memory.cpp
index a9dbf56c15..b4ba14ddc9 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -30,7 +30,7 @@
#include "os/dir_access.h"
#include "os/copymem.h"
-#include "globals.h"
+#include "global_config.h"
#include "map.h"
static Map<String, Vector<uint8_t> >* files = NULL;
@@ -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_network.cpp b/core/io/file_access_network.cpp
index 19076b57be..d9fdc9cedc 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "file_access_network.h"
#include "marshalls.h"
-#include "globals.h"
+#include "global_config.h"
#include "os/os.h"
#include "io/ip.h"
@@ -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;
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index 7e3a6d1fa0..fa1bebde16 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -31,7 +31,7 @@
#include <stdio.h>
-#define PACK_VERSION 0
+#define PACK_VERSION 1
Error PackedData::add_pack(const String& p_path) {
@@ -167,8 +167,8 @@ bool PackedSourcePCK::try_open_pack(const String& p_path) {
uint32_t ver_minor = f->get_32();
uint32_t ver_rev = f->get_32();
- ERR_EXPLAIN("Pack version newer than supported by engine: "+itos(version));
- ERR_FAIL_COND_V( version > PACK_VERSION, ERR_INVALID_DATA);
+ ERR_EXPLAIN("Pack version unsupported: "+itos(version));
+ ERR_FAIL_COND_V( version != PACK_VERSION, ERR_INVALID_DATA);
ERR_EXPLAIN("Pack created with a newer version of the engine: "+itos(ver_major)+"."+itos(ver_minor)+"."+itos(ver_rev));
ERR_FAIL_COND_V( ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), ERR_INVALID_DATA);
@@ -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 83340a662b..0a1320e57b 100644
--- a/core/io/file_access_pack.h
+++ b/core/io/file_access_pack.h
@@ -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 c4439f2599..87f07cb7b1 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -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/http_client.cpp b/core/io/http_client.cpp
index 5e57f55f87..ae14f8fa38 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -29,14 +29,9 @@
#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;
@@ -57,7 +52,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;
@@ -66,7 +61,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, ip_type);
+ resolving=IP::get_singleton()->resolve_hostname_queue_item(conn_host);
status=STATUS_RESOLVING;
}
@@ -232,7 +227,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;
@@ -267,7 +262,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) {
@@ -300,7 +295,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;
@@ -345,7 +340,7 @@ Error HTTPClient::poll(){
int rs = response_str.size();
if (
(rs>=2 && response_str[rs-2]=='\n' && response_str[rs-1]=='\n') ||
- (rs>=4 && response_str[rs-4]=='\r' && response_str[rs-3]=='\n' && rs>=4 && response_str[rs-2]=='\r' && response_str[rs-1]=='\n')
+ (rs>=4 && response_str[rs-4]=='\r' && response_str[rs-3]=='\n' && response_str[rs-2]=='\r' && response_str[rs-1]=='\n')
) {
@@ -566,11 +561,13 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
int to_read = MIN(body_left,read_chunk_size);
PoolByteArray ret;
ret.resize(to_read);
- PoolByteArray::Write w = ret.write();
int _offset = 0;
while (to_read > 0) {
int rec=0;
- err = _get_http_data(w.ptr()+_offset,to_read,rec);
+ {
+ PoolByteArray::Write w = ret.write();
+ err = _get_http_data(w.ptr()+_offset,to_read,rec);
+ }
if (rec>0) {
body_left-=rec;
to_read-=rec;
@@ -639,32 +636,31 @@ Error HTTPClient::_get_http_data(uint8_t* p_buffer, int p_bytes,int &r_received)
void HTTPClient::_bind_methods() {
- ClassDB::bind_method(_MD("set_ip_type","ip_type"),&HTTPClient::set_ip_type);
- ClassDB::bind_method(_MD("connect:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect,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);
+ ClassDB::bind_method(D_METHOD("connect_to_host:Error","host","port","use_ssl","verify_host"),&HTTPClient::connect_to_host,DEFVAL(false),DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("set_connection","connection:StreamPeer"),&HTTPClient::set_connection);
+ ClassDB::bind_method(D_METHOD("get_connection:StreamPeer"),&HTTPClient::get_connection);
+ ClassDB::bind_method(D_METHOD("request_raw","method","url","headers","body"),&HTTPClient::request_raw);
+ ClassDB::bind_method(D_METHOD("request","method","url","headers","body"),&HTTPClient::request,DEFVAL(String()));
+ ClassDB::bind_method(D_METHOD("send_body_text","body"),&HTTPClient::send_body_text);
+ ClassDB::bind_method(D_METHOD("send_body_data","body"),&HTTPClient::send_body_data);
+ ClassDB::bind_method(D_METHOD("close"),&HTTPClient::close);
- 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);
+ ClassDB::bind_method(D_METHOD("has_response"),&HTTPClient::has_response);
+ ClassDB::bind_method(D_METHOD("is_response_chunked"),&HTTPClient::is_response_chunked);
+ ClassDB::bind_method(D_METHOD("get_response_code"),&HTTPClient::get_response_code);
+ ClassDB::bind_method(D_METHOD("get_response_headers"),&HTTPClient::_get_response_headers);
+ ClassDB::bind_method(D_METHOD("get_response_headers_as_dictionary"),&HTTPClient::_get_response_headers_as_dictionary);
+ ClassDB::bind_method(D_METHOD("get_response_body_length"),&HTTPClient::get_response_body_length);
+ ClassDB::bind_method(D_METHOD("read_response_body_chunk"),&HTTPClient::read_response_body_chunk);
+ ClassDB::bind_method(D_METHOD("set_read_chunk_size","bytes"),&HTTPClient::set_read_chunk_size);
- 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);
+ ClassDB::bind_method(D_METHOD("set_blocking_mode","enabled"),&HTTPClient::set_blocking_mode);
+ ClassDB::bind_method(D_METHOD("is_blocking_mode_enabled"),&HTTPClient::is_blocking_mode_enabled);
- ClassDB::bind_method(_MD("get_status"),&HTTPClient::get_status);
- ClassDB::bind_method(_MD("poll:Error"),&HTTPClient::poll);
+ ClassDB::bind_method(D_METHOD("get_status"),&HTTPClient::get_status);
+ ClassDB::bind_method(D_METHOD("poll:Error"),&HTTPClient::poll);
- ClassDB::bind_method(_MD("query_string_from_dict:String","fields"),&HTTPClient::query_string_from_dict);
+ ClassDB::bind_method(D_METHOD("query_string_from_dict:String","fields"),&HTTPClient::query_string_from_dict);
BIND_CONSTANT( METHOD_GET );
@@ -766,7 +762,6 @@ 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 c6f96db1d6..4b0c1b730f 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -132,7 +132,6 @@ public:
private:
- IP::Type ip_type;
Status status;
IP::ResolverID resolving;
int conn_port;
@@ -165,9 +164,8 @@ 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;
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index d4d10e2126..2b01e865f4 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -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/ip.cpp b/core/io/ip.cpp
index 0eb1f221c9..d820273a14 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -82,7 +82,7 @@ struct _IP_ResolverPrivate {
continue;
queue[i].response=IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type);
- if (queue[i].response==IP_Address())
+ if (!queue[i].response.is_valid())
queue[i].status=IP::RESOLVER_STATUS_ERROR;
else
queue[i].status=IP::RESOLVER_STATUS_DONE;
@@ -218,13 +218,13 @@ Array IP::_get_local_addresses() const {
void IP::_bind_methods() {
- 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(""));
+ ClassDB::bind_method(D_METHOD("resolve_hostname","host","ip_type"),&IP::resolve_hostname,DEFVAL(IP::TYPE_ANY));
+ ClassDB::bind_method(D_METHOD("resolve_hostname_queue_item","host","ip_type"),&IP::resolve_hostname_queue_item,DEFVAL(IP::TYPE_ANY));
+ ClassDB::bind_method(D_METHOD("get_resolve_item_status","id"),&IP::get_resolve_item_status);
+ ClassDB::bind_method(D_METHOD("get_resolve_item_address","id"),&IP::get_resolve_item_address);
+ ClassDB::bind_method(D_METHOD("erase_resolve_item","id"),&IP::erase_resolve_item);
+ ClassDB::bind_method(D_METHOD("get_local_addresses"),&IP::_get_local_addresses);
+ ClassDB::bind_method(D_METHOD("clear_cache"),&IP::clear_cache, DEFVAL(""));
BIND_CONSTANT( RESOLVER_STATUS_NONE );
BIND_CONSTANT( RESOLVER_STATUS_WAITING );
diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp
index 1fda7fed7b..69c7df619d 100644
--- a/core/io/ip_address.cpp
+++ b/core/io/ip_address.cpp
@@ -38,6 +38,9 @@ IP_Address::operator Variant() const {
IP_Address::operator String() const {
+ if(!valid)
+ return "";
+
if(is_ipv4())
// IPv4 address mapped to IPv6
return itos(field8[12])+"."+itos(field8[13])+"."+itos(field8[14])+"."+itos(field8[15]);
@@ -171,6 +174,8 @@ void IP_Address::_parse_ipv4(const String& p_string, int p_start, uint8_t* p_ret
void IP_Address::clear() {
memset(&field8[0], 0, sizeof(field8));
+ valid = false;
+ wildcard = false;
};
bool IP_Address::is_ipv4() const{
@@ -184,6 +189,7 @@ const uint8_t *IP_Address::get_ipv4() const{
void IP_Address::set_ipv4(const uint8_t *p_ip) {
clear();
+ valid = true;
field16[5]=0xffff;
field32[3]=*((const uint32_t *)p_ip);
}
@@ -194,6 +200,7 @@ const uint8_t *IP_Address::get_ipv6() const{
void IP_Address::set_ipv6(const uint8_t *p_buf) {
clear();
+ valid = true;
for (int i=0; i<16; i++)
field8[i] = p_buf[i];
}
@@ -201,14 +208,25 @@ void IP_Address::set_ipv6(const uint8_t *p_buf) {
IP_Address::IP_Address(const String& p_string) {
clear();
- if (p_string.find(":") >= 0) {
+ if (p_string == "*") {
+ // Wildcard (not a vaild IP)
+ wildcard = true;
+
+ } else if (p_string.find(":") >= 0) {
+ // IPv6
_parse_ipv6(p_string);
- } else {
- // Mapped to IPv6
+ valid = true;
+
+ } else if (p_string.get_slice_count(".") == 4) {
+ // IPv4 (mapped to IPv6 internally)
field16[5] = 0xffff;
_parse_ipv4(p_string, 0, &field8[12]);
- };
+ valid = true;
+
+ } else {
+ ERR_PRINT("Invalid IP address");
+ }
}
_FORCE_INLINE_ static void _32_to_buf(uint8_t* p_dst, uint32_t p_n) {
@@ -222,6 +240,7 @@ _FORCE_INLINE_ static void _32_to_buf(uint8_t* p_dst, uint32_t p_n) {
IP_Address::IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, bool is_v6) {
clear();
+ valid = true;
if (!is_v6) {
// Mapped to IPv6
field16[5]=0xffff;
diff --git a/core/io/ip_address.h b/core/io/ip_address.h
index 87f32b0ac2..257836601a 100644
--- a/core/io/ip_address.h
+++ b/core/io/ip_address.h
@@ -41,6 +41,9 @@ private:
uint32_t field32[4];
};
+ bool valid;
+ bool wildcard;
+
protected:
void _parse_ipv6(const String& p_string);
void _parse_ipv4(const String& p_string, int p_start, uint8_t* p_ret);
@@ -48,12 +51,16 @@ protected:
public:
//operator Variant() const;
bool operator==(const IP_Address& p_ip) const {
+ if (p_ip.valid != valid) return false;
+ if (!valid) return false;
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 {
+ if (p_ip.valid != valid) return true;
+ if (!valid) return true;
for (int i=0; i<4; i++)
if (field32[i] != p_ip.field32[i])
return true;
@@ -61,6 +68,8 @@ public:
}
void clear();
+ bool is_wildcard() const {return wildcard;}
+ bool is_valid() const {return valid;}
bool is_ipv4() const;
const uint8_t *get_ipv4() const;
void set_ipv4(const uint8_t *p_ip);
diff --git a/core/io/json.cpp b/core/io/json.cpp
index c0aa530a12..5ade25aab4 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -100,7 +100,7 @@ String JSON::print(const Variant& p_var) {
Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token& r_token,int &line,String &r_err_str) {
- while (true) {
+ while (p_len > 0) {
switch(p_str[idx]) {
case '\n': {
@@ -374,7 +374,7 @@ Error JSON::_parse_array(Array &array,const CharType *p_str,int &index, int p_le
}
- return OK;
+ return ERR_PARSE_ERROR;
}
@@ -446,7 +446,7 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i
}
}
- return OK;
+ return ERR_PARSE_ERROR;
}
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index e958edc93e..a8c1cd0a10 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -641,7 +641,6 @@ 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);
- ERR_FAIL_COND_V(count<0,ERR_INVALID_DATA);
PoolVector<String> strings;
buf+=4;
@@ -691,7 +690,6 @@ 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);
- ERR_FAIL_COND_V(count<0,ERR_INVALID_DATA);
buf+=4;
len-=4;
@@ -729,7 +727,6 @@ 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);
- ERR_FAIL_COND_V(count<0,ERR_INVALID_DATA);
buf+=4;
len-=4;
@@ -768,7 +765,6 @@ 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);
- ERR_FAIL_COND_V(count<0,ERR_INVALID_DATA);
buf+=4;
len-=4;
diff --git a/core/io/networked_multiplayer_peer.cpp b/core/io/networked_multiplayer_peer.cpp
index 6133401a8c..fb81a806e2 100644
--- a/core/io/networked_multiplayer_peer.cpp
+++ b/core/io/networked_multiplayer_peer.cpp
@@ -1,20 +1,48 @@
+/*************************************************************************/
+/* networked_multiplayer_peer.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 "networked_multiplayer_peer.h"
void NetworkedMultiplayerPeer::_bind_methods() {
- ClassDB::bind_method(_MD("set_transfer_mode","mode"), &NetworkedMultiplayerPeer::set_transfer_mode );
- ClassDB::bind_method(_MD("set_target_peer","id"), &NetworkedMultiplayerPeer::set_target_peer );
+ ClassDB::bind_method(D_METHOD("set_transfer_mode","mode"), &NetworkedMultiplayerPeer::set_transfer_mode );
+ ClassDB::bind_method(D_METHOD("set_target_peer","id"), &NetworkedMultiplayerPeer::set_target_peer );
- ClassDB::bind_method(_MD("get_packet_peer"), &NetworkedMultiplayerPeer::get_packet_peer );
+ ClassDB::bind_method(D_METHOD("get_packet_peer"), &NetworkedMultiplayerPeer::get_packet_peer );
- ClassDB::bind_method(_MD("poll"), &NetworkedMultiplayerPeer::poll );
+ ClassDB::bind_method(D_METHOD("poll"), &NetworkedMultiplayerPeer::poll );
- ClassDB::bind_method(_MD("get_connection_status"), &NetworkedMultiplayerPeer::get_connection_status );
- ClassDB::bind_method(_MD("get_unique_id"), &NetworkedMultiplayerPeer::get_unique_id );
+ ClassDB::bind_method(D_METHOD("get_connection_status"), &NetworkedMultiplayerPeer::get_connection_status );
+ ClassDB::bind_method(D_METHOD("get_unique_id"), &NetworkedMultiplayerPeer::get_unique_id );
- 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 );
+ ClassDB::bind_method(D_METHOD("set_refuse_new_connections","enable"), &NetworkedMultiplayerPeer::set_refuse_new_connections );
+ ClassDB::bind_method(D_METHOD("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 a59d9367d1..5d859a2f25 100644
--- a/core/io/networked_multiplayer_peer.h
+++ b/core/io/networked_multiplayer_peer.h
@@ -1,3 +1,31 @@
+/*************************************************************************/
+/* networked_multiplayer_peer.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 NETWORKED_MULTIPLAYER_PEER_H
#define NETWORKED_MULTIPLAYER_PEER_H
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index 5ff09f9fb0..cf5883121f 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -29,7 +29,7 @@
#include "packet_peer.h"
#include "io/marshalls.h"
-#include "globals.h"
+#include "global_config.h"
/* helpers / binders */
@@ -126,12 +126,12 @@ Error PacketPeer::_get_packet_error() const {
void PacketPeer::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("get_var:Variant"),&PacketPeer::_bnd_get_var);
+ ClassDB::bind_method(D_METHOD("put_var", "var:Variant"),&PacketPeer::put_var);
+ ClassDB::bind_method(D_METHOD("get_packet"),&PacketPeer::_get_packet);
+ ClassDB::bind_method(D_METHOD("put_packet:Error", "buffer"),&PacketPeer::_put_packet);
+ ClassDB::bind_method(D_METHOD("get_packet_error:Error"),&PacketPeer::_get_packet_error);
+ ClassDB::bind_method(D_METHOD("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() {
- ClassDB::bind_method(_MD("set_stream_peer","peer:StreamPeer"),&PacketPeerStream::_set_stream_peer);
+ ClassDB::bind_method(D_METHOD("set_stream_peer","peer:StreamPeer"),&PacketPeerStream::_set_stream_peer);
}
Error PacketPeerStream::_poll_buffer() const {
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp
index 91d1fc5f98..c4a6fd79a8 100644
--- a/core/io/packet_peer_udp.cpp
+++ b/core/io/packet_peer_udp.cpp
@@ -36,37 +36,31 @@ 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_type);
- if (ip==IP_Address())
+ ip=IP::get_singleton()->resolve_hostname(p_address);
+ if (!ip.is_valid())
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() {
- 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_send_address","host","port"),&PacketPeerUDP::_set_send_address);
+ ClassDB::bind_method(D_METHOD("listen:Error","port", "bind_address", "recv_buf_size"),&PacketPeerUDP::listen,DEFVAL("*"),DEFVAL(65536));
+ ClassDB::bind_method(D_METHOD("close"),&PacketPeerUDP::close);
+ ClassDB::bind_method(D_METHOD("wait:Error"),&PacketPeerUDP::wait);
+ ClassDB::bind_method(D_METHOD("is_listening"),&PacketPeerUDP::is_listening);
+ ClassDB::bind_method(D_METHOD("get_packet_ip"),&PacketPeerUDP::_get_packet_ip);
+ //ClassDB::bind_method(D_METHOD("get_packet_address"),&PacketPeerUDP::_get_packet_address);
+ ClassDB::bind_method(D_METHOD("get_packet_port"),&PacketPeerUDP::get_packet_port);
+ ClassDB::bind_method(D_METHOD("set_dest_address","host","port"),&PacketPeerUDP::_set_dest_address);
}
@@ -87,5 +81,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 17a2817f34..726406887c 100644
--- a/core/io/packet_peer_udp.h
+++ b/core/io/packet_peer_udp.h
@@ -38,25 +38,22 @@ class PacketPeerUDP : public PacketPeer {
protected:
- IP::Type ip_type;
-
static PacketPeerUDP* (*_create)();
static void _bind_methods();
String _get_packet_ip() const;
- virtual Error _set_send_address(const String& p_address,int p_port);
+ Error _set_dest_address(const String& p_address,int p_port);
public:
- virtual void set_ip_type(IP::Type p_type);
- virtual Error listen(int p_port, int p_recv_buffer_size=65536)=0;
+ virtual Error listen(int p_port, IP_Address p_bind_address=IP_Address("*"), 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
index a9f357a7c8..2cd46843e8 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* pkc_packer.cpp */
+/* pck_packer.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -52,9 +52,9 @@ static void _pad(FileAccess* p_file, int p_bytes) {
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);
+ ClassDB::bind_method(D_METHOD("pck_start","pck_name","alignment"),&PCKPacker::pck_start);
+ ClassDB::bind_method(D_METHOD("add_file","pck_path","source_path"),&PCKPacker::add_file);
+ ClassDB::bind_method(D_METHOD("flush","verbose"),&PCKPacker::flush);
};
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index c093b087b8..2d733842fa 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "version.h"
#include "resource_format_binary.h"
-#include "globals.h"
+#include "global_config.h"
#include "io/file_access_compressed.h"
#include "io/marshalls.h"
#include "os/dir_access.h"
@@ -80,7 +80,8 @@ enum {
OBJECT_EXTERNAL_RESOURCE=1,
OBJECT_INTERNAL_RESOURCE=2,
OBJECT_EXTERNAL_RESOURCE_INDEX=3,
- FORMAT_VERSION=1,
+ //version 2: added 64 bits support for float and int
+ FORMAT_VERSION=2,
FORMAT_VERSION_CAN_RENAME_DEPS=1
@@ -97,6 +98,27 @@ void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) {
}
+
+StringName ResourceInteractiveLoaderBinary::_get_string() {
+
+ uint32_t id = f->get_32();
+ if (id&0x80000000) {
+ uint32_t len = id&0x7FFFFFFF;
+ if (len>str_buf.size()) {
+ str_buf.resize(len);
+ }
+ if (len==0)
+ return StringName();
+ f->get_buffer((uint8_t*)&str_buf[0],len);
+ String s;
+ s.parse_utf8(&str_buf[0]);
+ return s;
+ }
+
+ return string_map[id];
+
+}
+
Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
@@ -271,8 +293,8 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
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();
+ print_line("image format: "+String(Image::get_format_name(fmt))+" datalen "+itos(datalen));
PoolVector<uint8_t> imgdata;
imgdata.resize(datalen);
@@ -281,6 +303,14 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
_advance_padding(datalen);
w=PoolVector<uint8_t>::Write();
+#ifdef TOOLS_ENABLED
+//compatibility
+ int correct_size = Image::get_image_data_size(width,height,fmt,mipmaps?-1:0);
+ if (correct_size < datalen) {
+ WARN_PRINT("Image data was too large, shrinking for compatibility")
+ imgdata.resize(correct_size);
+ }
+#endif
r_v=Image(width,height,mipmaps,fmt,imgdata);
} else {
@@ -322,10 +352,10 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) {
for(int i=0;i<name_count;i++)
- names.push_back(string_map[f->get_32()]);
+ names.push_back(_get_string());
for(uint32_t i=0;i<subname_count;i++)
- subnames.push_back(string_map[f->get_32()]);
- property=string_map[f->get_32()];
+ subnames.push_back(_get_string());
+ property=_get_string();
NodePath np = NodePath(names,subnames,absolute,property);
//print_line("got path: "+String(np));
@@ -640,6 +670,8 @@ Error ResourceInteractiveLoaderBinary::poll(){
if (s<external_resources.size()) {
String path = external_resources[s].path;
+
+ print_line("load external res: "+path);
if (remaps.has(path)) {
path=remaps[path];
}
@@ -710,6 +742,8 @@ Error ResourceInteractiveLoaderBinary::poll(){
String t = get_unicode_string();
+// print_line("loading resource of type "+t+" path is "+path);
+
Object *obj = ClassDB::instance(t);
if (!obj) {
error=ERR_FILE_CORRUPT;
@@ -736,8 +770,8 @@ Error ResourceInteractiveLoaderBinary::poll(){
for(int i=0;i<pc;i++) {
- uint32_t name_idx = f->get_32();
- if (name_idx>=(uint32_t)string_map.size()) {
+ StringName name = _get_string();
+ if (name==StringName()) {
error=ERR_FILE_CORRUPT;
ERR_FAIL_V(ERR_FILE_CORRUPT);
}
@@ -748,7 +782,7 @@ Error ResourceInteractiveLoaderBinary::poll(){
if (error)
return error;
- res->set(string_map[name_idx],value);
+ res->set(name,value);
}
#ifdef TOOLS_ENABLED
res->set_edited(false);
@@ -758,30 +792,7 @@ Error ResourceInteractiveLoaderBinary::poll(){
resource_cache.push_back(res);
if (main) {
- if (importmd_ofs) {
-
- f->seek(importmd_ofs);
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- imd->set_editor(get_unicode_string());
- int sc = f->get_32();
- for(int i=0;i<sc;i++) {
-
- String src = get_unicode_string();
- String md5 = get_unicode_string();
- imd->add_source(src,md5);
- }
- int pc = f->get_32();
-
- for(int i=0;i<pc;i++) {
-
- String name = get_unicode_string();
- Variant val;
- parse_variant(val);
- imd->set_option(name,val);
- }
- res->set_import_metadata(imd);
- }
f->close();
resource=res;
error=ERR_FILE_EOF;
@@ -848,9 +859,6 @@ void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f,List<Stri
for(int i=0;i<external_resources.size();i++) {
String dep=external_resources[i].path;
- if (dep.ends_with("*")) {
- dep=ResourceLoader::guess_full_filename(dep,external_resources[i].type);
- }
if (p_add_types && external_resources[i].type!=String()) {
dep+="::"+external_resources[i].type;
@@ -1059,7 +1067,7 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(cons
Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
+ //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
ria->open(f);
@@ -1103,53 +1111,6 @@ bool ResourceFormatLoaderBinary::handles_type(const String& p_type) const{
return true; //handles all
}
-Error ResourceFormatLoaderBinary::load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const {
-
-
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
- if (!f) {
- return ERR_FILE_CANT_OPEN;
- }
-
- Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
- ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
- ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
- ria->recognize(f);
- if(ria->error!=OK)
- return ERR_FILE_UNRECOGNIZED;
- f=ria->f;
- uint64_t imp_ofs = f->get_64();
-
- if (imp_ofs==0)
- return ERR_UNAVAILABLE;
-
- f->seek(imp_ofs);
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- imd->set_editor(ria->get_unicode_string());
- int sc = f->get_32();
- for(int i=0;i<sc;i++) {
-
- String src = ria->get_unicode_string();
- String md5 = ria->get_unicode_string();
- imd->add_source(src,md5);
- }
- int pc = f->get_32();
-
- for(int i=0;i<pc;i++) {
-
- String name = ria->get_unicode_string();
- Variant val;
- ria->parse_variant(val);
- imd->set_option(name,val);
- }
-
- r_var=imd;
-
- return OK;
-
-}
-
void ResourceFormatLoaderBinary::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types) {
@@ -1159,14 +1120,14 @@ void ResourceFormatLoaderBinary::get_dependencies(const String& p_path,List<Stri
Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
+ //ria->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);
@@ -1250,7 +1211,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path,const
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();
@@ -1384,7 +1345,7 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const
Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary );
ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path);
ria->res_path=ria->local_path;
-// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
+ //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
String r = ria->recognize(f);
return r;
@@ -1708,8 +1669,10 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property,
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()]);
@@ -2150,7 +2113,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()) {
@@ -2176,30 +2139,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_
}
f->seek_end();
- print_line("SAVING: "+p_path);
- if (p_resource->get_import_metadata().is_valid()) {
- uint64_t md_pos = f->get_pos();
- Ref<ResourceImportMetadata> imd=p_resource->get_import_metadata();
- save_unicode_string(imd->get_editor());
- f->store_32(imd->get_source_count());
- for(int i=0;i<imd->get_source_count();i++) {
- save_unicode_string(imd->get_source_path(i));
- save_unicode_string(imd->get_source_md5(i));
- print_line("SAVE PATH: "+imd->get_source_path(i));
- print_line("SAVE MD5: "+imd->get_source_md5(i));
- }
- List<String> options;
- imd->get_options(&options);
- f->store_32(options.size());
- for(List<String>::Element *E=options.front();E;E=E->next()) {
- save_unicode_string(E->get());
- write_variant(imd->get_option(E->get()));
- }
-
- f->seek(md_at);
- f->store_64(md_pos);
- f->seek_end();
- }
f->store_buffer((const uint8_t*)"RSRC",4); //magic at end
@@ -2237,6 +2176,8 @@ void ResourceFormatSaverBinary::get_recognized_extensions(const RES& p_resource,
String base = p_resource->get_base_extension().to_lower();
p_extensions->push_back(base);
+ if (base!="res")
+ p_extensions->push_back("res");
}
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index 611029e792..1fab6144d5 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -54,6 +54,8 @@ class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
//Map<int,StringName> string_map;
Vector<StringName> string_map;
+ StringName _get_string();
+
struct ExtResoucre {
String path;
String type;
@@ -109,7 +111,6 @@ public:
virtual bool handles_type(const String& p_type) const;
virtual String get_resource_type(const String &p_path) const;
virtual void get_dependencies(const String& p_path, List<String> *p_dependencies, bool p_add_types=false);
- virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const;
virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp
new file mode 100644
index 0000000000..892c2988dc
--- /dev/null
+++ b/core/io/resource_import.cpp
@@ -0,0 +1,259 @@
+#include "resource_import.h"
+#include "variant_parser.h"
+#include "os/os.h"
+
+Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndType &r_path_and_type) const {
+
+ Error err;
+ FileAccess *f= FileAccess::open(p_path+".import",FileAccess::READ,&err);
+
+ if (!f)
+ return err;
+
+ VariantParser::StreamFile stream;
+ stream.f=f;
+
+ String assign;
+ Variant value;
+ VariantParser::Tag next_tag;
+
+ int lines=0;
+ String error_text;
+ while(true) {
+
+ assign=Variant();
+ next_tag.fields.clear();
+ next_tag.name=String();
+
+ err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL,true);
+ if (err==ERR_FILE_EOF) {
+ memdelete(f);
+ return OK;
+ }
+ else if (err!=OK) {
+ ERR_PRINTS("ResourceFormatImporter::load - "+p_path+".import:"+itos(lines)+" error: "+error_text);
+ memdelete(f);
+ return err;
+ }
+
+ if (assign!=String()) {
+ if (assign.begins_with("path.") && r_path_and_type.path==String()) {
+ String feature = assign.get_slicec('.',1);
+ if (OS::get_singleton()->check_feature_support(feature)) {
+ r_path_and_type.path=value;
+ }
+
+ } else if (assign=="path") {
+ r_path_and_type.path=value;
+ } else if (assign=="type") {
+ r_path_and_type.type=value;
+ }
+
+ } else if (next_tag.name!="remap") {
+ break;
+ }
+ }
+
+ memdelete(f);
+
+ if (r_path_and_type.path==String() || r_path_and_type.type==String()) {
+ return ERR_FILE_CORRUPT;
+ }
+ return OK;
+
+}
+
+
+RES ResourceFormatImporter::load(const String &p_path,const String& p_original_path,Error *r_error) {
+
+ PathAndType pat;
+ Error err = _get_path_and_type(p_path,pat);
+
+ if (err!=OK) {
+
+ if (r_error)
+ *r_error=err;
+
+ return RES();
+ }
+
+
+ RES res = ResourceLoader::load(pat.path,pat.type,false,r_error);
+
+#ifdef TOOLS_ENABLED
+ if (res.is_valid()) {
+ res->set_import_last_modified_time( res->get_last_modified_time() ); //pass this, if used
+ res->set_import_path(pat.path);
+ }
+#endif
+
+ return res;
+
+}
+
+void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const{
+
+ Set<String> found;
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (!found.has(F->get())) {
+ p_extensions->push_back(F->get());
+ found.insert(F->get());
+ }
+ }
+ }
+}
+
+void ResourceFormatImporter::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const{
+
+ if (p_type=="") {
+ return get_recognized_extensions(p_extensions);
+ }
+
+ Set<String> found;
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ String res_type = E->get()->get_resource_type();
+ if (res_type==String())
+ continue;
+
+ if (!ClassDB::is_parent_class(res_type,p_type))
+ continue;
+
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (!found.has(F->get())) {
+ p_extensions->push_back(F->get());
+ found.insert(F->get());
+ }
+ }
+ }
+}
+
+bool ResourceFormatImporter::recognize_path(const String& p_path,const String& p_for_type) const{
+
+ return FileAccess::exists(p_path+".import");
+
+}
+
+bool ResourceFormatImporter::can_be_imported(const String& p_path) const {
+
+ return ResourceFormatLoader::recognize_path(p_path);
+}
+
+
+bool ResourceFormatImporter::handles_type(const String& p_type) const {
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+
+ String res_type = E->get()->get_resource_type();
+ if (res_type==String())
+ continue;
+ if (ClassDB::is_parent_class(res_type,p_type))
+ return true;
+
+ }
+
+ return true;
+}
+
+
+String ResourceFormatImporter::get_internal_resource_path(const String& p_path) const {
+
+ PathAndType pat;
+ Error err = _get_path_and_type(p_path,pat);
+
+ if (err!=OK) {
+
+ return String();
+ }
+
+ return pat.path;
+}
+
+String ResourceFormatImporter::get_resource_type(const String &p_path) const {
+
+ PathAndType pat;
+ Error err = _get_path_and_type(p_path,pat);
+
+ if (err!=OK) {
+
+ return "";
+ }
+
+ return pat.type;
+}
+
+void ResourceFormatImporter::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types){
+
+ PathAndType pat;
+ Error err = _get_path_and_type(p_path,pat);
+
+ if (err!=OK) {
+
+ return;
+ }
+
+ return ResourceLoader::get_dependencies(pat.path,p_dependencies,p_add_types);
+}
+
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String& p_name) {
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ if (E->get()->get_importer_name()==p_name) {
+ return E->get();
+ }
+ }
+
+ return Ref<ResourceImporter>();
+}
+
+
+void ResourceFormatImporter::get_importers_for_extension(const String& p_extension,List<Ref<ResourceImporter> > *r_importers) {
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (p_extension.to_lower()==F->get()) {
+ r_importers->push_back(E->get());
+ }
+ }
+ }
+}
+
+Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String& p_extension) {
+
+
+ Ref<ResourceImporter> importer;
+ float priority=0;
+
+ for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) {
+
+ List<String> local_exts;
+ E->get()->get_recognized_extensions(&local_exts);
+ for (List<String>::Element *F=local_exts.front();F;F=F->next()) {
+ if (p_extension.to_lower()==F->get() && E->get()->get_priority() > priority) {
+ importer=E->get();
+ priority=E->get()->get_priority();
+ }
+ }
+ }
+
+ return importer;
+}
+
+String ResourceFormatImporter::get_import_base_path(const String& p_for_file) const {
+
+ return "res://.import/"+p_for_file.get_file()+"-"+p_for_file.md5_text();
+}
+
+ResourceFormatImporter *ResourceFormatImporter::singleton=NULL;
+
+ResourceFormatImporter::ResourceFormatImporter() {
+ singleton=this;
+}
diff --git a/core/io/resource_import.h b/core/io/resource_import.h
new file mode 100644
index 0000000000..387b3902fe
--- /dev/null
+++ b/core/io/resource_import.h
@@ -0,0 +1,77 @@
+#ifndef RESOURCE_IMPORT_H
+#define RESOURCE_IMPORT_H
+
+
+#include "io/resource_loader.h"
+class ResourceImporter;
+
+class ResourceFormatImporter : public ResourceFormatLoader {
+
+ struct PathAndType {
+ String path;
+ String type;
+ };
+
+
+ Error _get_path_and_type(const String& p_path,PathAndType & r_path_and_type) const;
+
+ static ResourceFormatImporter *singleton;
+
+ Set< Ref<ResourceImporter> > importers;
+public:
+
+ static ResourceFormatImporter *get_singleton() { return singleton; }
+ virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
+ virtual bool recognize_path(const String& p_path,const String& p_for_type=String()) const;
+ virtual bool handles_type(const String& p_type) const;
+ virtual String get_resource_type(const String &p_path) const;
+ virtual void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);
+
+ virtual bool can_be_imported(const String& p_path) const;
+
+ String get_internal_resource_path(const String& p_path) const;
+
+ void add_importer(const Ref<ResourceImporter>& p_importer) { importers.insert(p_importer); }
+ Ref<ResourceImporter> get_importer_by_name(const String& p_name);
+ Ref<ResourceImporter> get_importer_by_extension(const String& p_extension);
+ void get_importers_for_extension(const String& p_extension,List<Ref<ResourceImporter> > *r_importers);
+
+ String get_import_base_path(const String& p_for_file) const;
+ ResourceFormatImporter();
+};
+
+
+class ResourceImporter : public Reference {
+
+ GDCLASS(ResourceImporter,Reference)
+public:
+ virtual String get_importer_name() const=0;
+ virtual String get_visible_name() const=0;
+ virtual void get_recognized_extensions(List<String> *p_extensions) const=0;
+ virtual String get_save_extension() const=0;
+ virtual String get_resource_type() const=0;
+ virtual float get_priority() const { return 1.0; }
+
+ struct ImportOption {
+ PropertyInfo option;
+ Variant default_value;
+
+ ImportOption(const PropertyInfo& p_info,const Variant& p_default) { option=p_info; default_value=p_default; }
+ ImportOption() {}
+ };
+
+
+ virtual int get_preset_count() const { return 0; }
+ virtual String get_preset_name(int p_idx) const { return String(); }
+
+ virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const=0;
+ virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const=0;
+
+
+ virtual Error import(const String& p_source_file,const String& p_save_path,const Map<StringName,Variant>& p_options,List<String>* r_platform_variants,List<String>* r_gen_files=NULL)=0;
+
+};
+
+#endif // RESOURCE_IMPORT_H
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index cc3c8ce006..c14389eefa 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "resource_loader.h"
#include "print_string.h"
-#include "globals.h"
+#include "global_config.h"
#include "path_remap.h"
#include "os/file_access.h"
#include "os/os.h"
@@ -47,21 +47,30 @@ Error ResourceInteractiveLoader::wait() {
return err;
}
+bool ResourceFormatLoader::recognize_path(const String& p_path,const String& p_for_type) const {
-bool ResourceFormatLoader::recognize(const String& p_extension) const {
+ String extension = p_path.get_extension();
List<String> extensions;
- get_recognized_extensions(&extensions);
+ if (p_for_type==String()) {
+ get_recognized_extensions(&extensions);
+ } else {
+ get_recognized_extensions_for_type(p_for_type,&extensions);
+ }
+
for (List<String>::Element *E=extensions.front();E;E=E->next()) {
- if (E->get().nocasecmp_to(p_extension.extension())==0)
+
+ if (E->get().nocasecmp_to(extension)==0)
return true;
}
return false;
+
}
+
void ResourceFormatLoader::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const {
if (p_type=="" || handles_type(p_type))
@@ -78,11 +87,11 @@ void ResourceLoader::get_recognized_extensions_for_type(const String& p_type,Lis
void ResourceInteractiveLoader::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("get_resource"),&ResourceInteractiveLoader::get_resource);
+ ClassDB::bind_method(D_METHOD("poll"),&ResourceInteractiveLoader::poll);
+ ClassDB::bind_method(D_METHOD("wait"),&ResourceInteractiveLoader::wait);
+ ClassDB::bind_method(D_METHOD("get_stage"),&ResourceInteractiveLoader::get_stage);
+ ClassDB::bind_method(D_METHOD("get_stage_count"),&ResourceInteractiveLoader::get_stage_count);
}
class ResourceInteractiveLoaderDefault : public ResourceInteractiveLoader {
@@ -166,7 +175,7 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- local_path=find_complete_path(local_path,p_type_hint);
+
ERR_FAIL_COND_V(local_path=="",RES());
if (!p_no_cache && ResourceCache::has(local_path)) {
@@ -177,31 +186,28 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
return RES( ResourceCache::get(local_path ) );
}
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
-
if (OS::get_singleton()->is_stdout_verbose())
- print_line("load resource: "+remapped_path);
-
- String extension=remapped_path.extension();
+ print_line("load resource: "+local_path);
bool found=false;
for (int i=0;i<loader_count;i++) {
- if (!loader[i]->recognize(extension))
- continue;
- if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
+ if (!loader[i]->recognize_path(local_path,p_type_hint)) {
+ print_line("path not recognized");
continue;
+ }
found=true;
- RES res = loader[i]->load(remapped_path,local_path,r_error);
- if (res.is_null())
+ RES res = loader[i]->load(local_path,local_path,r_error);
+ if (res.is_null()) {
continue;
+ }
if (!p_no_cache)
res->set_path(local_path);
#ifdef TOOLS_ENABLED
res->set_edited(false);
if (timestamp_on_load) {
- uint64_t mt = FileAccess::get_modified_time(remapped_path);
+ uint64_t mt = FileAccess::get_modified_time(local_path);
//printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt);
res->set_last_modified_time(mt);
}
@@ -220,82 +226,6 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p
}
-Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p_path) {
-
-
-
- String local_path;
- if (p_path.is_rel_path())
- local_path="res://"+p_path;
- else
- local_path = GlobalConfig::get_singleton()->localize_path(p_path);
-
- String extension=p_path.extension();
- Ref<ResourceImportMetadata> ret;
-
- for (int i=0;i<loader_count;i++) {
-
- if (!loader[i]->recognize(extension))
- continue;
-
- Error err = loader[i]->load_import_metadata(local_path,ret);
- if (err==OK)
- break;
- }
-
-
- return ret;
-
-}
-
-
-
-String ResourceLoader::find_complete_path(const String& p_path,const String& p_type) {
- //this is an old vestige when the engine saved files without extension.
- //remains here for compatibility with old projects and only because it
- //can be sometimes nice to open files using .* from a script and have it guess
- //the right extension.
-
- String local_path = p_path;
- if (local_path.ends_with("*")) {
-
- //find the extension for resource that ends with *
- local_path = local_path.substr(0,local_path.length()-1);
- List<String> extensions;
- get_recognized_extensions_for_type(p_type,&extensions);
- List<String> candidates;
-
- for(List<String>::Element *E=extensions.front();E;E=E->next()) {
-
- String path = local_path+E->get();
-
- if (PathRemap::get_singleton()->has_remap(path) || FileAccess::exists(path)) {
- candidates.push_back(path);
- }
-
- }
-
-
- if (candidates.size()==0) {
- return "";
- } else if (candidates.size()==1 || p_type=="") {
- return candidates.front()->get();
- } else {
-
- for(List<String>::Element *E=candidates.front();E;E=E->next()) {
-
- String rt = get_resource_type(E->get());
- if (ClassDB::is_parent_class(rt,p_type)) {
- return E->get();
- }
- }
-
- return "";
- }
- }
-
- return local_path;
-}
Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path,const String& p_type_hint,bool p_no_cache,Error *r_error) {
@@ -309,7 +239,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- local_path=find_complete_path(local_path,p_type_hint);
+
ERR_FAIL_COND_V(local_path=="",Ref<ResourceInteractiveLoader>());
@@ -329,19 +259,14 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
if (OS::get_singleton()->is_stdout_verbose())
print_line("load resource: ");
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
-
- String extension=remapped_path.extension();
bool found=false;
for (int i=0;i<loader_count;i++) {
- if (!loader[i]->recognize(extension))
- continue;
- if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
+ if (!loader[i]->recognize_path(local_path,p_type_hint))
continue;
found=true;
- Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(remapped_path,r_error);
+ Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(local_path,r_error);
if (ril.is_null())
continue;
if (!p_no_cache)
@@ -383,18 +308,16 @@ void ResourceLoader::get_dependencies(const String& p_path, List<String> *p_depe
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
-
- String extension=remapped_path.extension();
-
for (int i=0;i<loader_count;i++) {
- if (!loader[i]->recognize(extension))
+ if (!loader[i]->recognize_path(local_path))
+ continue;
+ /*
+ if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
- //if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
- // continue;
+ */
- loader[i]->get_dependencies(remapped_path,p_dependencies,p_add_types);
+ loader[i]->get_dependencies(local_path,p_dependencies,p_add_types);
}
}
@@ -408,18 +331,17 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String,
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
-
- String extension=remapped_path.extension();
for (int i=0;i<loader_count;i++) {
- if (!loader[i]->recognize(extension))
+ if (!loader[i]->recognize_path(local_path))
+ continue;
+ /*
+ if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
- //if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
- // continue;
+ */
- return loader[i]->rename_dependencies(p_path,p_map);
+ return loader[i]->rename_dependencies(local_path,p_map);
}
@@ -428,17 +350,6 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String,
}
-String ResourceLoader::guess_full_filename(const String &p_path,const String& p_type) {
-
- String local_path;
- if (p_path.is_rel_path())
- local_path="res://"+p_path;
- else
- local_path = GlobalConfig::get_singleton()->localize_path(p_path);
-
- return find_complete_path(local_path,p_type);
-
-}
String ResourceLoader::get_resource_type(const String &p_path) {
@@ -448,8 +359,6 @@ String ResourceLoader::get_resource_type(const String &p_path) {
else
local_path = GlobalConfig::get_singleton()->localize_path(p_path);
- String remapped_path = PathRemap::get_singleton()->get_remap(local_path);
- String extension=remapped_path.extension();
for (int i=0;i<loader_count;i++) {
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 7979bd02a7..f464415e12 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -61,11 +61,10 @@ public:
virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const=0;
virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const;
- bool recognize(const String& p_extension) const;
+ virtual bool recognize_path(const String& p_path,const String& p_for_type=String()) const;
virtual bool handles_type(const String& p_type) const=0;
virtual String get_resource_type(const String &p_path) const=0;
virtual void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);
- virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const { return ERR_UNAVAILABLE; }
virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map) { return OK; }
virtual ~ResourceFormatLoader() {}
@@ -92,14 +91,12 @@ class ResourceLoader {
static DependencyErrorNotify dep_err_notify;
static bool abort_on_missing_resource;
- static String find_complete_path(const String& p_path,const String& p_type);
public:
static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL);
static RES load(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL);
- static Ref<ResourceImportMetadata> load_import_metadata(const String &p_path);
static void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions);
static void add_resource_format_loader(ResourceFormatLoader *p_format_loader,bool p_at_front=false);
@@ -107,8 +104,6 @@ public:
static void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false);
static Error rename_dependencies(const String &p_path,const Map<String,String>& p_map);
- static String guess_full_filename(const String &p_path,const String& p_type);
-
static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load=p_timestamp; }
static void notify_load_error(const String& p_err) { if (err_notify) err_notify(err_notify_ud,p_err); }
@@ -122,4 +117,6 @@ public:
static bool get_abort_on_missing_resources() { return abort_on_missing_resource; }
};
+
+
#endif
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 9081adaa8f..f0bea30051 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "resource_saver.h"
-#include "globals.h"
+#include "global_config.h"
#include "os/file_access.h"
#include "script_language.h"
#include "resource_loader.h"
@@ -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;
}
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index a2812edb81..3c4719269f 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -389,57 +389,57 @@ Variant StreamPeer::get_var(){
void StreamPeer::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("put_data","data"),&StreamPeer::_put_data);
+ ClassDB::bind_method(D_METHOD("put_partial_data","data"),&StreamPeer::_put_partial_data);
+
+ ClassDB::bind_method(D_METHOD("get_data","bytes"),&StreamPeer::_get_data);
+ ClassDB::bind_method(D_METHOD("get_partial_data","bytes"),&StreamPeer::_get_partial_data);
+
+ ClassDB::bind_method(D_METHOD("get_available_bytes"),&StreamPeer::get_available_bytes);
+
+ ClassDB::bind_method(D_METHOD("set_big_endian","enable"),&StreamPeer::set_big_endian);
+ ClassDB::bind_method(D_METHOD("is_big_endian_enabled"),&StreamPeer::is_big_endian_enabled);
+
+ ClassDB::bind_method(D_METHOD("put_8","val"),&StreamPeer::put_8);
+ ClassDB::bind_method(D_METHOD("put_u8","val"),&StreamPeer::put_u8);
+ ClassDB::bind_method(D_METHOD("put_16","val"),&StreamPeer::put_16);
+ ClassDB::bind_method(D_METHOD("put_u16","val"),&StreamPeer::put_u16);
+ ClassDB::bind_method(D_METHOD("put_32","val"),&StreamPeer::put_32);
+ ClassDB::bind_method(D_METHOD("put_u32","val"),&StreamPeer::put_u32);
+ ClassDB::bind_method(D_METHOD("put_64","val"),&StreamPeer::put_64);
+ ClassDB::bind_method(D_METHOD("put_u64","val"),&StreamPeer::put_u64);
+ ClassDB::bind_method(D_METHOD("put_float","val"),&StreamPeer::put_float);
+ ClassDB::bind_method(D_METHOD("put_double","val"),&StreamPeer::put_double);
+ ClassDB::bind_method(D_METHOD("put_utf8_string","val"),&StreamPeer::put_utf8_string);
+ ClassDB::bind_method(D_METHOD("put_var","val:Variant"),&StreamPeer::put_var);
+
+ ClassDB::bind_method(D_METHOD("get_8"),&StreamPeer::get_8);
+ ClassDB::bind_method(D_METHOD("get_u8"),&StreamPeer::get_u8);
+ ClassDB::bind_method(D_METHOD("get_16"),&StreamPeer::get_16);
+ ClassDB::bind_method(D_METHOD("get_u16"),&StreamPeer::get_u16);
+ ClassDB::bind_method(D_METHOD("get_32"),&StreamPeer::get_32);
+ ClassDB::bind_method(D_METHOD("get_u32"),&StreamPeer::get_u32);
+ ClassDB::bind_method(D_METHOD("get_64"),&StreamPeer::get_64);
+ ClassDB::bind_method(D_METHOD("get_u64"),&StreamPeer::get_u64);
+ ClassDB::bind_method(D_METHOD("get_float"),&StreamPeer::get_float);
+ ClassDB::bind_method(D_METHOD("get_double"),&StreamPeer::get_double);
+ ClassDB::bind_method(D_METHOD("get_string","bytes"),&StreamPeer::get_string);
+ ClassDB::bind_method(D_METHOD("get_utf8_string","bytes"),&StreamPeer::get_utf8_string);
+ ClassDB::bind_method(D_METHOD("get_var:Variant"),&StreamPeer::get_var);
}
////////////////////////////////
void StreamPeerBuffer::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("seek","pos"),&StreamPeerBuffer::seek);
+ ClassDB::bind_method(D_METHOD("get_size"),&StreamPeerBuffer::get_size);
+ ClassDB::bind_method(D_METHOD("get_pos"),&StreamPeerBuffer::get_pos);
+ ClassDB::bind_method(D_METHOD("resize","size"),&StreamPeerBuffer::resize);
+ ClassDB::bind_method(D_METHOD("set_data_array","data"),&StreamPeerBuffer::set_data_array);
+ ClassDB::bind_method(D_METHOD("get_data_array"),&StreamPeerBuffer::get_data_array);
+ ClassDB::bind_method(D_METHOD("clear"),&StreamPeerBuffer::clear);
+ ClassDB::bind_method(D_METHOD("duplicate:StreamPeerBuffer"),&StreamPeerBuffer::duplicate);
}
@@ -492,6 +492,8 @@ Error StreamPeerBuffer::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_r
PoolVector<uint8_t>::Read r = data.read();
copymem(p_buffer,r.ptr(),r_received);
+
+ // FIXME: return what? OK or ERR_*
}
int StreamPeerBuffer::get_available_bytes() const {
diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp
index aab42a2989..5f7247bd7a 100644
--- a/core/io/stream_peer_ssl.cpp
+++ b/core/io/stream_peer_ssl.cpp
@@ -57,10 +57,10 @@ bool StreamPeerSSL::is_available() {
void StreamPeerSSL::_bind_methods() {
- ClassDB::bind_method(_MD("accept:Error","stream:StreamPeer"),&StreamPeerSSL::accept);
- ClassDB::bind_method(_MD("connect:Error","stream:StreamPeer","validate_certs","for_hostname"),&StreamPeerSSL::connect,DEFVAL(false),DEFVAL(String()));
- ClassDB::bind_method(_MD("get_status"),&StreamPeerSSL::get_status);
- ClassDB::bind_method(_MD("disconnect"),&StreamPeerSSL::disconnect);
+ ClassDB::bind_method(D_METHOD("accept_stream:Error","stream:StreamPeer"),&StreamPeerSSL::accept_stream);
+ ClassDB::bind_method(D_METHOD("connect_to_stream:Error","stream:StreamPeer","validate_certs","for_hostname"),&StreamPeerSSL::connect_to_stream,DEFVAL(false),DEFVAL(String()));
+ ClassDB::bind_method(D_METHOD("get_status"),&StreamPeerSSL::get_status);
+ ClassDB::bind_method(D_METHOD("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 8675433a30..9aafac874d 100644
--- a/core/io/stream_peer_ssl.h
+++ b/core/io/stream_peer_ssl.h
@@ -57,11 +57,11 @@ 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();
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index 2218057cf7..cedc33079e 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -36,29 +36,23 @@ Error StreamPeerTCP::_connect(const String& p_address,int p_port) {
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())
+ ip=IP::get_singleton()->resolve_hostname(p_address);
+ if (!ip.is_valid())
return ERR_CANT_RESOLVE;
}
- connect(ip,p_port);
+ connect_to_host(ip,p_port);
return OK;
}
-void StreamPeerTCP::set_ip_type(IP::Type p_type) {
- disconnect();
- ip_type = p_type;
-}
-
void StreamPeerTCP::_bind_methods() {
- ClassDB::bind_method(_MD("set_ip_type","ip_type"),&StreamPeerTCP::set_ip_type);
- ClassDB::bind_method(_MD("connect","host","port"),&StreamPeerTCP::_connect);
- ClassDB::bind_method(_MD("is_connected"),&StreamPeerTCP::is_connected);
- 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"),&StreamPeerTCP::disconnect);
+ ClassDB::bind_method(D_METHOD("connect_to_host","host","port"),&StreamPeerTCP::_connect);
+ ClassDB::bind_method(D_METHOD("is_connected_to_host"),&StreamPeerTCP::is_connected_to_host);
+ ClassDB::bind_method(D_METHOD("get_status"),&StreamPeerTCP::get_status);
+ ClassDB::bind_method(D_METHOD("get_connected_host"),&StreamPeerTCP::get_connected_host);
+ ClassDB::bind_method(D_METHOD("get_connected_port"),&StreamPeerTCP::get_connected_port);
+ ClassDB::bind_method(D_METHOD("disconnect_from_host"),&StreamPeerTCP::disconnect_from_host);
BIND_CONSTANT( STATUS_NONE );
BIND_CONSTANT( STATUS_CONNECTING );
@@ -83,7 +77,6 @@ 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 8f6dfaf3f8..4401378743 100644
--- a/core/io/stream_peer_tcp.h
+++ b/core/io/stream_peer_tcp.h
@@ -51,22 +51,19 @@ 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 void set_ip_type(IP::Type p_type);
- virtual Error connect(const IP_Address& p_host, uint16_t p_port)=0;
+ 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 bfa5dce58f..5127bd6e3b 100644
--- a/core/io/tcp_server.cpp
+++ b/core/io/tcp_server.cpp
@@ -44,33 +44,17 @@ TCP_Server* TCP_Server::create() {
return _create();
}
-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);
-
-}
-
-void TCP_Server::set_ip_type(IP::Type p_type) {
- stop();
- ip_type = p_type;
-}
-
void TCP_Server::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("listen","port","bind_address"),&TCP_Server::listen,DEFVAL("*"));
+ ClassDB::bind_method(D_METHOD("is_connection_available"),&TCP_Server::is_connection_available);
+ ClassDB::bind_method(D_METHOD("take_connection"),&TCP_Server::take_connection);
+ ClassDB::bind_method(D_METHOD("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 3d7b3ddd8d..3cbd8c58cf 100644
--- a/core/io/tcp_server.h
+++ b/core/io/tcp_server.h
@@ -38,17 +38,13 @@ class TCP_Server : public Reference {
GDCLASS( TCP_Server, Reference );
protected:
- IP::Type ip_type;
-
static TCP_Server* (*_create)();
//bind helper
- Error _listen(uint16_t p_port, PoolVector<String> p_accepted_hosts=PoolVector<String>());
static void _bind_methods();
public:
- 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 Error listen(uint16_t p_port, const IP_Address p_bind_address=IP_Address("*"))=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 8c4c1c8180..bee38e037f 100644
--- a/core/io/translation_loader_po.cpp
+++ b/core/io/translation_loader_po.cpp
@@ -204,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/xml_parser.cpp b/core/io/xml_parser.cpp
index 0322f23056..1a4ff1a8d4 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -379,23 +379,23 @@ Error XMLParser::seek(uint64_t p_pos) {
void XMLParser::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("read"),&XMLParser::read);
+ ClassDB::bind_method(D_METHOD("get_node_type"),&XMLParser::get_node_type);
+ ClassDB::bind_method(D_METHOD("get_node_name"),&XMLParser::get_node_name);
+ ClassDB::bind_method(D_METHOD("get_node_data"),&XMLParser::get_node_data);
+ ClassDB::bind_method(D_METHOD("get_node_offset"),&XMLParser::get_node_offset);
+ ClassDB::bind_method(D_METHOD("get_attribute_count"),&XMLParser::get_attribute_count);
+ ClassDB::bind_method(D_METHOD("get_attribute_name","idx"),&XMLParser::get_attribute_name);
+ ClassDB::bind_method(D_METHOD("get_attribute_value","idx"),(String (XMLParser::*)(int) const) &XMLParser::get_attribute_value);
+ ClassDB::bind_method(D_METHOD("has_attribute","name"),&XMLParser::has_attribute);
+ ClassDB::bind_method(D_METHOD("get_named_attribute_value","name"), (String (XMLParser::*)(const String&) const) &XMLParser::get_attribute_value);
+ ClassDB::bind_method(D_METHOD("get_named_attribute_value_safe","name"), &XMLParser::get_attribute_value_safe);
+ ClassDB::bind_method(D_METHOD("is_empty"),&XMLParser::is_empty);
+ ClassDB::bind_method(D_METHOD("get_current_line"),&XMLParser::get_current_line);
+ ClassDB::bind_method(D_METHOD("skip_section"),&XMLParser::skip_section);
+ ClassDB::bind_method(D_METHOD("seek","pos"),&XMLParser::seek);
+ ClassDB::bind_method(D_METHOD("open","file"),&XMLParser::open);
+ ClassDB::bind_method(D_METHOD("open_buffer","buffer"),&XMLParser::open_buffer);
BIND_CONSTANT( NODE_NONE );
BIND_CONSTANT( NODE_ELEMENT );
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/map.h b/core/map.h
index af35fec332..d1a4c209ad 100644
--- a/core/map.h
+++ b/core/map.h
@@ -149,7 +149,7 @@ private:
#ifdef GLOBALNIL_DISABLED
memdelete_allocator<Element,A>(_nil);
#endif
-// memdelete_allocator<Element,A>(_root);
+ //memdelete_allocator<Element,A>(_root);
}
};
@@ -428,7 +428,7 @@ private:
Element *aux=node->parent->left;
if (aux->color==RED) {
_set_color(aux,BLACK);
- _set_color(node->parent,RED);;
+ _set_color(node->parent,RED);
_rotate_right(node->parent);
aux=node->parent->left;
}
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 0d6997183f..7e31957e3e 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* a_star.cpp */
+/* a_star.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -39,7 +39,7 @@ int AStar::get_available_point_id() const {
return points.back()->key()+1;
}
-void AStar::add_point(int p_id, const Vector3 &p_pos, float p_weight_scale) {
+void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
ERR_FAIL_COND(p_id<0);
if (!points.has(p_id)) {
Point *pt = memnew( Point );
@@ -62,7 +62,7 @@ Vector3 AStar::get_point_pos(int p_id) const{
return points[p_id]->pos;
}
-float AStar::get_point_weight_scale(int p_id) const{
+real_t AStar::get_point_weight_scale(int p_id) const{
ERR_FAIL_COND_V(!points.has(p_id),0);
@@ -145,11 +145,11 @@ void AStar::clear(){
int AStar::get_closest_point(const Vector3& p_point) const{
int closest_id=-1;
- float closest_dist=1e20;
+ real_t closest_dist=1e20;
for (const Map<int,Point*>::Element *E=points.front();E;E=E->next()) {
- float d = p_point.distance_squared_to(E->get()->pos);
+ real_t d = p_point.distance_squared_to(E->get()->pos);
if (closest_id<0 || d<closest_dist) {
closest_dist=d;
closest_id=E->key();
@@ -162,7 +162,7 @@ int AStar::get_closest_point(const Vector3& p_point) const{
}
Vector3 AStar::get_closest_pos_in_segment(const Vector3& p_point) const {
- float closest_dist = 1e20;
+ real_t closest_dist = 1e20;
bool found=false;
Vector3 closest_point;
@@ -175,7 +175,7 @@ Vector3 AStar::get_closest_pos_in_segment(const Vector3& p_point) const {
};
Vector3 p = Geometry::get_closest_point_to_segment(p_point,segment);
- float d = p_point.distance_squared_to(p);
+ real_t d = p_point.distance_squared_to(p);
if (!found || d<closest_dist) {
closest_point=p;
@@ -220,14 +220,14 @@ bool AStar::_solve(Point* begin_point, Point* end_point) {
//check open list
SelfList<Point> *least_cost_point=NULL;
- float least_cost=1e30;
+ real_t least_cost=1e30;
//this could be faster (cache previous results)
for (SelfList<Point> *E=open_list.first();E;E=E->next()) {
Point *p=E->self();
- float cost=p->distance;
+ real_t cost=p->distance;
cost+=p->pos.distance_to(end_point->pos);
cost*=p->weight_scale;
@@ -249,7 +249,7 @@ bool AStar::_solve(Point* begin_point, Point* end_point) {
Point* e=p->neighbours[i];
- float distance = p->pos.distance_to(e->pos) + p->distance;
+ real_t distance = p->pos.distance_to(e->pos) + p->distance;
distance*=e->weight_scale;
@@ -407,23 +407,23 @@ PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
void AStar::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("get_available_point_id"),&AStar::get_available_point_id);
+ ClassDB::bind_method(D_METHOD("add_point","id","pos","weight_scale"),&AStar::add_point,DEFVAL(1.0));
+ ClassDB::bind_method(D_METHOD("get_point_pos","id"),&AStar::get_point_pos);
+ ClassDB::bind_method(D_METHOD("get_point_weight_scale","id"),&AStar::get_point_weight_scale);
+ ClassDB::bind_method(D_METHOD("remove_point","id"),&AStar::remove_point);
- 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);
+ ClassDB::bind_method(D_METHOD("connect_points","id","to_id"),&AStar::connect_points);
+ ClassDB::bind_method(D_METHOD("disconnect_points","id","to_id"),&AStar::disconnect_points);
+ ClassDB::bind_method(D_METHOD("are_points_connected","id","to_id"),&AStar::are_points_connected);
- ClassDB::bind_method(_MD("clear"),&AStar::clear);
+ ClassDB::bind_method(D_METHOD("clear"),&AStar::clear);
- 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);
+ ClassDB::bind_method(D_METHOD("get_closest_point","to_pos"),&AStar::get_closest_point);
+ ClassDB::bind_method(D_METHOD("get_closest_pos_in_segment","to_pos"),&AStar::get_closest_pos_in_segment);
- 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);
+ ClassDB::bind_method(D_METHOD("get_point_path","from_id","to_id"),&AStar::get_point_path);
+ ClassDB::bind_method(D_METHOD("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 35e6ead226..c4c955ed2d 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -48,14 +48,14 @@ class AStar: public Reference {
int id;
Vector3 pos;
- float weight_scale;
+ real_t weight_scale;
uint64_t last_pass;
Vector<Point*> neighbours;
//used for pathfinding
Point *prev_point;
- float distance;
+ real_t distance;
Point() : list(this) {}
};
@@ -98,9 +98,9 @@ public:
int get_available_point_id() const;
- void add_point(int p_id,const Vector3& p_pos,float p_weight_scale=1);
+ void add_point(int p_id,const Vector3& p_pos,real_t p_weight_scale=1);
Vector3 get_point_pos(int p_id) const;
- float get_point_weight_scale(int p_id) const;
+ real_t get_point_weight_scale(int p_id) const;
void remove_point(int p_id);
void connect_points(int p_id,int p_with_id);
diff --git a/core/math/audio_frame.cpp b/core/math/audio_frame.cpp
new file mode 100644
index 0000000000..566ba23992
--- /dev/null
+++ b/core/math/audio_frame.cpp
@@ -0,0 +1,2 @@
+#include "audio_frame.h"
+
diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h
new file mode 100644
index 0000000000..acd74903bb
--- /dev/null
+++ b/core/math/audio_frame.h
@@ -0,0 +1,61 @@
+#ifndef AUDIOFRAME_H
+#define AUDIOFRAME_H
+
+#include "typedefs.h"
+
+
+static inline float undenormalise(volatile float f)
+{
+ union {
+ uint32_t i;
+ float f;
+ } v;
+
+ v.f = f;
+
+ // original: return (v.i & 0x7f800000) == 0 ? 0.0f : f;
+ // version from Tim Blechmann:
+ return (v.i & 0x7f800000) < 0x08000000 ? 0.0f : f;
+}
+
+
+struct AudioFrame {
+
+ //left and right samples
+ float l,r;
+
+ _ALWAYS_INLINE_ const float& operator[](int idx) const { return idx==0?l:r; }
+ _ALWAYS_INLINE_ float& operator[](int idx) { return idx==0?l:r; }
+
+ _ALWAYS_INLINE_ AudioFrame operator+(const AudioFrame& p_frame) const { return AudioFrame(l+p_frame.l,r+p_frame.r); }
+ _ALWAYS_INLINE_ AudioFrame operator-(const AudioFrame& p_frame) const { return AudioFrame(l-p_frame.l,r-p_frame.r); }
+ _ALWAYS_INLINE_ AudioFrame operator*(const AudioFrame& p_frame) const { return AudioFrame(l*p_frame.l,r*p_frame.r); }
+ _ALWAYS_INLINE_ AudioFrame operator/(const AudioFrame& p_frame) const { return AudioFrame(l/p_frame.l,r/p_frame.r); }
+
+ _ALWAYS_INLINE_ AudioFrame operator+(float p_sample) const { return AudioFrame(l+p_sample,r+p_sample); }
+ _ALWAYS_INLINE_ AudioFrame operator-(float p_sample) const { return AudioFrame(l-p_sample,r-p_sample); }
+ _ALWAYS_INLINE_ AudioFrame operator*(float p_sample) const { return AudioFrame(l*p_sample,r*p_sample); }
+ _ALWAYS_INLINE_ AudioFrame operator/(float p_sample) const { return AudioFrame(l/p_sample,r/p_sample); }
+
+ _ALWAYS_INLINE_ void operator+=(const AudioFrame& p_frame) { l+=p_frame.l; r+=p_frame.r; }
+ _ALWAYS_INLINE_ void operator-=(const AudioFrame& p_frame) { l-=p_frame.l; r-=p_frame.r; }
+ _ALWAYS_INLINE_ void operator*=(const AudioFrame& p_frame) { l*=p_frame.l; r*=p_frame.r; }
+ _ALWAYS_INLINE_ void operator/=(const AudioFrame& p_frame) { l/=p_frame.l; r/=p_frame.r; }
+
+ _ALWAYS_INLINE_ void operator+=(float p_sample) { l+=p_sample; r+=p_sample; }
+ _ALWAYS_INLINE_ void operator-=(float p_sample) { l-=p_sample; r-=p_sample; }
+ _ALWAYS_INLINE_ void operator*=(float p_sample) { l*=p_sample; r*=p_sample; }
+ _ALWAYS_INLINE_ void operator/=(float p_sample) { l/=p_sample; r/=p_sample; }
+
+ _ALWAYS_INLINE_ void undenormalise() {
+ l = ::undenormalise(l);
+ r = ::undenormalise(r);
+ }
+
+ _ALWAYS_INLINE_ AudioFrame(float p_l, float p_r) {l=p_l; r=p_r;}
+ _ALWAYS_INLINE_ AudioFrame(const AudioFrame& p_frame) {l=p_frame.l; r=p_frame.r;}
+
+ _ALWAYS_INLINE_ AudioFrame() {}
+};
+
+#endif
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index b888b6b56c..1ca6385032 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -87,8 +87,8 @@ int BSP_Tree::_get_points_inside(int p_node,const Vector3* p_points,int *p_indic
max+=p_center;
min+=p_center;
- float dist_min = p.distance_to(min);
- float dist_max = p.distance_to(max);
+ real_t dist_min = p.distance_to(min);
+ real_t dist_max = p.distance_to(max);
if ((dist_min * dist_max) < CMP_EPSILON ) { //intersection, test point by point
@@ -290,13 +290,13 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const {
}
-static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,float p_tolerance) {
+static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,real_t p_tolerance) {
int ic = p_indices.size();
const int*indices=p_indices.ptr();
int best_plane = -1;
- float best_plane_cost = 1e20;
+ real_t best_plane_cost = 1e20;
// Loop to find the polygon that best divides the set.
@@ -317,7 +317,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
for(int k=0;k<3;k++) {
- float d = p.distance_to(g.vertex[j]);
+ real_t d = p.distance_to(g.vertex[j]);
if (Math::abs(d)>p_tolerance) {
@@ -340,13 +340,13 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
- //double split_cost = num_spanning / (double) face_count;
- double relation = Math::abs(num_over-num_under) / (double) ic;
+ //real_t split_cost = num_spanning / (real_t) face_count;
+ real_t relation = Math::abs(num_over-num_under) / (real_t) ic;
// being honest, i never found a way to add split cost to the mix in a meaninguful way
// in this engine, also, will likely be ignored anyway
- double plane_cost = /*split_cost +*/ relation;
+ real_t plane_cost = /*split_cost +*/ relation;
//printf("plane %i, %i over, %i under, %i spanning, cost is %g\n",i,num_over,num_under,num_spanning,plane_cost);
if (plane_cost<best_plane_cost) {
@@ -362,7 +362,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
}
-static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,float p_tolerance) {
+static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,real_t p_tolerance) {
ERR_FAIL_COND_V( p_nodes.size() == BSP_Tree::MAX_NODES, -1 );
@@ -390,15 +390,17 @@ 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;
for(int j=0;j<3;j++) {
- float d = divisor_plane.distance_to(f.vertex[j]);
+ real_t d = divisor_plane.distance_to(f.vertex[j]);
if (Math::abs(d)>p_tolerance) {
if (d > 0)
@@ -471,7 +473,7 @@ BSP_Tree::operator Variant() const {
Dictionary d;
d["error_radius"]=error_radius;
- Vector<float> plane_values;
+ Vector<real_t> plane_values;
plane_values.resize(planes.size()*4);
for(int i=0;i<planes.size();i++) {
@@ -520,13 +522,13 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
if (d["planes"].get_type()==Variant::POOL_REAL_ARRAY) {
- PoolVector<float> src_planes=d["planes"];
+ PoolVector<real_t> src_planes=d["planes"];
int plane_count=src_planes.size();
ERR_FAIL_COND(plane_count%4);
planes.resize(plane_count/4);
if (plane_count) {
- PoolVector<float>::Read r = src_planes.read();
+ PoolVector<real_t>::Read r = src_planes.read();
for(int i=0;i<plane_count/4;i++) {
planes[i].normal.x=r[i*4+0];
@@ -546,7 +548,7 @@ 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);
PoolVector<int>::Read r = src_nodes.read();
@@ -560,7 +562,7 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
}
-BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) {
+BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,real_t p_error_radius) {
// compute aabb
@@ -613,7 +615,7 @@ BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) {
error_radius=p_error_radius;
}
-BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,float p_error_radius) {
+BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,real_t p_error_radius) {
nodes=p_nodes;
planes=p_planes;
diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h
index e01df96555..c0071438db 100644
--- a/core/math/bsp_tree.h
+++ b/core/math/bsp_tree.h
@@ -30,7 +30,7 @@
#define BSP_TREE_H
#include "plane.h"
-#include "aabb.h"
+#include "rect3.h"
#include "face3.h"
#include "vector.h"
#include "dvector.h"
@@ -66,7 +66,7 @@ private:
Vector<Node> nodes;
Vector<Plane> planes;
Rect3 aabb;
- float error_radius;
+ real_t error_radius;
int _get_points_inside(int p_node,const Vector3* p_points,int *p_indices, const Vector3& p_center,const Vector3& p_half_extents,int p_indices_count) const;
@@ -91,8 +91,8 @@ public:
BSP_Tree();
BSP_Tree(const Variant& p_variant);
- BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius=0);
- BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,float p_error_radius=0);
+ BSP_Tree(const PoolVector<Face3>& p_faces,real_t p_error_radius=0);
+ BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,real_t p_error_radius=0);
~BSP_Tree();
};
@@ -110,7 +110,7 @@ bool BSP_Tree::_test_convex(const Node* p_nodes, const Plane* p_planes,int p_cur
const Plane& p=p_planes[n.plane];
- float min,max;
+ real_t min,max;
p_convex.project_range(p.normal,min,max);
bool go_under = min < p.d;
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index c44ff4682a..3b47a75c65 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -65,15 +65,15 @@ Plane CameraMatrix::xform4(const Plane& p_vec4) const {
return ret;
}
-void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p_z_near, float p_z_far,bool p_flip_fov) {
+void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far,bool p_flip_fov) {
if (p_flip_fov) {
p_fovy_degrees=get_fovy(p_fovy_degrees,1.0/p_aspect);
}
- float sine, cotangent, deltaZ;
- float radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
+ real_t sine, cotangent, deltaZ;
+ real_t radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
deltaZ = p_z_far - p_z_near;
sine = Math::sin(radians);
@@ -94,7 +94,7 @@ void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p
}
-void CameraMatrix::set_orthogonal(float p_left, float p_right, float p_bottom, float p_top, float p_znear, float p_zfar) {
+void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
set_identity();
@@ -109,7 +109,7 @@ void CameraMatrix::set_orthogonal(float p_left, float p_right, float p_bottom, f
}
-void CameraMatrix::set_orthogonal(float p_size, float p_aspect, float p_znear, float p_zfar,bool p_flip_fov) {
+void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar,bool p_flip_fov) {
if (!p_flip_fov) {
p_size*=p_aspect;
@@ -120,7 +120,7 @@ void CameraMatrix::set_orthogonal(float p_size, float p_aspect, float p_znear, f
-void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, float p_top, float p_near, float p_far) {
+void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
#if 0
///@TODO, give a check to this. I'm not sure if it's working.
set_identity();
@@ -134,19 +134,31 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa
matrix[3][2]=-1;
matrix[3][3]=0;
#else
- float *te = &matrix[0][0];
- float x = 2 * p_near / ( p_right - p_left );
- float y = 2 * p_near / ( p_top - p_bottom );
-
- float a = ( p_right + p_left ) / ( p_right - p_left );
- float b = ( p_top + p_bottom ) / ( p_top - p_bottom );
- float c = - ( p_far + p_near ) / ( p_far - p_near );
- float d = - 2 * p_far * p_near / ( p_far - p_near );
-
- te[0] = x; te[4] = 0; te[8] = a; te[12] = 0;
- te[1] = 0; te[5] = y; te[9] = b; te[13] = 0;
- te[2] = 0; te[6] = 0; te[10] = c; te[14] = d;
- te[3] = 0; te[7] = 0; te[11] = - 1; te[15] = 0;
+ real_t *te = &matrix[0][0];
+ real_t x = 2 * p_near / ( p_right - p_left );
+ real_t y = 2 * p_near / ( p_top - p_bottom );
+
+ real_t a = ( p_right + p_left ) / ( p_right - p_left );
+ real_t b = ( p_top + p_bottom ) / ( p_top - p_bottom );
+ real_t c = - ( p_far + p_near ) / ( p_far - p_near );
+ real_t d = - 2 * p_far * p_near / ( p_far - p_near );
+
+ te[0] = x;
+ te[1] = 0;
+ te[2] = 0;
+ te[3] = 0;
+ te[4] = 0;
+ te[5] = y;
+ te[6] = 0;
+ te[7] = 0;
+ te[8] = a;
+ te[9] = b;
+ te[10] = c;
+ te[11] = -1;
+ te[12] = 0;
+ te[13] = 0;
+ te[14] = d;
+ te[15] = 0;
#endif
@@ -154,9 +166,9 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa
-float CameraMatrix::get_z_far() const {
+real_t CameraMatrix::get_z_far() const {
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
Plane new_plane=Plane(matrix[ 3] - matrix[ 2],
matrix[ 7] - matrix[ 6],
matrix[11] - matrix[10],
@@ -167,9 +179,9 @@ float CameraMatrix::get_z_far() const {
return new_plane.d;
}
-float CameraMatrix::get_z_near() const {
+real_t CameraMatrix::get_z_near() const {
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
Plane new_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
@@ -179,25 +191,28 @@ float CameraMatrix::get_z_near() const {
return new_plane.d;
}
-void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const {
+void CameraMatrix::get_viewport_size(real_t& r_width, real_t& r_height) const {
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
- -matrix[15] - matrix[14]).normalized();
+ -matrix[15] - matrix[14]);
+ near_plane.normalize();
///////--- Right Plane ---///////
Plane right_plane=Plane(matrix[ 3] - matrix[ 0],
matrix[ 7] - matrix[ 4],
matrix[11] - matrix[ 8],
- - matrix[15] + matrix[12]).normalized();
+ - matrix[15] + matrix[12]);
+ right_plane.normalize();
Plane top_plane=Plane(matrix[ 3] - matrix[ 1],
matrix[ 7] - matrix[ 5],
matrix[11] - matrix[ 9],
- -matrix[15] + matrix[13]).normalized();
+ -matrix[15] + matrix[13]);
+ top_plane.normalize();
Vector3 res;
near_plane.intersect_3(right_plane,top_plane,&res);
@@ -208,32 +223,35 @@ void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const {
bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8points) const {
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
- -matrix[15] - matrix[14]).normalized();
+ -matrix[15] - matrix[14]);
+ near_plane.normalize();
///////--- Far Plane ---///////
Plane far_plane=Plane(matrix[ 2] - matrix[ 3],
matrix[ 6] - matrix[ 7],
matrix[10] - matrix[11],
- matrix[15] - matrix[14]).normalized();
-
+ matrix[15] - matrix[14]);
+ far_plane.normalize();
///////--- Right Plane ---///////
Plane right_plane=Plane(matrix[ 0] - matrix[ 3],
matrix[ 4] - matrix[ 7],
matrix[8] - matrix[ 11],
- - matrix[15] + matrix[12]).normalized();
+ - matrix[15] + matrix[12]);
+ right_plane.normalize();
///////--- Top Plane ---///////
Plane top_plane=Plane(matrix[ 1] - matrix[ 3],
matrix[ 5] - matrix[ 7],
matrix[9] - matrix[ 11],
- -matrix[15] + matrix[13]).normalized();
+ -matrix[15] + matrix[13]);
+ top_plane.normalize();
Vector3 near_endpoint;
Vector3 far_endpoint;
@@ -266,7 +284,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
Vector<Plane> planes;
- const float * matrix = (const float*)this->matrix;
+ const real_t * matrix = (const real_t*)this->matrix;
Plane new_plane;
@@ -359,9 +377,9 @@ void CameraMatrix::invert() {
int i,j,k;
int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */
- float pvt_val; /* Value of current pivot element */
- float hold; /* Temporary storage */
- float determinat; /* Determinant */
+ real_t pvt_val; /* Value of current pivot element */
+ real_t hold; /* Temporary storage */
+ real_t determinat; /* Determinant */
determinat = 1.0;
for (k=0; k<4; k++) {
@@ -474,7 +492,7 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix& p_matrix) const {
void CameraMatrix::set_light_bias() {
- float *m=&matrix[0][0];
+ real_t *m=&matrix[0][0];
m[0]=0.5,
m[1]=0.0,
@@ -497,7 +515,7 @@ void CameraMatrix::set_light_bias() {
void CameraMatrix::set_light_atlas_rect(const Rect2& p_rect) {
- float *m=&matrix[0][0];
+ real_t *m=&matrix[0][0];
m[0]=p_rect.size.width,
m[1]=0.0,
@@ -527,9 +545,9 @@ CameraMatrix::operator String() const {
return str;
}
-float CameraMatrix::get_aspect() const {
+real_t CameraMatrix::get_aspect() const {
- float w,h;
+ real_t w,h;
get_viewport_size(w,h);
return w/h;
}
@@ -543,13 +561,14 @@ int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const {
}
-float CameraMatrix::get_fov() const {
- const float * matrix = (const float*)this->matrix;
+real_t CameraMatrix::get_fov() const {
+ const real_t * matrix = (const real_t*)this->matrix;
Plane right_plane=Plane(matrix[ 3] - matrix[ 0],
matrix[ 7] - matrix[ 4],
matrix[11] - matrix[ 8],
- - matrix[15] + matrix[12]).normalized();
+ - matrix[15] + matrix[12]);
+ right_plane.normalize();
return Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x)))*2.0;
}
@@ -594,7 +613,7 @@ void CameraMatrix::scale_translate_to_fit(const Rect3& p_aabb) {
CameraMatrix::operator Transform() const {
Transform tr;
- const float *m=&matrix[0][0];
+ const real_t *m=&matrix[0][0];
tr.basis.elements[0][0]=m[0];
tr.basis.elements[1][0]=m[1];
@@ -618,7 +637,7 @@ CameraMatrix::operator Transform() const {
CameraMatrix::CameraMatrix(const Transform& p_transform) {
const Transform &tr = p_transform;
- float *m=&matrix[0][0];
+ real_t *m=&matrix[0][0];
m[0]=tr.basis.elements[0][0];
m[1]=tr.basis.elements[1][0];
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index 952f1e8fb2..c96f8259b5 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -48,32 +48,32 @@ struct CameraMatrix {
PLANE_BOTTOM
};
- float matrix[4][4];
+ real_t matrix[4][4];
void set_identity();
void set_zero();
void set_light_bias();
void set_light_atlas_rect(const Rect2& p_rect);
- void set_perspective(float p_fovy_degrees, float p_aspect, float p_z_near, float p_z_far,bool p_flip_fov=false);
- void set_orthogonal(float p_left, float p_right, float p_bottom, float p_top, float p_znear, float p_zfar);
- void set_orthogonal(float p_size, float p_aspect, float p_znear, float p_zfar,bool p_flip_fov=false);
- void set_frustum(float p_left, float p_right, float p_bottom, float p_top, float p_near, float p_far);
+ void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far,bool p_flip_fov=false);
+ void set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar);
+ void set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar,bool p_flip_fov=false);
+ void set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far);
- static float get_fovy(float p_fovx,float p_aspect) {
+ static real_t get_fovy(real_t p_fovx,real_t p_aspect) {
return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5))*2.0);
}
- float get_z_far() const;
- float get_z_near() const;
- float get_aspect() const;
- float get_fov() const;
+ real_t get_z_far() const;
+ real_t get_z_near() const;
+ real_t get_aspect() const;
+ real_t get_fov() const;
Vector<Plane> get_projection_planes(const Transform& p_transform) const;
bool get_endpoints(const Transform& p_transform,Vector3 *p_8points) const;
- void get_viewport_size(float& r_width, float& r_height) const;
+ void get_viewport_size(real_t& r_width, real_t& r_height) const;
void invert();
CameraMatrix inverse() const;
@@ -102,7 +102,7 @@ Vector3 CameraMatrix::xform(const Vector3& p_vec3) const {
ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0];
ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1];
ret.z = matrix[0][2] * p_vec3.x + matrix[1][2] * p_vec3.y + matrix[2][2] * p_vec3.z + matrix[3][2];
- float w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3];
+ real_t w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3];
return ret/w;
}
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index faf124593e..60fab6748a 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -168,8 +168,8 @@ Face3::Side Face3::get_side_of(const Face3& p_face,ClockDirection p_clock_dir) c
Vector3 Face3::get_random_point_inside() const {
- float a=Math::random(0,1);
- float b=Math::random(0,1);
+ real_t a=Math::random(0,1);
+ real_t b=Math::random(0,1);
if (a>b) {
SWAP(a,b);
}
@@ -215,9 +215,9 @@ bool Face3::intersects_aabb(const Rect3& p_aabb) const {
#define TEST_AXIS(m_ax)\
{\
- float aabb_min=p_aabb.pos.m_ax;\
- float aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
- float tri_min,tri_max;\
+ real_t aabb_min=p_aabb.pos.m_ax;\
+ real_t aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
+ real_t tri_min,tri_max;\
for (int i=0;i<3;i++) {\
if (i==0 || vertex[i].m_ax > tri_max)\
tri_max=vertex[i].m_ax;\
@@ -255,7 +255,7 @@ bool Face3::intersects_aabb(const Rect3& p_aabb) const {
continue; // coplanar
axis.normalize();
- float minA,maxA,minB,maxB;
+ real_t minA,maxA,minB,maxB;
p_aabb.project_range_in_plane(Plane(axis,0),minA,maxA);
project_range(axis,Transform(),minB,maxB);
@@ -272,12 +272,12 @@ Face3::operator String() const {
return String()+vertex[0]+", "+vertex[1]+", "+vertex[2];
}
-void Face3::project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const {
+void Face3::project_range(const Vector3& p_normal,const Transform& p_transform,real_t& r_min, real_t& r_max) const {
for (int i=0;i<3;i++) {
Vector3 v=p_transform.xform(vertex[i]);
- float d=p_normal.dot(v);
+ real_t d=p_normal.dot(v);
if (i==0 || d > r_max)
r_max=d;
@@ -316,11 +316,11 @@ void Face3::get_support(const Vector3& p_normal,const Transform& p_transform,Vec
/** FIND SUPPORT VERTEX **/
int vert_support_idx=-1;
- float support_max;
+ real_t support_max;
for (int i=0;i<3;i++) {
- float d=n.dot(vertex[i]);
+ real_t d=n.dot(vertex[i]);
if (i==0 || d > support_max) {
support_max=d;
@@ -336,7 +336,7 @@ void Face3::get_support(const Vector3& p_normal,const Transform& p_transform,Vec
continue;
// check if edge is valid as a support
- float dot=(vertex[i]-vertex[(i+1)%3]).normalized().dot(n);
+ real_t dot=(vertex[i]-vertex[(i+1)%3]).normalized().dot(n);
dot=ABS(dot);
if (dot < _EDGE_IS_VALID_SUPPORT_TRESHOLD) {
@@ -362,15 +362,15 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
Vector3 edge1 = vertex[2] - vertex[0];
Vector3 v0 = vertex[0] - p_point;
- float a = edge0.dot( edge0 );
- float b = edge0.dot( edge1 );
- float c = edge1.dot( edge1 );
- float d = edge0.dot( v0 );
- float e = edge1.dot( v0 );
+ real_t a = edge0.dot( edge0 );
+ real_t b = edge0.dot( edge1 );
+ real_t c = edge1.dot( edge1 );
+ real_t d = edge0.dot( v0 );
+ real_t e = edge1.dot( v0 );
- float det = a*c - b*b;
- float s = b*e - c*d;
- float t = b*d - a*e;
+ real_t det = a*c - b*b;
+ real_t s = b*e - c*d;
+ real_t t = b*d - a*e;
if ( s + t < det )
{
@@ -402,7 +402,7 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
}
else
{
- float invDet = 1.f / det;
+ real_t invDet = 1.f / det;
s *= invDet;
t *= invDet;
}
@@ -411,12 +411,12 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
{
if ( s < 0.f )
{
- float tmp0 = b+d;
- float tmp1 = c+e;
+ real_t tmp0 = b+d;
+ real_t tmp1 = c+e;
if ( tmp1 > tmp0 )
{
- float numer = tmp1 - tmp0;
- float denom = a-2*b+c;
+ real_t numer = tmp1 - tmp0;
+ real_t denom = a-2*b+c;
s = CLAMP( numer/denom, 0.f, 1.f );
t = 1-s;
}
@@ -430,8 +430,8 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
{
if ( a+d > b+e )
{
- float numer = c+e-b-d;
- float denom = a-2*b+c;
+ real_t numer = c+e-b-d;
+ real_t denom = a-2*b+c;
s = CLAMP( numer/denom, 0.f, 1.f );
t = 1-s;
}
@@ -443,8 +443,8 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
}
else
{
- float numer = c+e-b-d;
- float denom = a-2*b+c;
+ real_t numer = c+e-b-d;
+ real_t denom = a-2*b+c;
s = CLAMP( numer/denom, 0.f, 1.f );
t = 1.f - s;
}
diff --git a/core/math/face3.h b/core/math/face3.h
index f08eb227b1..a0da588ea5 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -31,7 +31,7 @@
#include "vector3.h"
#include "plane.h"
-#include "aabb.h"
+#include "rect3.h"
#include "transform.h"
class Face3 {
@@ -76,7 +76,7 @@ public:
ClockDirection get_clock_dir() const; ///< todo, test if this is returning the proper clockwisity
void get_support(const Vector3& p_normal,const Transform& p_transform,Vector3 *p_vertices,int* p_count,int p_max) const;
- void project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const;
+ void project_range(const Vector3& p_normal,const Transform& p_transform,real_t& r_min, real_t& r_max) const;
Rect3 get_aabb() const {
@@ -109,9 +109,9 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
(perp.z>0) ? -half_extents.z : half_extents.z
);
- float d = perp.dot(vertex[0]);
- float dist_a = perp.dot(ofs+sup)-d;
- float dist_b = perp.dot(ofs-sup)-d;
+ real_t d = perp.dot(vertex[0]);
+ real_t dist_a = perp.dot(ofs+sup)-d;
+ real_t dist_b = perp.dot(ofs-sup)-d;
if (dist_a*dist_b > 0)
return false; //does not intersect the plane
@@ -119,9 +119,9 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
#define TEST_AXIS(m_ax)\
{\
- float aabb_min=p_aabb.pos.m_ax;\
- float aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
- float tri_min,tri_max;\
+ real_t aabb_min=p_aabb.pos.m_ax;\
+ real_t aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
+ real_t tri_min,tri_max;\
for (int i=0;i<3;i++) {\
if (i==0 || vertex[i].m_ax > tri_max)\
tri_max=vertex[i].m_ax;\
@@ -236,16 +236,16 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
(axis.z>0) ? -half_extents.z : half_extents.z
);
- float maxB = axis.dot(ofs+sup2);
- float minB = axis.dot(ofs-sup2);
+ real_t maxB = axis.dot(ofs+sup2);
+ real_t minB = axis.dot(ofs-sup2);
if (minB>maxB) {
SWAP(maxB,minB);
}
- float minT=1e20,maxT=-1e20;
+ real_t minT=1e20,maxT=-1e20;
for (int k=0;k<3;k++) {
- float d=axis.dot(vertex[k]);
+ real_t d=axis.dot(vertex[k]);
if (d > maxT)
maxT=d;
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index bf3364a052..6570dfe672 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -580,7 +580,7 @@ static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int l
}
-PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,float *p_error ) {
+PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,real_t *p_error ) {
#define _MIN_SIZE 1.0
#define _MAX_LENGTH 20
@@ -755,7 +755,7 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector<Plane> &p_planes
#define SUBPLANE_SIZE 1024.0
- float subplane_size = 1024.0; // should compute this from the actual plane
+ real_t subplane_size = 1024.0; // should compute this from the actual plane
for (int i=0;i<p_planes.size();i++) {
Plane p =p_planes[i];
@@ -910,7 +910,7 @@ PoolVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) {
return planes;
}
-PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
+PoolVector<Plane> Geometry::build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis) {
PoolVector<Plane> planes;
@@ -933,7 +933,7 @@ PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height
}
-PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) {
+PoolVector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) {
PoolVector<Plane> planes;
@@ -957,7 +957,7 @@ PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p
for (int j=1;j<=p_lats;j++) {
//todo this is stupid, fix
- Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized();
+ Vector3 angle = normal.linear_interpolate(axis,j/(real_t)p_lats).normalized();
Vector3 pos = angle*p_radius;
planes.push_back( Plane( pos, angle ) );
planes.push_back( Plane( pos * axis_neg, angle * axis_neg) );
@@ -969,7 +969,7 @@ PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p
}
-PoolVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
+PoolVector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
PoolVector<Plane> planes;
@@ -991,7 +991,7 @@ PoolVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height,
for (int j=1;j<=p_lats;j++) {
- Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized();
+ Vector3 angle = normal.linear_interpolate(axis,j/(real_t)p_lats).normalized();
Vector3 pos = axis*p_height*0.5 + angle*p_radius;
planes.push_back( Plane( pos, angle ) );
planes.push_back( Plane( pos * axis_neg, angle * axis_neg) );
@@ -1108,13 +1108,13 @@ void Geometry::make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_resul
//find the result with the best aspect ratio
int best=-1;
- float best_aspect=1e20;
+ real_t best_aspect=1e20;
for(int i=0;i<results.size();i++) {
- float h = nearest_power_of_2(results[i].max_h);
- float w = nearest_power_of_2(results[i].max_w);
- float aspect = h>w ? h/w : w/h;
+ real_t h = nearest_power_of_2(results[i].max_h);
+ real_t w = nearest_power_of_2(results[i].max_w);
+ real_t aspect = h>w ? h/w : w/h;
if (aspect < best_aspect) {
best=i;
best_aspect=aspect;
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 9800e5513c..1dd7df038d 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -48,15 +48,15 @@ public:
- static float get_closest_points_between_segments( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2, Vector2& c1, Vector2& c2) {
+ static real_t get_closest_points_between_segments( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2, Vector2& c1, Vector2& c2) {
Vector2 d1 = q1 - p1; // Direction vector of segment S1
Vector2 d2 = q2 - p2; // Direction vector of segment S2
Vector2 r = p1 - p2;
- float a = d1.dot(d1); // Squared length of segment S1, always nonnegative
- float e = d2.dot(d2); // Squared length of segment S2, always nonnegative
- float f = d2.dot(r);
- float s,t;
+ real_t a = d1.dot(d1); // Squared length of segment S1, always nonnegative
+ real_t e = d2.dot(d2); // Squared length of segment S2, always nonnegative
+ real_t f = d2.dot(r);
+ real_t s,t;
// Check if either or both segments degenerate into points
if (a <= CMP_EPSILON && e <= CMP_EPSILON) {
// Both segments degenerate into points
@@ -66,25 +66,25 @@ public:
}
if (a <= CMP_EPSILON) {
// First segment degenerates into a point
- s = 0.0f;
+ s = 0.0;
t = f / e; // s = 0 => t = (b*s + f) / e = f / e
- t = CLAMP(t, 0.0f, 1.0f);
+ t = CLAMP(t, 0.0, 1.0);
} else {
- float c = d1.dot(r);
+ real_t c = d1.dot(r);
if (e <= CMP_EPSILON) {
// Second segment degenerates into a point
- t = 0.0f;
- s = CLAMP(-c / a, 0.0f, 1.0f); // t = 0 => s = (b*t - c) / a = -c / a
+ t = 0.0;
+ s = CLAMP(-c / a, 0.0, 1.0); // t = 0 => s = (b*t - c) / a = -c / a
} else {
// The general nondegenerate case starts here
- float b = d1.dot(d2);
- float denom = a*e-b*b; // Always nonnegative
+ real_t b = d1.dot(d2);
+ real_t denom = a*e-b*b; // Always nonnegative
// If segments not parallel, compute closest point on L1 to L2 and
// clamp to segment S1. Else pick arbitrary s (here 0)
- if (denom != 0.0f) {
- s = CLAMP((b*f - c*e) / denom, 0.0f, 1.0f);
+ if (denom != 0.0) {
+ s = CLAMP((b*f - c*e) / denom, 0.0, 1.0);
} else
- s = 0.0f;
+ s = 0.0;
// Compute point on L2 closest to S1(s) using
// t = Dot((P1 + D1*s) - P2,D2) / Dot(D2,D2) = (b*s + f) / e
t = (b*s + f) / e;
@@ -92,12 +92,12 @@ public:
//If t in [0,1] done. Else clamp t, recompute s for the new value
// of t using s = Dot((P2 + D2*t) - P1,D1) / Dot(D1,D1)= (t*b - c) / a
// and clamp s to [0, 1]
- if (t < 0.0f) {
- t = 0.0f;
- s = CLAMP(-c / a, 0.0f, 1.0f);
- } else if (t > 1.0f) {
- t = 1.0f;
- s = CLAMP((b - c) / a, 0.0f, 1.0f);
+ if (t < 0.0) {
+ t = 0.0;
+ s = CLAMP(-c / a, 0.0, 1.0);
+ } else if (t > 1.0) {
+ t = 1.0;
+ s = CLAMP((b - c) / a, 0.0, 1.0);
}
}
}
@@ -109,12 +109,13 @@ public:
static void get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2,Vector3& c1, Vector3& c2)
{
+#if 0
//do the function 'd' as defined by pb. I think is is dot product of some sort
#define d_of(m,n,o,p) ( (m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z) )
//caluclate the parpametric position on the 2 curves, mua and mub
- float mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) );
- float mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1);
+ real_t mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) );
+ real_t mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1);
//clip the value between [0..1] constraining the solution to lie on the original curves
if (mua < 0) mua = 0;
@@ -123,9 +124,36 @@ public:
if (mub > 1) mub = 1;
c1 = p1.linear_interpolate(p2,mua);
c2 = q1.linear_interpolate(q2,mub);
+#endif
+
+ Vector3 u = p2 - p1;
+ Vector3 v = q2 - q1;
+ Vector3 w = p1 - q1;
+ float a = u.dot(u);
+ float b = u.dot(v);
+ float c = v.dot(v); // always >= 0
+ float d = u.dot(w);
+ float e = v.dot(w);
+ float D = a*c - b*b; // always >= 0
+ float sc, tc;
+
+ // compute the line parameters of the two closest points
+ if (D < CMP_EPSILON) { // the lines are almost parallel
+ sc = 0.0;
+ tc = (b>c ? d/b : e/c); // use the largest denominator
+ }
+ else {
+ sc = (b*e - c*d) / D;
+ tc = (a*e - b*d) / D;
+ }
+
+ c1 = w + sc * u;
+ c2 = w + tc * v;
+ // get the difference of the two closest points
+ //Vector dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc)
}
- static float get_closest_distance_between_segments( const Vector3& p_from_a,const Vector3& p_to_a, const Vector3& p_from_b,const Vector3& p_to_b) {
+ static real_t get_closest_distance_between_segments( const Vector3& p_from_a,const Vector3& p_to_a, const Vector3& p_from_b,const Vector3& p_to_b) {
Vector3 u = p_to_a - p_from_a;
Vector3 v = p_to_b - p_from_b;
Vector3 w = p_from_a - p_to_a;
@@ -273,22 +301,22 @@ public:
Vector3 sphere_pos=p_sphere_pos-p_from;
Vector3 rel=(p_to-p_from);
- float rel_l=rel.length();
+ real_t rel_l=rel.length();
if (rel_l<CMP_EPSILON)
return false; // both points are the same
Vector3 normal=rel/rel_l;
- float sphere_d=normal.dot(sphere_pos);
+ real_t sphere_d=normal.dot(sphere_pos);
//Vector3 ray_closest=normal*sphere_d;
- float ray_distance=sphere_pos.distance_to(normal*sphere_d);
+ real_t ray_distance=sphere_pos.distance_to(normal*sphere_d);
if (ray_distance>=p_sphere_radius)
return false;
- float inters_d2=p_sphere_radius*p_sphere_radius - ray_distance*ray_distance;
- float inters_d=sphere_d;
+ real_t inters_d2=p_sphere_radius*p_sphere_radius - ray_distance*ray_distance;
+ real_t inters_d=sphere_d;
if (inters_d2>=CMP_EPSILON)
inters_d-=Math::sqrt(inters_d2);
@@ -297,7 +325,7 @@ public:
if (inters_d<0 || inters_d>rel_l)
return false;
- Vector3 result=p_from+normal*inters_d;;
+ Vector3 result=p_from+normal*inters_d;
if (r_res)
*r_res=result;
@@ -307,17 +335,17 @@ public:
return true;
}
- static inline bool segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius,Vector3* r_res=0,Vector3 *r_norm=0) {
+ static inline bool segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, real_t p_height,real_t p_radius,Vector3* r_res=0,Vector3 *r_norm=0) {
Vector3 rel=(p_to-p_from);
- float rel_l=rel.length();
+ real_t rel_l=rel.length();
if (rel_l<CMP_EPSILON)
return false; // both points are the same
// first check if they are parallel
Vector3 normal=(rel/rel_l);
Vector3 crs = normal.cross(Vector3(0,0,1));
- float crs_l=crs.length();
+ real_t crs_l=crs.length();
Vector3 z_dir;
@@ -328,13 +356,13 @@ public:
z_dir=crs/crs_l;
}
- float dist=z_dir.dot(p_from);
+ real_t dist=z_dir.dot(p_from);
if (dist>=p_radius)
return false; // too far away
// convert to 2D
- float w2=p_radius*p_radius-dist*dist;
+ real_t w2=p_radius*p_radius-dist*dist;
if (w2<CMP_EPSILON)
return false; //avoid numerical error
Size2 size(Math::sqrt(w2),p_height*0.5);
@@ -344,7 +372,7 @@ public:
Vector2 from2D(x_dir.dot(p_from),p_from.z);
Vector2 to2D(x_dir.dot(p_to),p_to.z);
- float min=0,max=1;
+ real_t min=0,max=1;
int axis=-1;
@@ -464,12 +492,12 @@ public:
Vector3 p=p_point-p_segment[0];
Vector3 n=p_segment[1]-p_segment[0];
- float l =n.length();
+ real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
- float d=n.dot(p);
+ real_t d=n.dot(p);
if (d<=0.0)
return p_segment[0]; // before first point
@@ -483,12 +511,12 @@ public:
Vector3 p=p_point-p_segment[0];
Vector3 n=p_segment[1]-p_segment[0];
- float l =n.length();
+ real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
- float d=n.dot(p);
+ real_t d=n.dot(p);
return p_segment[0]+n*d; // inside
}
@@ -497,12 +525,12 @@ public:
Vector2 p=p_point-p_segment[0];
Vector2 n=p_segment[1]-p_segment[0];
- float l =n.length();
+ real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
- float d=n.dot(p);
+ real_t d=n.dot(p);
if (d<=0.0)
return p_segment[0]; // before first point
@@ -529,12 +557,12 @@ public:
Vector2 p=p_point-p_segment[0];
Vector2 n=p_segment[1]-p_segment[0];
- float l =n.length();
+ real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
- float d=n.dot(p);
+ real_t d=n.dot(p);
return p_segment[0]+n*d; // inside
}
@@ -555,7 +583,7 @@ public:
if ((C.y<0 && D.y<0) || (C.y>=0 && D.y>=0))
return false;
- float ABpos=D.x+(C.x-D.x)*D.y/(D.y-C.y);
+ real_t ABpos=D.x+(C.x-D.x)*D.y/(D.y-C.y);
// Fail if segment C-D crosses line A-B outside of segment A-B.
if (ABpos<0 || ABpos>1.0)
@@ -595,7 +623,7 @@ public:
static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle,const Vector3& p_normal,const Vector3& p_sphere_pos, real_t p_sphere_radius,Vector3& r_triangle_contact,Vector3& r_sphere_contact) {
- float d=p_normal.dot(p_sphere_pos)-p_normal.dot(p_triangle[0]);
+ real_t d=p_normal.dot(p_sphere_pos)-p_normal.dot(p_triangle[0]);
if (d > p_sphere_radius || d < -p_sphere_radius) // not touching the plane of the face, return
return false;
@@ -629,7 +657,7 @@ public:
Vector3 axis =n1.cross(n2).cross(n1);
axis.normalize(); // ugh
- float ad=axis.dot(n2);
+ real_t ad=axis.dot(n2);
if (ABS(ad)>p_sphere_radius) {
// no chance with this edge, too far away
@@ -639,7 +667,7 @@ public:
// check point within edge capsule cylinder
/** 4th TEST INSIDE EDGE POINTS **/
- float sphere_at = n1.dot(n2);
+ real_t sphere_at = n1.dot(n2);
if (sphere_at>=0 && sphere_at<n1.dot(n1)) {
@@ -650,7 +678,7 @@ public:
return true;
}
- float r2=p_sphere_radius*p_sphere_radius;
+ real_t r2=p_sphere_radius*p_sphere_radius;
if (n2.length_squared()<r2) {
@@ -726,8 +754,8 @@ public:
int outside_count = 0;
for (int a = 0; a < polygon.size(); a++) {
- //float p_plane.d = (*this) * polygon[a];
- float dist = p_plane.distance_to(polygon[a]);
+ //real_t p_plane.d = (*this) * polygon[a];
+ real_t dist = p_plane.distance_to(polygon[a]);
if (dist <-CMP_POINT_IN_PLANE_EPSILON) {
location_cache[a] = LOC_INSIDE;
inside_count++;
@@ -750,9 +778,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++) {
@@ -763,8 +789,8 @@ public:
const Vector3& v2 = polygon[index];
Vector3 segment= v1 - v2;
- double den=p_plane.normal.dot( segment );
- double dist=p_plane.distance_to( v1 ) / den;
+ real_t den=p_plane.normal.dot( segment );
+ real_t dist=p_plane.distance_to( v1 ) / den;
dist=-dist;
clipped.push_back( v1 + segment * dist );
}
@@ -773,8 +799,8 @@ public:
if ((loc == LOC_INSIDE) && (location_cache[previous] == LOC_OUTSIDE)) {
const Vector3& v2 = polygon[previous];
Vector3 segment= v1 - v2;
- double den=p_plane.normal.dot( segment );
- double dist=p_plane.distance_to( v1 ) / den;
+ real_t den=p_plane.normal.dot( segment );
+ real_t dist=p_plane.distance_to( v1 ) / den;
dist=-dist;
clipped.push_back( v1 + segment * dist );
}
@@ -810,7 +836,7 @@ public:
static PoolVector< PoolVector< Face3 > > separate_objects( PoolVector< Face3 > p_array );
- static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, float *p_error=NULL ); ///< create a "wrap" that encloses the given geometry
+ static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, real_t *p_error=NULL ); ///< create a "wrap" that encloses the given geometry
struct MeshData {
@@ -886,9 +912,9 @@ public:
}
- static double vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B)
+ static real_t vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B)
{
- return (double)(A.x - O.x) * (B.y - O.y) - (double)(A.y - O.y) * (B.x - O.x);
+ return (real_t)(A.x - O.x) * (B.y - O.y) - (real_t)(A.y - O.y) * (B.x - O.x);
}
// Returns a list of points on the convex hull in counter-clockwise order.
@@ -920,10 +946,10 @@ public:
}
static MeshData build_convex_mesh(const PoolVector<Plane> &p_planes);
- static PoolVector<Plane> build_sphere_planes(float p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z);
+ static PoolVector<Plane> build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z);
static PoolVector<Plane> build_box_planes(const Vector3& p_extents);
- static PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
- static PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
+ static PoolVector<Plane> build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
+ static PoolVector<Plane> build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
static void make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, Size2i& r_size);
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp
index c6860ba2e8..76eeece688 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -239,10 +239,10 @@ Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, co
real_t t3 = t2 * t;
Vector2 out;
- out = 0.5f * ( ( p1 * 2.0f) +
+ out = 0.5 * ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
- ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 +
- ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 );
+ ( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 +
+ ( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 );
return out;
/*
diff --git a/core/math/math_2d.h b/core/math/math_2d.h
index 7896299c24..a24c4266ee 100644
--- a/core/math/math_2d.h
+++ b/core/math/math_2d.h
@@ -154,7 +154,7 @@ struct Vector2 {
Vector2 floor() const;
Vector2 snapped(const Vector2& p_by) const;
- real_t get_aspect() const { return width/height; }
+ real_t aspect() const { return width/height; }
operator String() const { return String::num(x)+", "+String::num(y); }
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 8353aa0ebe..c730b4fa30 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -27,12 +27,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "math_funcs.h"
-
#include "core/os/os.h"
-#include "float.h"
-uint32_t Math::default_seed=1;
-
+pcg32_random_t Math::default_pcg = {1, PCG_DEFAULT_INC_64};
#define PHI 0x9e3779b9
@@ -40,59 +37,30 @@ uint32_t Math::default_seed=1;
static uint32_t Q[4096];
#endif
-uint32_t Math::rand_from_seed(uint32_t *seed) {
- // Xorshift31 PRNG
- if ( *seed == 0 ) *seed = Math::RANDOM_MAX;
- (*seed) ^= (*seed) << 13;
- (*seed) ^= (*seed) >> 17;
- (*seed) ^= (*seed) << 5;
- return (*seed) & Math::RANDOM_MAX;
+// TODO: we should eventually expose pcg.inc too
+uint32_t Math::rand_from_seed(uint64_t *seed) {
+ pcg32_random_t pcg = {*seed, PCG_DEFAULT_INC_64};
+ uint32_t r = pcg32_random_r(&pcg);
+ *seed = pcg.state;
+ return r;
}
-void Math::seed(uint32_t x) {
- default_seed=x;
+void Math::seed(uint64_t x) {
+ default_pcg.state=x;
}
void Math::randomize() {
OS::Time time = OS::get_singleton()->get_time();
- seed(OS::get_singleton()->get_ticks_usec()*(time.hour+1)*(time.min+1)*(time.sec+1)*rand()); /* *OS::get_singleton()->get_time().sec); // windows doesn't have get_time(), returns always 0 */
+ seed(OS::get_singleton()->get_ticks_usec()*(time.hour+1)*(time.min+1)*(time.sec+1)*rand()); // TODO: can be simplified.
}
uint32_t Math::rand() {
-
- return rand_from_seed(&default_seed);
-}
-
-double Math::randf() {
-
- return (double)rand() / (double)Math::RANDOM_MAX;
-}
-
-
-double Math::round(double p_val) {
-
- if (p_val>=0) {
- return ::floor(p_val+0.5);
- } else {
- p_val=-p_val;
- return -::floor(p_val+0.5);
- }
-}
-
-double Math::dectime(double p_value,double p_amount, double p_step) {
-
- float sgn = p_value < 0 ? -1.0 : 1.0;
- float val = absf(p_value);
- val-=p_amount*p_step;
- if (val<0.0)
- val=0.0;
- return val*sgn;
+ return pcg32_random_r(&default_pcg);
}
int Math::step_decimals(double p_step) {
-
static const int maxn=9;
static const double sd[maxn]={
0.9999, // somehow compensate for floating point error
@@ -106,7 +74,7 @@ int Math::step_decimals(double p_step) {
0.000000009999
};
- double as=absf(p_step);
+ double as=Math::abs(p_step);
for(int i=0;i<maxn;i++) {
if (as>=sd[i]) {
return i;
@@ -116,8 +84,16 @@ int Math::step_decimals(double p_step) {
return maxn;
}
-double Math::ease(double p_x, double p_c) {
+double Math::dectime(double p_value,double p_amount, double p_step) {
+ double sgn = p_value < 0 ? -1.0 : 1.0;
+ double val = Math::abs(p_value);
+ val-=p_amount*p_step;
+ if (val<0.0)
+ val=0.0;
+ return val*sgn;
+}
+double Math::ease(double p_x, double p_c) {
if (p_x<0)
p_x=0;
else if (p_x>1.0)
@@ -138,20 +114,16 @@ double Math::ease(double p_x, double p_c) {
}
} else
return 0; // no ease (raw)
-
}
double Math::stepify(double p_value,double p_step) {
-
if (p_step!=0) {
-
- p_value=floor( p_value / p_step + 0.5 ) * p_step;
+ p_value=Math::floor( p_value / p_step + 0.5 ) * p_step;
}
return p_value;
}
-
uint32_t Math::larger_prime(uint32_t p_val) {
static const uint32_t primes[] = {
@@ -200,22 +172,15 @@ uint32_t Math::larger_prime(uint32_t p_val) {
}
double Math::random(double from, double to) {
-
unsigned int r = Math::rand();
double ret = (double)r/(double)RANDOM_MAX;
return (ret)*(to-from) + from;
}
-double Math::pow(double x, double y) {
-
- return ::pow(x,y);
+float Math::random(float from, float to) {
+ unsigned int r = Math::rand();
+ float ret = (float)r/(float)RANDOM_MAX;
+ return (ret)*(to-from) + from;
}
-double Math::log(double x) {
-
- return ::log(x);
-}
-double Math::exp(double x) {
- return ::exp(x);
-}
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 8ce59224ff..ae461eda2e 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -31,169 +31,145 @@
#include "typedefs.h"
#include "math_defs.h"
+#include "pcg.h"
-#ifndef NO_MATH_H
#include <math.h>
-#endif
-
+#include <float.h>
+
#define Math_PI 3.14159265358979323846
#define Math_SQRT12 0.7071067811865475244008443621048490
+#define Math_LN2 0.693147180559945309417
+#define Math_INF INFINITY
+#define Math_NAN NAN
class Math {
+ static pcg32_random_t default_pcg;
- static uint32_t default_seed;
public:
Math() {} // useless to instance
enum {
- RANDOM_MAX=2147483647L
+ RANDOM_MAX=4294967295L
};
- static _ALWAYS_INLINE_ double sin(double p_x) {
-
- return ::sin(p_x);
-
- }
-
- static _ALWAYS_INLINE_ double cos(double p_x) {
-
- return ::cos(p_x);
-
- }
-
- static _ALWAYS_INLINE_ double tan(double p_x) {
-
- return ::tan(p_x);
-
- }
- static _ALWAYS_INLINE_ double sinh(double p_x) {
-
- return ::sinh(p_x);
- }
-
- static _ALWAYS_INLINE_ double cosh(double p_x) {
-
- return ::cosh(p_x);
- }
-
- static _ALWAYS_INLINE_ double tanh(double p_x) {
-
- return ::tanh(p_x);
- }
+ static _ALWAYS_INLINE_ double sin(double p_x) { return ::sin(p_x); }
+ static _ALWAYS_INLINE_ float sin(float p_x) { return ::sinf(p_x); }
+ static _ALWAYS_INLINE_ double cos(double p_x) { return ::cos(p_x); }
+ static _ALWAYS_INLINE_ float cos(float p_x) { return ::cosf(p_x); }
- static _ALWAYS_INLINE_ double asin(double p_x) {
+ static _ALWAYS_INLINE_ double tan(double p_x) { return ::tan(p_x); }
+ static _ALWAYS_INLINE_ float tan(float p_x) { return ::tanf(p_x); }
- return ::asin(p_x);
+ static _ALWAYS_INLINE_ double sinh(double p_x) { return ::sinh(p_x); }
+ static _ALWAYS_INLINE_ float sinh(float p_x) { return ::sinhf(p_x); }
- }
+ static _ALWAYS_INLINE_ double cosh(double p_x) { return ::cosh(p_x); }
+ static _ALWAYS_INLINE_ float cosh(float p_x) { return ::coshf(p_x); }
- static _ALWAYS_INLINE_ double acos(double p_x) {
+ static _ALWAYS_INLINE_ double tanh(double p_x) { return ::tanh(p_x); }
+ static _ALWAYS_INLINE_ float tanh(float p_x) { return ::tanhf(p_x); }
- return ::acos(p_x);
- }
+ static _ALWAYS_INLINE_ double asin(double p_x) { return ::asin(p_x); }
+ static _ALWAYS_INLINE_ float asin(float p_x) { return ::asinf(p_x); }
- static _ALWAYS_INLINE_ double atan(double p_x) {
+ static _ALWAYS_INLINE_ double acos(double p_x) { return ::acos(p_x); }
+ static _ALWAYS_INLINE_ float acos(float p_x) { return ::acosf(p_x); }
- return ::atan(p_x);
- }
+ static _ALWAYS_INLINE_ double atan(double p_x) { return ::atan(p_x); }
+ static _ALWAYS_INLINE_ float atan(float p_x) { return ::atanf(p_x); }
- static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) {
+ static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { return ::atan2(p_y,p_x); }
+ static _ALWAYS_INLINE_ float atan2(float p_y, float p_x) { return ::atan2f(p_y,p_x); }
- return ::atan2(p_y,p_x);
+ static _ALWAYS_INLINE_ double sqrt(double p_x) { return ::sqrt(p_x); }
+ static _ALWAYS_INLINE_ float sqrt(float p_x) { return ::sqrtf(p_x); }
- }
+ static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) { return ::fmod(p_x,p_y); }
+ static _ALWAYS_INLINE_ float fmod(float p_x,float p_y) { return ::fmodf(p_x,p_y); }
- static _ALWAYS_INLINE_ double deg2rad(double p_y) {
+ static _ALWAYS_INLINE_ double floor(double p_x) { return ::floor(p_x); }
+ static _ALWAYS_INLINE_ float floor(float p_x) { return ::floorf(p_x); }
- return p_y*Math_PI/180.0;
- }
+ static _ALWAYS_INLINE_ double ceil(double p_x) { return ::ceil(p_x); }
+ static _ALWAYS_INLINE_ float ceil(float p_x) { return ::ceilf(p_x); }
- static _ALWAYS_INLINE_ double rad2deg(double p_y) {
+ static _ALWAYS_INLINE_ double pow(double p_x, double p_y) { return ::pow(p_x,p_y); }
+ static _ALWAYS_INLINE_ float pow(float p_x, float p_y) { return ::powf(p_x,p_y); }
- return p_y*180.0/Math_PI;
- }
+ static _ALWAYS_INLINE_ double log(double p_x) { return ::log(p_x); }
+ static _ALWAYS_INLINE_ float log(float p_x) { return ::logf(p_x); }
+ static _ALWAYS_INLINE_ double exp(double p_x) { return ::exp(p_x); }
+ static _ALWAYS_INLINE_ float exp(float p_x) { return ::expf(p_x); }
- static _ALWAYS_INLINE_ double sqrt(double p_x) {
+ static _ALWAYS_INLINE_ bool is_nan(double p_val) { return (p_val!=p_val); }
+ static _ALWAYS_INLINE_ bool is_nan(float p_val) { return (p_val!=p_val); }
- return ::sqrt(p_x);
+ static _ALWAYS_INLINE_ bool is_inf(double p_val) {
+ #ifdef _MSC_VER
+ return !_finite(p_val);
+ #else
+ return isinf(p_val);
+ #endif
}
-
- static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) {
-
- return ::fmod(p_x,p_y);
+
+ static _ALWAYS_INLINE_ bool is_inf(float p_val) {
+ #ifdef _MSC_VER
+ return !_finite(p_val);
+ #else
+ return isinf(p_val);
+ #endif
}
+
+ static _ALWAYS_INLINE_ double abs(double g) { return absd(g); }
+ static _ALWAYS_INLINE_ float abs(float g) { return absf(g); }
+ static _ALWAYS_INLINE_ int abs(int g) { return g > 0 ? g : -g; }
- static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) {
-
- if (p_x>=0) {
-
- return fmod(p_x,p_y);
+ static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) { return (p_x>=0) ? Math::fmod(p_x,p_y) : p_y-Math::fmod(-p_x,p_y); }
+ static _ALWAYS_INLINE_ float fposmod(float p_x,float p_y) { return (p_x>=0) ? Math::fmod(p_x,p_y) : p_y-Math::fmod(-p_x,p_y); }
- } else {
+ static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y*Math_PI/180.0; }
+ static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y*Math_PI/180.0; }
- return p_y-fmod(-p_x,p_y);
- }
-
- }
- static _ALWAYS_INLINE_ double floor(double p_x) {
+ static _ALWAYS_INLINE_ double rad2deg(double p_y) { return p_y*180.0/Math_PI; }
+ static _ALWAYS_INLINE_ float rad2deg(float p_y) { return p_y*180.0/Math_PI; }
- return ::floor(p_x);
- }
-
- static _ALWAYS_INLINE_ double ceil(double p_x) {
+ static _ALWAYS_INLINE_ double lerp(double a, double b, double c) { return a+(b-a)*c; }
+ static _ALWAYS_INLINE_ float lerp(float a, float b, float c) { return a+(b-a)*c; }
- return ::ceil(p_x);
- }
+ static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log( p_linear ) * 8.6858896380650365530225783783321; }
+ static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log( p_linear ) * 8.6858896380650365530225783783321; }
+ static _ALWAYS_INLINE_ double db2linear(double p_db) { return Math::exp( p_db * 0.11512925464970228420089957273422 ); }
+ static _ALWAYS_INLINE_ float db2linear(float p_db) { return Math::exp( p_db * 0.11512925464970228420089957273422 ); }
- static uint32_t rand_from_seed(uint32_t *seed);
+ static _ALWAYS_INLINE_ double round(double p_val) { return (p_val>=0) ? Math::floor(p_val+0.5) : -Math::floor(-p_val+0.5); }
+ static _ALWAYS_INLINE_ float round(float p_val) { return (p_val>=0) ? Math::floor(p_val+0.5) : -Math::floor(-p_val+0.5); }
+ // double only, as these functions are mainly used by the editor and not performance-critical,
static double ease(double p_x, double p_c);
static int step_decimals(double p_step);
static double stepify(double p_value,double p_step);
- static void seed(uint32_t x=0);
- static void randomize();
- static uint32_t larger_prime(uint32_t p_val);
static double dectime(double p_value,double p_amount, double p_step);
+ static uint32_t larger_prime(uint32_t p_val);
- static inline double linear2db(double p_linear) {
-
- return Math::log( p_linear ) * 8.6858896380650365530225783783321;
- }
-
- static inline double db2linear(double p_db) {
-
- return Math::exp( p_db * 0.11512925464970228420089957273422 );
- }
-
- static _ALWAYS_INLINE_ bool is_nan(double p_val) {
-
- return (p_val!=p_val);
- }
-
- static _ALWAYS_INLINE_ bool is_inf(double p_val) {
-
- #ifdef _MSC_VER
- return !_finite(p_val);
- #else
- return isinf(p_val);
- #endif
-
- }
-
+ static void seed(uint64_t x=0);
+ static void randomize();
+ static uint32_t rand_from_seed(uint64_t *seed);
static uint32_t rand();
- static double randf();
-
- static double round(double p_val);
+ static _ALWAYS_INLINE_ double randf() { return (double)rand() / (double)Math::RANDOM_MAX; }
+ static _ALWAYS_INLINE_ float randd() { return (float)rand() / (float)Math::RANDOM_MAX; }
static double random(double from, double to);
+ static float random(float from, float to);
+ static real_t random(int from, int to) { return (real_t)random((real_t)from, (real_t)to); }
- static _FORCE_INLINE_ bool isequal_approx(real_t a, real_t b) {
+
+ static _ALWAYS_INLINE_ bool isequal_approx(real_t a, real_t b) {
// TODO: Comparing floats for approximate-equality is non-trivial.
// Using epsilon should cover the typical cases in Godot (where a == b is used to compare two reals), such as matrix and vector comparison operators.
// A proper implementation in terms of ULPs should eventually replace the contents of this function.
@@ -203,18 +179,7 @@ public:
}
- static _FORCE_INLINE_ real_t abs(real_t g) {
-
-#ifdef REAL_T_IS_DOUBLE
-
- return absd(g);
-#else
-
- return absf(g);
-#endif
- }
-
- static _FORCE_INLINE_ float absf(float g) {
+ static _ALWAYS_INLINE_ float absf(float g) {
union {
float f;
@@ -226,7 +191,7 @@ public:
return u.f;
}
- static _FORCE_INLINE_ double absd(double g) {
+ static _ALWAYS_INLINE_ double absd(double g) {
union {
double d;
@@ -238,12 +203,12 @@ public:
}
//this function should be as fast as possible and rounding mode should not matter
- static _FORCE_INLINE_ int fast_ftoi(float a) {
+ static _ALWAYS_INLINE_ int fast_ftoi(float a) {
static int b;
#if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone?
- b = (int)((a>0.0f) ? (a + 0.5f):(a -0.5f));
+ b = (int)((a>0.0) ? (a + 0.5):(a -0.5));
#elif defined(_MSC_VER) && _MSC_VER < 1800
__asm fld a
@@ -266,23 +231,16 @@ public:
#if defined(__GNUC__)
- static _FORCE_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
+ static _ALWAYS_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
+ static _ALWAYS_INLINE_ int64_t dtoll(float p_float) { return (int64_t)p_float; } ///@TODO OPTIMIZE and rename
#else
- static _FORCE_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
+ static _ALWAYS_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
+ static _ALWAYS_INLINE_ int64_t dtoll(float p_float) { return (int64_t)p_float; } ///@TODO OPTIMIZE and rename
#endif
- static _FORCE_INLINE_ float lerp(float a, float b, float c) {
-
- return a+(b-a)*c;
- }
-
- static double pow(double x, double y);
- static double log(double x);
- static double exp(double x);
-
- static _FORCE_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h)
+ static _ALWAYS_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h)
{
uint16_t h_exp, h_sig;
uint32_t f_sgn, f_exp, f_sig;
@@ -314,7 +272,7 @@ public:
}
}
- static _FORCE_INLINE_ float halfptr_to_float(const uint16_t *h) {
+ static _ALWAYS_INLINE_ float halfptr_to_float(const uint16_t *h) {
union {
uint32_t u32;
@@ -325,7 +283,7 @@ public:
return u.f32;
}
- static _FORCE_INLINE_ uint16_t make_half_float(float f) {
+ static _ALWAYS_INLINE_ uint16_t make_half_float(float f) {
union {
float fv;
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index e9c3442582..1fabfbbd4c 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -504,9 +504,9 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
ERR_FAIL_COND(is_rotation() == false);
- double angle,x,y,z; // variables for result
- double epsilon = 0.01; // margin to allow for rounding errors
- double epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
+ real_t angle,x,y,z; // variables for result
+ real_t epsilon = 0.01; // margin to allow for rounding errors
+ real_t epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
if ( (Math::abs(elements[1][0]-elements[0][1])< epsilon)
&& (Math::abs(elements[2][0]-elements[0][2])< epsilon)
@@ -525,12 +525,12 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
}
// otherwise this singularity is angle = 180
angle = Math_PI;
- double xx = (elements[0][0]+1)/2;
- double yy = (elements[1][1]+1)/2;
- double zz = (elements[2][2]+1)/2;
- double xy = (elements[1][0]+elements[0][1])/4;
- double xz = (elements[2][0]+elements[0][2])/4;
- double yz = (elements[2][1]+elements[1][2])/4;
+ real_t xx = (elements[0][0]+1)/2;
+ real_t yy = (elements[1][1]+1)/2;
+ real_t zz = (elements[2][2]+1)/2;
+ real_t xy = (elements[1][0]+elements[0][1])/4;
+ real_t xz = (elements[2][0]+elements[0][2])/4;
+ real_t yz = (elements[2][1]+elements[1][2])/4;
if ((xx > yy) && (xx > zz)) { // elements[0][0] is the largest diagonal term
if (xx< epsilon) {
x = 0;
@@ -567,7 +567,7 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
return;
}
// as we have reached here there are no singularities so we can handle normally
- double s = Math::sqrt((elements[1][2] - elements[2][1])*(elements[1][2] - elements[2][1])
+ real_t s = Math::sqrt((elements[1][2] - elements[2][1])*(elements[1][2] - elements[2][1])
+(elements[2][0] - elements[0][2])*(elements[2][0] - elements[0][2])
+(elements[0][1] - elements[1][0])*(elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise
diff --git a/core/math/octree.h b/core/math/octree.h
index 1a41413a76..e566df6a4f 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -30,7 +30,7 @@
#define OCTREE_H
#include "vector3.h"
-#include "aabb.h"
+#include "rect3.h"
#include "list.h"
#include "variant.h"
#include "map.h"
@@ -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]);
+ */
}
};
@@ -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++;
@@ -431,7 +435,7 @@ int Octree<T,use_pairs,AL>::get_subindex(OctreeElementID p_id) const {
template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant) {
- float element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues
+ real_t element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues
if (p_octant->aabb.size.x/OCTREE_DIVISOR < element_size) {
//if (p_octant->aabb.size.x*0.5 < element_size) {
@@ -970,8 +974,10 @@ void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const Rect3& 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 );
diff --git a/core/math/pcg.cpp b/core/math/pcg.cpp
new file mode 100644
index 0000000000..eac3b36d36
--- /dev/null
+++ b/core/math/pcg.cpp
@@ -0,0 +1,15 @@
+// *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org
+// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
+
+#include "pcg.h"
+
+uint32_t pcg32_random_r(pcg32_random_t* rng)
+{
+ uint64_t oldstate = rng->state;
+ // Advance internal state
+ rng->state = oldstate * 6364136223846793005ULL + (rng->inc|1);
+ // Calculate output function (XSH RR), uses old state for max ILP
+ uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
+ uint32_t rot = oldstate >> 59u;
+ return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
+}
diff --git a/core/math/pcg.h b/core/math/pcg.h
new file mode 100644
index 0000000000..81f4c9770e
--- /dev/null
+++ b/core/math/pcg.h
@@ -0,0 +1,14 @@
+// *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org
+// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
+
+#ifndef RANDOM_H
+#define RANDOM_H
+
+#include "typedefs.h"
+
+#define PCG_DEFAULT_INC_64 1442695040888963407ULL
+
+typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t;
+uint32_t pcg32_random_r(pcg32_random_t* rng);
+
+#endif // RANDOM_H
diff --git a/core/math/plane.h b/core/math/plane.h
index f746ea2067..8235c59135 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -99,7 +99,7 @@ real_t Plane::distance_to(const Vector3 &p_point) const {
bool Plane::has_point(const Vector3 &p_point,real_t _epsilon) const {
- float dist=normal.dot(p_point) - d;
+ real_t dist=normal.dot(p_point) - d;
dist=ABS(dist);
return ( dist <= _epsilon);
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index 055e2b7c35..4085f9b84a 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -124,8 +124,8 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
// Standard case (slerp)
real_t sine = Math::sqrt(1 - cosine*cosine);
real_t angle = Math::atan2(sine, cosine);
- real_t inv_sine = 1.0f / sine;
- real_t coeff_0 = Math::sin((1.0f - t) * angle) * inv_sine;
+ real_t inv_sine = 1.0 / sine;
+ real_t coeff_0 = Math::sin((1.0 - t) * angle) * inv_sine;
real_t coeff_1 = Math::sin(t * angle) * inv_sine;
Quat ret= src * coeff_0 + dst * coeff_1;
@@ -137,7 +137,7 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
// 2. "rkP" and "q" are almost invedste of each other (cosine ~= -1), there
// are an infinite number of possibilities interpolation. but we haven't
// have method to fix this case, so just use linear interpolation here.
- Quat ret = src * (1.0f - t) + dst *t;
+ Quat ret = src * (1.0 - t) + dst *t;
// taking the complement requires renormalisation
ret.normalize();
return ret;
@@ -194,14 +194,14 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
const Quat &from = *this;
- float dot = from.dot(q);
+ real_t dot = from.dot(q);
- if (Math::absf(dot) > 0.9999f) return from;
+ if (Math::absf(dot) > 0.9999) return from;
- float theta = Math::acos(dot),
- sinT = 1.0f / Math::sin(theta),
+ real_t theta = Math::acos(dot),
+ sinT = 1.0 / Math::sin(theta),
newFactor = Math::sin(t * theta) * sinT,
- invFactor = Math::sin((1.0f - t) * theta) * sinT;
+ invFactor = Math::sin((1.0 - t) * theta) * sinT;
return Quat(invFactor * from.x + newFactor * q.x,
invFactor * from.y + newFactor * q.y,
@@ -259,7 +259,7 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const {
//the only way to do slerp :|
- float t2 = (1.0-t)*t*2;
+ real_t t2 = (1.0-t)*t*2;
Quat sp = this->slerp(q,t);
Quat sq = prep.slerpni(postq,t);
return sp.slerpni(sq,t2);
diff --git a/core/math/quat.h b/core/math/quat.h
index 43c2cab9e6..d3a50343a3 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -119,8 +119,8 @@ public:
w=0;
} else {
- real_t s = Math::sqrt((1.0f + d) * 2.0f);
- real_t rs = 1.0f / s;
+ real_t s = Math::sqrt((1.0 + d) * 2.0);
+ real_t rs = 1.0 / s;
x=c.x*rs;
y=c.y*rs;
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index ab81a068d4..32fc0e01e8 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -86,7 +86,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
if (!valid_points[i])
continue;
- float d = p_points[i][longest_axis];
+ real_t d = p_points[i][longest_axis];
if (i==0 || d < min) {
simplex[0]=i;
@@ -105,7 +105,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
{
- float maxd;
+ real_t maxd;
Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]];
for(int i=0;i<p_points.size();i++) {
@@ -127,7 +127,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
//fourth vertex is the one most further away from the plane
{
- float maxd;
+ real_t maxd;
Plane p(p_points[simplex[0]],p_points[simplex[1]],p_points[simplex[2]]);
for(int i=0;i<p_points.size();i++) {
@@ -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 04d25fef18..7bd23d31f2 100644
--- a/core/math/quick_hull.h
+++ b/core/math/quick_hull.h
@@ -29,7 +29,7 @@
#ifndef QUICK_HULL_H
#define QUICK_HULL_H
-#include "aabb.h"
+#include "rect3.h"
#include "set.h"
#include "list.h"
#include "geometry.h"
diff --git a/core/math/aabb.cpp b/core/math/rect3.cpp
index 3518eea7ac..d3f95b89e8 100644
--- a/core/math/aabb.cpp
+++ b/core/math/rect3.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* aabb.cpp */
+/* rect3.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -26,11 +26,11 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "aabb.h"
+#include "rect3.h"
#include "print_string.h"
-float Rect3::get_area() const {
+real_t Rect3::get_area() const {
return size.x*size.y*size.z;
@@ -114,8 +114,8 @@ bool Rect3::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3*
Vector3 c1, c2;
Vector3 end = pos+size;
- float near=-1e20;
- float far=1e20;
+ real_t near=-1e20;
+ real_t far=1e20;
int axis=0;
for (int i=0;i<3;i++){
@@ -159,7 +159,7 @@ bool Rect3::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector
real_t min=0,max=1;
int axis=0;
- float sign=0;
+ real_t sign=0;
for(int i=0;i<3;i++) {
real_t seg_from=p_from[i];
@@ -167,7 +167,7 @@ bool Rect3::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector
real_t box_begin=pos[i];
real_t box_end=box_begin+size[i];
real_t cmin,cmax;
- float csign;
+ real_t csign;
if (seg_from < seg_to) {
diff --git a/core/math/aabb.h b/core/math/rect3.h
index 2816d1f012..902592b02c 100644
--- a/core/math/aabb.h
+++ b/core/math/rect3.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* aabb.h */
+/* rect3.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -33,6 +33,8 @@
#include "vector3.h"
#include "plane.h"
+#include "math_defs.h"
+
/**
* AABB / AABB (Axis Aligned Bounding Box)
* This is implemented by a point (pos) and the box size
@@ -45,7 +47,7 @@ public:
Vector3 pos;
Vector3 size;
- float get_area() const; /// get area
+ real_t get_area() const; /// get area
_FORCE_INLINE_ bool has_no_area() const {
return (size.x<=CMP_EPSILON || size.y<=CMP_EPSILON || size.z<=CMP_EPSILON);
@@ -74,7 +76,7 @@ public:
Rect3 intersection(const Rect3& p_aabb) const; ///get box where two intersect, empty if no intersection occurs
bool intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const;
- _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, float t0, float t1) const;
+ _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, real_t t0, real_t t1) const;
_FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
bool intersects_plane(const Plane &p_plane) const;
@@ -98,7 +100,7 @@ public:
_FORCE_INLINE_ Vector3 get_endpoint(int p_point) const;
Rect3 expand(const Vector3& p_vector) const;
- _FORCE_INLINE_ void project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max) const;
+ _FORCE_INLINE_ void project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const;
_FORCE_INLINE_ void expand_to(const Vector3& p_vector); /** expand to contain a point if necesary */
operator String() const;
@@ -293,13 +295,13 @@ inline void Rect3::expand_to(const Vector3& p_vector) {
size=end-begin;
}
-void Rect3::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max) const {
+void Rect3::project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const {
Vector3 half_extents( size.x * 0.5, size.y * 0.5, size.z * 0.5 );
Vector3 center( pos.x + half_extents.x, pos.y + half_extents.y, pos.z + half_extents.z );
- float length = p_plane.normal.abs().dot(half_extents);
- float distance = p_plane.distance_to( center );
+ real_t length = p_plane.normal.abs().dot(half_extents);
+ real_t distance = p_plane.distance_to( center );
r_min = distance - length;
r_max = distance + length;
}
@@ -334,14 +336,14 @@ inline real_t Rect3::get_shortest_axis_size() const {
return max_size;
}
-bool Rect3::smits_intersect_ray(const Vector3 &from,const Vector3& dir, float t0, float t1) const {
+bool Rect3::smits_intersect_ray(const Vector3 &from,const Vector3& dir, real_t t0, real_t t1) const {
- float divx=1.0/dir.x;
- float divy=1.0/dir.y;
- float divz=1.0/dir.z;
+ real_t divx=1.0/dir.x;
+ real_t divy=1.0/dir.y;
+ real_t divz=1.0/dir.z;
Vector3 upbound=pos+size;
- float tmin, tmax, tymin, tymax, tzmin, tzmax;
+ real_t tmin, tmax, tymin, tymax, tzmin, tzmax;
if (dir.x >= 0) {
tmin = (pos.x - from.x) * divx;
tmax = (upbound.x - from.x) * divx;
diff --git a/core/math/transform.h b/core/math/transform.h
index d65e87cc6a..45d7b2a12c 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -31,7 +31,7 @@
#include "matrix3.h"
#include "plane.h"
-#include "aabb.h"
+#include "rect3.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index fc5f55066b..247cb90a48 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -236,21 +236,22 @@ Vector3 TriangleMesh::get_area_normal(const Rect3& p_aabb) const {
stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node;
}
}
-
- } continue;
+ continue;
+ }
case VISIT_LEFT_BIT: {
stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node;
stack[level+1]=b.left|TEST_AABB_BIT;
level++;
-
- } continue;
+ continue;
+ }
case VISIT_RIGHT_BIT: {
stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
stack[level+1]=b.right|TEST_AABB_BIT;
level++;
- } continue;
+ continue;
+ }
case VISIT_DONE_BIT: {
if (level==0) {
@@ -258,8 +259,8 @@ Vector3 TriangleMesh::get_area_normal(const Rect3& p_aabb) const {
break;
} else
level--;
-
- } continue;
+ continue;
+ }
}
@@ -320,7 +321,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) {
@@ -339,7 +340,7 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end
if (f3.intersects_segment(p_begin,p_end,&res)) {
- float nd = n.dot(res);
+ real_t nd = n.dot(res);
if (nd<d) {
d=nd;
@@ -357,21 +358,22 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end
stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node;
}
}
-
- } continue;
+ continue;
+ }
case VISIT_LEFT_BIT: {
stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node;
stack[level+1]=b.left|TEST_AABB_BIT;
level++;
-
- } continue;
+ continue;
+ }
case VISIT_RIGHT_BIT: {
stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
stack[level+1]=b.right|TEST_AABB_BIT;
level++;
- } continue;
+ continue;
+ }
case VISIT_DONE_BIT: {
if (level==0) {
@@ -379,8 +381,8 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end
break;
} else
level--;
-
- } continue;
+ continue;
+ }
}
@@ -460,7 +462,7 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec
if (f3.intersects_ray(p_begin,p_dir,&res)) {
- float nd = n.dot(res);
+ real_t nd = n.dot(res);
if (nd<d) {
d=nd;
@@ -478,21 +480,22 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec
stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node;
}
}
-
- } continue;
+ continue;
+ }
case VISIT_LEFT_BIT: {
stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node;
stack[level+1]=b.left|TEST_AABB_BIT;
level++;
-
- } continue;
+ continue;
+ }
case VISIT_RIGHT_BIT: {
stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node;
stack[level+1]=b.right|TEST_AABB_BIT;
level++;
- } continue;
+ continue;
+ }
case VISIT_DONE_BIT: {
if (level==0) {
@@ -500,8 +503,8 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec
break;
} else
level--;
-
- } continue;
+ continue;
+ }
}
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index 82b49be7f3..128b6ca331 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -28,19 +28,19 @@
/*************************************************************************/
#include "triangulate.h"
-float Triangulate::get_area(const Vector<Vector2> &contour)
+real_t Triangulate::get_area(const Vector<Vector2> &contour)
{
int n = contour.size();
const Vector2 *c=&contour[0];
- float A=0.0f;
+ real_t A=0.0;
for(int p=n-1,q=0; q<n; p=q++)
{
A+= c[p].cross(c[q]);
}
- return A*0.5f;
+ return A*0.5;
}
/*
@@ -48,14 +48,14 @@ float Triangulate::get_area(const Vector<Vector2> &contour)
defined by A, B, C.
*/
-bool Triangulate::is_inside_triangle(float Ax, float Ay,
- float Bx, float By,
- float Cx, float Cy,
- float Px, float Py)
+bool Triangulate::is_inside_triangle(real_t Ax, real_t Ay,
+ real_t Bx, real_t By,
+ real_t Cx, real_t Cy,
+ real_t Px, real_t Py)
{
- float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
- float cCROSSap, bCROSScp, aCROSSbp;
+ real_t ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
+ real_t cCROSSap, bCROSScp, aCROSSbp;
ax = Cx - Bx; ay = Cy - By;
bx = Ax - Cx; by = Ay - Cy;
@@ -68,13 +68,13 @@ bool Triangulate::is_inside_triangle(float Ax, float Ay,
cCROSSap = cx*apy - cy*apx;
bCROSScp = bx*cpy - by*cpx;
- return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
+ return ((aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0));
};
bool Triangulate::snip(const Vector<Vector2> &p_contour,int u,int v,int w,int n,const Vector<int>& V)
{
int p;
- float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
+ real_t Ax, Ay, Bx, By, Cx, Cy, Px, Py;
const Vector2 *contour=&p_contour[0];
Ax = contour[V[u]].x;
@@ -112,7 +112,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result
/* we want a counter-clockwise polygon in V */
- if ( 0.0f < get_area(contour) )
+ if ( 0.0 < get_area(contour) )
for (int v=0; v<n; v++) V[v] = v;
else
for(int v=0; v<n; v++) V[v] = (n-1)-v;
diff --git a/core/math/triangulate.h b/core/math/triangulate.h
index d22677a8b8..ce77334519 100644
--- a/core/math/triangulate.h
+++ b/core/math/triangulate.h
@@ -45,14 +45,14 @@ public:
static bool triangulate(const Vector< Vector2 > &contour, Vector<int> &result);
// compute area of a contour/polygon
- static float get_area(const Vector< Vector2 > &contour);
+ static real_t get_area(const Vector< Vector2 > &contour);
// decide if point Px/Py is inside triangle defined by
// (Ax,Ay) (Bx,By) (Cx,Cy)
- static bool is_inside_triangle(float Ax, float Ay,
- float Bx, float By,
- float Cx, float Cy,
- float Px, float Py);
+ static bool is_inside_triangle(real_t Ax, real_t Ay,
+ real_t Bx, real_t By,
+ real_t Cx, real_t Cy,
+ real_t Px, real_t Py);
private:
diff --git a/core/math/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 3eb978333d..2ab5fa0465 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -30,12 +30,12 @@
#include "matrix3.h"
-void Vector3::rotate(const Vector3& p_axis,float p_phi) {
+void Vector3::rotate(const Vector3& p_axis,real_t p_phi) {
*this=Basis(p_axis,p_phi).xform(*this);
}
-Vector3 Vector3::rotated(const Vector3& p_axis,float p_phi) const {
+Vector3 Vector3::rotated(const Vector3& p_axis,real_t p_phi) const {
Vector3 r = *this;
r.rotate(p_axis,p_phi);
@@ -63,13 +63,13 @@ int Vector3::max_axis() const {
}
-void Vector3::snap(float p_val) {
+void Vector3::snap(real_t p_val) {
x=Math::stepify(x,p_val);
y=Math::stepify(y,p_val);
z=Math::stepify(z,p_val);
}
-Vector3 Vector3::snapped(float p_val) const {
+Vector3 Vector3::snapped(real_t p_val) const {
Vector3 v=*this;
v.snap(p_val);
@@ -77,7 +77,7 @@ Vector3 Vector3::snapped(float p_val) const {
}
-Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const {
+Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
@@ -87,9 +87,9 @@ Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, c
{
//normalize
- float ab = p0.distance_to(p1);
- float bc = p1.distance_to(p2);
- float cd = p2.distance_to(p3);
+ real_t ab = p0.distance_to(p1);
+ real_t bc = p1.distance_to(p2);
+ real_t cd = p2.distance_to(p3);
if (ab>0)
p0 = p1+(p0-p1)*(bc/ab);
@@ -98,41 +98,41 @@ Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, c
}
- float t = p_t;
- float t2 = t * t;
- float t3 = t2 * t;
+ real_t t = p_t;
+ real_t t2 = t * t;
+ real_t t3 = t2 * t;
Vector3 out;
- out = 0.5f * ( ( p1 * 2.0f) +
+ out = 0.5 * ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
- ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 +
- ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 );
+ ( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 +
+ ( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 );
return out;
}
-Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const {
+Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
Vector3 p2=p_b;
Vector3 p3=p_post_b;
- float t = p_t;
- float t2 = t * t;
- float t3 = t2 * t;
+ real_t t = p_t;
+ real_t t2 = t * t;
+ real_t t3 = t2 * t;
Vector3 out;
- out = 0.5f * ( ( p1 * 2.0f) +
+ out = 0.5 * ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
- ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 +
- ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 );
+ ( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 +
+ ( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 );
return out;
}
#if 0
-Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const {
+Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
@@ -141,9 +141,9 @@ Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, co
if (true) {
- float ab = p0.distance_to(p1);
- float bc = p1.distance_to(p2);
- float cd = p2.distance_to(p3);
+ real_t ab = p0.distance_to(p1);
+ real_t bc = p1.distance_to(p2);
+ real_t cd = p2.distance_to(p3);
//if (ab>bc) {
if (ab>0)
@@ -156,23 +156,23 @@ Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, co
//}
}
- float t = p_t;
- float t2 = t * t;
- float t3 = t2 * t;
+ real_t t = p_t;
+ real_t t2 = t * t;
+ real_t t3 = t2 * t;
Vector3 out;
- out.x = 0.5f * ( ( 2.0f * p1.x ) +
+ out.x = 0.5 * ( ( 2.0 * p1.x ) +
( -p0.x + p2.x ) * t +
- ( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 +
- ( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 );
- out.y = 0.5f * ( ( 2.0f * p1.y ) +
+ ( 2.0 * p0.x - 5.0 * p1.x + 4 * p2.x - p3.x ) * t2 +
+ ( -p0.x + 3.0 * p1.x - 3.0 * p2.x + p3.x ) * t3 );
+ out.y = 0.5 * ( ( 2.0 * p1.y ) +
( -p0.y + p2.y ) * t +
- ( 2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y ) * t2 +
- ( -p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y ) * t3 );
- out.z = 0.5f * ( ( 2.0f * p1.z ) +
+ ( 2.0 * p0.y - 5.0 * p1.y + 4 * p2.y - p3.y ) * t2 +
+ ( -p0.y + 3.0 * p1.y - 3.0 * p2.y + p3.y ) * t3 );
+ out.z = 0.5 * ( ( 2.0 * p1.z ) +
( -p0.z + p2.z ) * t +
- ( 2.0f * p0.z - 5.0f * p1.z + 4 * p2.z - p3.z ) * t2 +
- ( -p0.z + 3.0f * p1.z - 3.0f * p2.z + p3.z ) * t3 );
+ ( 2.0 * p0.z - 5.0 * p1.z + 4 * p2.z - p3.z ) * t2 +
+ ( -p0.z + 3.0 * p1.z - 3.0 * p2.z + p3.z ) * t3 );
return out;
}
# endif
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 9ae9b69dfa..a289f9bf4c 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -79,17 +79,17 @@ struct Vector3 {
_FORCE_INLINE_ void zero();
- void snap(float p_val);
- Vector3 snapped(float p_val) const;
+ void snap(real_t p_val);
+ Vector3 snapped(real_t p_val) const;
- void rotate(const Vector3& p_axis,float p_phi);
- Vector3 rotated(const Vector3& p_axis,float p_phi) const;
+ void rotate(const Vector3& p_axis,real_t p_phi);
+ Vector3 rotated(const Vector3& p_axis,real_t p_phi) const;
/* Static Methods between 2 vector3s */
- _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,float p_t) const;
- Vector3 cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const;
- Vector3 cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const;
+ _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,real_t p_t) const;
+ Vector3 cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const;
+ Vector3 cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const;
_FORCE_INLINE_ Vector3 cross(const Vector3& p_b) const;
_FORCE_INLINE_ real_t dot(const Vector3& p_b) const;
@@ -195,7 +195,7 @@ Vector3 Vector3::ceil() const {
return Vector3( Math::ceil(x), Math::ceil(y), Math::ceil(z) );
}
-Vector3 Vector3::linear_interpolate(const Vector3& p_b,float p_t) const {
+Vector3 Vector3::linear_interpolate(const Vector3& p_b,real_t p_t) const {
return Vector3(
x+(p_t * (p_b.x-x)),
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index fe46e1671c..50b52e4970 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -27,8 +27,10 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "message_queue.h"
-#include "globals.h"
+
+#include "global_config.h"
#include "script_language.h"
+
MessageQueue *MessageQueue::singleton=NULL;
MessageQueue *MessageQueue::get_singleton() {
diff --git a/core/method_bind.cpp b/core/method_bind.cpp
index f323f3bc24..3465edff63 100644
--- a/core/method_bind.cpp
+++ b/core/method_bind.cpp
@@ -26,7 +26,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+// object.h needs to be the first include *before* method_bind.h
+// FIXME: Find out why and fix potential cyclical dependencies.
#include "object.h"
+
#include "method_bind.h"
diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h
index 36b42c84f3..a35e44b66c 100644
--- a/core/method_ptrcall.h
+++ b/core/method_ptrcall.h
@@ -74,7 +74,7 @@ MAKE_PTRARG(Vector3);
MAKE_PTRARG(Transform2D);
MAKE_PTRARG(Plane);
MAKE_PTRARG(Quat);
-MAKE_PTRARG(AABB);
+MAKE_PTRARG(Rect3);
MAKE_PTRARG(Basis);
MAKE_PTRARG(Transform);
MAKE_PTRARG(Color);
@@ -84,13 +84,13 @@ MAKE_PTRARG(RID);
MAKE_PTRARG(InputEvent);
MAKE_PTRARG(Dictionary);
MAKE_PTRARG(Array);
-MAKE_PTRARG(ByteArray);
-MAKE_PTRARG(IntArray);
-MAKE_PTRARG(RealArray);
-MAKE_PTRARG(StringArray);
-MAKE_PTRARG(Vector2Array);
-MAKE_PTRARG(Vector3Array);
-MAKE_PTRARG(ColorArray);
+MAKE_PTRARG(PoolByteArray);
+MAKE_PTRARG(PoolIntArray);
+MAKE_PTRARG(PoolRealArray);
+MAKE_PTRARG(PoolStringArray);
+MAKE_PTRARG(PoolVector2Array);
+MAKE_PTRARG(PoolVector3Array);
+MAKE_PTRARG(PoolColorArray);
MAKE_PTRARG(Variant);
diff --git a/core/object.cpp b/core/object.cpp
index 3bb917bd38..79905a6be6 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -27,8 +27,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "object.h"
+
#include "print_string.h"
-#include "object_type_db.h"
+#include "class_db.h"
#include "script_language.h"
#include "message_queue.h"
#include "core_string_names.h"
@@ -369,8 +370,10 @@ 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;
ClassDB::set_property(this,p_name,p_value,success);
@@ -380,7 +383,7 @@ void Object::set(const String& p_name, const Variant& p_value) {
if (p_name=="__meta__") {
metadata=p_value;
- } else if (p_name=="script/script") {
+ } else if (p_name=="script") {
set_script(p_value);
} else if (script_instance) {
script_instance->set(p_name,p_value);
@@ -410,8 +413,10 @@ void Object::set(const StringName& p_name, const Variant& p_value, bool *r_valid
//try built-in setgetter
{
if (ClassDB::set_property(this,p_name,p_value,r_valid)) {
- //if (r_valid)
- // *r_valid=true;
+ /*
+ if (r_valid)
+ *r_valid=true;
+ */
return;
}
}
@@ -511,7 +516,7 @@ Variant Object::get(const String& p_name) const {
if (p_name=="__meta__")
return metadata;
- else if (p_name=="script/script")
+ else if (p_name=="script")
return script;
if (script_instance) {
@@ -534,7 +539,7 @@ void Object::get_property_list(List<PropertyInfo> *p_list,bool p_reversed) const
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));
+ p_list->push_back( PropertyInfo( Variant::OBJECT, "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));
if (script_instance && !p_reversed) {
@@ -1036,7 +1041,7 @@ void Object::set_script(const RefPtr& p_script) {
}
- _change_notify("script/script");
+ _change_notify("script");
emit_signal(CoreStringNames::get_singleton()->script_changed);
}
@@ -1670,31 +1675,31 @@ void Object::clear_internal_resource_paths() {
void Object::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("get_class"),&Object::get_class);
+ ClassDB::bind_method(D_METHOD("is_class","type"),&Object::is_class);
+ ClassDB::bind_method(D_METHOD("set","property","value"),&Object::_set_bind);
+ ClassDB::bind_method(D_METHOD("get","property"),&Object::_get_bind);
+ ClassDB::bind_method(D_METHOD("get_property_list"),&Object::_get_property_list_bind);
+ ClassDB::bind_method(D_METHOD("get_method_list"),&Object::_get_method_list_bind);
+ ClassDB::bind_method(D_METHOD("notification","what","reversed"),&Object::notification,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_instance_ID"),&Object::get_instance_ID);
- ClassDB::bind_method(_MD("set_script","script:Script"),&Object::set_script);
- ClassDB::bind_method(_MD("get_script:Script"),&Object::get_script);
+ ClassDB::bind_method(D_METHOD("set_script","script:Script"),&Object::set_script);
+ ClassDB::bind_method(D_METHOD("get_script:Script"),&Object::get_script);
- 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);
+ ClassDB::bind_method(D_METHOD("set_meta","name","value"),&Object::set_meta);
+ ClassDB::bind_method(D_METHOD("get_meta","name","value"),&Object::get_meta);
+ ClassDB::bind_method(D_METHOD("has_meta","name"),&Object::has_meta);
+ ClassDB::bind_method(D_METHOD("get_meta_list"),&Object::_get_meta_list_bind);
//todo reimplement this per language so all 5 arguments can be called
-// 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()));
+ //ClassDB::bind_method(D_METHOD("call","method","arg1","arg2","arg3","arg4"),&Object::_call_bind,DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()));
+ //ClassDB::bind_method(D_METHOD("call_deferred","method","arg1","arg2","arg3","arg4"),&Object::_call_deferred_bind,DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()),DEFVAL(Variant()));
- 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()));
+ ClassDB::bind_method(D_METHOD("add_user_signal","signal","arguments"),&Object::_add_user_signal,DEFVAL(Array()));
+ ClassDB::bind_method(D_METHOD("has_user_signal","signal"),&Object::_has_user_signal);
+ //ClassDB::bind_method(D_METHOD("emit_signal","signal","arguments"),&Object::_emit_signal,DEFVAL(Array()));
{
@@ -1723,27 +1728,27 @@ void Object::_bind_methods() {
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call_deferred",&Object::_call_deferred_bind,mi);
}
- ClassDB::bind_method(_MD("callv:Variant","method","arg_array"),&Object::callv);
+ ClassDB::bind_method(D_METHOD("callv:Variant","method","arg_array"),&Object::callv);
- ClassDB::bind_method(_MD("has_method","method"),&Object::has_method);
+ ClassDB::bind_method(D_METHOD("has_method","method"),&Object::has_method);
- 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);
+ ClassDB::bind_method(D_METHOD("get_signal_list"),&Object::_get_signal_list);
+ ClassDB::bind_method(D_METHOD("get_signal_connection_list","signal"),&Object::_get_signal_connection_list);
- 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);
+ ClassDB::bind_method(D_METHOD("connect","signal","target:Object","method","binds","flags"),&Object::connect,DEFVAL(Array()),DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("disconnect","signal","target:Object","method"),&Object::disconnect);
+ ClassDB::bind_method(D_METHOD("is_connected","signal","target:Object","method"),&Object::is_connected);
- 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);
+ ClassDB::bind_method(D_METHOD("set_block_signals","enable"),&Object::set_block_signals);
+ ClassDB::bind_method(D_METHOD("is_blocking_signals"),&Object::is_blocking_signals);
+ ClassDB::bind_method(D_METHOD("set_message_translation","enable"),&Object::set_message_translation);
+ ClassDB::bind_method(D_METHOD("can_translate_messages"),&Object::can_translate_messages);
+ ClassDB::bind_method(D_METHOD("property_list_changed_notify"),&Object::property_list_changed_notify);
- ClassDB::bind_method(_MD("XL_MESSAGE","message"),&Object::XL_MESSAGE);
- ClassDB::bind_method(_MD("tr","message"),&Object::tr);
+ ClassDB::bind_method(D_METHOD("XL_MESSAGE","message"),&Object::XL_MESSAGE);
+ ClassDB::bind_method(D_METHOD("tr","message"),&Object::tr);
- ClassDB::bind_method(_MD("is_queued_for_deletion"),&Object::is_queued_for_deletion);
+ ClassDB::bind_method(D_METHOD("is_queued_for_deletion"),&Object::is_queued_for_deletion);
ClassDB::add_virtual_method("Object",MethodInfo("free"),false);
diff --git a/core/object.h b/core/object.h
index a54693eab6..3fe31bee6b 100644
--- a/core/object.h
+++ b/core/object.h
@@ -103,6 +103,7 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_SCRIPT_VARIABLE=8192,
PROPERTY_USAGE_STORE_IF_NULL=16384,
PROPERTY_USAGE_ANIMATE_AS_TRIGGER=32768,
+ PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED=65536,
PROPERTY_USAGE_DEFAULT=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK,
PROPERTY_USAGE_DEFAULT_INTL=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_INTERNATIONALIZED,
@@ -113,12 +114,12 @@ enum PropertyUsageFlags {
#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_PROPERTY( m_property, m_setter, m_getter ) ClassDB::add_property( get_class_static(), m_property, _scs_create(m_setter), _scs_create(m_getter) )
+#define ADD_PROPERTYI( m_property, m_setter, m_getter, m_index ) ClassDB::add_property( get_class_static(), m_property, _scs_create(m_setter), _scs_create(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), _scs_create(m_setter), _scs_create(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), _scs_create(m_setter), _scs_create(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), _scs_create(m_setter), _scs_create(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), _scs_create(m_setter), _scs_create(m_getter), m_index )
#define ADD_GROUP( m_name, m_prefix ) ClassDB::add_property_group( get_class_static(), m_name, m_prefix )
struct PropertyInfo {
@@ -579,8 +580,8 @@ public:
}
/* 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;
@@ -679,7 +680,7 @@ class ObjectDB {
unsigned long i;
} u;
u.p=p_obj;
- return HashMapHahserDefault::hash((uint64_t)u.i);
+ return HashMapHasherDefault::hash((uint64_t)u.i);
}
};
@@ -721,6 +722,6 @@ public:
};
//needed by macros
-#include "object_type_db.h"
+#include "class_db.h"
#endif
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 804fe15c39..974225a3e8 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -30,7 +30,7 @@
#include "os/file_access.h"
#include "os/memory.h"
#include "os/os.h"
-#include "globals.h"
+#include "global_config.h"
String DirAccess::_get_root_path() const {
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index f824b5f319..7c173fc780 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -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 06723c5131..ae592720e8 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "file_access.h"
-#include "globals.h"
+#include "global_config.h"
#include "os/os.h"
#include "core/io/marshalls.h"
#include "io/md5.h"
diff --git a/core/os/input.cpp b/core/os/input.cpp
index d2bd433ed9..34883e63ba 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -29,7 +29,7 @@
#include "input.h"
#include "input_map.h"
#include "os/os.h"
-#include "globals.h"
+#include "global_config.h"
Input *Input::singleton=NULL;
Input *Input::get_singleton() {
@@ -38,7 +38,7 @@ Input *Input::get_singleton() {
}
void Input::set_mouse_mode(MouseMode p_mode) {
- ERR_FAIL_INDEX(p_mode,3);
+ ERR_FAIL_INDEX(p_mode,4);
OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode);
}
@@ -49,43 +49,45 @@ Input::MouseMode Input::get_mouse_mode() const {
void Input::_bind_methods() {
- 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_mouse_speed"),&Input::get_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()));
+ ClassDB::bind_method(D_METHOD("is_key_pressed","scancode"),&Input::is_key_pressed);
+ ClassDB::bind_method(D_METHOD("is_mouse_button_pressed","button"),&Input::is_mouse_button_pressed);
+ ClassDB::bind_method(D_METHOD("is_joy_button_pressed","device","button"),&Input::is_joy_button_pressed);
+ ClassDB::bind_method(D_METHOD("is_action_pressed","action"),&Input::is_action_pressed);
+ ClassDB::bind_method(D_METHOD("is_action_just_pressed","action"),&Input::is_action_just_pressed);
+ ClassDB::bind_method(D_METHOD("is_action_just_released","action"),&Input::is_action_just_released);
+ ClassDB::bind_method(D_METHOD("add_joy_mapping","mapping", "update_existing"),&Input::add_joy_mapping, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("remove_joy_mapping","guid"),&Input::remove_joy_mapping);
+ ClassDB::bind_method(D_METHOD("is_joy_known","device"),&Input::is_joy_known);
+ ClassDB::bind_method(D_METHOD("get_joy_axis","device","axis"),&Input::get_joy_axis);
+ ClassDB::bind_method(D_METHOD("get_joy_name","device"),&Input::get_joy_name);
+ ClassDB::bind_method(D_METHOD("get_joy_guid","device"),&Input::get_joy_guid);
+ ClassDB::bind_method(D_METHOD("get_connected_joypads"),&Input::get_connected_joypads);
+ ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength);
+ ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration);
+ ClassDB::bind_method(D_METHOD("get_joy_button_string", "button_index"), &Input::get_joy_button_string);
+ ClassDB::bind_method(D_METHOD("get_joy_button_index_from_string", "button"), &Input::get_joy_button_index_from_string);
+ ClassDB::bind_method(D_METHOD("get_joy_axis_string", "axis_index"), &Input::get_joy_axis_string);
+ ClassDB::bind_method(D_METHOD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string);
+ ClassDB::bind_method(D_METHOD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("stop_joy_vibration", "device"), &Input::stop_joy_vibration);
+ ClassDB::bind_method(D_METHOD("get_gravity"),&Input::get_gravity);
+ ClassDB::bind_method(D_METHOD("get_accelerometer"),&Input::get_accelerometer);
+ ClassDB::bind_method(D_METHOD("get_magnetometer"),&Input::get_magnetometer);
+ ClassDB::bind_method(D_METHOD("get_gyroscope"),&Input::get_gyroscope);
+ //ClassDB::bind_method(D_METHOD("get_mouse_pos"),&Input::get_mouse_pos); - this is not the function you want
+ ClassDB::bind_method(D_METHOD("get_last_mouse_speed"),&Input::get_last_mouse_speed);
+ ClassDB::bind_method(D_METHOD("get_mouse_button_mask"),&Input::get_mouse_button_mask);
+ ClassDB::bind_method(D_METHOD("set_mouse_mode","mode"),&Input::set_mouse_mode);
+ ClassDB::bind_method(D_METHOD("get_mouse_mode"),&Input::get_mouse_mode);
+ ClassDB::bind_method(D_METHOD("warp_mouse_pos","to"),&Input::warp_mouse_pos);
+ ClassDB::bind_method(D_METHOD("action_press","action"),&Input::action_press);
+ ClassDB::bind_method(D_METHOD("action_release","action"),&Input::action_release);
+ ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor","image:Texture","hotspot"),&Input::set_custom_mouse_cursor,DEFVAL(Vector2()));
BIND_CONSTANT( MOUSE_MODE_VISIBLE );
BIND_CONSTANT( MOUSE_MODE_HIDDEN );
BIND_CONSTANT( MOUSE_MODE_CAPTURED );
+ BIND_CONSTANT( MOUSE_MODE_CONFINED );
ADD_SIGNAL( MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "connected")) );
}
diff --git a/core/os/input.h b/core/os/input.h
index c365894f46..2cea154a50 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -47,7 +47,8 @@ public:
enum MouseMode {
MOUSE_MODE_VISIBLE,
MOUSE_MODE_HIDDEN,
- MOUSE_MODE_CAPTURED
+ MOUSE_MODE_CAPTURED,
+ MOUSE_MODE_CONFINED
};
void set_mouse_mode(MouseMode p_mode);
@@ -77,11 +78,12 @@ 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;
+ virtual Vector3 get_gravity() const=0;
virtual Vector3 get_accelerometer() const=0;
virtual Vector3 get_magnetometer() const=0;
virtual Vector3 get_gyroscope() const=0;
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 3cc595208f..4ef99558ad 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -39,6 +39,8 @@ bool InputEvent::operator==(const InputEvent &p_event) const {
}
switch(type) {
+ /** Current clang-format style doesn't play well with the aligned return values of that switch. */
+ /* clang-format off */
case NONE:
return true;
case KEY:
@@ -80,6 +82,7 @@ bool InputEvent::operator==(const InputEvent &p_event) const {
case ACTION:
return action.action == p_event.action.action
&& action.pressed == p_event.action.pressed;
+ /* clang-format on */
default:
ERR_PRINT("No logic to compare InputEvents of this type, this shouldn't happen.");
}
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index 309348ea31..40fa86d09f 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -36,6 +36,7 @@ struct _KeyCodeText {
static const _KeyCodeText _keycodes[]={
+ /* clang-format off */
{KEY_ESCAPE ,"Escape"},
{KEY_TAB ,"Tab"},
{KEY_BACKTAB ,"BackTab"},
@@ -281,7 +282,8 @@ static const _KeyCodeText _keycodes[]={
{KEY_DIVISION ,"Division"},
{KEY_YDIAERESIS ,"Ydiaeresis"},
- {0 ,0}
+ {0 ,0}
+ /* clang-format on */
};
bool keycode_has_unicode(uint32_t p_keycode) {
@@ -299,7 +301,8 @@ bool keycode_has_unicode(uint32_t p_keycode) {
case KEY_MEDIAPREVIOUS: case KEY_MEDIANEXT: case KEY_MEDIARECORD: case KEY_HOMEPAGE: case KEY_FAVORITES: case KEY_SEARCH: case KEY_STANDBY:
case KEY_OPENURL: case KEY_LAUNCHMAIL: case KEY_LAUNCHMEDIA: case KEY_LAUNCH0: case KEY_LAUNCH1: case KEY_LAUNCH2: case KEY_LAUNCH3: case KEY_LAUNCH4:
case KEY_LAUNCH5: case KEY_LAUNCH6: case KEY_LAUNCH7: case KEY_LAUNCH8: case KEY_LAUNCH9: case KEY_LAUNCHA: case KEY_LAUNCHB: case KEY_LAUNCHC: case KEY_LAUNCHD:
- case KEY_LAUNCHE: case KEY_LAUNCHF: return false;
+ case KEY_LAUNCHE: case KEY_LAUNCHF:
+ return false;
}
return true;
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index 11396666d2..dcda8e8952 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -31,12 +31,12 @@
void MainLoop::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("input_event","ev"),&MainLoop::input_event);
+ ClassDB::bind_method(D_METHOD("input_text","text"),&MainLoop::input_text);
+ ClassDB::bind_method(D_METHOD("init"),&MainLoop::init);
+ ClassDB::bind_method(D_METHOD("iteration","delta"),&MainLoop::iteration);
+ ClassDB::bind_method(D_METHOD("idle","delta"),&MainLoop::idle);
+ ClassDB::bind_method(D_METHOD("finish"),&MainLoop::finish);
BIND_VMETHOD( MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"ev")) );
BIND_VMETHOD( MethodInfo("_input_text",PropertyInfo(Variant::STRING,"text")) );
diff --git a/core/os/memory.h b/core/os/memory.h
index 0e6dea48d3..49424037ff 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -97,8 +97,8 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
#define memnew(m_class) _post_initialize(new("") m_class)
_ALWAYS_INLINE_ void * operator new(size_t p_size,void *p_pointer,size_t check, const char *p_description) {
-// 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;
}
diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp
index f5f7f757c3..acdcb492d9 100644
--- a/core/os/mutex.cpp
+++ b/core/os/mutex.cpp
@@ -47,7 +47,7 @@ Mutex::~Mutex() {
}
-Mutex *_global_mutex=NULL;;
+Mutex *_global_mutex=NULL;
void _global_lock() {
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 677bf63e69..912f7f0b0f 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -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 "global_config.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;
@@ -98,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;
}
@@ -152,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 {
@@ -187,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;
@@ -261,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) {
@@ -513,20 +484,13 @@ 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;
@@ -548,49 +512,21 @@ 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 5ea3216f24..e179b82dae 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -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;
@@ -141,7 +131,8 @@ public:
enum MouseMode {
MOUSE_MODE_VISIBLE,
MOUSE_MODE_HIDDEN,
- MOUSE_MODE_CAPTURED
+ MOUSE_MODE_CAPTURED,
+ MOUSE_MODE_CONFINED
};
virtual void set_mouse_mode(MouseMode p_mode);
@@ -185,15 +176,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);
@@ -217,7 +199,6 @@ public:
virtual MainLoop *get_main_loop() const=0;
- String get_custom_level() const { return _custom_level; }
virtual void yield();
@@ -280,17 +261,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 {
@@ -416,10 +389,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;
@@ -434,7 +403,7 @@ public:
virtual void set_use_vsync(bool p_enable);
virtual bool is_vsync_enabled() const;
- Dictionary get_engine_version() const;
+ virtual bool check_feature_support(const String& p_feature)=0;
bool is_hidpi_allowed() const { return _allow_hidpi; }
OS();
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index 5f3b877822..803a217fca 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -27,11 +27,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "packed_data_container.h"
+
#include "io/marshalls.h"
#include "core_string_names.h"
-
Variant PackedDataContainer::getvar(const Variant& p_key, bool *r_valid) const {
bool err=false;
@@ -382,15 +382,15 @@ Variant PackedDataContainer::_iter_get(const Variant& p_iter){
void PackedDataContainer::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("_set_data"),&PackedDataContainer::_set_data);
+ ClassDB::bind_method(D_METHOD("_get_data"),&PackedDataContainer::_get_data);
+ ClassDB::bind_method(D_METHOD("_iter_init"),&PackedDataContainer::_iter_init);
+ ClassDB::bind_method(D_METHOD("_iter_get"),&PackedDataContainer::_iter_get);
+ ClassDB::bind_method(D_METHOD("_iter_next"),&PackedDataContainer::_iter_next);
+ ClassDB::bind_method(D_METHOD("pack:Error","value"),&PackedDataContainer::pack);
+ ClassDB::bind_method(D_METHOD("size"),&PackedDataContainer::size);
- ADD_PROPERTY( PropertyInfo(Variant::POOL_BYTE_ARRAY,"__data__"),_SCS("_set_data"),_SCS("_get_data"));
+ ADD_PROPERTY( PropertyInfo(Variant::POOL_BYTE_ARRAY,"__data__"),"_set_data","_get_data");
}
@@ -426,11 +426,11 @@ bool PackedDataContainerRef::_is_dictionary() const {
void PackedDataContainerRef::_bind_methods() {
- 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);
+ ClassDB::bind_method(D_METHOD("size"),&PackedDataContainerRef::size);
+ ClassDB::bind_method(D_METHOD("_iter_init"),&PackedDataContainerRef::_iter_init);
+ ClassDB::bind_method(D_METHOD("_iter_get"),&PackedDataContainerRef::_iter_get);
+ ClassDB::bind_method(D_METHOD("_iter_next"),&PackedDataContainerRef::_iter_next);
+ ClassDB::bind_method(D_METHOD("_is_dictionary"),&PackedDataContainerRef::_is_dictionary);
}
diff --git a/core/pair.h b/core/pair.h
index d75cbed642..174ffb3883 100644
--- a/core/pair.h
+++ b/core/pair.h
@@ -39,4 +39,13 @@ struct Pair {
Pair( F p_first, S p_second) { first=p_first; second=p_second; }
};
+template<class F,class S>
+struct PairSort {
+
+ bool operator()(const Pair<F,S>& A, const Pair<F,S>& B) const {
+ return A.first < B.first;
+ }
+};
+
+
#endif // PAIR_H
diff --git a/core/path_db.cpp b/core/path_db.cpp
index 25f62ed951..679372898c 100644
--- a/core/path_db.cpp
+++ b/core/path_db.cpp
@@ -27,8 +27,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "path_db.h"
-#include "print_string.h"
+#include "print_string.h"
uint32_t NodePath::hash() const {
@@ -334,7 +334,7 @@ NodePath::NodePath(const String& p_path) {
StringName property;
Vector<StringName> subpath;
- int absolute=(path[0]=='/')?1:0;;
+ int absolute=(path[0]=='/')?1:0;
bool last_is_slash=true;
int slices=0;
int subpath_pos=path.find(":");
diff --git a/core/path_remap.cpp b/core/path_remap.cpp
index fd5b38fa79..bbaba71bba 100644
--- a/core/path_remap.cpp
+++ b/core/path_remap.cpp
@@ -27,177 +27,4 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "path_remap.h"
-#include "globals.h"
-#include "os/os.h"
-#include "translation.h"
-PathRemap* PathRemap::singleton=NULL;
-PathRemap* PathRemap::get_singleton() {
-
- return singleton;
-}
-
-void PathRemap::add_remap(const String& p_from, const String& p_to,const String& p_locale) {
-
- if (!remap.has(p_from)) {
- remap[p_from]=RemapData();
- }
-
- if (p_locale==String())
- remap[p_from].always=p_to;
- else
- remap[p_from].locale[p_locale]=p_to;
-}
-
-
-String PathRemap::get_remap(const String& p_from) const {
-
- const RemapData *ptr=remap.getptr(p_from);
- if (!ptr) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap failed: "+p_from);
- return p_from;
- } else {
-
- const RemapData *ptr2=NULL;
-
- String locale = TranslationServer::get_singleton()->get_locale();
-
- if (ptr->locale.has(locale)) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap found: "+p_from+" -> "+ptr->locale[locale]);
-
- ptr2=remap.getptr(ptr->locale[locale]);
-
- if (ptr2 && ptr2->always!=String()) //may have atlas or export remap too
- return ptr2->always;
- else
- return ptr->locale[locale];
- }
-
- int p = locale.find("_");
- if (p!=-1) {
- locale=locale.substr(0,p);
- if (ptr->locale.has(locale)) {
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap found: "+p_from+" -> "+ptr->locale[locale]);
-
- ptr2=remap.getptr(ptr->locale[locale]);
-
- if (ptr2 && ptr2->always!=String()) //may have atlas or export remap too
- return ptr2->always;
- else
- return ptr->locale[locale];
-
- }
- }
-
- if (ptr->always!=String()) {
- if (OS::get_singleton()->is_stdout_verbose()) {
- print_line("remap found: "+p_from+" -> "+ptr->always);
- }
- return ptr->always;
- }
-
- if (OS::get_singleton()->is_stdout_verbose())
- print_line("remap failed: "+p_from);
-
- return p_from;
- }
-}
-bool PathRemap::has_remap(const String& p_from) const{
-
- return remap.has(p_from);
-}
-
-void PathRemap::erase_remap(const String& p_from){
-
- ERR_FAIL_COND(!remap.has(p_from));
- remap.erase(p_from);
-}
-
-void PathRemap::clear_remaps() {
-
- remap.clear();
-}
-
-void PathRemap::load_remaps() {
-
- // default remaps first
- PoolVector<String> remaps = GlobalConfig::get_singleton()->get("remap/all");
-
- {
- int rlen = remaps.size();
-
- ERR_FAIL_COND( rlen%2 );
- PoolVector<String>::Read r = remaps.read();
- for(int i=0;i<rlen/2;i++) {
-
- String from = r[i*2+0];
- String to = r[i*2+1];
- add_remap(from,to);
- }
- }
-
-
- // platform remaps second, so override
- 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 );
- PoolVector<String>::Read r = remaps.read();
- for(int i=0;i<rlen/2;i++) {
-
- String from = r[i*2+0];
- String to = r[i*2+1];
-// print_line("add remap: "+from+" -> "+to);
- add_remap(from,to);
- }
- }
-
-
- //locale based remaps
-
- if (GlobalConfig::get_singleton()->has("locale/translation_remaps")) {
-
- Dictionary remaps = GlobalConfig::get_singleton()->get("locale/translation_remaps");
- List<Variant> rk;
- remaps.get_key_list(&rk);
- for(List<Variant>::Element *E=rk.front();E;E=E->next()) {
-
- String source = E->get();
- PoolStringArray sa = remaps[E->get()];
- int sas = sa.size();
- PoolStringArray::Read r = sa.read();
-
- for(int i=0;i<sas;i++) {
-
- String s = r[i];
- int qp = s.find_last(":");
- if (qp!=-1) {
- String path = s.substr(0,qp);
- String locale = s.substr(qp+1,s.length());
- add_remap(source,path,locale);
- }
- }
- }
-
- }
-
-}
-
-void PathRemap::_bind_methods() {
-
- ClassDB::bind_method(_MD("add_remap","from","to","locale"),&PathRemap::add_remap,DEFVAL(String()));
- ClassDB::bind_method(_MD("has_remap","path"),&PathRemap::has_remap);
- ClassDB::bind_method(_MD("get_remap","path"),&PathRemap::get_remap);
- ClassDB::bind_method(_MD("erase_remap","path"),&PathRemap::erase_remap);
- ClassDB::bind_method(_MD("clear_remaps"),&PathRemap::clear_remaps);
-}
-
-PathRemap::PathRemap() {
-
- singleton=this;
-}
diff --git a/core/path_remap.h b/core/path_remap.h
index a106030f95..966bb10ea5 100644
--- a/core/path_remap.h
+++ b/core/path_remap.h
@@ -29,39 +29,4 @@
#ifndef PATH_REMAP_H
#define PATH_REMAP_H
-#include "hash_map.h"
-#include "ustring.h"
-#include "object.h"
-
-
-class PathRemap : public Object {
-
- GDCLASS(PathRemap,Object);
-
- static PathRemap* singleton;
- struct RemapData {
- String always;
- Map<String,String> locale;
- };
-
- HashMap<String,RemapData> remap;
-protected:
-
- static void _bind_methods();
-public:
-
- void add_remap(const String& p_from, const String& p_to,const String& p_locale=String());
- bool has_remap(const String& p_from) const;
- //_FORCE_INLINE_ String get_remap(const String& p_from) const { const String *ptr=remap.getptr(p_from); if (!ptr) return p_from; else return *ptr; }
- String get_remap(const String& p_from) const;
- void erase_remap(const String& p_from);
- void clear_remaps();
-
- void load_remaps();
-
- static PathRemap* get_singleton();
-
- PathRemap();
-};
-
#endif // PATH_REMAP_H
diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp
index e425218060..3260225ac3 100644
--- a/core/pool_allocator.cpp
+++ b/core/pool_allocator.cpp
@@ -27,12 +27,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "pool_allocator.h"
+
#include "error_macros.h"
#include "core/os/os.h"
#include "os/memory.h"
#include "os/copymem.h"
#include "print_string.h"
+
#include <assert.h>
+
#define COMPACT_CHUNK( m_entry , m_to_pos ) \
do { \
void *_dst=&((unsigned char*)pool)[m_to_pos]; \
@@ -501,7 +504,7 @@ const void *PoolAllocator::get(ID p_mem) const {
return NULL;
}
- if (e->pos<0 || (int)e->pos>=pool_size) {
+ if ((int)e->pos>=pool_size) {
mt_unlock();
ERR_PRINT("e->pos<0 || e->pos>=pool_size");
@@ -543,7 +546,7 @@ void *PoolAllocator::get(ID p_mem) {
return NULL;
}
- if (e->pos<0 || (int)e->pos>=pool_size) {
+ if ((int)e->pos>=pool_size) {
mt_unlock();
ERR_PRINT("e->pos<0 || e->pos>=pool_size");
diff --git a/core/print_string.cpp b/core/print_string.cpp
index 3faed62bb4..36316af619 100644
--- a/core/print_string.cpp
+++ b/core/print_string.cpp
@@ -27,7 +27,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "print_string.h"
+
#include "os/os.h"
+
#include <stdio.h>
static PrintHandlerList *print_handler_list=NULL;
diff --git a/core/profile_clock.cpp b/core/profile_clock.cpp
deleted file mode 100644
index 0806275463..0000000000
--- a/core/profile_clock.cpp
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "profile_clock.h"
-
-
diff --git a/core/profile_clock.h b/core/profile_clock.h
deleted file mode 100644
index e254580249..0000000000
--- a/core/profile_clock.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef PROFILE_CLOCK_H
-#define PROFILE_CLOCK_H
-
-
-
-
-#endif // PROFILE_CLOCK_H
diff --git a/core/ref_ptr.cpp b/core/ref_ptr.cpp
index e781bae496..29ffe974d2 100644
--- a/core/ref_ptr.cpp
+++ b/core/ref_ptr.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "ref_ptr.h"
+
#include "reference.h"
#include "resource.h"
diff --git a/core/reference.cpp b/core/reference.cpp
index 69e053cc1a..5e8244d2ca 100644
--- a/core/reference.cpp
+++ b/core/reference.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "reference.h"
+
#include "script_language.h"
@@ -54,9 +55,9 @@ bool Reference::init_ref() {
void Reference::_bind_methods() {
- ClassDB::bind_method(_MD("init_ref"),&Reference::init_ref);
- ClassDB::bind_method(_MD("reference"),&Reference::reference);
- ClassDB::bind_method(_MD("unreference"),&Reference::unreference);
+ ClassDB::bind_method(D_METHOD("init_ref"),&Reference::init_ref);
+ ClassDB::bind_method(D_METHOD("reference"),&Reference::reference);
+ ClassDB::bind_method(D_METHOD("unreference"),&Reference::unreference);
}
int Reference::reference_get_count() const {
@@ -126,7 +127,7 @@ WeakRef::WeakRef() {
void WeakRef::_bind_methods() {
- ClassDB::bind_method(_MD("get_ref:Object"),&WeakRef::get_ref);
+ ClassDB::bind_method(D_METHOD("get_ref:Object"),&WeakRef::get_ref);
}
#if 0
diff --git a/core/reference.h b/core/reference.h
index ce196801bb..e130b4c2b4 100644
--- a/core/reference.h
+++ b/core/reference.h
@@ -32,7 +32,7 @@
#include "object.h"
#include "safe_refcount.h"
#include "ref_ptr.h"
-#include "object_type_db.h"
+#include "class_db.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index fe88d1d13d..00f6f8662f 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -35,8 +35,8 @@
#include "io/packet_peer.h"
#include "math/a_star.h"
#include "math/triangle_mesh.h"
-#include "globals.h"
-#include "object_type_db.h"
+#include "global_config.h"
+#include "class_db.h"
#include "geometry.h"
#include "bind/core_bind.h"
#include "core_string_names.h"
@@ -45,6 +45,7 @@
#include "compressed_translation.h"
#include "io/translation_loader_po.h"
#include "io/resource_format_binary.h"
+#include "io/resource_import.h"
#include "io/stream_peer_ssl.h"
#include "os/input.h"
#include "core/io/xml_parser.h"
@@ -57,11 +58,12 @@
static ResourceFormatSaverBinary *resource_saver_binary=NULL;
static ResourceFormatLoaderBinary *resource_loader_binary=NULL;
-
+static ResourceFormatImporter *resource_format_importer=NULL;
static _ResourceLoader *_resource_loader=NULL;
static _ResourceSaver *_resource_saver=NULL;
static _OS *_os=NULL;
+static _Engine *_engine=NULL;
static _ClassDB *_classdb=NULL;
static _Marshalls *_marshalls = NULL;
static TranslationLoaderPO *resource_format_po=NULL;
@@ -104,12 +106,14 @@ void register_core_types() {
resource_loader_binary = memnew( ResourceFormatLoaderBinary );
ResourceLoader::add_resource_format_loader(resource_loader_binary);
+ resource_format_importer = memnew( ResourceFormatImporter );
+ ResourceLoader::add_resource_format_loader(resource_format_importer);
+
ClassDB::register_class<Object>();
ClassDB::register_class<Reference>();
ClassDB::register_class<WeakRef>();
- ClassDB::register_class<ResourceImportMetadata>();
ClassDB::register_class<Resource>();
ClassDB::register_class<FuncRef>();
ClassDB::register_virtual_class<StreamPeer>();
@@ -122,7 +126,7 @@ void register_core_types() {
ClassDB::register_virtual_class<PacketPeer>();
ClassDB::register_class<PacketPeerStream>();
ClassDB::register_class<MainLoop>();
-// ClassDB::register_type<OptimizedSaver>();
+ //ClassDB::register_type<OptimizedSaver>();
ClassDB::register_class<Translation>();
ClassDB::register_class<PHashTranslation>();
ClassDB::register_class<UndoRedo>();
@@ -156,6 +160,7 @@ void register_core_types() {
_resource_loader=memnew(_ResourceLoader);
_resource_saver=memnew(_ResourceSaver);
_os=memnew(_OS);
+ _engine=memnew(_Engine);
_classdb=memnew(_ClassDB);
_marshalls = memnew(_Marshalls);
@@ -177,12 +182,11 @@ void register_core_singletons() {
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Geometry",_Geometry::get_singleton()) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceLoader",_ResourceLoader::get_singleton()) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceSaver",_ResourceSaver::get_singleton()) );
- GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("PathRemap",PathRemap::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("OS",_OS::get_singleton() ) );
+ GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Engine",_Engine::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ClassDB",_classdb ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Marshalls",_Marshalls::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("TranslationServer",TranslationServer::get_singleton() ) );
- GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("TS",TranslationServer::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Input",Input::get_singleton() ) );
GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("InputMap",InputMap::get_singleton() ) );
@@ -196,6 +200,7 @@ void unregister_core_types() {
memdelete( _resource_loader );
memdelete( _resource_saver );
memdelete( _os);
+ memdelete( _engine );
memdelete( _classdb );
memdelete( _marshalls );
@@ -205,6 +210,8 @@ void unregister_core_types() {
memdelete(resource_saver_binary);
if (resource_loader_binary)
memdelete(resource_loader_binary);
+ if (resource_format_importer)
+ memdelete(resource_format_importer);
memdelete( resource_format_po );
diff --git a/core/resource.cpp b/core/resource.cpp
index db4d2ec0db..fe3cb2df92 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -27,124 +27,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "resource.h"
+
#include "core_string_names.h"
-#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) {
-
- editor=p_editor;
-}
-
-String ResourceImportMetadata::get_editor() const{
-
- return editor;
-}
-
-void ResourceImportMetadata::add_source(const String& p_path,const String& p_md5) {
-
- Source s;
- s.md5=p_md5;
- s.path=p_path;
- sources.push_back(s);
-}
-
-String ResourceImportMetadata::get_source_path(int p_idx) const{
- ERR_FAIL_INDEX_V(p_idx,sources.size(),String());
- return sources[p_idx].path;
-}
-String ResourceImportMetadata::get_source_md5(int p_idx) const{
- ERR_FAIL_INDEX_V(p_idx,sources.size(),String());
- return sources[p_idx].md5;
-}
-
-void ResourceImportMetadata::set_source_md5(int p_idx,const String& p_md5) {
-
- ERR_FAIL_INDEX(p_idx,sources.size());
- sources[p_idx].md5=p_md5;
-
-}
-
-void ResourceImportMetadata::remove_source(int p_idx){
-
- ERR_FAIL_INDEX(p_idx,sources.size());
- sources.remove(p_idx);
-
-}
-
-int ResourceImportMetadata::get_source_count() const {
-
- return sources.size();
-}
-void ResourceImportMetadata::set_option(const String& p_key, const Variant& p_value) {
-
- if (p_value.get_type()==Variant::NIL) {
- options.erase(p_key);
- return;
- }
-
- ERR_FAIL_COND(p_value.get_type() == Variant::OBJECT);
- ERR_FAIL_COND(p_value.get_type() == Variant::_RID);
-
- options[p_key]=p_value;
-
-}
-
-bool ResourceImportMetadata::has_option(const String& p_key) const {
-
- return options.has(p_key);
-}
-
-Variant ResourceImportMetadata::get_option(const String& p_key) const {
-
- ERR_FAIL_COND_V(!options.has(p_key),Variant());
-
- return options[p_key];
-}
-
-void ResourceImportMetadata::get_options(List<String> *r_options) const {
-
- for(Map<String,Variant>::Element *E=options.front();E;E=E->next()) {
-
- r_options->push_back(E->key());
- }
-
-}
-
-PoolStringArray ResourceImportMetadata::_get_options() const {
-
- PoolStringArray option_names;
- option_names.resize(options.size());
- int i=0;
- for(Map<String,Variant>::Element *E=options.front();E;E=E->next()) {
-
- option_names.set(i++,E->key());
- }
-
- return option_names;
-}
-
-void ResourceImportMetadata::_bind_methods() {
-
- ClassDB::bind_method(_MD("set_editor","name"),&ResourceImportMetadata::set_editor);
- ClassDB::bind_method(_MD("get_editor"),&ResourceImportMetadata::get_editor);
- ClassDB::bind_method(_MD("add_source","path","md5"),&ResourceImportMetadata::add_source, "");
- ClassDB::bind_method(_MD("get_source_path","idx"),&ResourceImportMetadata::get_source_path);
- ClassDB::bind_method(_MD("get_source_md5","idx"),&ResourceImportMetadata::get_source_md5);
- ClassDB::bind_method(_MD("set_source_md5","idx", "md5"),&ResourceImportMetadata::set_source_md5);
- ClassDB::bind_method(_MD("remove_source","idx"),&ResourceImportMetadata::remove_source);
- ClassDB::bind_method(_MD("get_source_count"),&ResourceImportMetadata::get_source_count);
- ClassDB::bind_method(_MD("set_option","key","value"),&ResourceImportMetadata::set_option);
- ClassDB::bind_method(_MD("get_option","key"),&ResourceImportMetadata::get_option);
- ClassDB::bind_method(_MD("get_options"),&ResourceImportMetadata::_get_options);
-}
-
-ResourceImportMetadata::ResourceImportMetadata() {
-
-
-}
+#include <stdio.h>
void Resource::emit_changed() {
@@ -198,7 +87,7 @@ 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::resources[path_cache]=this;
ResourceCache::lock->write_unlock();
}
@@ -379,21 +268,6 @@ void Resource::notify_change_to_owners() {
}
}
-void Resource::set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata) {
-#ifdef TOOLS_ENABLED
- import_metadata=p_metadata;
-#endif
-}
-
-Ref<ResourceImportMetadata> Resource::get_import_metadata() const {
-
-#ifdef TOOLS_ENABLED
- return import_metadata;
-#else
- return Ref<ResourceImportMetadata>();
-#endif
-
-}
#ifdef TOOLS_ENABLED
@@ -453,25 +327,23 @@ 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));
+ ClassDB::bind_method(D_METHOD("set_path","path"),&Resource::_set_path);
+ ClassDB::bind_method(D_METHOD("take_over_path","path"),&Resource::_take_over_path);
+ ClassDB::bind_method(D_METHOD("get_path"),&Resource::get_path);
+ ClassDB::bind_method(D_METHOD("set_name","name"),&Resource::set_name);
+ ClassDB::bind_method(D_METHOD("get_name"),&Resource::get_name);
+ ClassDB::bind_method(D_METHOD("get_rid"),&Resource::get_rid);
+ ClassDB::bind_method(D_METHOD("set_local_to_scene","enable"),&Resource::set_local_to_scene);
+ ClassDB::bind_method(D_METHOD("is_local_to_scene"),&Resource::is_local_to_scene);
+ ClassDB::bind_method(D_METHOD("get_local_scene:Node"),&Resource::get_local_scene);
+ ClassDB::bind_method(D_METHOD("setup_local_to_scene"),&Resource::setup_local_to_scene);
+
+ ClassDB::bind_method(D_METHOD("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"));
+ ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"resource_local_to_scene" ), "set_local_to_scene","is_local_to_scene");
+ ADD_PROPERTY( PropertyInfo(Variant::STRING,"resource_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR ), "set_path","get_path");
+ ADD_PROPERTYNZ( PropertyInfo(Variant::STRING,"resource_name"), "set_name","get_name");
BIND_VMETHOD( MethodInfo("_setup_local_to_scene") );
@@ -481,9 +353,11 @@ Resource::Resource() {
#ifdef TOOLS_ENABLED
last_modified_time=0;
+ import_last_modified_time=0;
#endif
subindex=0;
+ local_to_scene=false;
local_scene=NULL;
}
@@ -522,18 +396,19 @@ void ResourceCache::clear() {
void ResourceCache::reload_externals() {
- //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) {
- lock->read_lock();;
+ lock->read_lock();
bool b = resources.has(p_path);
- lock->read_unlock();;
+ lock->read_unlock();
return b;
diff --git a/core/resource.h b/core/resource.h
index 284c59e1a8..b29077a3b8 100644
--- a/core/resource.h
+++ b/core/resource.h
@@ -33,7 +33,7 @@
#include "safe_refcount.h"
#include "ref_ptr.h"
#include "reference.h"
-#include "object_type_db.h"
+#include "class_db.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
@@ -46,47 +46,6 @@ virtual String get_base_extension() const { return m_ext; }\
private:
-class ResourceImportMetadata : public Reference {
-
- GDCLASS( ResourceImportMetadata, Reference );
-
- struct Source {
- String path;
- String md5;
- };
-
- Vector<Source> sources;
- String editor;
-
- Map<String,Variant> options;
-
- PoolStringArray _get_options() const;
-
-protected:
-
- static void _bind_methods();
-public:
-
- void set_editor(const String& p_editor);
- String get_editor() const;
-
- void add_source(const String& p_path,const String& p_md5="");
- String get_source_path(int p_idx) const;
- String get_source_md5(int p_idx) const;
- void set_source_md5(int p_idx,const String& p_md5);
- void remove_source(int p_idx);
- int get_source_count() const;
-
- void set_option(const String& p_key, const Variant& p_value);
- Variant get_option(const String& p_key) const;
- bool has_option(const String& p_key) const;
-
- void get_options(List<String> *r_options) const;
-
-
- ResourceImportMetadata();
-};
-
class Resource : public Reference {
@@ -106,8 +65,9 @@ friend class ResourceCache;
virtual bool _use_builtin_script() const { return true; }
#ifdef TOOLS_ENABLED
- Ref<ResourceImportMetadata> import_metadata;
uint64_t last_modified_time;
+ uint64_t import_last_modified_time;
+ String import_path;
#endif
bool local_to_scene;
@@ -147,10 +107,6 @@ public:
Ref<Resource> duplicate(bool p_subresources=false);
Ref<Resource> duplicate_for_local_scene(Node *p_scene,Map<Ref<Resource>,Ref<Resource> >& remap_cache);
-
- void set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata);
- Ref<ResourceImportMetadata> get_import_metadata() const;
-
void set_local_to_scene(bool p_enable);
bool is_local_to_scene() const;
virtual void setup_local_to_scene();
@@ -164,6 +120,12 @@ public:
virtual void set_last_modified_time(uint64_t p_time) { last_modified_time=p_time; }
uint64_t get_last_modified_time() const { return last_modified_time; }
+ virtual void set_import_last_modified_time(uint64_t p_time) { import_last_modified_time=p_time; }
+ uint64_t get_import_last_modified_time() const { return import_last_modified_time; }
+
+ void set_import_path(const String& p_path) { import_path=p_path; }
+ String get_import_path() const { return import_path; }
+
#endif
virtual RID get_rid() const; // some resources may offer conversion to RID
diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp
index ede37bbe8a..50617f2062 100644
--- a/core/safe_refcount.cpp
+++ b/core/safe_refcount.cpp
@@ -44,6 +44,14 @@ uint32_t atomic_conditional_increment( register uint32_t * pw ) {
return *pw;
}
+uint32_t atomic_increment( register uint32_t * pw ) {
+
+ (*pw)++;
+
+ return *pw;
+
+}
+
uint32_t atomic_decrement( register uint32_t * pw ) {
(*pw)--;
diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp
index a8d77668f5..22aceac4c5 100644
--- a/core/script_debugger_local.cpp
+++ b/core/script_debugger_local.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "script_debugger_local.h"
+
#include "os/os.h"
void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) {
@@ -286,7 +287,7 @@ void ScriptDebuggerLocal::profiling_end() {
for(int i=0;i<ofs;i++) {
print_line(itos(i)+":"+pinfo[i].signature);
- float tt=USEC_TO_SEC(pinfo[i].total_time);;
+ float tt=USEC_TO_SEC(pinfo[i].total_time);
float st=USEC_TO_SEC(pinfo[i].self_time);
print_line("\ttotal_ms: "+rtos(tt)+"\tself_ms: "+rtos(st)+"total%: "+itos(tt*100/total_time)+"\tself%: "+itos(st*100/total_time)+"\tcalls: "+itos(pinfo[i].call_count));
}
diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp
index 62fcd5247f..b14eb51b6c 100644
--- a/core/script_debugger_remote.cpp
+++ b/core/script_debugger_remote.cpp
@@ -27,10 +27,12 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "script_debugger_remote.h"
+
#include "os/os.h"
#include "io/ip.h"
-#include "globals.h"
+#include "global_config.h"
#include "os/input.h"
+
void ScriptDebuggerRemote::_send_video_memory() {
List<ResourceUsage> usage;
@@ -66,7 +68,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,7 +131,7 @@ 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();
}
@@ -446,7 +448,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);
}
@@ -778,7 +780,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
@@ -887,7 +889,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;
@@ -928,7 +930,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);
}
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 52ae181c32..32db35d018 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -46,13 +46,13 @@ void Script::_notification( int p_what) {
void Script::_bind_methods() {
- 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));
+ ClassDB::bind_method(D_METHOD("can_instance"),&Script::can_instance);
+ //ClassDB::bind_method(D_METHOD("instance_create","base_object"),&Script::instance_create);
+ ClassDB::bind_method(D_METHOD("instance_has","base_object"),&Script::instance_has);
+ ClassDB::bind_method(D_METHOD("has_source_code"),&Script::has_source_code);
+ ClassDB::bind_method(D_METHOD("get_source_code"),&Script::get_source_code);
+ ClassDB::bind_method(D_METHOD("set_source_code","source"),&Script::set_source_code);
+ ClassDB::bind_method(D_METHOD("reload","keep_state"),&Script::reload,DEFVAL(false));
}
diff --git a/core/set.h b/core/set.h
index 9da2887671..a921fc661f 100644
--- a/core/set.h
+++ b/core/set.h
@@ -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;
@@ -416,7 +416,7 @@ private:
Element *aux=node->parent->left;
if (aux->color==RED) {
_set_color(aux,BLACK);
- _set_color(node->parent,RED);;
+ _set_color(node->parent,RED);
_rotate_right(node->parent);
aux=node->parent->left;
}
diff --git a/core/string_db.cpp b/core/string_db.cpp
index be35a44ed1..004b07b9e5 100644
--- a/core/string_db.cpp
+++ b/core/string_db.cpp
@@ -27,8 +27,10 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "string_db.h"
+
#include "print_string.h"
#include "os/os.h"
+
StaticCString StaticCString::create(const char *p_ptr) {
StaticCString scs; scs.ptr=p_ptr; return scs;
}
diff --git a/core/string_db.h b/core/string_db.h
index a14cdbc7ba..2c5262adaa 100644
--- a/core/string_db.h
+++ b/core/string_db.h
@@ -155,7 +155,4 @@ struct StringNameHasher {
StringName _scs_create(const char *p_chr);
-//#define _SCS(m_cstr) (m_cstr[0]?StringName(StaticCString::create(m_cstr)):StringName())
-#define _SCS(m_cstr) _scs_create(m_cstr)
-
#endif
diff --git a/core/translation.cpp b/core/translation.cpp
index 5215e5f6d1..d9d4fe7784 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -27,7 +27,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "translation.h"
-#include "globals.h"
+
+#include "global_config.h"
#include "io/resource_loader.h"
#include "os/os.h"
@@ -669,6 +670,7 @@ static const char* locale_names[]={
"Sanskrit (India)",
"Santali (India)",
"Sardinian (Italy)",
+"Scots (Scotland)",
"Sindhi (India)",
"Northern Sami (Norway)",
"Samogitian (Lithuania)",
@@ -750,6 +752,20 @@ static const char* locale_names[]={
0
};
+bool TranslationServer::is_locale_valid(const String& p_locale) {
+
+ const char **ptr=locale_list;
+
+ while (*ptr) {
+
+ if (*ptr==p_locale)
+ return true;
+ ptr++;
+ }
+
+ return false;
+
+}
Vector<String> TranslationServer::get_all_locales() {
@@ -899,18 +915,18 @@ int Translation::get_message_count() const {
void Translation::_bind_methods() {
- 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") );
+ ClassDB::bind_method(D_METHOD("set_locale","locale"),&Translation::set_locale);
+ ClassDB::bind_method(D_METHOD("get_locale"),&Translation::get_locale);
+ ClassDB::bind_method(D_METHOD("add_message","src_message","xlated_message"),&Translation::add_message);
+ ClassDB::bind_method(D_METHOD("get_message","src_message"),&Translation::get_message);
+ ClassDB::bind_method(D_METHOD("erase_message","src_message"),&Translation::erase_message);
+ ClassDB::bind_method(D_METHOD("get_message_list"),&Translation::_get_message_list);
+ ClassDB::bind_method(D_METHOD("get_message_count"),&Translation::get_message_count);
+ ClassDB::bind_method(D_METHOD("_set_messages"),&Translation::_set_messages);
+ ClassDB::bind_method(D_METHOD("_get_messages"),&Translation::_get_messages);
+
+ ADD_PROPERTY( PropertyInfo(Variant::POOL_STRING_ARRAY,"messages",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), "_set_messages", "_get_messages") ;
+ ADD_PROPERTY( PropertyInfo(Variant::STRING,"locale"), "set_locale", "get_locale") ;
}
Translation::Translation() {
@@ -1121,15 +1137,15 @@ StringName TranslationServer::tool_translate(const StringName& p_message) const
void TranslationServer::_bind_methods() {
- ClassDB::bind_method(_MD("set_locale","locale"),&TranslationServer::set_locale);
- ClassDB::bind_method(_MD("get_locale"),&TranslationServer::get_locale);
+ ClassDB::bind_method(D_METHOD("set_locale","locale"),&TranslationServer::set_locale);
+ ClassDB::bind_method(D_METHOD("get_locale"),&TranslationServer::get_locale);
- ClassDB::bind_method(_MD("translate","message"),&TranslationServer::translate);
+ ClassDB::bind_method(D_METHOD("translate","message"),&TranslationServer::translate);
- ClassDB::bind_method(_MD("add_translation","translation:Translation"),&TranslationServer::add_translation);
- ClassDB::bind_method(_MD("remove_translation","translation:Translation"),&TranslationServer::remove_translation);
+ ClassDB::bind_method(D_METHOD("add_translation","translation:Translation"),&TranslationServer::add_translation);
+ ClassDB::bind_method(D_METHOD("remove_translation","translation:Translation"),&TranslationServer::remove_translation);
- ClassDB::bind_method(_MD("clear"),&TranslationServer::clear);
+ ClassDB::bind_method(D_METHOD("clear"),&TranslationServer::clear);
}
diff --git a/core/translation.h b/core/translation.h
index 85ab4a229d..feed352549 100644
--- a/core/translation.h
+++ b/core/translation.h
@@ -102,6 +102,7 @@ public:
static Vector<String> get_all_locales();
static Vector<String> get_all_locale_names();
+ static bool is_locale_valid(const String& p_locale);
void set_tool_translation(const Ref<Translation>& p_translation);
StringName tool_translate(const StringName& p_message) const;
diff --git a/core/typedefs.h b/core/typedefs.h
index 176c77570d..c630887924 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -40,41 +40,39 @@
#define _STR(m_x) #m_x
#define _MKSTR(m_x) _STR(m_x)
#endif
-// have to include version.h for this to work, include it in the .cpp not the .h
+
+/**
+ * Version macros - it is necessary to include "version.h" for those to work.
+ * Include it in the .cpp file, not the header.
+ */
#ifdef VERSION_PATCH
-#define VERSION_MKSTRING _MKSTR(VERSION_MAJOR)"." _MKSTR(VERSION_MINOR)"." _MKSTR(VERSION_PATCH)"." _MKSTR(VERSION_STATUS)"." _MKSTR(VERSION_REVISION)
+#define VERSION_MKSTRING "" _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR) "." _MKSTR(VERSION_PATCH) "." _MKSTR(VERSION_STATUS) "." _MKSTR(VERSION_REVISION)
#else
-#define VERSION_MKSTRING _MKSTR(VERSION_MAJOR)"." _MKSTR(VERSION_MINOR)"." _MKSTR(VERSION_STATUS)"." _MKSTR(VERSION_REVISION)
+#define VERSION_MKSTRING "" _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR) "." _MKSTR(VERSION_STATUS) "." _MKSTR(VERSION_REVISION)
#endif // VERSION_PATCH
-#define VERSION_FULL_NAME _MKSTR(VERSION_NAME)" v" VERSION_MKSTRING
+#define VERSION_FULL_NAME "" _MKSTR(VERSION_NAME) " v" VERSION_MKSTRING
#ifndef _ALWAYS_INLINE_
#if defined(__GNUC__) && (__GNUC__ >= 4 )
-# define _ALWAYS_INLINE_ __attribute__((always_inline)) inline
+#define _ALWAYS_INLINE_ __attribute__((always_inline)) inline
#elif defined(__llvm__)
-# define _ALWAYS_INLINE_ __attribute__((always_inline)) inline
+#define _ALWAYS_INLINE_ __attribute__((always_inline)) inline
#elif defined(_MSC_VER)
-# define _ALWAYS_INLINE_ __forceinline
+#define _ALWAYS_INLINE_ __forceinline
#else
-# define _ALWAYS_INLINE_ inline
+#define _ALWAYS_INLINE_ inline
#endif
#endif
#ifndef _FORCE_INLINE_
-
#ifdef DEBUG_ENABLED
-
#define _FORCE_INLINE_ inline
-
#else
-
#define _FORCE_INLINE_ _ALWAYS_INLINE_
-
#endif
-
#endif
@@ -97,16 +95,16 @@ T *_nullptr() { T*t=NULL; return t; }
*/
#ifdef _WIN32
-# undef min // override standard definition
-# undef max // override standard definition
-# undef ERROR // override (really stupid) wingdi.h standard definition
-# undef DELETE // override (another really stupid) winnt.h standard definition
-# undef MessageBox // override winuser.h standard definition
-# undef MIN // override standard definition
-# undef MAX // override standard definition
-# undef CLAMP // override standard definition
-# undef Error
-# undef OK
+#undef min // override standard definition
+#undef max // override standard definition
+#undef ERROR // override (really stupid) wingdi.h standard definition
+#undef DELETE // override (another really stupid) winnt.h standard definition
+#undef MessageBox // override winuser.h standard definition
+#undef MIN // override standard definition
+#undef MAX // override standard definition
+#undef CLAMP // override standard definition
+#undef Error
+#undef OK
#endif
#include "error_macros.h"
@@ -150,30 +148,30 @@ inline void __swap_tmpl(T &x, T &y ) {
#endif //swap
-#define HEX2CHR( m_hex ) ( (m_hex>='0' && m_hex<='9')?(m_hex-'0'):\
- ((m_hex>='A' && m_hex<='F')?(10+m_hex-'A'):\
- ((m_hex>='a' && m_hex<='f')?(10+m_hex-'a'):0)))
+/* clang-format off */
+#define HEX2CHR(m_hex) \
+ ((m_hex >= '0' && m_hex <= '9') ? (m_hex - '0') : \
+ ((m_hex >= 'A' && m_hex <= 'F') ? (10 + m_hex - 'A') : \
+ ((m_hex >= 'a' && m_hex <= 'f') ? (10 + m_hex - 'a') : 0)))
+/* clang-format on */
// Macro to check whether we are compiled by clang
// and we have a specific builtin
#if defined(__llvm__) && defined(__has_builtin)
- #define _llvm_has_builtin(x) __has_builtin(x)
+#define _llvm_has_builtin(x) __has_builtin(x)
#else
- #define _llvm_has_builtin(x) 0
+#define _llvm_has_builtin(x) 0
#endif
#if (defined(__GNUC__) && (__GNUC__ >= 5)) || _llvm_has_builtin(__builtin_mul_overflow)
-# define _mul_overflow __builtin_mul_overflow
+#define _mul_overflow __builtin_mul_overflow
#endif
#if (defined(__GNUC__) && (__GNUC__ >= 5)) || _llvm_has_builtin(__builtin_add_overflow)
-# define _add_overflow __builtin_add_overflow
+#define _add_overflow __builtin_add_overflow
#endif
-
-
-
/** Function to find the nearest (bigger) power of 2 to an integer */
static _FORCE_INLINE_ unsigned int nearest_power_of_2(unsigned int x) {
@@ -276,14 +274,11 @@ struct _GlobalLock {
};
#define GLOBAL_LOCK_FUNCTION _GlobalLock _global_lock_;
-#ifdef NO_SAFE_CAST
+#ifdef NO_SAFE_CAST
#define SAFE_CAST static_cast
-
#else
-
#define SAFE_CAST dynamic_cast
-
#endif
#define MT_SAFE
@@ -291,7 +286,4 @@ struct _GlobalLock {
#define __STRX(m_index) #m_index
#define __STR(m_index) __STRX(m_index)
-
-
#endif /* typedefs.h */
-
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index acb262d400..f91f1aa14b 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "undo_redo.h"
+
#include "os/os.h"
void UndoRedo::_discard_redo() {
@@ -484,11 +485,11 @@ Variant UndoRedo::_add_undo_method(const Variant** p_args, int p_argcount, Varia
void UndoRedo::_bind_methods() {
- ClassDB::bind_method(_MD("create_action","name","merge_mode"),&UndoRedo::create_action, DEFVAL(MERGE_DISABLE) );
- ClassDB::bind_method(_MD("commit_action"),&UndoRedo::commit_action);
+ ClassDB::bind_method(D_METHOD("create_action","name","merge_mode"),&UndoRedo::create_action, DEFVAL(MERGE_DISABLE) );
+ ClassDB::bind_method(D_METHOD("commit_action"),&UndoRedo::commit_action);
- //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);
+ //ClassDB::bind_method(D_METHOD("add_do_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_do_method);
+ //ClassDB::bind_method(D_METHOD("add_undo_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_undo_method);
{
MethodInfo mi;
@@ -510,13 +511,13 @@ void UndoRedo::_bind_methods() {
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"add_undo_method",&UndoRedo::_add_undo_method,mi);
}
- 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);
+ ClassDB::bind_method(D_METHOD("add_do_property","object", "property", "value:Variant"),&UndoRedo::add_do_property);
+ ClassDB::bind_method(D_METHOD("add_undo_property","object", "property", "value:Variant"),&UndoRedo::add_undo_property);
+ ClassDB::bind_method(D_METHOD("add_do_reference","object"),&UndoRedo::add_do_reference);
+ ClassDB::bind_method(D_METHOD("add_undo_reference","object"),&UndoRedo::add_undo_reference);
+ ClassDB::bind_method(D_METHOD("clear_history"),&UndoRedo::clear_history);
+ ClassDB::bind_method(D_METHOD("get_current_action_name"),&UndoRedo::get_current_action_name);
+ ClassDB::bind_method(D_METHOD("get_version"),&UndoRedo::get_version);
BIND_CONSTANT(MERGE_DISABLE);
BIND_CONSTANT(MERGE_ENDS);
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 27bb8eac72..7d88989d04 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -26,8 +26,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include <wchar.h>
#include "ustring.h"
+
#include "os/memory.h"
#include "print_string.h"
#include "math_funcs.h"
@@ -36,10 +36,8 @@
#include "ucaps.h"
#include "color.h"
#include "variant.h"
-#define MAX_DIGITS 6
-#define UPPERCASE(m_c) (((m_c)>='a' && (m_c)<='z')?((m_c)-('a'-'A')):(m_c))
-#define LOWERCASE(m_c) (((m_c)>='A' && (m_c)<='Z')?((m_c)+('a'-'A')):(m_c))
+#include <wchar.h>
#ifndef NO_USE_STDLIB
#include <stdlib.h>
@@ -50,8 +48,44 @@
#define snprintf _snprintf
#endif
+#define MAX_DIGITS 6
+#define UPPERCASE(m_c) (((m_c)>='a' && (m_c)<='z')?((m_c)-('a'-'A')):(m_c))
+#define LOWERCASE(m_c) (((m_c)>='A' && (m_c)<='Z')?((m_c)+('a'-'A')):(m_c))
+
+
+
+
/** STRING **/
+bool CharString::operator<(const CharString& p_right) const {
+
+ if (length()==0) {
+ return p_right.length()!=0;
+ }
+
+
+ const char *this_str=get_data();
+ const char *that_str=get_data();
+ while (true) {
+
+ if (*that_str==0 && *this_str==0)
+ return false; //this can't be equal, sadly
+ else if (*this_str==0)
+ return true; //if this is empty, and the other one is not, then we're less.. I think?
+ else if (*that_str==0)
+ return false; //otherwise the other one is smaller..
+ else if (*this_str < *that_str ) //more than
+ return true;
+ else if (*this_str > *that_str ) //less than
+ return false;
+
+ this_str++;
+ that_str++;
+ }
+
+ return false; //should never reach here anyway
+}
+
const char *CharString::get_data() const {
if (size())
@@ -560,7 +594,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 +608,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) {
@@ -1255,7 +1289,7 @@ _FORCE_INLINE static int parse_utf8_char(const char *p_utf8,unsigned int *p_ucs4
unichar=*p_utf8;
else {
- unichar=(0xFF >> (len +1)) & *p_utf8;;
+ unichar=(0xFF >> (len +1)) & *p_utf8;
for (int i=1;i<len;i++) {
@@ -1404,7 +1438,7 @@ bool String::parse_utf8(const char* p_utf8,int p_len) {
unichar=*p_utf8;
else {
- unichar=(0xFF >> (len +1)) & *p_utf8;;
+ unichar=(0xFF >> (len +1)) & *p_utf8;
for (int i=1;i<len;i++) {
@@ -1420,7 +1454,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
@@ -2951,6 +2985,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;
@@ -3336,8 +3442,17 @@ String String::c_escape() const {
escaped=escaped.replace("\t","\\t");
escaped=escaped.replace("\v","\\v");
escaped=escaped.replace("\'","\\'");
- escaped=escaped.replace("\"","\\\"");
escaped=escaped.replace("\?","\\?");
+ escaped=escaped.replace("\"","\\\"");
+
+ return escaped;
+}
+
+String String::c_escape_multiline() const {
+
+ String escaped=*this;
+ escaped=escaped.replace("\\","\\\\");
+ escaped=escaped.replace("\"","\\\"");
return escaped;
}
@@ -3812,7 +3927,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)
@@ -3822,11 +3937,11 @@ 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.size()>0 && p_file.operator [](0)=='/'))
return *this+p_file;
- else
- return *this+"/"+p_file;
+ return *this+"/"+p_file;
}
String String::percent_encode() const {
@@ -3891,7 +4006,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)
@@ -3986,12 +4101,8 @@ String String::sprintf(const Array& values, bool* error) const {
case 'X': base = 16; capitalize = true; break;
}
// Get basic number.
- String str = String::num_int64(value, base, capitalize);
-
- // Sign.
- if (show_sign && value >= 0) {
- str = str.insert(0, "+");
- }
+ String str = String::num_int64(ABS(value), base, capitalize);
+ int number_len = str.length();
// Padding.
String pad_char = pad_with_zeroes ? String("0") : String(" ");
@@ -4001,6 +4112,13 @@ String String::sprintf(const Array& values, bool* error) const {
str = str.lpad(min_chars, pad_char);
}
+ // Sign.
+ if (show_sign && value >= 0) {
+ str = str.insert(pad_with_zeroes?0:str.length()-number_len, "+");
+ } else if (value < 0) {
+ str = str.insert(pad_with_zeroes?0:str.length()-number_len, "-");
+ }
+
formatted += str;
++value_index;
in_format = false;
@@ -4211,4 +4329,3 @@ String RTR(const String& p_text) {
return p_text;
}
-
diff --git a/core/ustring.h b/core/ustring.h
index 9a145143d0..87289f9e16 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -41,6 +41,8 @@
class CharString : public Vector<char> {
public:
+
+ bool operator<(const CharString& p_right) const;
int length() const { return size() ? size()-1 : 0; }
const char *get_data() const;
operator const char*() {return get_data();};
@@ -125,6 +127,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;
@@ -176,8 +179,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;
@@ -217,6 +220,7 @@ public:
String http_escape() const;
String http_unescape() const;
String c_escape() const;
+ String c_escape_multiline() const;
String c_unescape() const;
String json_escape() const;
String word_wrap(int p_chars_per_line) const;
diff --git a/core/variant.cpp b/core/variant.cpp
index 5a670a2786..f45c3fd55d 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -27,6 +27,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "variant.h"
+
+#include "math_funcs.h"
#include "resource.h"
#include "print_string.h"
#include "scene/main/node.h"
@@ -1764,7 +1766,7 @@ Variant::operator Transform() const {
if (type==TRANSFORM2D) {
return *_data._transform2d;
} else if (type==TRANSFORM) {
- const Transform& t = *_data._transform;;
+ const Transform& t = *_data._transform;
Transform2D m;
m.elements[0][0]=t.basis.elements[0][0];
m.elements[0][1]=t.basis.elements[1][0];
@@ -2673,14 +2675,10 @@ uint32_t Variant::hash() const {
case INT: {
return _data._int;
-
} break;
case REAL: {
- MarshallFloat mf;
- mf.f=_data._real;
- return mf.i;
-
+ return hash_djb2_one_float(_data._real);
} break;
case STRING: {
@@ -2920,6 +2918,186 @@ uint32_t Variant::hash() const {
}
+#define hash_compare_scalar(p_lhs, p_rhs)\
+ ((p_lhs) == (p_rhs)) || (Math::is_nan(p_lhs) == Math::is_nan(p_rhs))
+
+#define hash_compare_vector2(p_lhs, p_rhs)\
+ (hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
+ (hash_compare_scalar((p_lhs).y, (p_rhs).y))
+
+#define hash_compare_vector3(p_lhs, p_rhs)\
+ (hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
+ (hash_compare_scalar((p_lhs).y, (p_rhs).y)) && \
+ (hash_compare_scalar((p_lhs).z, (p_rhs).z))
+
+#define hash_compare_quat(p_lhs, p_rhs)\
+ (hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
+ (hash_compare_scalar((p_lhs).y, (p_rhs).y)) && \
+ (hash_compare_scalar((p_lhs).z, (p_rhs).z)) && \
+ (hash_compare_scalar((p_lhs).w, (p_rhs).w))
+
+#define hash_compare_color(p_lhs, p_rhs)\
+ (hash_compare_scalar((p_lhs).r, (p_rhs).r)) && \
+ (hash_compare_scalar((p_lhs).g, (p_rhs).g)) && \
+ (hash_compare_scalar((p_lhs).b, (p_rhs).b)) && \
+ (hash_compare_scalar((p_lhs).a, (p_rhs).a))
+
+#define hash_compare_pool_array(p_lhs, p_rhs, p_type, p_compare_func)\
+ const PoolVector<p_type>& l = *reinterpret_cast<const PoolVector<p_type>*>(p_lhs);\
+ const PoolVector<p_type>& r = *reinterpret_cast<const PoolVector<p_type>*>(p_rhs);\
+ \
+ if(l.size() != r.size()) \
+ return false; \
+ \
+ PoolVector<p_type>::Read lr = l.read(); \
+ PoolVector<p_type>::Read rr = r.read(); \
+ \
+ for(int i = 0; i < l.size(); ++i) { \
+ if(! p_compare_func((lr[i]), (rr[i]))) \
+ return false; \
+ }\
+ \
+ return true
+
+bool Variant::hash_compare(const Variant& p_variant) const {
+ if (type != p_variant.type)
+ return false;
+
+ switch( type ) {
+ case REAL: {
+ return hash_compare_scalar(_data._real, p_variant._data._real);
+ } break;
+
+ case VECTOR2: {
+ const Vector2* l = reinterpret_cast<const Vector2*>(_data._mem);
+ const Vector2* r = reinterpret_cast<const Vector2*>(p_variant._data._mem);
+
+ return hash_compare_vector2(*l, *r);
+ } break;
+
+ case RECT2: {
+ const Rect2* l = reinterpret_cast<const Rect2*>(_data._mem);
+ const Rect2* r = reinterpret_cast<const Rect2*>(p_variant._data._mem);
+
+ return (hash_compare_vector2(l->pos, r->pos)) &&
+ (hash_compare_vector2(l->size, r->size));
+ } break;
+
+ case TRANSFORM2D: {
+ Transform2D* l = _data._transform2d;
+ Transform2D* r = p_variant._data._transform2d;
+
+ for(int i=0;i<3;i++) {
+ if (! (hash_compare_vector2(l->elements[i], r->elements[i])))
+ return false;
+ }
+
+ return true;
+ } break;
+
+ case VECTOR3: {
+ const Vector3* l = reinterpret_cast<const Vector3*>(_data._mem);
+ const Vector3* r = reinterpret_cast<const Vector3*>(p_variant._data._mem);
+
+ return hash_compare_vector3(*l, *r);
+ } break;
+
+ case PLANE: {
+ const Plane* l = reinterpret_cast<const Plane*>(_data._mem);
+ const Plane* r = reinterpret_cast<const Plane*>(p_variant._data._mem);
+
+ return (hash_compare_vector3(l->normal, r->normal)) &&
+ (hash_compare_scalar(l->d, r->d));
+ } break;
+
+ case RECT3: {
+ const Rect3* l = _data._rect3;
+ const Rect3* r = p_variant._data._rect3;
+
+ return (hash_compare_vector3(l->pos, r->pos) &&
+ (hash_compare_vector3(l->size, r->size)));
+
+ } break;
+
+ case QUAT: {
+ const Quat* l = reinterpret_cast<const Quat*>(_data._mem);
+ const Quat* r = reinterpret_cast<const Quat*>(p_variant._data._mem);
+
+ return hash_compare_quat(*l, *r);
+ } break;
+
+ case BASIS: {
+ const Basis* l = _data._basis;
+ const Basis* r = p_variant._data._basis;
+
+ for(int i=0;i<3;i++) {
+ if (! (hash_compare_vector3(l->elements[i], r->elements[i])))
+ return false;
+ }
+
+ return true;
+ } break;
+
+ case TRANSFORM: {
+ const Transform* l = _data._transform;
+ const Transform* r = p_variant._data._transform;
+
+ for(int i=0;i<3;i++) {
+ if (! (hash_compare_vector3(l->basis.elements[i], r->basis.elements[i])))
+ return false;
+ }
+
+ return hash_compare_vector3(l->origin, r->origin);
+ } break;
+
+ case COLOR: {
+ const Color* l = reinterpret_cast<const Color*>(_data._mem);
+ const Color* r = reinterpret_cast<const Color*>(p_variant._data._mem);
+
+ return hash_compare_color(*l, *r);
+ } break;
+
+ case ARRAY: {
+ const Array& l = *(reinterpret_cast<const Array*>(_data._mem));
+ const Array& r = *(reinterpret_cast<const Array*>(p_variant._data._mem));
+
+ if(l.size() != r.size())
+ return false;
+
+ for(int i = 0; i < l.size(); ++i) {
+ if(! l[i].hash_compare(r[i]))
+ return false;
+ }
+
+ return true;
+ } break;
+
+ case POOL_REAL_ARRAY: {
+ hash_compare_pool_array(_data._mem, p_variant._data._mem, real_t, hash_compare_scalar);
+ } break;
+
+ case POOL_VECTOR2_ARRAY: {
+ hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector2, hash_compare_vector2);
+ } break;
+
+ case POOL_VECTOR3_ARRAY: {
+ hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector3, hash_compare_vector3);
+ } break;
+
+ case POOL_COLOR_ARRAY: {
+ hash_compare_pool_array(_data._mem, p_variant._data._mem, Color, hash_compare_color);
+ } break;
+
+ default:
+ bool v;
+ Variant r;
+ evaluate(OP_EQUAL,*this,p_variant,r,v);
+ return r;
+ }
+
+ return false;
+}
+
bool Variant::is_ref() const {
diff --git a/core/variant.h b/core/variant.h
index 9d29fd64c3..f9ceca1ca0 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -33,7 +33,7 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-#include "aabb.h"
+#include "rect3.h"
#include "ustring.h"
#include "vector3.h"
#include "plane.h"
@@ -421,6 +421,7 @@ public:
bool operator<(const Variant& p_variant) const;
uint32_t hash() const;
+ bool hash_compare(const Variant& p_variant) const;
bool booleanize(bool &valid) const;
void static_assign(const Variant& p_variant);
@@ -459,6 +460,10 @@ struct VariantHasher {
static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); }
};
+struct VariantComparator {
+
+ static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); }
+};
Variant::ObjData& Variant::_get_obj() {
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 0c8b40539d..376e646fc2 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -27,6 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "variant.h"
+
#include "object.h"
#include "os/os.h"
#include "core_string_names.h"
@@ -146,7 +147,7 @@ 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) {
@@ -261,6 +262,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);
@@ -272,8 +274,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);
@@ -349,12 +351,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);
@@ -562,6 +564,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM1(PoolStringArray,append);
VCALL_LOCALMEM1(PoolStringArray,append_array);
VCALL_LOCALMEM0(PoolStringArray,invert);
+ VCALL_LOCALMEM1R(PoolStringArray,join);
VCALL_LOCALMEM0R(PoolVector2Array,size);
VCALL_LOCALMEM2(PoolVector2Array,set);
@@ -1051,32 +1054,32 @@ Variant Variant::construct(const Variant::Type p_type, const Variant** p_args, i
// math types
- case VECTOR2: return Vector2(); // 5
+ case VECTOR2: return Vector2(); // 5
case RECT2: return Rect2();
case VECTOR3: return Vector3();
case TRANSFORM2D: return Transform2D();
case PLANE: return Plane();
case QUAT: return Quat();
- case RECT3: return Rect3(); //sorry naming convention fail :( not like it's used often // 10
+ case RECT3: return Rect3(); // 10
case BASIS: return Basis();
case TRANSFORM: return Transform();
// misc types
case COLOR: return Color();
- case IMAGE: return Image();;
- case NODE_PATH: return NodePath();; // 15
- case _RID: return RID();;
+ case IMAGE: return Image();
+ case NODE_PATH: return NodePath(); // 15
+ case _RID: return RID();
case OBJECT: return (Object*)NULL;
- case INPUT_EVENT: return InputEvent();;
- case DICTIONARY: return Dictionary();;
- case ARRAY: return Array();; // 20
- 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();;
+ case INPUT_EVENT: return InputEvent();
+ case DICTIONARY: return Dictionary();
+ case ARRAY: return Array(); // 20
+ 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();
+ case POOL_COLOR_ARRAY: return PoolColorArray();
default: return Variant();
}
@@ -1125,27 +1128,27 @@ 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 RECT3: return (Rect3(*p_args[0])); //sorry naming convention fail :( not like it's used often // 10
+ case RECT3: return (Rect3(*p_args[0])); // 10
case BASIS: return (Basis(p_args[0]->operator Basis()));
case TRANSFORM: return (Transform(p_args[0]->operator Transform()));
// misc types
case COLOR: return p_args[0]->type == Variant::STRING ? Color::html(*p_args[0]) : Color::hex(*p_args[0]);
case IMAGE: return (Image(*p_args[0]));
- case NODE_PATH: return (NodePath(p_args[0]->operator NodePath())); // 15
+ case NODE_PATH: return (NodePath(p_args[0]->operator NodePath())); // 15
case _RID: return (RID(*p_args[0]));
case OBJECT: return ((Object*)(p_args[0]->operator Object *()));
case INPUT_EVENT: return (InputEvent(*p_args[0]));
case DICTIONARY: return p_args[0]->operator Dictionary();
- case ARRAY: return p_args[0]->operator Array();
+ case ARRAY: return p_args[0]->operator Array(); // 20
// arrays
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_VECTOR2_ARRAY: return (PoolVector2Array(*p_args[0])); // 25
+ case POOL_VECTOR3_ARRAY: return (PoolVector3Array(*p_args[0]));
case POOL_COLOR_ARRAY: return (PoolColorArray(*p_args[0]));
default: return Variant();
}
@@ -1360,15 +1363,15 @@ void register_variant_methods() {
_VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX);
#define ADDFUNC0(m_vtype,m_ret,m_class,m_method,m_defarg)\
-_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg);
+_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_scs_create(#m_method),VCALL(m_class,m_method),m_defarg);
#define ADDFUNC1(m_vtype,m_ret,m_class,m_method,m_arg1,m_argname1,m_defarg)\
-_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_SCS(m_argname1)) );
+_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_scs_create(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_scs_create(m_argname1)) );
#define ADDFUNC2(m_vtype,m_ret,m_class,m_method,m_arg1,m_argname1,m_arg2,m_argname2,m_defarg)\
-_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_SCS(m_argname1)),_VariantCall::Arg(Variant::m_arg2,_SCS(m_argname2)));
+_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_scs_create(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_scs_create(m_argname1)),_VariantCall::Arg(Variant::m_arg2,_scs_create(m_argname2)));
#define ADDFUNC3(m_vtype,m_ret,m_class,m_method,m_arg1,m_argname1,m_arg2,m_argname2,m_arg3,m_argname3,m_defarg)\
-_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_SCS(m_argname1)),_VariantCall::Arg(Variant::m_arg2,_SCS(m_argname2)),_VariantCall::Arg(Variant::m_arg3,_SCS(m_argname3)));
+_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_scs_create(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_scs_create(m_argname1)),_VariantCall::Arg(Variant::m_arg2,_scs_create(m_argname2)),_VariantCall::Arg(Variant::m_arg3,_scs_create(m_argname3)));
#define ADDFUNC4(m_vtype,m_ret,m_class,m_method,m_arg1,m_argname1,m_arg2,m_argname2,m_arg3,m_argname3,m_arg4,m_argname4,m_defarg)\
-_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_SCS(m_argname1)),_VariantCall::Arg(Variant::m_arg2,_SCS(m_argname2)),_VariantCall::Arg(Variant::m_arg3,_SCS(m_argname3)),_VariantCall::Arg(Variant::m_arg4,_SCS(m_argname4)));
+_VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_scs_create(#m_method),VCALL(m_class,m_method),m_defarg,_VariantCall::Arg(Variant::m_arg1,_scs_create(m_argname1)),_VariantCall::Arg(Variant::m_arg2,_scs_create(m_argname2)),_VariantCall::Arg(Variant::m_arg3,_scs_create(m_argname3)),_VariantCall::Arg(Variant::m_arg4,_scs_create(m_argname4)));
/* STRING */
@@ -1392,6 +1395,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
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());
@@ -1405,8 +1409,8 @@ _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());
@@ -1457,7 +1461,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC0(VECTOR2,VECTOR2,Vector2,tangent,varray());
ADDFUNC0(VECTOR2,VECTOR2,Vector2,floor,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());
@@ -1634,6 +1638,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
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());
+ ADDFUNC1(POOL_STRING_ARRAY,STRING,PoolStringArray,join,STRING,"string",varray());
ADDFUNC0(POOL_VECTOR2_ARRAY,INT,PoolVector2Array,size,varray());
ADDFUNC2(POOL_VECTOR2_ARRAY,NIL,PoolVector2Array,set,INT,"idx",VECTOR2,"vector2",varray());
diff --git a/core/variant_construct_string.cpp b/core/variant_construct_string.cpp
index 8db756aa79..56aa9891fb 100644
--- a/core/variant_construct_string.cpp
+++ b/core/variant_construct_string.cpp
@@ -169,7 +169,7 @@ Error VariantConstruct::_get_token(const CharType *p_str, int &idx, int p_len, T
case 'r': res=13; break;
case '\"': res='\"'; break;
case '\\': res='\\'; break;
- case '/': res='/'; break; //wtf
+ case '/': res='/'; break;
case 'u': {
//hexnumbarh - oct is deprecated
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 50f0b96715..28e804b5bf 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -27,9 +27,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "variant.h"
+
#include "object.h"
#include "script_language.h"
#include "core_string_names.h"
+
Variant::operator bool() const {
bool b;
@@ -1391,7 +1393,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
v->basis.set_axis(index,p_value);
return;
}
- } if (p_index.get_type()==Variant::STRING) {
+ } else if (p_index.get_type()==Variant::STRING) {
Transform *v=_data._transform;
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
@@ -2148,7 +2150,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
valid=true;
return index==3?v->origin:v->basis.get_axis(index);
}
- } if (p_index.get_type()==Variant::STRING) {
+ } else if (p_index.get_type()==Variant::STRING) {
const Transform *v=_data._transform;
const String *str=reinterpret_cast<const String*>(p_index._data._mem);
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 402c8d41da..a2ecb1516d 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -27,11 +27,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "variant_parser.h"
+
#include "io/resource_loader.h"
#include "os/keyboard.h"
-
CharType VariantParser::StreamFile::get_char() {
return f->get_8();
@@ -430,7 +430,7 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String>& strings,
Token token;
get_token(p_stream,token,line,r_err_str);
if (token.type!=TK_PARENTHESIS_OPEN) {
- r_err_str="Expected '(' in old-style engine.cfg construct";
+ r_err_str="Expected '(' in old-style godot.cfg construct";
return ERR_PARSE_ERROR;
}
@@ -442,7 +442,7 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String>& strings,
CharType c=p_stream->get_char();
if (p_stream->is_eof()) {
- r_err_str="Unexpected EOF while parsing old-style engine.cfg construct";
+ r_err_str="Unexpected EOF while parsing old-style godot.cfg construct";
return ERR_PARSE_ERROR;
}
@@ -1328,7 +1328,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value=arr;
return OK;
- } else if (id=="key") { // compatibility with engine.cfg
+ } else if (id=="key") { // compatibility with godot.cfg
Vector<String> params;
Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
@@ -1364,7 +1364,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value=ie;
return OK;
- } else if (id=="mbutton") { // compatibility with engine.cfg
+ } else if (id=="mbutton") { // compatibility with godot.cfg
Vector<String> params;
Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
@@ -1379,7 +1379,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value=ie;
return OK;
- } else if (id=="jbutton") { // compatibility with engine.cfg
+ } else if (id=="jbutton") { // compatibility with godot.cfg
Vector<String> params;
Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
@@ -1394,7 +1394,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value=ie;
return OK;
- } else if (id=="jaxis") { // compatibility with engine.cfg
+ } else if (id=="jaxis") { // compatibility with godot.cfg
Vector<String> params;
Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
@@ -1412,19 +1412,19 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value= ie;
return OK;
- } else if (id=="img") { // compatibility with engine.cfg
+ } else if (id=="img") { // compatibility with godot.cfg
- Token token;
+ Token token; // FIXME: no need for this declaration? the first argument in line 509 is a Token& token.
get_token(p_stream,token,line,r_err_str);
if (token.type!=TK_PARENTHESIS_OPEN) {
- r_err_str="Expected '(' in old-style engine.cfg construct";
+ r_err_str="Expected '(' in old-style godot.cfg construct";
return ERR_PARSE_ERROR;
}
while(true) {
CharType c = p_stream->get_char();
if (p_stream->is_eof()) {
- r_err_str="Unexpected EOF in old style engine.cfg img()";
+ r_err_str="Unexpected EOF in old style godot.cfg img()";
return ERR_PARSE_ERROR;
}
if (c==')')
@@ -1873,7 +1873,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
String str=p_variant;
- str="\""+str.c_escape()+"\"";
+ str="\""+str.c_escape_multiline()+"\"";
p_store_string_func(p_store_string_ud, str );
} break;
case Variant::VECTOR2: {
@@ -1989,7 +1989,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
PoolVector<uint8_t> data = img.get_data();
int len = data.size();
PoolVector<uint8_t>::Read r = data.read();
- const uint8_t *ptr=r.ptr();;
+ const uint8_t *ptr=r.ptr();
for (int i=0;i<len;i++) {
if (i>0)
@@ -2091,20 +2091,22 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
dict.get_key_list(&keys);
keys.sort();
- p_store_string_func(p_store_string_ud,"{ ");
+ p_store_string_func(p_store_string_ud,"{\n");
for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
- //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,":");
+ p_store_string_func(p_store_string_ud,": ");
write(dict[E->get()],p_store_string_func,p_store_string_ud,p_encode_res_func,p_encode_res_ud);
if (E->next())
- p_store_string_func(p_store_string_ud,", ");
+ p_store_string_func(p_store_string_ud,",\n");
}
- p_store_string_func(p_store_string_ud," }");
+ p_store_string_func(p_store_string_ud,"\n}");
} break;
@@ -2131,7 +2133,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
PoolVector<uint8_t> data = p_variant;
int len = data.size();
PoolVector<uint8_t>::Read r = data.read();
- const uint8_t *ptr=r.ptr();;
+ const uint8_t *ptr=r.ptr();
for (int i=0;i<len;i++) {
if (i>0)
@@ -2150,7 +2152,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
PoolVector<int> data = p_variant;
int len = data.size();
PoolVector<int>::Read r = data.read();
- const int *ptr=r.ptr();;
+ const int *ptr=r.ptr();
for (int i=0;i<len;i++) {
@@ -2170,7 +2172,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
PoolVector<real_t> data = p_variant;
int len = data.size();
PoolVector<real_t>::Read r = data.read();
- const real_t *ptr=r.ptr();;
+ const real_t *ptr=r.ptr();
for (int i=0;i<len;i++) {
@@ -2188,7 +2190,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
PoolVector<String> data = p_variant;
int len = data.size();
PoolVector<String>::Read r = data.read();
- const String *ptr=r.ptr();;
+ const String *ptr=r.ptr();
String s;
//write_string("\n");
@@ -2211,7 +2213,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
PoolVector<Vector2> data = p_variant;
int len = data.size();
PoolVector<Vector2>::Read r = data.read();
- const Vector2 *ptr=r.ptr();;
+ const Vector2 *ptr=r.ptr();
for (int i=0;i<len;i++) {
@@ -2229,7 +2231,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
PoolVector<Vector3> data = p_variant;
int len = data.size();
PoolVector<Vector3>::Read r = data.read();
- const Vector3 *ptr=r.ptr();;
+ const Vector3 *ptr=r.ptr();
for (int i=0;i<len;i++) {
@@ -2248,7 +2250,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
PoolVector<Color> data = p_variant;
int len = data.size();
PoolVector<Color>::Read r = data.read();
- const Color *ptr=r.ptr();;
+ const Color *ptr=r.ptr();
for (int i=0;i<len;i++) {
diff --git a/core/vector.h b/core/vector.h
index 3119657cbb..1cb3fee256 100644
--- a/core/vector.h
+++ b/core/vector.h
@@ -81,7 +81,7 @@ class Vector {
size_t p;
if (_mul_overflow(p_elements, sizeof(T), &o)) return false;
*out = nearest_power_of_2(o);
- if (_add_overflow(o, 32, &p)) return false; //no longer allocated here
+ if (_add_overflow(o, static_cast<size_t>(32), &p)) return false; //no longer allocated here
return true;
#else
// Speed is more important than correctness here, do the operations unchecked