summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub92
-rw-r--r--core/allocators.h3
-rw-r--r--core/array.cpp8
-rw-r--r--core/array.h3
-rw-r--r--core/bind/SCsub2
-rw-r--r--core/bind/core_bind.cpp17
-rw-r--r--core/bind/core_bind.h19
-rw-r--r--core/class_db.cpp10
-rw-r--r--core/class_db.h8
-rw-r--r--core/color.cpp10
-rw-r--r--core/color.h6
-rw-r--r--core/color_names.inc2
-rw-r--r--core/command_queue_mt.cpp2
-rw-r--r--core/command_queue_mt.h10
-rw-r--r--core/compressed_translation.cpp2
-rw-r--r--core/compressed_translation.h2
-rw-r--r--core/core_builders.py35
-rw-r--r--core/core_string_names.h2
-rw-r--r--core/cowdata.h9
-rw-r--r--core/dictionary.cpp11
-rw-r--r--core/dictionary.h8
-rw-r--r--core/dvector.h16
-rw-r--r--core/engine.cpp10
-rw-r--r--core/engine.h9
-rw-r--r--core/error_macros.cpp2
-rw-r--r--core/error_macros.h2
-rw-r--r--core/func_ref.h2
-rw-r--r--core/global_constants.cpp8
-rw-r--r--core/global_constants.h2
-rw-r--r--core/hash_map.h16
-rw-r--r--core/hashfuncs.h12
-rw-r--r--core/helper/SCsub7
-rw-r--r--core/image.cpp56
-rw-r--r--core/image.h8
-rw-r--r--core/input_map.cpp8
-rw-r--r--core/input_map.h4
-rw-r--r--core/io/SCsub3
-rw-r--r--core/io/compression.cpp9
-rw-r--r--core/io/compression.h2
-rw-r--r--core/io/config_file.cpp7
-rw-r--r--core/io/config_file.h2
-rw-r--r--core/io/file_access_buffered.cpp4
-rw-r--r--core/io/file_access_buffered.h7
-rw-r--r--core/io/file_access_compressed.cpp5
-rw-r--r--core/io/file_access_compressed.h4
-rw-r--r--core/io/file_access_encrypted.cpp4
-rw-r--r--core/io/file_access_encrypted.h2
-rw-r--r--core/io/file_access_memory.cpp8
-rw-r--r--core/io/file_access_memory.h2
-rw-r--r--core/io/file_access_network.cpp15
-rw-r--r--core/io/file_access_network.h11
-rw-r--r--core/io/file_access_pack.cpp7
-rw-r--r--core/io/file_access_pack.h10
-rw-r--r--core/io/file_access_zip.h4
-rw-r--r--core/io/http_client.cpp56
-rw-r--r--core/io/http_client.h8
-rw-r--r--core/io/image_loader.cpp4
-rw-r--r--core/io/image_loader.h10
-rw-r--r--core/io/ip.cpp7
-rw-r--r--core/io/ip.h4
-rw-r--r--core/io/ip_address.h2
-rw-r--r--core/io/json.cpp3
-rw-r--r--core/io/json.h2
-rw-r--r--core/io/logger.cpp10
-rw-r--r--core/io/logger.h9
-rw-r--r--core/io/marshalls.cpp22
-rw-r--r--core/io/marshalls.h6
-rw-r--r--core/io/multiplayer_api.cpp191
-rw-r--r--core/io/multiplayer_api.h9
-rw-r--r--core/io/net_socket.cpp (renamed from core/helper/value_evaluator.h)22
-rw-r--r--core/io/net_socket.h79
-rw-r--r--core/io/networked_multiplayer_peer.h2
-rw-r--r--core/io/packet_peer.cpp5
-rw-r--r--core/io/packet_peer.h7
-rw-r--r--core/io/packet_peer_udp.cpp197
-rw-r--r--core/io/packet_peer_udp.h42
-rw-r--r--core/io/pck_packer.cpp3
-rw-r--r--core/io/resource_format_binary.cpp4
-rw-r--r--core/io/resource_format_binary.h7
-rw-r--r--core/io/resource_import.cpp4
-rw-r--r--core/io/resource_import.h3
-rw-r--r--core/io/resource_loader.cpp30
-rw-r--r--core/io/resource_loader.h10
-rw-r--r--core/io/resource_saver.cpp11
-rw-r--r--core/io/resource_saver.h4
-rw-r--r--core/io/stream_peer.cpp18
-rw-r--r--core/io/stream_peer.h7
-rw-r--r--core/io/stream_peer_ssl.cpp63
-rw-r--r--core/io/stream_peer_ssl.h7
-rw-r--r--core/io/stream_peer_tcp.cpp311
-rw-r--r--core/io/stream_peer_tcp.h45
-rw-r--r--core/io/tcp_server.cpp97
-rw-r--r--core/io/tcp_server.h25
-rw-r--r--core/io/translation_loader_po.cpp5
-rw-r--r--core/io/translation_loader_po.h7
-rw-r--r--core/io/xml_parser.cpp4
-rw-r--r--core/io/xml_parser.h8
-rw-r--r--core/io/zip_io.cpp137
-rw-r--r--core/io/zip_io.h114
-rw-r--r--core/list.h4
-rw-r--r--core/map.h2
-rw-r--r--core/math/SCsub2
-rw-r--r--core/math/a_star.cpp27
-rw-r--r--core/math/a_star.h5
-rw-r--r--core/math/aabb.cpp2
-rw-r--r--core/math/aabb.h6
-rw-r--r--core/math/audio_frame.h2
-rw-r--r--core/math/bsp_tree.cpp10
-rw-r--r--core/math/bsp_tree.h14
-rw-r--r--core/math/camera_matrix.cpp5
-rw-r--r--core/math/camera_matrix.h5
-rw-r--r--core/math/delaunay.h2
-rw-r--r--core/math/expression.cpp53
-rw-r--r--core/math/face3.cpp12
-rw-r--r--core/math/face3.h8
-rw-r--r--core/math/geometry.cpp3
-rw-r--r--core/math/geometry.h17
-rw-r--r--core/math/math_fieldwise.cpp (renamed from core/helper/math_fieldwise.cpp)2
-rw-r--r--core/math/math_fieldwise.h (renamed from core/helper/math_fieldwise.h)0
-rw-r--r--core/math/math_funcs.cpp12
-rw-r--r--core/math/math_funcs.h6
-rw-r--r--core/math/matrix3.cpp28
-rw-r--r--core/math/matrix3.h6
-rw-r--r--core/math/octree.h14
-rw-r--r--core/math/plane.cpp2
-rw-r--r--core/math/plane.h2
-rw-r--r--core/math/quat.cpp23
-rw-r--r--core/math/quat.h12
-rw-r--r--core/math/quick_hull.cpp3
-rw-r--r--core/math/quick_hull.h8
-rw-r--r--core/math/rect2.cpp2
-rw-r--r--core/math/rect2.h2
-rw-r--r--core/math/transform.cpp7
-rw-r--r--core/math/transform.h8
-rw-r--r--core/math/transform_2d.h2
-rw-r--r--core/math/triangle_mesh.cpp3
-rw-r--r--core/math/triangle_mesh.h5
-rw-r--r--core/math/triangulate.cpp2
-rw-r--r--core/math/triangulate.h2
-rw-r--r--core/math/vector2.cpp4
-rw-r--r--core/math/vector2.h6
-rw-r--r--core/math/vector3.cpp3
-rw-r--r--core/math/vector3.h25
-rw-r--r--core/message_queue.cpp5
-rw-r--r--core/message_queue.h7
-rw-r--r--core/method_bind.cpp2
-rw-r--r--core/method_bind.h11
-rw-r--r--core/method_ptrcall.h6
-rw-r--r--core/node_path.cpp4
-rw-r--r--core/node_path.h5
-rw-r--r--core/oa_hash_map.h16
-rw-r--r--core/object.cpp58
-rw-r--r--core/object.h42
-rw-r--r--core/ordered_hash_map.h6
-rw-r--r--core/os/SCsub2
-rw-r--r--core/os/copymem.h2
-rw-r--r--core/os/dir_access.cpp10
-rw-r--r--core/os/dir_access.h6
-rw-r--r--core/os/file_access.cpp6
-rw-r--r--core/os/file_access.h9
-rw-r--r--core/os/input.cpp10
-rw-r--r--core/os/input.h6
-rw-r--r--core/os/input_event.cpp20
-rw-r--r--core/os/input_event.h13
-rw-r--r--core/os/keyboard.cpp3
-rw-r--r--core/os/keyboard.h7
-rw-r--r--core/os/main_loop.cpp3
-rw-r--r--core/os/main_loop.h8
-rw-r--r--core/os/memory.cpp8
-rw-r--r--core/os/memory.h3
-rw-r--r--core/os/midi_driver.cpp2
-rw-r--r--core/os/midi_driver.h3
-rw-r--r--core/os/mutex.cpp4
-rw-r--r--core/os/mutex.h2
-rw-r--r--core/os/os.cpp12
-rw-r--r--core/os/os.h17
-rw-r--r--core/os/rw_lock.cpp2
-rw-r--r--core/os/rw_lock.h6
-rw-r--r--core/os/semaphore.cpp3
-rw-r--r--core/os/semaphore.h3
-rw-r--r--core/os/shell.h4
-rw-r--r--core/os/thread.h6
-rw-r--r--core/os/thread_dummy.cpp2
-rw-r--r--core/os/thread_dummy.h8
-rw-r--r--core/os/thread_safe.cpp5
-rw-r--r--core/os/thread_safe.h2
-rw-r--r--core/os/threaded_array_processor.h10
-rw-r--r--core/packed_data_container.cpp4
-rw-r--r--core/packed_data_container.h2
-rw-r--r--core/pool_allocator.cpp8
-rw-r--r--core/pool_allocator.h2
-rw-r--r--core/print_string.cpp2
-rw-r--r--core/print_string.h2
-rw-r--r--core/project_settings.cpp109
-rw-r--r--core/project_settings.h7
-rw-r--r--core/ref_ptr.cpp4
-rw-r--r--core/ref_ptr.h2
-rw-r--r--core/reference.cpp2
-rw-r--r--core/reference.h8
-rw-r--r--core/register_core_types.cpp74
-rw-r--r--core/resource.cpp9
-rw-r--r--core/resource.h12
-rw-r--r--core/rid.h11
-rw-r--r--core/ring_buffer.h2
-rw-r--r--core/safe_refcount.h6
-rw-r--r--core/script_debugger_local.cpp4
-rw-r--r--core/script_debugger_local.h4
-rw-r--r--core/script_debugger_remote.cpp87
-rw-r--r--core/script_debugger_remote.h10
-rw-r--r--core/script_language.cpp3
-rw-r--r--core/script_language.h9
-rw-r--r--core/self_list.h2
-rw-r--r--core/set.h5
-rw-r--r--core/sort.h5
-rw-r--r--core/string_buffer.h3
-rw-r--r--core/string_db.cpp4
-rw-r--r--core/string_db.h6
-rw-r--r--core/translation.cpp17
-rw-r--r--core/translation.h2
-rw-r--r--core/typedefs.h19
-rw-r--r--core/undo_redo.cpp2
-rw-r--r--core/undo_redo.h4
-rw-r--r--core/ustring.cpp52
-rw-r--r--core/ustring.h16
-rw-r--r--core/variant.cpp14
-rw-r--r--core/variant.h36
-rw-r--r--core/variant_call.cpp12
-rw-r--r--core/variant_op.cpp26
-rw-r--r--core/variant_parser.cpp10
-rw-r--r--core/variant_parser.h6
-rw-r--r--core/vector.h9
-rw-r--r--core/version.h2
-rw-r--r--core/vmap.h4
-rw-r--r--core/vset.h4
234 files changed, 2262 insertions, 1268 deletions
diff --git a/core/SCsub b/core/SCsub
index c8e2e10b9f..c6d0b7e5b1 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -8,7 +8,6 @@ from platform_methods import run_in_subprocess
env.core_sources = []
-
# Generate global defaults
gd_call = ""
gd_inc = ""
@@ -18,7 +17,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 "project_settings.h"\n'
+gd_cpp = '#include "core/project_settings.h"\n'
gd_cpp += gd_inc
gd_cpp += "void ProjectSettings::register_global_defaults() {\n" + gd_call + "\n}\n"
@@ -52,13 +51,17 @@ if ("SCRIPT_AES256_ENCRYPTION_KEY" in os.environ):
# NOTE: It is safe to generate this file here, since this is still executed serially
with open("script_encryption_key.gen.cpp", "w") as f:
- f.write("#include \"project_settings.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
+ f.write("#include \"core/project_settings.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
+
+# Add required thirdparty code.
+env_thirdparty = env.Clone()
+env_thirdparty.disable_warnings()
-# Add required thirdparty code. Header paths are hardcoded, we don't need to append
+# Misc thirdparty code: header paths are hardcoded, we don't need to append
# to the include path (saves a few chars on the compiler invocation for touchy MSVC...)
-thirdparty_dir = "#thirdparty/misc/"
-thirdparty_sources = [
+thirdparty_misc_dir = "#thirdparty/misc/"
+thirdparty_misc_sources = [
# C sources
"base64.c",
"fastlz.c",
@@ -72,10 +75,34 @@ thirdparty_sources = [
"pcg.cpp",
"triangulator.cpp",
]
-thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
-env.add_source_files(env.core_sources, thirdparty_sources)
-
-# Minizip library, can be unbundled in theory
+thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources]
+env_thirdparty.add_source_files(env.core_sources, thirdparty_misc_sources)
+
+# Zlib library, can be unbundled
+if env['builtin_zlib']:
+ thirdparty_zlib_dir = "#thirdparty/zlib/"
+ thirdparty_zlib_sources = [
+ "adler32.c",
+ "compress.c",
+ "crc32.c",
+ "deflate.c",
+ "infback.c",
+ "inffast.c",
+ "inflate.c",
+ "inftrees.c",
+ "trees.c",
+ "uncompr.c",
+ "zutil.c",
+ ]
+ thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
+
+ env_thirdparty.Append(CPPPATH=[thirdparty_zlib_dir])
+ # Needs to be available in main env too
+ env.Append(CPPPATH=[thirdparty_zlib_dir])
+
+ env_thirdparty.add_source_files(env.core_sources, thirdparty_zlib_sources)
+
+# Minizip library, could be unbundled in theory
# However, our version has some custom modifications, so it won't compile with the system one
thirdparty_minizip_dir = "#thirdparty/minizip/"
thirdparty_minizip_sources = [
@@ -84,15 +111,50 @@ thirdparty_minizip_sources = [
"zip.c",
]
thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
-env.add_source_files(env.core_sources, thirdparty_minizip_sources)
-
-if 'builtin_zstd' in env and env['builtin_zstd']:
- SConscript("#thirdparty/zstd/SCsub")
+env_thirdparty.add_source_files(env.core_sources, thirdparty_minizip_sources)
+
+# Zstd library, can be unbundled in theory
+# though we currently use some private symbols
+# https://github.com/godotengine/godot/issues/17374
+if env['builtin_zstd']:
+ thirdparty_zstd_dir = "#thirdparty/zstd/"
+ thirdparty_zstd_sources = [
+ "common/entropy_common.c",
+ "common/error_private.c",
+ "common/fse_decompress.c",
+ "common/pool.c",
+ "common/threading.c",
+ "common/xxhash.c",
+ "common/zstd_common.c",
+ "compress/fse_compress.c",
+ "compress/huf_compress.c",
+ "compress/zstd_compress.c",
+ "compress/zstd_double_fast.c",
+ "compress/zstd_fast.c",
+ "compress/zstd_lazy.c",
+ "compress/zstd_ldm.c",
+ "compress/zstdmt_compress.c",
+ "compress/zstd_opt.c",
+ "decompress/huf_decompress.c",
+ "decompress/zstd_decompress.c",
+ ]
+ thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
+
+ env_thirdparty.Append(CPPPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"])
+ env_thirdparty.Append(CCFLAGS="-DZSTD_STATIC_LINKING_ONLY")
+ env.Append(CPPPATH=thirdparty_zstd_dir)
+ # Also needed in main env includes will trigger warnings
+ env.Append(CCFLAGS="-DZSTD_STATIC_LINKING_ONLY")
+
+ env_thirdparty.add_source_files(env.core_sources, thirdparty_zstd_sources)
# Godot's own sources
env.add_source_files(env.core_sources, "*.cpp")
+# Certificates
+env.Depends("#core/io/certs_compressed.gen.h", ["#thirdparty/certs/ca-certificates.crt", env.Value(env['builtin_certs']), env.Value(env['system_certs_path'])])
+env.CommandNoCache("#core/io/certs_compressed.gen.h", "#thirdparty/certs/ca-certificates.crt", run_in_subprocess(core_builders.make_certs_header))
# Make binders
env.CommandNoCache(['method_bind.gen.inc', 'method_bind_ext.gen.inc'], 'make_binders.py', run_in_subprocess(make_binders.run))
@@ -114,10 +176,8 @@ SConscript('os/SCsub')
SConscript('math/SCsub')
SConscript('io/SCsub')
SConscript('bind/SCsub')
-SConscript('helper/SCsub')
# Build it all as a library
lib = env.add_library("core", env.core_sources)
env.Prepend(LIBS=[lib])
-Export('env')
diff --git a/core/allocators.h b/core/allocators.h
index e17ab298d6..840b117958 100644
--- a/core/allocators.h
+++ b/core/allocators.h
@@ -31,7 +31,8 @@
#ifndef ALLOCATORS_H
#define ALLOCATORS_H
-#include "os/memory.h"
+#include "core/os/memory.h"
+
template <int PREALLOC_COUNT = 64, int MAX_HANDS = 8>
class BalloonAllocator {
diff --git a/core/array.cpp b/core/array.cpp
index ebad0df126..9708452850 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -30,10 +30,10 @@
#include "array.h"
-#include "hashfuncs.h"
-#include "object.h"
-#include "variant.h"
-#include "vector.h"
+#include "core/hashfuncs.h"
+#include "core/object.h"
+#include "core/variant.h"
+#include "core/vector.h"
class ArrayPrivate {
public:
diff --git a/core/array.h b/core/array.h
index c824c9b4f7..fa5113a376 100644
--- a/core/array.h
+++ b/core/array.h
@@ -31,7 +31,8 @@
#ifndef ARRAY_H
#define ARRAY_H
-#include "typedefs.h"
+#include "core/typedefs.h"
+
class Variant;
class ArrayPrivate;
class Object;
diff --git a/core/bind/SCsub b/core/bind/SCsub
index 4efc902717..1c5f954470 100644
--- a/core/bind/SCsub
+++ b/core/bind/SCsub
@@ -3,5 +3,3 @@
Import('env')
env.add_source_files(env.core_sources, "*.cpp")
-
-Export('env')
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 2bd271205a..a3ff4bf13e 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -30,14 +30,14 @@
#include "core_bind.h"
+#include "core/io/file_access_compressed.h"
+#include "core/io/file_access_encrypted.h"
+#include "core/io/json.h"
+#include "core/io/marshalls.h"
+#include "core/math/geometry.h"
+#include "core/os/keyboard.h"
+#include "core/os/os.h"
#include "core/project_settings.h"
-#include "geometry.h"
-#include "io/file_access_compressed.h"
-#include "io/file_access_encrypted.h"
-#include "io/json.h"
-#include "io/marshalls.h"
-#include "os/keyboard.h"
-#include "os/os.h"
#include "thirdparty/misc/base64.h"
@@ -180,6 +180,7 @@ void _ResourceSaver::_bind_methods() {
BIND_ENUM_CONSTANT(FLAG_OMIT_EDITOR_PROPERTIES);
BIND_ENUM_CONSTANT(FLAG_SAVE_BIG_ENDIAN);
BIND_ENUM_CONSTANT(FLAG_COMPRESS);
+ BIND_ENUM_CONSTANT(FLAG_REPLACE_SUBRESOURCE_PATHS);
}
_ResourceSaver::_ResourceSaver() {
@@ -2487,7 +2488,7 @@ _Thread::~_Thread() {
if (active) {
ERR_EXPLAIN("Reference to a Thread object object was lost while the thread is still running...");
}
- ERR_FAIL_COND(active == true);
+ ERR_FAIL_COND(active);
}
/////////////////////////////////////
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 21aea12b23..79403879ac 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -31,15 +31,15 @@
#ifndef CORE_BIND_H
#define CORE_BIND_H
-#include "image.h"
-#include "io/compression.h"
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
-#include "os/dir_access.h"
-#include "os/file_access.h"
-#include "os/os.h"
-#include "os/semaphore.h"
-#include "os/thread.h"
+#include "core/image.h"
+#include "core/io/compression.h"
+#include "core/io/resource_loader.h"
+#include "core/io/resource_saver.h"
+#include "core/os/dir_access.h"
+#include "core/os/file_access.h"
+#include "core/os/os.h"
+#include "core/os/semaphore.h"
+#include "core/os/thread.h"
class _ResourceLoader : public Object {
GDCLASS(_ResourceLoader, Object);
@@ -80,6 +80,7 @@ public:
FLAG_OMIT_EDITOR_PROPERTIES = 8,
FLAG_SAVE_BIG_ENDIAN = 16,
FLAG_COMPRESS = 32,
+ FLAG_REPLACE_SUBRESOURCE_PATHS = 64,
};
static _ResourceSaver *get_singleton() { return singleton; }
diff --git a/core/class_db.cpp b/core/class_db.cpp
index eceefa1ee4..71809d5454 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -30,9 +30,9 @@
#include "class_db.h"
-#include "engine.h"
-#include "os/mutex.h"
-#include "version.h"
+#include "core/engine.h"
+#include "core/os/mutex.h"
+#include "core/version.h"
#define OBJTYPE_RLOCK RWLockRead _rw_lockr_(lock);
#define OBJTYPE_WLOCK RWLockWrite _rw_lockw_(lock);
@@ -809,10 +809,10 @@ void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_COND(!type);
- ClassInfo *check = type;
StringName sname = p_signal.name;
-#ifdef DEBUG_METHODS_ENABLED
+#ifdef DEBUG_METHODS_ENABLED
+ ClassInfo *check = type;
while (check) {
if (check->signal_map.has(sname)) {
ERR_EXPLAIN("Type " + String(p_class) + " already has signal: " + String(sname));
diff --git a/core/class_db.h b/core/class_db.h
index 66a67f6c9f..11cc3033cf 100644
--- a/core/class_db.h
+++ b/core/class_db.h
@@ -31,16 +31,16 @@
#ifndef CLASS_DB_H
#define CLASS_DB_H
-#include "method_bind.h"
-#include "object.h"
-#include "print_string.h"
+#include "core/method_bind.h"
+#include "core/object.h"
+#include "core/print_string.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
/** To bind more then 6 parameters include this:
- * #include "method_bind_ext.gen.inc"
+ * #include "core/method_bind_ext.gen.inc"
*/
#define DEFVAL(m_defval) (m_defval)
diff --git a/core/color.cpp b/core/color.cpp
index 17c9e2daeb..ac314417ec 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -30,10 +30,10 @@
#include "color.h"
-#include "color_names.inc"
-#include "map.h"
-#include "math_funcs.h"
-#include "print_string.h"
+#include "core/color_names.inc"
+#include "core/map.h"
+#include "core/math/math_funcs.h"
+#include "core/print_string.h"
uint32_t Color::to_argb32() const {
@@ -468,7 +468,7 @@ String Color::to_html(bool p_alpha) const {
return txt;
}
-Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) {
+Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
p_h = Math::fmod(p_h * 360.0f, 360.0f);
if (p_h < 0.0)
diff --git a/core/color.h b/core/color.h
index 00f4c9e9e8..d6ad5f91c5 100644
--- a/core/color.h
+++ b/core/color.h
@@ -31,8 +31,8 @@
#ifndef COLOR_H
#define COLOR_H
-#include "math_funcs.h"
-#include "ustring.h"
+#include "core/math/math_funcs.h"
+#include "core/ustring.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -194,7 +194,7 @@ struct Color {
static bool html_is_valid(const String &p_color);
static Color named(const String &p_name);
String to_html(bool p_alpha = true) const;
- Color from_hsv(float p_h, float p_s, float p_v, float p_a);
+ Color from_hsv(float p_h, float p_s, float p_v, float p_a) const;
static Color from_rgbe9995(uint32_t p_color);
_FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys
diff --git a/core/color_names.inc b/core/color_names.inc
index 3ae42648d0..e126bfe0f8 100644
--- a/core/color_names.inc
+++ b/core/color_names.inc
@@ -1,5 +1,5 @@
// 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"
+#include "core/map.h"
static Map<String, Color> _named_colors;
static void _populate_named_colors() {
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index a39c920dfa..1b3a74bd0d 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -30,7 +30,7 @@
#include "command_queue_mt.h"
-#include "os/os.h"
+#include "core/os/os.h"
void CommandQueueMT::lock() {
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index 7978eaa7bf..5911cf5006 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -31,11 +31,11 @@
#ifndef COMMAND_QUEUE_MT_H
#define COMMAND_QUEUE_MT_H
-#include "os/memory.h"
-#include "os/mutex.h"
-#include "os/semaphore.h"
-#include "simple_type.h"
-#include "typedefs.h"
+#include "core/os/memory.h"
+#include "core/os/mutex.h"
+#include "core/os/semaphore.h"
+#include "core/simple_type.h"
+#include "core/typedefs.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp
index 46df63066b..7dd5308fab 100644
--- a/core/compressed_translation.cpp
+++ b/core/compressed_translation.cpp
@@ -30,7 +30,7 @@
#include "compressed_translation.h"
-#include "pair.h"
+#include "core/pair.h"
extern "C" {
#include "thirdparty/misc/smaz.h"
diff --git a/core/compressed_translation.h b/core/compressed_translation.h
index ccc47d0bf6..b3d193b478 100644
--- a/core/compressed_translation.h
+++ b/core/compressed_translation.h
@@ -31,7 +31,7 @@
#ifndef COMPRESSED_TRANSLATION_H
#define COMPRESSED_TRANSLATION_H
-#include "translation.h"
+#include "core/translation.h"
class PHashTranslation : public Translation {
diff --git a/core/core_builders.py b/core/core_builders.py
index 90e505aab9..f3a9e3b221 100644
--- a/core/core_builders.py
+++ b/core/core_builders.py
@@ -4,7 +4,40 @@ All such functions are invoked in a subprocess on Windows to prevent build flaki
"""
from platform_methods import subprocess_main
-from compat import iteritems, itervalues, open_utf8, escape_string
+from compat import iteritems, itervalues, open_utf8, escape_string, byte_to_str
+
+
+def make_certs_header(target, source, env):
+
+ src = source[0]
+ dst = target[0]
+ f = open(src, "rb")
+ g = open_utf8(dst, "w")
+ buf = f.read()
+ decomp_size = len(buf)
+ import zlib
+ buf = zlib.compress(buf)
+
+ g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
+ g.write("#ifndef _CERTS_RAW_H\n")
+ g.write("#define _CERTS_RAW_H\n")
+
+ # System certs path. Editor will use them if defined. (for package maintainers)
+ path = env['system_certs_path']
+ g.write("#define _SYSTEM_CERTS_PATH \"%s\"\n" % str(path))
+ if env['builtin_certs']:
+ # Defined here and not in env so changing it does not trigger a full rebuild.
+ g.write("#define BUILTIN_CERTS_ENABLED\n")
+ g.write("static const int _certs_compressed_size = " + str(len(buf)) + ";\n")
+ g.write("static const int _certs_uncompressed_size = " + str(decomp_size) + ";\n")
+ g.write("static const unsigned char _certs_compressed[] = {\n")
+ for i in range(len(buf)):
+ g.write("\t" + byte_to_str(buf[i]) + ",\n")
+ g.write("};\n")
+ g.write("#endif")
+
+ g.close()
+ f.close()
def make_authors_header(target, source, env):
diff --git a/core/core_string_names.h b/core/core_string_names.h
index dcbce14aac..3fdb240408 100644
--- a/core/core_string_names.h
+++ b/core/core_string_names.h
@@ -31,7 +31,7 @@
#ifndef CORE_STRING_NAMES_H
#define CORE_STRING_NAMES_H
-#include "string_db.h"
+#include "core/string_db.h"
class CoreStringNames {
diff --git a/core/cowdata.h b/core/cowdata.h
index 6a8f644d53..54ece4c856 100644
--- a/core/cowdata.h
+++ b/core/cowdata.h
@@ -31,8 +31,8 @@
#ifndef COWDATA_H_
#define COWDATA_H_
-#include "os/memory.h"
-#include "safe_refcount.h"
+#include "core/os/memory.h"
+#include "core/safe_refcount.h"
template <class T>
class Vector;
@@ -87,7 +87,10 @@ private:
#if defined(_add_overflow) && defined(_mul_overflow)
size_t o;
size_t p;
- if (_mul_overflow(p_elements, sizeof(T), &o)) return false;
+ if (_mul_overflow(p_elements, sizeof(T), &o)) {
+ *out = 0;
+ return false;
+ }
*out = next_power_of_2(o);
if (_add_overflow(o, static_cast<size_t>(32), &p)) return false; //no longer allocated here
return true;
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index 9cc913fa0d..ccbdff3816 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -30,9 +30,9 @@
#include "dictionary.h"
-#include "ordered_hash_map.h"
-#include "safe_refcount.h"
-#include "variant.h"
+#include "core/ordered_hash_map.h"
+#include "core/safe_refcount.h"
+#include "core/variant.h"
struct DictionaryPrivate {
@@ -145,6 +145,11 @@ bool Dictionary::operator==(const Dictionary &p_dictionary) const {
return _p == p_dictionary._p;
}
+bool Dictionary::operator!=(const Dictionary &p_dictionary) const {
+
+ return _p != p_dictionary._p;
+}
+
void Dictionary::_ref(const Dictionary &p_from) const {
//make a copy first (thread safe)
diff --git a/core/dictionary.h b/core/dictionary.h
index dbf2233819..d3b98c2f63 100644
--- a/core/dictionary.h
+++ b/core/dictionary.h
@@ -31,9 +31,10 @@
#ifndef DICTIONARY_H
#define DICTIONARY_H
-#include "array.h"
-#include "list.h"
-#include "ustring.h"
+#include "core/array.h"
+#include "core/list.h"
+#include "core/ustring.h"
+
class Variant;
struct DictionaryPrivate;
@@ -68,6 +69,7 @@ public:
bool erase(const Variant &p_key);
bool operator==(const Dictionary &p_dictionary) const;
+ bool operator!=(const Dictionary &p_dictionary) const;
uint32_t hash() const;
void operator=(const Dictionary &p_dictionary);
diff --git a/core/dvector.h b/core/dvector.h
index e03a755e6c..2830c57ec0 100644
--- a/core/dvector.h
+++ b/core/dvector.h
@@ -31,12 +31,12 @@
#ifndef DVECTOR_H
#define DVECTOR_H
-#include "os/copymem.h"
-#include "os/memory.h"
-#include "os/rw_lock.h"
-#include "pool_allocator.h"
-#include "safe_refcount.h"
-#include "ustring.h"
+#include "core/os/copymem.h"
+#include "core/os/memory.h"
+#include "core/os/rw_lock.h"
+#include "core/pool_allocator.h"
+#include "core/safe_refcount.h"
+#include "core/ustring.h"
struct MemoryPool {
@@ -149,7 +149,7 @@ class PoolVector {
}
}
- if (old_alloc->refcount.unref() == true) {
+ if (old_alloc->refcount.unref()) {
//this should never happen but..
#ifdef DEBUG_ENABLED
@@ -209,7 +209,7 @@ class PoolVector {
if (!alloc)
return;
- if (alloc->refcount.unref() == false) {
+ if (!alloc->refcount.unref()) {
alloc = NULL;
return;
}
diff --git a/core/engine.cpp b/core/engine.cpp
index 7c8024b946..fceb602dcf 100644
--- a/core/engine.cpp
+++ b/core/engine.cpp
@@ -30,11 +30,11 @@
#include "engine.h"
-#include "authors.gen.h"
-#include "donors.gen.h"
-#include "license.gen.h"
-#include "version.h"
-#include "version_hash.gen.h"
+#include "core/authors.gen.h"
+#include "core/donors.gen.h"
+#include "core/license.gen.h"
+#include "core/version.h"
+#include "core/version_hash.gen.h"
void Engine::set_iterations_per_second(int p_ips) {
diff --git a/core/engine.h b/core/engine.h
index 031ba29cd6..82b1e5d681 100644
--- a/core/engine.h
+++ b/core/engine.h
@@ -31,10 +31,10 @@
#ifndef ENGINE_H
#define ENGINE_H
-#include "list.h"
-#include "os/main_loop.h"
-#include "ustring.h"
-#include "vector.h"
+#include "core/list.h"
+#include "core/os/main_loop.h"
+#include "core/ustring.h"
+#include "core/vector.h"
class Engine {
@@ -125,6 +125,7 @@ public:
String get_license_text() const;
Engine();
+ virtual ~Engine() {}
};
#endif // ENGINE_H
diff --git a/core/error_macros.cpp b/core/error_macros.cpp
index 5786802930..c1a0dd0dfc 100644
--- a/core/error_macros.cpp
+++ b/core/error_macros.cpp
@@ -30,7 +30,7 @@
#include "error_macros.h"
-#include "io/logger.h"
+#include "core/io/logger.h"
#include "os/os.h"
bool _err_error_exists = false;
diff --git a/core/error_macros.h b/core/error_macros.h
index bee738ceea..8cec18d24f 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -31,7 +31,7 @@
#ifndef ERROR_MACROS_H
#define ERROR_MACROS_H
-#include "typedefs.h"
+#include "core/typedefs.h"
/**
* Error macros. Unlike exceptions and asserts, these macros try to maintain consistency and stability
* inside the code. It is recommended to always return processable data, so in case of an error, the
diff --git a/core/func_ref.h b/core/func_ref.h
index 681fe747d6..930c376abf 100644
--- a/core/func_ref.h
+++ b/core/func_ref.h
@@ -31,7 +31,7 @@
#ifndef FUNC_REF_H
#define FUNC_REF_H
-#include "reference.h"
+#include "core/reference.h"
class FuncRef : public Reference {
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index 962881e720..c70f960a66 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -30,10 +30,10 @@
#include "global_constants.h"
-#include "object.h"
-#include "os/input_event.h"
-#include "os/keyboard.h"
-#include "variant.h"
+#include "core/object.h"
+#include "core/os/input_event.h"
+#include "core/os/keyboard.h"
+#include "core/variant.h"
struct _GlobalConstant {
diff --git a/core/global_constants.h b/core/global_constants.h
index 76f618989c..48f16934a3 100644
--- a/core/global_constants.h
+++ b/core/global_constants.h
@@ -31,7 +31,7 @@
#ifndef GLOBAL_CONSTANTS_H
#define GLOBAL_CONSTANTS_H
-#include "string_db.h"
+#include "core/string_db.h"
class GlobalConstants {
public:
diff --git a/core/hash_map.h b/core/hash_map.h
index 2df743ba7d..3869cd3c36 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -31,12 +31,12 @@
#ifndef HASH_MAP_H
#define HASH_MAP_H
-#include "error_macros.h"
-#include "hashfuncs.h"
-#include "list.h"
-#include "math_funcs.h"
-#include "os/memory.h"
-#include "ustring.h"
+#include "core/error_macros.h"
+#include "core/hashfuncs.h"
+#include "core/list.h"
+#include "core/math/math_funcs.h"
+#include "core/os/memory.h"
+#include "core/ustring.h"
/**
* @class HashMap
@@ -150,7 +150,7 @@ private:
if (new_hash_table_power == -1)
return;
- Element **new_hash_table = memnew_arr(Element *, (1 << new_hash_table_power));
+ Element **new_hash_table = memnew_arr(Element *, ((uint64_t)1 << new_hash_table_power));
if (!new_hash_table) {
ERR_PRINT("Out of Memory");
@@ -230,7 +230,7 @@ private:
if (!p_t.hash_table || p_t.hash_table_power == 0)
return; /* not copying from empty table */
- hash_table = memnew_arr(Element *, 1 << p_t.hash_table_power);
+ hash_table = memnew_arr(Element *, (uint64_t)1 << p_t.hash_table_power);
hash_table_power = p_t.hash_table_power;
elements = p_t.elements;
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index 735e679d1e..457cfadc9c 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -31,12 +31,12 @@
#ifndef HASHFUNCS_H
#define HASHFUNCS_H
-#include "math_defs.h"
-#include "math_funcs.h"
-#include "node_path.h"
-#include "string_db.h"
-#include "typedefs.h"
-#include "ustring.h"
+#include "core/math/math_defs.h"
+#include "core/math/math_funcs.h"
+#include "core/node_path.h"
+#include "core/string_db.h"
+#include "core/typedefs.h"
+#include "core/ustring.h"
/**
* Hashing functions
diff --git a/core/helper/SCsub b/core/helper/SCsub
deleted file mode 100644
index 4efc902717..0000000000
--- a/core/helper/SCsub
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env python
-
-Import('env')
-
-env.add_source_files(env.core_sources, "*.cpp")
-
-Export('env')
diff --git a/core/image.cpp b/core/image.cpp
index 08bb9a35c3..172f5e517a 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -30,15 +30,15 @@
#include "image.h"
+#include "core/hash_map.h"
#include "core/io/image_loader.h"
+#include "core/io/resource_loader.h"
+#include "core/math/math_funcs.h"
#include "core/os/copymem.h"
-#include "hash_map.h"
-#include "math_funcs.h"
-#include "print_string.h"
+#include "core/print_string.h"
-#include "io/resource_loader.h"
-#include "math_funcs.h"
#include "thirdparty/misc/hq2x.h"
+
#include <stdio.h>
const char *Image::format_names[Image::FORMAT_MAX] = {
@@ -307,6 +307,7 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_widt
r_width = w;
r_height = h;
}
+
int Image::get_mipmap_offset(int p_mipmap) const {
ERR_FAIL_INDEX_V(p_mipmap, get_mipmap_count() + 1, -1);
@@ -499,8 +500,6 @@ void Image::convert(Format p_new_format) {
bool gen_mipmaps = mipmaps;
- //mipmaps=false;
-
_copy_internals_from(new_img);
if (gen_mipmaps)
@@ -781,9 +780,9 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
// Setup mipmap-aware scaling
Image dst2;
- int mip1;
- int mip2;
- float mip1_weight;
+ int mip1 = 0;
+ int mip2 = 0;
+ float mip1_weight = 0;
if (mipmap_aware) {
float avg_scale = ((float)p_width / width + (float)p_height / height) * 0.5f;
if (avg_scale >= 1.0f) {
@@ -799,6 +798,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
if (interpolate_mipmaps) {
dst2.create(p_width, p_height, 0, format);
}
+
bool had_mipmaps = mipmaps;
if (interpolate_mipmaps && !had_mipmaps) {
generate_mipmaps();
@@ -951,6 +951,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
}
void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {
+
if (!_can_modify(format)) {
ERR_EXPLAIN("Cannot crop in indexed, compressed or custom image formats.");
ERR_FAIL();
@@ -996,7 +997,7 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {
}
}
- if (mipmaps > 0)
+ if (has_mipmaps())
dst.generate_mipmaps();
_copy_internals_from(dst);
}
@@ -1013,10 +1014,10 @@ void Image::flip_y() {
ERR_FAIL();
}
- bool gm = mipmaps;
-
- if (gm)
+ bool used_mipmaps = has_mipmaps();
+ if (used_mipmaps) {
clear_mipmaps();
+ }
{
PoolVector<uint8_t>::Write w = data.write();
@@ -1037,8 +1038,9 @@ void Image::flip_y() {
}
}
- if (gm)
+ if (used_mipmaps) {
generate_mipmaps();
+ }
}
void Image::flip_x() {
@@ -1048,9 +1050,10 @@ void Image::flip_x() {
ERR_FAIL();
}
- bool gm = mipmaps;
- if (gm)
+ bool used_mipmaps = has_mipmaps();
+ if (used_mipmaps) {
clear_mipmaps();
+ }
{
PoolVector<uint8_t>::Write w = data.write();
@@ -1071,8 +1074,9 @@ void Image::flip_x() {
}
}
- if (gm)
+ if (used_mipmaps) {
generate_mipmaps();
+ }
}
int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps) {
@@ -1167,12 +1171,13 @@ void Image::expand_x2_hq2x() {
ERR_FAIL_COND(!_can_modify(format));
- Format current = format;
- bool mm = has_mipmaps();
- if (mm) {
+ bool used_mipmaps = has_mipmaps();
+ if (used_mipmaps) {
clear_mipmaps();
}
+ Format current = format;
+
if (current != FORMAT_RGBA8)
convert(FORMAT_RGBA8);
@@ -1193,6 +1198,8 @@ void Image::expand_x2_hq2x() {
if (current != FORMAT_RGBA8)
convert(current);
+ // FIXME: This is likely meant to use "used_mipmaps" as defined above, but if we do,
+ // we end up with a regression: GH-22747
if (mipmaps) {
generate_mipmaps();
}
@@ -1466,7 +1473,8 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
void Image::create(const char **p_xpm) {
- int size_width, size_height;
+ int size_width = 0;
+ int size_height = 0;
int pixelchars = 0;
mipmaps = false;
bool has_alpha = false;
@@ -1482,8 +1490,8 @@ void Image::create(const char **p_xpm) {
int line = 0;
HashMap<String, Color> colormap;
- int colormap_size;
- uint32_t pixel_size;
+ int colormap_size = 0;
+ uint32_t pixel_size = 0;
PoolVector<uint8_t>::Write w;
while (status != DONE) {
diff --git a/core/image.h b/core/image.h
index 6af55ca8d9..11f9380c3c 100644
--- a/core/image.h
+++ b/core/image.h
@@ -31,10 +31,10 @@
#ifndef IMAGE_H
#define IMAGE_H
-#include "color.h"
-#include "dvector.h"
-#include "rect2.h"
-#include "resource.h"
+#include "core/color.h"
+#include "core/dvector.h"
+#include "core/math/rect2.h"
+#include "core/resource.h"
/**
* @author Juan Linietsky <reduzio@gmail.com>
diff --git a/core/input_map.cpp b/core/input_map.cpp
index ffc8a39da5..b88d99470a 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -30,8 +30,8 @@
#include "input_map.h"
-#include "os/keyboard.h"
-#include "project_settings.h"
+#include "core/os/keyboard.h"
+#include "core/project_settings.h"
InputMap *InputMap::singleton = NULL;
@@ -199,6 +199,10 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
Ref<InputEventAction> input_event_action = p_event;
if (input_event_action.is_valid()) {
+ if (p_pressed != NULL)
+ *p_pressed = input_event_action->is_pressed();
+ if (p_strength != NULL)
+ *p_strength = (*p_pressed) ? 1.0f : 0.0f;
return input_event_action->get_action() == p_action;
}
diff --git a/core/input_map.h b/core/input_map.h
index bdec75c65b..8f286277d1 100644
--- a/core/input_map.h
+++ b/core/input_map.h
@@ -31,8 +31,8 @@
#ifndef INPUT_MAP_H
#define INPUT_MAP_H
-#include "object.h"
-#include "os/input_event.h"
+#include "core/object.h"
+#include "core/os/input_event.h"
class InputMap : public Object {
diff --git a/core/io/SCsub b/core/io/SCsub
index 79b56cb716..1c5f954470 100644
--- a/core/io/SCsub
+++ b/core/io/SCsub
@@ -3,6 +3,3 @@
Import('env')
env.add_source_files(env.core_sources, "*.cpp")
-
-Export('env')
-
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index bc3bfcf356..3c0b6541bd 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -29,9 +29,10 @@
/*************************************************************************/
#include "compression.h"
-#include "os/copymem.h"
-#include "project_settings.h"
-#include "zip_io.h"
+
+#include "core/io/zip_io.h"
+#include "core/os/copymem.h"
+#include "core/project_settings.h"
#include "thirdparty/misc/fastlz.h"
@@ -174,7 +175,7 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
} break;
case MODE_ZSTD: {
ZSTD_DCtx *dctx = ZSTD_createDCtx();
- if (zstd_long_distance_matching) ZSTD_DCtx_setMaxWindowSize(dctx, 1 << zstd_window_log_size);
+ if (zstd_long_distance_matching) ZSTD_DCtx_setMaxWindowSize(dctx, (size_t)1 << zstd_window_log_size);
int ret = ZSTD_decompressDCtx(dctx, p_dst, p_dst_max_size, p_src, p_src_size);
ZSTD_freeDCtx(dctx);
return ret;
diff --git a/core/io/compression.h b/core/io/compression.h
index a0ccd539cb..2f770e6aee 100644
--- a/core/io/compression.h
+++ b/core/io/compression.h
@@ -31,7 +31,7 @@
#ifndef COMPRESSION_H
#define COMPRESSION_H
-#include "typedefs.h"
+#include "core/typedefs.h"
class Compression {
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index aa06ae5cc0..e2bc0f5d8f 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -29,9 +29,10 @@
/*************************************************************************/
#include "config_file.h"
-#include "os/file_access.h"
-#include "os/keyboard.h"
-#include "variant_parser.h"
+
+#include "core/os/file_access.h"
+#include "core/os/keyboard.h"
+#include "core/variant_parser.h"
PoolStringArray ConfigFile::_get_sections() const {
diff --git a/core/io/config_file.h b/core/io/config_file.h
index ac749bed76..2bc439d413 100644
--- a/core/io/config_file.h
+++ b/core/io/config_file.h
@@ -32,7 +32,7 @@
#define CONFIG_FILE_H
#include "core/ordered_hash_map.h"
-#include "reference.h"
+#include "core/reference.h"
class ConfigFile : public Reference {
diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp
index dcaf99e24a..d44c8a9585 100644
--- a/core/io/file_access_buffered.cpp
+++ b/core/io/file_access_buffered.cpp
@@ -30,9 +30,7 @@
#include "file_access_buffered.h"
-#include <string.h>
-
-#include "error_macros.h"
+#include "core/error_macros.h"
Error FileAccessBuffered::set_error(Error p_error) const {
diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h
index f4ed47d6bc..a36a9a4603 100644
--- a/core/io/file_access_buffered.h
+++ b/core/io/file_access_buffered.h
@@ -31,10 +31,9 @@
#ifndef FILE_ACCESS_BUFFERED_H
#define FILE_ACCESS_BUFFERED_H
-#include "os/file_access.h"
-
-#include "dvector.h"
-#include "ustring.h"
+#include "core/dvector.h"
+#include "core/os/file_access.h"
+#include "core/ustring.h"
class FileAccessBuffered : public FileAccess {
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index d6547ba19f..645d97ae7e 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -29,7 +29,9 @@
/*************************************************************************/
#include "file_access_compressed.h"
-#include "print_string.h"
+
+#include "core/print_string.h"
+
void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) {
magic = p_magic.ascii().get_data();
@@ -291,7 +293,6 @@ uint8_t FileAccessCompressed::get_8() const {
} else {
read_block--;
at_end = true;
- ret = 0;
}
}
diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h
index 587f58a7c6..5be42a6d32 100644
--- a/core/io/file_access_compressed.h
+++ b/core/io/file_access_compressed.h
@@ -31,8 +31,8 @@
#ifndef FILE_ACCESS_COMPRESSED_H
#define FILE_ACCESS_COMPRESSED_H
-#include "io/compression.h"
-#include "os/file_access.h"
+#include "core/io/compression.h"
+#include "core/os/file_access.h"
class FileAccessCompressed : public FileAccess {
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 812e881114..28bf55b962 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -30,9 +30,9 @@
#include "file_access_encrypted.h"
+#include "core/os/copymem.h"
+#include "core/print_string.h"
#include "core/variant.h"
-#include "os/copymem.h"
-#include "print_string.h"
#include "thirdparty/misc/aes256.h"
#include "thirdparty/misc/md5.h"
diff --git a/core/io/file_access_encrypted.h b/core/io/file_access_encrypted.h
index b9365a9fd0..873dbfa7e8 100644
--- a/core/io/file_access_encrypted.h
+++ b/core/io/file_access_encrypted.h
@@ -31,7 +31,7 @@
#ifndef FILE_ACCESS_ENCRYPTED_H
#define FILE_ACCESS_ENCRYPTED_H
-#include "os/file_access.h"
+#include "core/os/file_access.h"
class FileAccessEncrypted : public FileAccess {
public:
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp
index c4eb2848b1..4c2aa4294d 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -30,10 +30,10 @@
#include "file_access_memory.h"
-#include "map.h"
-#include "os/copymem.h"
-#include "os/dir_access.h"
-#include "project_settings.h"
+#include "core/map.h"
+#include "core/os/copymem.h"
+#include "core/os/dir_access.h"
+#include "core/project_settings.h"
static Map<String, Vector<uint8_t> > *files = NULL;
diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h
index 2136f4cc0c..e474fb0d05 100644
--- a/core/io/file_access_memory.h
+++ b/core/io/file_access_memory.h
@@ -31,7 +31,7 @@
#ifndef FILE_ACCESS_MEMORY_H
#define FILE_ACCESS_MEMORY_H
-#include "os/file_access.h"
+#include "core/os/file_access.h"
class FileAccessMemory : public FileAccess {
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index d72d3ca9f1..b9544ac166 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -29,10 +29,11 @@
/*************************************************************************/
#include "file_access_network.h"
-#include "io/ip.h"
-#include "marshalls.h"
-#include "os/os.h"
-#include "project_settings.h"
+
+#include "core/io/ip.h"
+#include "core/io/marshalls.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
//#define DEBUG_PRINT(m_p) print_line(m_p)
//#define DEBUG_TIME(m_what) printf("MS: %s - %lli\n",m_what,OS::get_singleton()->get_ticks_usec());
@@ -226,7 +227,7 @@ FileAccessNetworkClient::FileAccessNetworkClient() {
quit = false;
singleton = this;
last_id = 0;
- client = Ref<StreamPeerTCP>(StreamPeerTCP::create_ref());
+ client.instance();
sem = Semaphore::create();
lockcount = 0;
}
@@ -499,8 +500,9 @@ uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) {
void FileAccessNetwork::configure() {
GLOBAL_DEF("network/remote_fs/page_size", 65536);
+ ProjectSettings::get_singleton()->set_custom_property_info("network/remote_fs/page_size", PropertyInfo(Variant::INT, "network/remote_fs/page_size", PROPERTY_HINT_RANGE, "1,65536,1,or_greater")); //is used as denominator and can't be zero
GLOBAL_DEF("network/remote_fs/page_read_ahead", 4);
- GLOBAL_DEF("network/remote_fs/max_pages", 20);
+ ProjectSettings::get_singleton()->set_custom_property_info("network/remote_fs/page_read_ahead", PropertyInfo(Variant::INT, "network/remote_fs/page_read_ahead", PROPERTY_HINT_RANGE, "0,8,1,or_greater"));
}
FileAccessNetwork::FileAccessNetwork() {
@@ -518,7 +520,6 @@ FileAccessNetwork::FileAccessNetwork() {
nc->unlock_mutex();
page_size = GLOBAL_GET("network/remote_fs/page_size");
read_ahead = GLOBAL_GET("network/remote_fs/page_read_ahead");
- max_pages = GLOBAL_GET("network/remote_fs/max_pages");
last_activity_val = 0;
waiting_on_page = -1;
last_page = -1;
diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h
index be9bdb1af6..c929e8446d 100644
--- a/core/io/file_access_network.h
+++ b/core/io/file_access_network.h
@@ -31,10 +31,10 @@
#ifndef FILE_ACCESS_NETWORK_H
#define FILE_ACCESS_NETWORK_H
-#include "io/stream_peer_tcp.h"
-#include "os/file_access.h"
-#include "os/semaphore.h"
-#include "os/thread.h"
+#include "core/io/stream_peer_tcp.h"
+#include "core/os/file_access.h"
+#include "core/os/semaphore.h"
+#include "core/os/thread.h"
class FileAccessNetwork;
@@ -47,8 +47,6 @@ class FileAccessNetworkClient {
int size;
};
- int ml;
-
List<BlockRequest> block_requests;
Semaphore *sem;
@@ -100,7 +98,6 @@ class FileAccessNetwork : public FileAccess {
int page_size;
int read_ahead;
- int max_pages;
mutable int waiting_on_page;
mutable int last_activity_val;
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index efb4c7a073..40f756ba9a 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "file_access_pack.h"
-#include "version.h"
+
+#include "core/version.h"
#include <stdio.h>
@@ -168,11 +169,11 @@ bool PackedSourcePCK::try_open_pack(const String &p_path) {
uint32_t version = f->get_32();
uint32_t ver_major = f->get_32();
uint32_t ver_minor = f->get_32();
- uint32_t ver_rev = f->get_32();
+ f->get_32(); // ver_rev
ERR_EXPLAIN("Pack version unsupported: " + itos(version));
ERR_FAIL_COND_V(version != PACK_VERSION, false);
- ERR_EXPLAIN("Pack created with a newer version of the engine: " + itos(ver_major) + "." + itos(ver_minor) + "." + itos(ver_rev));
+ ERR_EXPLAIN("Pack created with a newer version of the engine: " + itos(ver_major) + "." + itos(ver_minor));
ERR_FAIL_COND_V(ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), false);
for (int i = 0; i < 16; i++) {
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h
index f29e431d9a..9e31bcf88a 100644
--- a/core/io/file_access_pack.h
+++ b/core/io/file_access_pack.h
@@ -31,11 +31,11 @@
#ifndef FILE_ACCESS_PACK_H
#define FILE_ACCESS_PACK_H
-#include "list.h"
-#include "map.h"
-#include "os/dir_access.h"
-#include "os/file_access.h"
-#include "print_string.h"
+#include "core/list.h"
+#include "core/map.h"
+#include "core/os/dir_access.h"
+#include "core/os/file_access.h"
+#include "core/print_string.h"
class PackSource;
diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h
index df83575f6a..9bb1ad221a 100644
--- a/core/io/file_access_zip.h
+++ b/core/io/file_access_zip.h
@@ -34,7 +34,7 @@
#define FILE_ACCESS_ZIP_H
#include "core/io/file_access_pack.h"
-#include "map.h"
+#include "core/map.h"
#include "thirdparty/minizip/unzip.h"
@@ -90,8 +90,6 @@ class FileAccessZip : public FileAccess {
mutable bool at_eof;
- ZipArchive *archive;
-
public:
virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file
virtual void close(); ///< close a file
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 2425bb6d69..36dd688e77 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "http_client.h"
-#include "io/stream_peer_ssl.h"
-#include "version.h"
+
+#include "core/io/stream_peer_ssl.h"
+#include "core/version.h"
const char *HTTPClient::_methods[METHOD_MAX] = {
"GET",
@@ -274,7 +275,7 @@ void HTTPClient::close() {
response_headers.clear();
response_str.clear();
- body_size = 0;
+ body_size = -1;
body_left = 0;
chunk_left = 0;
read_until_eof = false;
@@ -348,7 +349,7 @@ Error HTTPClient::poll() {
}
if (ssl->get_status() == StreamPeerSSL::STATUS_CONNECTED) {
- // Handshake has been successfull
+ // Handshake has been successful
handshaking = false;
status = STATUS_CONNECTED;
return OK;
@@ -373,7 +374,20 @@ Error HTTPClient::poll() {
} break;
}
} break;
+ case STATUS_BODY:
case STATUS_CONNECTED: {
+ // Check if we are still connected
+ if (ssl) {
+ Ref<StreamPeerSSL> tmp = connection;
+ tmp->poll();
+ if (tmp->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
+ status = STATUS_CONNECTION_ERROR;
+ return ERR_CONNECTION_ERROR;
+ }
+ } else if (tcp_connection->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
+ status = STATUS_CONNECTION_ERROR;
+ return ERR_CONNECTION_ERROR;
+ }
// Connection established, requests can now be made
return OK;
} break;
@@ -403,7 +417,7 @@ Error HTTPClient::poll() {
String response;
response.parse_utf8((const char *)response_str.ptr());
Vector<String> responses = response.split("\n");
- body_size = 0;
+ body_size = -1;
chunked = false;
body_left = 0;
chunk_left = 0;
@@ -447,7 +461,7 @@ Error HTTPClient::poll() {
}
}
- if (body_size || chunked) {
+ if (body_size != -1 || chunked) {
status = STATUS_BODY;
} else if (!keep_alive) {
@@ -467,7 +481,8 @@ Error HTTPClient::poll() {
case STATUS_DISCONNECTED: {
return ERR_UNCONFIGURED;
} break;
- case STATUS_CONNECTION_ERROR: {
+ case STATUS_CONNECTION_ERROR:
+ case STATUS_SSL_HANDSHAKE_ERROR: {
return ERR_CONNECTION_ERROR;
} break;
case STATUS_CANT_CONNECT: {
@@ -664,11 +679,24 @@ Error HTTPClient::_get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received
if (blocking) {
- Error err = connection->get_data(p_buffer, p_bytes);
- if (err == OK)
- r_received = p_bytes;
- else
- r_received = 0;
+ // We can't use StreamPeer.get_data, since when reaching EOF we will get an
+ // error without knowing how many bytes we received.
+ Error err = ERR_FILE_EOF;
+ int read = 0;
+ int left = p_bytes;
+ r_received = 0;
+ while (left > 0) {
+ err = connection->get_partial_data(p_buffer + r_received, left, read);
+ if (err == OK) {
+ r_received += read;
+ } else if (err == ERR_FILE_EOF) {
+ r_received += read;
+ return err;
+ } else {
+ return err;
+ }
+ left -= read;
+ }
return err;
} else {
return connection->get_partial_data(p_buffer, p_bytes, r_received);
@@ -682,11 +710,11 @@ void HTTPClient::set_read_chunk_size(int p_size) {
HTTPClient::HTTPClient() {
- tcp_connection = StreamPeerTCP::create_ref();
+ tcp_connection.instance();
resolving = IP::RESOLVER_INVALID_ID;
status = STATUS_DISCONNECTED;
conn_port = -1;
- body_size = 0;
+ body_size = -1;
chunked = false;
body_left = 0;
read_until_eof = false;
diff --git a/core/io/http_client.h b/core/io/http_client.h
index 82b56b01db..9e674e4c1d 100644
--- a/core/io/http_client.h
+++ b/core/io/http_client.h
@@ -31,10 +31,10 @@
#ifndef HTTP_CLIENT_H
#define HTTP_CLIENT_H
-#include "io/ip.h"
-#include "io/stream_peer.h"
-#include "io/stream_peer_tcp.h"
-#include "reference.h"
+#include "core/io/ip.h"
+#include "core/io/stream_peer.h"
+#include "core/io/stream_peer_tcp.h"
+#include "core/reference.h"
class HTTPClient : public Reference {
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index b8fd13d67c..3ae9ff676c 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -30,7 +30,8 @@
#include "image_loader.h"
-#include "print_string.h"
+#include "core/print_string.h"
+
bool ImageFormatLoader::recognize(const String &p_extension) const {
List<String> extensions;
@@ -117,7 +118,6 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin
if (r_error) {
*r_error = ERR_CANT_OPEN;
}
- memdelete(f);
return RES();
}
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index fbb654c326..561f275e0c 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -31,11 +31,11 @@
#ifndef IMAGE_LOADER_H
#define IMAGE_LOADER_H
-#include "image.h"
-#include "io/resource_loader.h"
-#include "list.h"
-#include "os/file_access.h"
-#include "ustring.h"
+#include "core/image.h"
+#include "core/io/resource_loader.h"
+#include "core/list.h"
+#include "core/os/file_access.h"
+#include "core/ustring.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index 82c94ca0b2..f56e850796 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -29,9 +29,10 @@
/*************************************************************************/
#include "ip.h"
-#include "hash_map.h"
-#include "os/semaphore.h"
-#include "os/thread.h"
+
+#include "core/hash_map.h"
+#include "core/os/semaphore.h"
+#include "core/os/thread.h"
VARIANT_ENUM_CAST(IP::ResolverStatus);
diff --git a/core/io/ip.h b/core/io/ip.h
index d55b05b6fe..967f04a4bd 100644
--- a/core/io/ip.h
+++ b/core/io/ip.h
@@ -31,8 +31,8 @@
#ifndef IP_H
#define IP_H
-#include "io/ip_address.h"
-#include "os/os.h"
+#include "core/io/ip_address.h"
+#include "core/os/os.h"
struct _IP_ResolverPrivate;
diff --git a/core/io/ip_address.h b/core/io/ip_address.h
index d7b031b960..607ce81ef4 100644
--- a/core/io/ip_address.h
+++ b/core/io/ip_address.h
@@ -31,7 +31,7 @@
#ifndef IP_ADDRESS_H
#define IP_ADDRESS_H
-#include "ustring.h"
+#include "core/ustring.h"
struct IP_Address {
diff --git a/core/io/json.cpp b/core/io/json.cpp
index 7b2c5a62df..26e18828e5 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "json.h"
-#include "print_string.h"
+
+#include "core/print_string.h"
const char *JSON::tk_name[TK_MAX] = {
"'{'",
diff --git a/core/io/json.h b/core/io/json.h
index 9c12423798..af6c463331 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -31,7 +31,7 @@
#ifndef JSON_H
#define JSON_H
-#include "variant.h"
+#include "core/variant.h"
class JSON {
diff --git a/core/io/logger.cpp b/core/io/logger.cpp
index 786bec461b..01755c8ee9 100644
--- a/core/io/logger.cpp
+++ b/core/io/logger.cpp
@@ -30,9 +30,9 @@
#include "logger.h"
-#include "os/dir_access.h"
-#include "os/os.h"
-#include "print_string.h"
+#include "core/os/dir_access.h"
+#include "core/os/os.h"
+#include "core/print_string.h"
// va_copy was defined in the C99, but not in C++ standards before C++11.
// When you compile C++ without --std=c++<XX> option, compilers still define
@@ -45,6 +45,10 @@
#endif
#endif
+#if defined(MINGW_ENABLED) || defined(_MSC_VER)
+#define sprintf sprintf_s
+#endif
+
bool Logger::should_log(bool p_err) {
return (!p_err || _print_error_enabled) && (p_err || _print_line_enabled);
}
diff --git a/core/io/logger.h b/core/io/logger.h
index 631e7a0589..d32b43b030 100644
--- a/core/io/logger.h
+++ b/core/io/logger.h
@@ -31,9 +31,10 @@
#ifndef LOGGER_H
#define LOGGER_H
-#include "os/file_access.h"
-#include "ustring.h"
-#include "vector.h"
+#include "core/os/file_access.h"
+#include "core/ustring.h"
+#include "core/vector.h"
+
#include <stdarg.h>
class Logger {
@@ -106,4 +107,4 @@ public:
virtual ~CompositeLogger();
};
-#endif \ No newline at end of file
+#endif
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index e97df0c261..6338cee39d 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -29,9 +29,11 @@
/*************************************************************************/
#include "marshalls.h"
-#include "os/keyboard.h"
-#include "print_string.h"
-#include "reference.h"
+
+#include "core/os/keyboard.h"
+#include "core/print_string.h"
+#include "core/reference.h"
+
#include <limits.h>
#include <stdio.h>
@@ -805,7 +807,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
case Variant::INT: {
int64_t val = p_variant;
- if (val > 0x7FFFFFFF || val < -0x80000000) {
+ if (val > (int64_t)INT_MAX || val < (int64_t)INT_MIN) {
flags |= ENCODE_FLAG_64;
}
} break;
@@ -822,6 +824,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
flags |= ENCODE_FLAG_OBJECT_AS_ID;
}
} break;
+ default: {} // nothing to do at this stage
}
if (buf) {
@@ -847,17 +850,16 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::INT: {
- int64_t val = p_variant;
- if (val > 0x7FFFFFFF || val < -0x80000000) {
+ if (flags & ENCODE_FLAG_64) {
//64 bits
if (buf) {
- encode_uint64(val, buf);
+ encode_uint64(p_variant.operator int64_t(), buf);
}
r_len += 8;
} else {
if (buf) {
- encode_uint32(int32_t(val), buf);
+ encode_uint32(p_variant.operator int32_t(), buf);
}
r_len += 4;
@@ -865,9 +867,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::REAL: {
- double d = p_variant;
- float f = d;
- if (double(f) != d) {
+ if (flags & ENCODE_FLAG_64) {
if (buf) {
encode_double(p_variant.operator double(), buf);
}
diff --git a/core/io/marshalls.h b/core/io/marshalls.h
index 381e4e3d20..1284520945 100644
--- a/core/io/marshalls.h
+++ b/core/io/marshalls.h
@@ -31,10 +31,10 @@
#ifndef MARSHALLS_H
#define MARSHALLS_H
-#include "typedefs.h"
+#include "core/reference.h"
+#include "core/typedefs.h"
+#include "core/variant.h"
-#include "reference.h"
-#include "variant.h"
/**
* Miscellaneous helpers for marshalling data types, and encoding
* in an endian independent way
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 8e67f1c97a..b3f0a76a80 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -28,7 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "core/io/multiplayer_api.h"
+#include "multiplayer_api.h"
+
#include "core/io/marshalls.h"
#include "scene/main/node.h"
@@ -37,24 +38,26 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
switch (mode) {
case MultiplayerAPI::RPC_MODE_DISABLED: {
- //do nothing
+ // Do nothing.
} break;
case MultiplayerAPI::RPC_MODE_REMOTE: {
- //do nothing also, no need to call local
+ // Do nothing also. Remote cannot produce a local call.
} break;
+ case MultiplayerAPI::RPC_MODE_MASTERSYNC: {
+ if (is_master)
+ r_skip_rpc = true; // I am the master, so skip remote call.
+ } // Do not break, fall over to other sync.
case MultiplayerAPI::RPC_MODE_REMOTESYNC:
- case MultiplayerAPI::RPC_MODE_MASTERSYNC:
- case MultiplayerAPI::RPC_MODE_SLAVESYNC:
- case MultiplayerAPI::RPC_MODE_SYNC: {
- //call it, sync always results in call
+ case MultiplayerAPI::RPC_MODE_PUPPETSYNC: {
+ // Call it, sync always results in a local call.
return true;
} break;
case MultiplayerAPI::RPC_MODE_MASTER: {
if (is_master)
- r_skip_rpc = true; //no other master so..
+ r_skip_rpc = true; // I am the master, so skip remote call.
return is_master;
} break;
- case MultiplayerAPI::RPC_MODE_SLAVE: {
+ case MultiplayerAPI::RPC_MODE_PUPPET: {
return !is_master;
} break;
}
@@ -67,19 +70,16 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i
case MultiplayerAPI::RPC_MODE_DISABLED: {
return false;
} break;
- case MultiplayerAPI::RPC_MODE_REMOTE: {
- return true;
- } break;
- case MultiplayerAPI::RPC_MODE_REMOTESYNC:
- case MultiplayerAPI::RPC_MODE_SYNC: {
+ case MultiplayerAPI::RPC_MODE_REMOTE:
+ case MultiplayerAPI::RPC_MODE_REMOTESYNC: {
return true;
} break;
case MultiplayerAPI::RPC_MODE_MASTERSYNC:
case MultiplayerAPI::RPC_MODE_MASTER: {
return p_node->is_network_master();
} break;
- case MultiplayerAPI::RPC_MODE_SLAVESYNC:
- case MultiplayerAPI::RPC_MODE_SLAVE: {
+ case MultiplayerAPI::RPC_MODE_PUPPETSYNC:
+ case MultiplayerAPI::RPC_MODE_PUPPET: {
return !p_node->is_network_master() && p_remote_id == p_node->get_network_master();
} break;
}
@@ -94,7 +94,7 @@ void MultiplayerAPI::poll() {
network_peer->poll();
- if (!network_peer.is_valid()) //it's possible that polling might have resulted in a disconnection, so check here
+ if (!network_peer.is_valid()) // It's possible that polling might have resulted in a disconnection, so check here.
return;
while (network_peer->get_available_packet_count()) {
@@ -113,7 +113,7 @@ void MultiplayerAPI::poll() {
rpc_sender_id = 0;
if (!network_peer.is_valid()) {
- break; //it's also possible that a packet or RPC caused a disconnection, so also check here
+ break; // It's also possible that a packet or RPC caused a disconnection, so also check here.
}
}
}
@@ -160,7 +160,9 @@ Ref<NetworkedMultiplayerPeer> MultiplayerAPI::get_network_peer() const {
void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ ERR_EXPLAIN("Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it");
ERR_FAIL_COND(root_node == NULL);
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 1);
uint8_t packet_type = p_packet[0];
@@ -180,13 +182,15 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
case NETWORK_COMMAND_REMOTE_CALL:
case NETWORK_COMMAND_REMOTE_SET: {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 6);
Node *node = _process_get_node(p_from, p_packet, p_packet_len);
+ ERR_EXPLAIN("Invalid packet received. Requested node was not found.");
ERR_FAIL_COND(node == NULL);
- //detect cstring end
+ // Detect cstring end.
int len_end = 5;
for (; len_end < p_packet_len; len_end++) {
if (p_packet[len_end] == 0) {
@@ -194,6 +198,7 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
}
}
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(len_end >= p_packet_len);
StringName name = String::utf8((const char *)&p_packet[5]);
@@ -222,9 +227,11 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
Node *node = NULL;
if (target & 0x80000000) {
- //use full path (not cached yet)
+ // Use full path (not cached yet).
int ofs = target & 0x7FFFFFFF;
+
+ ERR_EXPLAIN("Invalid packet received. Size smaller than declared.");
ERR_FAIL_COND_V(ofs >= p_packet_len, NULL);
String paths;
@@ -237,17 +244,19 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
if (!node)
ERR_PRINTS("Failed to get path from RPC: " + String(np));
} else {
- //use cached path
+ // Use cached path.
int id = target;
Map<int, PathGetCache>::Element *E = path_get_cache.find(p_from);
+ ERR_EXPLAIN("Invalid packet received. Requests invalid peer cache.");
ERR_FAIL_COND_V(!E, NULL);
Map<int, PathGetCache::NodeInfo>::Element *F = E->get().nodes.find(id);
+ ERR_EXPLAIN("Invalid packet received. Unabled to find requested cached node.");
ERR_FAIL_COND_V(!F, NULL);
PathGetCache::NodeInfo *ni = &F->get();
- //do proper caching later
+ // Do proper caching later.
node = root_node->get_node(ni->path);
if (!node)
@@ -258,9 +267,10 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_offset >= p_packet_len);
- // Check that remote can call the RPC on this node
+ // Check that remote can call the RPC on this node.
RPCMode rpc_mode = RPC_MODE_DISABLED;
const Map<StringName, RPCMode>::Element *E = p_node->get_node_rpc_mode(p_name);
if (E) {
@@ -268,6 +278,8 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
} else if (p_node->get_script_instance()) {
rpc_mode = p_node->get_script_instance()->get_rpc_mode(p_name);
}
+
+ ERR_EXPLAIN("RPC '" + String(p_name) + "' is not allowed from: " + itos(p_from) + ". Mode is " + itos((int)rpc_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
ERR_FAIL_COND(!_can_call_mode(p_node, rpc_mode, p_from));
int argc = p_packet[p_offset];
@@ -280,11 +292,14 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
for (int i = 0; i < argc; i++) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_offset >= p_packet_len);
+
int vlen;
Error err = decode_variant(args.write[i], &p_packet[p_offset], p_packet_len - p_offset, &vlen);
+ ERR_EXPLAIN("Invalid packet received. Unable to decode RPC argument.");
ERR_FAIL_COND(err != OK);
- //args[i]=p_packet[3+i];
+
argp.write[i] = &args[i];
p_offset += vlen;
}
@@ -301,9 +316,10 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_offset >= p_packet_len);
- // Check that remote can call the RSET on this node
+ // Check that remote can call the RSET on this node.
RPCMode rset_mode = RPC_MODE_DISABLED;
const Map<StringName, RPCMode>::Element *E = p_node->get_node_rset_mode(p_name);
if (E) {
@@ -311,10 +327,15 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p
} else if (p_node->get_script_instance()) {
rset_mode = p_node->get_script_instance()->get_rset_mode(p_name);
}
+
+ ERR_EXPLAIN("RSET '" + String(p_name) + "' is not allowed from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
ERR_FAIL_COND(!_can_call_mode(p_node, rset_mode, p_from));
Variant value;
- decode_variant(value, &p_packet[p_offset], p_packet_len - p_offset);
+ Error err = decode_variant(value, &p_packet[p_offset], p_packet_len - p_offset);
+
+ ERR_EXPLAIN("Invalid packet received. Unable to decode RSET value.");
+ ERR_FAIL_COND(err != OK);
bool valid;
@@ -327,6 +348,7 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p
void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 5);
int id = decode_uint32(&p_packet[1]);
@@ -345,9 +367,7 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
path_get_cache[p_from].nodes[id] = ni;
- //send ack
-
- //encode path
+ // Encode path to send ack.
CharString pname = String(path).utf8();
int len = encode_cstring(pname.get_data(), NULL);
@@ -364,6 +384,7 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 2);
String paths;
@@ -372,31 +393,33 @@ void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet,
NodePath path = paths;
PathSentCache *psc = path_send_cache.getptr(path);
+ ERR_EXPLAIN("Invalid packet received. Tries to confirm a path which was not found in cache.");
ERR_FAIL_COND(!psc);
Map<int, bool>::Element *E = psc->confirmed_peers.find(p_from);
+ ERR_EXPLAIN("Invalid packet received. Source peer was not found in cache for the given path.");
ERR_FAIL_COND(!E);
E->get() = true;
}
bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int p_target) {
bool has_all_peers = true;
- List<int> peers_to_add; //if one is missing, take note to add it
+ List<int> peers_to_add; // If one is missing, take note to add it.
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
if (p_target < 0 && E->get() == -p_target)
- continue; //continue, excluded
+ continue; // Continue, excluded.
if (p_target > 0 && E->get() != p_target)
- continue; //continue, not for this peer
+ continue; // Continue, not for this peer.
Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
- if (!F || F->get() == false) {
- //path was not cached, or was cached but is unconfirmed
+ if (!F || !F->get()) {
+ // Path was not cached, or was cached but is unconfirmed.
if (!F) {
- //not cached at all, take note
+ // Not cached at all, take note.
peers_to_add.push_back(E->get());
}
@@ -404,11 +427,11 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int
}
}
- //those that need to be added, send a message for this
+ // Those that need to be added, send a message for this.
for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) {
- //encode function name
+ // Encode function name.
CharString pname = String(p_path).utf8();
int len = encode_cstring(pname.get_data(), NULL);
@@ -419,11 +442,11 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int
encode_uint32(psc->id, &packet.write[1]);
encode_cstring(pname.get_data(), &packet.write[5]);
- network_peer->set_target_peer(E->get()); //to all of you
+ network_peer->set_target_peer(E->get()); // To all of you.
network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
network_peer->put_packet(packet.ptr(), packet.size());
- psc->confirmed_peers.insert(E->get(), false); //insert into confirmed, but as false since it was not confirmed
+ psc->confirmed_peers.insert(E->get(), false); // Insert into confirmed, but as false since it was not confirmed.
}
return has_all_peers;
@@ -462,35 +485,36 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
}
NodePath from_path = (root_node->get_path()).rel_path_to(p_from->get_path());
+ ERR_EXPLAIN("Unable to send RPC. Relative path is empty. THIS IS LIKELY A BUG IN THE ENGINE!");
ERR_FAIL_COND(from_path.is_empty());
- //see if the path is cached
+ // See if the path is cached.
PathSentCache *psc = path_send_cache.getptr(from_path);
if (!psc) {
- //path is not cached, create
+ // Path is not cached, create.
path_send_cache[from_path] = PathSentCache();
psc = path_send_cache.getptr(from_path);
psc->id = last_send_cache_id++;
}
- //create base packet, lots of hardcode because it must be tight
+ // Create base packet, lots of hardcode because it must be tight.
int ofs = 0;
#define MAKE_ROOM(m_amount) \
if (packet_cache.size() < m_amount) packet_cache.resize(m_amount);
- //encode type
+ // Encode type.
MAKE_ROOM(1);
packet_cache.write[0] = p_set ? NETWORK_COMMAND_REMOTE_SET : NETWORK_COMMAND_REMOTE_CALL;
ofs += 1;
- //encode ID
+ // Encode ID.
MAKE_ROOM(ofs + 4);
encode_uint32(psc->id, &(packet_cache.write[ofs]));
ofs += 4;
- //encode function name
+ // Encode function name.
CharString name = String(p_name).utf8();
int len = encode_cstring(name.get_data(), NULL);
MAKE_ROOM(ofs + len);
@@ -498,20 +522,22 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
ofs += len;
if (p_set) {
- //set argument
+ // Set argument.
Error err = encode_variant(*p_arg[0], NULL, len);
+ ERR_EXPLAIN("Unable to encode RSET value. THIS IS LIKELY A BUG IN THE ENGINE!");
ERR_FAIL_COND(err != OK);
MAKE_ROOM(ofs + len);
encode_variant(*p_arg[0], &(packet_cache.write[ofs]), len);
ofs += len;
} else {
- //call arguments
+ // Call arguments.
MAKE_ROOM(ofs + 1);
packet_cache.write[ofs] = p_argcount;
ofs += 1;
for (int i = 0; i < p_argcount; i++) {
Error err = encode_variant(*p_arg[i], NULL, len);
+ ERR_EXPLAIN("Unable to encode RPC argument. THIS IS LIKELY A BUG IN THE ENGINE!");
ERR_FAIL_COND(err != OK);
MAKE_ROOM(ofs + len);
encode_variant(*p_arg[i], &(packet_cache.write[ofs]), len);
@@ -519,21 +545,21 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
}
}
- //see if all peers have cached path (is so, call can be fast)
+ // See if all peers have cached path (is so, call can be fast).
bool has_all_peers = _send_confirm_path(from_path, psc, p_to);
- //take chance and set transfer mode, since all send methods will use it
+ // Take chance and set transfer mode, since all send methods will use it.
network_peer->set_transfer_mode(p_unreliable ? NetworkedMultiplayerPeer::TRANSFER_MODE_UNRELIABLE : NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
if (has_all_peers) {
- //they all have verified paths, so send fast
- network_peer->set_target_peer(p_to); //to all of you
- network_peer->put_packet(packet_cache.ptr(), ofs); //a message with love
+ // They all have verified paths, so send fast.
+ network_peer->set_target_peer(p_to); // To all of you.
+ network_peer->put_packet(packet_cache.ptr(), ofs); // A message with love.
} else {
- //not all verified path, so send one by one
+ // Not all verified path, so send one by one.
- //apend path at the end, since we will need it for some packets
+ // Append path at the end, since we will need it for some packets.
CharString pname = String(from_path).utf8();
int path_len = encode_cstring(pname.get_data(), NULL);
MAKE_ROOM(ofs + path_len);
@@ -542,23 +568,23 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
if (p_to < 0 && E->get() == -p_to)
- continue; //continue, excluded
+ continue; // Continue, excluded.
if (p_to > 0 && E->get() != p_to)
- continue; //continue, not for this peer
+ continue; // Continue, not for this peer.
Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
- ERR_CONTINUE(!F); //should never happen
+ ERR_CONTINUE(!F); // Should never happen.
- network_peer->set_target_peer(E->get()); //to this one specifically
+ network_peer->set_target_peer(E->get()); // To this one specifically.
- if (F->get() == true) {
- //this one confirmed path, so use id
+ if (F->get()) {
+ // This one confirmed path, so use id.
encode_uint32(psc->id, &(packet_cache.write[1]));
network_peer->put_packet(packet_cache.ptr(), ofs);
} else {
- //this one did not confirm path yet, so use entire path (sorry!)
- encode_uint32(0x80000000 | ofs, &(packet_cache.write[1])); //offset to path and flag
+ // This one did not confirm path yet, so use entire path (sorry!).
+ encode_uint32(0x80000000 | ofs, &(packet_cache.write[1])); // Offset to path and flag.
network_peer->put_packet(packet_cache.ptr(), ofs + path_len);
}
}
@@ -573,7 +599,7 @@ void MultiplayerAPI::_add_peer(int p_id) {
void MultiplayerAPI::_del_peer(int p_id) {
connected_peers.erase(p_id);
- path_get_cache.erase(p_id); //I no longer need your cache, sorry
+ path_get_cache.erase(p_id); // I no longer need your cache, sorry.
emit_signal("network_peer_disconnected", p_id);
}
@@ -594,8 +620,12 @@ void MultiplayerAPI::_server_disconnected() {
void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) {
- ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_EXPLAIN("Trying to call an RPC while no network peer is active.");
ERR_FAIL_COND(!network_peer.is_valid());
+ ERR_EXPLAIN("Trying to call an RPC on a node which is not inside SceneTree.");
+ ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_EXPLAIN("Trying to call an RPC via a network peer which is not connected.");
+ ERR_FAIL_COND(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED);
int node_id = network_peer->get_unique_id();
bool skip_rpc = false;
@@ -604,7 +634,7 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
bool is_master = p_node->is_network_master();
if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
- //check that send mode can use local call
+ // Check that send mode can use local call.
const Map<StringName, RPCMode>::Element *E = p_node->get_node_rpc_mode(p_method);
if (E) {
@@ -612,9 +642,9 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
if (call_local_native) {
- // done below
+ // Done below.
} else if (p_node->get_script_instance()) {
- //attempt with script
+ // Attempt with script.
RPCMode rpc_mode = p_node->get_script_instance()->get_rpc_mode(p_method);
call_local_script = _should_call_local(rpc_mode, is_master, skip_rpc);
}
@@ -650,15 +680,19 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) {
- ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_EXPLAIN("Trying to RSET while no network peer is active.");
ERR_FAIL_COND(!network_peer.is_valid());
+ ERR_EXPLAIN("Trying to RSET on a node which is not inside SceneTree.");
+ ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_EXPLAIN("Trying to send an RSET via a network peer which is not connected.");
+ ERR_FAIL_COND(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED);
int node_id = network_peer->get_unique_id();
bool is_master = p_node->is_network_master();
bool skip_rset = false;
if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
- //check that send mode can use local call
+ // Check that send mode can use local call.
bool set_local = false;
@@ -678,7 +712,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
return;
}
} else if (p_node->get_script_instance()) {
- //attempt with script
+ // Attempt with script.
RPCMode rpc_mode = p_node->get_script_instance()->get_rset_mode(p_property);
set_local = _should_call_local(rpc_mode, is_master, skip_rset);
@@ -706,8 +740,11 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
Error MultiplayerAPI::send_bytes(PoolVector<uint8_t> p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) {
+ ERR_EXPLAIN("Trying to send an empty raw packet.");
ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA);
+ ERR_EXPLAIN("Trying to send a raw packet while no network peer is active.");
ERR_FAIL_COND_V(!network_peer.is_valid(), ERR_UNCONFIGURED);
+ ERR_EXPLAIN("Trying to send a raw packet via a network peer which is not connected.");
ERR_FAIL_COND_V(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED);
MAKE_ROOM(p_data.size() + 1);
@@ -723,6 +760,7 @@ Error MultiplayerAPI::send_bytes(PoolVector<uint8_t> p_data, int p_to, Networked
void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 2);
PoolVector<uint8_t> out;
@@ -737,30 +775,36 @@ void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_pac
int MultiplayerAPI::get_network_unique_id() const {
+ ERR_EXPLAIN("No network peer is assigned. Unable to get unique network ID.");
ERR_FAIL_COND_V(!network_peer.is_valid(), 0);
return network_peer->get_unique_id();
}
bool MultiplayerAPI::is_network_server() const {
+ // XXX Maybe fail silently? Maybe should actually return true to make development of both local and online multiplayer easier?
+ ERR_EXPLAIN("No network peer is assigned. I can't be a server.");
ERR_FAIL_COND_V(!network_peer.is_valid(), false);
return network_peer->is_server();
}
void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) {
+ ERR_EXPLAIN("No network peer is assigned. Unable to set 'refuse_new_connections'.");
ERR_FAIL_COND(!network_peer.is_valid());
network_peer->set_refuse_new_connections(p_refuse);
}
bool MultiplayerAPI::is_refusing_new_network_connections() const {
+ ERR_EXPLAIN("No network peer is assigned. Unable to get 'refuse_new_connections'.");
ERR_FAIL_COND_V(!network_peer.is_valid(), false);
return network_peer->is_refusing_new_connections();
}
Vector<int> MultiplayerAPI::get_network_connected_peers() const {
+ ERR_EXPLAIN("No network peer is assigned. Assume no peers are connected.");
ERR_FAIL_COND_V(!network_peer.is_valid(), Vector<int>());
Vector<int> ret;
@@ -803,12 +847,13 @@ void MultiplayerAPI::_bind_methods() {
BIND_ENUM_CONSTANT(RPC_MODE_DISABLED);
BIND_ENUM_CONSTANT(RPC_MODE_REMOTE);
- BIND_ENUM_CONSTANT(RPC_MODE_SYNC);
BIND_ENUM_CONSTANT(RPC_MODE_MASTER);
- BIND_ENUM_CONSTANT(RPC_MODE_SLAVE);
+ BIND_ENUM_CONSTANT(RPC_MODE_PUPPET);
+ BIND_ENUM_CONSTANT(RPC_MODE_SLAVE); // Deprecated.
BIND_ENUM_CONSTANT(RPC_MODE_REMOTESYNC);
+ BIND_ENUM_CONSTANT(RPC_MODE_SYNC); // Deprecated.
BIND_ENUM_CONSTANT(RPC_MODE_MASTERSYNC);
- BIND_ENUM_CONSTANT(RPC_MODE_SLAVESYNC);
+ BIND_ENUM_CONSTANT(RPC_MODE_PUPPETSYNC);
}
MultiplayerAPI::MultiplayerAPI() {
diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h
index e47b1830e8..c86e76e91a 100644
--- a/core/io/multiplayer_api.h
+++ b/core/io/multiplayer_api.h
@@ -91,12 +91,13 @@ public:
RPC_MODE_DISABLED, // No rpc for this method, calls to this will be blocked (default)
RPC_MODE_REMOTE, // Using rpc() on it will call method / set property in all remote peers
- RPC_MODE_SYNC, // Using rpc() on it will call method / set property in all remote peers and locally
RPC_MODE_MASTER, // Using rpc() on it will call method on wherever the master is, be it local or remote
- RPC_MODE_SLAVE, // Using rpc() on it will call method for all slaves
- RPC_MODE_REMOTESYNC, // Same as RPC_MODE_SYNC, compatibility
+ RPC_MODE_PUPPET, // Using rpc() on it will call method for all puppets
+ RPC_MODE_SLAVE = RPC_MODE_PUPPET, // Deprecated, same as puppet
+ RPC_MODE_REMOTESYNC, // Using rpc() on it will call method / set property in all remote peers and locally
+ RPC_MODE_SYNC = RPC_MODE_REMOTESYNC, // Deprecated. Same as RPC_MODE_REMOTESYNC
RPC_MODE_MASTERSYNC, // Using rpc() on it will call method / set property in the master peer and locally
- RPC_MODE_SLAVESYNC, // Using rpc() on it will call method / set property in all slave peers and locally
+ RPC_MODE_PUPPETSYNC, // Using rpc() on it will call method / set property in all puppets peers and locally
};
void poll();
diff --git a/core/helper/value_evaluator.h b/core/io/net_socket.cpp
index 39177a7820..10bcf62eda 100644
--- a/core/helper/value_evaluator.h
+++ b/core/io/net_socket.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* value_evaluator.h */
+/* net_socket.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,19 +28,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef VALUE_EVALUATOR_H
-#define VALUE_EVALUATOR_H
+#include "net_socket.h"
-#include "core/object.h"
+NetSocket *(*NetSocket::_create)() = NULL;
-class ValueEvaluator : public Object {
+NetSocket *NetSocket::create() {
- GDCLASS(ValueEvaluator, Object);
+ if (_create)
+ return _create();
-public:
- virtual double eval(const String &p_text) {
- return p_text.to_double();
- }
-};
-
-#endif // VALUE_EVALUATOR_H
+ ERR_PRINT("Unable to create network socket, platform not supported");
+ return NULL;
+}
diff --git a/core/io/net_socket.h b/core/io/net_socket.h
new file mode 100644
index 0000000000..0665bec9fd
--- /dev/null
+++ b/core/io/net_socket.h
@@ -0,0 +1,79 @@
+/*************************************************************************/
+/* net_socket.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* 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 NET_SOCKET_H
+#define NET_SOCKET_H
+
+#include "core/io/ip.h"
+#include "core/reference.h"
+
+class NetSocket : public Reference {
+
+protected:
+ static NetSocket *(*_create)();
+
+public:
+ static NetSocket *create();
+
+ enum PollType {
+ POLL_TYPE_IN,
+ POLL_TYPE_OUT,
+ POLL_TYPE_IN_OUT
+ };
+
+ enum Type {
+ TYPE_NONE,
+ TYPE_TCP,
+ TYPE_UDP,
+ };
+
+ virtual Error open(Type p_type, IP::Type &ip_type) = 0;
+ virtual void close() = 0;
+ virtual Error bind(IP_Address p_addr, uint16_t p_port) = 0;
+ virtual Error listen(int p_max_pending) = 0;
+ virtual Error connect_to_host(IP_Address p_addr, uint16_t p_port) = 0;
+ virtual Error poll(PollType p_type, int timeout) const = 0;
+ virtual Error recv(uint8_t *p_buffer, int p_len, int &r_read) = 0;
+ virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port) = 0;
+ virtual Error send(const uint8_t *p_buffer, int p_len, int &r_sent) = 0;
+ virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) = 0;
+ virtual Ref<NetSocket> accept(IP_Address &r_ip, uint16_t &r_port) = 0;
+
+ virtual bool is_open() const = 0;
+ virtual int get_available_bytes() const = 0;
+
+ virtual void set_broadcasting_enabled(bool p_enabled) = 0;
+ virtual void set_blocking_enabled(bool p_enabled) = 0;
+ virtual void set_ipv6_only_enabled(bool p_enabled) = 0;
+ virtual void set_tcp_no_delay_enabled(bool p_enabled) = 0;
+ virtual void set_reuse_address_enabled(bool p_enabled) = 0;
+};
+
+#endif // NET_SOCKET_H
diff --git a/core/io/networked_multiplayer_peer.h b/core/io/networked_multiplayer_peer.h
index 66089c27b9..8e83c528a0 100644
--- a/core/io/networked_multiplayer_peer.h
+++ b/core/io/networked_multiplayer_peer.h
@@ -31,7 +31,7 @@
#ifndef NETWORKED_MULTIPLAYER_PEER_H
#define NETWORKED_MULTIPLAYER_PEER_H
-#include "io/packet_peer.h"
+#include "core/io/packet_peer.h"
class NetworkedMultiplayerPeer : public PacketPeer {
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index dc4997dfc2..b6dd4eaf6f 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -30,8 +30,9 @@
#include "packet_peer.h"
-#include "io/marshalls.h"
-#include "project_settings.h"
+#include "core/io/marshalls.h"
+#include "core/project_settings.h"
+
/* helpers / binders */
PacketPeer::PacketPeer() {
diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h
index b10152e96b..a6559df460 100644
--- a/core/io/packet_peer.h
+++ b/core/io/packet_peer.h
@@ -31,9 +31,10 @@
#ifndef PACKET_PEER_H
#define PACKET_PEER_H
-#include "io/stream_peer.h"
-#include "object.h"
-#include "ring_buffer.h"
+#include "core/io/stream_peer.h"
+#include "core/object.h"
+#include "core/ring_buffer.h"
+
class PacketPeer : public Reference {
GDCLASS(PacketPeer, Reference);
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp
index bfbea15582..d33ba6f855 100644
--- a/core/io/packet_peer_udp.cpp
+++ b/core/io/packet_peer_udp.cpp
@@ -29,9 +29,8 @@
/*************************************************************************/
#include "packet_peer_udp.h"
-#include "io/ip.h"
-PacketPeerUDP *(*PacketPeerUDP::_create)() = NULL;
+#include "core/io/ip.h"
void PacketPeerUDP::set_blocking_mode(bool p_enable) {
@@ -58,6 +57,177 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) {
return OK;
}
+int PacketPeerUDP::get_available_packet_count() const {
+
+ // TODO we should deprecate this, and expose poll instead!
+ Error err = const_cast<PacketPeerUDP *>(this)->_poll();
+ if (err != OK)
+ return -1;
+
+ return queue_count;
+}
+
+Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
+
+ Error err = _poll();
+ if (err != OK)
+ return err;
+ if (queue_count == 0)
+ return ERR_UNAVAILABLE;
+
+ uint32_t size = 0;
+ uint8_t ipv6[16];
+ rb.read(ipv6, 16, true);
+ packet_ip.set_ipv6(ipv6);
+ rb.read((uint8_t *)&packet_port, 4, true);
+ rb.read((uint8_t *)&size, 4, true);
+ rb.read(packet_buffer, size, true);
+ --queue_count;
+ *r_buffer = packet_buffer;
+ r_buffer_size = size;
+ return OK;
+}
+
+Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
+
+ ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V(!peer_addr.is_valid(), ERR_UNCONFIGURED);
+
+ Error err;
+ int sent = -1;
+
+ if (!_sock->is_open()) {
+ IP::Type ip_type = peer_addr.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+ err = _sock->open(NetSocket::TYPE_UDP, ip_type);
+ ERR_FAIL_COND_V(err != OK, err);
+ _sock->set_blocking_enabled(false);
+ }
+
+ do {
+ err = _sock->sendto(p_buffer, p_buffer_size, sent, peer_addr, peer_port);
+ if (err != OK) {
+ if (err != ERR_BUSY)
+ return FAILED;
+ else if (!blocking)
+ return ERR_BUSY;
+ // Keep trying to send full packet
+ continue;
+ }
+ return OK;
+
+ } while (sent != p_buffer_size);
+
+ return OK;
+}
+
+int PacketPeerUDP::get_max_packet_size() const {
+
+ return 512; // uhm maybe not
+}
+
+Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) {
+
+ ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
+ ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
+
+ Error err;
+ IP::Type ip_type = IP::TYPE_ANY;
+
+ if (p_bind_address.is_valid())
+ ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+
+ err = _sock->open(NetSocket::TYPE_UDP, ip_type);
+
+ if (err != OK)
+ return ERR_CANT_CREATE;
+
+ _sock->set_blocking_enabled(false);
+ _sock->set_reuse_address_enabled(true);
+ err = _sock->bind(p_bind_address, p_port);
+
+ if (err != OK) {
+ _sock->close();
+ return err;
+ }
+ rb.resize(nearest_shift(p_recv_buffer_size));
+ return OK;
+}
+
+void PacketPeerUDP::close() {
+
+ if (_sock.is_valid())
+ _sock->close();
+ rb.resize(16);
+ queue_count = 0;
+}
+
+Error PacketPeerUDP::wait() {
+
+ ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
+ return _sock->poll(NetSocket::POLL_TYPE_IN, -1);
+}
+
+Error PacketPeerUDP::_poll() {
+
+ ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
+
+ if (!_sock->is_open()) {
+ return FAILED;
+ }
+
+ Error err;
+ int read;
+ IP_Address ip;
+ uint16_t port;
+
+ while (true) {
+ err = _sock->recvfrom(recv_buffer, sizeof(recv_buffer), read, ip, port);
+
+ if (err != OK) {
+ if (err == ERR_BUSY)
+ break;
+ return FAILED;
+ }
+
+ if (rb.space_left() < read + 24) {
+#ifdef TOOLS_ENABLED
+ WARN_PRINTS("Buffer full, dropping packets!");
+#endif
+ continue;
+ }
+
+ uint32_t port32 = port;
+ rb.write(ip.get_ipv6(), 16);
+ rb.write((uint8_t *)&port32, 4);
+ rb.write((uint8_t *)&read, 4);
+ rb.write(recv_buffer, read);
+ ++queue_count;
+ }
+
+ return OK;
+}
+bool PacketPeerUDP::is_listening() const {
+
+ return _sock.is_valid() && _sock->is_open();
+}
+
+IP_Address PacketPeerUDP::get_packet_address() const {
+
+ return packet_ip;
+}
+
+int PacketPeerUDP::get_packet_port() const {
+
+ return packet_port;
+}
+
+void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) {
+
+ peer_addr = p_address;
+ peer_port = p_port;
+}
+
void PacketPeerUDP::_bind_methods() {
ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536));
@@ -65,26 +235,21 @@ void PacketPeerUDP::_bind_methods() {
ClassDB::bind_method(D_METHOD("wait"), &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);
}
-Ref<PacketPeerUDP> PacketPeerUDP::create_ref() {
-
- if (!_create)
- return Ref<PacketPeerUDP>();
- return Ref<PacketPeerUDP>(_create());
-}
-
-PacketPeerUDP *PacketPeerUDP::create() {
+PacketPeerUDP::PacketPeerUDP() {
- if (!_create)
- return NULL;
- return _create();
+ _sock = Ref<NetSocket>(NetSocket::create());
+ blocking = true;
+ packet_port = 0;
+ queue_count = 0;
+ peer_port = 0;
+ rb.resize(16);
}
-PacketPeerUDP::PacketPeerUDP() {
+PacketPeerUDP::~PacketPeerUDP() {
- blocking = true;
+ close();
}
diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h
index 035f4ad1c9..4366b0eb82 100644
--- a/core/io/packet_peer_udp.h
+++ b/core/io/packet_peer_udp.h
@@ -31,37 +31,55 @@
#ifndef PACKET_PEER_UDP_H
#define PACKET_PEER_UDP_H
-#include "io/ip.h"
-#include "io/packet_peer.h"
+#include "core/io/ip.h"
+#include "core/io/net_socket.h"
+#include "core/io/packet_peer.h"
class PacketPeerUDP : public PacketPeer {
GDCLASS(PacketPeerUDP, PacketPeer);
protected:
+ enum {
+ PACKET_BUFFER_SIZE = 65536
+ };
+
+ RingBuffer<uint8_t> rb;
+ uint8_t recv_buffer[PACKET_BUFFER_SIZE];
+ uint8_t packet_buffer[PACKET_BUFFER_SIZE];
+ IP_Address packet_ip;
+ int packet_port;
+ int queue_count;
+
+ IP_Address peer_addr;
+ int peer_port;
bool blocking;
+ Ref<NetSocket> _sock;
- static PacketPeerUDP *(*_create)();
static void _bind_methods();
String _get_packet_ip() const;
Error _set_dest_address(const String &p_address, int p_port);
+ Error _poll();
public:
void set_blocking_mode(bool p_enable);
- virtual Error listen(int p_port, const 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_dest_address(const IP_Address &p_address, int p_port) = 0;
+ Error listen(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536);
+ void close();
+ Error wait();
+ bool is_listening() const;
+ IP_Address get_packet_address() const;
+ int get_packet_port() const;
+ void set_dest_address(const IP_Address &p_address, int p_port);
- static Ref<PacketPeerUDP> create_ref();
- static PacketPeerUDP *create();
+ Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
+ Error get_packet(const uint8_t **r_buffer, int &r_buffer_size);
+ int get_available_packet_count() const;
+ int get_max_packet_size() const;
PacketPeerUDP();
+ ~PacketPeerUDP();
};
#endif // PACKET_PEER_UDP_H
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
index 2fd73db27d..3df8c01760 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "pck_packer.h"
+
#include "core/os/file_access.h"
-#include "version.h"
+#include "core/version.h"
static uint64_t _align(uint64_t p_n, int p_alignment) {
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 02c2c6ce1a..aa73d7bc5c 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -1309,7 +1309,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
case Variant::INT: {
int64_t val = p_property;
- if (val > 0x7FFFFFFF || val < -0x80000000) {
+ if (val > 0x7FFFFFFF || val < -(int64_t)0x80000000) {
f->store_32(VARIANT_INT64);
f->store_64(val);
@@ -1718,7 +1718,7 @@ void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const
CharString utf8 = p_string.utf8();
if (p_bit_on_len) {
- f->store_32(utf8.length() + 1 | 0x80000000);
+ f->store_32((utf8.length() + 1) | 0x80000000);
} else {
f->store_32(utf8.length() + 1);
}
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index 021f7f6a2f..513252055f 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -31,9 +31,9 @@
#ifndef RESOURCE_FORMAT_BINARY_H
#define RESOURCE_FORMAT_BINARY_H
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
+#include "core/io/resource_loader.h"
+#include "core/io/resource_saver.h"
+#include "core/os/file_access.h"
class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
@@ -119,7 +119,6 @@ class ResourceFormatSaverBinaryInstance {
bool skip_editor;
bool big_endian;
bool takeover_paths;
- int bin_meta_idx;
FileAccess *f;
String magic;
Set<RES> resource_set;
diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp
index cfe6655504..ffea43b6bf 100644
--- a/core/io/resource_import.cpp
+++ b/core/io/resource_import.cpp
@@ -30,8 +30,8 @@
#include "resource_import.h"
-#include "os/os.h"
-#include "variant_parser.h"
+#include "core/os/os.h"
+#include "core/variant_parser.h"
Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid) const {
diff --git a/core/io/resource_import.h b/core/io/resource_import.h
index 80e0743eda..53718bd789 100644
--- a/core/io/resource_import.h
+++ b/core/io/resource_import.h
@@ -31,7 +31,8 @@
#ifndef RESOURCE_IMPORT_H
#define RESOURCE_IMPORT_H
-#include "io/resource_loader.h"
+#include "core/io/resource_loader.h"
+
class ResourceImporter;
class ResourceFormatImporter : public ResourceFormatLoader {
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 66dc9730c5..71b01aa94a 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -29,14 +29,16 @@
/*************************************************************************/
#include "resource_loader.h"
-#include "io/resource_import.h"
-#include "os/file_access.h"
-#include "os/os.h"
-#include "path_remap.h"
-#include "print_string.h"
-#include "project_settings.h"
-#include "translation.h"
-#include "variant_parser.h"
+
+#include "core/io/resource_import.h"
+#include "core/os/file_access.h"
+#include "core/os/os.h"
+#include "core/path_remap.h"
+#include "core/print_string.h"
+#include "core/project_settings.h"
+#include "core/translation.h"
+#include "core/variant_parser.h"
+
ResourceFormatLoader *ResourceLoader::loader[MAX_LOADERS];
int ResourceLoader::loader_count = 0;
@@ -257,6 +259,10 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
}
#endif
+ if (_loaded_callback) {
+ _loaded_callback(res, p_path);
+ }
+
return res;
}
@@ -633,6 +639,12 @@ void ResourceLoader::clear_path_remaps() {
path_remaps.clear();
}
+void ResourceLoader::set_load_callback(ResourceLoadedCallback p_callback) {
+ _loaded_callback = p_callback;
+}
+
+ResourceLoadedCallback ResourceLoader::_loaded_callback = NULL;
+
ResourceLoadErrorNotify ResourceLoader::err_notify = NULL;
void *ResourceLoader::err_notify_ud = NULL;
@@ -645,3 +657,5 @@ bool ResourceLoader::timestamp_on_load = false;
SelfList<Resource>::List ResourceLoader::remapped_list;
HashMap<String, Vector<String> > ResourceLoader::translation_remaps;
HashMap<String, String> ResourceLoader::path_remaps;
+
+ResourceLoaderImport ResourceLoader::import = NULL;
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index f78464ef0c..7ade4a2dfc 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -31,7 +31,7 @@
#ifndef RESOURCE_LOADER_H
#define RESOURCE_LOADER_H
-#include "resource.h"
+#include "core/resource.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
@@ -77,6 +77,9 @@ public:
typedef void (*ResourceLoadErrorNotify)(void *p_ud, const String &p_text);
typedef void (*DependencyErrorNotify)(void *p_ud, const String &p_loading, const String &p_which, const String &p_type);
+typedef Error (*ResourceLoaderImport)(const String &p_path);
+typedef void (*ResourceLoadedCallback)(RES p_resource, const String &p_path);
+
class ResourceLoader {
enum {
@@ -104,6 +107,8 @@ class ResourceLoader {
//internal load function
static RES _load(const String &p_path, const String &p_original_path, const String &p_type_hint, bool p_no_cache, Error *r_error);
+ static ResourceLoadedCallback _loaded_callback;
+
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);
@@ -147,6 +152,9 @@ public:
static void reload_translation_remaps();
static void load_translation_remaps();
static void clear_translation_remaps();
+
+ static void set_load_callback(ResourceLoadedCallback p_callback);
+ static ResourceLoaderImport import;
};
#endif
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 3dcd94880a..097e81e308 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -29,10 +29,11 @@
/*************************************************************************/
#include "resource_saver.h"
-#include "os/file_access.h"
-#include "project_settings.h"
-#include "resource_loader.h"
-#include "script_language.h"
+
+#include "core/io/resource_loader.h"
+#include "core/os/file_access.h"
+#include "core/project_settings.h"
+#include "core/script_language.h"
ResourceFormatSaver *ResourceSaver::saver[MAX_SAVERS];
@@ -89,7 +90,7 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t
rwcopy->set_path(old_path);
if (save_callback && p_path.begins_with("res://"))
- save_callback(p_path);
+ save_callback(p_resource, p_path);
return OK;
} else {
diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h
index 396f37d414..6134d9db57 100644
--- a/core/io/resource_saver.h
+++ b/core/io/resource_saver.h
@@ -31,7 +31,7 @@
#ifndef RESOURCE_SAVER_H
#define RESOURCE_SAVER_H
-#include "resource.h"
+#include "core/resource.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
@@ -46,7 +46,7 @@ public:
virtual ~ResourceFormatSaver() {}
};
-typedef void (*ResourceSavedCallback)(const String &p_path);
+typedef void (*ResourceSavedCallback)(Ref<Resource> p_resource, const String &p_path);
class ResourceSaver {
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index 3e0ee088c2..3f608b720c 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "stream_peer.h"
-#include "io/marshalls.h"
+
+#include "core/io/marshalls.h"
Error StreamPeer::_put_data(const PoolVector<uint8_t> &p_data) {
@@ -208,6 +209,12 @@ void StreamPeer::put_double(double p_val) {
}
put_data(buf, 8);
}
+void StreamPeer::put_string(const String &p_string) {
+
+ CharString cs = p_string.ascii();
+ put_u32(cs.length());
+ put_data((const uint8_t *)cs.get_data(), cs.length());
+}
void StreamPeer::put_utf8_string(const String &p_string) {
CharString cs = p_string.utf8();
@@ -324,6 +331,8 @@ double StreamPeer::get_double() {
}
String StreamPeer::get_string(int p_bytes) {
+ if (p_bytes < 0)
+ p_bytes = get_u32();
ERR_FAIL_COND_V(p_bytes < 0, String());
Vector<char> buf;
@@ -336,6 +345,8 @@ String StreamPeer::get_string(int p_bytes) {
}
String StreamPeer::get_utf8_string(int p_bytes) {
+ if (p_bytes < 0)
+ p_bytes = get_u32();
ERR_FAIL_COND_V(p_bytes < 0, String());
Vector<uint8_t> buf;
@@ -385,6 +396,7 @@ void StreamPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("put_u64", "value"), &StreamPeer::put_u64);
ClassDB::bind_method(D_METHOD("put_float", "value"), &StreamPeer::put_float);
ClassDB::bind_method(D_METHOD("put_double", "value"), &StreamPeer::put_double);
+ ClassDB::bind_method(D_METHOD("put_string", "value"), &StreamPeer::put_string);
ClassDB::bind_method(D_METHOD("put_utf8_string", "value"), &StreamPeer::put_utf8_string);
ClassDB::bind_method(D_METHOD("put_var", "value"), &StreamPeer::put_var);
@@ -398,8 +410,8 @@ void StreamPeer::_bind_methods() {
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_string", "bytes"), &StreamPeer::get_string, DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("get_utf8_string", "bytes"), &StreamPeer::get_utf8_string, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("get_var"), &StreamPeer::get_var);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "big_endian"), "set_big_endian", "is_big_endian_enabled");
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index 605b0a7980..f189960cbd 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -31,7 +31,7 @@
#ifndef STREAM_PEER_H
#define STREAM_PEER_H
-#include "reference.h"
+#include "core/reference.h"
class StreamPeer : public Reference {
GDCLASS(StreamPeer, Reference);
@@ -71,6 +71,7 @@ public:
void put_u64(uint64_t p_val);
void put_float(float p_val);
void put_double(double p_val);
+ void put_string(const String &p_string);
void put_utf8_string(const String &p_string);
void put_var(const Variant &p_variant);
@@ -84,8 +85,8 @@ public:
int64_t get_64();
float get_float();
double get_double();
- String get_string(int p_bytes);
- String get_utf8_string(int p_bytes);
+ String get_string(int p_bytes = -1);
+ String get_utf8_string(int p_bytes = -1);
Variant get_var();
StreamPeer() { big_endian = false; }
diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp
index 25adb6a6ee..138f91301e 100644
--- a/core/io/stream_peer_ssl.cpp
+++ b/core/io/stream_peer_ssl.cpp
@@ -29,8 +29,11 @@
/*************************************************************************/
#include "stream_peer_ssl.h"
-#include "os/file_access.h"
-#include "project_settings.h"
+
+#include "core/io/certs_compressed.gen.h"
+#include "core/io/compression.h"
+#include "core/os/file_access.h"
+#include "core/project_settings.h"
StreamPeerSSL *(*StreamPeerSSL::_create)() = NULL;
@@ -41,13 +44,20 @@ StreamPeerSSL *StreamPeerSSL::create() {
StreamPeerSSL::LoadCertsFromMemory StreamPeerSSL::load_certs_func = NULL;
bool StreamPeerSSL::available = false;
-bool StreamPeerSSL::initialize_certs = true;
void StreamPeerSSL::load_certs_from_memory(const PoolByteArray &p_memory) {
if (load_certs_func)
load_certs_func(p_memory);
}
+void StreamPeerSSL::load_certs_from_file(String p_path) {
+ if (p_path != "") {
+ PoolByteArray certs = get_cert_file_as_array(p_path);
+ if (certs.size() > 0)
+ load_certs_func(certs);
+ }
+}
+
bool StreamPeerSSL::is_available() {
return available;
}
@@ -60,6 +70,25 @@ bool StreamPeerSSL::is_blocking_handshake_enabled() const {
return blocking_handshake;
}
+PoolByteArray StreamPeerSSL::get_cert_file_as_array(String p_path) {
+
+ PoolByteArray out;
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
+ if (f) {
+ int flen = f->get_len();
+ out.resize(flen + 1);
+ PoolByteArray::Write w = out.write();
+ f->get_buffer(w.ptr(), flen);
+ w[flen] = 0; // Make sure it ends with string terminator
+ memdelete(f);
+#ifdef DEBUG_ENABLED
+ print_verbose(vformat("Loaded certs from '%s'.", p_path));
+#endif
+ }
+
+ return out;
+}
+
PoolByteArray StreamPeerSSL::get_project_cert_array() {
PoolByteArray out;
@@ -67,24 +96,21 @@ PoolByteArray StreamPeerSSL::get_project_cert_array() {
ProjectSettings::get_singleton()->set_custom_property_info("network/ssl/certificates", PropertyInfo(Variant::STRING, "network/ssl/certificates", PROPERTY_HINT_FILE, "*.crt"));
if (certs_path != "") {
-
- FileAccess *f = FileAccess::open(certs_path, FileAccess::READ);
- if (f) {
- int flen = f->get_len();
- out.resize(flen + 1);
- {
- PoolByteArray::Write w = out.write();
- f->get_buffer(w.ptr(), flen);
- w[flen] = 0; //end f string
- }
-
- memdelete(f);
-
+ // Use certs defined in project settings.
+ return get_cert_file_as_array(certs_path);
+ }
+#ifdef BUILTIN_CERTS_ENABLED
+ else {
+ // Use builtin certs only if user did not override it in project settings.
+ out.resize(_certs_uncompressed_size + 1);
+ PoolByteArray::Write w = out.write();
+ Compression::decompress(w.ptr(), _certs_uncompressed_size, _certs_compressed, _certs_compressed_size, Compression::MODE_DEFLATE);
+ w[_certs_uncompressed_size] = 0; // Make sure it ends with string terminator
#ifdef DEBUG_ENABLED
- print_verbose(vformat("Loaded certs from '%s'.", certs_path));
+ print_verbose("Loaded builtin certs");
#endif
- }
}
+#endif
return out;
}
@@ -102,6 +128,7 @@ void StreamPeerSSL::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blocking_handshake"), "set_blocking_handshake_enabled", "is_blocking_handshake_enabled");
BIND_ENUM_CONSTANT(STATUS_DISCONNECTED);
+ BIND_ENUM_CONSTANT(STATUS_HANDSHAKING);
BIND_ENUM_CONSTANT(STATUS_CONNECTED);
BIND_ENUM_CONSTANT(STATUS_ERROR);
BIND_ENUM_CONSTANT(STATUS_ERROR_HOSTNAME_MISMATCH);
diff --git a/core/io/stream_peer_ssl.h b/core/io/stream_peer_ssl.h
index 870704e875..8ce36d7e7d 100644
--- a/core/io/stream_peer_ssl.h
+++ b/core/io/stream_peer_ssl.h
@@ -31,7 +31,7 @@
#ifndef STREAM_PEER_SSL_H
#define STREAM_PEER_SSL_H
-#include "io/stream_peer.h"
+#include "core/io/stream_peer.h"
class StreamPeerSSL : public StreamPeer {
GDCLASS(StreamPeerSSL, StreamPeer);
@@ -46,9 +46,6 @@ protected:
static LoadCertsFromMemory load_certs_func;
static bool available;
- friend class Main;
- static bool initialize_certs;
-
bool blocking_handshake;
public:
@@ -72,7 +69,9 @@ public:
static StreamPeerSSL *create();
+ static PoolByteArray get_cert_file_as_array(String p_path);
static PoolByteArray get_project_cert_array();
+ static void load_certs_from_file(String p_path);
static void load_certs_from_memory(const PoolByteArray &p_memory);
static bool is_available();
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index 54ebb3ae0d..28561e8cbc 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -30,7 +30,294 @@
#include "stream_peer_tcp.h"
-StreamPeerTCP *(*StreamPeerTCP::_create)() = NULL;
+Error StreamPeerTCP::_poll_connection() {
+
+ ERR_FAIL_COND_V(status != STATUS_CONNECTING || !_sock.is_valid() || !_sock->is_open(), FAILED);
+
+ Error err = _sock->connect_to_host(peer_host, peer_port);
+
+ if (err == OK) {
+ status = STATUS_CONNECTED;
+ return OK;
+ } else if (err == ERR_BUSY) {
+ // Still trying to connect
+ return OK;
+ }
+
+ disconnect_from_host();
+ status = STATUS_ERROR;
+ return ERR_CONNECTION_ERROR;
+}
+
+void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port) {
+
+ _sock = p_sock;
+ _sock->set_blocking_enabled(false);
+
+ status = STATUS_CONNECTING;
+
+ peer_host = p_host;
+ peer_port = p_port;
+}
+
+Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port) {
+
+ ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
+ ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER);
+
+ Error err;
+ IP::Type ip_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+
+ err = _sock->open(NetSocket::TYPE_TCP, ip_type);
+ ERR_FAIL_COND_V(err != OK, FAILED);
+
+ _sock->set_blocking_enabled(false);
+
+ err = _sock->connect_to_host(p_host, p_port);
+
+ if (err == OK) {
+ status = STATUS_CONNECTED;
+ } else if (err == ERR_BUSY) {
+ status = STATUS_CONNECTING;
+ } else {
+ ERR_PRINT("Connection to remote host failed!");
+ disconnect_from_host();
+ return FAILED;
+ }
+
+ peer_host = p_host;
+ peer_port = p_port;
+
+ return OK;
+}
+
+Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) {
+
+ ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
+
+ if (status == STATUS_NONE || status == STATUS_ERROR) {
+
+ return FAILED;
+ }
+
+ if (status != STATUS_CONNECTED) {
+
+ if (_poll_connection() != OK) {
+
+ return FAILED;
+ }
+
+ if (status != STATUS_CONNECTED) {
+ r_sent = 0;
+ return OK;
+ }
+ }
+
+ if (!_sock->is_open())
+ return FAILED;
+
+ Error err;
+ int data_to_send = p_bytes;
+ const uint8_t *offset = p_data;
+ int total_sent = 0;
+
+ while (data_to_send) {
+
+ int sent_amount = 0;
+ err = _sock->send(offset, data_to_send, sent_amount);
+
+ if (err != OK) {
+
+ if (err != ERR_BUSY) {
+ disconnect_from_host();
+ return FAILED;
+ }
+
+ if (!p_block) {
+ r_sent = total_sent;
+ return OK;
+ }
+
+ // Block and wait for the socket to accept more data
+ err = _sock->poll(NetSocket::POLL_TYPE_OUT, -1);
+ if (err != OK) {
+ disconnect_from_host();
+ return FAILED;
+ }
+ } else {
+
+ data_to_send -= sent_amount;
+ offset += sent_amount;
+ total_sent += sent_amount;
+ }
+ }
+
+ r_sent = total_sent;
+
+ return OK;
+}
+
+Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) {
+
+ if (!is_connected_to_host()) {
+
+ return FAILED;
+ }
+
+ if (status == STATUS_CONNECTING) {
+
+ if (_poll_connection() != OK) {
+
+ return FAILED;
+ }
+
+ if (status != STATUS_CONNECTED) {
+ r_received = 0;
+ return OK;
+ }
+ }
+
+ Error err;
+ int to_read = p_bytes;
+ int total_read = 0;
+ r_received = 0;
+
+ while (to_read) {
+
+ int read = 0;
+ err = _sock->recv(p_buffer + total_read, to_read, read);
+
+ if (err != OK) {
+
+ if (err != ERR_BUSY) {
+ disconnect_from_host();
+ return FAILED;
+ }
+
+ if (!p_block) {
+ r_received = total_read;
+ return OK;
+ }
+
+ err = _sock->poll(NetSocket::POLL_TYPE_IN, -1);
+
+ if (err != OK) {
+ disconnect_from_host();
+ return FAILED;
+ }
+
+ } else if (read == 0) {
+
+ disconnect_from_host();
+ r_received = total_read;
+ return ERR_FILE_EOF;
+
+ } else {
+
+ to_read -= read;
+ total_read += read;
+ }
+ }
+
+ r_received = total_read;
+
+ return OK;
+}
+
+void StreamPeerTCP::set_no_delay(bool p_enabled) {
+
+ ERR_FAIL_COND(!is_connected_to_host());
+ _sock->set_tcp_no_delay_enabled(p_enabled);
+}
+
+bool StreamPeerTCP::is_connected_to_host() const {
+
+ if (status == STATUS_NONE || status == STATUS_ERROR) {
+
+ return false;
+ }
+
+ if (status != STATUS_CONNECTED) {
+ return true;
+ }
+
+ return _sock.is_valid() && _sock->is_open();
+}
+
+StreamPeerTCP::Status StreamPeerTCP::get_status() {
+
+ if (status == STATUS_CONNECTING) {
+ _poll_connection();
+ } else if (status == STATUS_CONNECTED) {
+ Error err;
+ err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
+ if (err == OK) {
+ // FIN received
+ if (_sock->get_available_bytes() == 0) {
+ disconnect_from_host();
+ return status;
+ }
+ }
+ // Also poll write
+ err = _sock->poll(NetSocket::POLL_TYPE_IN_OUT, 0);
+ if (err != OK && err != ERR_BUSY) {
+ // Got an error
+ disconnect_from_host();
+ status = STATUS_ERROR;
+ }
+ }
+
+ return status;
+}
+
+void StreamPeerTCP::disconnect_from_host() {
+
+ if (_sock.is_valid() && _sock->is_open())
+ _sock->close();
+
+ status = STATUS_NONE;
+ peer_host = IP_Address();
+ peer_port = 0;
+}
+
+Error StreamPeerTCP::put_data(const uint8_t *p_data, int p_bytes) {
+
+ int total;
+ return write(p_data, p_bytes, total, true);
+}
+
+Error StreamPeerTCP::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
+
+ return write(p_data, p_bytes, r_sent, false);
+}
+
+Error StreamPeerTCP::get_data(uint8_t *p_buffer, int p_bytes) {
+
+ int total;
+ return read(p_buffer, p_bytes, total, true);
+}
+
+Error StreamPeerTCP::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
+
+ return read(p_buffer, p_bytes, r_received, false);
+}
+
+int StreamPeerTCP::get_available_bytes() const {
+
+ ERR_FAIL_COND_V(!_sock.is_valid(), -1);
+ return _sock->get_available_bytes();
+}
+
+IP_Address StreamPeerTCP::get_connected_host() const {
+
+ return peer_host;
+}
+
+uint16_t StreamPeerTCP::get_connected_port() const {
+
+ return peer_port;
+}
Error StreamPeerTCP::_connect(const String &p_address, int p_port) {
@@ -62,23 +349,15 @@ void StreamPeerTCP::_bind_methods() {
BIND_ENUM_CONSTANT(STATUS_ERROR);
}
-Ref<StreamPeerTCP> StreamPeerTCP::create_ref() {
+StreamPeerTCP::StreamPeerTCP() {
- if (!_create)
- return Ref<StreamPeerTCP>();
- return Ref<StreamPeerTCP>(_create());
+ _sock = Ref<NetSocket>(NetSocket::create());
+ status = STATUS_NONE;
+ peer_host = IP_Address();
+ peer_port = 0;
}
-StreamPeerTCP *StreamPeerTCP::create() {
+StreamPeerTCP::~StreamPeerTCP() {
- if (!_create)
- return NULL;
- return _create();
+ disconnect_from_host();
}
-
-StreamPeerTCP::StreamPeerTCP() {
-}
-
-StreamPeerTCP::~StreamPeerTCP(){
-
-};
diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h
index 8a16d820f2..de364915cd 100644
--- a/core/io/stream_peer_tcp.h
+++ b/core/io/stream_peer_tcp.h
@@ -31,10 +31,10 @@
#ifndef STREAM_PEER_TCP_H
#define STREAM_PEER_TCP_H
-#include "stream_peer.h"
-
-#include "io/ip.h"
-#include "ip_address.h"
+#include "core/io/ip.h"
+#include "core/io/ip_address.h"
+#include "core/io/net_socket.h"
+#include "core/io/stream_peer.h"
class StreamPeerTCP : public StreamPeer {
@@ -51,24 +51,37 @@ public:
};
protected:
- virtual Error _connect(const String &p_address, int p_port);
- static StreamPeerTCP *(*_create)();
+ Ref<NetSocket> _sock;
+ Status status;
+ IP_Address peer_host;
+ uint16_t peer_port;
+
+ Error _connect(const String &p_address, int p_port);
+ Error _poll_connection();
+ Error write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block);
+ Error read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block);
+
static void _bind_methods();
public:
- virtual Error connect_to_host(const IP_Address &p_host, uint16_t p_port) = 0;
+ void accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port);
+
+ Error connect_to_host(const IP_Address &p_host, uint16_t p_port);
+ bool is_connected_to_host() const;
+ IP_Address get_connected_host() const;
+ uint16_t get_connected_port() const;
+ void disconnect_from_host();
- //read/write from streampeer
+ int get_available_bytes() const;
+ Status get_status();
- virtual bool is_connected_to_host() const = 0;
- virtual Status get_status() const = 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_no_delay(bool p_enabled) = 0;
+ void set_no_delay(bool p_enabled);
- static Ref<StreamPeerTCP> create_ref();
- static StreamPeerTCP *create();
+ // Read/Write from StreamPeer
+ Error put_data(const uint8_t *p_data, int p_bytes);
+ Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);
+ Error get_data(uint8_t *p_buffer, int p_bytes);
+ Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received);
StreamPeerTCP();
~StreamPeerTCP();
diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp
index 5916d58390..b8194cb17f 100644
--- a/core/io/tcp_server.cpp
+++ b/core/io/tcp_server.cpp
@@ -30,29 +30,98 @@
#include "tcp_server.h"
-TCP_Server *(*TCP_Server::_create)() = NULL;
+void TCP_Server::_bind_methods() {
+
+ 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);
+}
+
+Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
+
+ ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
+ ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
+
+ Error err;
+ IP::Type ip_type = IP::TYPE_ANY;
+
+ // If the bind address is valid use its type as the socket type
+ if (p_bind_address.is_valid())
+ ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+
+ err = _sock->open(NetSocket::TYPE_TCP, ip_type);
+
+ ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
+
+ _sock->set_blocking_enabled(false);
+ _sock->set_reuse_address_enabled(true);
+
+ err = _sock->bind(p_bind_address, p_port);
+
+ if (err != OK) {
+
+ _sock->close();
+ return ERR_ALREADY_IN_USE;
+ }
-Ref<TCP_Server> TCP_Server::create_ref() {
+ err = _sock->listen(MAX_PENDING_CONNECTIONS);
- if (!_create)
- return NULL;
- return Ref<TCP_Server>(_create());
+ if (err != OK) {
+ _sock->close();
+ return FAILED;
+ }
+ return OK;
}
-TCP_Server *TCP_Server::create() {
+bool TCP_Server::is_connection_available() const {
- if (!_create)
- return NULL;
- return _create();
+ ERR_FAIL_COND_V(!_sock.is_valid(), false);
+
+ if (!_sock->is_open())
+ return false;
+
+ Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
+ if (err != OK) {
+ return false;
+ }
+
+ return true;
}
-void TCP_Server::_bind_methods() {
+Ref<StreamPeerTCP> TCP_Server::take_connection() {
- 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);
+ Ref<StreamPeerTCP> conn;
+ if (!is_connection_available()) {
+ return conn;
+ }
+
+ Ref<NetSocket> ns;
+ IP_Address ip;
+ uint16_t port = 0;
+ ns = _sock->accept(ip, port);
+ if (!ns.is_valid())
+ return conn;
+
+ conn = Ref<StreamPeerTCP>(memnew(StreamPeerTCP));
+ conn->accept_socket(ns, ip, port);
+ return conn;
+}
+
+void TCP_Server::stop() {
+
+ if (_sock.is_valid()) {
+ _sock->close();
+ }
}
TCP_Server::TCP_Server() {
+
+ _sock = Ref<NetSocket>(NetSocket::create());
+}
+
+TCP_Server::~TCP_Server() {
+
+ stop();
}
diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h
index a250e8b249..4c89197d9a 100644
--- a/core/io/tcp_server.h
+++ b/core/io/tcp_server.h
@@ -31,31 +31,32 @@
#ifndef TCP_SERVER_H
#define TCP_SERVER_H
-#include "io/ip.h"
-#include "io/stream_peer.h"
-#include "stream_peer_tcp.h"
+#include "core/io/ip.h"
+#include "core/io/net_socket.h"
+#include "core/io/stream_peer.h"
+#include "core/io/stream_peer_tcp.h"
class TCP_Server : public Reference {
GDCLASS(TCP_Server, Reference);
protected:
- static TCP_Server *(*_create)();
+ enum {
+ MAX_PENDING_CONNECTIONS = 8
+ };
- //bind helper
+ Ref<NetSocket> _sock;
static void _bind_methods();
public:
- 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;
+ Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*"));
+ bool is_connection_available() const;
+ Ref<StreamPeerTCP> take_connection();
- virtual void stop() = 0; //stop listening
-
- static Ref<TCP_Server> create_ref();
- static TCP_Server *create();
+ void stop(); // Stop listening
TCP_Server();
+ ~TCP_Server();
};
#endif // TCP_SERVER_H
diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp
index 85c1fc5ddf..830c2b6694 100644
--- a/core/io/translation_loader_po.cpp
+++ b/core/io/translation_loader_po.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "translation_loader_po.h"
-#include "os/file_access.h"
-#include "translation.h"
+
+#include "core/os/file_access.h"
+#include "core/translation.h"
RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const String &p_path) {
diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h
index 33cf9bd8b4..670a9fdd7e 100644
--- a/core/io/translation_loader_po.h
+++ b/core/io/translation_loader_po.h
@@ -31,9 +31,10 @@
#ifndef TRANSLATION_LOADER_PO_H
#define TRANSLATION_LOADER_PO_H
-#include "io/resource_loader.h"
-#include "os/file_access.h"
-#include "translation.h"
+#include "core/io/resource_loader.h"
+#include "core/os/file_access.h"
+#include "core/translation.h"
+
class TranslationLoaderPO : public ResourceFormatLoader {
public:
static RES load_translation(FileAccess *f, Error *r_error, const String &p_path = String());
diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp
index 33c9b56d5a..8c0cbd6e55 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -29,7 +29,9 @@
/*************************************************************************/
#include "xml_parser.h"
-#include "print_string.h"
+
+#include "core/print_string.h"
+
//#define DEBUG_XML
VARIANT_ENUM_CAST(XMLParser::NodeType);
diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h
index 297b57ffdc..bbc7671a0e 100644
--- a/core/io/xml_parser.h
+++ b/core/io/xml_parser.h
@@ -31,10 +31,10 @@
#ifndef XML_PARSER_H
#define XML_PARSER_H
-#include "os/file_access.h"
-#include "reference.h"
-#include "ustring.h"
-#include "vector.h"
+#include "core/os/file_access.h"
+#include "core/reference.h"
+#include "core/ustring.h"
+#include "core/vector.h"
/*
Based on irrXML (see their zlib license). Added mainly for compatibility with their Collada loader.
diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp
new file mode 100644
index 0000000000..b7f841b66f
--- /dev/null
+++ b/core/io/zip_io.cpp
@@ -0,0 +1,137 @@
+/*************************************************************************/
+/* zip_io.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* 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 "zip_io.h"
+
+#include "core/os/copymem.h"
+
+void *zipio_open(void *data, const char *p_fname, int mode) {
+
+ FileAccess *&f = *(FileAccess **)data;
+
+ String fname;
+ fname.parse_utf8(p_fname);
+
+ if (mode & ZLIB_FILEFUNC_MODE_WRITE) {
+ f = FileAccess::open(fname, FileAccess::WRITE);
+ } else {
+
+ f = FileAccess::open(fname, FileAccess::READ);
+ }
+
+ if (!f)
+ return NULL;
+
+ return data;
+}
+
+uLong zipio_read(void *data, void *fdata, void *buf, uLong size) {
+
+ FileAccess *f = *(FileAccess **)data;
+ return f->get_buffer((uint8_t *)buf, size);
+}
+
+uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) {
+
+ FileAccess *f = *(FileAccess **)opaque;
+ f->store_buffer((uint8_t *)buf, size);
+ return size;
+}
+
+long zipio_tell(voidpf opaque, voidpf stream) {
+
+ FileAccess *f = *(FileAccess **)opaque;
+ return f->get_position();
+}
+
+long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
+
+ FileAccess *f = *(FileAccess **)opaque;
+
+ int pos = offset;
+ switch (origin) {
+
+ case ZLIB_FILEFUNC_SEEK_CUR:
+ pos = f->get_position() + offset;
+ break;
+ case ZLIB_FILEFUNC_SEEK_END:
+ pos = f->get_len() + offset;
+ break;
+ default:
+ break;
+ };
+
+ f->seek(pos);
+ return 0;
+}
+
+int zipio_close(voidpf opaque, voidpf stream) {
+
+ FileAccess *&f = *(FileAccess **)opaque;
+ if (f) {
+ f->close();
+ f = NULL;
+ }
+ return 0;
+}
+
+int zipio_testerror(voidpf opaque, voidpf stream) {
+
+ FileAccess *f = *(FileAccess **)opaque;
+ return (f && f->get_error() != OK) ? 1 : 0;
+}
+
+voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) {
+
+ voidpf ptr = memalloc(items * size);
+ zeromem(ptr, items * size);
+ return ptr;
+}
+
+void zipio_free(voidpf opaque, voidpf address) {
+
+ memfree(address);
+}
+
+zlib_filefunc_def zipio_create_io_from_file(FileAccess **p_file) {
+
+ zlib_filefunc_def io;
+ io.opaque = p_file;
+ io.zopen_file = zipio_open;
+ io.zread_file = zipio_read;
+ io.zwrite_file = zipio_write;
+ io.ztell_file = zipio_tell;
+ io.zseek_file = zipio_seek;
+ io.zclose_file = zipio_close;
+ io.zerror_file = zipio_testerror;
+ io.alloc_mem = zipio_alloc;
+ io.free_mem = zipio_free;
+ return io;
+}
diff --git a/core/io/zip_io.h b/core/io/zip_io.h
index 3a7fdb0302..bba7d67332 100644
--- a/core/io/zip_io.h
+++ b/core/io/zip_io.h
@@ -31,114 +31,28 @@
#ifndef ZIP_IO_H
#define ZIP_IO_H
-#include "os/copymem.h"
-#include "os/file_access.h"
+#include "core/os/file_access.h"
+// Not direclty used in this header, but assumed available in downstream users
+// like platform/*/export/export.cpp. Could be fixed, but probably better to have
+// thirdparty includes in as little headers as possible.
#include "thirdparty/minizip/unzip.h"
#include "thirdparty/minizip/zip.h"
-static void *zipio_open(void *data, const char *p_fname, int mode) {
+void *zipio_open(void *data, const char *p_fname, int mode);
+uLong zipio_read(void *data, void *fdata, void *buf, uLong size);
+uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size);
- FileAccess *&f = *(FileAccess **)data;
+long zipio_tell(voidpf opaque, voidpf stream);
+long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin);
- String fname;
- fname.parse_utf8(p_fname);
+int zipio_close(voidpf opaque, voidpf stream);
- if (mode & ZLIB_FILEFUNC_MODE_WRITE) {
- f = FileAccess::open(fname, FileAccess::WRITE);
- } else {
+int zipio_testerror(voidpf opaque, voidpf stream);
- f = FileAccess::open(fname, FileAccess::READ);
- }
+voidpf zipio_alloc(voidpf opaque, uInt items, uInt size);
+void zipio_free(voidpf opaque, voidpf address);
- if (!f)
- return NULL;
-
- return data;
-};
-
-static uLong zipio_read(void *data, void *fdata, void *buf, uLong size) {
-
- FileAccess *f = *(FileAccess **)data;
- return f->get_buffer((uint8_t *)buf, size);
-};
-
-static uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) {
-
- FileAccess *f = *(FileAccess **)opaque;
- f->store_buffer((uint8_t *)buf, size);
- return size;
-};
-
-static long zipio_tell(voidpf opaque, voidpf stream) {
-
- FileAccess *f = *(FileAccess **)opaque;
- return f->get_position();
-};
-
-static long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
-
- FileAccess *f = *(FileAccess **)opaque;
-
- int pos = offset;
- switch (origin) {
-
- case ZLIB_FILEFUNC_SEEK_CUR:
- pos = f->get_position() + offset;
- break;
- case ZLIB_FILEFUNC_SEEK_END:
- pos = f->get_len() + offset;
- break;
- default:
- break;
- };
-
- f->seek(pos);
- return 0;
-};
-
-static int zipio_close(voidpf opaque, voidpf stream) {
-
- FileAccess *&f = *(FileAccess **)opaque;
- if (f) {
- f->close();
- f = NULL;
- }
- return 0;
-};
-
-static int zipio_testerror(voidpf opaque, voidpf stream) {
-
- FileAccess *f = *(FileAccess **)opaque;
- return (f && f->get_error() != OK) ? 1 : 0;
-};
-
-static voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) {
-
- voidpf ptr = memalloc(items * size);
- zeromem(ptr, items * size);
- return ptr;
-}
-
-static void zipio_free(voidpf opaque, voidpf address) {
-
- memfree(address);
-}
-
-static zlib_filefunc_def zipio_create_io_from_file(FileAccess **p_file) {
-
- zlib_filefunc_def io;
- io.opaque = p_file;
- io.zopen_file = zipio_open;
- io.zread_file = zipio_read;
- io.zwrite_file = zipio_write;
- io.ztell_file = zipio_tell;
- io.zseek_file = zipio_seek;
- io.zclose_file = zipio_close;
- io.zerror_file = zipio_testerror;
- io.alloc_mem = zipio_alloc;
- io.free_mem = zipio_free;
- return io;
-}
+zlib_filefunc_def zipio_create_io_from_file(FileAccess **p_file);
#endif // ZIP_IO_H
diff --git a/core/list.h b/core/list.h
index f977df4634..281f253a59 100644
--- a/core/list.h
+++ b/core/list.h
@@ -31,8 +31,8 @@
#ifndef GLOBALS_LIST_H
#define GLOBALS_LIST_H
-#include "os/memory.h"
-#include "sort.h"
+#include "core/os/memory.h"
+#include "core/sort.h"
/**
* Generic Templatized Linked List Implementation.
diff --git a/core/map.h b/core/map.h
index 700d4b8693..cab8965bb3 100644
--- a/core/map.h
+++ b/core/map.h
@@ -31,7 +31,7 @@
#ifndef MAP_H
#define MAP_H
-#include "set.h"
+#include "core/set.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/core/math/SCsub b/core/math/SCsub
index 4efc902717..1c5f954470 100644
--- a/core/math/SCsub
+++ b/core/math/SCsub
@@ -3,5 +3,3 @@
Import('env')
env.add_source_files(env.core_sources, "*.cpp")
-
-Export('env')
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 021391da83..451c45cade 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -29,9 +29,10 @@
/*************************************************************************/
#include "a_star.h"
-#include "geometry.h"
+
+#include "core/math/geometry.h"
+#include "core/script_language.h"
#include "scene/scene_string_names.h"
-#include "script_language.h"
int AStar::get_available_point_id() const {
@@ -249,14 +250,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
n->distance = _compute_cost(begin_point->id, n->id) * n->weight_scale;
n->last_pass = pass;
open_list.add(&n->list);
-
- if (end_point == n) {
- found_route = true;
- break;
- }
}
- while (!found_route) {
+ while (true) {
if (open_list.first() == NULL) {
// No path found
@@ -276,13 +272,16 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
cost += _estimate_cost(p->id, end_point->id);
if (cost < least_cost) {
-
least_cost_point = E;
least_cost = cost;
}
}
Point *p = least_cost_point->self();
+ if (p == end_point) {
+ found_route = true;
+ break;
+ }
for (Set<Point *>::Element *E = p->neighbours.front(); E; E = E->next()) {
@@ -294,7 +293,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
// Already visited, is this cheaper?
if (e->distance > distance) {
-
e->prev_point = p;
e->distance = distance;
}
@@ -305,18 +303,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
e->distance = distance;
e->last_pass = pass; // Mark as used
open_list.add(&e->list);
-
- if (e == end_point) {
- // End reached; stop algorithm
- found_route = true;
- break;
- }
}
}
- if (found_route)
- break;
-
open_list.remove(least_cost_point);
}
diff --git a/core/math/a_star.h b/core/math/a_star.h
index 8c1b5f64cb..d2ef765006 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -31,8 +31,9 @@
#ifndef ASTAR_H
#define ASTAR_H
-#include "reference.h"
-#include "self_list.h"
+#include "core/reference.h"
+#include "core/self_list.h"
+
/**
A* pathfinding algorithm
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp
index e2e71dda92..d0cb2b5195 100644
--- a/core/math/aabb.cpp
+++ b/core/math/aabb.cpp
@@ -30,7 +30,7 @@
#include "aabb.h"
-#include "print_string.h"
+#include "core/print_string.h"
real_t AABB::get_area() const {
diff --git a/core/math/aabb.h b/core/math/aabb.h
index cdb8eb48a3..0b03b7d314 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -31,9 +31,9 @@
#ifndef AABB_H
#define AABB_H
-#include "math_defs.h"
-#include "plane.h"
-#include "vector3.h"
+#include "core/math/math_defs.h"
+#include "core/math/plane.h"
+#include "core/math/vector3.h"
/**
* AABB / AABB (Axis Aligned Bounding Box)
diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h
index 67ba025e1c..fde26e8056 100644
--- a/core/math/audio_frame.h
+++ b/core/math/audio_frame.h
@@ -31,7 +31,7 @@
#ifndef AUDIOFRAME_H
#define AUDIOFRAME_H
-#include "typedefs.h"
+#include "core/typedefs.h"
static inline float undenormalise(volatile float f) {
union {
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index 24096de551..6ffc963783 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "bsp_tree.h"
-#include "error_macros.h"
-#include "print_string.h"
+
+#include "core/error_macros.h"
+#include "core/print_string.h"
void BSP_Tree::from_aabb(const AABB &p_aabb) {
@@ -164,7 +165,6 @@ int BSP_Tree::get_points_inside(const Vector3 *p_points, int p_point_count) cons
int pass_count = 0;
const Node *nodesptr = &nodes[0];
const Plane *planesptr = &planes[0];
- int plane_count = planes.size();
int node_count = nodes.size();
if (node_count == 0) // no nodes!
@@ -191,9 +191,9 @@ int BSP_Tree::get_points_inside(const Vector3 *p_points, int p_point_count) cons
break;
}
- uint16_t plane = nodesptr[idx].plane;
#ifdef DEBUG_ENABLED
-
+ int plane_count = planes.size();
+ uint16_t plane = nodesptr[idx].plane;
ERR_FAIL_INDEX_V(plane, plane_count, false);
#endif
diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h
index fb16818ae7..b06e6b8539 100644
--- a/core/math/bsp_tree.h
+++ b/core/math/bsp_tree.h
@@ -31,13 +31,13 @@
#ifndef BSP_TREE_H
#define BSP_TREE_H
-#include "aabb.h"
-#include "dvector.h"
-#include "face3.h"
-#include "method_ptrcall.h"
-#include "plane.h"
-#include "variant.h"
-#include "vector.h"
+#include "core/dvector.h"
+#include "core/math/aabb.h"
+#include "core/math/face3.h"
+#include "core/math/plane.h"
+#include "core/method_ptrcall.h"
+#include "core/variant.h"
+#include "core/vector.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 1ab9b3532e..3a082d5720 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "camera_matrix.h"
-#include "math_funcs.h"
-#include "print_string.h"
+
+#include "core/math/math_funcs.h"
+#include "core/print_string.h"
void CameraMatrix::set_identity() {
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index a689c7238a..bd20908ad9 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -31,8 +31,9 @@
#ifndef CAMERA_MATRIX_H
#define CAMERA_MATRIX_H
-#include "rect2.h"
-#include "transform.h"
+#include "core/math/rect2.h"
+#include "core/math/transform.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/math/delaunay.h b/core/math/delaunay.h
index d47dc5240b..9c5eef9069 100644
--- a/core/math/delaunay.h
+++ b/core/math/delaunay.h
@@ -31,7 +31,7 @@
#ifndef DELAUNAY_H
#define DELAUNAY_H
-#include "rect2.h"
+#include "core/math/rect2.h"
class Delaunay2D {
public:
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 53e6aae36c..0cfb54234c 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -30,13 +30,13 @@
#include "expression.h"
-#include "class_db.h"
-#include "func_ref.h"
-#include "io/marshalls.h"
-#include "math_funcs.h"
-#include "os/os.h"
-#include "reference.h"
-#include "variant_parser.h"
+#include "core/class_db.h"
+#include "core/func_ref.h"
+#include "core/io/marshalls.h"
+#include "core/math/math_funcs.h"
+#include "core/os/os.h"
+#include "core/reference.h"
+#include "core/variant_parser.h"
const char *Expression::func_name[Expression::FUNC_MAX] = {
"sin",
@@ -756,6 +756,10 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
////////
+static bool _is_number(CharType c) {
+ return (c >= '0' && c <= '9');
+}
+
Error Expression::_get_token(Token &r_token) {
while (true) {
@@ -813,17 +817,12 @@ Error Expression::_get_token(Token &r_token) {
r_token.type = TK_COLON;
return OK;
};
- case '.': {
-
- r_token.type = TK_PERIOD;
- return OK;
- };
case '$': {
r_token.type = TK_INPUT;
int index = 0;
do {
- if (expression[str_ofs] < '0' || expression[str_ofs] > '9') {
+ if (!_is_number(expression[str_ofs])) {
_set_error("Expected number after '$'");
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
@@ -832,7 +831,7 @@ Error Expression::_get_token(Token &r_token) {
index += expression[str_ofs] - '0';
str_ofs++;
- } while (expression[str_ofs] >= '0' && expression[str_ofs] <= '9');
+ } while (_is_number(expression[str_ofs]));
r_token.value = index;
return OK;
@@ -979,14 +978,14 @@ Error Expression::_get_token(Token &r_token) {
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
- if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
+ if (!(_is_number(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
_set_error("Malformed hex constant in string");
r_token.type = TK_ERROR;
return ERR_PARSE_ERROR;
}
CharType v;
- if (c >= '0' && c <= '9') {
+ if (_is_number(c)) {
v = c - '0';
} else if (c >= 'a' && c <= 'f') {
v = c - 'a';
@@ -1032,7 +1031,8 @@ Error Expression::_get_token(Token &r_token) {
break;
}
- if (cchar >= '0' && cchar <= '9') {
+ CharType next_char = (str_ofs >= expression.length()) ? 0 : expression[str_ofs];
+ if (_is_number(cchar) || (cchar == '.' && _is_number(next_char))) {
//a number
String num;
@@ -1053,7 +1053,7 @@ Error Expression::_get_token(Token &r_token) {
switch (reading) {
case READING_INT: {
- if (c >= '0' && c <= '9') {
+ if (_is_number(c)) {
//pass
} else if (c == '.') {
reading = READING_DEC;
@@ -1067,7 +1067,7 @@ Error Expression::_get_token(Token &r_token) {
} break;
case READING_DEC: {
- if (c >= '0' && c <= '9') {
+ if (_is_number(c)) {
} else if (c == 'e') {
reading = READING_EXP;
@@ -1079,7 +1079,7 @@ Error Expression::_get_token(Token &r_token) {
} break;
case READING_EXP: {
- if (c >= '0' && c <= '9') {
+ if (_is_number(c)) {
exp_beg = true;
} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
@@ -1114,7 +1114,7 @@ Error Expression::_get_token(Token &r_token) {
String id;
bool first = true;
- while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) {
+ while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && _is_number(cchar))) {
id += String::chr(cchar);
cchar = GET_CHAR();
@@ -1176,6 +1176,12 @@ Error Expression::_get_token(Token &r_token) {
}
return OK;
+
+ } else if (cchar == '.') {
+ // Handled down there as we support '.[0-9]' as numbers above
+ r_token.type = TK_PERIOD;
+ return OK;
+
} else {
_set_error("Unexpected character.");
r_token.type = TK_ERROR;
@@ -1183,6 +1189,7 @@ Error Expression::_get_token(Token &r_token) {
}
}
}
+#undef GET_CHAR
}
r_token.type = TK_ERROR;
@@ -2113,6 +2120,10 @@ Error Expression::parse(const String &p_expression, const Vector<String> &p_inpu
}
Variant Expression::execute(Array p_inputs, Object *p_base, bool p_show_error) {
+ if (error_set) {
+ ERR_EXPLAIN("There was previously a parse error: " + error_str);
+ ERR_FAIL_V(Variant());
+ }
execution_error = false;
Variant output;
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index 801f2a3b4d..8366137131 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "face3.h"
-#include "geometry.h"
+
+#include "core/math/geometry.h"
int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_over[3]) const {
@@ -201,11 +202,12 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const {
{ \
real_t aabb_min = p_aabb.position.m_ax; \
real_t aabb_max = p_aabb.position.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) \
+ real_t tri_min = vertex[0].m_ax; \
+ real_t tri_max = vertex[0].m_ax; \
+ for (int i = 1; i < 3; i++) { \
+ if (vertex[i].m_ax > tri_max) \
tri_max = vertex[i].m_ax; \
- if (i == 0 || vertex[i].m_ax < tri_min) \
+ if (vertex[i].m_ax < tri_min) \
tri_min = vertex[i].m_ax; \
} \
\
diff --git a/core/math/face3.h b/core/math/face3.h
index faed0fa8d4..b41daf04d4 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -31,10 +31,10 @@
#ifndef FACE3_H
#define FACE3_H
-#include "aabb.h"
-#include "plane.h"
-#include "transform.h"
-#include "vector3.h"
+#include "core/math/aabb.h"
+#include "core/math/plane.h"
+#include "core/math/transform.h"
+#include "core/math/vector3.h"
class Face3 {
public:
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index d8cb657b5e..be5e40e4e6 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "geometry.h"
-#include "print_string.h"
+
+#include "core/print_string.h"
bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) {
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 83b9467a30..a813a90774 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -31,14 +31,15 @@
#ifndef GEOMETRY_H
#define GEOMETRY_H
-#include "dvector.h"
-#include "face3.h"
-#include "object.h"
-#include "print_string.h"
-#include "rect2.h"
-#include "triangulate.h"
-#include "vector.h"
-#include "vector3.h"
+#include "core/dvector.h"
+#include "core/math/face3.h"
+#include "core/math/rect2.h"
+#include "core/math/triangulate.h"
+#include "core/math/vector3.h"
+#include "core/object.h"
+#include "core/print_string.h"
+#include "core/vector.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/helper/math_fieldwise.cpp b/core/math/math_fieldwise.cpp
index ff3f8b3520..20b2341ab0 100644
--- a/core/helper/math_fieldwise.cpp
+++ b/core/math/math_fieldwise.cpp
@@ -30,7 +30,7 @@
#ifdef TOOLS_ENABLED
-#include "core/helper/math_fieldwise.h"
+#include "math_fieldwise.h"
#define SETUP_TYPE(m_type) \
m_type source = p_source; \
diff --git a/core/helper/math_fieldwise.h b/core/math/math_fieldwise.h
index 0e7cc3ea4a..0e7cc3ea4a 100644
--- a/core/helper/math_fieldwise.h
+++ b/core/math/math_fieldwise.h
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 5c8512d8bd..0c06d2a2b5 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -57,7 +57,7 @@ uint32_t Math::rand() {
}
int Math::step_decimals(double p_step) {
- static const int maxn = 9;
+ static const int maxn = 10;
static const double sd[maxn] = {
0.9999, // somehow compensate for floating point error
0.09999,
@@ -67,17 +67,19 @@ int Math::step_decimals(double p_step) {
0.000009999,
0.0000009999,
0.00000009999,
- 0.000000009999
+ 0.000000009999,
+ 0.0000000009999
};
- double as = Math::abs(p_step);
+ double abs = Math::abs(p_step);
+ double decs = abs - (int)abs; // Strip away integer part
for (int i = 0; i < maxn; i++) {
- if (as >= sd[i]) {
+ if (decs >= sd[i]) {
return i;
}
}
- return maxn;
+ return 0;
}
double Math::dectime(double p_value, double p_amount, double p_step) {
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 992084a653..9a486a49d0 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -31,8 +31,8 @@
#ifndef MATH_FUNCS_H
#define MATH_FUNCS_H
-#include "math_defs.h"
-#include "typedefs.h"
+#include "core/math/math_defs.h"
+#include "core/typedefs.h"
#include "thirdparty/misc/pcg.h"
@@ -46,7 +46,7 @@ class Math {
public:
Math() {} // useless to instance
- static const uint64_t RANDOM_MAX = 4294967295;
+ static const uint64_t RANDOM_MAX = 0xFFFFFFFF;
static _ALWAYS_INLINE_ double sin(double p_x) { return ::sin(p_x); }
static _ALWAYS_INLINE_ float sin(float p_x) { return ::sinf(p_x); }
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index 7db41756ed..925a7b3f1e 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -29,9 +29,11 @@
/*************************************************************************/
#include "matrix3.h"
-#include "math_funcs.h"
-#include "os/copymem.h"
-#include "print_string.h"
+
+#include "core/math/math_funcs.h"
+#include "core/os/copymem.h"
+#include "core/print_string.h"
+
#define cofac(row1, col1, row2, col2) \
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1])
@@ -297,14 +299,14 @@ Vector3 Basis::rotref_posscale_decomposition(Basis &rotref) const {
ERR_FAIL_COND_V(determinant() == 0, Vector3());
Basis m = transposed() * (*this);
- ERR_FAIL_COND_V(m.is_diagonal() == false, Vector3());
+ ERR_FAIL_COND_V(!m.is_diagonal(), Vector3());
#endif
Vector3 scale = get_scale();
Basis inv_scale = Basis().scaled(scale.inverse()); // this will also absorb the sign of scale
rotref = (*this) * inv_scale;
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(rotref.is_orthogonal() == false, Vector3());
+ ERR_FAIL_COND_V(!rotref.is_orthogonal(), Vector3());
#endif
return scale.abs();
}
@@ -428,7 +430,7 @@ Vector3 Basis::get_euler_xyz() const {
Vector3 euler;
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_rotation() == false, euler);
+ ERR_FAIL_COND_V(!is_rotation(), euler);
#endif
real_t sy = elements[0][2];
if (sy < 1.0) {
@@ -495,7 +497,7 @@ Vector3 Basis::get_euler_yxz() const {
Vector3 euler;
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_rotation() == false, euler);
+ ERR_FAIL_COND_V(!is_rotation(), euler);
#endif
real_t m12 = elements[1][2];
@@ -554,7 +556,7 @@ bool Basis::is_equal_approx(const Basis &a, const Basis &b) const {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (Math::is_equal_approx(a.elements[i][j], b.elements[i][j]) == false)
+ if (!Math::is_equal_approx(a.elements[i][j], b.elements[i][j]))
return false;
}
}
@@ -598,7 +600,7 @@ Basis::operator String() const {
Quat Basis::get_quat() const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_rotation() == false, Quat());
+ ERR_FAIL_COND_V(!is_rotation(), Quat());
#endif
real_t trace = elements[0][0] + elements[1][1] + elements[2][2];
real_t temp[4];
@@ -695,7 +697,7 @@ void Basis::set_orthogonal_index(int p_index) {
void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND(is_rotation() == false);
+ ERR_FAIL_COND(!is_rotation());
#endif
real_t angle, x, y, z; // variables for result
real_t epsilon = 0.01; // margin to allow for rounding errors
@@ -783,7 +785,7 @@ void Basis::set_quat(const Quat &p_quat) {
void Basis::set_axis_angle(const Vector3 &p_axis, real_t p_phi) {
// Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_angle
#ifdef MATH_CHECKS
- ERR_FAIL_COND(p_axis.is_normalized() == false);
+ ERR_FAIL_COND(!p_axis.is_normalized());
#endif
Vector3 axis_sq(p_axis.x * p_axis.x, p_axis.y * p_axis.y, p_axis.z * p_axis.z);
@@ -835,8 +837,8 @@ void Basis::set_diagonal(const Vector3 p_diag) {
Basis Basis::slerp(const Basis &target, const real_t &t) const {
// TODO: implement this directly without using quaternions to make it more efficient
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_rotation() == false, Basis());
- ERR_FAIL_COND_V(target.is_rotation() == false, Basis());
+ ERR_FAIL_COND_V(!is_rotation(), Basis());
+ ERR_FAIL_COND_V(!target.is_rotation(), Basis());
#endif
Quat from(*this);
diff --git a/core/math/matrix3.h b/core/math/matrix3.h
index 9ff1a97dc9..35bf75bbe4 100644
--- a/core/math/matrix3.h
+++ b/core/math/matrix3.h
@@ -28,16 +28,18 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "vector3.h"
+// Circular dependency between Vector3 and Basis :/
+#include "core/math/vector3.h"
#ifndef MATRIX3_H
#define MATRIX3_H
-#include "quat.h"
+#include "core/math/quat.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class Basis {
public:
Vector3 elements[3];
diff --git a/core/math/octree.h b/core/math/octree.h
index 4e3d6257f0..cd89743a5a 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -31,12 +31,12 @@
#ifndef OCTREE_H
#define OCTREE_H
-#include "aabb.h"
-#include "list.h"
-#include "map.h"
-#include "print_string.h"
-#include "variant.h"
-#include "vector3.h"
+#include "core/list.h"
+#include "core/map.h"
+#include "core/math/aabb.h"
+#include "core/math/vector3.h"
+#include "core/print_string.h"
+#include "core/variant.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
@@ -478,7 +478,7 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
splits++;
}
} else {
- /* check againt AABB where child should be */
+ /* check against AABB where child should be */
AABB aabb = p_octant->aabb;
aabb.size *= 0.5;
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index 78bb1771a4..3c597d57f8 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -30,7 +30,7 @@
#include "plane.h"
-#include "math_funcs.h"
+#include "core/math/math_funcs.h"
#define _PLANE_EQ_DOT_EPSILON 0.999
#define _PLANE_EQ_D_EPSILON 0.0001
diff --git a/core/math/plane.h b/core/math/plane.h
index e567422dd0..4eedebb79e 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -31,7 +31,7 @@
#ifndef PLANE_H
#define PLANE_H
-#include "vector3.h"
+#include "core/math/vector3.h"
class Plane {
public:
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index 2251571146..791e84f089 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "quat.h"
-#include "matrix3.h"
-#include "print_string.h"
+
+#include "core/math/matrix3.h"
+#include "core/print_string.h"
// set_euler_xyz expects a vector containing the Euler angles in the format
// (ax,ay,az), where ax is the angle of rotation around x axis,
@@ -99,7 +100,7 @@ void Quat::set_euler_yxz(const Vector3 &p_euler) {
// This implementation uses YXZ convention (Z is the first rotation).
Vector3 Quat::get_euler_yxz() const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_normalized() == false, Vector3(0, 0, 0));
+ ERR_FAIL_COND_V(!is_normalized(), Vector3(0, 0, 0));
#endif
Basis m(*this);
return m.get_euler_yxz();
@@ -139,15 +140,15 @@ bool Quat::is_normalized() const {
Quat Quat::inverse() const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_normalized() == false, Quat());
+ ERR_FAIL_COND_V(!is_normalized(), Quat());
#endif
return Quat(-x, -y, -z, w);
}
Quat Quat::slerp(const Quat &q, const real_t &t) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_normalized() == false, Quat());
- ERR_FAIL_COND_V(q.is_normalized() == false, Quat());
+ ERR_FAIL_COND_V(!is_normalized(), Quat());
+ ERR_FAIL_COND_V(!q.is_normalized(), Quat());
#endif
Quat to1;
real_t omega, cosom, sinom, scale0, scale1;
@@ -193,8 +194,8 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
Quat Quat::slerpni(const Quat &q, const real_t &t) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_normalized() == false, Quat());
- ERR_FAIL_COND_V(q.is_normalized() == false, Quat());
+ ERR_FAIL_COND_V(!is_normalized(), Quat());
+ ERR_FAIL_COND_V(!q.is_normalized(), Quat());
#endif
const Quat &from = *this;
@@ -215,8 +216,8 @@ 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 {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_normalized() == false, Quat());
- ERR_FAIL_COND_V(q.is_normalized() == false, Quat());
+ ERR_FAIL_COND_V(!is_normalized(), Quat());
+ ERR_FAIL_COND_V(!q.is_normalized(), Quat());
#endif
//the only way to do slerp :|
real_t t2 = (1.0 - t) * t * 2;
@@ -232,7 +233,7 @@ Quat::operator String() const {
void Quat::set_axis_angle(const Vector3 &axis, const real_t &angle) {
#ifdef MATH_CHECKS
- ERR_FAIL_COND(axis.is_normalized() == false);
+ ERR_FAIL_COND(!axis.is_normalized());
#endif
real_t d = axis.length();
if (d == 0)
diff --git a/core/math/quat.h b/core/math/quat.h
index 6dc8d66f60..c4f9b3a732 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -28,18 +28,20 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "vector3.h"
+// Circular dependency between Vector3 and Basis :/
+#include "core/math/vector3.h"
#ifndef QUAT_H
#define QUAT_H
-#include "math_defs.h"
-#include "math_funcs.h"
-#include "ustring.h"
+#include "core/math/math_defs.h"
+#include "core/math/math_funcs.h"
+#include "core/ustring.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class Quat {
public:
real_t x, y, z, w;
@@ -85,7 +87,7 @@ public:
_FORCE_INLINE_ Vector3 xform(const Vector3 &v) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_normalized() == false, v);
+ ERR_FAIL_COND_V(!is_normalized(), v);
#endif
Vector3 u(x, y, z);
Vector3 uv = u.cross(v);
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index 9d4f4f66b7..23823b339a 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "quick_hull.h"
-#include "map.h"
+
+#include "core/map.h"
uint32_t QuickHull::debug_stop_after = 0xFFFFFFFF;
diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h
index eef4a9adff..0ac2758323 100644
--- a/core/math/quick_hull.h
+++ b/core/math/quick_hull.h
@@ -31,10 +31,10 @@
#ifndef QUICK_HULL_H
#define QUICK_HULL_H
-#include "aabb.h"
-#include "geometry.h"
-#include "list.h"
-#include "set.h"
+#include "core/list.h"
+#include "core/math/aabb.h"
+#include "core/math/geometry.h"
+#include "core/set.h"
class QuickHull {
diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp
index 480bccdff1..24c1c8c984 100644
--- a/core/math/rect2.cpp
+++ b/core/math/rect2.cpp
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "transform_2d.h" // Includes rect2.h but Rect2 needs Transform2D
+#include "core/math/transform_2d.h" // Includes rect2.h but Rect2 needs Transform2D
bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const {
diff --git a/core/math/rect2.h b/core/math/rect2.h
index 20329bee0d..96c0e177d3 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -31,7 +31,7 @@
#ifndef RECT2_H
#define RECT2_H
-#include "vector2.h" // also includes math_funcs and ustring
+#include "core/math/vector2.h" // also includes math_funcs and ustring
struct Transform2D;
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index 976e0f174e..75257a6e60 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -29,9 +29,10 @@
/*************************************************************************/
#include "transform.h"
-#include "math_funcs.h"
-#include "os/copymem.h"
-#include "print_string.h"
+
+#include "core/math/math_funcs.h"
+#include "core/os/copymem.h"
+#include "core/print_string.h"
void Transform::affine_invert() {
diff --git a/core/math/transform.h b/core/math/transform.h
index c06eaec604..97c8bf9ab0 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -31,12 +31,14 @@
#ifndef TRANSFORM_H
#define TRANSFORM_H
-#include "aabb.h"
-#include "matrix3.h"
-#include "plane.h"
+#include "core/math/aabb.h"
+#include "core/math/matrix3.h"
+#include "core/math/plane.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class Transform {
public:
Basis basis;
diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h
index bf73755f0d..c8fc3c39e3 100644
--- a/core/math/transform_2d.h
+++ b/core/math/transform_2d.h
@@ -31,7 +31,7 @@
#ifndef TRANSFORM_2D_H
#define TRANSFORM_2D_H
-#include "rect2.h" // also includes vector2, math_funcs, and ustring
+#include "core/math/rect2.h" // also includes vector2, math_funcs, and ustring
struct Transform2D {
// Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper":
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index 5475f733c3..6b8dc5eeb3 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "triangle_mesh.h"
-#include "sort.h"
+
+#include "core/sort.h"
int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc) {
diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h
index bf793fc50f..e5f181fba7 100644
--- a/core/math/triangle_mesh.h
+++ b/core/math/triangle_mesh.h
@@ -31,8 +31,9 @@
#ifndef TRIANGLE_MESH_H
#define TRIANGLE_MESH_H
-#include "face3.h"
-#include "reference.h"
+#include "core/math/face3.h"
+#include "core/reference.h"
+
class TriangleMesh : public Reference {
GDCLASS(TriangleMesh, Reference);
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index 0edc0ea039..69ffc95946 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -186,7 +186,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
nv--;
- /* resest error detection counter */
+ /* reset error detection counter */
count = 2 * nv;
}
}
diff --git a/core/math/triangulate.h b/core/math/triangulate.h
index a0f56f5f27..2b0557ee55 100644
--- a/core/math/triangulate.h
+++ b/core/math/triangulate.h
@@ -31,7 +31,7 @@
#ifndef TRIANGULATE_H
#define TRIANGULATE_H
-#include "vector2.h"
+#include "core/math/vector2.h"
/*
http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index 84c9f0fca6..7c6f056f09 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -167,7 +167,7 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
// slide returns the component of the vector along the given plane, specified by its normal vector.
Vector2 Vector2::slide(const Vector2 &p_normal) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector2());
+ ERR_FAIL_COND_V(!p_normal.is_normalized(), Vector2());
#endif
return *this - p_normal * this->dot(p_normal);
}
@@ -178,7 +178,7 @@ Vector2 Vector2::bounce(const Vector2 &p_normal) const {
Vector2 Vector2::reflect(const Vector2 &p_normal) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector2());
+ ERR_FAIL_COND_V(!p_normal.is_normalized(), Vector2());
#endif
return 2.0 * p_normal * this->dot(p_normal) - *this;
}
diff --git a/core/math/vector2.h b/core/math/vector2.h
index fbcdc80b60..e5e555597d 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -31,8 +31,8 @@
#ifndef VECTOR2_H
#define VECTOR2_H
-#include "math_funcs.h"
-#include "ustring.h"
+#include "core/math/math_funcs.h"
+#include "core/ustring.h"
struct Vector2i;
@@ -230,7 +230,7 @@ Vector2 Vector2::linear_interpolate(const Vector2 &p_b, real_t p_t) const {
Vector2 Vector2::slerp(const Vector2 &p_b, real_t p_t) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_normalized() == false, Vector2());
+ ERR_FAIL_COND_V(!is_normalized(), Vector2());
#endif
real_t theta = angle_to(p_b);
return rotated(theta * p_t);
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 78d52d5cd1..5dbb01493d 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "vector3.h"
-#include "matrix3.h"
+
+#include "core/math/matrix3.h"
void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) {
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 5f0e8919ff..16feba6a0c 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -31,10 +31,10 @@
#ifndef VECTOR3_H
#define VECTOR3_H
-#include "math_defs.h"
-#include "math_funcs.h"
-#include "typedefs.h"
-#include "ustring.h"
+#include "core/math/math_defs.h"
+#include "core/math/math_funcs.h"
+#include "core/typedefs.h"
+#include "core/ustring.h"
class Basis;
@@ -150,13 +150,8 @@ struct Vector3 {
}
};
-#ifdef VECTOR3_IMPL_OVERRIDE
-
-#include "vector3_inline.h"
-
-#else
-
-#include "matrix3.h"
+// Should be included after class definition, otherwise we get circular refs
+#include "core/math/matrix3.h"
Vector3 Vector3::cross(const Vector3 &p_b) const {
@@ -223,7 +218,7 @@ Vector3 Vector3::linear_interpolate(const Vector3 &p_b, real_t p_t) const {
Vector3 Vector3::slerp(const Vector3 &p_b, real_t p_t) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(is_normalized() == false, Vector3());
+ ERR_FAIL_COND_V(!is_normalized(), Vector3());
#endif
real_t theta = angle_to(p_b);
@@ -435,7 +430,7 @@ void Vector3::zero() {
// slide returns the component of the vector along the given plane, specified by its normal vector.
Vector3 Vector3::slide(const Vector3 &p_normal) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector3());
+ ERR_FAIL_COND_V(!p_normal.is_normalized(), Vector3());
#endif
return *this - p_normal * this->dot(p_normal);
}
@@ -446,11 +441,9 @@ Vector3 Vector3::bounce(const Vector3 &p_normal) const {
Vector3 Vector3::reflect(const Vector3 &p_normal) const {
#ifdef MATH_CHECKS
- ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector3());
+ ERR_FAIL_COND_V(!p_normal.is_normalized(), Vector3());
#endif
return 2.0 * p_normal * this->dot(p_normal) - *this;
}
-#endif
-
#endif // VECTOR3_H
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index 97ee236a46..abfc73407a 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -30,8 +30,8 @@
#include "message_queue.h"
-#include "project_settings.h"
-#include "script_language.h"
+#include "core/project_settings.h"
+#include "core/script_language.h"
MessageQueue *MessageQueue::singleton = NULL;
@@ -338,6 +338,7 @@ MessageQueue::MessageQueue() {
buffer_end = 0;
buffer_max_used = 0;
buffer_size = GLOBAL_DEF_RST("memory/limits/message_queue/max_size_kb", DEFAULT_QUEUE_SIZE_KB);
+ ProjectSettings::get_singleton()->set_custom_property_info("memory/limits/message_queue/max_size_kb", PropertyInfo(Variant::INT, "memory/limits/message_queue/max_size_kb", PROPERTY_HINT_RANGE, "0,2048,1,or_greater"));
buffer_size *= 1024;
buffer = memnew_arr(uint8_t, buffer_size);
}
diff --git a/core/message_queue.h b/core/message_queue.h
index be5ffe4fae..2083bb0639 100644
--- a/core/message_queue.h
+++ b/core/message_queue.h
@@ -31,9 +31,8 @@
#ifndef MESSAGE_QUEUE_H
#define MESSAGE_QUEUE_H
-#include "object.h"
-#include "os/mutex.h"
-#include "os/thread_safe.h"
+#include "core/object.h"
+#include "core/os/thread_safe.h"
class MessageQueue {
@@ -44,8 +43,6 @@ class MessageQueue {
DEFAULT_QUEUE_SIZE_KB = 1024
};
- Mutex *mutex;
-
enum {
TYPE_CALL,
TYPE_NOTIFICATION,
diff --git a/core/method_bind.cpp b/core/method_bind.cpp
index 52ee9e0848..fa5b88b5ac 100644
--- a/core/method_bind.cpp
+++ b/core/method_bind.cpp
@@ -30,7 +30,7 @@
// 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 "core/object.h"
#include "method_bind.h"
diff --git a/core/method_bind.h b/core/method_bind.h
index 7ee687ee40..7788de919c 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -31,10 +31,11 @@
#ifndef METHOD_BIND_H
#define METHOD_BIND_H
-#include "list.h"
-#include "method_ptrcall.h"
-#include "object.h"
-#include "variant.h"
+#include "core/list.h"
+#include "core/method_ptrcall.h"
+#include "core/object.h"
+#include "core/variant.h"
+
#include <stdio.h>
/**
@@ -45,7 +46,7 @@
#define DEBUG_METHODS_ENABLED
#endif
-#include "type_info.h"
+#include "core/type_info.h"
enum MethodFlags {
diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h
index 6a33cf4d70..b706e65d53 100644
--- a/core/method_ptrcall.h
+++ b/core/method_ptrcall.h
@@ -31,9 +31,9 @@
#ifndef METHOD_PTRCALL_H
#define METHOD_PTRCALL_H
-#include "transform_2d.h"
-#include "typedefs.h"
-#include "variant.h"
+#include "core/math/transform_2d.h"
+#include "core/typedefs.h"
+#include "core/variant.h"
#ifdef PTRCALL_ENABLED
diff --git a/core/node_path.cpp b/core/node_path.cpp
index 7d4116fa1e..91e2aa5f4e 100644
--- a/core/node_path.cpp
+++ b/core/node_path.cpp
@@ -30,7 +30,7 @@
#include "node_path.h"
-#include "print_string.h"
+#include "core/print_string.h"
void NodePath::_update_hash_cache() const {
@@ -276,7 +276,7 @@ NodePath NodePath::get_as_property_path() const {
String initial_subname = data->path[0];
- for (size_t i = 1; i < data->path.size(); i++) {
+ for (int i = 1; i < data->path.size(); i++) {
initial_subname += "/" + data->path[i];
}
new_path.insert(0, initial_subname);
diff --git a/core/node_path.h b/core/node_path.h
index 71235029af..4a72d4a4d5 100644
--- a/core/node_path.h
+++ b/core/node_path.h
@@ -31,8 +31,9 @@
#ifndef NODE_PATH_H
#define NODE_PATH_H
-#include "string_db.h"
-#include "ustring.h"
+#include "core/string_db.h"
+#include "core/ustring.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/oa_hash_map.h b/core/oa_hash_map.h
index 3a17fc21f3..9840442519 100644
--- a/core/oa_hash_map.h
+++ b/core/oa_hash_map.h
@@ -31,10 +31,10 @@
#ifndef OA_HASH_MAP_H
#define OA_HASH_MAP_H
-#include "hashfuncs.h"
-#include "math_funcs.h"
-#include "os/copymem.h"
-#include "os/memory.h"
+#include "core/hashfuncs.h"
+#include "core/math/math_funcs.h"
+#include "core/os/copymem.h"
+#include "core/os/memory.h"
/**
* A HashMap implementation that uses open addressing with robinhood hashing.
@@ -125,7 +125,7 @@ private:
while (42) {
if (hashes[pos] == EMPTY_HASH) {
- _construct(pos, hash, p_key, p_value);
+ _construct(pos, hash, key, value);
return;
}
@@ -136,7 +136,7 @@ private:
if (hashes[pos] & DELETED_HASH_BIT) {
// we found a place where we can fit in!
- _construct(pos, hash, p_key, p_value);
+ _construct(pos, hash, key, value);
return;
}
@@ -166,7 +166,7 @@ private:
values = memnew_arr(TValue, capacity);
hashes = memnew_arr(uint32_t, capacity);
- for (int i = 0; i < capacity; i++) {
+ for (uint32_t i = 0; i < capacity; i++) {
hashes[i] = 0;
}
@@ -311,7 +311,7 @@ public:
values = memnew_arr(TValue, p_initial_capacity);
hashes = memnew_arr(uint32_t, p_initial_capacity);
- for (int i = 0; i < p_initial_capacity; i++) {
+ for (uint32_t i = 0; i < p_initial_capacity; i++) {
hashes[i] = 0;
}
}
diff --git a/core/object.cpp b/core/object.cpp
index 24a31930a0..374e10726a 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -30,14 +30,14 @@
#include "object.h"
-#include "class_db.h"
-#include "core_string_names.h"
-#include "message_queue.h"
-#include "os/os.h"
-#include "print_string.h"
-#include "resource.h"
-#include "script_language.h"
-#include "translation.h"
+#include "core/class_db.h"
+#include "core/core_string_names.h"
+#include "core/message_queue.h"
+#include "core/os/os.h"
+#include "core/print_string.h"
+#include "core/resource.h"
+#include "core/script_language.h"
+#include "core/translation.h"
#ifdef DEBUG_ENABLED
@@ -277,8 +277,8 @@ MethodInfo::MethodInfo(Variant::Type ret, const String &p_name, const PropertyIn
MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name) :
name(p_name),
- flags(METHOD_FLAG_NORMAL),
return_val(p_ret),
+ flags(METHOD_FLAG_NORMAL),
id(0) {
}
@@ -440,16 +440,6 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
if (r_valid)
*r_valid = true;
return;
-#ifdef TOOLS_ENABLED
- } else if (p_name == CoreStringNames::get_singleton()->_sections_unfolded) {
- Array arr = p_value;
- for (int i = 0; i < arr.size(); i++) {
- editor_section_folding.insert(arr[i]);
- }
- if (r_valid)
- *r_valid = true;
- return;
-#endif
}
//something inside the object... :|
@@ -520,16 +510,7 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
if (r_valid)
*r_valid = true;
return ret;
-#ifdef TOOLS_ENABLED
- } else if (p_name == CoreStringNames::get_singleton()->_sections_unfolded) {
- Array array;
- for (Set<String>::Element *E = editor_section_folding.front(); E; E = E->next()) {
- array.push_back(E->get());
- }
- if (r_valid)
- *r_valid = true;
- return array;
-#endif
+
} else {
//something inside the object... :|
bool success = _getv(p_name, ret);
@@ -657,11 +638,6 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons
#endif
p_list->push_back(PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NONZERO));
}
-#ifdef TOOLS_ENABLED
- if (editor_section_folding.size()) {
- p_list->push_back(PropertyInfo(Variant::ARRAY, CoreStringNames::get_singleton()->_sections_unfolded, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
- }
-#endif
if (!metadata.empty())
p_list->push_back(PropertyInfo(Variant::DICTIONARY, "__meta__", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_STORE_IF_NONZERO));
if (script_instance && !p_reversed) {
@@ -1254,7 +1230,10 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
target->call(c.method, args, argc, ce);
if (ce.error != Variant::CallError::CALL_OK) {
-
+#ifdef DEBUG_ENABLED
+ if (c.flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref<Script>(script)->is_tool()))
+ continue;
+#endif
if (ce.error == Variant::CallError::CALL_ERROR_INVALID_METHOD && !ClassDB::class_exists(target->get_class_name())) {
//most likely object is not initialized yet, do not throw error.
} else {
@@ -2014,11 +1993,13 @@ ObjectID ObjectDB::add_instance(Object *p_object) {
ERR_FAIL_COND_V(p_object->get_instance_id() != 0, 0);
rw_lock->write_lock();
- instances[++instance_counter] = p_object;
- instance_checks[p_object] = instance_counter;
+ ObjectID instance_id = ++instance_counter;
+ instances[instance_id] = p_object;
+ instance_checks[p_object] = instance_id;
+
rw_lock->write_unlock();
- return instance_counter;
+ return instance_id;
}
void ObjectDB::remove_instance(Object *p_object) {
@@ -2095,6 +2076,5 @@ void ObjectDB::cleanup() {
instances.clear();
instance_checks.clear();
rw_lock->write_unlock();
-
memdelete(rw_lock);
}
diff --git a/core/object.h b/core/object.h
index 43e1cf4785..0fee7c2157 100644
--- a/core/object.h
+++ b/core/object.h
@@ -31,13 +31,13 @@
#ifndef OBJECT_H
#define OBJECT_H
-#include "hash_map.h"
-#include "list.h"
-#include "map.h"
-#include "os/rw_lock.h"
-#include "set.h"
-#include "variant.h"
-#include "vmap.h"
+#include "core/hash_map.h"
+#include "core/list.h"
+#include "core/map.h"
+#include "core/os/rw_lock.h"
+#include "core/set.h"
+#include "core/variant.h"
+#include "core/vmap.h"
#define VARIANT_ARG_LIST const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant()
#define VARIANT_ARG_PASS p_arg1, p_arg2, p_arg3, p_arg4, p_arg5
@@ -116,6 +116,7 @@ enum PropertyUsageFlags {
PROPERTY_USAGE_NIL_IS_VARIANT = 1 << 19,
PROPERTY_USAGE_INTERNAL = 1 << 20,
PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE = 1 << 21, // If the object is duplicated also this property will be duplicated
+ PROPERTY_USAGE_HIGH_END_GFX = 1 << 22,
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,
@@ -187,11 +188,11 @@ Array convert_property_list(const List<PropertyInfo> *p_list);
struct MethodInfo {
String name;
- List<PropertyInfo> arguments;
- Vector<Variant> default_arguments;
PropertyInfo return_val;
uint32_t flags;
int id;
+ List<PropertyInfo> arguments;
+ Vector<Variant> default_arguments;
inline bool operator==(const MethodInfo &p_method) const { return id == p_method.id; }
inline bool operator<(const MethodInfo &p_method) const { return id == p_method.id ? (name < p_method.name) : (id < p_method.id); }
@@ -317,7 +318,7 @@ protected:
virtual void _initialize_classv() { \
initialize_class(); \
} \
- _FORCE_INLINE_ bool (Object::*(_get_get() const))(const StringName &p_name, Variant &) const { \
+ _FORCE_INLINE_ bool (Object::*_get_get() const)(const StringName &p_name, Variant &) const { \
return (bool (Object::*)(const StringName &, Variant &) const) & m_class::_get; \
} \
virtual bool _getv(const StringName &p_name, Variant &r_ret) const { \
@@ -327,7 +328,7 @@ protected:
} \
return m_inherits::_getv(p_name, r_ret); \
} \
- _FORCE_INLINE_ bool (Object::*(_get_set() const))(const StringName &p_name, const Variant &p_property) { \
+ _FORCE_INLINE_ bool (Object::*_get_set() const)(const StringName &p_name, const Variant &p_property) { \
return (bool (Object::*)(const StringName &, const Variant &)) & m_class::_set; \
} \
virtual bool _setv(const StringName &p_name, const Variant &p_property) { \
@@ -337,7 +338,7 @@ protected:
} \
return false; \
} \
- _FORCE_INLINE_ void (Object::*(_get_get_property_list() const))(List<PropertyInfo> * p_list) const { \
+ _FORCE_INLINE_ void (Object::*_get_get_property_list() const)(List<PropertyInfo> * p_list) const { \
return (void (Object::*)(List<PropertyInfo> *) const) & m_class::_get_property_list; \
} \
virtual void _get_property_listv(List<PropertyInfo> *p_list, bool p_reversed) const { \
@@ -356,7 +357,7 @@ protected:
m_inherits::_get_property_listv(p_list, p_reversed); \
} \
} \
- _FORCE_INLINE_ void (Object::*(_get_notification() const))(int) { \
+ _FORCE_INLINE_ void (Object::*_get_notification() const)(int) { \
return (void (Object::*)(int)) & m_class::_notification; \
} \
virtual void _notificationv(int p_notification, bool p_reversed) { \
@@ -421,7 +422,7 @@ private:
};
#ifdef DEBUG_ENABLED
- friend class _ObjectDebugLock;
+ friend struct _ObjectDebugLock;
#endif
friend bool predelete_handler(Object *);
friend void postinitialize_handler(Object *);
@@ -513,16 +514,16 @@ protected:
_FORCE_INLINE_ static void (*_get_bind_methods())() {
return &Object::_bind_methods;
}
- _FORCE_INLINE_ bool (Object::*(_get_get() const))(const StringName &p_name, Variant &r_ret) const {
+ _FORCE_INLINE_ bool (Object::*_get_get() const)(const StringName &p_name, Variant &r_ret) const {
return &Object::_get;
}
- _FORCE_INLINE_ bool (Object::*(_get_set() const))(const StringName &p_name, const Variant &p_property) {
+ _FORCE_INLINE_ bool (Object::*_get_set() const)(const StringName &p_name, const Variant &p_property) {
return &Object::_set;
}
- _FORCE_INLINE_ void (Object::*(_get_get_property_list() const))(List<PropertyInfo> *p_list) const {
+ _FORCE_INLINE_ void (Object::*_get_get_property_list() const)(List<PropertyInfo> *p_list) const {
return &Object::_get_property_list;
}
- _FORCE_INLINE_ void (Object::*(_get_notification() const))(int) {
+ _FORCE_INLINE_ void (Object::*_get_notification() const)(int) {
return &Object::_notification;
}
static void get_valid_parents_static(List<String> *p_parents);
@@ -722,6 +723,9 @@ public:
#ifdef TOOLS_ENABLED
void editor_set_section_unfold(const String &p_section, bool p_unfolded);
bool editor_is_section_unfolded(const String &p_section);
+ const Set<String> &editor_get_section_folding() const { return editor_section_folding; }
+ void editor_clear_section_folding() { editor_section_folding.clear(); }
+
#endif
//used by script languages to store binding data
@@ -779,6 +783,6 @@ public:
};
//needed by macros
-#include "class_db.h"
+#include "core/class_db.h"
#endif
diff --git a/core/ordered_hash_map.h b/core/ordered_hash_map.h
index 93ce9a90a7..092bf314d0 100644
--- a/core/ordered_hash_map.h
+++ b/core/ordered_hash_map.h
@@ -31,9 +31,9 @@
#ifndef ORDERED_HASH_MAP_H
#define ORDERED_HASH_MAP_H
-#include "hash_map.h"
-#include "list.h"
-#include "pair.h"
+#include "core/hash_map.h"
+#include "core/list.h"
+#include "core/pair.h"
/**
* A hash map which allows to iterate elements in insertion order.
diff --git a/core/os/SCsub b/core/os/SCsub
index 4efc902717..1c5f954470 100644
--- a/core/os/SCsub
+++ b/core/os/SCsub
@@ -3,5 +3,3 @@
Import('env')
env.add_source_files(env.core_sources, "*.cpp")
-
-Export('env')
diff --git a/core/os/copymem.h b/core/os/copymem.h
index 87d77bd426..999c770e85 100644
--- a/core/os/copymem.h
+++ b/core/os/copymem.h
@@ -31,7 +31,7 @@
#ifndef COPYMEM_H
#define COPYMEM_H
-#include "typedefs.h"
+#include "core/typedefs.h"
#ifdef PLATFORM_COPYMEM
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index e631d6e994..daa3eacd5f 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -29,10 +29,11 @@
/*************************************************************************/
#include "dir_access.h"
-#include "os/file_access.h"
-#include "os/memory.h"
-#include "os/os.h"
-#include "project_settings.h"
+
+#include "core/os/file_access.h"
+#include "core/os/memory.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
String DirAccess::_get_root_path() const {
@@ -226,6 +227,7 @@ String DirAccess::fix_path(String p_path) const {
return p_path;
} break;
+ case ACCESS_MAX: break; // Can't happen, but silences warning
}
return p_path;
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index 4df0618021..773f0bcd41 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -31,14 +31,14 @@
#ifndef DIR_ACCESS_H
#define DIR_ACCESS_H
-#include "typedefs.h"
-#include "ustring.h"
+#include "core/typedefs.h"
+#include "core/ustring.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-//@ TOOD, excellent candidate for THREAD_SAFE MACRO, should go through all these and add THREAD_SAFE where it applies
+//@ TODO, excellent candidate for THREAD_SAFE MACRO, should go through all these and add THREAD_SAFE where it applies
class DirAccess {
public:
enum AccessType {
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 59f07c03e7..e09e5e16ad 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -32,8 +32,8 @@
#include "core/io/file_access_pack.h"
#include "core/io/marshalls.h"
-#include "os/os.h"
-#include "project_settings.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
#include "thirdparty/misc/md5.h"
#include "thirdparty/misc/sha256.h"
@@ -46,7 +46,6 @@ bool FileAccess::backup_save = false;
FileAccess *FileAccess::create(AccessType p_access) {
- ERR_FAIL_COND_V(!create_func, 0);
ERR_FAIL_INDEX_V(p_access, ACCESS_MAX, 0);
FileAccess *ret = create_func[p_access]();
@@ -166,6 +165,7 @@ String FileAccess::fix_path(const String &p_path) const {
return r_path;
} break;
+ case ACCESS_MAX: break; // Can't happen, but silences warning
}
return r_path;
diff --git a/core/os/file_access.h b/core/os/file_access.h
index c4635fdfbb..b7d93e9f5d 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -31,10 +31,11 @@
#ifndef FILE_ACCESS_H
#define FILE_ACCESS_H
-#include "math_defs.h"
-#include "os/memory.h"
-#include "typedefs.h"
-#include "ustring.h"
+#include "core/math/math_defs.h"
+#include "core/os/memory.h"
+#include "core/typedefs.h"
+#include "core/ustring.h"
+
/**
* Multi-Platform abstraction for accessing to files.
*/
diff --git a/core/os/input.cpp b/core/os/input.cpp
index a5b0f91e63..4cd1f0b24a 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -29,9 +29,11 @@
/*************************************************************************/
#include "input.h"
-#include "input_map.h"
-#include "os/os.h"
-#include "project_settings.h"
+
+#include "core/input_map.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
+
Input *Input::singleton = NULL;
Input *Input::get_singleton() {
@@ -40,7 +42,7 @@ Input *Input::get_singleton() {
}
void Input::set_mouse_mode(MouseMode p_mode) {
- ERR_FAIL_INDEX(p_mode, 4);
+ ERR_FAIL_INDEX((int)p_mode, 4);
OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode);
}
diff --git a/core/os/input.h b/core/os/input.h
index 001871c5dc..db523d6789 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -31,9 +31,9 @@
#ifndef INPUT_H
#define INPUT_H
-#include "object.h"
-#include "os/main_loop.h"
-#include "os/thread_safe.h"
+#include "core/object.h"
+#include "core/os/main_loop.h"
+#include "core/os/thread_safe.h"
class Input : public Object {
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 12c6ef7d3b..5bbdd7efb2 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -30,8 +30,8 @@
#include "input_event.h"
-#include "input_map.h"
-#include "os/keyboard.h"
+#include "core/input_map.h"
+#include "core/os/keyboard.h"
void InputEvent::set_device(int p_device) {
device = p_device;
@@ -962,6 +962,22 @@ bool InputEventAction::is_action(const StringName &p_action) const {
return action == p_action;
}
+bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
+
+ Ref<InputEventAction> act = p_event;
+ if (act.is_null())
+ return false;
+
+ bool match = action == act->action;
+ if (match) {
+ if (p_pressed != NULL)
+ *p_pressed = act->pressed;
+ if (p_strength != NULL)
+ *p_strength = (*p_pressed) ? 1.0f : 0.0f;
+ }
+ return match;
+}
+
String InputEventAction::as_text() const {
return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 8732c7e377..789d19c5b2 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -31,11 +31,12 @@
#ifndef INPUT_EVENT_H
#define INPUT_EVENT_H
-#include "os/copymem.h"
-#include "resource.h"
-#include "transform_2d.h"
-#include "typedefs.h"
-#include "ustring.h"
+#include "core/math/transform_2d.h"
+#include "core/os/copymem.h"
+#include "core/resource.h"
+#include "core/typedefs.h"
+#include "core/ustring.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -480,6 +481,8 @@ public:
virtual bool is_action(const StringName &p_action) const;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
+
virtual bool shortcut_match(const Ref<InputEvent> &p_event) const;
virtual bool is_action_type() const { return true; }
virtual String as_text() const;
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index 9dfc91e308..abc579c58d 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "keyboard.h"
-#include "os/os.h"
+
+#include "core/os/os.h"
struct _KeyCodeText {
int code;
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index a0e6f8b2ef..17bf5eaa48 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -31,13 +31,10 @@
#ifndef KEYBOARD_H
#define KEYBOARD_H
-#include "ustring.h"
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
+#include "core/ustring.h"
/**
-@author Juan Linietsky <reduzio@gmail.com>
+ @author Juan Linietsky <reduzio@gmail.com>
*/
/*
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index 6dba77ec9a..0945cdd512 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "main_loop.h"
-#include "script_language.h"
+
+#include "core/script_language.h"
void MainLoop::_bind_methods() {
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index f96e46141e..43f74302a8 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -31,12 +31,14 @@
#ifndef MAIN_LOOP_H
#define MAIN_LOOP_H
-#include "os/input_event.h"
-#include "reference.h"
-#include "script_language.h"
+#include "core/os/input_event.h"
+#include "core/reference.h"
+#include "core/script_language.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class MainLoop : public Object {
GDCLASS(MainLoop, Object);
diff --git a/core/os/memory.cpp b/core/os/memory.cpp
index 3eab4343a9..f25e40ef78 100644
--- a/core/os/memory.cpp
+++ b/core/os/memory.cpp
@@ -29,9 +29,11 @@
/*************************************************************************/
#include "memory.h"
-#include "copymem.h"
+
+#include "core/error_macros.h"
+#include "core/os/copymem.h"
#include "core/safe_refcount.h"
-#include "error_macros.h"
+
#include <stdio.h>
#include <stdlib.h>
@@ -170,9 +172,9 @@ void Memory::free_static(void *p_ptr, bool p_pad_align) {
if (prepad) {
mem -= PAD_ALIGN;
- uint64_t *s = (uint64_t *)mem;
#ifdef DEBUG_ENABLED
+ uint64_t *s = (uint64_t *)mem;
atomic_sub(&mem_usage, *s);
#endif
diff --git a/core/os/memory.h b/core/os/memory.h
index f5c6c0b38a..3501c3f14e 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -31,7 +31,8 @@
#ifndef MEMORY_H
#define MEMORY_H
-#include "safe_refcount.h"
+#include "core/safe_refcount.h"
+
#include <stddef.h>
/**
diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp
index 7b4f84473c..2b20a708ed 100644
--- a/core/os/midi_driver.cpp
+++ b/core/os/midi_driver.cpp
@@ -30,8 +30,8 @@
#include "midi_driver.h"
+#include "core/os/os.h"
#include "main/input_default.h"
-#include "os/os.h"
MIDIDriver *MIDIDriver::singleton = NULL;
MIDIDriver *MIDIDriver::get_singleton() {
diff --git a/core/os/midi_driver.h b/core/os/midi_driver.h
index 1a3a67a411..ceb4e71d66 100644
--- a/core/os/midi_driver.h
+++ b/core/os/midi_driver.h
@@ -31,8 +31,9 @@
#ifndef MIDI_DRIVER_H
#define MIDI_DRIVER_H
+#include "core/typedefs.h"
#include "core/variant.h"
-#include "typedefs.h"
+
/**
* Multi-Platform abstraction for accessing to MIDI.
*/
diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp
index 7c4ea2323c..0c01b06bd6 100644
--- a/core/os/mutex.cpp
+++ b/core/os/mutex.cpp
@@ -29,7 +29,9 @@
/*************************************************************************/
#include "mutex.h"
-#include "error_macros.h"
+
+#include "core/error_macros.h"
+
#include <stddef.h>
Mutex *(*Mutex::create_func)(bool) = 0;
diff --git a/core/os/mutex.h b/core/os/mutex.h
index 9debe7f41b..788cc00397 100644
--- a/core/os/mutex.h
+++ b/core/os/mutex.h
@@ -31,7 +31,7 @@
#ifndef MUTEX_H
#define MUTEX_H
-#include "error_list.h"
+#include "core/error_list.h"
/**
* @class Mutex
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 0e6251a4fb..7547b6a042 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -30,13 +30,13 @@
#include "os.h"
-#include "dir_access.h"
-#include "input.h"
-#include "os/file_access.h"
-#include "os/midi_driver.h"
-#include "project_settings.h"
+#include "core/os/dir_access.h"
+#include "core/os/file_access.h"
+#include "core/os/input.h"
+#include "core/os/midi_driver.h"
+#include "core/project_settings.h"
+#include "core/version_generated.gen.h"
#include "servers/audio_server.h"
-#include "version_generated.gen.h"
#include <stdarg.h>
diff --git a/core/os/os.h b/core/os/os.h
index 100af95ef1..7786ffb26e 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -31,13 +31,14 @@
#ifndef OS_H
#define OS_H
-#include "engine.h"
-#include "image.h"
-#include "io/logger.h"
-#include "list.h"
-#include "os/main_loop.h"
-#include "ustring.h"
-#include "vector.h"
+#include "core/engine.h"
+#include "core/image.h"
+#include "core/io/logger.h"
+#include "core/list.h"
+#include "core/os/main_loop.h"
+#include "core/ustring.h"
+#include "core/vector.h"
+
#include <stdarg.h>
/**
@@ -128,7 +129,7 @@ protected:
RenderThreadMode _render_thread_mode;
- // functions used by main to initialize/deintialize the OS
+ // functions used by main to initialize/deinitialize the OS
void add_logger(Logger *p_logger);
virtual void initialize_core() = 0;
diff --git a/core/os/rw_lock.cpp b/core/os/rw_lock.cpp
index 35489490ed..5e51a1dbce 100644
--- a/core/os/rw_lock.cpp
+++ b/core/os/rw_lock.cpp
@@ -30,7 +30,7 @@
#include "rw_lock.h"
-#include "error_macros.h"
+#include "core/error_macros.h"
#include <stddef.h>
diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h
index 3e53300c9f..4333d9a016 100644
--- a/core/os/rw_lock.h
+++ b/core/os/rw_lock.h
@@ -31,7 +31,7 @@
#ifndef RWLOCK_H
#define RWLOCK_H
-#include "error_list.h"
+#include "core/error_list.h"
class RWLock {
protected:
@@ -57,9 +57,7 @@ class RWLockRead {
public:
RWLockRead(const RWLock *p_lock) {
- if (p_lock) {
- lock = const_cast<RWLock *>(p_lock);
- }
+ lock = const_cast<RWLock *>(p_lock);
if (lock) lock->read_lock();
}
~RWLockRead() {
diff --git a/core/os/semaphore.cpp b/core/os/semaphore.cpp
index 0377aeeb29..448d17dd14 100644
--- a/core/os/semaphore.cpp
+++ b/core/os/semaphore.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "semaphore.h"
-#include "error_macros.h"
+
+#include "core/error_macros.h"
Semaphore *(*Semaphore::create_func)() = 0;
diff --git a/core/os/semaphore.h b/core/os/semaphore.h
index f3021bf74c..6cec06ea28 100644
--- a/core/os/semaphore.h
+++ b/core/os/semaphore.h
@@ -31,11 +31,12 @@
#ifndef SEMAPHORE_H
#define SEMAPHORE_H
-#include "error_list.h"
+#include "core/error_list.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
+
class Semaphore {
protected:
static Semaphore *(*create_func)();
diff --git a/core/os/shell.h b/core/os/shell.h
index d3d92028ea..146c35cbc8 100644
--- a/core/os/shell.h
+++ b/core/os/shell.h
@@ -31,8 +31,8 @@
#ifndef SHELL_H
#define SHELL_H
-#include "typedefs.h"
-#include "ustring.h"
+#include "core/typedefs.h"
+#include "core/ustring.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/core/os/thread.h b/core/os/thread.h
index c2947bccab..97e97652a5 100644
--- a/core/os/thread.h
+++ b/core/os/thread.h
@@ -31,13 +31,13 @@
#ifndef THREAD_H
#define THREAD_H
-#include "typedefs.h"
+#include "core/typedefs.h"
+#include "core/ustring.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-#include "ustring.h"
-
typedef void (*ThreadCreateCallback)(void *p_userdata);
class Thread {
diff --git a/core/os/thread_dummy.cpp b/core/os/thread_dummy.cpp
index b6371235c4..9e0adf9994 100644
--- a/core/os/thread_dummy.cpp
+++ b/core/os/thread_dummy.cpp
@@ -30,7 +30,7 @@
#include "thread_dummy.h"
-#include "memory.h"
+#include "core/os/memory.h"
Thread *ThreadDummy::create(ThreadCreateCallback p_callback, void *p_user, const Thread::Settings &p_settings) {
return memnew(ThreadDummy);
diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h
index 74957b95fe..6f46a4a20c 100644
--- a/core/os/thread_dummy.h
+++ b/core/os/thread_dummy.h
@@ -31,10 +31,10 @@
#ifndef THREAD_DUMMY_H
#define THREAD_DUMMY_H
-#include "mutex.h"
-#include "rw_lock.h"
-#include "semaphore.h"
-#include "thread.h"
+#include "core/os/mutex.h"
+#include "core/os/rw_lock.h"
+#include "core/os/semaphore.h"
+#include "core/os/thread.h"
class ThreadDummy : public Thread {
diff --git a/core/os/thread_safe.cpp b/core/os/thread_safe.cpp
index acb37df02b..3fe039e1b6 100644
--- a/core/os/thread_safe.cpp
+++ b/core/os/thread_safe.cpp
@@ -29,8 +29,9 @@
/*************************************************************************/
#include "thread_safe.h"
-#include "error_macros.h"
-#include "os/memory.h"
+
+#include "core/error_macros.h"
+#include "core/os/memory.h"
ThreadSafe::ThreadSafe() {
diff --git a/core/os/thread_safe.h b/core/os/thread_safe.h
index f0876f38a1..a17ceeed1d 100644
--- a/core/os/thread_safe.h
+++ b/core/os/thread_safe.h
@@ -31,7 +31,7 @@
#ifndef THREAD_SAFE_H
#define THREAD_SAFE_H
-#include "os/mutex.h"
+#include "core/os/mutex.h"
class ThreadSafe {
diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h
index 3ff7db2a44..89c3b7cec3 100644
--- a/core/os/threaded_array_processor.h
+++ b/core/os/threaded_array_processor.h
@@ -31,11 +31,11 @@
#ifndef THREADED_ARRAY_PROCESSOR_H
#define THREADED_ARRAY_PROCESSOR_H
-#include "os/mutex.h"
-#include "os/os.h"
-#include "os/thread.h"
-#include "safe_refcount.h"
-#include "thread_safe.h"
+#include "core/os/mutex.h"
+#include "core/os/os.h"
+#include "core/os/thread.h"
+#include "core/os/thread_safe.h"
+#include "core/safe_refcount.h"
template <class C, class U>
struct ThreadArrayProcessData {
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index 45e060fa4a..e4ca8fafa5 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -30,8 +30,8 @@
#include "packed_data_container.h"
-#include "core_string_names.h"
-#include "io/marshalls.h"
+#include "core/core_string_names.h"
+#include "core/io/marshalls.h"
Variant PackedDataContainer::getvar(const Variant &p_key, bool *r_valid) const {
diff --git a/core/packed_data_container.h b/core/packed_data_container.h
index fe36417000..0e1dff1f70 100644
--- a/core/packed_data_container.h
+++ b/core/packed_data_container.h
@@ -31,7 +31,7 @@
#ifndef PACKED_DATA_CONTAINER_H
#define PACKED_DATA_CONTAINER_H
-#include "resource.h"
+#include "core/resource.h"
class PackedDataContainer : public Resource {
diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp
index 8952314212..6997c993f4 100644
--- a/core/pool_allocator.cpp
+++ b/core/pool_allocator.cpp
@@ -30,11 +30,11 @@
#include "pool_allocator.h"
+#include "core/error_macros.h"
+#include "core/os/copymem.h"
+#include "core/os/memory.h"
#include "core/os/os.h"
-#include "error_macros.h"
-#include "os/copymem.h"
-#include "os/memory.h"
-#include "print_string.h"
+#include "core/print_string.h"
#include <assert.h>
diff --git a/core/pool_allocator.h b/core/pool_allocator.h
index d9731aa3eb..12e2b597db 100644
--- a/core/pool_allocator.h
+++ b/core/pool_allocator.h
@@ -31,7 +31,7 @@
#ifndef POOL_ALLOCATOR_H
#define POOL_ALLOCATOR_H
-#include "typedefs.h"
+#include "core/typedefs.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/core/print_string.cpp b/core/print_string.cpp
index e1e42d2b56..f53d50e078 100644
--- a/core/print_string.cpp
+++ b/core/print_string.cpp
@@ -30,7 +30,7 @@
#include "print_string.h"
-#include "os/os.h"
+#include "core/os/os.h"
#include <stdio.h>
diff --git a/core/print_string.h b/core/print_string.h
index c1d2d0ff3a..8f4fbb1f7b 100644
--- a/core/print_string.h
+++ b/core/print_string.h
@@ -31,7 +31,7 @@
#ifndef PRINT_STRING_H
#define PRINT_STRING_H
-#include "ustring.h"
+#include "core/ustring.h"
extern void (*_print_func)(String);
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 890789ec6f..407bb78375 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -30,16 +30,17 @@
#include "project_settings.h"
-#include "bind/core_bind.h"
-#include "core_string_names.h"
-#include "io/file_access_network.h"
-#include "io/file_access_pack.h"
-#include "io/marshalls.h"
-#include "os/dir_access.h"
-#include "os/file_access.h"
-#include "os/keyboard.h"
-#include "os/os.h"
-#include "variant_parser.h"
+#include "core/bind/core_bind.h"
+#include "core/core_string_names.h"
+#include "core/io/file_access_network.h"
+#include "core/io/file_access_pack.h"
+#include "core/io/marshalls.h"
+#include "core/os/dir_access.h"
+#include "core/os/file_access.h"
+#include "core/os/keyboard.h"
+#include "core/os/os.h"
+#include "core/variant_parser.h"
+
#include <zlib.h>
#define FORMAT_VERSION 4
@@ -59,7 +60,7 @@ String ProjectSettings::get_resource_path() const {
String ProjectSettings::localize_path(const String &p_path) const {
if (resource_path == "")
- return p_path; //not initialied yet
+ return p_path; //not initialized yet
if (p_path.begins_with("res://") || p_path.begins_with("user://") ||
(p_path.is_abs_path() && !p_path.begins_with(resource_path)))
@@ -287,9 +288,28 @@ void ProjectSettings::_convert_to_last_version() {
}
}
+/*
+ * This method is responsible for loading a project.godot file and/or data file
+ * using the following merit order:
+ * - If using NetworkClient, try to lookup project file or fail.
+ * - If --main-pack was passed by the user (`p_main_pack`), load it or fail.
+ * - Search for .pck file matching binary name. There are two possibilities:
+ * o exec_path.get_basename() + '.pck' (e.g. 'win_game.exe' -> 'win_game.pck')
+ * o exec_path + '.pck' (e.g. 'linux_game' -> 'linux_game.pck')
+ * For each tentative, if the file exists, load it or fail.
+ * - On relevant platforms (Android/iOS), lookup project file in OS resource path.
+ * If found, load it or fail.
+ * - Lookup project file in passed `p_path` (--path passed by the user), i.e. we
+ * are running from source code.
+ * If not found and `p_upwards` is true (--upwards passed by the user), look for
+ * project files in parent folders up to the system root (used to run a game
+ * from command line while in a subfolder).
+ * If a project file is found, load it or fail.
+ * If nothing was found, error out.
+ */
Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards) {
- //If looking for files in network, just use network!
+ // If looking for files in a network client, use it directly
if (FileAccessNetworkClient::get_singleton()) {
@@ -301,9 +321,7 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
return err;
}
- String exec_path = OS::get_singleton()->get_executable_path();
-
- //Attempt with a passed main pack first
+ // Attempt with a user-defined main pack first
if (p_main_pack != "") {
@@ -319,25 +337,39 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
return err;
}
- //Attempt with execname.pck
+ // Attempt with exec_name.pck
+ // (This is the usual case when distributing a Godot game.)
+
+ // Based on the OS, it can be the exec path + '.pck' (Linux w/o extension, macOS in .app bundle)
+ // or the exec path's basename + '.pck' (Windows).
+ // We need to test both possibilities as extensions for Linux binaries are optional
+ // (so both 'mygame.bin' and 'mygame' should be able to find 'mygame.pck').
+
+ String exec_path = OS::get_singleton()->get_executable_path();
+
if (exec_path != "") {
bool found = false;
- // get our filename without our path (note, using exec_path.get_file before get_basename anymore because not all file systems have dots in their file names!)
- String filebase_name = exec_path.get_file().get_basename();
+ String exec_dir = exec_path.get_base_dir();
+ String exec_filename = exec_path.get_file();
+ String exec_basename = exec_filename.get_basename();
+
+ // Try to load data pack at the location of the executable
+ // As mentioned above, we have two potential names to attempt
- // try to open at the location of executable
- String datapack_name = exec_path.get_base_dir().plus_file(filebase_name) + ".pck";
- if (_load_resource_pack(datapack_name)) {
+ if (_load_resource_pack(exec_dir.plus_file(exec_basename + ".pck")) ||
+ _load_resource_pack(exec_dir.plus_file(exec_filename + ".pck"))) {
found = true;
} else {
- datapack_name = filebase_name + ".pck";
- if (_load_resource_pack(datapack_name)) {
+ // If we couldn't find them next to the executable, we attempt
+ // the current working directory. Same story, two tests.
+ if (_load_resource_pack(exec_basename + ".pck") ||
+ _load_resource_pack(exec_filename + ".pck")) {
found = true;
}
}
- // if we opened our package, try and load our project...
+ // If we opened our package, try and load our project
if (found) {
Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
if (err == OK) {
@@ -349,17 +381,15 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
}
}
- //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 overridden!
- //if the OS would rather use somewhere else, then it will not be empty.
+ // 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 ProjectSettings->get_resource_path which will be empty if not overridden!
+ // If the OS would rather use a specific location, 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] == '/')
+ if (resource_path != "" && resource_path[resource_path.length() - 1] == '/') {
resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end
-
- // data.pck and data.zip are deprecated and no longer supported, apologies.
- // make sure this is loaded from the resource path
+ }
Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
if (err == OK) {
@@ -370,21 +400,19 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
return err;
}
- //Nothing was found, try to find a project.godot somewhere!
+ // Nothing was found, try to find a project file in provided path (`p_path`)
+ // or, if requested (`p_upwards`) in parent directories.
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
ERR_FAIL_COND_V(!d, ERR_CANT_CREATE);
-
d->change_dir(p_path);
- String candidate = d->get_current_dir();
String current_dir = d->get_current_dir();
-
+ String candidate = current_dir;
bool found = false;
Error err;
while (true) {
-
err = _load_settings_text_or_binary(current_dir.plus_file("project.godot"), current_dir.plus_file("project.binary"));
if (err == OK) {
// Optional, we don't mind if it fails
@@ -395,10 +423,10 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
}
if (p_upwards) {
- // Try to load settings ascending through dirs shape!
+ // Try to load settings ascending through parent directories
d->change_dir("..");
if (d->get_current_dir() == current_dir)
- break; //not doing anything useful
+ break; // not doing anything useful
current_dir = d->get_current_dir();
} else {
break;
@@ -415,6 +443,8 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
if (resource_path.length() && resource_path[resource_path.length() - 1] == '/')
resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end
+ // If we're loading a project.godot from source code, we can operate some
+ // ProjectSettings conversions if need be.
_convert_to_last_version();
return OK;
@@ -1132,6 +1162,7 @@ ProjectSettings::ProjectSettings() {
custom_prop_info["rendering/quality/intended_usage/framebuffer_allocation"] = PropertyInfo(Variant::INT, "rendering/quality/intended_usage/framebuffer_allocation", PROPERTY_HINT_ENUM, "2D,2D Without Sampling,3D,3D Without Effects");
GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
+ custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
//assigning here, because using GLOBAL_GET on every block for compressing can be slow
Compression::zstd_long_distance_matching = GLOBAL_DEF("compression/formats/zstd/long_distance_matching", false);
diff --git a/core/project_settings.h b/core/project_settings.h
index 75ebc5acc8..611355f2ef 100644
--- a/core/project_settings.h
+++ b/core/project_settings.h
@@ -31,9 +31,10 @@
#ifndef GLOBAL_CONFIG_H
#define GLOBAL_CONFIG_H
-#include "object.h"
-#include "os/thread_safe.h"
-#include "set.h"
+#include "core/object.h"
+#include "core/os/thread_safe.h"
+#include "core/set.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/ref_ptr.cpp b/core/ref_ptr.cpp
index e3ef817df1..7f0cc0cd75 100644
--- a/core/ref_ptr.cpp
+++ b/core/ref_ptr.cpp
@@ -30,8 +30,8 @@
#include "ref_ptr.h"
-#include "reference.h"
-#include "resource.h"
+#include "core/reference.h"
+#include "core/resource.h"
void RefPtr::operator=(const RefPtr &p_other) {
diff --git a/core/ref_ptr.h b/core/ref_ptr.h
index a074718d22..3f15c680b8 100644
--- a/core/ref_ptr.h
+++ b/core/ref_ptr.h
@@ -36,7 +36,7 @@
* It's basically an opaque container of a Reference reference, so Variant can use it.
*/
-#include "rid.h"
+#include "core/rid.h"
class RefPtr {
diff --git a/core/reference.cpp b/core/reference.cpp
index 6e1520d81d..b79ad0bf3d 100644
--- a/core/reference.cpp
+++ b/core/reference.cpp
@@ -30,7 +30,7 @@
#include "reference.h"
-#include "script_language.h"
+#include "core/script_language.h"
bool Reference::init_ref() {
diff --git a/core/reference.h b/core/reference.h
index 25e02180fa..4c607fed87 100644
--- a/core/reference.h
+++ b/core/reference.h
@@ -31,10 +31,10 @@
#ifndef REFERENCE_H
#define REFERENCE_H
-#include "class_db.h"
-#include "object.h"
-#include "ref_ptr.h"
-#include "safe_refcount.h"
+#include "core/class_db.h"
+#include "core/object.h"
+#include "core/ref_ptr.h"
+#include "core/safe_refcount.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 859015f44b..430004bb96 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -30,40 +30,40 @@
#include "register_core_types.h"
-#include "bind/core_bind.h"
-#include "class_db.h"
-#include "compressed_translation.h"
+#include "core/bind/core_bind.h"
+#include "core/class_db.h"
+#include "core/compressed_translation.h"
+#include "core/core_string_names.h"
+#include "core/engine.h"
+#include "core/func_ref.h"
+#include "core/input_map.h"
+#include "core/io/config_file.h"
+#include "core/io/http_client.h"
+#include "core/io/image_loader.h"
+#include "core/io/marshalls.h"
+#include "core/io/multiplayer_api.h"
+#include "core/io/networked_multiplayer_peer.h"
+#include "core/io/packet_peer.h"
+#include "core/io/packet_peer_udp.h"
+#include "core/io/pck_packer.h"
+#include "core/io/resource_format_binary.h"
+#include "core/io/resource_import.h"
+#include "core/io/stream_peer_ssl.h"
+#include "core/io/tcp_server.h"
+#include "core/io/translation_loader_po.h"
#include "core/io/xml_parser.h"
-#include "core_string_names.h"
-#include "engine.h"
-#include "func_ref.h"
-#include "geometry.h"
-#include "input_map.h"
-#include "io/config_file.h"
-#include "io/http_client.h"
-#include "io/image_loader.h"
-#include "io/marshalls.h"
-#include "io/multiplayer_api.h"
-#include "io/networked_multiplayer_peer.h"
-#include "io/packet_peer.h"
-#include "io/packet_peer_udp.h"
-#include "io/pck_packer.h"
-#include "io/resource_format_binary.h"
-#include "io/resource_import.h"
-#include "io/stream_peer_ssl.h"
-#include "io/tcp_server.h"
-#include "io/translation_loader_po.h"
-#include "math/a_star.h"
-#include "math/expression.h"
-#include "math/triangle_mesh.h"
-#include "os/input.h"
-#include "os/main_loop.h"
-#include "packed_data_container.h"
-#include "path_remap.h"
-#include "project_settings.h"
-#include "translation.h"
-
-#include "undo_redo.h"
+#include "core/math/a_star.h"
+#include "core/math/expression.h"
+#include "core/math/geometry.h"
+#include "core/math/triangle_mesh.h"
+#include "core/os/input.h"
+#include "core/os/main_loop.h"
+#include "core/packed_data_container.h"
+#include "core/path_remap.h"
+#include "core/project_settings.h"
+#include "core/translation.h"
+#include "core/undo_redo.h"
+
static ResourceFormatSaverBinary *resource_saver_binary = NULL;
static ResourceFormatLoaderBinary *resource_loader_binary = NULL;
static ResourceFormatImporter *resource_format_importer = NULL;
@@ -146,9 +146,9 @@ void register_core_types() {
ClassDB::register_class<FuncRef>();
ClassDB::register_virtual_class<StreamPeer>();
ClassDB::register_class<StreamPeerBuffer>();
- ClassDB::register_custom_instance_class<StreamPeerTCP>();
- ClassDB::register_custom_instance_class<TCP_Server>();
- ClassDB::register_custom_instance_class<PacketPeerUDP>();
+ ClassDB::register_class<StreamPeerTCP>();
+ ClassDB::register_class<TCP_Server>();
+ ClassDB::register_class<PacketPeerUDP>();
ClassDB::register_custom_instance_class<StreamPeerSSL>();
ClassDB::register_virtual_class<IP>();
ClassDB::register_virtual_class<PacketPeer>();
@@ -156,7 +156,6 @@ void register_core_types() {
ClassDB::register_virtual_class<NetworkedMultiplayerPeer>();
ClassDB::register_class<MultiplayerAPI>();
ClassDB::register_class<MainLoop>();
- //ClassDB::register_type<OptimizedSaver>();
ClassDB::register_class<Translation>();
ClassDB::register_class<PHashTranslation>();
ClassDB::register_class<UndoRedo>();
@@ -200,6 +199,7 @@ void register_core_types() {
void register_core_settings() {
//since in register core types, globals may not e present
GLOBAL_DEF_RST("network/limits/packet_peer_stream/max_buffer_po2", (16));
+ ProjectSettings::get_singleton()->set_custom_property_info("network/limits/packet_peer_stream/max_buffer_po2", PropertyInfo(Variant::INT, "network/limits/packet_peer_stream/max_buffer_po2", PROPERTY_HINT_RANGE, "0,64,1,or_greater"));
}
void register_core_singletons() {
diff --git a/core/resource.cpp b/core/resource.cpp
index f447f785b1..4dcd338e94 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -30,11 +30,12 @@
#include "resource.h"
-#include "core_string_names.h"
-#include "io/resource_loader.h"
-#include "os/file_access.h"
+#include "core/core_string_names.h"
+#include "core/io/resource_loader.h"
+#include "core/os/file_access.h"
+#include "core/script_language.h"
#include "scene/main/node.h" //only so casting works
-#include "script_language.h"
+
#include <stdio.h>
void Resource::emit_changed() {
diff --git a/core/resource.h b/core/resource.h
index 60c63bfe7f..b2812c11e1 100644
--- a/core/resource.h
+++ b/core/resource.h
@@ -31,12 +31,12 @@
#ifndef RESOURCE_H
#define RESOURCE_H
-#include "class_db.h"
-#include "object.h"
-#include "ref_ptr.h"
-#include "reference.h"
-#include "safe_refcount.h"
-#include "self_list.h"
+#include "core/class_db.h"
+#include "core/object.h"
+#include "core/ref_ptr.h"
+#include "core/reference.h"
+#include "core/safe_refcount.h"
+#include "core/self_list.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
diff --git a/core/rid.h b/core/rid.h
index 42306aea36..81d5b45d21 100644
--- a/core/rid.h
+++ b/core/rid.h
@@ -31,11 +31,11 @@
#ifndef RID_H
#define RID_H
-#include "list.h"
-#include "os/memory.h"
-#include "safe_refcount.h"
-#include "set.h"
-#include "typedefs.h"
+#include "core/list.h"
+#include "core/os/memory.h"
+#include "core/safe_refcount.h"
+#include "core/set.h"
+#include "core/typedefs.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
@@ -118,7 +118,6 @@ protected:
p_rid._data->_owner = NULL;
}
-#
#endif
public:
diff --git a/core/ring_buffer.h b/core/ring_buffer.h
index 00628a4ab3..2516880064 100644
--- a/core/ring_buffer.h
+++ b/core/ring_buffer.h
@@ -31,7 +31,7 @@
#ifndef RINGBUFFER_H
#define RINGBUFFER_H
-#include "vector.h"
+#include "core/vector.h"
template <typename T>
class RingBuffer {
diff --git a/core/safe_refcount.h b/core/safe_refcount.h
index 36bcf5e576..940d31b2cb 100644
--- a/core/safe_refcount.h
+++ b/core/safe_refcount.h
@@ -31,11 +31,9 @@
#ifndef SAFE_REFCOUNT_H
#define SAFE_REFCOUNT_H
-#include "os/mutex.h"
-/* x86/x86_64 GCC */
-
+#include "core/os/mutex.h"
+#include "core/typedefs.h"
#include "platform_config.h"
-#include "typedefs.h"
// Atomic functions, these are used for multithread safe reference counters!
diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp
index 6949b5802b..7093c3ebdb 100644
--- a/core/script_debugger_local.cpp
+++ b/core/script_debugger_local.cpp
@@ -29,9 +29,9 @@
/*************************************************************************/
#include "script_debugger_local.h"
-#include "scene/main/scene_tree.h"
-#include "os/os.h"
+#include "core/os/os.h"
+#include "scene/main/scene_tree.h"
void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue) {
diff --git a/core/script_debugger_local.h b/core/script_debugger_local.h
index 7eea6ef215..1f7b5c590c 100644
--- a/core/script_debugger_local.h
+++ b/core/script_debugger_local.h
@@ -31,8 +31,8 @@
#ifndef SCRIPT_DEBUGGER_LOCAL_H
#define SCRIPT_DEBUGGER_LOCAL_H
-#include "list.h"
-#include "script_language.h"
+#include "core/list.h"
+#include "core/script_language.h"
class ScriptDebuggerLocal : public ScriptDebugger {
diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp
index 2b9b5d6037..621a94ab1a 100644
--- a/core/script_debugger_remote.cpp
+++ b/core/script_debugger_remote.cpp
@@ -30,12 +30,12 @@
#include "script_debugger_remote.h"
-#include "engine.h"
-#include "io/ip.h"
-#include "io/marshalls.h"
-#include "os/input.h"
-#include "os/os.h"
-#include "project_settings.h"
+#include "core/engine.h"
+#include "core/io/ip.h"
+#include "core/io/marshalls.h"
+#include "core/os/input.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
#include "scene/main/node.h"
#include "scene/resources/packed_scene.h"
@@ -77,18 +77,19 @@ Error ScriptDebuggerRemote::connect_to_host(const String &p_host, uint16_t p_por
for (int i = 0; i < tries; i++) {
if (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED) {
+ print_verbose("Remote Debugger: Connected!");
break;
} else {
const int ms = waits[i];
OS::get_singleton()->delay_usec(ms * 1000);
- ERR_PRINTS("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec.");
+ print_verbose("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec.");
};
};
if (tcp_client->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
- ERR_PRINTS("Remote Debugger: Unable to connect.");
+ ERR_PRINTS("Remote Debugger: Unable to connect. Status: " + String::num(tcp_client->get_status()));
return FAILED;
};
@@ -97,36 +98,6 @@ Error ScriptDebuggerRemote::connect_to_host(const String &p_host, uint16_t p_por
return OK;
}
-static int _ScriptDebuggerRemote_found_id = 0;
-static Object *_ScriptDebuggerRemote_find = NULL;
-static void _ScriptDebuggerRemote_debug_func(Object *p_obj) {
-
- if (_ScriptDebuggerRemote_find == p_obj) {
- _ScriptDebuggerRemote_found_id = p_obj->get_instance_id();
- }
-}
-
-static ObjectID safe_get_instance_id(const Variant &p_v) {
-
- Object *o = p_v;
- if (o == NULL)
- return 0;
- else {
-
- REF r = p_v;
- if (r.is_valid()) {
-
- return r->get_instance_id();
- } else {
-
- _ScriptDebuggerRemote_found_id = 0;
- _ScriptDebuggerRemote_find = NULL;
- ObjectDB::debug_objects(_ScriptDebuggerRemote_debug_func);
- return _ScriptDebuggerRemote_found_id;
- }
- }
-}
-
void ScriptDebuggerRemote::_put_variable(const String &p_name, const Variant &p_variable) {
packet_peer_stream->put_var(p_name);
@@ -607,8 +578,14 @@ void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) {
for (ScriptConstantsMap::Element *sc = constants.front(); sc; sc = sc->next()) {
for (Map<StringName, Variant>::Element *E = sc->get().front(); E; E = E->next()) {
String script_path = sc->key() == si->get_script().ptr() ? "" : sc->key()->get_path().get_file() + "/";
- PropertyInfo pi(E->value().get_type(), "Constants/" + script_path + E->key());
- properties.push_back(PropertyDesc(pi, E->value()));
+ if (E->value().get_type() == Variant::OBJECT) {
+ Variant id = ((Object *)E->value())->get_instance_id();
+ PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
+ properties.push_back(PropertyDesc(pi, id));
+ } else {
+ PropertyInfo pi(E->value().get_type(), "Constants/" + script_path + E->key());
+ properties.push_back(PropertyDesc(pi, E->value()));
+ }
}
}
}
@@ -621,8 +598,14 @@ void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) {
Map<StringName, Variant> constants;
s->get_constants(&constants);
for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) {
- PropertyInfo pi(E->value().get_type(), String("Constants/") + E->key());
- properties.push_front(PropertyDesc(pi, E->value()));
+ if (E->value().get_type() == Variant::OBJECT) {
+ Variant id = ((Object *)E->value())->get_instance_id();
+ PropertyInfo pi(id.get_type(), "Constants/" + E->key(), PROPERTY_HINT_OBJECT_ID, "Object");
+ properties.push_front(PropertyDesc(pi, E->value()));
+ } else {
+ PropertyInfo pi(E->value().get_type(), String("Constants/") + E->key());
+ properties.push_front(PropertyDesc(pi, E->value()));
+ }
}
}
}
@@ -661,11 +644,13 @@ void ScriptDebuggerRemote::_send_object_id(ObjectID p_id) {
prop.push_back(Variant());
} else {
prop.push_back(pi.hint);
- if (res.is_null())
- prop.push_back(pi.hint_string);
- else
- prop.push_back(String("RES:") + res->get_path());
+ prop.push_back(pi.hint_string);
prop.push_back(pi.usage);
+
+ if (!res.is_null()) {
+ var = res->get_path();
+ }
+
prop.push_back(var);
}
send_props.push_back(prop);
@@ -1084,18 +1069,18 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() :
max_frame_functions(16),
skip_profile_frame(false),
reload_all_scripts(false),
- tcp_client(StreamPeerTCP::create_ref()),
+ tcp_client(Ref<StreamPeerTCP>(memnew(StreamPeerTCP))),
packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))),
last_perf_time(0),
performance(Engine::get_singleton()->get_singleton_object("Performance")),
requested_quit(false),
mutex(Mutex::create()),
- max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")),
max_messages_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_messages_per_frame")),
- max_errors_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_errors_per_frame")),
- char_count(0),
n_messages_dropped(0),
+ max_errors_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_errors_per_frame")),
n_errors_dropped(0),
+ max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")),
+ char_count(0),
last_msec(0),
msec_count(0),
allow_focus_steal_pid(0),
@@ -1115,7 +1100,7 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() :
eh.userdata = this;
add_error_handler(&eh);
- profile_info.resize(CLAMP(int(ProjectSettings::get_singleton()->get("debug/settings/profiler/max_functions")), 128, 65535));
+ profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions"));
profile_info_ptrs.resize(profile_info.size());
}
diff --git a/core/script_debugger_remote.h b/core/script_debugger_remote.h
index b68fc4f9c9..5cd3a23a37 100644
--- a/core/script_debugger_remote.h
+++ b/core/script_debugger_remote.h
@@ -31,11 +31,11 @@
#ifndef SCRIPT_DEBUGGER_REMOTE_H
#define SCRIPT_DEBUGGER_REMOTE_H
-#include "io/packet_peer.h"
-#include "io/stream_peer_tcp.h"
-#include "list.h"
-#include "os/os.h"
-#include "script_language.h"
+#include "core/io/packet_peer.h"
+#include "core/io/stream_peer_tcp.h"
+#include "core/list.h"
+#include "core/os/os.h"
+#include "core/script_language.h"
class ScriptDebuggerRemote : public ScriptDebugger {
diff --git a/core/script_language.cpp b/core/script_language.cpp
index e146fb773c..5b65da9ef1 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -29,7 +29,8 @@
/*************************************************************************/
#include "script_language.h"
-#include "project_settings.h"
+
+#include "core/project_settings.h"
ScriptLanguage *ScriptServer::_languages[MAX_LANGUAGES];
int ScriptServer::_language_count = 0;
diff --git a/core/script_language.h b/core/script_language.h
index 573e7b4fa1..bcd9c2c5ea 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -31,10 +31,11 @@
#ifndef SCRIPT_LANGUAGE_H
#define SCRIPT_LANGUAGE_H
-#include "io/multiplayer_api.h"
-#include "map.h"
-#include "pair.h"
-#include "resource.h"
+#include "core/io/multiplayer_api.h"
+#include "core/map.h"
+#include "core/pair.h"
+#include "core/resource.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/self_list.h b/core/self_list.h
index 6e84e1cd5f..9a4ecdeef9 100644
--- a/core/self_list.h
+++ b/core/self_list.h
@@ -31,7 +31,7 @@
#ifndef SELF_LIST_H
#define SELF_LIST_H
-#include "typedefs.h"
+#include "core/typedefs.h"
template <class T>
class SelfList {
diff --git a/core/set.h b/core/set.h
index d79dd81644..59aa54128e 100644
--- a/core/set.h
+++ b/core/set.h
@@ -31,8 +31,8 @@
#ifndef SET_H
#define SET_H
-#include "os/memory.h"
-#include "typedefs.h"
+#include "core/os/memory.h"
+#include "core/typedefs.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
@@ -595,6 +595,7 @@ public:
return e;
}
+ inline bool empty() const { return _data.size_cache == 0; }
inline int size() const { return _data.size_cache; }
int calculate_depth() const {
diff --git a/core/sort.h b/core/sort.h
index 97983829e1..e112304d1b 100644
--- a/core/sort.h
+++ b/core/sort.h
@@ -31,10 +31,7 @@
#ifndef SORT_H
#define SORT_H
-#include "typedefs.h"
-/**
- @author ,,, <red@lunatea>
-*/
+#include "core/typedefs.h"
#define ERR_BAD_COMPARE(cond) \
if (unlikely(cond)) { \
diff --git a/core/string_buffer.h b/core/string_buffer.h
index 5d3be0ecf1..38dce5e6bf 100644
--- a/core/string_buffer.h
+++ b/core/string_buffer.h
@@ -31,8 +31,7 @@
#ifndef STRING_BUFFER_H
#define STRING_BUFFER_H
-#include "ustring.h"
-#include <string.h>
+#include "core/ustring.h"
template <int SHORT_BUFFER_SIZE = 64>
class StringBuffer {
diff --git a/core/string_db.cpp b/core/string_db.cpp
index 067e4493a1..a798df8795 100644
--- a/core/string_db.cpp
+++ b/core/string_db.cpp
@@ -30,8 +30,8 @@
#include "string_db.h"
-#include "os/os.h"
-#include "print_string.h"
+#include "core/os/os.h"
+#include "core/print_string.h"
StaticCString StaticCString::create(const char *p_ptr) {
StaticCString scs;
diff --git a/core/string_db.h b/core/string_db.h
index 965385b136..46bb77df93 100644
--- a/core/string_db.h
+++ b/core/string_db.h
@@ -31,9 +31,9 @@
#ifndef STRING_DB_H
#define STRING_DB_H
-#include "os/mutex.h"
-#include "safe_refcount.h"
-#include "ustring.h"
+#include "core/os/mutex.h"
+#include "core/safe_refcount.h"
+#include "core/ustring.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
diff --git a/core/translation.cpp b/core/translation.cpp
index 82a16d0b17..25e67e9b96 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -30,9 +30,9 @@
#include "translation.h"
-#include "io/resource_loader.h"
-#include "os/os.h"
-#include "project_settings.h"
+#include "core/io/resource_loader.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
// ISO 639-1 language codes, with the addition of glibc locales with their
// regional identifiers. This list must match the language names (in English)
@@ -938,11 +938,14 @@ void TranslationServer::set_locale(const String &p_locale) {
if (!is_locale_valid(univ_locale)) {
String trimmed_locale = get_trimmed_locale(univ_locale);
+ print_verbose(vformat("Unsupported locale '%s', falling back to '%s'.", p_locale, trimmed_locale));
- ERR_EXPLAIN("Invalid locale: " + trimmed_locale);
- ERR_FAIL_COND(!is_locale_valid(trimmed_locale));
-
- locale = trimmed_locale;
+ if (!is_locale_valid(trimmed_locale)) {
+ ERR_PRINTS(vformat("Unsupported locale '%s', falling back to 'en'.", trimmed_locale));
+ locale = "en";
+ } else {
+ locale = trimmed_locale;
+ }
} else {
locale = univ_locale;
}
diff --git a/core/translation.h b/core/translation.h
index e7c0dcbc07..be626f4eb9 100644
--- a/core/translation.h
+++ b/core/translation.h
@@ -31,7 +31,7 @@
#ifndef TRANSLATION_H
#define TRANSLATION_H
-#include "resource.h"
+#include "core/resource.h"
class Translation : public Resource {
diff --git a/core/typedefs.h b/core/typedefs.h
index 094f1bbfd5..5c15da9c2d 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -32,6 +32,7 @@
#define TYPEDEFS_H
#include <stddef.h>
+
/**
* Basic definitions and simple functions to be used everywhere.
*/
@@ -43,6 +44,7 @@
#define _MKSTR(m_x) _STR(m_x)
#endif
+//should always inline no matter what
#ifndef _ALWAYS_INLINE_
#if defined(__GNUC__) && (__GNUC__ >= 4)
@@ -57,10 +59,17 @@
#endif
+//should always inline, except in some cases because it makes debugging harder
#ifndef _FORCE_INLINE_
+
+#ifdef DISABLE_FORCED_INLINE
+#define _FORCE_INLINE_ inline
+#else
#define _FORCE_INLINE_ _ALWAYS_INLINE_
#endif
+#endif
+
//custom, gcc-safe offsetof, because gcc complains a lot.
template <class T>
T *_nullptr() {
@@ -96,19 +105,19 @@ T *_nullptr() {
#undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enum
#endif
-#include "int_types.h"
+#include "core/int_types.h"
-#include "error_list.h"
-#include "error_macros.h"
+#include "core/error_list.h"
+#include "core/error_macros.h"
/** Generic ABS function, for math uses please use Math::abs */
#ifndef ABS
-#define ABS(m_v) ((m_v < 0) ? (-(m_v)) : (m_v))
+#define ABS(m_v) (((m_v) < 0) ? (-(m_v)) : (m_v))
#endif
#ifndef SGN
-#define SGN(m_v) ((m_v < 0) ? (-1.0) : (+1.0))
+#define SGN(m_v) (((m_v) < 0) ? (-1.0) : (+1.0))
#endif
#ifndef MIN
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index 3d90608dd7..7d67076df5 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -30,7 +30,7 @@
#include "undo_redo.h"
-#include "os/os.h"
+#include "core/os/os.h"
void UndoRedo::_discard_redo() {
diff --git a/core/undo_redo.h b/core/undo_redo.h
index 3a17c78851..22dcd60472 100644
--- a/core/undo_redo.h
+++ b/core/undo_redo.h
@@ -31,8 +31,8 @@
#ifndef UNDO_REDO_H
#define UNDO_REDO_H
-#include "object.h"
-#include "resource.h"
+#include "core/object.h"
+#include "core/resource.h"
class UndoRedo : public Object {
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 96e3a3d784..2191bb5e23 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -30,12 +30,13 @@
#include "ustring.h"
-#include "color.h"
-#include "math_funcs.h"
-#include "os/memory.h"
-#include "print_string.h"
-#include "ucaps.h"
-#include "variant.h"
+#include "core/color.h"
+#include "core/math/math_funcs.h"
+#include "core/os/memory.h"
+#include "core/print_string.h"
+#include "core/translation.h"
+#include "core/ucaps.h"
+#include "core/variant.h"
#include "thirdparty/misc/md5.h"
#include "thirdparty/misc/sha256.h"
@@ -48,7 +49,7 @@
#endif
#if defined(MINGW_ENABLED) || defined(_MSC_VER)
-#define snprintf _snprintf
+#define snprintf _snprintf_s
#endif
#define MAX_DIGITS 6
@@ -585,6 +586,8 @@ String String::camelcase_to_underscore(bool lowercase) const {
bool is_upper = cstr[i] >= A && cstr[i] <= Z;
bool is_number = cstr[i] >= '0' && cstr[i] <= '9';
bool are_next_2_lower = false;
+ bool is_next_lower = false;
+ bool is_next_number = false;
bool was_precedent_upper = cstr[i - 1] >= A && cstr[i - 1] <= Z;
bool was_precedent_number = cstr[i - 1] >= '0' && cstr[i - 1] <= '9';
@@ -592,7 +595,18 @@ String String::camelcase_to_underscore(bool lowercase) const {
are_next_2_lower = cstr[i + 1] >= a && cstr[i + 1] <= z && cstr[i + 2] >= a && cstr[i + 2] <= z;
}
- bool should_split = ((is_upper && !was_precedent_upper && !was_precedent_number) || (was_precedent_upper && is_upper && are_next_2_lower) || (is_number && !was_precedent_number));
+ if (i + 1 < this->size()) {
+ is_next_lower = cstr[i + 1] >= a && cstr[i + 1] <= z;
+ is_next_number = cstr[i + 1] >= '0' && cstr[i + 1] <= '9';
+ }
+
+ const bool a = is_upper && !was_precedent_upper && !was_precedent_number;
+ const bool b = was_precedent_upper && is_upper && are_next_2_lower;
+ const bool c = is_number && !was_precedent_number;
+ const bool can_break_number_letter = is_number && !was_precedent_number && is_next_lower;
+ const bool can_break_letter_number = !is_number && was_precedent_number && (is_next_lower || is_next_number);
+
+ bool should_split = a || b || c || can_break_number_letter || can_break_letter_number;
if (should_split) {
new_string += this->substr(start_index, i - start_index) + "_";
start_index = i;
@@ -1827,8 +1841,8 @@ static double built_in_strtod(const C *string, /* A decimal ASCII floating-point
int sign, expSign = false;
double fraction, dblExp;
const double *d;
- register const C *p;
- register int c;
+ const C *p;
+ int c;
int exp = 0; /* Exponent read from "EX" field. */
int fracExp = 0; /* Exponent that derives from the fractional
* part. Under normal circumstances, it is
@@ -2760,16 +2774,13 @@ String String::format(const Variant &values, String placeholder) const {
if (value_arr.size() == 2) {
Variant v_key = value_arr[0];
- String key;
-
- key = v_key.get_construct_string();
+ String key = v_key;
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();
+ String val = v_val;
if (val.left(1) == "\"" && val.right(val.length() - 1) == "\"") {
val = val.substr(1, val.length() - 2);
@@ -2781,8 +2792,7 @@ String String::format(const Variant &values, String placeholder) const {
}
} else { //Array structure ["RobotGuy","Logis","rookie"]
Variant v_val = values_arr[i];
- String val;
- val = v_val.get_construct_string();
+ String val = v_val;
if (val.left(1) == "\"" && val.right(val.length() - 1) == "\"") {
val = val.substr(1, val.length() - 2);
@@ -2801,8 +2811,8 @@ String String::format(const Variant &values, String placeholder) const {
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();
+ String key = E->get();
+ String val = d[E->get()];
if (key.left(1) == "\"" && key.right(key.length() - 1) == "\"") {
key = key.substr(1, key.length() - 2);
@@ -3091,7 +3101,7 @@ String String::simplify_path() const {
} else if (s.begins_with("user://")) {
drive = "user://";
- s = s.substr(6, s.length());
+ s = s.substr(7, s.length());
} else if (s.begins_with("/") || s.begins_with("\\")) {
drive = s.substr(0, 1);
@@ -4204,8 +4214,6 @@ String String::unquote() const {
return substr(1, length() - 2);
}
-#include "translation.h"
-
#ifdef TOOLS_ENABLED
String TTR(const String &p_text) {
diff --git a/core/ustring.h b/core/ustring.h
index 01397f6912..d2766ec7a3 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -28,16 +28,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef RSTRING_H
-#define RSTRING_H
+#ifndef USTRING_H
+#define USTRING_H
-#include "array.h"
-#include "cowdata.h"
-#include "typedefs.h"
-#include "vector.h"
+#include "core/array.h"
+#include "core/cowdata.h"
+#include "core/typedefs.h"
+#include "core/vector.h"
/**
- @author red <red@killy>
+ @author Juan Linietsky <reduzio@gmail.com>
*/
class CharString {
@@ -366,4 +366,4 @@ String RTR(const String &);
bool is_symbol(CharType c);
bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end);
-#endif
+#endif // USTRING_H
diff --git a/core/variant.cpp b/core/variant.cpp
index b0e97900a2..edbe66ba31 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -30,14 +30,14 @@
#include "variant.h"
-#include "core_string_names.h"
-#include "io/marshalls.h"
-#include "math_funcs.h"
-#include "print_string.h"
-#include "resource.h"
+#include "core/core_string_names.h"
+#include "core/io/marshalls.h"
+#include "core/math/math_funcs.h"
+#include "core/print_string.h"
+#include "core/resource.h"
+#include "core/variant_parser.h"
#include "scene/gui/control.h"
#include "scene/main/node.h"
-#include "variant_parser.h"
String Variant::get_type_name(Variant::Type p_type) {
@@ -858,7 +858,7 @@ bool Variant::is_one() const {
// atomic types
case BOOL: {
- return _data._bool == true;
+ return _data._bool;
} break;
case INT: {
diff --git a/core/variant.h b/core/variant.h
index 577a33aa4d..8953217760 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -35,23 +35,23 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
-#include "aabb.h"
-#include "array.h"
-#include "color.h"
-#include "dictionary.h"
-#include "dvector.h"
-#include "face3.h"
-#include "io/ip_address.h"
-#include "matrix3.h"
-#include "node_path.h"
-#include "plane.h"
-#include "quat.h"
-#include "ref_ptr.h"
-#include "rid.h"
-#include "transform.h"
-#include "transform_2d.h"
-#include "ustring.h"
-#include "vector3.h"
+#include "core/array.h"
+#include "core/color.h"
+#include "core/dictionary.h"
+#include "core/dvector.h"
+#include "core/io/ip_address.h"
+#include "core/math/aabb.h"
+#include "core/math/face3.h"
+#include "core/math/matrix3.h"
+#include "core/math/plane.h"
+#include "core/math/quat.h"
+#include "core/math/transform.h"
+#include "core/math/transform_2d.h"
+#include "core/math/vector3.h"
+#include "core/node_path.h"
+#include "core/ref_ptr.h"
+#include "core/rid.h"
+#include "core/ustring.h"
class RefPtr;
class Object;
@@ -116,7 +116,7 @@ public:
};
private:
- friend class _VariantCall;
+ friend struct _VariantCall;
// Variant takes 20 bytes when real_t is float, and 36 if double
// it only allocates extra memory for aabb/matrix.
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 8b18b274b6..8693a584f2 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -31,11 +31,11 @@
#include "variant.h"
#include "core/color_names.inc"
-#include "core_string_names.h"
-#include "io/compression.h"
-#include "object.h"
-#include "os/os.h"
-#include "script_language.h"
+#include "core/core_string_names.h"
+#include "core/io/compression.h"
+#include "core/object.h"
+#include "core/os/os.h"
+#include "core/script_language.h"
typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args);
typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args);
@@ -1895,6 +1895,7 @@ void register_variant_methods() {
_VariantCall::add_constant(Variant::VECTOR3, "AXIS_Z", Vector3::AXIS_Z);
_VariantCall::add_variant_constant(Variant::VECTOR3, "ZERO", Vector3(0, 0, 0));
+ _VariantCall::add_variant_constant(Variant::VECTOR3, "ONE", Vector3(1, 1, 1));
_VariantCall::add_variant_constant(Variant::VECTOR3, "INF", Vector3(Math_INF, Math_INF, Math_INF));
_VariantCall::add_variant_constant(Variant::VECTOR3, "LEFT", Vector3(-1, 0, 0));
_VariantCall::add_variant_constant(Variant::VECTOR3, "RIGHT", Vector3(1, 0, 0));
@@ -1904,6 +1905,7 @@ void register_variant_methods() {
_VariantCall::add_variant_constant(Variant::VECTOR3, "BACK", Vector3(0, 0, 1));
_VariantCall::add_variant_constant(Variant::VECTOR2, "ZERO", Vector2(0, 0));
+ _VariantCall::add_variant_constant(Variant::VECTOR2, "ONE", Vector2(1, 1));
_VariantCall::add_variant_constant(Variant::VECTOR2, "INF", Vector2(Math_INF, Math_INF));
_VariantCall::add_variant_constant(Variant::VECTOR2, "LEFT", Vector2(-1, 0));
_VariantCall::add_variant_constant(Variant::VECTOR2, "RIGHT", Vector2(1, 0));
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index bfa69b1fde..d193858966 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -30,9 +30,9 @@
#include "variant.h"
-#include "core_string_names.h"
-#include "object.h"
-#include "script_language.h"
+#include "core/core_string_names.h"
+#include "core/object.h"
+#include "core/script_language.h"
#define CASE_TYPE_ALL(PREFIX, OP) \
CASE_TYPE(PREFIX, OP, INT) \
@@ -521,7 +521,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
const Dictionary *arr_a = reinterpret_cast<const Dictionary *>(p_a._data._mem);
const Dictionary *arr_b = reinterpret_cast<const Dictionary *>(p_b._data._mem);
- _RETURN((*arr_a == *arr_b) == false);
+ _RETURN(*arr_a != *arr_b);
}
CASE_TYPE(math, OP_NOT_EQUAL, ARRAY) {
@@ -1656,13 +1656,13 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
} else if (p_index == CoreStringNames::singleton->a) {
return v->a;
} else if (p_index == CoreStringNames::singleton->r8) {
- return int(v->r * 255.0);
+ return int(Math::round(v->r * 255.0));
} else if (p_index == CoreStringNames::singleton->g8) {
- return int(v->g * 255.0);
+ return int(Math::round(v->g * 255.0));
} else if (p_index == CoreStringNames::singleton->b8) {
- return int(v->b * 255.0);
+ return int(Math::round(v->b * 255.0));
} else if (p_index == CoreStringNames::singleton->a8) {
- return int(v->a * 255.0);
+ return int(Math::round(v->a * 255.0));
} else if (p_index == CoreStringNames::singleton->h) {
return v->get_h();
} else if (p_index == CoreStringNames::singleton->s) {
@@ -3521,7 +3521,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
//not as efficient but..
real_t va = a;
real_t vb = b;
- r_dst = (1.0 - c) * va + vb * c;
+ r_dst = va + (vb - va) * c;
} else {
r_dst = a;
@@ -3542,13 +3542,13 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
case INT: {
int64_t va = a._data._int;
int64_t vb = b._data._int;
- r_dst = int((1.0 - c) * va + vb * c);
+ r_dst = int(va + (vb - va) * c);
}
return;
case REAL: {
real_t va = a._data._real;
real_t vb = b._data._real;
- r_dst = (1.0 - c) * va + vb * c;
+ r_dst = va + (vb - va) * c;
}
return;
case STRING: {
@@ -3556,7 +3556,9 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
String sa = *reinterpret_cast<const String *>(a._data._mem);
String sb = *reinterpret_cast<const String *>(b._data._mem);
String dst;
- int csize = sb.length() * c + sa.length() * (1.0 - c);
+ int sa_len = sa.length();
+ int sb_len = sb.length();
+ int csize = sa_len + (sb_len - sa_len) * c;
if (csize == 0) {
r_dst = "";
return;
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 446aee286d..3d5ae74e92 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -30,10 +30,10 @@
#include "variant_parser.h"
+#include "core/io/resource_loader.h"
+#include "core/os/input_event.h"
+#include "core/os/keyboard.h"
#include "core/string_buffer.h"
-#include "io/resource_loader.h"
-#include "os/input_event.h"
-#include "os/keyboard.h"
CharType VariantParser::StreamFile::get_char() {
@@ -1429,10 +1429,10 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
break;
if (parsing_tag && token.type == TK_PERIOD) {
- r_tag.name += "."; //support tags such as [someprop.Anroid] for specific platforms
+ r_tag.name += "."; //support tags such as [someprop.Android] for specific platforms
get_token(p_stream, token, line, r_err_str);
} else if (parsing_tag && token.type == TK_COLON) {
- r_tag.name += ":"; //support tags such as [someprop.Anroid] for specific platforms
+ r_tag.name += ":"; //support tags such as [someprop.Android] for specific platforms
get_token(p_stream, token, line, r_err_str);
} else {
parsing_tag = false;
diff --git a/core/variant_parser.h b/core/variant_parser.h
index 8d95595234..531c1d59cd 100644
--- a/core/variant_parser.h
+++ b/core/variant_parser.h
@@ -31,9 +31,9 @@
#ifndef VARIANT_PARSER_H
#define VARIANT_PARSER_H
-#include "os/file_access.h"
-#include "resource.h"
-#include "variant.h"
+#include "core/os/file_access.h"
+#include "core/resource.h"
+#include "core/variant.h"
class VariantParser {
public:
diff --git a/core/vector.h b/core/vector.h
index 52e8758f9b..38a1082407 100644
--- a/core/vector.h
+++ b/core/vector.h
@@ -36,10 +36,11 @@
* @author Juan Linietsky
* Vector container. Regular Vector Container. Use with care and for smaller arrays when possible. Use PoolVector for large arrays.
*/
-#include "cowdata.h"
-#include "error_macros.h"
-#include "os/memory.h"
-#include "sort.h"
+
+#include "core/cowdata.h"
+#include "core/error_macros.h"
+#include "core/os/memory.h"
+#include "core/sort.h"
template <class T>
class VectorWriteProxy {
diff --git a/core/version.h b/core/version.h
index d39172865a..2a3a282d82 100644
--- a/core/version.h
+++ b/core/version.h
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "version_generated.gen.h"
+#include "core/version_generated.gen.h"
// Godot versions are of the form <major>.<minor> for the initial release,
// and then <major>.<minor>.<patch> for subsequent bugfix releases where <patch> != 0
diff --git a/core/vmap.h b/core/vmap.h
index ce0ddc4ec6..9fc99e636d 100644
--- a/core/vmap.h
+++ b/core/vmap.h
@@ -31,8 +31,8 @@
#ifndef VMAP_H
#define VMAP_H
-#include "cowdata.h"
-#include "typedefs.h"
+#include "core/cowdata.h"
+#include "core/typedefs.h"
template <class T, class V>
class VMap {
diff --git a/core/vset.h b/core/vset.h
index 7f4d8e7f62..9ec329b45f 100644
--- a/core/vset.h
+++ b/core/vset.h
@@ -31,8 +31,8 @@
#ifndef VSET_H
#define VSET_H
-#include "typedefs.h"
-#include "vector.h"
+#include "core/typedefs.h"
+#include "core/vector.h"
template <class T>
class VSet {