diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/SCsub | 9 | ||||
-rw-r--r-- | core/bind/SCsub | 5 | ||||
-rw-r--r-- | core/color_names.inc | 155 | ||||
-rw-r--r-- | core/config/SCsub | 7 | ||||
-rw-r--r-- | core/config/engine.cpp (renamed from core/engine.cpp) | 0 | ||||
-rw-r--r-- | core/config/engine.h (renamed from core/engine.h) | 6 | ||||
-rw-r--r-- | core/config/project_settings.cpp (renamed from core/project_settings.cpp) | 4 | ||||
-rw-r--r-- | core/config/project_settings.h (renamed from core/project_settings.h) | 4 | ||||
-rw-r--r-- | core/core_bind.cpp (renamed from core/bind/core_bind.cpp) | 2 | ||||
-rw-r--r-- | core/core_bind.h (renamed from core/bind/core_bind.h) | 2 | ||||
-rw-r--r-- | core/core_constants.cpp | 690 | ||||
-rw-r--r-- | core/core_constants.h (renamed from core/global_constants.h) | 10 | ||||
-rw-r--r-- | core/core_string_names.h | 2 | ||||
-rw-r--r-- | core/crypto/aes_context.h | 2 | ||||
-rw-r--r-- | core/crypto/crypto.cpp | 2 | ||||
-rw-r--r-- | core/crypto/crypto.h | 4 | ||||
-rw-r--r-- | core/crypto/crypto_core.h | 2 | ||||
-rw-r--r-- | core/crypto/hashing_context.h | 2 | ||||
-rw-r--r-- | core/debugger/debugger_marshalls.h | 2 | ||||
-rw-r--r-- | core/debugger/engine_debugger.h | 12 | ||||
-rw-r--r-- | core/debugger/local_debugger.h | 4 | ||||
-rw-r--r-- | core/debugger/remote_debugger.cpp | 4 | ||||
-rw-r--r-- | core/debugger/remote_debugger.h | 8 | ||||
-rw-r--r-- | core/debugger/remote_debugger_peer.cpp | 2 | ||||
-rw-r--r-- | core/debugger/remote_debugger_peer.h | 4 | ||||
-rw-r--r-- | core/debugger/script_debugger.h | 10 | ||||
-rw-r--r-- | core/error/SCsub | 7 | ||||
-rw-r--r-- | core/error/error_list.h (renamed from core/error_list.h) | 0 | ||||
-rw-r--r-- | core/error/error_macros.cpp (renamed from core/error_macros.cpp) | 4 | ||||
-rw-r--r-- | core/error/error_macros.h (renamed from core/error_macros.h) | 0 | ||||
-rw-r--r-- | core/func_ref.cpp | 101 | ||||
-rw-r--r-- | core/func_ref.h | 55 | ||||
-rw-r--r-- | core/global_constants.cpp | 690 | ||||
-rw-r--r-- | core/input/input.cpp | 53 | ||||
-rw-r--r-- | core/input/input.h | 8 | ||||
-rw-r--r-- | core/input/input_event.cpp | 57 | ||||
-rw-r--r-- | core/input/input_event.h | 17 | ||||
-rw-r--r-- | core/input/input_map.cpp | 24 | ||||
-rw-r--r-- | core/input/input_map.h | 7 | ||||
-rw-r--r-- | core/int_types.h | 62 | ||||
-rw-r--r-- | core/io/compression.cpp | 2 | ||||
-rw-r--r-- | core/io/compression.h | 2 | ||||
-rw-r--r-- | core/io/config_file.cpp | 2 | ||||
-rw-r--r-- | core/io/config_file.h | 6 | ||||
-rw-r--r-- | core/io/dtls_server.cpp | 2 | ||||
-rw-r--r-- | core/io/file_access_buffered.cpp | 2 | ||||
-rw-r--r-- | core/io/file_access_buffered.h | 2 | ||||
-rw-r--r-- | core/io/file_access_compressed.cpp | 2 | ||||
-rw-r--r-- | core/io/file_access_encrypted.cpp | 4 | ||||
-rw-r--r-- | core/io/file_access_memory.cpp | 4 | ||||
-rw-r--r-- | core/io/file_access_network.cpp | 2 | ||||
-rw-r--r-- | core/io/file_access_pack.cpp | 32 | ||||
-rw-r--r-- | core/io/file_access_pack.h | 30 | ||||
-rw-r--r-- | core/io/file_access_zip.h | 2 | ||||
-rw-r--r-- | core/io/http_client.h | 2 | ||||
-rw-r--r-- | core/io/image.cpp (renamed from core/image.cpp) | 6 | ||||
-rw-r--r-- | core/io/image.h (renamed from core/image.h) | 4 | ||||
-rw-r--r-- | core/io/image_loader.cpp | 2 | ||||
-rw-r--r-- | core/io/image_loader.h | 6 | ||||
-rw-r--r-- | core/io/ip.cpp | 2 | ||||
-rw-r--r-- | core/io/ip_address.h | 2 | ||||
-rw-r--r-- | core/io/json.cpp | 34 | ||||
-rw-r--r-- | core/io/json.h | 25 | ||||
-rw-r--r-- | core/io/logger.cpp | 2 | ||||
-rw-r--r-- | core/io/logger.h | 4 | ||||
-rw-r--r-- | core/io/marshalls.cpp | 8 | ||||
-rw-r--r-- | core/io/marshalls.h | 4 | ||||
-rw-r--r-- | core/io/multiplayer_api.h | 2 | ||||
-rw-r--r-- | core/io/net_socket.h | 2 | ||||
-rw-r--r-- | core/io/packed_data_container.cpp (renamed from core/packed_data_container.cpp) | 2 | ||||
-rw-r--r-- | core/io/packed_data_container.h (renamed from core/packed_data_container.h) | 2 | ||||
-rw-r--r-- | core/io/packet_peer.cpp | 2 | ||||
-rw-r--r-- | core/io/packet_peer.h | 4 | ||||
-rw-r--r-- | core/io/packet_peer_dtls.cpp | 2 | ||||
-rw-r--r-- | core/io/pck_packer.h | 2 | ||||
-rw-r--r-- | core/io/resource.cpp (renamed from core/resource.cpp) | 2 | ||||
-rw-r--r-- | core/io/resource.h (renamed from core/resource.h) | 8 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 6 | ||||
-rw-r--r-- | core/io/resource_importer.cpp | 4 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 10 | ||||
-rw-r--r-- | core/io/resource_loader.h | 2 | ||||
-rw-r--r-- | core/io/resource_saver.cpp | 6 | ||||
-rw-r--r-- | core/io/resource_saver.h | 2 | ||||
-rw-r--r-- | core/io/stream_peer.h | 2 | ||||
-rw-r--r-- | core/io/stream_peer_ssl.cpp | 2 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.cpp | 2 | ||||
-rw-r--r-- | core/io/translation_loader_po.cpp | 4 | ||||
-rw-r--r-- | core/io/translation_loader_po.h | 2 | ||||
-rw-r--r-- | core/io/xml_parser.cpp | 2 | ||||
-rw-r--r-- | core/io/xml_parser.h | 6 | ||||
-rw-r--r-- | core/math/a_star.cpp | 2 | ||||
-rw-r--r-- | core/math/a_star.h | 4 | ||||
-rw-r--r-- | core/math/aabb.cpp | 4 | ||||
-rw-r--r-- | core/math/basis.cpp | 2 | ||||
-rw-r--r-- | core/math/camera_matrix.cpp | 2 | ||||
-rw-r--r-- | core/math/color.cpp (renamed from core/color.cpp) | 88 | ||||
-rw-r--r-- | core/math/color.h (renamed from core/color.h) | 74 | ||||
-rw-r--r-- | core/math/color_names.inc | 160 | ||||
-rw-r--r-- | core/math/delaunay_3d.h | 10 | ||||
-rw-r--r-- | core/math/disjoint_set.h | 4 | ||||
-rw-r--r-- | core/math/expression.cpp | 750 | ||||
-rw-r--r-- | core/math/expression.h | 85 | ||||
-rw-r--r-- | core/math/geometry_2d.h | 4 | ||||
-rw-r--r-- | core/math/geometry_3d.cpp | 2 | ||||
-rw-r--r-- | core/math/geometry_3d.h | 4 | ||||
-rw-r--r-- | core/math/math_fieldwise.h | 2 | ||||
-rw-r--r-- | core/math/math_funcs.cpp | 2 | ||||
-rw-r--r-- | core/math/octree.h | 8 | ||||
-rw-r--r-- | core/math/plane.cpp | 2 | ||||
-rw-r--r-- | core/math/quat.cpp | 2 | ||||
-rw-r--r-- | core/math/quat.h | 2 | ||||
-rw-r--r-- | core/math/quick_hull.cpp | 2 | ||||
-rw-r--r-- | core/math/quick_hull.h | 4 | ||||
-rw-r--r-- | core/math/random_number_generator.h | 2 | ||||
-rw-r--r-- | core/math/transform.cpp | 9 | ||||
-rw-r--r-- | core/math/transform.h | 5 | ||||
-rw-r--r-- | core/math/transform_2d.cpp | 2 | ||||
-rw-r--r-- | core/math/transform_2d.h | 6 | ||||
-rw-r--r-- | core/math/triangle_mesh.cpp | 2 | ||||
-rw-r--r-- | core/math/triangle_mesh.h | 2 | ||||
-rw-r--r-- | core/math/vector2.h | 2 | ||||
-rw-r--r-- | core/math/vector3.h | 2 | ||||
-rw-r--r-- | core/math/vector3i.h | 2 | ||||
-rw-r--r-- | core/object/SCsub | 7 | ||||
-rw-r--r-- | core/object/callable_method_pointer.cpp (renamed from core/callable_method_pointer.cpp) | 0 | ||||
-rw-r--r-- | core/object/callable_method_pointer.h (renamed from core/callable_method_pointer.h) | 10 | ||||
-rw-r--r-- | core/object/class_db.cpp (renamed from core/class_db.cpp) | 2 | ||||
-rw-r--r-- | core/object/class_db.h (renamed from core/class_db.h) | 8 | ||||
-rw-r--r-- | core/object/message_queue.cpp (renamed from core/message_queue.cpp) | 4 | ||||
-rw-r--r-- | core/object/message_queue.h (renamed from core/message_queue.h) | 2 | ||||
-rw-r--r-- | core/object/method_bind.cpp (renamed from core/method_bind.cpp) | 2 | ||||
-rw-r--r-- | core/object/method_bind.h (renamed from core/method_bind.h) | 2 | ||||
-rw-r--r-- | core/object/object.cpp (renamed from core/object.cpp) | 15 | ||||
-rw-r--r-- | core/object/object.h (renamed from core/object.h) | 18 | ||||
-rw-r--r-- | core/object/object_id.h (renamed from core/object_id.h) | 0 | ||||
-rw-r--r-- | core/object/reference.cpp (renamed from core/reference.cpp) | 2 | ||||
-rw-r--r-- | core/object/reference.h (renamed from core/reference.h) | 4 | ||||
-rw-r--r-- | core/object/script_language.cpp (renamed from core/script_language.cpp) | 2 | ||||
-rw-r--r-- | core/object/script_language.h (renamed from core/script_language.h) | 6 | ||||
-rw-r--r-- | core/object/undo_redo.cpp (renamed from core/undo_redo.cpp) | 0 | ||||
-rw-r--r-- | core/object/undo_redo.h (renamed from core/undo_redo.h) | 4 | ||||
-rw-r--r-- | core/os/dir_access.cpp | 2 | ||||
-rw-r--r-- | core/os/dir_access.h | 2 | ||||
-rw-r--r-- | core/os/file_access.cpp | 12 | ||||
-rw-r--r-- | core/os/file_access.h | 2 | ||||
-rw-r--r-- | core/os/keyboard.h | 2 | ||||
-rw-r--r-- | core/os/main_loop.cpp | 2 | ||||
-rw-r--r-- | core/os/main_loop.h | 4 | ||||
-rw-r--r-- | core/os/memory.cpp | 4 | ||||
-rw-r--r-- | core/os/memory.h | 4 | ||||
-rw-r--r-- | core/os/midi_driver.h | 2 | ||||
-rw-r--r-- | core/os/mutex.h | 2 | ||||
-rw-r--r-- | core/os/os.cpp | 2 | ||||
-rw-r--r-- | core/os/os.h | 10 | ||||
-rw-r--r-- | core/os/pool_allocator.cpp (renamed from core/pool_allocator.cpp) | 4 | ||||
-rw-r--r-- | core/os/pool_allocator.h (renamed from core/pool_allocator.h) | 0 | ||||
-rw-r--r-- | core/os/rw_lock.cpp | 2 | ||||
-rw-r--r-- | core/os/rw_lock.h | 2 | ||||
-rw-r--r-- | core/os/semaphore.h | 2 | ||||
-rw-r--r-- | core/os/spin_lock.h (renamed from core/spin_lock.h) | 0 | ||||
-rw-r--r-- | core/os/thread.h | 2 | ||||
-rw-r--r-- | core/os/threaded_array_processor.h | 2 | ||||
-rw-r--r-- | core/register_core_types.cpp | 36 | ||||
-rw-r--r-- | core/string/SCsub | 7 | ||||
-rw-r--r-- | core/string/compressed_translation.cpp (renamed from core/compressed_translation.cpp) | 2 | ||||
-rw-r--r-- | core/string/compressed_translation.h (renamed from core/compressed_translation.h) | 2 | ||||
-rw-r--r-- | core/string/node_path.cpp (renamed from core/node_path.cpp) | 2 | ||||
-rw-r--r-- | core/string/node_path.h (renamed from core/node_path.h) | 4 | ||||
-rw-r--r-- | core/string/print_string.cpp (renamed from core/print_string.cpp) | 0 | ||||
-rw-r--r-- | core/string/print_string.h (renamed from core/print_string.h) | 2 | ||||
-rw-r--r-- | core/string/string_buffer.h (renamed from core/string_buffer.h) | 2 | ||||
-rw-r--r-- | core/string/string_builder.cpp (renamed from core/string_builder.cpp) | 0 | ||||
-rw-r--r-- | core/string/string_builder.h (renamed from core/string_builder.h) | 4 | ||||
-rw-r--r-- | core/string/string_name.cpp (renamed from core/string_name.cpp) | 2 | ||||
-rw-r--r-- | core/string/string_name.h (renamed from core/string_name.h) | 4 | ||||
-rw-r--r-- | core/string/translation.cpp (renamed from core/translation.cpp) | 2 | ||||
-rw-r--r-- | core/string/translation.h (renamed from core/translation.h) | 2 | ||||
-rw-r--r-- | core/string/translation_po.cpp (renamed from core/translation_po.cpp) | 0 | ||||
-rw-r--r-- | core/string/translation_po.h (renamed from core/translation_po.h) | 2 | ||||
-rw-r--r-- | core/string/ucaps.h (renamed from core/ucaps.h) | 0 | ||||
-rw-r--r-- | core/string/ustring.cpp (renamed from core/ustring.cpp) | 10 | ||||
-rw-r--r-- | core/string/ustring.h (renamed from core/ustring.h) | 28 | ||||
-rw-r--r-- | core/templates/SCsub | 7 | ||||
-rw-r--r-- | core/templates/command_queue_mt.cpp (renamed from core/command_queue_mt.cpp) | 2 | ||||
-rw-r--r-- | core/templates/command_queue_mt.h (renamed from core/command_queue_mt.h) | 2 | ||||
-rw-r--r-- | core/templates/cowdata.h (renamed from core/cowdata.h) | 4 | ||||
-rw-r--r-- | core/templates/hash_map.h (renamed from core/hash_map.h) | 8 | ||||
-rw-r--r-- | core/templates/hashfuncs.h (renamed from core/hashfuncs.h) | 10 | ||||
-rw-r--r-- | core/templates/list.h (renamed from core/list.h) | 4 | ||||
-rw-r--r-- | core/templates/local_vector.h (renamed from core/local_vector.h) | 6 | ||||
-rw-r--r-- | core/templates/map.h (renamed from core/map.h) | 4 | ||||
-rw-r--r-- | core/templates/oa_hash_map.h (renamed from core/oa_hash_map.h) | 2 | ||||
-rw-r--r-- | core/templates/ordered_hash_map.h (renamed from core/ordered_hash_map.h) | 6 | ||||
-rw-r--r-- | core/templates/pair.h (renamed from core/pair.h) | 0 | ||||
-rw-r--r-- | core/templates/rid.h (renamed from core/rid.h) | 0 | ||||
-rw-r--r-- | core/templates/rid_owner.cpp (renamed from core/rid_owner.cpp) | 0 | ||||
-rw-r--r-- | core/templates/rid_owner.h (renamed from core/rid_owner.h) | 14 | ||||
-rw-r--r-- | core/templates/ring_buffer.h (renamed from core/ring_buffer.h) | 2 | ||||
-rw-r--r-- | core/templates/safe_refcount.cpp (renamed from core/safe_refcount.cpp) | 0 | ||||
-rw-r--r-- | core/templates/safe_refcount.h (renamed from core/safe_refcount.h) | 0 | ||||
-rw-r--r-- | core/templates/self_list.h (renamed from core/self_list.h) | 2 | ||||
-rw-r--r-- | core/templates/set.h (renamed from core/set.h) | 0 | ||||
-rw-r--r-- | core/templates/simple_type.h (renamed from core/simple_type.h) | 0 | ||||
-rw-r--r-- | core/templates/sort_array.h (renamed from core/sort_array.h) | 2 | ||||
-rw-r--r-- | core/templates/thread_work_pool.cpp (renamed from core/thread_work_pool.cpp) | 0 | ||||
-rw-r--r-- | core/templates/thread_work_pool.h (renamed from core/thread_work_pool.h) | 0 | ||||
-rw-r--r-- | core/templates/vector.h (renamed from core/vector.h) | 6 | ||||
-rw-r--r-- | core/templates/vmap.h (renamed from core/vmap.h) | 2 | ||||
-rw-r--r-- | core/templates/vset.h (renamed from core/vset.h) | 2 | ||||
-rw-r--r-- | core/typedefs.h | 4 | ||||
-rw-r--r-- | core/variant/SCsub | 7 | ||||
-rw-r--r-- | core/variant/array.cpp (renamed from core/array.cpp) | 17 | ||||
-rw-r--r-- | core/variant/array.h (renamed from core/array.h) | 1 | ||||
-rw-r--r-- | core/variant/binder_common.h (renamed from core/binder_common.h) | 47 | ||||
-rw-r--r-- | core/variant/callable.cpp (renamed from core/callable.cpp) | 8 | ||||
-rw-r--r-- | core/variant/callable.h (renamed from core/callable.h) | 6 | ||||
-rw-r--r-- | core/variant/callable_bind.cpp (renamed from core/callable_bind.cpp) | 0 | ||||
-rw-r--r-- | core/variant/callable_bind.h (renamed from core/callable_bind.h) | 4 | ||||
-rw-r--r-- | core/variant/container_type_validate.h (renamed from core/container_type_validate.h) | 4 | ||||
-rw-r--r-- | core/variant/dictionary.cpp (renamed from core/dictionary.cpp) | 6 | ||||
-rw-r--r-- | core/variant/dictionary.h (renamed from core/dictionary.h) | 6 | ||||
-rw-r--r-- | core/variant/method_ptrcall.h (renamed from core/method_ptrcall.h) | 4 | ||||
-rw-r--r-- | core/variant/type_info.h (renamed from core/type_info.h) | 2 | ||||
-rw-r--r-- | core/variant/typed_array.h (renamed from core/typed_array.h) | 10 | ||||
-rw-r--r-- | core/variant/variant.cpp (renamed from core/variant.cpp) | 112 | ||||
-rw-r--r-- | core/variant/variant.h (renamed from core/variant.h) | 211 | ||||
-rw-r--r-- | core/variant/variant_call.cpp (renamed from core/variant_call.cpp) | 1669 | ||||
-rw-r--r-- | core/variant/variant_construct.cpp | 812 | ||||
-rw-r--r-- | core/variant/variant_internal.h (renamed from core/variant_internal.h) | 495 | ||||
-rw-r--r-- | core/variant/variant_op.cpp (renamed from core/variant_op.cpp) | 91 | ||||
-rw-r--r-- | core/variant/variant_parser.cpp (renamed from core/variant_parser.cpp) | 2 | ||||
-rw-r--r-- | core/variant/variant_parser.h (renamed from core/variant_parser.h) | 4 | ||||
-rw-r--r-- | core/variant/variant_setget.cpp (renamed from core/variant_setget.cpp) | 12 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 1392 |
234 files changed, 5249 insertions, 3590 deletions
diff --git a/core/SCsub b/core/SCsub index b9f06d12ae..78a4395619 100644 --- a/core/SCsub +++ b/core/SCsub @@ -34,7 +34,7 @@ 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 "core/project_settings.h"\nuint8_t script_encryption_key[32]={' + txt + "};\n") + f.write('#include "core/config/project_settings.h"\nuint8_t script_encryption_key[32]={' + txt + "};\n") # Add required thirdparty code. @@ -174,7 +174,12 @@ SConscript("crypto/SCsub") SConscript("io/SCsub") SConscript("debugger/SCsub") SConscript("input/SCsub") -SConscript("bind/SCsub") +SConscript("variant/SCsub") +SConscript("object/SCsub") +SConscript("templates/SCsub") +SConscript("string/SCsub") +SConscript("config/SCsub") +SConscript("error/SCsub") # Build it all as a library diff --git a/core/bind/SCsub b/core/bind/SCsub deleted file mode 100644 index 19a6549225..0000000000 --- a/core/bind/SCsub +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env python - -Import("env") - -env.add_source_files(env.core_sources, "*.cpp") diff --git a/core/color_names.inc b/core/color_names.inc deleted file mode 100644 index 2b50d88b02..0000000000 --- a/core/color_names.inc +++ /dev/null @@ -1,155 +0,0 @@ -// Names from https://en.wikipedia.org/wiki/X11_color_names -#include "core/map.h" - -static Map<String, Color> _named_colors; -static void _populate_named_colors() { - if (!_named_colors.empty()) { - return; - } - _named_colors.insert("aliceblue", Color(0.94, 0.97, 1.00)); - _named_colors.insert("antiquewhite", Color(0.98, 0.92, 0.84)); - _named_colors.insert("aqua", Color(0.00, 1.00, 1.00)); - _named_colors.insert("aquamarine", Color(0.50, 1.00, 0.83)); - _named_colors.insert("azure", Color(0.94, 1.00, 1.00)); - _named_colors.insert("beige", Color(0.96, 0.96, 0.86)); - _named_colors.insert("bisque", Color(1.00, 0.89, 0.77)); - _named_colors.insert("black", Color(0.00, 0.00, 0.00)); - _named_colors.insert("blanchedalmond", Color(1.00, 0.92, 0.80)); - _named_colors.insert("blue", Color(0.00, 0.00, 1.00)); - _named_colors.insert("blueviolet", Color(0.54, 0.17, 0.89)); - _named_colors.insert("brown", Color(0.65, 0.16, 0.16)); - _named_colors.insert("burlywood", Color(0.87, 0.72, 0.53)); - _named_colors.insert("cadetblue", Color(0.37, 0.62, 0.63)); - _named_colors.insert("chartreuse", Color(0.50, 1.00, 0.00)); - _named_colors.insert("chocolate", Color(0.82, 0.41, 0.12)); - _named_colors.insert("coral", Color(1.00, 0.50, 0.31)); - _named_colors.insert("cornflower", Color(0.39, 0.58, 0.93)); - _named_colors.insert("cornsilk", Color(1.00, 0.97, 0.86)); - _named_colors.insert("crimson", Color(0.86, 0.08, 0.24)); - _named_colors.insert("cyan", Color(0.00, 1.00, 1.00)); - _named_colors.insert("darkblue", Color(0.00, 0.00, 0.55)); - _named_colors.insert("darkcyan", Color(0.00, 0.55, 0.55)); - _named_colors.insert("darkgoldenrod", Color(0.72, 0.53, 0.04)); - _named_colors.insert("darkgray", Color(0.66, 0.66, 0.66)); - _named_colors.insert("darkgreen", Color(0.00, 0.39, 0.00)); - _named_colors.insert("darkkhaki", Color(0.74, 0.72, 0.42)); - _named_colors.insert("darkmagenta", Color(0.55, 0.00, 0.55)); - _named_colors.insert("darkolivegreen", Color(0.33, 0.42, 0.18)); - _named_colors.insert("darkorange", Color(1.00, 0.55, 0.00)); - _named_colors.insert("darkorchid", Color(0.60, 0.20, 0.80)); - _named_colors.insert("darkred", Color(0.55, 0.00, 0.00)); - _named_colors.insert("darksalmon", Color(0.91, 0.59, 0.48)); - _named_colors.insert("darkseagreen", Color(0.56, 0.74, 0.56)); - _named_colors.insert("darkslateblue", Color(0.28, 0.24, 0.55)); - _named_colors.insert("darkslategray", Color(0.18, 0.31, 0.31)); - _named_colors.insert("darkturquoise", Color(0.00, 0.81, 0.82)); - _named_colors.insert("darkviolet", Color(0.58, 0.00, 0.83)); - _named_colors.insert("deeppink", Color(1.00, 0.08, 0.58)); - _named_colors.insert("deepskyblue", Color(0.00, 0.75, 1.00)); - _named_colors.insert("dimgray", Color(0.41, 0.41, 0.41)); - _named_colors.insert("dodgerblue", Color(0.12, 0.56, 1.00)); - _named_colors.insert("firebrick", Color(0.70, 0.13, 0.13)); - _named_colors.insert("floralwhite", Color(1.00, 0.98, 0.94)); - _named_colors.insert("forestgreen", Color(0.13, 0.55, 0.13)); - _named_colors.insert("fuchsia", Color(1.00, 0.00, 1.00)); - _named_colors.insert("gainsboro", Color(0.86, 0.86, 0.86)); - _named_colors.insert("ghostwhite", Color(0.97, 0.97, 1.00)); - _named_colors.insert("gold", Color(1.00, 0.84, 0.00)); - _named_colors.insert("goldenrod", Color(0.85, 0.65, 0.13)); - _named_colors.insert("gray", Color(0.75, 0.75, 0.75)); - _named_colors.insert("webgray", Color(0.50, 0.50, 0.50)); - _named_colors.insert("green", Color(0.00, 1.00, 0.00)); - _named_colors.insert("webgreen", Color(0.00, 0.50, 0.00)); - _named_colors.insert("greenyellow", Color(0.68, 1.00, 0.18)); - _named_colors.insert("honeydew", Color(0.94, 1.00, 0.94)); - _named_colors.insert("hotpink", Color(1.00, 0.41, 0.71)); - _named_colors.insert("indianred", Color(0.80, 0.36, 0.36)); - _named_colors.insert("indigo", Color(0.29, 0.00, 0.51)); - _named_colors.insert("ivory", Color(1.00, 1.00, 0.94)); - _named_colors.insert("khaki", Color(0.94, 0.90, 0.55)); - _named_colors.insert("lavender", Color(0.90, 0.90, 0.98)); - _named_colors.insert("lavenderblush", Color(1.00, 0.94, 0.96)); - _named_colors.insert("lawngreen", Color(0.49, 0.99, 0.00)); - _named_colors.insert("lemonchiffon", Color(1.00, 0.98, 0.80)); - _named_colors.insert("lightblue", Color(0.68, 0.85, 0.90)); - _named_colors.insert("lightcoral", Color(0.94, 0.50, 0.50)); - _named_colors.insert("lightcyan", Color(0.88, 1.00, 1.00)); - _named_colors.insert("lightgoldenrod", Color(0.98, 0.98, 0.82)); - _named_colors.insert("lightgray", Color(0.83, 0.83, 0.83)); - _named_colors.insert("lightgreen", Color(0.56, 0.93, 0.56)); - _named_colors.insert("lightpink", Color(1.00, 0.71, 0.76)); - _named_colors.insert("lightsalmon", Color(1.00, 0.63, 0.48)); - _named_colors.insert("lightseagreen", Color(0.13, 0.70, 0.67)); - _named_colors.insert("lightskyblue", Color(0.53, 0.81, 0.98)); - _named_colors.insert("lightslategray", Color(0.47, 0.53, 0.60)); - _named_colors.insert("lightsteelblue", Color(0.69, 0.77, 0.87)); - _named_colors.insert("lightyellow", Color(1.00, 1.00, 0.88)); - _named_colors.insert("lime", Color(0.00, 1.00, 0.00)); - _named_colors.insert("limegreen", Color(0.20, 0.80, 0.20)); - _named_colors.insert("linen", Color(0.98, 0.94, 0.90)); - _named_colors.insert("magenta", Color(1.00, 0.00, 1.00)); - _named_colors.insert("maroon", Color(0.69, 0.19, 0.38)); - _named_colors.insert("webmaroon", Color(0.50, 0.00, 0.00)); - _named_colors.insert("mediumaquamarine", Color(0.40, 0.80, 0.67)); - _named_colors.insert("mediumblue", Color(0.00, 0.00, 0.80)); - _named_colors.insert("mediumorchid", Color(0.73, 0.33, 0.83)); - _named_colors.insert("mediumpurple", Color(0.58, 0.44, 0.86)); - _named_colors.insert("mediumseagreen", Color(0.24, 0.70, 0.44)); - _named_colors.insert("mediumslateblue", Color(0.48, 0.41, 0.93)); - _named_colors.insert("mediumspringgreen", Color(0.00, 0.98, 0.60)); - _named_colors.insert("mediumturquoise", Color(0.28, 0.82, 0.80)); - _named_colors.insert("mediumvioletred", Color(0.78, 0.08, 0.52)); - _named_colors.insert("midnightblue", Color(0.10, 0.10, 0.44)); - _named_colors.insert("mintcream", Color(0.96, 1.00, 0.98)); - _named_colors.insert("mistyrose", Color(1.00, 0.89, 0.88)); - _named_colors.insert("moccasin", Color(1.00, 0.89, 0.71)); - _named_colors.insert("navajowhite", Color(1.00, 0.87, 0.68)); - _named_colors.insert("navyblue", Color(0.00, 0.00, 0.50)); - _named_colors.insert("oldlace", Color(0.99, 0.96, 0.90)); - _named_colors.insert("olive", Color(0.50, 0.50, 0.00)); - _named_colors.insert("olivedrab", Color(0.42, 0.56, 0.14)); - _named_colors.insert("orange", Color(1.00, 0.65, 0.00)); - _named_colors.insert("orangered", Color(1.00, 0.27, 0.00)); - _named_colors.insert("orchid", Color(0.85, 0.44, 0.84)); - _named_colors.insert("palegoldenrod", Color(0.93, 0.91, 0.67)); - _named_colors.insert("palegreen", Color(0.60, 0.98, 0.60)); - _named_colors.insert("paleturquoise", Color(0.69, 0.93, 0.93)); - _named_colors.insert("palevioletred", Color(0.86, 0.44, 0.58)); - _named_colors.insert("papayawhip", Color(1.00, 0.94, 0.84)); - _named_colors.insert("peachpuff", Color(1.00, 0.85, 0.73)); - _named_colors.insert("peru", Color(0.80, 0.52, 0.25)); - _named_colors.insert("pink", Color(1.00, 0.75, 0.80)); - _named_colors.insert("plum", Color(0.87, 0.63, 0.87)); - _named_colors.insert("powderblue", Color(0.69, 0.88, 0.90)); - _named_colors.insert("purple", Color(0.63, 0.13, 0.94)); - _named_colors.insert("webpurple", Color(0.50, 0.00, 0.50)); - _named_colors.insert("rebeccapurple", Color(0.40, 0.20, 0.60)); - _named_colors.insert("red", Color(1.00, 0.00, 0.00)); - _named_colors.insert("rosybrown", Color(0.74, 0.56, 0.56)); - _named_colors.insert("royalblue", Color(0.25, 0.41, 0.88)); - _named_colors.insert("saddlebrown", Color(0.55, 0.27, 0.07)); - _named_colors.insert("salmon", Color(0.98, 0.50, 0.45)); - _named_colors.insert("sandybrown", Color(0.96, 0.64, 0.38)); - _named_colors.insert("seagreen", Color(0.18, 0.55, 0.34)); - _named_colors.insert("seashell", Color(1.00, 0.96, 0.93)); - _named_colors.insert("sienna", Color(0.63, 0.32, 0.18)); - _named_colors.insert("silver", Color(0.75, 0.75, 0.75)); - _named_colors.insert("skyblue", Color(0.53, 0.81, 0.92)); - _named_colors.insert("slateblue", Color(0.42, 0.35, 0.80)); - _named_colors.insert("slategray", Color(0.44, 0.50, 0.56)); - _named_colors.insert("snow", Color(1.00, 0.98, 0.98)); - _named_colors.insert("springgreen", Color(0.00, 1.00, 0.50)); - _named_colors.insert("steelblue", Color(0.27, 0.51, 0.71)); - _named_colors.insert("tan", Color(0.82, 0.71, 0.55)); - _named_colors.insert("teal", Color(0.00, 0.50, 0.50)); - _named_colors.insert("thistle", Color(0.85, 0.75, 0.85)); - _named_colors.insert("tomato", Color(1.00, 0.39, 0.28)); - _named_colors.insert("turquoise", Color(0.25, 0.88, 0.82)); - _named_colors.insert("transparent", Color(1.00, 1.00, 1.00, 0.00)); - _named_colors.insert("violet", Color(0.93, 0.51, 0.93)); - _named_colors.insert("wheat", Color(0.96, 0.87, 0.70)); - _named_colors.insert("white", Color(1.00, 1.00, 1.00)); - _named_colors.insert("whitesmoke", Color(0.96, 0.96, 0.96)); - _named_colors.insert("yellow", Color(1.00, 1.00, 0.00)); - _named_colors.insert("yellowgreen", Color(0.60, 0.80, 0.20)); -} diff --git a/core/config/SCsub b/core/config/SCsub new file mode 100644 index 0000000000..bf70285490 --- /dev/null +++ b/core/config/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import("env") + +env_config = env.Clone() + +env_config.add_source_files(env.core_sources, "*.cpp") diff --git a/core/engine.cpp b/core/config/engine.cpp index b0037ffb37..b0037ffb37 100644 --- a/core/engine.cpp +++ b/core/config/engine.cpp diff --git a/core/engine.h b/core/config/engine.h index b581c58ec5..1d3d963b39 100644 --- a/core/engine.h +++ b/core/config/engine.h @@ -31,10 +31,10 @@ #ifndef ENGINE_H #define ENGINE_H -#include "core/list.h" #include "core/os/main_loop.h" -#include "core/ustring.h" -#include "core/vector.h" +#include "core/string/ustring.h" +#include "core/templates/list.h" +#include "core/templates/vector.h" class Engine { public: diff --git a/core/project_settings.cpp b/core/config/project_settings.cpp index 3829474626..aa954ed300 100644 --- a/core/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -30,7 +30,7 @@ #include "project_settings.h" -#include "core/bind/core_bind.h" +#include "core/core_bind.h" #include "core/core_string_names.h" #include "core/io/file_access_network.h" #include "core/io/file_access_pack.h" @@ -39,7 +39,7 @@ #include "core/os/file_access.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/variant_parser.h" +#include "core/variant/variant_parser.h" #include <zlib.h> diff --git a/core/project_settings.h b/core/config/project_settings.h index 9a1d9cee97..a8c9adc587 100644 --- a/core/project_settings.h +++ b/core/config/project_settings.h @@ -31,9 +31,9 @@ #ifndef PROJECT_SETTINGS_H #define PROJECT_SETTINGS_H -#include "core/class_db.h" +#include "core/object/class_db.h" #include "core/os/thread_safe.h" -#include "core/set.h" +#include "core/templates/set.h" class ProjectSettings : public Object { GDCLASS(ProjectSettings, Object); diff --git a/core/bind/core_bind.cpp b/core/core_bind.cpp index baf5d4b928..f3bdea1eec 100644 --- a/core/bind/core_bind.cpp +++ b/core/core_bind.cpp @@ -30,6 +30,7 @@ #include "core_bind.h" +#include "core/config/project_settings.h" #include "core/crypto/crypto_core.h" #include "core/debugger/engine_debugger.h" #include "core/io/file_access_compressed.h" @@ -40,7 +41,6 @@ #include "core/math/geometry_3d.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/project_settings.h" /** * Time constants borrowed from loc_time.h diff --git a/core/bind/core_bind.h b/core/core_bind.h index e75e740cd5..7794750387 100644 --- a/core/bind/core_bind.h +++ b/core/core_bind.h @@ -31,8 +31,8 @@ #ifndef CORE_BIND_H #define CORE_BIND_H -#include "core/image.h" #include "core/io/compression.h" +#include "core/io/image.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" #include "core/os/dir_access.h" diff --git a/core/core_constants.cpp b/core/core_constants.cpp new file mode 100644 index 0000000000..4229436e84 --- /dev/null +++ b/core/core_constants.cpp @@ -0,0 +1,690 @@ +/*************************************************************************/ +/* core_constants.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 "core_constants.h" + +#include "core/input/input_event.h" +#include "core/object/class_db.h" +#include "core/os/keyboard.h" +#include "core/variant/variant.h" + +struct _CoreConstant { +#ifdef DEBUG_METHODS_ENABLED + StringName enum_name; + bool ignore_value_in_docs; +#endif + const char *name; + int value; + + _CoreConstant() {} + +#ifdef DEBUG_METHODS_ENABLED + _CoreConstant(const StringName &p_enum_name, const char *p_name, int p_value, bool p_ignore_value_in_docs = false) : + enum_name(p_enum_name), + ignore_value_in_docs(p_ignore_value_in_docs), + name(p_name), + value(p_value) { + } +#else + _CoreConstant(const char *p_name, int p_value) : + name(p_name), + value(p_value) { + } +#endif +}; + +static Vector<_CoreConstant> _global_constants; + +#ifdef DEBUG_METHODS_ENABLED + +#define BIND_CORE_CONSTANT(m_constant) \ + _global_constants.push_back(_CoreConstant(StringName(), #m_constant, m_constant)); + +#define BIND_CORE_ENUM_CONSTANT(m_constant) \ + _global_constants.push_back(_CoreConstant(__constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant)); + +#define BIND_CORE_ENUM_CONSTANT_CUSTOM(m_custom_name, m_constant) \ + _global_constants.push_back(_CoreConstant(__constant_get_enum_name(m_constant, #m_constant), m_custom_name, m_constant)); + +#define BIND_CORE_CONSTANT_NO_VAL(m_constant) \ + _global_constants.push_back(_CoreConstant(StringName(), #m_constant, m_constant, true)); + +#define BIND_CORE_ENUM_CONSTANT_NO_VAL(m_constant) \ + _global_constants.push_back(_CoreConstant(__constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant, true)); + +#define BIND_CORE_ENUM_CONSTANT_CUSTOM_NO_VAL(m_custom_name, m_constant) \ + _global_constants.push_back(_CoreConstant(__constant_get_enum_name(m_constant, #m_constant), m_custom_name, m_constant, true)); + +#else + +#define BIND_CORE_CONSTANT(m_constant) \ + _global_constants.push_back(_CoreConstant(#m_constant, m_constant)); + +#define BIND_CORE_ENUM_CONSTANT(m_constant) \ + _global_constants.push_back(_CoreConstant(#m_constant, m_constant)); + +#define BIND_CORE_ENUM_CONSTANT_CUSTOM(m_custom_name, m_constant) \ + _global_constants.push_back(_CoreConstant(m_custom_name, m_constant)); + +#define BIND_CORE_CONSTANT_NO_VAL(m_constant) \ + _global_constants.push_back(_CoreConstant(#m_constant, m_constant)); + +#define BIND_CORE_ENUM_CONSTANT_NO_VAL(m_constant) \ + _global_constants.push_back(_CoreConstant(#m_constant, m_constant)); + +#define BIND_CORE_ENUM_CONSTANT_CUSTOM_NO_VAL(m_custom_name, m_constant) \ + _global_constants.push_back(_CoreConstant(m_custom_name, m_constant)); + +#endif + +VARIANT_ENUM_CAST(KeyList); +VARIANT_ENUM_CAST(KeyModifierMask); +VARIANT_ENUM_CAST(ButtonList); +VARIANT_ENUM_CAST(JoyButtonList); +VARIANT_ENUM_CAST(JoyAxisList); +VARIANT_ENUM_CAST(MidiMessageList); + +void register_global_constants() { + BIND_CORE_ENUM_CONSTANT(MARGIN_LEFT); + BIND_CORE_ENUM_CONSTANT(MARGIN_TOP); + BIND_CORE_ENUM_CONSTANT(MARGIN_RIGHT); + BIND_CORE_ENUM_CONSTANT(MARGIN_BOTTOM); + + BIND_CORE_ENUM_CONSTANT(CORNER_TOP_LEFT); + BIND_CORE_ENUM_CONSTANT(CORNER_TOP_RIGHT); + BIND_CORE_ENUM_CONSTANT(CORNER_BOTTOM_RIGHT); + BIND_CORE_ENUM_CONSTANT(CORNER_BOTTOM_LEFT); + + BIND_CORE_ENUM_CONSTANT(VERTICAL); + BIND_CORE_ENUM_CONSTANT(HORIZONTAL); + + BIND_CORE_ENUM_CONSTANT(HALIGN_LEFT); + BIND_CORE_ENUM_CONSTANT(HALIGN_CENTER); + BIND_CORE_ENUM_CONSTANT(HALIGN_RIGHT); + + BIND_CORE_ENUM_CONSTANT(VALIGN_TOP); + BIND_CORE_ENUM_CONSTANT(VALIGN_CENTER); + BIND_CORE_ENUM_CONSTANT(VALIGN_BOTTOM); + + // huge list of keys + BIND_CORE_CONSTANT(SPKEY); + + BIND_CORE_ENUM_CONSTANT(KEY_ESCAPE); + BIND_CORE_ENUM_CONSTANT(KEY_TAB); + BIND_CORE_ENUM_CONSTANT(KEY_BACKTAB); + BIND_CORE_ENUM_CONSTANT(KEY_BACKSPACE); + BIND_CORE_ENUM_CONSTANT(KEY_ENTER); + BIND_CORE_ENUM_CONSTANT(KEY_KP_ENTER); + BIND_CORE_ENUM_CONSTANT(KEY_INSERT); + BIND_CORE_ENUM_CONSTANT(KEY_DELETE); + BIND_CORE_ENUM_CONSTANT(KEY_PAUSE); + BIND_CORE_ENUM_CONSTANT(KEY_PRINT); + BIND_CORE_ENUM_CONSTANT(KEY_SYSREQ); + BIND_CORE_ENUM_CONSTANT(KEY_CLEAR); + BIND_CORE_ENUM_CONSTANT(KEY_HOME); + BIND_CORE_ENUM_CONSTANT(KEY_END); + BIND_CORE_ENUM_CONSTANT(KEY_LEFT); + BIND_CORE_ENUM_CONSTANT(KEY_UP); + BIND_CORE_ENUM_CONSTANT(KEY_RIGHT); + BIND_CORE_ENUM_CONSTANT(KEY_DOWN); + BIND_CORE_ENUM_CONSTANT(KEY_PAGEUP); + BIND_CORE_ENUM_CONSTANT(KEY_PAGEDOWN); + BIND_CORE_ENUM_CONSTANT(KEY_SHIFT); + BIND_CORE_ENUM_CONSTANT(KEY_CONTROL); + BIND_CORE_ENUM_CONSTANT(KEY_META); + BIND_CORE_ENUM_CONSTANT(KEY_ALT); + BIND_CORE_ENUM_CONSTANT(KEY_CAPSLOCK); + BIND_CORE_ENUM_CONSTANT(KEY_NUMLOCK); + BIND_CORE_ENUM_CONSTANT(KEY_SCROLLLOCK); + BIND_CORE_ENUM_CONSTANT(KEY_F1); + BIND_CORE_ENUM_CONSTANT(KEY_F2); + BIND_CORE_ENUM_CONSTANT(KEY_F3); + BIND_CORE_ENUM_CONSTANT(KEY_F4); + BIND_CORE_ENUM_CONSTANT(KEY_F5); + BIND_CORE_ENUM_CONSTANT(KEY_F6); + BIND_CORE_ENUM_CONSTANT(KEY_F7); + BIND_CORE_ENUM_CONSTANT(KEY_F8); + BIND_CORE_ENUM_CONSTANT(KEY_F9); + BIND_CORE_ENUM_CONSTANT(KEY_F10); + BIND_CORE_ENUM_CONSTANT(KEY_F11); + BIND_CORE_ENUM_CONSTANT(KEY_F12); + BIND_CORE_ENUM_CONSTANT(KEY_F13); + BIND_CORE_ENUM_CONSTANT(KEY_F14); + BIND_CORE_ENUM_CONSTANT(KEY_F15); + BIND_CORE_ENUM_CONSTANT(KEY_F16); + BIND_CORE_ENUM_CONSTANT(KEY_KP_MULTIPLY); + BIND_CORE_ENUM_CONSTANT(KEY_KP_DIVIDE); + BIND_CORE_ENUM_CONSTANT(KEY_KP_SUBTRACT); + BIND_CORE_ENUM_CONSTANT(KEY_KP_PERIOD); + BIND_CORE_ENUM_CONSTANT(KEY_KP_ADD); + BIND_CORE_ENUM_CONSTANT(KEY_KP_0); + BIND_CORE_ENUM_CONSTANT(KEY_KP_1); + BIND_CORE_ENUM_CONSTANT(KEY_KP_2); + BIND_CORE_ENUM_CONSTANT(KEY_KP_3); + BIND_CORE_ENUM_CONSTANT(KEY_KP_4); + BIND_CORE_ENUM_CONSTANT(KEY_KP_5); + BIND_CORE_ENUM_CONSTANT(KEY_KP_6); + BIND_CORE_ENUM_CONSTANT(KEY_KP_7); + BIND_CORE_ENUM_CONSTANT(KEY_KP_8); + BIND_CORE_ENUM_CONSTANT(KEY_KP_9); + BIND_CORE_ENUM_CONSTANT(KEY_SUPER_L); + BIND_CORE_ENUM_CONSTANT(KEY_SUPER_R); + BIND_CORE_ENUM_CONSTANT(KEY_MENU); + BIND_CORE_ENUM_CONSTANT(KEY_HYPER_L); + BIND_CORE_ENUM_CONSTANT(KEY_HYPER_R); + BIND_CORE_ENUM_CONSTANT(KEY_HELP); + BIND_CORE_ENUM_CONSTANT(KEY_DIRECTION_L); + BIND_CORE_ENUM_CONSTANT(KEY_DIRECTION_R); + BIND_CORE_ENUM_CONSTANT(KEY_BACK); + BIND_CORE_ENUM_CONSTANT(KEY_FORWARD); + BIND_CORE_ENUM_CONSTANT(KEY_STOP); + BIND_CORE_ENUM_CONSTANT(KEY_REFRESH); + BIND_CORE_ENUM_CONSTANT(KEY_VOLUMEDOWN); + BIND_CORE_ENUM_CONSTANT(KEY_VOLUMEMUTE); + BIND_CORE_ENUM_CONSTANT(KEY_VOLUMEUP); + BIND_CORE_ENUM_CONSTANT(KEY_BASSBOOST); + BIND_CORE_ENUM_CONSTANT(KEY_BASSUP); + BIND_CORE_ENUM_CONSTANT(KEY_BASSDOWN); + BIND_CORE_ENUM_CONSTANT(KEY_TREBLEUP); + BIND_CORE_ENUM_CONSTANT(KEY_TREBLEDOWN); + BIND_CORE_ENUM_CONSTANT(KEY_MEDIAPLAY); + BIND_CORE_ENUM_CONSTANT(KEY_MEDIASTOP); + BIND_CORE_ENUM_CONSTANT(KEY_MEDIAPREVIOUS); + BIND_CORE_ENUM_CONSTANT(KEY_MEDIANEXT); + BIND_CORE_ENUM_CONSTANT(KEY_MEDIARECORD); + BIND_CORE_ENUM_CONSTANT(KEY_HOMEPAGE); + BIND_CORE_ENUM_CONSTANT(KEY_FAVORITES); + BIND_CORE_ENUM_CONSTANT(KEY_SEARCH); + BIND_CORE_ENUM_CONSTANT(KEY_STANDBY); + BIND_CORE_ENUM_CONSTANT(KEY_OPENURL); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHMAIL); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHMEDIA); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH0); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH1); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH2); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH3); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH4); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH5); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH6); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH7); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH8); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH9); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHA); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHB); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHC); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHD); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHE); + BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHF); + + BIND_CORE_ENUM_CONSTANT(KEY_UNKNOWN); + BIND_CORE_ENUM_CONSTANT(KEY_SPACE); + BIND_CORE_ENUM_CONSTANT(KEY_EXCLAM); + BIND_CORE_ENUM_CONSTANT(KEY_QUOTEDBL); + BIND_CORE_ENUM_CONSTANT(KEY_NUMBERSIGN); + BIND_CORE_ENUM_CONSTANT(KEY_DOLLAR); + BIND_CORE_ENUM_CONSTANT(KEY_PERCENT); + BIND_CORE_ENUM_CONSTANT(KEY_AMPERSAND); + BIND_CORE_ENUM_CONSTANT(KEY_APOSTROPHE); + BIND_CORE_ENUM_CONSTANT(KEY_PARENLEFT); + BIND_CORE_ENUM_CONSTANT(KEY_PARENRIGHT); + BIND_CORE_ENUM_CONSTANT(KEY_ASTERISK); + BIND_CORE_ENUM_CONSTANT(KEY_PLUS); + BIND_CORE_ENUM_CONSTANT(KEY_COMMA); + BIND_CORE_ENUM_CONSTANT(KEY_MINUS); + BIND_CORE_ENUM_CONSTANT(KEY_PERIOD); + BIND_CORE_ENUM_CONSTANT(KEY_SLASH); + BIND_CORE_ENUM_CONSTANT(KEY_0); + BIND_CORE_ENUM_CONSTANT(KEY_1); + BIND_CORE_ENUM_CONSTANT(KEY_2); + BIND_CORE_ENUM_CONSTANT(KEY_3); + BIND_CORE_ENUM_CONSTANT(KEY_4); + BIND_CORE_ENUM_CONSTANT(KEY_5); + BIND_CORE_ENUM_CONSTANT(KEY_6); + BIND_CORE_ENUM_CONSTANT(KEY_7); + BIND_CORE_ENUM_CONSTANT(KEY_8); + BIND_CORE_ENUM_CONSTANT(KEY_9); + BIND_CORE_ENUM_CONSTANT(KEY_COLON); + BIND_CORE_ENUM_CONSTANT(KEY_SEMICOLON); + BIND_CORE_ENUM_CONSTANT(KEY_LESS); + BIND_CORE_ENUM_CONSTANT(KEY_EQUAL); + BIND_CORE_ENUM_CONSTANT(KEY_GREATER); + BIND_CORE_ENUM_CONSTANT(KEY_QUESTION); + BIND_CORE_ENUM_CONSTANT(KEY_AT); + BIND_CORE_ENUM_CONSTANT(KEY_A); + BIND_CORE_ENUM_CONSTANT(KEY_B); + BIND_CORE_ENUM_CONSTANT(KEY_C); + BIND_CORE_ENUM_CONSTANT(KEY_D); + BIND_CORE_ENUM_CONSTANT(KEY_E); + BIND_CORE_ENUM_CONSTANT(KEY_F); + BIND_CORE_ENUM_CONSTANT(KEY_G); + BIND_CORE_ENUM_CONSTANT(KEY_H); + BIND_CORE_ENUM_CONSTANT(KEY_I); + BIND_CORE_ENUM_CONSTANT(KEY_J); + BIND_CORE_ENUM_CONSTANT(KEY_K); + BIND_CORE_ENUM_CONSTANT(KEY_L); + BIND_CORE_ENUM_CONSTANT(KEY_M); + BIND_CORE_ENUM_CONSTANT(KEY_N); + BIND_CORE_ENUM_CONSTANT(KEY_O); + BIND_CORE_ENUM_CONSTANT(KEY_P); + BIND_CORE_ENUM_CONSTANT(KEY_Q); + BIND_CORE_ENUM_CONSTANT(KEY_R); + BIND_CORE_ENUM_CONSTANT(KEY_S); + BIND_CORE_ENUM_CONSTANT(KEY_T); + BIND_CORE_ENUM_CONSTANT(KEY_U); + BIND_CORE_ENUM_CONSTANT(KEY_V); + BIND_CORE_ENUM_CONSTANT(KEY_W); + BIND_CORE_ENUM_CONSTANT(KEY_X); + BIND_CORE_ENUM_CONSTANT(KEY_Y); + BIND_CORE_ENUM_CONSTANT(KEY_Z); + BIND_CORE_ENUM_CONSTANT(KEY_BRACKETLEFT); + BIND_CORE_ENUM_CONSTANT(KEY_BACKSLASH); + BIND_CORE_ENUM_CONSTANT(KEY_BRACKETRIGHT); + BIND_CORE_ENUM_CONSTANT(KEY_ASCIICIRCUM); + BIND_CORE_ENUM_CONSTANT(KEY_UNDERSCORE); + BIND_CORE_ENUM_CONSTANT(KEY_QUOTELEFT); + BIND_CORE_ENUM_CONSTANT(KEY_BRACELEFT); + BIND_CORE_ENUM_CONSTANT(KEY_BAR); + BIND_CORE_ENUM_CONSTANT(KEY_BRACERIGHT); + BIND_CORE_ENUM_CONSTANT(KEY_ASCIITILDE); + BIND_CORE_ENUM_CONSTANT(KEY_NOBREAKSPACE); + BIND_CORE_ENUM_CONSTANT(KEY_EXCLAMDOWN); + BIND_CORE_ENUM_CONSTANT(KEY_CENT); + BIND_CORE_ENUM_CONSTANT(KEY_STERLING); + BIND_CORE_ENUM_CONSTANT(KEY_CURRENCY); + BIND_CORE_ENUM_CONSTANT(KEY_YEN); + BIND_CORE_ENUM_CONSTANT(KEY_BROKENBAR); + BIND_CORE_ENUM_CONSTANT(KEY_SECTION); + BIND_CORE_ENUM_CONSTANT(KEY_DIAERESIS); + BIND_CORE_ENUM_CONSTANT(KEY_COPYRIGHT); + BIND_CORE_ENUM_CONSTANT(KEY_ORDFEMININE); + BIND_CORE_ENUM_CONSTANT(KEY_GUILLEMOTLEFT); + BIND_CORE_ENUM_CONSTANT(KEY_NOTSIGN); + BIND_CORE_ENUM_CONSTANT(KEY_HYPHEN); + BIND_CORE_ENUM_CONSTANT(KEY_REGISTERED); + BIND_CORE_ENUM_CONSTANT(KEY_MACRON); + BIND_CORE_ENUM_CONSTANT(KEY_DEGREE); + BIND_CORE_ENUM_CONSTANT(KEY_PLUSMINUS); + BIND_CORE_ENUM_CONSTANT(KEY_TWOSUPERIOR); + BIND_CORE_ENUM_CONSTANT(KEY_THREESUPERIOR); + BIND_CORE_ENUM_CONSTANT(KEY_ACUTE); + BIND_CORE_ENUM_CONSTANT(KEY_MU); + BIND_CORE_ENUM_CONSTANT(KEY_PARAGRAPH); + BIND_CORE_ENUM_CONSTANT(KEY_PERIODCENTERED); + BIND_CORE_ENUM_CONSTANT(KEY_CEDILLA); + BIND_CORE_ENUM_CONSTANT(KEY_ONESUPERIOR); + BIND_CORE_ENUM_CONSTANT(KEY_MASCULINE); + BIND_CORE_ENUM_CONSTANT(KEY_GUILLEMOTRIGHT); + BIND_CORE_ENUM_CONSTANT(KEY_ONEQUARTER); + BIND_CORE_ENUM_CONSTANT(KEY_ONEHALF); + BIND_CORE_ENUM_CONSTANT(KEY_THREEQUARTERS); + BIND_CORE_ENUM_CONSTANT(KEY_QUESTIONDOWN); + BIND_CORE_ENUM_CONSTANT(KEY_AGRAVE); + BIND_CORE_ENUM_CONSTANT(KEY_AACUTE); + BIND_CORE_ENUM_CONSTANT(KEY_ACIRCUMFLEX); + BIND_CORE_ENUM_CONSTANT(KEY_ATILDE); + BIND_CORE_ENUM_CONSTANT(KEY_ADIAERESIS); + BIND_CORE_ENUM_CONSTANT(KEY_ARING); + BIND_CORE_ENUM_CONSTANT(KEY_AE); + BIND_CORE_ENUM_CONSTANT(KEY_CCEDILLA); + BIND_CORE_ENUM_CONSTANT(KEY_EGRAVE); + BIND_CORE_ENUM_CONSTANT(KEY_EACUTE); + BIND_CORE_ENUM_CONSTANT(KEY_ECIRCUMFLEX); + BIND_CORE_ENUM_CONSTANT(KEY_EDIAERESIS); + BIND_CORE_ENUM_CONSTANT(KEY_IGRAVE); + BIND_CORE_ENUM_CONSTANT(KEY_IACUTE); + BIND_CORE_ENUM_CONSTANT(KEY_ICIRCUMFLEX); + BIND_CORE_ENUM_CONSTANT(KEY_IDIAERESIS); + BIND_CORE_ENUM_CONSTANT(KEY_ETH); + BIND_CORE_ENUM_CONSTANT(KEY_NTILDE); + BIND_CORE_ENUM_CONSTANT(KEY_OGRAVE); + BIND_CORE_ENUM_CONSTANT(KEY_OACUTE); + BIND_CORE_ENUM_CONSTANT(KEY_OCIRCUMFLEX); + BIND_CORE_ENUM_CONSTANT(KEY_OTILDE); + BIND_CORE_ENUM_CONSTANT(KEY_ODIAERESIS); + BIND_CORE_ENUM_CONSTANT(KEY_MULTIPLY); + BIND_CORE_ENUM_CONSTANT(KEY_OOBLIQUE); + BIND_CORE_ENUM_CONSTANT(KEY_UGRAVE); + BIND_CORE_ENUM_CONSTANT(KEY_UACUTE); + BIND_CORE_ENUM_CONSTANT(KEY_UCIRCUMFLEX); + BIND_CORE_ENUM_CONSTANT(KEY_UDIAERESIS); + BIND_CORE_ENUM_CONSTANT(KEY_YACUTE); + BIND_CORE_ENUM_CONSTANT(KEY_THORN); + BIND_CORE_ENUM_CONSTANT(KEY_SSHARP); + + BIND_CORE_ENUM_CONSTANT(KEY_DIVISION); + BIND_CORE_ENUM_CONSTANT(KEY_YDIAERESIS); + + BIND_CORE_ENUM_CONSTANT(KEY_CODE_MASK); + BIND_CORE_ENUM_CONSTANT(KEY_MODIFIER_MASK); + + BIND_CORE_ENUM_CONSTANT(KEY_MASK_SHIFT); + BIND_CORE_ENUM_CONSTANT(KEY_MASK_ALT); + BIND_CORE_ENUM_CONSTANT(KEY_MASK_META); + BIND_CORE_ENUM_CONSTANT(KEY_MASK_CTRL); + BIND_CORE_ENUM_CONSTANT_NO_VAL(KEY_MASK_CMD); + BIND_CORE_ENUM_CONSTANT(KEY_MASK_KPAD); + BIND_CORE_ENUM_CONSTANT(KEY_MASK_GROUP_SWITCH); + + // mouse + BIND_CORE_ENUM_CONSTANT(BUTTON_LEFT); + BIND_CORE_ENUM_CONSTANT(BUTTON_RIGHT); + BIND_CORE_ENUM_CONSTANT(BUTTON_MIDDLE); + BIND_CORE_ENUM_CONSTANT(BUTTON_XBUTTON1); + BIND_CORE_ENUM_CONSTANT(BUTTON_XBUTTON2); + BIND_CORE_ENUM_CONSTANT(BUTTON_WHEEL_UP); + BIND_CORE_ENUM_CONSTANT(BUTTON_WHEEL_DOWN); + BIND_CORE_ENUM_CONSTANT(BUTTON_WHEEL_LEFT); + BIND_CORE_ENUM_CONSTANT(BUTTON_WHEEL_RIGHT); + BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_LEFT); + BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_RIGHT); + BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_MIDDLE); + BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_XBUTTON1); + BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_XBUTTON2); + + // Joypad buttons + BIND_CORE_ENUM_CONSTANT(JOY_INVALID_BUTTON); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_A); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_B); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_X); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_Y); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_BACK); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_GUIDE); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_START); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_LEFT_STICK); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_RIGHT_STICK); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_LEFT_SHOULDER); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_RIGHT_SHOULDER); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_UP); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_DOWN); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_LEFT); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_RIGHT); + BIND_CORE_ENUM_CONSTANT(JOY_SDL_BUTTONS); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_X); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_CROSS); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_CIRCLE); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_SQUARE); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_TRIANGLE); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_SELECT); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_START); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_PS); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_L1); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_R1); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_L3); + BIND_CORE_ENUM_CONSTANT(JOY_SONY_R3); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_A); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_B); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_X); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_Y); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_BACK); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_START); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_HOME); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_LS); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_RS); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_LB); + BIND_CORE_ENUM_CONSTANT(JOY_XBOX_RB); + BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_MAX); + + // Joypad axes + BIND_CORE_ENUM_CONSTANT(JOY_INVALID_AXIS); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_LEFT_X); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_LEFT_Y); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_RIGHT_X); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_RIGHT_Y); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_TRIGGER_LEFT); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_TRIGGER_RIGHT); + BIND_CORE_ENUM_CONSTANT(JOY_SDL_AXES); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_0_X); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_0_Y); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_1_X); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_1_Y); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_2_X); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_2_Y); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_3_X); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_3_Y); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_4_X); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_4_Y); + BIND_CORE_ENUM_CONSTANT(JOY_AXIS_MAX); + + // midi + BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_OFF); + BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_ON); + BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_AFTERTOUCH); + BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_CONTROL_CHANGE); + BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_PROGRAM_CHANGE); + BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_CHANNEL_PRESSURE); + BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_PITCH_BEND); + + // error list + + BIND_CORE_ENUM_CONSTANT(OK); // (0) + BIND_CORE_ENUM_CONSTANT(FAILED); + BIND_CORE_ENUM_CONSTANT(ERR_UNAVAILABLE); + BIND_CORE_ENUM_CONSTANT(ERR_UNCONFIGURED); + BIND_CORE_ENUM_CONSTANT(ERR_UNAUTHORIZED); + BIND_CORE_ENUM_CONSTANT(ERR_PARAMETER_RANGE_ERROR); // (5) + BIND_CORE_ENUM_CONSTANT(ERR_OUT_OF_MEMORY); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_NOT_FOUND); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_BAD_DRIVE); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_BAD_PATH); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_NO_PERMISSION); // (10) + BIND_CORE_ENUM_CONSTANT(ERR_FILE_ALREADY_IN_USE); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_CANT_OPEN); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_CANT_WRITE); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_CANT_READ); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_UNRECOGNIZED); // (15) + BIND_CORE_ENUM_CONSTANT(ERR_FILE_CORRUPT); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_MISSING_DEPENDENCIES); + BIND_CORE_ENUM_CONSTANT(ERR_FILE_EOF); + BIND_CORE_ENUM_CONSTANT(ERR_CANT_OPEN); + BIND_CORE_ENUM_CONSTANT(ERR_CANT_CREATE); // (20) + BIND_CORE_ENUM_CONSTANT(ERR_QUERY_FAILED); + BIND_CORE_ENUM_CONSTANT(ERR_ALREADY_IN_USE); + BIND_CORE_ENUM_CONSTANT(ERR_LOCKED); + BIND_CORE_ENUM_CONSTANT(ERR_TIMEOUT); + BIND_CORE_ENUM_CONSTANT(ERR_CANT_CONNECT); // (25) + BIND_CORE_ENUM_CONSTANT(ERR_CANT_RESOLVE); + BIND_CORE_ENUM_CONSTANT(ERR_CONNECTION_ERROR); + BIND_CORE_ENUM_CONSTANT(ERR_CANT_ACQUIRE_RESOURCE); + BIND_CORE_ENUM_CONSTANT(ERR_CANT_FORK); + BIND_CORE_ENUM_CONSTANT(ERR_INVALID_DATA); // (30) + BIND_CORE_ENUM_CONSTANT(ERR_INVALID_PARAMETER); + BIND_CORE_ENUM_CONSTANT(ERR_ALREADY_EXISTS); + BIND_CORE_ENUM_CONSTANT(ERR_DOES_NOT_EXIST); + BIND_CORE_ENUM_CONSTANT(ERR_DATABASE_CANT_READ); + BIND_CORE_ENUM_CONSTANT(ERR_DATABASE_CANT_WRITE); // (35) + BIND_CORE_ENUM_CONSTANT(ERR_COMPILATION_FAILED); + BIND_CORE_ENUM_CONSTANT(ERR_METHOD_NOT_FOUND); + BIND_CORE_ENUM_CONSTANT(ERR_LINK_FAILED); + BIND_CORE_ENUM_CONSTANT(ERR_SCRIPT_FAILED); + BIND_CORE_ENUM_CONSTANT(ERR_CYCLIC_LINK); // (40) + BIND_CORE_ENUM_CONSTANT(ERR_INVALID_DECLARATION); + BIND_CORE_ENUM_CONSTANT(ERR_DUPLICATE_SYMBOL); + BIND_CORE_ENUM_CONSTANT(ERR_PARSE_ERROR); + BIND_CORE_ENUM_CONSTANT(ERR_BUSY); + BIND_CORE_ENUM_CONSTANT(ERR_SKIP); // (45) + BIND_CORE_ENUM_CONSTANT(ERR_HELP); + BIND_CORE_ENUM_CONSTANT(ERR_BUG); + BIND_CORE_ENUM_CONSTANT(ERR_PRINTER_ON_FIRE); + + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_NONE); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_RANGE); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_EXP_RANGE); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_ENUM); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_EXP_EASING); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LENGTH); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_KEY_ACCEL); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_FLAGS); + + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_2D_RENDER); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_2D_PHYSICS); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_RENDER); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_PHYSICS); + + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_FILE); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_DIR); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_GLOBAL_FILE); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_GLOBAL_DIR); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_RESOURCE_TYPE); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_MULTILINE_TEXT); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_PLACEHOLDER_TEXT); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_COLOR_NO_ALPHA); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_IMAGE_COMPRESS_LOSSY); + BIND_CORE_ENUM_CONSTANT(PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS); + + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_STORAGE); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_EDITOR); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_NETWORK); + + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_EDITOR_HELPER); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_CHECKABLE); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_CHECKED); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_INTERNATIONALIZED); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_GROUP); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_CATEGORY); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_SUBGROUP); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_NO_INSTANCE_STATE); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_RESTART_IF_CHANGED); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_SCRIPT_VARIABLE); + + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_DEFAULT); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_DEFAULT_INTL); + BIND_CORE_ENUM_CONSTANT(PROPERTY_USAGE_NOEDITOR); + + BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_NORMAL); + BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_EDITOR); + BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_NOSCRIPT); + BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_CONST); + BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_REVERSE); + BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_VIRTUAL); + BIND_CORE_ENUM_CONSTANT(METHOD_FLAG_FROM_SCRIPT); + BIND_CORE_ENUM_CONSTANT(METHOD_FLAGS_DEFAULT); + + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_NIL", Variant::NIL); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_BOOL", Variant::BOOL); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_INT", Variant::INT); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_REAL", Variant::FLOAT); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_STRING", Variant::STRING); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2", Variant::VECTOR2); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2I", Variant::VECTOR2I); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_RECT2", Variant::RECT2); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_RECT2I", Variant::RECT2I); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3", Variant::VECTOR3); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3I", Variant::VECTOR3I); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM2D", Variant::TRANSFORM2D); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PLANE", Variant::PLANE); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_QUAT", Variant::QUAT); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_AABB", Variant::AABB); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_BASIS", Variant::BASIS); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM", Variant::TRANSFORM); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_COLOR", Variant::COLOR); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_STRING_NAME", Variant::STRING_NAME); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_NODE_PATH", Variant::NODE_PATH); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_RID", Variant::RID); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_OBJECT", Variant::OBJECT); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_CALLABLE", Variant::CALLABLE); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_SIGNAL", Variant::SIGNAL); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_DICTIONARY", Variant::DICTIONARY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_ARRAY", Variant::ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_RAW_ARRAY", Variant::PACKED_BYTE_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_INT32_ARRAY", Variant::PACKED_INT32_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_INT64_ARRAY", Variant::PACKED_INT64_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_FLOAT32_ARRAY", Variant::PACKED_FLOAT32_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_FLOAT64_ARRAY", Variant::PACKED_FLOAT64_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_STRING_ARRAY", Variant::PACKED_STRING_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2_ARRAY", Variant::PACKED_VECTOR2_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3_ARRAY", Variant::PACKED_VECTOR3_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_COLOR_ARRAY", Variant::PACKED_COLOR_ARRAY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX); + + //comparison + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_EQUAL", Variant::OP_EQUAL); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_NOT_EQUAL", Variant::OP_NOT_EQUAL); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_LESS", Variant::OP_LESS); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_LESS_EQUAL", Variant::OP_LESS_EQUAL); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_GREATER", Variant::OP_GREATER); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_GREATER_EQUAL", Variant::OP_GREATER_EQUAL); + //mathematic + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_ADD", Variant::OP_ADD); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_SUBTRACT", Variant::OP_SUBTRACT); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_MULTIPLY", Variant::OP_MULTIPLY); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_DIVIDE", Variant::OP_DIVIDE); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_NEGATE", Variant::OP_NEGATE); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_POSITIVE", Variant::OP_POSITIVE); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_MODULE", Variant::OP_MODULE); + //bitwise + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_SHIFT_LEFT", Variant::OP_SHIFT_LEFT); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_SHIFT_RIGHT", Variant::OP_SHIFT_RIGHT); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_BIT_AND", Variant::OP_BIT_AND); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_BIT_OR", Variant::OP_BIT_OR); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_BIT_XOR", Variant::OP_BIT_XOR); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_BIT_NEGATE", Variant::OP_BIT_NEGATE); + //logic + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_AND", Variant::OP_AND); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_OR", Variant::OP_OR); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_XOR", Variant::OP_XOR); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_NOT", Variant::OP_NOT); + //containment + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_IN", Variant::OP_IN); + BIND_CORE_ENUM_CONSTANT_CUSTOM("OP_MAX", Variant::OP_MAX); +} + +void unregister_global_constants() { + _global_constants.clear(); +} + +int CoreConstants::get_global_constant_count() { + return _global_constants.size(); +} + +#ifdef DEBUG_METHODS_ENABLED +StringName CoreConstants::get_global_constant_enum(int p_idx) { + return _global_constants[p_idx].enum_name; +} + +bool CoreConstants::get_ignore_value_in_docs(int p_idx) { + return _global_constants[p_idx].ignore_value_in_docs; +} +#else +StringName CoreConstants::get_global_constant_enum(int p_idx) { + return StringName(); +} + +bool CoreConstants::get_ignore_value_in_docs(int p_idx) { + return false; +} +#endif + +const char *CoreConstants::get_global_constant_name(int p_idx) { + return _global_constants[p_idx].name; +} + +int CoreConstants::get_global_constant_value(int p_idx) { + return _global_constants[p_idx].value; +} diff --git a/core/global_constants.h b/core/core_constants.h index 989633a6fa..6cddd9daec 100644 --- a/core/global_constants.h +++ b/core/core_constants.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* global_constants.h */ +/* core_constants.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,12 +28,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GLOBAL_CONSTANTS_H -#define GLOBAL_CONSTANTS_H +#ifndef CORE_CONSTANTS_H +#define CORE_CONSTANTS_H -#include "core/string_name.h" +#include "core/string/string_name.h" -class GlobalConstants { +class CoreConstants { public: static int get_global_constant_count(); static StringName get_global_constant_enum(int p_idx); diff --git a/core/core_string_names.h b/core/core_string_names.h index 43597ef301..c0bdc33d28 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 "core/string_name.h" +#include "core/string/string_name.h" class CoreStringNames { friend void register_core_types(); diff --git a/core/crypto/aes_context.h b/core/crypto/aes_context.h index 006ecee2ad..c23c504a72 100644 --- a/core/crypto/aes_context.h +++ b/core/crypto/aes_context.h @@ -32,7 +32,7 @@ #define AES_CONTEXT_H #include "core/crypto/crypto_core.h" -#include "core/reference.h" +#include "core/object/reference.h" class AESContext : public Reference { GDCLASS(AESContext, Reference); diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index 29d02e11df..d12108bca0 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -30,7 +30,7 @@ #include "crypto.h" -#include "core/engine.h" +#include "core/config/engine.h" #include "core/io/certs_compressed.gen.h" #include "core/io/compression.h" diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h index 916f7798eb..8325f043bf 100644 --- a/core/crypto/crypto.h +++ b/core/crypto/crypto.h @@ -32,10 +32,10 @@ #define CRYPTO_H #include "core/crypto/hashing_context.h" +#include "core/io/resource.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" -#include "core/reference.h" -#include "core/resource.h" +#include "core/object/reference.h" class CryptoKey : public Resource { GDCLASS(CryptoKey, Resource); diff --git a/core/crypto/crypto_core.h b/core/crypto/crypto_core.h index 9ab2871caa..57ba469f8d 100644 --- a/core/crypto/crypto_core.h +++ b/core/crypto/crypto_core.h @@ -31,7 +31,7 @@ #ifndef CRYPTO_CORE_H #define CRYPTO_CORE_H -#include "core/reference.h" +#include "core/object/reference.h" class CryptoCore { public: diff --git a/core/crypto/hashing_context.h b/core/crypto/hashing_context.h index f9454fa891..40d075afa9 100644 --- a/core/crypto/hashing_context.h +++ b/core/crypto/hashing_context.h @@ -31,7 +31,7 @@ #ifndef HASHING_CONTEXT_H #define HASHING_CONTEXT_H -#include "core/reference.h" +#include "core/object/reference.h" class HashingContext : public Reference { GDCLASS(HashingContext, Reference); diff --git a/core/debugger/debugger_marshalls.h b/core/debugger/debugger_marshalls.h index 7b7f4ac4b5..f5a1a891bf 100644 --- a/core/debugger/debugger_marshalls.h +++ b/core/debugger/debugger_marshalls.h @@ -31,7 +31,7 @@ #ifndef DEBUGGER_MARSHARLLS_H #define DEBUGGER_MARSHARLLS_H -#include "core/script_language.h" +#include "core/object/script_language.h" #include "servers/rendering_server.h" struct DebuggerMarshalls { diff --git a/core/debugger/engine_debugger.h b/core/debugger/engine_debugger.h index 8d5ebb2394..10f04bf97a 100644 --- a/core/debugger/engine_debugger.h +++ b/core/debugger/engine_debugger.h @@ -31,12 +31,12 @@ #ifndef ENGINE_DEBUGGER_H #define ENGINE_DEBUGGER_H -#include "core/array.h" -#include "core/map.h" -#include "core/string_name.h" -#include "core/ustring.h" -#include "core/variant.h" -#include "core/vector.h" +#include "core/string/string_name.h" +#include "core/string/ustring.h" +#include "core/templates/map.h" +#include "core/templates/vector.h" +#include "core/variant/array.h" +#include "core/variant/variant.h" class RemoteDebuggerPeer; class ScriptDebugger; diff --git a/core/debugger/local_debugger.h b/core/debugger/local_debugger.h index d342da6d44..dbdeec173b 100644 --- a/core/debugger/local_debugger.h +++ b/core/debugger/local_debugger.h @@ -32,8 +32,8 @@ #define LOCAL_DEBUGGER_H #include "core/debugger/engine_debugger.h" -#include "core/list.h" -#include "core/script_language.h" +#include "core/object/script_language.h" +#include "core/templates/list.h" class LocalDebugger : public EngineDebugger { private: diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index 9d55e1312e..ff89517497 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -30,13 +30,13 @@ #include "remote_debugger.h" +#include "core/config/project_settings.h" #include "core/debugger/debugger_marshalls.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" #include "core/input/input.h" +#include "core/object/script_language.h" #include "core/os/os.h" -#include "core/project_settings.h" -#include "core/script_language.h" #include "scene/main/node.h" #include "servers/display_server.h" diff --git a/core/debugger/remote_debugger.h b/core/debugger/remote_debugger.h index 320ee15996..37cc8af2a5 100644 --- a/core/debugger/remote_debugger.h +++ b/core/debugger/remote_debugger.h @@ -31,13 +31,13 @@ #ifndef REMOTE_DEBUGGER_H #define REMOTE_DEBUGGER_H -#include "core/array.h" -#include "core/class_db.h" #include "core/debugger/debugger_marshalls.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/remote_debugger_peer.h" -#include "core/string_name.h" -#include "core/ustring.h" +#include "core/object/class_db.h" +#include "core/string/string_name.h" +#include "core/string/ustring.h" +#include "core/variant/array.h" class RemoteDebugger : public EngineDebugger { public: diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 0ce0042f50..338c637014 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -30,9 +30,9 @@ #include "remote_debugger_peer.h" +#include "core/config/project_settings.h" #include "core/io/marshalls.h" #include "core/os/os.h" -#include "core/project_settings.h" bool RemoteDebuggerPeerTCP::is_peer_connected() { return connected; diff --git a/core/debugger/remote_debugger_peer.h b/core/debugger/remote_debugger_peer.h index 3a75a2a02b..79b88f5549 100644 --- a/core/debugger/remote_debugger_peer.h +++ b/core/debugger/remote_debugger_peer.h @@ -32,10 +32,10 @@ #define REMOTE_DEBUGGER_PEER_H #include "core/io/stream_peer_tcp.h" +#include "core/object/reference.h" #include "core/os/mutex.h" #include "core/os/thread.h" -#include "core/reference.h" -#include "core/ustring.h" +#include "core/string/ustring.h" class RemoteDebuggerPeer : public Reference { protected: diff --git a/core/debugger/script_debugger.h b/core/debugger/script_debugger.h index 0068691825..7f2f2becc2 100644 --- a/core/debugger/script_debugger.h +++ b/core/debugger/script_debugger.h @@ -31,11 +31,11 @@ #ifndef SCRIPT_DEBUGGER_H #define SCRIPT_DEBUGGER_H -#include "core/map.h" -#include "core/script_language.h" -#include "core/set.h" -#include "core/string_name.h" -#include "core/vector.h" +#include "core/object/script_language.h" +#include "core/string/string_name.h" +#include "core/templates/map.h" +#include "core/templates/set.h" +#include "core/templates/vector.h" class ScriptDebugger { typedef ScriptLanguage::StackInfo StackInfo; diff --git a/core/error/SCsub b/core/error/SCsub new file mode 100644 index 0000000000..dfd6248a94 --- /dev/null +++ b/core/error/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import("env") + +env_error = env.Clone() + +env_error.add_source_files(env.core_sources, "*.cpp") diff --git a/core/error_list.h b/core/error/error_list.h index a0218cf045..a0218cf045 100644 --- a/core/error_list.h +++ b/core/error/error_list.h diff --git a/core/error_macros.cpp b/core/error/error_macros.cpp index 2fae939965..80879dd25d 100644 --- a/core/error_macros.cpp +++ b/core/error/error_macros.cpp @@ -31,8 +31,8 @@ #include "error_macros.h" #include "core/io/logger.h" -#include "core/ustring.h" -#include "os/os.h" +#include "core/os/os.h" +#include "core/string/ustring.h" static ErrorHandlerList *error_handler_list = nullptr; diff --git a/core/error_macros.h b/core/error/error_macros.h index 6353961b04..6353961b04 100644 --- a/core/error_macros.h +++ b/core/error/error_macros.h diff --git a/core/func_ref.cpp b/core/func_ref.cpp deleted file mode 100644 index 7e062f16d0..0000000000 --- a/core/func_ref.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/*************************************************************************/ -/* func_ref.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 "func_ref.h" - -Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (id.is_null()) { - r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; - return Variant(); - } - Object *obj = ObjectDB::get_instance(id); - - if (!obj) { - r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; - return Variant(); - } - - return obj->call(function, p_args, p_argcount, r_error); -} - -Variant FuncRef::call_funcv(const Array &p_args) { - ERR_FAIL_COND_V(id.is_null(), Variant()); - - Object *obj = ObjectDB::get_instance(id); - - ERR_FAIL_COND_V(!obj, Variant()); - - return obj->callv(function, p_args); -} - -void FuncRef::set_instance(Object *p_obj) { - ERR_FAIL_NULL(p_obj); - id = p_obj->get_instance_id(); -} - -void FuncRef::set_function(const StringName &p_func) { - function = p_func; -} - -StringName FuncRef::get_function() { - return function; -} - -bool FuncRef::is_valid() const { - if (id.is_null()) { - return false; - } - - Object *obj = ObjectDB::get_instance(id); - if (!obj) { - return false; - } - - return obj->has_method(function); -} - -void FuncRef::_bind_methods() { - { - MethodInfo mi; - mi.name = "call_func"; - Vector<Variant> defargs; - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_func", &FuncRef::call_func, mi, defargs); - } - - ClassDB::bind_method(D_METHOD("call_funcv", "arg_array"), &FuncRef::call_funcv); - - ClassDB::bind_method(D_METHOD("set_instance", "instance"), &FuncRef::set_instance); - ClassDB::bind_method(D_METHOD("is_valid"), &FuncRef::is_valid); - - ClassDB::bind_method(D_METHOD("set_function", "name"), &FuncRef::set_function); - ClassDB::bind_method(D_METHOD("get_function"), &FuncRef::get_function); - - ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "function"), "set_function", "get_function"); -} diff --git a/core/func_ref.h b/core/func_ref.h deleted file mode 100644 index 75b84e705e..0000000000 --- a/core/func_ref.h +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************/ -/* func_ref.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 FUNC_REF_H -#define FUNC_REF_H - -#include "core/reference.h" - -class FuncRef : public Reference { - GDCLASS(FuncRef, Reference); - ObjectID id; - StringName function; - -protected: - static void _bind_methods(); - -public: - Variant call_func(const Variant **p_args, int p_argcount, Callable::CallError &r_error); - Variant call_funcv(const Array &p_args); - void set_instance(Object *p_obj); - void set_function(const StringName &p_func); - StringName get_function(); - bool is_valid() const; - - FuncRef() {} -}; - -#endif // FUNC_REF_H diff --git a/core/global_constants.cpp b/core/global_constants.cpp deleted file mode 100644 index bd4046553c..0000000000 --- a/core/global_constants.cpp +++ /dev/null @@ -1,690 +0,0 @@ -/*************************************************************************/ -/* global_constants.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 "global_constants.h" - -#include "core/class_db.h" -#include "core/input/input_event.h" -#include "core/os/keyboard.h" -#include "core/variant.h" - -struct _GlobalConstant { -#ifdef DEBUG_METHODS_ENABLED - StringName enum_name; - bool ignore_value_in_docs; -#endif - const char *name; - int value; - - _GlobalConstant() {} - -#ifdef DEBUG_METHODS_ENABLED - _GlobalConstant(const StringName &p_enum_name, const char *p_name, int p_value, bool p_ignore_value_in_docs = false) : - enum_name(p_enum_name), - ignore_value_in_docs(p_ignore_value_in_docs), - name(p_name), - value(p_value) { - } -#else - _GlobalConstant(const char *p_name, int p_value) : - name(p_name), - value(p_value) { - } -#endif -}; - -static Vector<_GlobalConstant> _global_constants; - -#ifdef DEBUG_METHODS_ENABLED - -#define BIND_GLOBAL_CONSTANT(m_constant) \ - _global_constants.push_back(_GlobalConstant(StringName(), #m_constant, m_constant)); - -#define BIND_GLOBAL_ENUM_CONSTANT(m_constant) \ - _global_constants.push_back(_GlobalConstant(__constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant)); - -#define BIND_GLOBAL_ENUM_CONSTANT_CUSTOM(m_custom_name, m_constant) \ - _global_constants.push_back(_GlobalConstant(__constant_get_enum_name(m_constant, #m_constant), m_custom_name, m_constant)); - -#define BIND_GLOBAL_CONSTANT_NO_VAL(m_constant) \ - _global_constants.push_back(_GlobalConstant(StringName(), #m_constant, m_constant, true)); - -#define BIND_GLOBAL_ENUM_CONSTANT_NO_VAL(m_constant) \ - _global_constants.push_back(_GlobalConstant(__constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant, true)); - -#define BIND_GLOBAL_ENUM_CONSTANT_CUSTOM_NO_VAL(m_custom_name, m_constant) \ - _global_constants.push_back(_GlobalConstant(__constant_get_enum_name(m_constant, #m_constant), m_custom_name, m_constant, true)); - -#else - -#define BIND_GLOBAL_CONSTANT(m_constant) \ - _global_constants.push_back(_GlobalConstant(#m_constant, m_constant)); - -#define BIND_GLOBAL_ENUM_CONSTANT(m_constant) \ - _global_constants.push_back(_GlobalConstant(#m_constant, m_constant)); - -#define BIND_GLOBAL_ENUM_CONSTANT_CUSTOM(m_custom_name, m_constant) \ - _global_constants.push_back(_GlobalConstant(m_custom_name, m_constant)); - -#define BIND_GLOBAL_CONSTANT_NO_VAL(m_constant) \ - _global_constants.push_back(_GlobalConstant(#m_constant, m_constant)); - -#define BIND_GLOBAL_ENUM_CONSTANT_NO_VAL(m_constant) \ - _global_constants.push_back(_GlobalConstant(#m_constant, m_constant)); - -#define BIND_GLOBAL_ENUM_CONSTANT_CUSTOM_NO_VAL(m_custom_name, m_constant) \ - _global_constants.push_back(_GlobalConstant(m_custom_name, m_constant)); - -#endif - -VARIANT_ENUM_CAST(KeyList); -VARIANT_ENUM_CAST(KeyModifierMask); -VARIANT_ENUM_CAST(ButtonList); -VARIANT_ENUM_CAST(JoyButtonList); -VARIANT_ENUM_CAST(JoyAxisList); -VARIANT_ENUM_CAST(MidiMessageList); - -void register_global_constants() { - BIND_GLOBAL_ENUM_CONSTANT(MARGIN_LEFT); - BIND_GLOBAL_ENUM_CONSTANT(MARGIN_TOP); - BIND_GLOBAL_ENUM_CONSTANT(MARGIN_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT(MARGIN_BOTTOM); - - BIND_GLOBAL_ENUM_CONSTANT(CORNER_TOP_LEFT); - BIND_GLOBAL_ENUM_CONSTANT(CORNER_TOP_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT(CORNER_BOTTOM_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT(CORNER_BOTTOM_LEFT); - - BIND_GLOBAL_ENUM_CONSTANT(VERTICAL); - BIND_GLOBAL_ENUM_CONSTANT(HORIZONTAL); - - BIND_GLOBAL_ENUM_CONSTANT(HALIGN_LEFT); - BIND_GLOBAL_ENUM_CONSTANT(HALIGN_CENTER); - BIND_GLOBAL_ENUM_CONSTANT(HALIGN_RIGHT); - - BIND_GLOBAL_ENUM_CONSTANT(VALIGN_TOP); - BIND_GLOBAL_ENUM_CONSTANT(VALIGN_CENTER); - BIND_GLOBAL_ENUM_CONSTANT(VALIGN_BOTTOM); - - // huge list of keys - BIND_GLOBAL_CONSTANT(SPKEY); - - BIND_GLOBAL_ENUM_CONSTANT(KEY_ESCAPE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_TAB); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BACKTAB); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BACKSPACE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ENTER); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_ENTER); - BIND_GLOBAL_ENUM_CONSTANT(KEY_INSERT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_DELETE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PAUSE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PRINT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SYSREQ); - BIND_GLOBAL_ENUM_CONSTANT(KEY_CLEAR); - BIND_GLOBAL_ENUM_CONSTANT(KEY_HOME); - BIND_GLOBAL_ENUM_CONSTANT(KEY_END); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LEFT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_UP); - BIND_GLOBAL_ENUM_CONSTANT(KEY_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_DOWN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PAGEUP); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PAGEDOWN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SHIFT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_CONTROL); - BIND_GLOBAL_ENUM_CONSTANT(KEY_META); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ALT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_CAPSLOCK); - BIND_GLOBAL_ENUM_CONSTANT(KEY_NUMLOCK); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SCROLLLOCK); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F1); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F2); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F3); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F4); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F5); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F6); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F7); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F8); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F9); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F10); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F11); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F12); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F13); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F14); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F15); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F16); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_MULTIPLY); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_DIVIDE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_SUBTRACT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_PERIOD); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_ADD); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_0); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_1); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_2); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_3); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_4); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_5); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_6); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_7); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_8); - BIND_GLOBAL_ENUM_CONSTANT(KEY_KP_9); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SUPER_L); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SUPER_R); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MENU); - BIND_GLOBAL_ENUM_CONSTANT(KEY_HYPER_L); - BIND_GLOBAL_ENUM_CONSTANT(KEY_HYPER_R); - BIND_GLOBAL_ENUM_CONSTANT(KEY_HELP); - BIND_GLOBAL_ENUM_CONSTANT(KEY_DIRECTION_L); - BIND_GLOBAL_ENUM_CONSTANT(KEY_DIRECTION_R); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BACK); - BIND_GLOBAL_ENUM_CONSTANT(KEY_FORWARD); - BIND_GLOBAL_ENUM_CONSTANT(KEY_STOP); - BIND_GLOBAL_ENUM_CONSTANT(KEY_REFRESH); - BIND_GLOBAL_ENUM_CONSTANT(KEY_VOLUMEDOWN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_VOLUMEMUTE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_VOLUMEUP); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BASSBOOST); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BASSUP); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BASSDOWN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_TREBLEUP); - BIND_GLOBAL_ENUM_CONSTANT(KEY_TREBLEDOWN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MEDIAPLAY); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MEDIASTOP); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MEDIAPREVIOUS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MEDIANEXT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MEDIARECORD); - BIND_GLOBAL_ENUM_CONSTANT(KEY_HOMEPAGE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_FAVORITES); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SEARCH); - BIND_GLOBAL_ENUM_CONSTANT(KEY_STANDBY); - BIND_GLOBAL_ENUM_CONSTANT(KEY_OPENURL); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCHMAIL); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCHMEDIA); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH0); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH1); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH2); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH3); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH4); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH5); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH6); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH7); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH8); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCH9); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCHA); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCHB); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCHC); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCHD); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCHE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LAUNCHF); - - BIND_GLOBAL_ENUM_CONSTANT(KEY_UNKNOWN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SPACE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_EXCLAM); - BIND_GLOBAL_ENUM_CONSTANT(KEY_QUOTEDBL); - BIND_GLOBAL_ENUM_CONSTANT(KEY_NUMBERSIGN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_DOLLAR); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PERCENT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_AMPERSAND); - BIND_GLOBAL_ENUM_CONSTANT(KEY_APOSTROPHE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PARENLEFT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PARENRIGHT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ASTERISK); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PLUS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_COMMA); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MINUS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PERIOD); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SLASH); - BIND_GLOBAL_ENUM_CONSTANT(KEY_0); - BIND_GLOBAL_ENUM_CONSTANT(KEY_1); - BIND_GLOBAL_ENUM_CONSTANT(KEY_2); - BIND_GLOBAL_ENUM_CONSTANT(KEY_3); - BIND_GLOBAL_ENUM_CONSTANT(KEY_4); - BIND_GLOBAL_ENUM_CONSTANT(KEY_5); - BIND_GLOBAL_ENUM_CONSTANT(KEY_6); - BIND_GLOBAL_ENUM_CONSTANT(KEY_7); - BIND_GLOBAL_ENUM_CONSTANT(KEY_8); - BIND_GLOBAL_ENUM_CONSTANT(KEY_9); - BIND_GLOBAL_ENUM_CONSTANT(KEY_COLON); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SEMICOLON); - BIND_GLOBAL_ENUM_CONSTANT(KEY_LESS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_EQUAL); - BIND_GLOBAL_ENUM_CONSTANT(KEY_GREATER); - BIND_GLOBAL_ENUM_CONSTANT(KEY_QUESTION); - BIND_GLOBAL_ENUM_CONSTANT(KEY_AT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_A); - BIND_GLOBAL_ENUM_CONSTANT(KEY_B); - BIND_GLOBAL_ENUM_CONSTANT(KEY_C); - BIND_GLOBAL_ENUM_CONSTANT(KEY_D); - BIND_GLOBAL_ENUM_CONSTANT(KEY_E); - BIND_GLOBAL_ENUM_CONSTANT(KEY_F); - BIND_GLOBAL_ENUM_CONSTANT(KEY_G); - BIND_GLOBAL_ENUM_CONSTANT(KEY_H); - BIND_GLOBAL_ENUM_CONSTANT(KEY_I); - BIND_GLOBAL_ENUM_CONSTANT(KEY_J); - BIND_GLOBAL_ENUM_CONSTANT(KEY_K); - BIND_GLOBAL_ENUM_CONSTANT(KEY_L); - BIND_GLOBAL_ENUM_CONSTANT(KEY_M); - BIND_GLOBAL_ENUM_CONSTANT(KEY_N); - BIND_GLOBAL_ENUM_CONSTANT(KEY_O); - BIND_GLOBAL_ENUM_CONSTANT(KEY_P); - BIND_GLOBAL_ENUM_CONSTANT(KEY_Q); - BIND_GLOBAL_ENUM_CONSTANT(KEY_R); - BIND_GLOBAL_ENUM_CONSTANT(KEY_S); - BIND_GLOBAL_ENUM_CONSTANT(KEY_T); - BIND_GLOBAL_ENUM_CONSTANT(KEY_U); - BIND_GLOBAL_ENUM_CONSTANT(KEY_V); - BIND_GLOBAL_ENUM_CONSTANT(KEY_W); - BIND_GLOBAL_ENUM_CONSTANT(KEY_X); - BIND_GLOBAL_ENUM_CONSTANT(KEY_Y); - BIND_GLOBAL_ENUM_CONSTANT(KEY_Z); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BRACKETLEFT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BACKSLASH); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BRACKETRIGHT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ASCIICIRCUM); - BIND_GLOBAL_ENUM_CONSTANT(KEY_UNDERSCORE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_QUOTELEFT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BRACELEFT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BAR); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BRACERIGHT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ASCIITILDE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_NOBREAKSPACE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_EXCLAMDOWN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_CENT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_STERLING); - BIND_GLOBAL_ENUM_CONSTANT(KEY_CURRENCY); - BIND_GLOBAL_ENUM_CONSTANT(KEY_YEN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_BROKENBAR); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SECTION); - BIND_GLOBAL_ENUM_CONSTANT(KEY_DIAERESIS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_COPYRIGHT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ORDFEMININE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_GUILLEMOTLEFT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_NOTSIGN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_HYPHEN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_REGISTERED); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MACRON); - BIND_GLOBAL_ENUM_CONSTANT(KEY_DEGREE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PLUSMINUS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_TWOSUPERIOR); - BIND_GLOBAL_ENUM_CONSTANT(KEY_THREESUPERIOR); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ACUTE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MU); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PARAGRAPH); - BIND_GLOBAL_ENUM_CONSTANT(KEY_PERIODCENTERED); - BIND_GLOBAL_ENUM_CONSTANT(KEY_CEDILLA); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ONESUPERIOR); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MASCULINE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_GUILLEMOTRIGHT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ONEQUARTER); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ONEHALF); - BIND_GLOBAL_ENUM_CONSTANT(KEY_THREEQUARTERS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_QUESTIONDOWN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_AGRAVE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_AACUTE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ACIRCUMFLEX); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ATILDE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ADIAERESIS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ARING); - BIND_GLOBAL_ENUM_CONSTANT(KEY_AE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_CCEDILLA); - BIND_GLOBAL_ENUM_CONSTANT(KEY_EGRAVE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_EACUTE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ECIRCUMFLEX); - BIND_GLOBAL_ENUM_CONSTANT(KEY_EDIAERESIS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_IGRAVE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_IACUTE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ICIRCUMFLEX); - BIND_GLOBAL_ENUM_CONSTANT(KEY_IDIAERESIS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ETH); - BIND_GLOBAL_ENUM_CONSTANT(KEY_NTILDE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_OGRAVE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_OACUTE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_OCIRCUMFLEX); - BIND_GLOBAL_ENUM_CONSTANT(KEY_OTILDE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_ODIAERESIS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MULTIPLY); - BIND_GLOBAL_ENUM_CONSTANT(KEY_OOBLIQUE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_UGRAVE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_UACUTE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_UCIRCUMFLEX); - BIND_GLOBAL_ENUM_CONSTANT(KEY_UDIAERESIS); - BIND_GLOBAL_ENUM_CONSTANT(KEY_YACUTE); - BIND_GLOBAL_ENUM_CONSTANT(KEY_THORN); - BIND_GLOBAL_ENUM_CONSTANT(KEY_SSHARP); - - BIND_GLOBAL_ENUM_CONSTANT(KEY_DIVISION); - BIND_GLOBAL_ENUM_CONSTANT(KEY_YDIAERESIS); - - BIND_GLOBAL_ENUM_CONSTANT(KEY_CODE_MASK); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MODIFIER_MASK); - - BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_SHIFT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_ALT); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_META); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_CTRL); - BIND_GLOBAL_ENUM_CONSTANT_NO_VAL(KEY_MASK_CMD); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_KPAD); - BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_GROUP_SWITCH); - - // mouse - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_LEFT); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MIDDLE); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_XBUTTON1); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_XBUTTON2); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_WHEEL_UP); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_WHEEL_DOWN); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_WHEEL_LEFT); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_WHEEL_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_LEFT); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_MIDDLE); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_XBUTTON1); - BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_XBUTTON2); - - // Joypad buttons - BIND_GLOBAL_ENUM_CONSTANT(JOY_INVALID_BUTTON); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_A); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_B); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_Y); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_BACK); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_GUIDE); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_START); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_LEFT_STICK); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_RIGHT_STICK); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_LEFT_SHOULDER); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_RIGHT_SHOULDER); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_DPAD_UP); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_DPAD_DOWN); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_DPAD_LEFT); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_DPAD_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SDL_BUTTONS); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_CROSS); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_CIRCLE); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_SQUARE); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_TRIANGLE); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_SELECT); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_START); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_PS); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_L1); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_R1); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_L3); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_R3); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_A); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_B); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_Y); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_BACK); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_START); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_HOME); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_LS); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_RS); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_LB); - BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_RB); - BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_MAX); - - // Joypad axes - BIND_GLOBAL_ENUM_CONSTANT(JOY_INVALID_AXIS); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_LEFT_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_LEFT_Y); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_RIGHT_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_RIGHT_Y); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_TRIGGER_LEFT); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_TRIGGER_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT(JOY_SDL_AXES); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_0_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_0_Y); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_1_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_1_Y); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_2_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_2_Y); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_3_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_3_Y); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_4_X); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_4_Y); - BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_MAX); - - // midi - BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_OFF); - BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_ON); - BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_AFTERTOUCH); - BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_CONTROL_CHANGE); - BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_PROGRAM_CHANGE); - BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_CHANNEL_PRESSURE); - BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_PITCH_BEND); - - // error list - - BIND_GLOBAL_ENUM_CONSTANT(OK); // (0) - BIND_GLOBAL_ENUM_CONSTANT(FAILED); - BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAVAILABLE); - BIND_GLOBAL_ENUM_CONSTANT(ERR_UNCONFIGURED); - BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAUTHORIZED); - BIND_GLOBAL_ENUM_CONSTANT(ERR_PARAMETER_RANGE_ERROR); // (5) - BIND_GLOBAL_ENUM_CONSTANT(ERR_OUT_OF_MEMORY); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_NOT_FOUND); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_BAD_DRIVE); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_BAD_PATH); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_NO_PERMISSION); // (10) - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_ALREADY_IN_USE); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CANT_OPEN); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CANT_WRITE); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CANT_READ); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_UNRECOGNIZED); // (15) - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CORRUPT); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_MISSING_DEPENDENCIES); - BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_EOF); - BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_OPEN); - BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_CREATE); // (20) - BIND_GLOBAL_ENUM_CONSTANT(ERR_QUERY_FAILED); - BIND_GLOBAL_ENUM_CONSTANT(ERR_ALREADY_IN_USE); - BIND_GLOBAL_ENUM_CONSTANT(ERR_LOCKED); - BIND_GLOBAL_ENUM_CONSTANT(ERR_TIMEOUT); - BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_CONNECT); // (25) - BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_RESOLVE); - BIND_GLOBAL_ENUM_CONSTANT(ERR_CONNECTION_ERROR); - BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_ACQUIRE_RESOURCE); - BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_FORK); - BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_DATA); // (30) - BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_PARAMETER); - BIND_GLOBAL_ENUM_CONSTANT(ERR_ALREADY_EXISTS); - BIND_GLOBAL_ENUM_CONSTANT(ERR_DOES_NOT_EXIST); - BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_READ); - BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_WRITE); // (35) - BIND_GLOBAL_ENUM_CONSTANT(ERR_COMPILATION_FAILED); - BIND_GLOBAL_ENUM_CONSTANT(ERR_METHOD_NOT_FOUND); - BIND_GLOBAL_ENUM_CONSTANT(ERR_LINK_FAILED); - BIND_GLOBAL_ENUM_CONSTANT(ERR_SCRIPT_FAILED); - BIND_GLOBAL_ENUM_CONSTANT(ERR_CYCLIC_LINK); // (40) - BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_DECLARATION); - BIND_GLOBAL_ENUM_CONSTANT(ERR_DUPLICATE_SYMBOL); - BIND_GLOBAL_ENUM_CONSTANT(ERR_PARSE_ERROR); - BIND_GLOBAL_ENUM_CONSTANT(ERR_BUSY); - BIND_GLOBAL_ENUM_CONSTANT(ERR_SKIP); // (45) - BIND_GLOBAL_ENUM_CONSTANT(ERR_HELP); - BIND_GLOBAL_ENUM_CONSTANT(ERR_BUG); - BIND_GLOBAL_ENUM_CONSTANT(ERR_PRINTER_ON_FIRE); - - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_NONE); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_RANGE); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_EXP_RANGE); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_ENUM); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_EXP_EASING); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_LENGTH); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_KEY_ACCEL); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_FLAGS); - - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_2D_RENDER); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_2D_PHYSICS); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_RENDER); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_LAYERS_3D_PHYSICS); - - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_FILE); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_DIR); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_GLOBAL_FILE); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_GLOBAL_DIR); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_RESOURCE_TYPE); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_MULTILINE_TEXT); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_PLACEHOLDER_TEXT); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_COLOR_NO_ALPHA); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_IMAGE_COMPRESS_LOSSY); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS); - - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_STORAGE); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_EDITOR); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_NETWORK); - - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_EDITOR_HELPER); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_CHECKABLE); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_CHECKED); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_INTERNATIONALIZED); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_GROUP); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_CATEGORY); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_SUBGROUP); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_NO_INSTANCE_STATE); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_RESTART_IF_CHANGED); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_SCRIPT_VARIABLE); - - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_DEFAULT); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_DEFAULT_INTL); - BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_USAGE_NOEDITOR); - - BIND_GLOBAL_ENUM_CONSTANT(METHOD_FLAG_NORMAL); - BIND_GLOBAL_ENUM_CONSTANT(METHOD_FLAG_EDITOR); - BIND_GLOBAL_ENUM_CONSTANT(METHOD_FLAG_NOSCRIPT); - BIND_GLOBAL_ENUM_CONSTANT(METHOD_FLAG_CONST); - BIND_GLOBAL_ENUM_CONSTANT(METHOD_FLAG_REVERSE); - BIND_GLOBAL_ENUM_CONSTANT(METHOD_FLAG_VIRTUAL); - BIND_GLOBAL_ENUM_CONSTANT(METHOD_FLAG_FROM_SCRIPT); - BIND_GLOBAL_ENUM_CONSTANT(METHOD_FLAGS_DEFAULT); - - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_NIL", Variant::NIL); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_BOOL", Variant::BOOL); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_INT", Variant::INT); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_REAL", Variant::FLOAT); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_STRING", Variant::STRING); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2", Variant::VECTOR2); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2I", Variant::VECTOR2I); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RECT2", Variant::RECT2); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RECT2I", Variant::RECT2I); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3", Variant::VECTOR3); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3I", Variant::VECTOR3I); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM2D", Variant::TRANSFORM2D); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_PLANE", Variant::PLANE); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_QUAT", Variant::QUAT); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_AABB", Variant::AABB); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_BASIS", Variant::BASIS); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM", Variant::TRANSFORM); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_COLOR", Variant::COLOR); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_STRING_NAME", Variant::STRING_NAME); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_NODE_PATH", Variant::NODE_PATH); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RID", Variant::_RID); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_OBJECT", Variant::OBJECT); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_CALLABLE", Variant::CALLABLE); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_SIGNAL", Variant::SIGNAL); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_DICTIONARY", Variant::DICTIONARY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_ARRAY", Variant::ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RAW_ARRAY", Variant::PACKED_BYTE_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_INT32_ARRAY", Variant::PACKED_INT32_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_INT64_ARRAY", Variant::PACKED_INT64_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_FLOAT32_ARRAY", Variant::PACKED_FLOAT32_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_FLOAT64_ARRAY", Variant::PACKED_FLOAT64_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_STRING_ARRAY", Variant::PACKED_STRING_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2_ARRAY", Variant::PACKED_VECTOR2_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3_ARRAY", Variant::PACKED_VECTOR3_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_COLOR_ARRAY", Variant::PACKED_COLOR_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX); - - //comparison - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_EQUAL", Variant::OP_EQUAL); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NOT_EQUAL", Variant::OP_NOT_EQUAL); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_LESS", Variant::OP_LESS); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_LESS_EQUAL", Variant::OP_LESS_EQUAL); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_GREATER", Variant::OP_GREATER); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_GREATER_EQUAL", Variant::OP_GREATER_EQUAL); - //mathematic - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_ADD", Variant::OP_ADD); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_SUBTRACT", Variant::OP_SUBTRACT); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_MULTIPLY", Variant::OP_MULTIPLY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_DIVIDE", Variant::OP_DIVIDE); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NEGATE", Variant::OP_NEGATE); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_POSITIVE", Variant::OP_POSITIVE); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_MODULE", Variant::OP_MODULE); - //bitwise - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_SHIFT_LEFT", Variant::OP_SHIFT_LEFT); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_SHIFT_RIGHT", Variant::OP_SHIFT_RIGHT); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_AND", Variant::OP_BIT_AND); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_OR", Variant::OP_BIT_OR); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_XOR", Variant::OP_BIT_XOR); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_BIT_NEGATE", Variant::OP_BIT_NEGATE); - //logic - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_AND", Variant::OP_AND); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_OR", Variant::OP_OR); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_XOR", Variant::OP_XOR); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_NOT", Variant::OP_NOT); - //containment - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_IN", Variant::OP_IN); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("OP_MAX", Variant::OP_MAX); -} - -void unregister_global_constants() { - _global_constants.clear(); -} - -int GlobalConstants::get_global_constant_count() { - return _global_constants.size(); -} - -#ifdef DEBUG_METHODS_ENABLED -StringName GlobalConstants::get_global_constant_enum(int p_idx) { - return _global_constants[p_idx].enum_name; -} - -bool GlobalConstants::get_ignore_value_in_docs(int p_idx) { - return _global_constants[p_idx].ignore_value_in_docs; -} -#else -StringName GlobalConstants::get_global_constant_enum(int p_idx) { - return StringName(); -} - -bool GlobalConstants::get_ignore_value_in_docs(int p_idx) { - return false; -} -#endif - -const char *GlobalConstants::get_global_constant_name(int p_idx) { - return _global_constants[p_idx].name; -} - -int GlobalConstants::get_global_constant_value(int p_idx) { - return _global_constants[p_idx].value; -} diff --git a/core/input/input.cpp b/core/input/input.cpp index b0b1d20222..a408cd674b 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -30,10 +30,10 @@ #include "input.h" +#include "core/config/project_settings.h" #include "core/input/default_controller_mappings.h" #include "core/input/input_map.h" #include "core/os/os.h" -#include "core/project_settings.h" #ifdef TOOLS_ENABLED #include "editor/editor_settings.h" @@ -149,6 +149,9 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("is_action_just_pressed", "action"), &Input::is_action_just_pressed); ClassDB::bind_method(D_METHOD("is_action_just_released", "action"), &Input::is_action_just_released); ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &Input::get_action_strength); + ClassDB::bind_method(D_METHOD("get_action_raw_strength", "action"), &Input::get_action_strength); + ClassDB::bind_method(D_METHOD("get_axis", "negative_action", "positive_action"), &Input::get_axis); + ClassDB::bind_method(D_METHOD("get_vector", "negative_x", "positive_x", "negative_y", "positive_y", "deadzone"), &Input::get_vector, DEFVAL(-1.0f)); ClassDB::bind_method(D_METHOD("add_joy_mapping", "mapping", "update_existing"), &Input::add_joy_mapping, DEFVAL(false)); ClassDB::bind_method(D_METHOD("remove_joy_mapping", "guid"), &Input::remove_joy_mapping); ClassDB::bind_method(D_METHOD("joy_connection_changed", "device", "connected", "name", "guid"), &Input::joy_connection_changed); @@ -215,7 +218,9 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\""; String pf = p_function; - if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) { + if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || + pf == "is_action_just_pressed" || pf == "is_action_just_released" || + pf == "get_action_strength" || pf == "get_axis" || pf == "get_vector")) { List<PropertyInfo> pinfo; ProjectSettings::get_singleton()->get_property_list(&pinfo); @@ -326,6 +331,46 @@ float Input::get_action_strength(const StringName &p_action) const { return E->get().strength; } +float Input::get_action_raw_strength(const StringName &p_action) const { + const Map<StringName, Action>::Element *E = action_state.find(p_action); + if (!E) { + return 0.0f; + } + + return E->get().raw_strength; +} + +float Input::get_axis(const StringName &p_negative_action, const StringName &p_positive_action) const { + return get_action_strength(p_positive_action) - get_action_strength(p_negative_action); +} + +Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone) const { + Vector2 vector = Vector2( + get_action_raw_strength(p_positive_x) - get_action_raw_strength(p_negative_x), + get_action_raw_strength(p_positive_y) - get_action_raw_strength(p_negative_y)); + + if (p_deadzone < 0.0f) { + // If the deadzone isn't specified, get it from the average of the actions. + p_deadzone = (InputMap::get_singleton()->action_get_deadzone(p_positive_x) + + InputMap::get_singleton()->action_get_deadzone(p_negative_x) + + InputMap::get_singleton()->action_get_deadzone(p_positive_y) + + InputMap::get_singleton()->action_get_deadzone(p_negative_y)) / + 4; + } + + // Circular length limiting and deadzone. + float length = vector.length(); + if (length <= p_deadzone) { + return Vector2(); + } else if (length > 1.0f) { + return vector / length; + } else { + // Inverse lerp length to map (p_deadzone, 1) to (0, 1). + return vector * (Math::inverse_lerp(p_deadzone, 1.0f, length) / length); + } + return vector; +} + float Input::get_joy_axis(int p_device, int p_axis) const { _THREAD_SAFE_METHOD_ int c = _combine_device(p_axis, p_device); @@ -603,10 +648,12 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em action.physics_frame = Engine::get_singleton()->get_physics_frames(); action.idle_frame = Engine::get_singleton()->get_idle_frames(); action.pressed = p_event->is_action_pressed(E->key()); - action.strength = 0.f; + action.strength = 0.0f; + action.raw_strength = 0.0f; action_state[E->key()] = action; } action_state[E->key()].strength = p_event->get_action_strength(E->key()); + action_state[E->key()].raw_strength = p_event->get_action_raw_strength(E->key()); } } diff --git a/core/input/input.h b/core/input/input.h index 60e378d72c..cbb884216a 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -32,7 +32,7 @@ #define INPUT_H #include "core/input/input_event.h" -#include "core/object.h" +#include "core/object/object.h" #include "core/os/thread_safe.h" class Input : public Object { @@ -117,6 +117,7 @@ private: uint64_t idle_frame; bool pressed; float strength; + float raw_strength; }; Map<StringName, Action> action_state; @@ -223,7 +224,6 @@ private: JoyAxisList _get_output_axis(String output); void _button_event(int p_device, int p_index, bool p_pressed); void _axis_event(int p_device, int p_axis, float p_value); - float _handle_deadzone(int p_device, int p_axis, float p_value); void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated); @@ -266,6 +266,10 @@ public: bool is_action_just_pressed(const StringName &p_action) const; bool is_action_just_released(const StringName &p_action) const; float get_action_strength(const StringName &p_action) const; + float get_action_raw_strength(const StringName &p_action) const; + + float get_axis(const StringName &p_negative_action, const StringName &p_positive_action) const; + Vector2 get_vector(const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone = -1.0f) const; float get_joy_axis(int p_device, int p_axis) const; String get_joy_name(int p_idx); diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 6ba082f86f..31ce1bb892 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -61,12 +61,17 @@ bool InputEvent::is_action_released(const StringName &p_action) const { } float InputEvent::get_action_strength(const StringName &p_action) const { - bool pressed; float strength; - bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, &pressed, &strength); + bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, nullptr, &strength); return valid ? strength : 0.0f; } +float InputEvent::get_action_raw_strength(const StringName &p_action) const { + float raw_strength; + bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>((InputEvent *)this), p_action, nullptr, nullptr, &raw_strength); + return valid ? raw_strength : 0.0f; +} + bool InputEvent::is_pressed() const { return false; } @@ -83,7 +88,7 @@ String InputEvent::as_text() const { return String(); } -bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { +bool InputEvent::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const { return false; } @@ -307,7 +312,7 @@ String InputEventKey::as_text() const { return kc; } -bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { +bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const { Ref<InputEventKey> key = p_event; if (key.is_null()) { return false; @@ -329,8 +334,12 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed if (p_pressed != nullptr) { *p_pressed = key->is_pressed(); } + float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; if (p_strength != nullptr) { - *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + *p_strength = strength; + } + if (p_raw_strength != nullptr) { + *p_raw_strength = strength; } } return match; @@ -470,7 +479,7 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co return mb; } -bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { +bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const { Ref<InputEventMouseButton> mb = p_event; if (mb.is_null()) { return false; @@ -481,8 +490,12 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p if (p_pressed != nullptr) { *p_pressed = mb->is_pressed(); } + float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; if (p_strength != nullptr) { - *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + *p_strength = strength; + } + if (p_raw_strength != nullptr) { + *p_raw_strength = strength; } } @@ -713,7 +726,7 @@ bool InputEventJoypadMotion::is_pressed() const { return Math::abs(axis_value) >= 0.5f; } -bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { +bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const { Ref<InputEventJoypadMotion> jm = p_event; if (jm.is_null()) { return false; @@ -721,8 +734,9 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool * bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event. if (match) { + float jm_abs_axis_value = Math::abs(jm->get_axis_value()); bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0); - bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false; + bool pressed = same_direction && jm_abs_axis_value >= p_deadzone; if (p_pressed != nullptr) { *p_pressed = pressed; } @@ -731,12 +745,19 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool * if (p_deadzone == 1.0f) { *p_strength = 1.0f; } else { - *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f); + *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, jm_abs_axis_value), 0.0f, 1.0f); } } else { *p_strength = 0.0f; } } + if (p_raw_strength != nullptr) { + if (same_direction) { // NOT pressed, because we want to ignore the deadzone. + *p_raw_strength = jm_abs_axis_value; + } else { + *p_raw_strength = 0.0f; + } + } } return match; } @@ -782,7 +803,7 @@ float InputEventJoypadButton::get_pressure() const { return pressure; } -bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { +bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const { Ref<InputEventJoypadButton> jb = p_event; if (jb.is_null()) { return false; @@ -793,8 +814,12 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool * if (p_pressed != nullptr) { *p_pressed = jb->is_pressed(); } + float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; if (p_strength != nullptr) { - *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + *p_strength = strength; + } + if (p_raw_strength != nullptr) { + *p_raw_strength = strength; } } @@ -997,7 +1022,7 @@ 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 { +bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const { Ref<InputEventAction> act = p_event; if (act.is_null()) { return false; @@ -1008,8 +1033,12 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pres if (p_pressed != nullptr) { *p_pressed = act->pressed; } + float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; if (p_strength != nullptr) { - *p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + *p_strength = strength; + } + if (p_raw_strength != nullptr) { + *p_raw_strength = strength; } } return match; diff --git a/core/input/input_event.h b/core/input/input_event.h index 815ba5ae80..50d56291d1 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -31,11 +31,11 @@ #ifndef INPUT_EVENT_H #define INPUT_EVENT_H +#include "core/io/resource.h" #include "core/math/transform_2d.h" #include "core/os/copymem.h" -#include "core/resource.h" +#include "core/string/ustring.h" #include "core/typedefs.h" -#include "core/ustring.h" /** * Input Event classes. These are used in the main loop. @@ -173,6 +173,7 @@ public: bool is_action_pressed(const StringName &p_action, bool p_allow_echo = false) const; bool is_action_released(const StringName &p_action) const; float get_action_strength(const StringName &p_action) const; + float get_action_raw_strength(const StringName &p_action) const; // To be removed someday, since they do not make sense for all events virtual bool is_pressed() const; @@ -182,7 +183,7 @@ public: virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; - virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const; + virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const; virtual bool shortcut_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const; @@ -283,7 +284,7 @@ public: uint32_t get_keycode_with_modifiers() const; uint32_t get_physical_keycode_with_modifiers() const; - virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override; + virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override; virtual bool is_action_type() const override { return true; } @@ -342,7 +343,7 @@ public: bool is_doubleclick() const; virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override; - virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override; + virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; virtual bool is_action_type() const override { return true; } virtual String as_text() const override; @@ -399,7 +400,7 @@ public: virtual bool is_pressed() const override; - virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override; + virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; virtual bool is_action_type() const override { return true; } virtual String as_text() const override; @@ -426,7 +427,7 @@ public: void set_pressure(float p_pressure); float get_pressure() const; - virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override; + virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override; virtual bool is_action_type() const override { return true; } @@ -511,7 +512,7 @@ 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 override; + virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override; virtual bool is_action_type() const override { return true; } diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index 6319ffc8f1..9fd5476f51 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -30,8 +30,9 @@ #include "input_map.h" +#include "core/config/project_settings.h" +#include "core/input/input.h" #include "core/os/keyboard.h" -#include "core/project_settings.h" InputMap *InputMap::singleton = nullptr; @@ -94,7 +95,7 @@ List<StringName> InputMap::get_actions() const { return actions; } -List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength) const { +List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength) const { ERR_FAIL_COND_V(!p_event.is_valid(), nullptr); for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) { @@ -105,7 +106,7 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re int device = e->get_device(); if (device == ALL_DEVICES || device == p_event->get_device()) { - if (e->action_match(p_event, p_pressed, p_strength, p_action.deadzone)) { + if (e->action_match(p_event, p_pressed, p_strength, p_raw_strength, p_action.deadzone)) { return E; } } @@ -118,6 +119,12 @@ bool InputMap::has_action(const StringName &p_action) const { return input_map.has(p_action); } +float InputMap::action_get_deadzone(const StringName &p_action) { + ERR_FAIL_COND_V_MSG(!input_map.has(p_action), 0.0f, "Request for nonexistent InputMap action '" + String(p_action) + "'."); + + return input_map[p_action].deadzone; +} + void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) { ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'."); @@ -145,6 +152,9 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event); if (E) { input_map[p_action].inputs.erase(E); + if (Input::get_singleton()->is_action_pressed(p_action)) { + Input::get_singleton()->action_release(p_action); + } } } @@ -179,7 +189,7 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName return event_get_action_status(p_event, p_action); } -bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed, float *p_strength) const { +bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed, float *p_strength, float *p_raw_strength) const { Map<StringName, Action>::Element *E = input_map.find(p_action); ERR_FAIL_COND_V_MSG(!E, false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); @@ -196,7 +206,8 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str bool pressed; float strength; - List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, &pressed, &strength); + float raw_strength; + List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, &pressed, &strength, &raw_strength); if (event != nullptr) { if (p_pressed != nullptr) { *p_pressed = pressed; @@ -204,6 +215,9 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str if (p_strength != nullptr) { *p_strength = strength; } + if (p_raw_strength != nullptr) { + *p_raw_strength = raw_strength; + } return true; } else { return false; diff --git a/core/input/input_map.h b/core/input/input_map.h index 755df26984..019a1056fb 100644 --- a/core/input/input_map.h +++ b/core/input/input_map.h @@ -31,8 +31,8 @@ #ifndef INPUT_MAP_H #define INPUT_MAP_H -#include "core/class_db.h" #include "core/input/input_event.h" +#include "core/object/class_db.h" class InputMap : public Object { GDCLASS(InputMap, Object); @@ -54,7 +54,7 @@ private: mutable Map<StringName, Action> input_map; - List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed = nullptr, float *p_strength = nullptr) const; + List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const; Array _action_get_events(const StringName &p_action); Array _get_actions(); @@ -70,6 +70,7 @@ public: void add_action(const StringName &p_action, float p_deadzone = 0.5); void erase_action(const StringName &p_action); + float action_get_deadzone(const StringName &p_action); void action_set_deadzone(const StringName &p_action, float p_deadzone); void action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event); bool action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event); @@ -78,7 +79,7 @@ public: const List<Ref<InputEvent>> *action_get_events(const StringName &p_action); bool event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const; - bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed = nullptr, float *p_strength = nullptr) const; + bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const; const Map<StringName, Action> &get_action_map() const; void load_from_globals(); diff --git a/core/int_types.h b/core/int_types.h deleted file mode 100644 index 71caa2202d..0000000000 --- a/core/int_types.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************/ -/* int_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 INT_TYPES_H -#define INT_TYPES_H - -#ifdef _MSC_VER - -typedef signed __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef signed __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef signed __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; - -#else - -#ifdef NO_STDINT_H -typedef unsigned char uint8_t; -typedef signed char int8_t; -typedef unsigned short uint16_t; -typedef signed short int16_t; -typedef unsigned int uint32_t; -typedef signed int int32_t; -typedef long long int64_t; -typedef unsigned long long uint64_t; -#else -#include <stdint.h> -#endif - -#endif // _MSC_VER - -#endif // INT_TYPES_H diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 7480262835..cd8793bb0a 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -30,9 +30,9 @@ #include "compression.h" +#include "core/config/project_settings.h" #include "core/io/zip_io.h" #include "core/os/copymem.h" -#include "core/project_settings.h" #include "thirdparty/misc/fastlz.h" diff --git a/core/io/compression.h b/core/io/compression.h index c103fa8eae..864869788a 100644 --- a/core/io/compression.h +++ b/core/io/compression.h @@ -31,8 +31,8 @@ #ifndef COMPRESSION_H #define COMPRESSION_H +#include "core/templates/vector.h" #include "core/typedefs.h" -#include "core/vector.h" class Compression { public: diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 1af9142317..8be39178db 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -32,7 +32,7 @@ #include "core/io/file_access_encrypted.h" #include "core/os/keyboard.h" -#include "core/variant_parser.h" +#include "core/variant/variant_parser.h" PackedStringArray ConfigFile::_get_sections() const { List<String> s; diff --git a/core/io/config_file.h b/core/io/config_file.h index ae06960f02..1dc4492ca8 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -31,10 +31,10 @@ #ifndef CONFIG_FILE_H #define CONFIG_FILE_H -#include "core/ordered_hash_map.h" +#include "core/object/reference.h" #include "core/os/file_access.h" -#include "core/reference.h" -#include "core/variant_parser.h" +#include "core/templates/ordered_hash_map.h" +#include "core/variant/variant_parser.h" class ConfigFile : public Reference { GDCLASS(ConfigFile, Reference); diff --git a/core/io/dtls_server.cpp b/core/io/dtls_server.cpp index e43b1f5385..1930f40c47 100644 --- a/core/io/dtls_server.cpp +++ b/core/io/dtls_server.cpp @@ -30,8 +30,8 @@ #include "dtls_server.h" +#include "core/config/project_settings.h" #include "core/os/file_access.h" -#include "core/project_settings.h" DTLSServer *(*DTLSServer::_create)() = nullptr; bool DTLSServer::available = false; diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp index 6208f3a4d1..714f3b6099 100644 --- a/core/io/file_access_buffered.cpp +++ b/core/io/file_access_buffered.cpp @@ -30,7 +30,7 @@ #include "file_access_buffered.h" -#include "core/error_macros.h" +#include "core/error/error_macros.h" Error FileAccessBuffered::set_error(Error p_error) const { return (last_error = p_error); diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h index 99d5ce903d..7fd99b6373 100644 --- a/core/io/file_access_buffered.h +++ b/core/io/file_access_buffered.h @@ -33,7 +33,7 @@ #include "core/os/file_access.h" -#include "core/ustring.h" +#include "core/string/ustring.h" class FileAccessBuffered : public FileAccess { public: diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 7817ccb773..4424192af2 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -30,7 +30,7 @@ #include "file_access_compressed.h" -#include "core/print_string.h" +#include "core/string/print_string.h" void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) { magic = p_magic.ascii().get_data(); diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index eb684f457e..2ac24d5169 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -32,8 +32,8 @@ #include "core/crypto/crypto_core.h" #include "core/os/copymem.h" -#include "core/print_string.h" -#include "core/variant.h" +#include "core/string/print_string.h" +#include "core/variant/variant.h" #include <stdio.h> diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index a65ff92a89..79cba63765 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 "core/map.h" +#include "core/config/project_settings.h" #include "core/os/copymem.h" #include "core/os/dir_access.h" -#include "core/project_settings.h" +#include "core/templates/map.h" static Map<String, Vector<uint8_t>> *files = nullptr; diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 6890740d90..1e9266f118 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -30,10 +30,10 @@ #include "file_access_network.h" +#include "core/config/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()); diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 8fdbb650d4..a025ca5730 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -31,7 +31,7 @@ #include "file_access_pack.h" #include "core/io/file_access_encrypted.h" -#include "core/script_language.h" +#include "core/object/script_language.h" #include "core/version.h" #include <stdio.h> @@ -442,8 +442,14 @@ String DirAccessPack::get_drive(int p_drive) { return ""; } -Error DirAccessPack::change_dir(String p_dir) { +PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) { String nd = p_dir.replace("\\", "/"); + + // Special handling since simplify_path() will forbid it + if (p_dir == "..") { + return current->parent; + } + bool absolute = false; if (nd.begins_with("res://")) { nd = nd.replace_first("res://", ""); @@ -483,13 +489,21 @@ Error DirAccessPack::change_dir(String p_dir) { pd = pd->subdirs[p]; } else { - return ERR_INVALID_PARAMETER; + return nullptr; } } - current = pd; + return pd; +} - return OK; +Error DirAccessPack::change_dir(String p_dir) { + PackedData::PackedDir *pd = _find_dir(p_dir); + if (pd) { + current = pd; + return OK; + } else { + return ERR_INVALID_PARAMETER; + } } String DirAccessPack::get_current_dir(bool p_include_drive) { @@ -507,13 +521,17 @@ String DirAccessPack::get_current_dir(bool p_include_drive) { bool DirAccessPack::file_exists(String p_file) { p_file = fix_path(p_file); - return current->files.has(p_file); + PackedData::PackedDir *pd = _find_dir(p_file.get_base_dir()); + if (!pd) { + return false; + } + return pd->files.has(p_file.get_file()); } bool DirAccessPack::dir_exists(String p_dir) { p_dir = fix_path(p_dir); - return current->subdirs.has(p_dir); + return _find_dir(p_dir) != nullptr; } Error DirAccessPack::make_dir(String p_dir) { diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index d934b0deb5..c13626a5aa 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 "core/list.h" -#include "core/map.h" #include "core/os/dir_access.h" #include "core/os/file_access.h" -#include "core/print_string.h" +#include "core/string/print_string.h" +#include "core/templates/list.h" +#include "core/templates/map.h" // Godot's packed file magic header ("GDPC" in ASCII). #define PACK_HEADER_MAGIC 0x43504447 @@ -122,6 +122,9 @@ public: _FORCE_INLINE_ FileAccess *try_open_path(const String &p_path); _FORCE_INLINE_ bool has_path(const String &p_path); + _FORCE_INLINE_ DirAccess *try_open_directory(const String &p_path); + _FORCE_INLINE_ bool has_directory(const String &p_path); + PackedData(); ~PackedData(); }; @@ -199,6 +202,16 @@ bool PackedData::has_path(const String &p_path) { return files.has(PathMD5(p_path.md5_buffer())); } +bool PackedData::has_directory(const String &p_path) { + DirAccess *da = try_open_directory(p_path); + if (da) { + memdelete(da); + return true; + } else { + return false; + } +} + class DirAccessPack : public DirAccess { PackedData::PackedDir *current; @@ -206,6 +219,8 @@ class DirAccessPack : public DirAccess { List<String> list_files; bool cdir = false; + PackedData::PackedDir *_find_dir(String p_dir); + public: virtual Error list_dir_begin(); virtual String get_next(); @@ -235,4 +250,13 @@ public: ~DirAccessPack() {} }; +DirAccess *PackedData::try_open_directory(const String &p_path) { + DirAccess *da = memnew(DirAccessPack()); + if (da->change_dir(p_path) != OK) { + memdelete(da); + da = nullptr; + } + return da; +} + #endif // FILE_ACCESS_PACK_H diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h index c251b3c424..eff07c60e2 100644 --- a/core/io/file_access_zip.h +++ b/core/io/file_access_zip.h @@ -34,7 +34,7 @@ #ifdef MINIZIP_ENABLED #include "core/io/file_access_pack.h" -#include "core/map.h" +#include "core/templates/map.h" #include "thirdparty/minizip/unzip.h" diff --git a/core/io/http_client.h b/core/io/http_client.h index a233d2d038..ece7e1924b 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -34,7 +34,7 @@ #include "core/io/ip.h" #include "core/io/stream_peer.h" #include "core/io/stream_peer_tcp.h" -#include "core/reference.h" +#include "core/object/reference.h" class HTTPClient : public Reference { GDCLASS(HTTPClient, Reference); diff --git a/core/image.cpp b/core/io/image.cpp index 950ff9b48d..005fd481e8 100644 --- a/core/image.cpp +++ b/core/io/image.cpp @@ -30,13 +30,13 @@ #include "image.h" -#include "core/error_macros.h" -#include "core/hash_map.h" +#include "core/error/error_macros.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 "core/print_string.h" +#include "core/string/print_string.h" +#include "core/templates/hash_map.h" #include <stdio.h> diff --git a/core/image.h b/core/io/image.h index d5d687b3ee..fecb90cab0 100644 --- a/core/image.h +++ b/core/io/image.h @@ -31,9 +31,9 @@ #ifndef IMAGE_H #define IMAGE_H -#include "core/color.h" +#include "core/io/resource.h" +#include "core/math/color.h" #include "core/math/rect2.h" -#include "core/resource.h" /** * @author Juan Linietsky <reduzio@gmail.com> diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index b1e92eb87f..f6d8668349 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -30,7 +30,7 @@ #include "image_loader.h" -#include "core/print_string.h" +#include "core/string/print_string.h" bool ImageFormatLoader::recognize(const String &p_extension) const { List<String> extensions; diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 9682f144c7..d5fb4678eb 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 "core/image.h" +#include "core/io/image.h" #include "core/io/resource_loader.h" -#include "core/list.h" #include "core/os/file_access.h" -#include "core/ustring.h" +#include "core/string/ustring.h" +#include "core/templates/list.h" class ImageLoader; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 24b8ec7cc1..9f3540efad 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -30,9 +30,9 @@ #include "ip.h" -#include "core/hash_map.h" #include "core/os/semaphore.h" #include "core/os/thread.h" +#include "core/templates/hash_map.h" VARIANT_ENUM_CAST(IP::ResolverStatus); diff --git a/core/io/ip_address.h b/core/io/ip_address.h index 2f8f83503e..7a813230f5 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 "core/ustring.h" +#include "core/string/ustring.h" struct IP_Address { private: diff --git a/core/io/json.cpp b/core/io/json.cpp index 1b89d966fd..d61c2b8236 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -30,7 +30,7 @@ #include "json.h" -#include "core/print_string.h" +#include "core/string/print_string.h" const char *JSON::tk_name[TK_MAX] = { "'{'", @@ -455,3 +455,35 @@ Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int & return err; } + +Error JSONParser::parse_string(const String &p_json_string) { + return JSON::parse(p_json_string, data, err_text, err_line); +} +String JSONParser::get_error_text() const { + return err_text; +} +int JSONParser::get_error_line() const { + return err_line; +} +Variant JSONParser::get_data() const { + return data; +} + +Error JSONParser::decode_data(const Variant &p_data, const String &p_indent, bool p_sort_keys) { + string = JSON::print(p_data, p_indent, p_sort_keys); + data = p_data; + return OK; +} + +String JSONParser::get_string() const { + return string; +} + +void JSONParser::_bind_methods() { + ClassDB::bind_method(D_METHOD("parse_string", "json_string"), &JSONParser::parse_string); + ClassDB::bind_method(D_METHOD("get_error_text"), &JSONParser::get_error_text); + ClassDB::bind_method(D_METHOD("get_error_line"), &JSONParser::get_error_line); + ClassDB::bind_method(D_METHOD("get_data"), &JSONParser::get_data); + ClassDB::bind_method(D_METHOD("decode_data", "data", "indent", "sort_keys"), &JSONParser::decode_data, DEFVAL(""), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("get_string"), &JSONParser::get_string); +} diff --git a/core/io/json.h b/core/io/json.h index 9122228163..2854d956ec 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -31,8 +31,8 @@ #ifndef JSON_H #define JSON_H -#include "core/variant.h" - +#include "core/object/reference.h" +#include "core/variant/variant.h" class JSON { enum TokenType { TK_CURLY_BRACKET_OPEN, @@ -75,4 +75,25 @@ public: static Error parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line); }; +class JSONParser : public Reference { + GDCLASS(JSONParser, Reference); + + Variant data; + String string; + String err_text; + int err_line = 0; + +protected: + static void _bind_methods(); + +public: + Error parse_string(const String &p_json_string); + String get_error_text() const; + int get_error_line() const; + Variant get_data() const; + + Error decode_data(const Variant &p_data, const String &p_indent = "", bool p_sort_keys = true); + String get_string() const; +}; + #endif // JSON_H diff --git a/core/io/logger.cpp b/core/io/logger.cpp index 886e5695b1..0e6a2e2c9f 100644 --- a/core/io/logger.cpp +++ b/core/io/logger.cpp @@ -32,7 +32,7 @@ #include "core/os/dir_access.h" #include "core/os/os.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #if defined(MINGW_ENABLED) || defined(_MSC_VER) #define sprintf sprintf_s diff --git a/core/io/logger.h b/core/io/logger.h index 277be9ed35..9eaf506c51 100644 --- a/core/io/logger.h +++ b/core/io/logger.h @@ -32,8 +32,8 @@ #define LOGGER_H #include "core/os/file_access.h" -#include "core/ustring.h" -#include "core/vector.h" +#include "core/string/ustring.h" +#include "core/templates/vector.h" #include <stdarg.h> diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index eb39b1433f..3cf4acaf39 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -30,9 +30,9 @@ #include "marshalls.h" +#include "core/object/reference.h" #include "core/os/keyboard.h" -#include "core/print_string.h" -#include "core/reference.h" +#include "core/string/print_string.h" #include <limits.h> #include <stdio.h> @@ -420,7 +420,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } } break; - case Variant::_RID: { + case Variant::RID: { r_variant = RID(); } break; case Variant::OBJECT: { @@ -1172,7 +1172,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 * 4; } break; - case Variant::_RID: { + case Variant::RID: { } break; case Variant::CALLABLE: { } break; diff --git a/core/io/marshalls.h b/core/io/marshalls.h index c8ed497528..6969a9b500 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -31,9 +31,9 @@ #ifndef MARSHALLS_H #define MARSHALLS_H -#include "core/reference.h" +#include "core/object/reference.h" #include "core/typedefs.h" -#include "core/variant.h" +#include "core/variant/variant.h" /** * Miscellaneous helpers for marshalling data types, and encoding diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index 06eab7796c..e0ce1c8ca4 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -32,7 +32,7 @@ #define MULTIPLAYER_API_H #include "core/io/networked_multiplayer_peer.h" -#include "core/reference.h" +#include "core/object/reference.h" class MultiplayerAPI : public Reference { GDCLASS(MultiplayerAPI, Reference); diff --git a/core/io/net_socket.h b/core/io/net_socket.h index 746945eced..67d0253985 100644 --- a/core/io/net_socket.h +++ b/core/io/net_socket.h @@ -32,7 +32,7 @@ #define NET_SOCKET_H #include "core/io/ip.h" -#include "core/reference.h" +#include "core/object/reference.h" class NetSocket : public Reference { protected: diff --git a/core/packed_data_container.cpp b/core/io/packed_data_container.cpp index f70482288d..fbe8fa8a28 100644 --- a/core/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -246,7 +246,7 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd } break; // misc types - case Variant::_RID: + case Variant::RID: case Variant::OBJECT: { return _pack(Variant(), tmpdata, string_cache); } break; diff --git a/core/packed_data_container.h b/core/io/packed_data_container.h index 28ec9cc87c..b784abcd16 100644 --- a/core/packed_data_container.h +++ b/core/io/packed_data_container.h @@ -31,7 +31,7 @@ #ifndef PACKED_DATA_CONTAINER_H #define PACKED_DATA_CONTAINER_H -#include "core/resource.h" +#include "core/io/resource.h" class PackedDataContainer : public Resource { GDCLASS(PackedDataContainer, Resource); diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index dacd548a3e..b6cc5bf42a 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -30,8 +30,8 @@ #include "packet_peer.h" +#include "core/config/project_settings.h" #include "core/io/marshalls.h" -#include "core/project_settings.h" /* helpers / binders */ diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index fb4dc181db..f7f080aa43 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -31,9 +31,9 @@ #ifndef PACKET_PEER_H #define PACKET_PEER_H -#include "core/class_db.h" #include "core/io/stream_peer.h" -#include "core/ring_buffer.h" +#include "core/object/class_db.h" +#include "core/templates/ring_buffer.h" class PacketPeer : public Reference { GDCLASS(PacketPeer, Reference); diff --git a/core/io/packet_peer_dtls.cpp b/core/io/packet_peer_dtls.cpp index 632f86a9f6..9f6fccc993 100644 --- a/core/io/packet_peer_dtls.cpp +++ b/core/io/packet_peer_dtls.cpp @@ -29,8 +29,8 @@ /*************************************************************************/ #include "packet_peer_dtls.h" +#include "core/config/project_settings.h" #include "core/os/file_access.h" -#include "core/project_settings.h" PacketPeerDTLS *(*PacketPeerDTLS::_create)() = nullptr; bool PacketPeerDTLS::available = false; diff --git a/core/io/pck_packer.h b/core/io/pck_packer.h index a6054dff2c..c1026c2499 100644 --- a/core/io/pck_packer.h +++ b/core/io/pck_packer.h @@ -31,7 +31,7 @@ #ifndef PCK_PACKER_H #define PCK_PACKER_H -#include "core/reference.h" +#include "core/object/reference.h" class FileAccess; diff --git a/core/resource.cpp b/core/io/resource.cpp index 3b589793ef..5b249f7af3 100644 --- a/core/resource.cpp +++ b/core/io/resource.cpp @@ -32,9 +32,9 @@ #include "core/core_string_names.h" #include "core/io/resource_loader.h" +#include "core/object/script_language.h" #include "core/os/file_access.h" #include "core/os/os.h" -#include "core/script_language.h" #include "scene/main/node.h" //only so casting works #include <stdio.h> diff --git a/core/resource.h b/core/io/resource.h index 41707f216d..6e0bd7d7f4 100644 --- a/core/resource.h +++ b/core/io/resource.h @@ -31,10 +31,10 @@ #ifndef RESOURCE_H #define RESOURCE_H -#include "core/class_db.h" -#include "core/reference.h" -#include "core/safe_refcount.h" -#include "core/self_list.h" +#include "core/object/class_db.h" +#include "core/object/reference.h" +#include "core/templates/safe_refcount.h" +#include "core/templates/self_list.h" #define RES_BASE_EXTENSION(m_ext) \ public: \ diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 21de7835ce..c67e68e4fc 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -30,11 +30,11 @@ #include "resource_format_binary.h" -#include "core/image.h" +#include "core/config/project_settings.h" #include "core/io/file_access_compressed.h" +#include "core/io/image.h" #include "core/io/marshalls.h" #include "core/os/dir_access.h" -#include "core/project_settings.h" #include "core/version.h" //#define print_bl(m_what) print_line(m_what) @@ -1467,7 +1467,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } } break; - case Variant::_RID: { + case Variant::RID: { f->store_32(VARIANT_RID); WARN_PRINT("Can't save RIDs."); RID val = p_property; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index 4d980bcf1a..c88331cf9e 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -30,9 +30,9 @@ #include "resource_importer.h" +#include "core/config/project_settings.h" #include "core/os/os.h" -#include "core/project_settings.h" -#include "core/variant_parser.h" +#include "core/variant/variant_parser.h" bool ResourceFormatImporter::SortImporterByName::operator()(const Ref<ResourceImporter> &p_a, const Ref<ResourceImporter> &p_b) const { return p_a->get_importer_name() < p_b->get_importer_name(); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index b5c598e860..a8ca6a817e 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -30,13 +30,13 @@ #include "resource_loader.h" +#include "core/config/project_settings.h" #include "core/io/resource_importer.h" #include "core/os/file_access.h" #include "core/os/os.h" -#include "core/print_string.h" -#include "core/project_settings.h" -#include "core/translation.h" -#include "core/variant_parser.h" +#include "core/string/print_string.h" +#include "core/string/translation.h" +#include "core/variant/variant_parser.h" #ifdef DEBUG_LOAD_THREADED #define print_lt(m_text) print_line(m_text) @@ -1057,7 +1057,7 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + "."); - ResourceFormatLoader *crl = Object::cast_to<ResourceFormatLoader>(obj); + Ref<ResourceFormatLoader> crl = Object::cast_to<ResourceFormatLoader>(obj); crl->set_script(s); ResourceLoader::add_resource_format_loader(crl); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 9322b5273a..02c668f214 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -31,9 +31,9 @@ #ifndef RESOURCE_LOADER_H #define RESOURCE_LOADER_H +#include "core/io/resource.h" #include "core/os/semaphore.h" #include "core/os/thread.h" -#include "core/resource.h" class ResourceFormatLoader : public Reference { GDCLASS(ResourceFormatLoader, Reference); diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index a8da215b61..6ded27d82f 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -29,10 +29,10 @@ /*************************************************************************/ #include "resource_saver.h" +#include "core/config/project_settings.h" #include "core/io/resource_loader.h" +#include "core/object/script_language.h" #include "core/os/file_access.h" -#include "core/project_settings.h" -#include "core/script_language.h" Ref<ResourceFormatSaver> ResourceSaver::saver[MAX_SAVERS]; @@ -214,7 +214,7 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) { ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + "."); - ResourceFormatSaver *crl = Object::cast_to<ResourceFormatSaver>(obj); + Ref<ResourceFormatSaver> crl = Object::cast_to<ResourceFormatSaver>(obj); crl->set_script(s); ResourceSaver::add_resource_format_saver(crl); diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 8b4cdd86f8..2e2950af53 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 "core/resource.h" +#include "core/io/resource.h" class ResourceFormatSaver : public Reference { GDCLASS(ResourceFormatSaver, Reference); diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h index 39097a57f2..8c1e918dd8 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 "core/reference.h" +#include "core/object/reference.h" class StreamPeer : public Reference { GDCLASS(StreamPeer, Reference); diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 3dc31c6769..daf36a5350 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -30,7 +30,7 @@ #include "stream_peer_ssl.h" -#include "core/engine.h" +#include "core/config/engine.h" StreamPeerSSL *(*StreamPeerSSL::_create)() = nullptr; diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index cce728c30a..aa9c409528 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -30,7 +30,7 @@ #include "stream_peer_tcp.h" -#include "core/project_settings.h" +#include "core/config/project_settings.h" Error StreamPeerTCP::_poll_connection() { ERR_FAIL_COND_V(status != STATUS_CONNECTING || !_sock.is_valid() || !_sock->is_open(), FAILED); diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index d8ddb213c3..34cccca540 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -31,8 +31,8 @@ #include "translation_loader_po.h" #include "core/os/file_access.h" -#include "core/translation.h" -#include "core/translation_po.h" +#include "core/string/translation.h" +#include "core/string/translation_po.h" RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { enum Status { diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h index a196a37dc0..16c9f1e680 100644 --- a/core/io/translation_loader_po.h +++ b/core/io/translation_loader_po.h @@ -33,7 +33,7 @@ #include "core/io/resource_loader.h" #include "core/os/file_access.h" -#include "core/translation.h" +#include "core/string/translation.h" class TranslationLoaderPO : public ResourceFormatLoader { public: diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index fc75ac7d1e..85143c0f04 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -30,7 +30,7 @@ #include "xml_parser.h" -#include "core/print_string.h" +#include "core/string/print_string.h" //#define DEBUG_XML diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h index ee2174d52c..d8cc26b4c1 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 "core/object/reference.h" #include "core/os/file_access.h" -#include "core/reference.h" -#include "core/ustring.h" -#include "core/vector.h" +#include "core/string/ustring.h" +#include "core/templates/vector.h" /* Based on irrXML (see their zlib license). Added mainly for compatibility with their Collada loader. diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 30f712b2c3..b4410acf7d 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -31,7 +31,7 @@ #include "a_star.h" #include "core/math/geometry_3d.h" -#include "core/script_language.h" +#include "core/object/script_language.h" #include "scene/scene_string_names.h" int AStar::get_available_point_id() const { diff --git a/core/math/a_star.h b/core/math/a_star.h index ba1c3033b8..a6fa771b30 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -31,8 +31,8 @@ #ifndef A_STAR_H #define A_STAR_H -#include "core/oa_hash_map.h" -#include "core/reference.h" +#include "core/object/reference.h" +#include "core/templates/oa_hash_map.h" /** A* pathfinding algorithm diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index e868ebc7c8..08673d0dd1 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -30,8 +30,8 @@ #include "aabb.h" -#include "core/print_string.h" -#include "core/variant.h" +#include "core/string/print_string.h" +#include "core/variant/variant.h" real_t AABB::get_area() const { return size.x * size.y * size.z; diff --git a/core/math/basis.cpp b/core/math/basis.cpp index a712ae7e3e..c6030d9757 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -32,7 +32,7 @@ #include "core/math/math_funcs.h" #include "core/os/copymem.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #define cofac(row1, col1, row2, col2) \ (elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1]) diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index c154d57a13..5e5efb6356 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -31,7 +31,7 @@ #include "camera_matrix.h" #include "core/math/math_funcs.h" -#include "core/print_string.h" +#include "core/string/print_string.h" float CameraMatrix::determinant() const { return matrix[0][3] * matrix[1][2] * matrix[2][1] * matrix[3][0] - matrix[0][2] * matrix[1][3] * matrix[2][1] * matrix[3][0] - diff --git a/core/color.cpp b/core/math/color.cpp index eacc6af017..2afe14bd63 100644 --- a/core/color.cpp +++ b/core/math/color.cpp @@ -30,10 +30,10 @@ #include "color.h" -#include "core/color_names.inc" -#include "core/map.h" +#include "color_names.inc" #include "core/math/math_funcs.h" -#include "core/print_string.h" +#include "core/string/print_string.h" +#include "core/templates/map.h" uint32_t Color::to_argb32() const { uint32_t c = (uint8_t)Math::round(a * 255); @@ -159,7 +159,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { a = p_alpha; if (p_s == 0) { - // acp_hromatic (grey) + // Achromatic (grey) r = g = b = p_v; return; } @@ -355,9 +355,6 @@ bool Color::html_is_valid(const String &p_color) { } Color Color::named(const String &p_name) { - if (_named_colors.empty()) { - _populate_named_colors(); // from color_names.inc - } String name = p_name; // Normalize name name = name.replace(" ", ""); @@ -367,9 +364,31 @@ Color Color::named(const String &p_name) { name = name.replace(".", ""); name = name.to_lower(); - const Map<String, Color>::Element *color = _named_colors.find(name); - ERR_FAIL_NULL_V_MSG(color, Color(), "Invalid color name: " + p_name + "."); - return color->value(); + int idx = 0; + while (named_colors[idx].name != nullptr) { + if (name == named_colors[idx].name) { + return named_colors[idx].color; + } + idx++; + } + + ERR_FAIL_V_MSG(Color(), "Invalid color name: " + p_name + "."); + + return Color(); +} + +int Color::get_named_color_count() { + int idx = 0; + while (named_colors[idx].name != nullptr) { + idx++; + } + return idx; +} +String Color::get_named_color_name(int p_idx) { + return named_colors[p_idx].name; +} +Color Color::get_named_color(int p_idx) { + return named_colors[p_idx].color; } String _to_hex(float p_val) { @@ -470,6 +489,13 @@ Color Color::operator+(const Color &p_color) const { a + p_color.a); } +void Color::operator+=(const Color &p_color) { + r = r + p_color.r; + g = g + p_color.g; + b = b + p_color.b; + a = a + p_color.a; +} + Color Color::operator-(const Color &p_color) const { return Color( r - p_color.r, @@ -493,12 +519,12 @@ Color Color::operator*(const Color &p_color) const { a * p_color.a); } -Color Color::operator*(real_t rvalue) const { +Color Color::operator*(real_t p_rvalue) const { return Color( - r * rvalue, - g * rvalue, - b * rvalue, - a * rvalue); + r * p_rvalue, + g * p_rvalue, + b * p_rvalue, + a * p_rvalue); } void Color::operator*=(const Color &p_color) { @@ -508,11 +534,11 @@ void Color::operator*=(const Color &p_color) { a = a * p_color.a; } -void Color::operator*=(real_t rvalue) { - r = r * rvalue; - g = g * rvalue; - b = b * rvalue; - a = a * rvalue; +void Color::operator*=(real_t p_rvalue) { + r = r * p_rvalue; + g = g * p_rvalue; + b = b * p_rvalue; + a = a * p_rvalue; } Color Color::operator/(const Color &p_color) const { @@ -523,12 +549,12 @@ Color Color::operator/(const Color &p_color) const { a / p_color.a); } -Color Color::operator/(real_t rvalue) const { +Color Color::operator/(real_t p_rvalue) const { return Color( - r / rvalue, - g / rvalue, - b / rvalue, - a / rvalue); + r / p_rvalue, + g / p_rvalue, + b / p_rvalue, + a / p_rvalue); } void Color::operator/=(const Color &p_color) { @@ -538,17 +564,17 @@ void Color::operator/=(const Color &p_color) { a = a / p_color.a; } -void Color::operator/=(real_t rvalue) { - if (rvalue == 0) { +void Color::operator/=(real_t p_rvalue) { + if (p_rvalue == 0) { r = 1.0; g = 1.0; b = 1.0; a = 1.0; } else { - r = r / rvalue; - g = g / rvalue; - b = b / rvalue; - a = a / rvalue; + r = r / p_rvalue; + g = g / p_rvalue; + b = b / p_rvalue; + a = a / p_rvalue; } } diff --git a/core/color.h b/core/math/color.h index eb9c5bfd15..a9be9e9035 100644 --- a/core/color.h +++ b/core/math/color.h @@ -32,7 +32,7 @@ #define COLOR_H #include "core/math/math_funcs.h" -#include "core/ustring.h" +#include "core/string/ustring.h" struct Color { union { @@ -45,9 +45,6 @@ struct Color { float components[4] = { 0, 0, 0, 1.0 }; }; - bool operator==(const Color &p_color) const { return (r == p_color.r && g == p_color.g && b == p_color.b && a == p_color.a); } - bool operator!=(const Color &p_color) const { return (r != p_color.r || g != p_color.g || b != p_color.b || a != p_color.a); } - uint32_t to_rgba32() const; uint32_t to_argb32() const; uint32_t to_abgr32() const; @@ -59,34 +56,36 @@ struct Color { float get_v() const; void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0); - _FORCE_INLINE_ float &operator[](int idx) { - return components[idx]; + _FORCE_INLINE_ float &operator[](int p_idx) { + return components[p_idx]; } - _FORCE_INLINE_ const float &operator[](int idx) const { - return components[idx]; + _FORCE_INLINE_ const float &operator[](int p_idx) const { + return components[p_idx]; } - Color operator+(const Color &p_color) const; - _FORCE_INLINE_ void operator+=(const Color &p_color) { - r = r + p_color.r; - g = g + p_color.g; - b = b + p_color.b; - a = a + p_color.a; + bool operator==(const Color &p_color) const { + return (r == p_color.r && g == p_color.g && b == p_color.b && a == p_color.a); + } + bool operator!=(const Color &p_color) const { + return (r != p_color.r || g != p_color.g || b != p_color.b || a != p_color.a); } + Color operator+(const Color &p_color) const; + void operator+=(const Color &p_color); + Color operator-() const; Color operator-(const Color &p_color) const; void operator-=(const Color &p_color); Color operator*(const Color &p_color) const; - Color operator*(real_t rvalue) const; + Color operator*(real_t p_rvalue) const; void operator*=(const Color &p_color); - void operator*=(real_t rvalue); + void operator*=(real_t p_rvalue); Color operator/(const Color &p_color) const; - Color operator/(real_t rvalue) const; + Color operator/(real_t p_rvalue) const; void operator/=(const Color &p_color); - void operator/=(real_t rvalue); + void operator/=(real_t p_rvalue); bool is_equal_approx(const Color &p_color) const; @@ -123,10 +122,9 @@ struct Color { _FORCE_INLINE_ uint32_t to_rgbe9995() const { const float pow2to9 = 512.0f; const float B = 15.0f; - //const float Emax = 31.0f; const float N = 9.0f; - float sharedexp = 65408.000f; //(( pow2to9 - 1.0f)/ pow2to9)*powf( 2.0f, 31.0f - 15.0f); + float sharedexp = 65408.000f; // Result of: ((pow2to9 - 1.0f) / pow2to9) * powf(2.0f, 31.0f - 15.0f) float cRed = MAX(0.0f, MIN(sharedexp, r)); float cGreen = MAX(0.0f, MIN(sharedexp, g)); @@ -134,8 +132,6 @@ struct Color { float cMax = MAX(cRed, MAX(cGreen, cBlue)); - // expp = MAX(-B - 1, log2(maxc)) + 1 + B - float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / Math_LN2)) + 1.0f + B; float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f); @@ -186,6 +182,9 @@ struct Color { static Color html(const String &p_rgba); static bool html_is_valid(const String &p_color); static Color named(const String &p_name); + static int get_named_color_count(); + static String get_named_color_name(int p_idx); + static Color get_named_color(int p_idx); String to_html(bool p_alpha = true) const; Color from_hsv(float p_h, float p_s, float p_v, float p_a) const; static Color from_rgbe9995(uint32_t p_rgbe); @@ -193,26 +192,27 @@ struct Color { _FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys operator String() const; - //for binder + // For the binder. _FORCE_INLINE_ void set_r8(int32_t r8) { r = (CLAMP(r8, 0, 255) / 255.0); } - _FORCE_INLINE_ int32_t get_r8() const { return CLAMP(uint32_t(r * 255.0), 0, 255); } + _FORCE_INLINE_ int32_t get_r8() const { return int32_t(CLAMP(r * 255.0, 0.0, 255.0)); } _FORCE_INLINE_ void set_g8(int32_t g8) { g = (CLAMP(g8, 0, 255) / 255.0); } - _FORCE_INLINE_ int32_t get_g8() const { return CLAMP(uint32_t(g * 255.0), 0, 255); } + _FORCE_INLINE_ int32_t get_g8() const { return int32_t(CLAMP(g * 255.0, 0.0, 255.0)); } _FORCE_INLINE_ void set_b8(int32_t b8) { b = (CLAMP(b8, 0, 255) / 255.0); } - _FORCE_INLINE_ int32_t get_b8() const { return CLAMP(uint32_t(b * 255.0), 0, 255); } + _FORCE_INLINE_ int32_t get_b8() const { return int32_t(CLAMP(b * 255.0, 0.0, 255.0)); } _FORCE_INLINE_ void set_a8(int32_t a8) { a = (CLAMP(a8, 0, 255) / 255.0); } - _FORCE_INLINE_ int32_t get_a8() const { return CLAMP(uint32_t(a * 255.0), 0, 255); } + _FORCE_INLINE_ int32_t get_a8() const { return int32_t(CLAMP(a * 255.0, 0.0, 255.0)); } - _FORCE_INLINE_ void set_h(float h) { set_hsv(h, get_s(), get_v()); } - _FORCE_INLINE_ void set_s(float s) { set_hsv(get_h(), s, get_v()); } - _FORCE_INLINE_ void set_v(float v) { set_hsv(get_h(), get_s(), v); } + _FORCE_INLINE_ void set_h(float p_h) { set_hsv(p_h, get_s(), get_v()); } + _FORCE_INLINE_ void set_s(float p_s) { set_hsv(get_h(), p_s, get_v()); } + _FORCE_INLINE_ void set_v(float p_v) { set_hsv(get_h(), get_s(), p_v); } _FORCE_INLINE_ Color() {} /** - * RGB / RGBA construct parameters. Alpha is optional, but defaults to 1.0 + * RGBA construct parameters. + * Alpha is not optional as otherwise we can't bind the RGB version for scripting. */ - _FORCE_INLINE_ Color(float p_r, float p_g, float p_b, float p_a = 1.0) { + _FORCE_INLINE_ Color(float p_r, float p_g, float p_b, float p_a) { r = p_r; g = p_g; b = p_b; @@ -220,6 +220,16 @@ struct Color { } /** + * RGB construct parameters. + */ + _FORCE_INLINE_ Color(float p_r, float p_g, float p_b) { + r = p_r; + g = p_g; + b = p_b; + a = 1.0; + } + + /** * Construct a Color from another Color, but with the specified alpha value. */ _FORCE_INLINE_ Color(const Color &p_c, float p_a) { diff --git a/core/math/color_names.inc b/core/math/color_names.inc new file mode 100644 index 0000000000..523c7e3c59 --- /dev/null +++ b/core/math/color_names.inc @@ -0,0 +1,160 @@ +// Names from https://en.wikipedia.org/wiki/X11_color_names + +// So this in a way that does not require memory allocation +// the old way leaked memory +// this is not used as often as for more performance to make sense + +struct NamedColor { + const char *name; + Color color; +}; + +static NamedColor named_colors[] = { + { "aliceblue", Color(0.94, 0.97, 1.00) }, + { "antiquewhite", Color(0.98, 0.92, 0.84) }, + { "aqua", Color(0.00, 1.00, 1.00) }, + { "aquamarine", Color(0.50, 1.00, 0.83) }, + { "azure", Color(0.94, 1.00, 1.00) }, + { "beige", Color(0.96, 0.96, 0.86) }, + { "bisque", Color(1.00, 0.89, 0.77) }, + { "black", Color(0.00, 0.00, 0.00) }, + { "blanchedalmond", Color(1.00, 0.92, 0.80) }, + { "blue", Color(0.00, 0.00, 1.00) }, + { "blueviolet", Color(0.54, 0.17, 0.89) }, + { "brown", Color(0.65, 0.16, 0.16) }, + { "burlywood", Color(0.87, 0.72, 0.53) }, + { "cadetblue", Color(0.37, 0.62, 0.63) }, + { "chartreuse", Color(0.50, 1.00, 0.00) }, + { "chocolate", Color(0.82, 0.41, 0.12) }, + { "coral", Color(1.00, 0.50, 0.31) }, + { "cornflower", Color(0.39, 0.58, 0.93) }, + { "cornsilk", Color(1.00, 0.97, 0.86) }, + { "crimson", Color(0.86, 0.08, 0.24) }, + { "cyan", Color(0.00, 1.00, 1.00) }, + { "darkblue", Color(0.00, 0.00, 0.55) }, + { "darkcyan", Color(0.00, 0.55, 0.55) }, + { "darkgoldenrod", Color(0.72, 0.53, 0.04) }, + { "darkgray", Color(0.66, 0.66, 0.66) }, + { "darkgreen", Color(0.00, 0.39, 0.00) }, + { "darkkhaki", Color(0.74, 0.72, 0.42) }, + { "darkmagenta", Color(0.55, 0.00, 0.55) }, + { "darkolivegreen", Color(0.33, 0.42, 0.18) }, + { "darkorange", Color(1.00, 0.55, 0.00) }, + { "darkorchid", Color(0.60, 0.20, 0.80) }, + { "darkred", Color(0.55, 0.00, 0.00) }, + { "darksalmon", Color(0.91, 0.59, 0.48) }, + { "darkseagreen", Color(0.56, 0.74, 0.56) }, + { "darkslateblue", Color(0.28, 0.24, 0.55) }, + { "darkslategray", Color(0.18, 0.31, 0.31) }, + { "darkturquoise", Color(0.00, 0.81, 0.82) }, + { "darkviolet", Color(0.58, 0.00, 0.83) }, + { "deeppink", Color(1.00, 0.08, 0.58) }, + { "deepskyblue", Color(0.00, 0.75, 1.00) }, + { "dimgray", Color(0.41, 0.41, 0.41) }, + { "dodgerblue", Color(0.12, 0.56, 1.00) }, + { "firebrick", Color(0.70, 0.13, 0.13) }, + { "floralwhite", Color(1.00, 0.98, 0.94) }, + { "forestgreen", Color(0.13, 0.55, 0.13) }, + { "fuchsia", Color(1.00, 0.00, 1.00) }, + { "gainsboro", Color(0.86, 0.86, 0.86) }, + { "ghostwhite", Color(0.97, 0.97, 1.00) }, + { "gold", Color(1.00, 0.84, 0.00) }, + { "goldenrod", Color(0.85, 0.65, 0.13) }, + { "gray", Color(0.75, 0.75, 0.75) }, + { "green", Color(0.00, 1.00, 0.00) }, + { "greenyellow", Color(0.68, 1.00, 0.18) }, + { "honeydew", Color(0.94, 1.00, 0.94) }, + { "hotpink", Color(1.00, 0.41, 0.71) }, + { "indianred", Color(0.80, 0.36, 0.36) }, + { "indigo", Color(0.29, 0.00, 0.51) }, + { "ivory", Color(1.00, 1.00, 0.94) }, + { "khaki", Color(0.94, 0.90, 0.55) }, + { "lavender", Color(0.90, 0.90, 0.98) }, + { "lavenderblush", Color(1.00, 0.94, 0.96) }, + { "lawngreen", Color(0.49, 0.99, 0.00) }, + { "lemonchiffon", Color(1.00, 0.98, 0.80) }, + { "lightblue", Color(0.68, 0.85, 0.90) }, + { "lightcoral", Color(0.94, 0.50, 0.50) }, + { "lightcyan", Color(0.88, 1.00, 1.00) }, + { "lightgoldenrod", Color(0.98, 0.98, 0.82) }, + { "lightgray", Color(0.83, 0.83, 0.83) }, + { "lightgreen", Color(0.56, 0.93, 0.56) }, + { "lightpink", Color(1.00, 0.71, 0.76) }, + { "lightsalmon", Color(1.00, 0.63, 0.48) }, + { "lightseagreen", Color(0.13, 0.70, 0.67) }, + { "lightskyblue", Color(0.53, 0.81, 0.98) }, + { "lightslategray", Color(0.47, 0.53, 0.60) }, + { "lightsteelblue", Color(0.69, 0.77, 0.87) }, + { "lightyellow", Color(1.00, 1.00, 0.88) }, + { "lime", Color(0.00, 1.00, 0.00) }, + { "limegreen", Color(0.20, 0.80, 0.20) }, + { "linen", Color(0.98, 0.94, 0.90) }, + { "magenta", Color(1.00, 0.00, 1.00) }, + { "maroon", Color(0.69, 0.19, 0.38) }, + { "mediumaquamarine", Color(0.40, 0.80, 0.67) }, + { "mediumblue", Color(0.00, 0.00, 0.80) }, + { "mediumorchid", Color(0.73, 0.33, 0.83) }, + { "mediumpurple", Color(0.58, 0.44, 0.86) }, + { "mediumseagreen", Color(0.24, 0.70, 0.44) }, + { "mediumslateblue", Color(0.48, 0.41, 0.93) }, + { "mediumspringgreen", Color(0.00, 0.98, 0.60) }, + { "mediumturquoise", Color(0.28, 0.82, 0.80) }, + { "mediumvioletred", Color(0.78, 0.08, 0.52) }, + { "midnightblue", Color(0.10, 0.10, 0.44) }, + { "mintcream", Color(0.96, 1.00, 0.98) }, + { "mistyrose", Color(1.00, 0.89, 0.88) }, + { "moccasin", Color(1.00, 0.89, 0.71) }, + { "navajowhite", Color(1.00, 0.87, 0.68) }, + { "navyblue", Color(0.00, 0.00, 0.50) }, + { "oldlace", Color(0.99, 0.96, 0.90) }, + { "olive", Color(0.50, 0.50, 0.00) }, + { "olivedrab", Color(0.42, 0.56, 0.14) }, + { "orange", Color(1.00, 0.65, 0.00) }, + { "orangered", Color(1.00, 0.27, 0.00) }, + { "orchid", Color(0.85, 0.44, 0.84) }, + { "palegoldenrod", Color(0.93, 0.91, 0.67) }, + { "palegreen", Color(0.60, 0.98, 0.60) }, + { "paleturquoise", Color(0.69, 0.93, 0.93) }, + { "palevioletred", Color(0.86, 0.44, 0.58) }, + { "papayawhip", Color(1.00, 0.94, 0.84) }, + { "peachpuff", Color(1.00, 0.85, 0.73) }, + { "peru", Color(0.80, 0.52, 0.25) }, + { "pink", Color(1.00, 0.75, 0.80) }, + { "plum", Color(0.87, 0.63, 0.87) }, + { "powderblue", Color(0.69, 0.88, 0.90) }, + { "purple", Color(0.63, 0.13, 0.94) }, + { "rebeccapurple", Color(0.40, 0.20, 0.60) }, + { "red", Color(1.00, 0.00, 0.00) }, + { "rosybrown", Color(0.74, 0.56, 0.56) }, + { "royalblue", Color(0.25, 0.41, 0.88) }, + { "saddlebrown", Color(0.55, 0.27, 0.07) }, + { "salmon", Color(0.98, 0.50, 0.45) }, + { "sandybrown", Color(0.96, 0.64, 0.38) }, + { "seagreen", Color(0.18, 0.55, 0.34) }, + { "seashell", Color(1.00, 0.96, 0.93) }, + { "sienna", Color(0.63, 0.32, 0.18) }, + { "silver", Color(0.75, 0.75, 0.75) }, + { "skyblue", Color(0.53, 0.81, 0.92) }, + { "slateblue", Color(0.42, 0.35, 0.80) }, + { "slategray", Color(0.44, 0.50, 0.56) }, + { "snow", Color(1.00, 0.98, 0.98) }, + { "springgreen", Color(0.00, 1.00, 0.50) }, + { "steelblue", Color(0.27, 0.51, 0.71) }, + { "tan", Color(0.82, 0.71, 0.55) }, + { "teal", Color(0.00, 0.50, 0.50) }, + { "thistle", Color(0.85, 0.75, 0.85) }, + { "tomato", Color(1.00, 0.39, 0.28) }, + { "transparent", Color(1.00, 1.00, 1.00, 0.00) }, + { "turquoise", Color(0.25, 0.88, 0.82) }, + { "violet", Color(0.93, 0.51, 0.93) }, + { "webgray", Color(0.50, 0.50, 0.50) }, + { "webgreen", Color(0.00, 0.50, 0.00) }, + { "webmaroon", Color(0.50, 0.00, 0.00) }, + { "webpurple", Color(0.50, 0.00, 0.50) }, + { "wheat", Color(0.96, 0.87, 0.70) }, + { "white", Color(1.00, 1.00, 1.00) }, + { "whitesmoke", Color(0.96, 0.96, 0.96) }, + { "yellow", Color(1.00, 1.00, 0.00) }, + { "yellowgreen", Color(0.60, 0.80, 0.20) }, + { nullptr, Color(0.60, 0.80, 0.20) }, +}; diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h index 014b4c4621..ea8655cfff 100644 --- a/core/math/delaunay_3d.h +++ b/core/math/delaunay_3d.h @@ -31,15 +31,15 @@ #ifndef DELAUNAY_3D_H #define DELAUNAY_3D_H -#include "core/local_vector.h" #include "core/math/aabb.h" #include "core/math/camera_matrix.h" #include "core/math/vector3.h" -#include "core/oa_hash_map.h" #include "core/os/file_access.h" -#include "core/print_string.h" -#include "core/variant.h" -#include "core/vector.h" +#include "core/string/print_string.h" +#include "core/templates/local_vector.h" +#include "core/templates/oa_hash_map.h" +#include "core/templates/vector.h" +#include "core/variant/variant.h" #include "thirdparty/misc/r128.h" diff --git a/core/math/disjoint_set.h b/core/math/disjoint_set.h index 198f46e111..51b9ce81af 100644 --- a/core/math/disjoint_set.h +++ b/core/math/disjoint_set.h @@ -31,8 +31,8 @@ #ifndef DISJOINT_SET_H #define DISJOINT_SET_H -#include "core/map.h" -#include "core/vector.h" +#include "core/templates/map.h" +#include "core/templates/vector.h" /** @author Marios Staikopoulos <marios@staik.net> diff --git a/core/math/expression.cpp b/core/math/expression.cpp index 0e72b153e4..d1f15caa5e 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -30,721 +30,12 @@ #include "expression.h" -#include "core/class_db.h" -#include "core/func_ref.h" #include "core/io/marshalls.h" #include "core/math/math_funcs.h" +#include "core/object/class_db.h" +#include "core/object/reference.h" #include "core/os/os.h" -#include "core/reference.h" -#include "core/variant_parser.h" - -const char *Expression::func_name[Expression::FUNC_MAX] = { - "sin", - "cos", - "tan", - "sinh", - "cosh", - "tanh", - "asin", - "acos", - "atan", - "atan2", - "sqrt", - "fmod", - "fposmod", - "posmod", - "floor", - "ceil", - "round", - "abs", - "sign", - "pow", - "log", - "exp", - "is_nan", - "is_inf", - "ease", - "step_decimals", - "stepify", - "lerp", - "lerp_angle", - "inverse_lerp", - "range_lerp", - "smoothstep", - "move_toward", - "dectime", - "randomize", - "randi", - "randf", - "randf_range", - "randi_range", - "seed", - "rand_seed", - "deg2rad", - "rad2deg", - "linear2db", - "db2linear", - "polar2cartesian", - "cartesian2polar", - "wrapi", - "wrapf", - "max", - "min", - "clamp", - "nearest_po2", - "weakref", - "funcref", - "convert", - "typeof", - "type_exists", - "char", - "ord", - "str", - "print", - "printerr", - "printraw", - "var2str", - "str2var", - "var2bytes", - "bytes2var", - "color_named", -}; - -Expression::BuiltinFunc Expression::find_function(const String &p_string) { - for (int i = 0; i < FUNC_MAX; i++) { - if (p_string == func_name[i]) { - return BuiltinFunc(i); - } - } - - return FUNC_MAX; -} - -String Expression::get_func_name(BuiltinFunc p_func) { - ERR_FAIL_INDEX_V(p_func, FUNC_MAX, String()); - return func_name[p_func]; -} - -int Expression::get_func_argument_count(BuiltinFunc p_func) { - switch (p_func) { - case MATH_RANDOMIZE: - case MATH_RANDI: - case MATH_RANDF: - return 0; - case MATH_SIN: - case MATH_COS: - case MATH_TAN: - case MATH_SINH: - case MATH_COSH: - case MATH_TANH: - case MATH_ASIN: - case MATH_ACOS: - case MATH_ATAN: - case MATH_SQRT: - case MATH_FLOOR: - case MATH_CEIL: - case MATH_ROUND: - case MATH_ABS: - case MATH_SIGN: - case MATH_LOG: - case MATH_EXP: - case MATH_ISNAN: - case MATH_ISINF: - case MATH_STEP_DECIMALS: - case MATH_SEED: - case MATH_RANDSEED: - case MATH_DEG2RAD: - case MATH_RAD2DEG: - case MATH_LINEAR2DB: - case MATH_DB2LINEAR: - case LOGIC_NEAREST_PO2: - case OBJ_WEAKREF: - case TYPE_OF: - case TEXT_CHAR: - case TEXT_ORD: - case TEXT_STR: - case TEXT_PRINT: - case TEXT_PRINTERR: - case TEXT_PRINTRAW: - case VAR_TO_STR: - case STR_TO_VAR: - case TYPE_EXISTS: - return 1; - case VAR_TO_BYTES: - case BYTES_TO_VAR: - case MATH_ATAN2: - case MATH_FMOD: - case MATH_FPOSMOD: - case MATH_POSMOD: - case MATH_POW: - case MATH_EASE: - case MATH_STEPIFY: - case MATH_RANDF_RANGE: - case MATH_RANDI_RANGE: - case MATH_POLAR2CARTESIAN: - case MATH_CARTESIAN2POLAR: - case LOGIC_MAX: - case LOGIC_MIN: - case FUNC_FUNCREF: - case TYPE_CONVERT: - case COLORN: - return 2; - case MATH_LERP: - case MATH_LERP_ANGLE: - case MATH_INVERSE_LERP: - case MATH_SMOOTHSTEP: - case MATH_MOVE_TOWARD: - case MATH_DECTIME: - case MATH_WRAP: - case MATH_WRAPF: - case LOGIC_CLAMP: - return 3; - case MATH_RANGE_LERP: - return 5; - case FUNC_MAX: { - } - } - return 0; -} - -#define VALIDATE_ARG_NUM(m_arg) \ - if (!p_inputs[m_arg]->is_num()) { \ - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; \ - r_error.argument = m_arg; \ - r_error.expected = Variant::FLOAT; \ - return; \ - } - -void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return, Callable::CallError &r_error, String &r_error_str) { - r_error.error = Callable::CallError::CALL_OK; - switch (p_func) { - case MATH_SIN: { - VALIDATE_ARG_NUM(0); - *r_return = Math::sin((double)*p_inputs[0]); - } break; - case MATH_COS: { - VALIDATE_ARG_NUM(0); - *r_return = Math::cos((double)*p_inputs[0]); - } break; - case MATH_TAN: { - VALIDATE_ARG_NUM(0); - *r_return = Math::tan((double)*p_inputs[0]); - } break; - case MATH_SINH: { - VALIDATE_ARG_NUM(0); - *r_return = Math::sinh((double)*p_inputs[0]); - } break; - case MATH_COSH: { - VALIDATE_ARG_NUM(0); - *r_return = Math::cosh((double)*p_inputs[0]); - } break; - case MATH_TANH: { - VALIDATE_ARG_NUM(0); - *r_return = Math::tanh((double)*p_inputs[0]); - } break; - case MATH_ASIN: { - VALIDATE_ARG_NUM(0); - *r_return = Math::asin((double)*p_inputs[0]); - } break; - case MATH_ACOS: { - VALIDATE_ARG_NUM(0); - *r_return = Math::acos((double)*p_inputs[0]); - } break; - case MATH_ATAN: { - VALIDATE_ARG_NUM(0); - *r_return = Math::atan((double)*p_inputs[0]); - } break; - case MATH_ATAN2: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - *r_return = Math::atan2((double)*p_inputs[0], (double)*p_inputs[1]); - } break; - case MATH_SQRT: { - VALIDATE_ARG_NUM(0); - *r_return = Math::sqrt((double)*p_inputs[0]); - } break; - case MATH_FMOD: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - *r_return = Math::fmod((double)*p_inputs[0], (double)*p_inputs[1]); - } break; - case MATH_FPOSMOD: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - *r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]); - } break; - case MATH_POSMOD: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - *r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]); - } break; - case MATH_FLOOR: { - VALIDATE_ARG_NUM(0); - *r_return = Math::floor((double)*p_inputs[0]); - } break; - case MATH_CEIL: { - VALIDATE_ARG_NUM(0); - *r_return = Math::ceil((double)*p_inputs[0]); - } break; - case MATH_ROUND: { - VALIDATE_ARG_NUM(0); - *r_return = Math::round((double)*p_inputs[0]); - } break; - case MATH_ABS: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; - *r_return = ABS(i); - } else if (p_inputs[0]->get_type() == Variant::FLOAT) { - real_t r = *p_inputs[0]; - *r_return = Math::abs(r); - } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::FLOAT; - } - } break; - case MATH_SIGN: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; - *r_return = i < 0 ? -1 : (i > 0 ? +1 : 0); - } else if (p_inputs[0]->get_type() == Variant::FLOAT) { - real_t r = *p_inputs[0]; - *r_return = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0); - } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::FLOAT; - } - } break; - case MATH_POW: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - *r_return = Math::pow((double)*p_inputs[0], (double)*p_inputs[1]); - } break; - case MATH_LOG: { - VALIDATE_ARG_NUM(0); - *r_return = Math::log((double)*p_inputs[0]); - } break; - case MATH_EXP: { - VALIDATE_ARG_NUM(0); - *r_return = Math::exp((double)*p_inputs[0]); - } break; - case MATH_ISNAN: { - VALIDATE_ARG_NUM(0); - *r_return = Math::is_nan((double)*p_inputs[0]); - } break; - case MATH_ISINF: { - VALIDATE_ARG_NUM(0); - *r_return = Math::is_inf((double)*p_inputs[0]); - } break; - case MATH_EASE: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - *r_return = Math::ease((double)*p_inputs[0], (double)*p_inputs[1]); - } break; - case MATH_STEP_DECIMALS: { - VALIDATE_ARG_NUM(0); - *r_return = Math::step_decimals((double)*p_inputs[0]); - } break; - case MATH_STEPIFY: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - *r_return = Math::stepify((double)*p_inputs[0], (double)*p_inputs[1]); - } break; - case MATH_LERP: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - *r_return = Math::lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); - } break; - case MATH_LERP_ANGLE: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - *r_return = Math::lerp_angle((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); - } break; - case MATH_INVERSE_LERP: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - *r_return = Math::inverse_lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); - } break; - case MATH_RANGE_LERP: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - VALIDATE_ARG_NUM(3); - VALIDATE_ARG_NUM(4); - *r_return = Math::range_lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2], (double)*p_inputs[3], (double)*p_inputs[4]); - } break; - case MATH_SMOOTHSTEP: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - *r_return = Math::smoothstep((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); - } break; - case MATH_MOVE_TOWARD: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - *r_return = Math::move_toward((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); - } break; - case MATH_DECTIME: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - *r_return = Math::dectime((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); - } break; - case MATH_RANDOMIZE: { - Math::randomize(); - - } break; - case MATH_RANDI: { - *r_return = Math::rand(); - } break; - case MATH_RANDF: { - *r_return = Math::randf(); - } break; - case MATH_RANDF_RANGE: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - *r_return = Math::random((double)*p_inputs[0], (double)*p_inputs[1]); - } break; - case MATH_RANDI_RANGE: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - *r_return = Math::random((int)*p_inputs[0], (int)*p_inputs[1]); - } break; - case MATH_SEED: { - VALIDATE_ARG_NUM(0); - uint64_t seed = *p_inputs[0]; - Math::seed(seed); - - } break; - case MATH_RANDSEED: { - VALIDATE_ARG_NUM(0); - uint64_t seed = *p_inputs[0]; - int ret = Math::rand_from_seed(&seed); - Array reta; - reta.push_back(ret); - reta.push_back(seed); - *r_return = reta; - - } break; - case MATH_DEG2RAD: { - VALIDATE_ARG_NUM(0); - *r_return = Math::deg2rad((double)*p_inputs[0]); - } break; - case MATH_RAD2DEG: { - VALIDATE_ARG_NUM(0); - *r_return = Math::rad2deg((double)*p_inputs[0]); - } break; - case MATH_LINEAR2DB: { - VALIDATE_ARG_NUM(0); - *r_return = Math::linear2db((double)*p_inputs[0]); - } break; - case MATH_DB2LINEAR: { - VALIDATE_ARG_NUM(0); - *r_return = Math::db2linear((double)*p_inputs[0]); - } break; - case MATH_POLAR2CARTESIAN: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - double r = *p_inputs[0]; - double th = *p_inputs[1]; - *r_return = Vector2(r * Math::cos(th), r * Math::sin(th)); - } break; - case MATH_CARTESIAN2POLAR: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - double x = *p_inputs[0]; - double y = *p_inputs[1]; - *r_return = Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x)); - } break; - case MATH_WRAP: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - *r_return = Math::wrapi((int64_t)*p_inputs[0], (int64_t)*p_inputs[1], (int64_t)*p_inputs[2]); - } break; - case MATH_WRAPF: { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - *r_return = Math::wrapf((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); - } break; - case LOGIC_MAX: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; - int64_t b = *p_inputs[1]; - *r_return = MAX(a, b); - } else { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - - real_t a = *p_inputs[0]; - real_t b = *p_inputs[1]; - - *r_return = MAX(a, b); - } - - } break; - case LOGIC_MIN: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; - int64_t b = *p_inputs[1]; - *r_return = MIN(a, b); - } else { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - - real_t a = *p_inputs[0]; - real_t b = *p_inputs[1]; - - *r_return = MIN(a, b); - } - } break; - case LOGIC_CLAMP: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT && p_inputs[2]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; - int64_t b = *p_inputs[1]; - int64_t c = *p_inputs[2]; - *r_return = CLAMP(a, b, c); - } else { - VALIDATE_ARG_NUM(0); - VALIDATE_ARG_NUM(1); - VALIDATE_ARG_NUM(2); - - real_t a = *p_inputs[0]; - real_t b = *p_inputs[1]; - real_t c = *p_inputs[2]; - - *r_return = CLAMP(a, b, c); - } - } break; - case LOGIC_NEAREST_PO2: { - VALIDATE_ARG_NUM(0); - int64_t num = *p_inputs[0]; - *r_return = next_power_of_2(num); - } break; - case OBJ_WEAKREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::OBJECT; - - return; - } - - if (p_inputs[0]->is_ref()) { - REF r = *p_inputs[0]; - if (!r.is_valid()) { - return; - } - - Ref<WeakRef> wref = memnew(WeakRef); - wref->set_ref(r); - *r_return = wref; - } else { - Object *obj = *p_inputs[0]; - if (!obj) { - return; - } - Ref<WeakRef> wref = memnew(WeakRef); - wref->set_obj(obj); - *r_return = wref; - } - - } break; - case FUNC_FUNCREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::OBJECT; - - return; - } - if (p_inputs[1]->get_type() != Variant::STRING && p_inputs[1]->get_type() != Variant::NODE_PATH) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 1; - r_error.expected = Variant::STRING; - - return; - } - - Ref<FuncRef> fr = memnew(FuncRef); - - fr->set_instance(*p_inputs[0]); - fr->set_function(*p_inputs[1]); - - *r_return = fr; - - } break; - case TYPE_CONVERT: { - VALIDATE_ARG_NUM(1); - int type = *p_inputs[1]; - if (type < 0 || type >= Variant::VARIANT_MAX) { - r_error_str = RTR("Invalid type argument to convert(), use TYPE_* constants."); - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::INT; - return; - - } else { - *r_return = Variant::construct(Variant::Type(type), p_inputs, 1, r_error); - } - } break; - case TYPE_OF: { - *r_return = p_inputs[0]->get_type(); - - } break; - case TYPE_EXISTS: { - *r_return = ClassDB::class_exists(*p_inputs[0]); - - } break; - case TEXT_CHAR: { - char32_t result[2] = { *p_inputs[0], 0 }; - - *r_return = String(result); - - } break; - case TEXT_ORD: { - if (p_inputs[0]->get_type() != Variant::STRING) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::STRING; - - return; - } - - String str = *p_inputs[0]; - - if (str.length() != 1) { - r_error_str = RTR("Expected a string of length 1 (a character)."); - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::STRING; - - return; - } - - *r_return = str.get(0); - - } break; - case TEXT_STR: { - String str = *p_inputs[0]; - - *r_return = str; - - } break; - case TEXT_PRINT: { - String str = *p_inputs[0]; - print_line(str); - - } break; - - case TEXT_PRINTERR: { - String str = *p_inputs[0]; - print_error(str); - - } break; - case TEXT_PRINTRAW: { - String str = *p_inputs[0]; - OS::get_singleton()->print("%s", str.utf8().get_data()); - - } break; - case VAR_TO_STR: { - String vars; - VariantWriter::write_to_string(*p_inputs[0], vars); - *r_return = vars; - } break; - case STR_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::STRING) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::STRING; - - return; - } - - VariantParser::StreamString ss; - ss.s = *p_inputs[0]; - - String errs; - int line; - Error err = VariantParser::parse(&ss, *r_return, errs, line); - - if (err != OK) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::STRING; - *r_return = "Parse error at line " + itos(line) + ": " + errs; - return; - } - - } break; - case VAR_TO_BYTES: { - PackedByteArray barr; - bool full_objects = *p_inputs[1]; - int len; - Error err = encode_variant(*p_inputs[0], nullptr, len, full_objects); - if (err) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::NIL; - r_error_str = "Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID)."; - return; - } - - barr.resize(len); - { - uint8_t *w = barr.ptrw(); - encode_variant(*p_inputs[0], w, len, full_objects); - } - *r_return = barr; - } break; - case BYTES_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::PACKED_BYTE_ARRAY) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::PACKED_BYTE_ARRAY; - - return; - } - - PackedByteArray varr = *p_inputs[0]; - bool allow_objects = *p_inputs[1]; - Variant ret; - { - const uint8_t *r = varr.ptr(); - Error err = decode_variant(ret, r, varr.size(), nullptr, allow_objects); - if (err != OK) { - r_error_str = RTR("Not enough bytes for decoding bytes, or invalid format."); - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = 0; - r_error.expected = Variant::PACKED_BYTE_ARRAY; - return; - } - } - - *r_return = ret; - - } break; - case COLORN: { - VALIDATE_ARG_NUM(1); - - Color color = Color::named(*p_inputs[0]); - color.a = *p_inputs[1]; - - *r_return = String(color); - - } break; - default: { - } - } -} - -//////// +#include "core/variant/variant_parser.h" static bool _is_number(char32_t c) { return (c >= '0' && c <= '9'); @@ -1119,18 +410,9 @@ Error Expression::_get_token(Token &r_token) { } else if (id == "self") { r_token.type = TK_SELF; } else { - for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (id == Variant::get_type_name(Variant::Type(i))) { - r_token.type = TK_BASIC_TYPE; - r_token.value = i; - return OK; - } - } - - BuiltinFunc bifunc = find_function(id); - if (bifunc != FUNC_MAX) { + if (Variant::has_utility_function(id)) { r_token.type = TK_BUILTIN_FUNC; - r_token.value = bifunc; + r_token.value = id; return OK; } @@ -1428,6 +710,8 @@ Expression::ENode *Expression::_parse_expression() { case TK_BUILTIN_FUNC: { //builtin function + StringName func = tk.value; + _get_token(tk); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '('"); @@ -1435,7 +719,7 @@ Expression::ENode *Expression::_parse_expression() { } BuiltinFuncNode *bifunc = alloc_node<BuiltinFuncNode>(); - bifunc->func = BuiltinFunc(int(tk.value)); + bifunc->func = func; while (true) { int cofs = str_ofs; @@ -1463,9 +747,11 @@ Expression::ENode *Expression::_parse_expression() { } } - int expected_args = get_func_argument_count(bifunc->func); - if (bifunc->arguments.size() != expected_args) { - _set_error("Builtin func '" + get_func_name(bifunc->func) + "' expects " + itos(expected_args) + " arguments."); + if (!Variant::is_utility_function_vararg(bifunc->func)) { + int expected_args = Variant::get_utility_function_argument_count(bifunc->func); + if (expected_args != bifunc->arguments.size()) { + _set_error("Builtin func '" + String(bifunc->func) + "' expects " + itos(expected_args) + " arguments."); + } } expr = bifunc; @@ -2048,7 +1334,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } Callable::CallError ce; - r_ret = Variant::construct(constructor->data_type, (const Variant **)argp.ptr(), argp.size(), ce); + Variant::construct(constructor->data_type, r_ret, (const Variant **)argp.ptr(), argp.size(), ce); if (ce.error != Callable::CallError::CALL_OK) { r_error_str = vformat(RTR("Invalid arguments to construct '%s'"), Variant::get_type_name(constructor->data_type)); @@ -2074,11 +1360,11 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: argp.write[i] = &arr[i]; } + r_ret = Variant(); //may not return anything Callable::CallError ce; - exec_func(bifunc->func, (const Variant **)argp.ptr(), &r_ret, ce, r_error_str); - + Variant::call_utility_function(bifunc->func, &r_ret, (const Variant **)argp.ptr(), argp.size(), ce); if (ce.error != Callable::CallError::CALL_OK) { - r_error_str = "Builtin Call Failed. " + r_error_str; + r_error_str = "Builtin Call Failed. " + Variant::get_call_error_text(bifunc->func, (const Variant **)argp.ptr(), argp.size(), ce); return true; } @@ -2110,7 +1396,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } Callable::CallError ce; - r_ret = base.call(call->method, (const Variant **)argp.ptr(), argp.size(), ce); + base.call(call->method, (const Variant **)argp.ptr(), argp.size(), r_ret, ce); if (ce.error != Callable::CallError::CALL_OK) { r_error_str = vformat(RTR("On call to '%s':"), String(call->method)); diff --git a/core/math/expression.h b/core/math/expression.h index 80aeb98589..d9cedb8c2c 100644 --- a/core/math/expression.h +++ b/core/math/expression.h @@ -31,93 +31,12 @@ #ifndef EXPRESSION_H #define EXPRESSION_H -#include "core/reference.h" +#include "core/object/reference.h" class Expression : public Reference { GDCLASS(Expression, Reference); -public: - enum BuiltinFunc { - MATH_SIN, - MATH_COS, - MATH_TAN, - MATH_SINH, - MATH_COSH, - MATH_TANH, - MATH_ASIN, - MATH_ACOS, - MATH_ATAN, - MATH_ATAN2, - MATH_SQRT, - MATH_FMOD, - MATH_FPOSMOD, - MATH_POSMOD, - MATH_FLOOR, - MATH_CEIL, - MATH_ROUND, - MATH_ABS, - MATH_SIGN, - MATH_POW, - MATH_LOG, - MATH_EXP, - MATH_ISNAN, - MATH_ISINF, - MATH_EASE, - MATH_STEP_DECIMALS, - MATH_STEPIFY, - MATH_LERP, - MATH_LERP_ANGLE, - MATH_INVERSE_LERP, - MATH_RANGE_LERP, - MATH_SMOOTHSTEP, - MATH_MOVE_TOWARD, - MATH_DECTIME, - MATH_RANDOMIZE, - MATH_RANDI, - MATH_RANDF, - MATH_RANDF_RANGE, - MATH_RANDI_RANGE, - MATH_SEED, - MATH_RANDSEED, - MATH_DEG2RAD, - MATH_RAD2DEG, - MATH_LINEAR2DB, - MATH_DB2LINEAR, - MATH_POLAR2CARTESIAN, - MATH_CARTESIAN2POLAR, - MATH_WRAP, - MATH_WRAPF, - LOGIC_MAX, - LOGIC_MIN, - LOGIC_CLAMP, - LOGIC_NEAREST_PO2, - OBJ_WEAKREF, - FUNC_FUNCREF, - TYPE_CONVERT, - TYPE_OF, - TYPE_EXISTS, - TEXT_CHAR, - TEXT_ORD, - TEXT_STR, - TEXT_PRINT, - TEXT_PRINTERR, - TEXT_PRINTRAW, - VAR_TO_STR, - STR_TO_VAR, - VAR_TO_BYTES, - BYTES_TO_VAR, - COLORN, - FUNC_MAX - }; - - static int get_func_argument_count(BuiltinFunc p_func); - static String get_func_name(BuiltinFunc p_func); - static void exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return, Callable::CallError &r_error, String &r_error_str); - static BuiltinFunc find_function(const String &p_string); - private: - static const char *func_name[FUNC_MAX]; - struct Input { Variant::Type type = Variant::NIL; String name; @@ -316,7 +235,7 @@ private: }; struct BuiltinFuncNode : public ENode { - BuiltinFunc func; + StringName func; Vector<ENode *> arguments; BuiltinFuncNode() { type = TYPE_BUILTIN_FUNC; diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index cfd7abfacb..12bad5768e 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -34,8 +34,8 @@ #include "core/math/delaunay_2d.h" #include "core/math/rect2.h" #include "core/math/triangulate.h" -#include "core/object.h" -#include "core/vector.h" +#include "core/object/object.h" +#include "core/templates/vector.h" class Geometry2D { Geometry2D(); diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index 2c19fe2085..56353de783 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -30,7 +30,7 @@ #include "geometry_3d.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #include "thirdparty/misc/clipper.hpp" #include "thirdparty/misc/triangulator.h" diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h index 11cac8f108..f10fbeaaaf 100644 --- a/core/math/geometry_3d.h +++ b/core/math/geometry_3d.h @@ -32,8 +32,8 @@ #define GEOMETRY_3D_H #include "core/math/face3.h" -#include "core/object.h" -#include "core/vector.h" +#include "core/object/object.h" +#include "core/templates/vector.h" class Geometry3D { Geometry3D(); diff --git a/core/math/math_fieldwise.h b/core/math/math_fieldwise.h index c1ee9ec8f0..e8aac0dced 100644 --- a/core/math/math_fieldwise.h +++ b/core/math/math_fieldwise.h @@ -33,7 +33,7 @@ #ifdef TOOLS_ENABLED -#include "core/variant.h" +#include "core/variant/variant.h" Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const String &p_field); diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 80413e5c22..e57257b442 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -30,7 +30,7 @@ #include "math_funcs.h" -#include "core/error_macros.h" +#include "core/error/error_macros.h" RandomPCG Math::default_rand(RandomPCG::DEFAULT_SEED, RandomPCG::DEFAULT_INC); diff --git a/core/math/octree.h b/core/math/octree.h index 5d9688d442..40201f99b1 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -31,13 +31,13 @@ #ifndef OCTREE_H #define OCTREE_H -#include "core/list.h" -#include "core/map.h" #include "core/math/aabb.h" #include "core/math/geometry_3d.h" #include "core/math/vector3.h" -#include "core/print_string.h" -#include "core/variant.h" +#include "core/string/print_string.h" +#include "core/templates/list.h" +#include "core/templates/map.h" +#include "core/variant/variant.h" typedef uint32_t OctreeElementID; diff --git a/core/math/plane.cpp b/core/math/plane.cpp index ae2021d2f6..e1ae3288ed 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -31,7 +31,7 @@ #include "plane.h" #include "core/math/math_funcs.h" -#include "core/variant.h" +#include "core/variant/variant.h" void Plane::set_normal(const Vector3 &p_normal) { normal = p_normal; diff --git a/core/math/quat.cpp b/core/math/quat.cpp index c10f5da494..b6a017dd41 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -31,7 +31,7 @@ #include "quat.h" #include "core/math/basis.h" -#include "core/print_string.h" +#include "core/string/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, diff --git a/core/math/quat.h b/core/math/quat.h index 1ab64a2655..f8ab537d7b 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -36,7 +36,7 @@ #include "core/math/math_defs.h" #include "core/math/math_funcs.h" -#include "core/ustring.h" +#include "core/string/ustring.h" class Quat { public: diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index 8ba1ba9286..8dff13c050 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -30,7 +30,7 @@ #include "quick_hull.h" -#include "core/map.h" +#include "core/templates/map.h" uint32_t QuickHull::debug_stop_after = 0xFFFFFFFF; diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h index cac8e58d23..80f32e191b 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 "core/list.h" #include "core/math/aabb.h" #include "core/math/geometry_3d.h" -#include "core/set.h" +#include "core/templates/list.h" +#include "core/templates/set.h" class QuickHull { public: diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h index 08e41d6c1c..0d0ea17205 100644 --- a/core/math/random_number_generator.h +++ b/core/math/random_number_generator.h @@ -32,7 +32,7 @@ #define RANDOM_NUMBER_GENERATOR_H #include "core/math/random_pcg.h" -#include "core/reference.h" +#include "core/object/reference.h" class RandomNumberGenerator : public Reference { GDCLASS(RandomNumberGenerator, Reference); diff --git a/core/math/transform.cpp b/core/math/transform.cpp index 0274dd18af..733bb4d55e 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -32,7 +32,7 @@ #include "core/math/math_funcs.h" #include "core/os/copymem.h" -#include "core/print_string.h" +#include "core/string/print_string.h" void Transform::affine_invert() { basis.invert(); @@ -200,6 +200,13 @@ Transform::Transform(const Basis &p_basis, const Vector3 &p_origin) : origin(p_origin) { } +Transform::Transform(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z, const Vector3 &p_origin) : + origin(p_origin) { + basis.set_axis(0, p_x); + basis.set_axis(1, p_y); + basis.set_axis(2, p_z); +} + Transform::Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t ox, real_t oy, real_t oz) { basis = Basis(xx, xy, xz, yx, yy, yz, zx, zy, zz); origin = Vector3(ox, oy, oz); diff --git a/core/math/transform.h b/core/math/transform.h index 71847d36ac..c63dbcb989 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -106,9 +106,10 @@ public: operator String() const; - Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t ox, real_t oy, real_t oz); - Transform(const Basis &p_basis, const Vector3 &p_origin = Vector3()); Transform() {} + Transform(const Basis &p_basis, const Vector3 &p_origin = Vector3()); + Transform(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z, const Vector3 &p_origin); + Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t ox, real_t oy, real_t oz); }; _FORCE_INLINE_ Vector3 Transform::xform(const Vector3 &p_vector) const { diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 180aeaa0af..00e561f973 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -251,7 +251,7 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t real_t dot = v1.dot(v2); - dot = (dot < -1.0) ? -1.0 : ((dot > 1.0) ? 1.0 : dot); //clamp dot to [-1,1] + dot = CLAMP(dot, -1.0, 1.0); Vector2 v; diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h index 46e97abaa7..342623939e 100644 --- a/core/math/transform_2d.h +++ b/core/math/transform_2d.h @@ -128,6 +128,12 @@ struct Transform2D { elements[2][1] = oy; } + Transform2D(const Vector2 &p_x, const Vector2 &p_y, const Vector2 &p_origin) { + elements[0] = p_x; + elements[1] = p_y; + elements[2] = p_origin; + } + Transform2D(real_t p_rot, const Vector2 &p_pos); Transform2D() { elements[0][0] = 1.0; diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index c9a546e385..cfe8422d80 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -30,7 +30,7 @@ #include "triangle_mesh.h" -#include "core/sort_array.h" +#include "core/templates/sort_array.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) { if (p_depth > max_depth) { diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h index 86412cf725..d719822ec3 100644 --- a/core/math/triangle_mesh.h +++ b/core/math/triangle_mesh.h @@ -32,7 +32,7 @@ #define TRIANGLE_MESH_H #include "core/math/face3.h" -#include "core/reference.h" +#include "core/object/reference.h" class TriangleMesh : public Reference { GDCLASS(TriangleMesh, Reference); diff --git a/core/math/vector2.h b/core/math/vector2.h index 31bb7208d3..8cb63b2fb5 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -32,7 +32,7 @@ #define VECTOR2_H #include "core/math/math_funcs.h" -#include "core/ustring.h" +#include "core/string/ustring.h" struct Vector2i; diff --git a/core/math/vector3.h b/core/math/vector3.h index 5370b297f1..ae8b9376cf 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -33,7 +33,7 @@ #include "core/math/math_funcs.h" #include "core/math/vector3i.h" -#include "core/ustring.h" +#include "core/string/ustring.h" class Basis; diff --git a/core/math/vector3i.h b/core/math/vector3i.h index 89774e9395..1bfd6d5ab2 100644 --- a/core/math/vector3i.h +++ b/core/math/vector3i.h @@ -31,8 +31,8 @@ #ifndef VECTOR3I_H #define VECTOR3I_H +#include "core/string/ustring.h" #include "core/typedefs.h" -#include "core/ustring.h" struct Vector3i { enum Axis { diff --git a/core/object/SCsub b/core/object/SCsub new file mode 100644 index 0000000000..5d429960e5 --- /dev/null +++ b/core/object/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import("env") + +env_object = env.Clone() + +env_object.add_source_files(env.core_sources, "*.cpp") diff --git a/core/callable_method_pointer.cpp b/core/object/callable_method_pointer.cpp index 21a917cbd7..21a917cbd7 100644 --- a/core/callable_method_pointer.cpp +++ b/core/object/callable_method_pointer.cpp diff --git a/core/callable_method_pointer.h b/core/object/callable_method_pointer.h index 2007b9f338..ee6da6a8db 100644 --- a/core/callable_method_pointer.h +++ b/core/object/callable_method_pointer.h @@ -31,12 +31,12 @@ #ifndef CALLABLE_METHOD_POINTER_H #define CALLABLE_METHOD_POINTER_H -#include "core/binder_common.h" -#include "core/callable.h" -#include "core/hashfuncs.h" -#include "core/object.h" +#include "core/object/object.h" #include "core/os/copymem.h" -#include "core/simple_type.h" +#include "core/templates/hashfuncs.h" +#include "core/templates/simple_type.h" +#include "core/variant/binder_common.h" +#include "core/variant/callable.h" class CallableCustomMethodPointerBase : public CallableCustom { uint32_t *comp_ptr; diff --git a/core/class_db.cpp b/core/object/class_db.cpp index 81bc901561..64ebeb427e 100644 --- a/core/class_db.cpp +++ b/core/object/class_db.cpp @@ -30,7 +30,7 @@ #include "class_db.h" -#include "core/engine.h" +#include "core/config/engine.h" #include "core/os/mutex.h" #include "core/version.h" diff --git a/core/class_db.h b/core/object/class_db.h index 22072066d9..94f26da60d 100644 --- a/core/class_db.h +++ b/core/object/class_db.h @@ -31,9 +31,9 @@ #ifndef CLASS_DB_H #define CLASS_DB_H -#include "core/method_bind.h" -#include "core/object.h" -#include "core/print_string.h" +#include "core/object/method_bind.h" +#include "core/object/object.h" +#include "core/string/print_string.h" /** To bind more then 6 parameters include this: * @@ -41,7 +41,7 @@ // Makes callable_mp readily available in all classes connecting signals. // Needs to come after method_bind and object have been included. -#include "core/callable_method_pointer.h" +#include "core/object/callable_method_pointer.h" #define DEFVAL(m_defval) (m_defval) diff --git a/core/message_queue.cpp b/core/object/message_queue.cpp index 6dcf24e7ed..f0d6786853 100644 --- a/core/message_queue.cpp +++ b/core/object/message_queue.cpp @@ -30,9 +30,9 @@ #include "message_queue.h" +#include "core/config/project_settings.h" #include "core/core_string_names.h" -#include "core/project_settings.h" -#include "core/script_language.h" +#include "core/object/script_language.h" MessageQueue *MessageQueue::singleton = nullptr; diff --git a/core/message_queue.h b/core/object/message_queue.h index 5d39ceee03..2901ab196a 100644 --- a/core/message_queue.h +++ b/core/object/message_queue.h @@ -31,7 +31,7 @@ #ifndef MESSAGE_QUEUE_H #define MESSAGE_QUEUE_H -#include "core/class_db.h" +#include "core/object/class_db.h" #include "core/os/thread_safe.h" class MessageQueue { diff --git a/core/method_bind.cpp b/core/object/method_bind.cpp index 3244c63292..e6652ac09f 100644 --- a/core/method_bind.cpp +++ b/core/object/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 "core/object.h" +#include "core/object/object.h" #include "method_bind.h" diff --git a/core/method_bind.h b/core/object/method_bind.h index d43186257b..ab4ba90b94 100644 --- a/core/method_bind.h +++ b/core/object/method_bind.h @@ -31,7 +31,7 @@ #ifndef METHOD_BIND_H #define METHOD_BIND_H -#include "core/binder_common.h" +#include "core/variant/binder_common.h" enum MethodFlags { diff --git a/core/object.cpp b/core/object/object.cpp index 3a52df9c60..c3f49856ca 100644 --- a/core/object.cpp +++ b/core/object/object.cpp @@ -30,14 +30,14 @@ #include "object.h" -#include "core/class_db.h" #include "core/core_string_names.h" -#include "core/message_queue.h" +#include "core/io/resource.h" +#include "core/object/class_db.h" +#include "core/object/message_queue.h" +#include "core/object/script_language.h" #include "core/os/os.h" -#include "core/print_string.h" -#include "core/resource.h" -#include "core/script_language.h" -#include "core/translation.h" +#include "core/string/print_string.h" +#include "core/string/translation.h" #ifdef DEBUG_ENABLED @@ -1690,7 +1690,8 @@ Variant::Type Object::get_static_property_type_indexed(const Vector<StringName> } Callable::CallError ce; - Variant check = Variant::construct(t, nullptr, 0, ce); + Variant check; + Variant::construct(t, check, nullptr, 0, ce); for (int i = 1; i < p_path.size(); i++) { if (check.get_type() == Variant::OBJECT || check.get_type() == Variant::DICTIONARY || check.get_type() == Variant::ARRAY) { diff --git a/core/object.h b/core/object/object.h index 765fb63c6e..c79745cf74 100644 --- a/core/object.h +++ b/core/object/object.h @@ -31,16 +31,16 @@ #ifndef OBJECT_H #define OBJECT_H -#include "core/callable_bind.h" -#include "core/hash_map.h" -#include "core/list.h" -#include "core/map.h" -#include "core/object_id.h" +#include "core/object/object_id.h" #include "core/os/rw_lock.h" -#include "core/set.h" -#include "core/spin_lock.h" -#include "core/variant.h" -#include "core/vmap.h" +#include "core/os/spin_lock.h" +#include "core/templates/hash_map.h" +#include "core/templates/list.h" +#include "core/templates/map.h" +#include "core/templates/set.h" +#include "core/templates/vmap.h" +#include "core/variant/callable_bind.h" +#include "core/variant/variant.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 diff --git a/core/object_id.h b/core/object/object_id.h index 63b0c27af8..63b0c27af8 100644 --- a/core/object_id.h +++ b/core/object/object_id.h diff --git a/core/reference.cpp b/core/object/reference.cpp index d1dba0d9bf..ce95d83dfc 100644 --- a/core/reference.cpp +++ b/core/object/reference.cpp @@ -30,7 +30,7 @@ #include "reference.h" -#include "core/script_language.h" +#include "core/object/script_language.h" bool Reference::init_ref() { if (reference()) { diff --git a/core/reference.h b/core/object/reference.h index 868894aad4..575f1cd914 100644 --- a/core/reference.h +++ b/core/object/reference.h @@ -31,8 +31,8 @@ #ifndef REFERENCE_H #define REFERENCE_H -#include "core/class_db.h" -#include "core/safe_refcount.h" +#include "core/object/class_db.h" +#include "core/templates/safe_refcount.h" class Reference : public Object { GDCLASS(Reference, Object); diff --git a/core/script_language.cpp b/core/object/script_language.cpp index d535c54dea..17ac75e19f 100644 --- a/core/script_language.cpp +++ b/core/object/script_language.cpp @@ -30,10 +30,10 @@ #include "script_language.h" +#include "core/config/project_settings.h" #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" -#include "core/project_settings.h" #include <stdint.h> diff --git a/core/script_language.h b/core/object/script_language.h index a94c128932..447216f14f 100644 --- a/core/script_language.h +++ b/core/object/script_language.h @@ -32,9 +32,9 @@ #define SCRIPT_LANGUAGE_H #include "core/io/multiplayer_api.h" -#include "core/map.h" -#include "core/pair.h" -#include "core/resource.h" +#include "core/io/resource.h" +#include "core/templates/map.h" +#include "core/templates/pair.h" class ScriptLanguage; diff --git a/core/undo_redo.cpp b/core/object/undo_redo.cpp index 1dcbb0cd6b..1dcbb0cd6b 100644 --- a/core/undo_redo.cpp +++ b/core/object/undo_redo.cpp diff --git a/core/undo_redo.h b/core/object/undo_redo.h index 68a553efd4..68d78e0d7d 100644 --- a/core/undo_redo.h +++ b/core/object/undo_redo.h @@ -31,8 +31,8 @@ #ifndef UNDO_REDO_H #define UNDO_REDO_H -#include "core/class_db.h" -#include "core/resource.h" +#include "core/io/resource.h" +#include "core/object/class_db.h" class UndoRedo : public Object { GDCLASS(UndoRedo, Object); diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 5e1cb8ea29..30b1b51b53 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -30,10 +30,10 @@ #include "dir_access.h" +#include "core/config/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 { switch (_access_type) { diff --git a/core/os/dir_access.h b/core/os/dir_access.h index 6bce9a4c12..0f4fa9b250 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -31,8 +31,8 @@ #ifndef DIR_ACCESS_H #define DIR_ACCESS_H +#include "core/string/ustring.h" #include "core/typedefs.h" -#include "core/ustring.h" //@ TODO, excellent candidate for THREAD_SAFE MACRO, should go through all these and add THREAD_SAFE where it applies class DirAccess { diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 9dbb2952f7..fd3c6f8806 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -30,11 +30,11 @@ #include "file_access.h" +#include "core/config/project_settings.h" #include "core/crypto/crypto_core.h" #include "core/io/file_access_pack.h" #include "core/io/marshalls.h" #include "core/os/os.h" -#include "core/project_settings.h" FileAccess::CreateFunc FileAccess::create_func[ACCESS_MAX] = { nullptr, nullptr }; @@ -51,7 +51,7 @@ FileAccess *FileAccess::create(AccessType p_access) { } bool FileAccess::exists(const String &p_name) { - if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name)) { + if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_name)) { return true; } @@ -456,7 +456,7 @@ void FileAccess::store_double(double p_dest) { } uint64_t FileAccess::get_modified_time(const String &p_file) { - if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) { + if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && (PackedData::get_singleton()->has_path(p_file) || PackedData::get_singleton()->has_directory(p_file))) { return 0; } @@ -469,7 +469,7 @@ uint64_t FileAccess::get_modified_time(const String &p_file) { } uint32_t FileAccess::get_unix_permissions(const String &p_file) { - if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) { + if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && (PackedData::get_singleton()->has_path(p_file) || PackedData::get_singleton()->has_directory(p_file))) { return 0; } @@ -482,6 +482,10 @@ uint32_t FileAccess::get_unix_permissions(const String &p_file) { } Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissions) { + if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && (PackedData::get_singleton()->has_path(p_file) || PackedData::get_singleton()->has_directory(p_file))) { + return ERR_UNAVAILABLE; + } + FileAccess *fa = create_for_path(p_file); ERR_FAIL_COND_V_MSG(!fa, ERR_CANT_CREATE, "Cannot create FileAccess for path '" + p_file + "'."); diff --git a/core/os/file_access.h b/core/os/file_access.h index 48b9ee4269..39b977a4d9 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -33,8 +33,8 @@ #include "core/math/math_defs.h" #include "core/os/memory.h" +#include "core/string/ustring.h" #include "core/typedefs.h" -#include "core/ustring.h" /** * Multi-Platform abstraction for accessing to files. diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 5d11e6a378..92664aff8f 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -31,7 +31,7 @@ #ifndef KEYBOARD_H #define KEYBOARD_H -#include "core/ustring.h" +#include "core/string/ustring.h" /* Special Key: diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 6651fb80d7..d29bcd011f 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -30,7 +30,7 @@ #include "main_loop.h" -#include "core/script_language.h" +#include "core/object/script_language.h" void MainLoop::_bind_methods() { BIND_VMETHOD(MethodInfo("_initialize")); diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 2c34cf193c..8c46ad9b6a 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -32,8 +32,8 @@ #define MAIN_LOOP_H #include "core/input/input_event.h" -#include "core/reference.h" -#include "core/script_language.h" +#include "core/object/reference.h" +#include "core/object/script_language.h" class MainLoop : public Object { GDCLASS(MainLoop, Object); diff --git a/core/os/memory.cpp b/core/os/memory.cpp index 8457c52092..f2723d13f6 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -30,9 +30,9 @@ #include "memory.h" -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include "core/os/copymem.h" -#include "core/safe_refcount.h" +#include "core/templates/safe_refcount.h" #include <stdio.h> #include <stdlib.h> diff --git a/core/os/memory.h b/core/os/memory.h index 46ffb4124b..dee08d4de4 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -31,8 +31,8 @@ #ifndef MEMORY_H #define MEMORY_H -#include "core/error_macros.h" -#include "core/safe_refcount.h" +#include "core/error/error_macros.h" +#include "core/templates/safe_refcount.h" #include <stddef.h> diff --git a/core/os/midi_driver.h b/core/os/midi_driver.h index bc922e1fcf..f487b31d4c 100644 --- a/core/os/midi_driver.h +++ b/core/os/midi_driver.h @@ -32,7 +32,7 @@ #define MIDI_DRIVER_H #include "core/typedefs.h" -#include "core/variant.h" +#include "core/variant/variant.h" /** * Multi-Platform abstraction for accessing to MIDI. diff --git a/core/os/mutex.h b/core/os/mutex.h index d42cbed821..778bdaba09 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -31,7 +31,7 @@ #ifndef MUTEX_H #define MUTEX_H -#include "core/error_list.h" +#include "core/error/error_list.h" #include "core/typedefs.h" #if !defined(NO_THREADS) diff --git a/core/os/os.cpp b/core/os/os.cpp index 3a398316bd..552bf043bf 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -30,11 +30,11 @@ #include "os.h" +#include "core/config/project_settings.h" #include "core/input/input.h" #include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/midi_driver.h" -#include "core/project_settings.h" #include "core/version_generated.gen.h" #include "servers/audio_server.h" diff --git a/core/os/os.h b/core/os/os.h index 4c1d930107..a1e75b5ee9 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -31,13 +31,13 @@ #ifndef OS_H #define OS_H -#include "core/engine.h" -#include "core/image.h" +#include "core/config/engine.h" +#include "core/io/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 "core/string/ustring.h" +#include "core/templates/list.h" +#include "core/templates/vector.h" #include <stdarg.h> diff --git a/core/pool_allocator.cpp b/core/os/pool_allocator.cpp index b222c20a00..52536ff45d 100644 --- a/core/pool_allocator.cpp +++ b/core/os/pool_allocator.cpp @@ -30,11 +30,11 @@ #include "pool_allocator.h" -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include "core/os/copymem.h" #include "core/os/memory.h" #include "core/os/os.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #include <assert.h> diff --git a/core/pool_allocator.h b/core/os/pool_allocator.h index 7d77af6266..7d77af6266 100644 --- a/core/pool_allocator.h +++ b/core/os/pool_allocator.h diff --git a/core/os/rw_lock.cpp b/core/os/rw_lock.cpp index a668fe2b4c..669f05c6b0 100644 --- a/core/os/rw_lock.cpp +++ b/core/os/rw_lock.cpp @@ -30,7 +30,7 @@ #include "rw_lock.h" -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include <stddef.h> diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h index 1035072cce..1190102a83 100644 --- a/core/os/rw_lock.h +++ b/core/os/rw_lock.h @@ -31,7 +31,7 @@ #ifndef RW_LOCK_H #define RW_LOCK_H -#include "core/error_list.h" +#include "core/error/error_list.h" class RWLock { protected: diff --git a/core/os/semaphore.h b/core/os/semaphore.h index 077e04704b..b170cada3a 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -31,7 +31,7 @@ #ifndef SEMAPHORE_H #define SEMAPHORE_H -#include "core/error_list.h" +#include "core/error/error_list.h" #include "core/typedefs.h" #if !defined(NO_THREADS) diff --git a/core/spin_lock.h b/core/os/spin_lock.h index 1bb810bb29..1bb810bb29 100644 --- a/core/spin_lock.h +++ b/core/os/spin_lock.h diff --git a/core/os/thread.h b/core/os/thread.h index f761d4ca43..d68476e683 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -31,8 +31,8 @@ #ifndef THREAD_H #define THREAD_H +#include "core/string/ustring.h" #include "core/typedefs.h" -#include "core/ustring.h" typedef void (*ThreadCreateCallback)(void *p_userdata); diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h index d27399e4cc..ed141a5339 100644 --- a/core/os/threaded_array_processor.h +++ b/core/os/threaded_array_processor.h @@ -35,7 +35,7 @@ #include "core/os/os.h" #include "core/os/thread.h" #include "core/os/thread_safe.h" -#include "core/safe_refcount.h" +#include "core/templates/safe_refcount.h" template <class C, class U> struct ThreadArrayProcessData { diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 54d3ec300f..7e32f215e7 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -30,24 +30,24 @@ #include "register_core_types.h" -#include "core/bind/core_bind.h" -#include "core/class_db.h" -#include "core/compressed_translation.h" +#include "core/config/engine.h" +#include "core/config/project_settings.h" +#include "core/core_bind.h" #include "core/core_string_names.h" #include "core/crypto/aes_context.h" #include "core/crypto/crypto.h" #include "core/crypto/hashing_context.h" -#include "core/engine.h" -#include "core/func_ref.h" #include "core/input/input.h" #include "core/input/input_map.h" #include "core/io/config_file.h" #include "core/io/dtls_server.h" #include "core/io/http_client.h" #include "core/io/image_loader.h" +#include "core/io/json.h" #include "core/io/marshalls.h" #include "core/io/multiplayer_api.h" #include "core/io/networked_multiplayer_peer.h" +#include "core/io/packed_data_container.h" #include "core/io/packet_peer.h" #include "core/io/packet_peer_dtls.h" #include "core/io/packet_peer_udp.h" @@ -65,11 +65,11 @@ #include "core/math/geometry_3d.h" #include "core/math/random_number_generator.h" #include "core/math/triangle_mesh.h" +#include "core/object/class_db.h" +#include "core/object/undo_redo.h" #include "core/os/main_loop.h" -#include "core/packed_data_container.h" -#include "core/project_settings.h" -#include "core/translation.h" -#include "core/undo_redo.h" +#include "core/string/compressed_translation.h" +#include "core/string/translation.h" static Ref<ResourceFormatSaverBinary> resource_saver_binary; static Ref<ResourceFormatLoaderBinary> resource_loader_binary; @@ -97,12 +97,6 @@ extern Mutex _global_mutex; extern void register_global_constants(); extern void unregister_global_constants(); -extern void register_variant_methods(); -extern void unregister_variant_methods(); -extern void register_variant_operators(); -extern void unregister_variant_operators(); -extern void register_variant_setters_getters(); -extern void unregister_variant_setters_getters(); void register_core_types() { //consistency check @@ -115,9 +109,8 @@ void register_core_types() { ResourceLoader::initialize(); register_global_constants(); - register_variant_methods(); - register_variant_operators(); - register_variant_setters_getters(); + + Variant::register_types(); CoreStringNames::create(); @@ -161,7 +154,6 @@ void register_core_types() { ClassDB::register_class<InputEventPanGesture>(); ClassDB::register_class<InputEventMIDI>(); - ClassDB::register_class<FuncRef>(); ClassDB::register_virtual_class<StreamPeer>(); ClassDB::register_class<StreamPeerBuffer>(); ClassDB::register_class<StreamPeerTCP>(); @@ -206,6 +198,7 @@ void register_core_types() { ClassDB::register_class<_Semaphore>(); ClassDB::register_class<XMLParser>(); + ClassDB::register_class<JSONParser>(); ClassDB::register_class<ConfigFile>(); @@ -325,9 +318,8 @@ void unregister_core_types() { ClassDB::cleanup_defaults(); ObjectDB::cleanup(); - unregister_variant_setters_getters(); - unregister_variant_operators(); - unregister_variant_methods(); + Variant::unregister_types(); + unregister_global_constants(); ClassDB::cleanup(); diff --git a/core/string/SCsub b/core/string/SCsub new file mode 100644 index 0000000000..3217166f18 --- /dev/null +++ b/core/string/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import("env") + +env_string = env.Clone() + +env_string.add_source_files(env.core_sources, "*.cpp") diff --git a/core/compressed_translation.cpp b/core/string/compressed_translation.cpp index a92275565d..bdb296a79b 100644 --- a/core/compressed_translation.cpp +++ b/core/string/compressed_translation.cpp @@ -30,7 +30,7 @@ #include "compressed_translation.h" -#include "core/pair.h" +#include "core/templates/pair.h" extern "C" { #include "thirdparty/misc/smaz.h" diff --git a/core/compressed_translation.h b/core/string/compressed_translation.h index c8b3cd2330..efb3535362 100644 --- a/core/compressed_translation.h +++ b/core/string/compressed_translation.h @@ -31,7 +31,7 @@ #ifndef COMPRESSED_TRANSLATION_H #define COMPRESSED_TRANSLATION_H -#include "core/translation.h" +#include "core/string/translation.h" class PHashTranslation : public Translation { GDCLASS(PHashTranslation, Translation); diff --git a/core/node_path.cpp b/core/string/node_path.cpp index 2a51dca74a..4d152d9258 100644 --- a/core/node_path.cpp +++ b/core/string/node_path.cpp @@ -30,7 +30,7 @@ #include "node_path.h" -#include "core/print_string.h" +#include "core/string/print_string.h" void NodePath::_update_hash_cache() const { uint32_t h = data->absolute ? 1 : 0; diff --git a/core/node_path.h b/core/string/node_path.h index 7c06bf01ce..b4513ddb3c 100644 --- a/core/node_path.h +++ b/core/string/node_path.h @@ -31,8 +31,8 @@ #ifndef NODE_PATH_H #define NODE_PATH_H -#include "core/string_name.h" -#include "core/ustring.h" +#include "core/string/string_name.h" +#include "core/string/ustring.h" class NodePath { struct Data { diff --git a/core/print_string.cpp b/core/string/print_string.cpp index 54de229471..54de229471 100644 --- a/core/print_string.cpp +++ b/core/string/print_string.cpp diff --git a/core/print_string.h b/core/string/print_string.h index 4d03f4a6de..3e8f244cc5 100644 --- a/core/print_string.h +++ b/core/string/print_string.h @@ -31,7 +31,7 @@ #ifndef PRINT_STRING_H #define PRINT_STRING_H -#include "core/ustring.h" +#include "core/string/ustring.h" extern void (*_print_func)(String); diff --git a/core/string_buffer.h b/core/string/string_buffer.h index a685720851..1317b538d4 100644 --- a/core/string_buffer.h +++ b/core/string/string_buffer.h @@ -31,7 +31,7 @@ #ifndef STRING_BUFFER_H #define STRING_BUFFER_H -#include "core/ustring.h" +#include "core/string/ustring.h" template <int SHORT_BUFFER_SIZE = 64> class StringBuffer { diff --git a/core/string_builder.cpp b/core/string/string_builder.cpp index dec299ffa3..dec299ffa3 100644 --- a/core/string_builder.cpp +++ b/core/string/string_builder.cpp diff --git a/core/string_builder.h b/core/string/string_builder.h index 2a37d14218..c732f1b9ea 100644 --- a/core/string_builder.h +++ b/core/string/string_builder.h @@ -31,8 +31,8 @@ #ifndef STRING_BUILDER_H #define STRING_BUILDER_H -#include "core/ustring.h" -#include "core/vector.h" +#include "core/string/ustring.h" +#include "core/templates/vector.h" class StringBuilder { uint32_t string_length = 0; diff --git a/core/string_name.cpp b/core/string/string_name.cpp index 21467825d1..34afdaee38 100644 --- a/core/string_name.cpp +++ b/core/string/string_name.cpp @@ -31,7 +31,7 @@ #include "string_name.h" #include "core/os/os.h" -#include "core/print_string.h" +#include "core/string/print_string.h" StaticCString StaticCString::create(const char *p_ptr) { StaticCString scs; diff --git a/core/string_name.h b/core/string/string_name.h index 937f25a496..e6b46506c3 100644 --- a/core/string_name.h +++ b/core/string/string_name.h @@ -32,8 +32,8 @@ #define STRING_NAME_H #include "core/os/mutex.h" -#include "core/safe_refcount.h" -#include "core/ustring.h" +#include "core/string/ustring.h" +#include "core/templates/safe_refcount.h" class Main; diff --git a/core/translation.cpp b/core/string/translation.cpp index 8c8ca06740..df8a26e5ce 100644 --- a/core/translation.cpp +++ b/core/string/translation.cpp @@ -30,9 +30,9 @@ #include "translation.h" +#include "core/config/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) diff --git a/core/translation.h b/core/string/translation.h index cba25a434f..8d34f7997e 100644 --- a/core/translation.h +++ b/core/string/translation.h @@ -31,7 +31,7 @@ #ifndef TRANSLATION_H #define TRANSLATION_H -#include "core/resource.h" +#include "core/io/resource.h" class Translation : public Resource { GDCLASS(Translation, Resource); diff --git a/core/translation_po.cpp b/core/string/translation_po.cpp index 203f29026b..203f29026b 100644 --- a/core/translation_po.cpp +++ b/core/string/translation_po.cpp diff --git a/core/translation_po.h b/core/string/translation_po.h index 88830210ef..c8a47bec5a 100644 --- a/core/translation_po.h +++ b/core/string/translation_po.h @@ -34,7 +34,7 @@ //#define DEBUG_TRANSLATION_PO #include "core/math/expression.h" -#include "core/translation.h" +#include "core/string/translation.h" class TranslationPO : public Translation { GDCLASS(TranslationPO, Translation); diff --git a/core/ucaps.h b/core/string/ucaps.h index 79b346acba..79b346acba 100644 --- a/core/ucaps.h +++ b/core/string/ucaps.h diff --git a/core/ustring.cpp b/core/string/ustring.cpp index 79db595714..b5758bddf3 100644 --- a/core/ustring.cpp +++ b/core/string/ustring.cpp @@ -30,14 +30,14 @@ #include "ustring.h" -#include "core/color.h" #include "core/crypto/crypto_core.h" +#include "core/math/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 "core/string/print_string.h" +#include "core/string/translation.h" +#include "core/string/ucaps.h" +#include "core/variant/variant.h" #include <cstdint> diff --git a/core/ustring.h b/core/string/ustring.h index bb7ab61eed..b46733ab66 100644 --- a/core/ustring.h +++ b/core/string/ustring.h @@ -31,10 +31,10 @@ #ifndef USTRING_H #define USTRING_H -#include "core/array.h" -#include "core/cowdata.h" +#include "core/templates/cowdata.h" +#include "core/templates/vector.h" #include "core/typedefs.h" -#include "core/vector.h" +#include "core/variant/array.h" /*************************************************************************/ /* CharProxy */ @@ -433,10 +433,10 @@ public: /** * The constructors must not depend on other overloads */ - /* String(char32_t p_char);*/ _FORCE_INLINE_ String() {} _FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); } + String &operator=(const String &p_str) { _cowdata._ref(p_str._cowdata); return *this; @@ -536,4 +536,24 @@ String RTRN(const String &p_text, const String &p_text_plural, int p_n, const St bool is_symbol(char32_t c); bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end); +_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr) { +} + +_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str) { + arr.push_back(p_str); +} + +template <class... P> +_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str, P... p_args) { + arr.push_back(p_str); + sarray_add_str(arr, p_args...); +} + +template <class... P> +_FORCE_INLINE_ Vector<String> sarray(P... p_args) { + Vector<String> arr; + sarray_add_str(arr, p_args...); + return arr; +} + #endif // USTRING_H diff --git a/core/templates/SCsub b/core/templates/SCsub new file mode 100644 index 0000000000..8c4c843a33 --- /dev/null +++ b/core/templates/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import("env") + +env_templates = env.Clone() + +env_templates.add_source_files(env.core_sources, "*.cpp") diff --git a/core/command_queue_mt.cpp b/core/templates/command_queue_mt.cpp index a55eed5d3c..a94853a21c 100644 --- a/core/command_queue_mt.cpp +++ b/core/templates/command_queue_mt.cpp @@ -30,8 +30,8 @@ #include "command_queue_mt.h" +#include "core/config/project_settings.h" #include "core/os/os.h" -#include "core/project_settings.h" void CommandQueueMT::lock() { mutex.lock(); diff --git a/core/command_queue_mt.h b/core/templates/command_queue_mt.h index 0e5bc7f369..ac38d330de 100644 --- a/core/command_queue_mt.h +++ b/core/templates/command_queue_mt.h @@ -34,7 +34,7 @@ #include "core/os/memory.h" #include "core/os/mutex.h" #include "core/os/semaphore.h" -#include "core/simple_type.h" +#include "core/templates/simple_type.h" #include "core/typedefs.h" #define COMMA(N) _COMMA_##N diff --git a/core/cowdata.h b/core/templates/cowdata.h index 79676e6d80..d5eb08286d 100644 --- a/core/cowdata.h +++ b/core/templates/cowdata.h @@ -31,9 +31,9 @@ #ifndef COWDATA_H #define COWDATA_H -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include "core/os/memory.h" -#include "core/safe_refcount.h" +#include "core/templates/safe_refcount.h" #include <string.h> diff --git a/core/hash_map.h b/core/templates/hash_map.h index 10fc931e7a..f6b889015a 100644 --- a/core/hash_map.h +++ b/core/templates/hash_map.h @@ -31,12 +31,12 @@ #ifndef HASH_MAP_H #define HASH_MAP_H -#include "core/error_macros.h" -#include "core/hashfuncs.h" -#include "core/list.h" +#include "core/error/error_macros.h" #include "core/math/math_funcs.h" #include "core/os/memory.h" -#include "core/ustring.h" +#include "core/string/ustring.h" +#include "core/templates/hashfuncs.h" +#include "core/templates/list.h" /** * @class HashMap diff --git a/core/hashfuncs.h b/core/templates/hashfuncs.h index f4048843fc..86bb1b5228 100644 --- a/core/hashfuncs.h +++ b/core/templates/hashfuncs.h @@ -33,12 +33,12 @@ #include "core/math/math_defs.h" #include "core/math/math_funcs.h" -#include "core/node_path.h" -#include "core/object_id.h" -#include "core/rid.h" -#include "core/string_name.h" +#include "core/object/object_id.h" +#include "core/string/node_path.h" +#include "core/string/string_name.h" +#include "core/string/ustring.h" +#include "core/templates/rid.h" #include "core/typedefs.h" -#include "core/ustring.h" /** * Hashing functions */ diff --git a/core/list.h b/core/templates/list.h index 1cef3c484d..d745066e4c 100644 --- a/core/list.h +++ b/core/templates/list.h @@ -31,9 +31,9 @@ #ifndef LIST_H #define LIST_H -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include "core/os/memory.h" -#include "core/sort_array.h" +#include "core/templates/sort_array.h" /** * Generic Templatized Linked List Implementation. diff --git a/core/local_vector.h b/core/templates/local_vector.h index b0dbd22b29..4ef040dc77 100644 --- a/core/local_vector.h +++ b/core/templates/local_vector.h @@ -31,11 +31,11 @@ #ifndef LOCAL_VECTOR_H #define LOCAL_VECTOR_H -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include "core/os/copymem.h" #include "core/os/memory.h" -#include "core/sort_array.h" -#include "core/vector.h" +#include "core/templates/sort_array.h" +#include "core/templates/vector.h" template <class T, class U = uint32_t, bool force_trivial = false> class LocalVector { diff --git a/core/map.h b/core/templates/map.h index fd4f500556..c454d69256 100644 --- a/core/map.h +++ b/core/templates/map.h @@ -31,8 +31,8 @@ #ifndef MAP_H #define MAP_H -#include "core/error_macros.h" -#include "core/set.h" +#include "core/error/error_macros.h" +#include "core/templates/set.h" // based on the very nice implementation of rb-trees by: // https://web.archive.org/web/20120507164830/http://web.mit.edu/~emin/www/source_code/red_black_tree/index.html diff --git a/core/oa_hash_map.h b/core/templates/oa_hash_map.h index 6061366ab3..d9d632b4ce 100644 --- a/core/oa_hash_map.h +++ b/core/templates/oa_hash_map.h @@ -31,10 +31,10 @@ #ifndef OA_HASH_MAP_H #define OA_HASH_MAP_H -#include "core/hashfuncs.h" #include "core/math/math_funcs.h" #include "core/os/copymem.h" #include "core/os/memory.h" +#include "core/templates/hashfuncs.h" /** * A HashMap implementation that uses open addressing with Robin Hood hashing. diff --git a/core/ordered_hash_map.h b/core/templates/ordered_hash_map.h index e6a6340a2f..9398868b01 100644 --- a/core/ordered_hash_map.h +++ b/core/templates/ordered_hash_map.h @@ -31,9 +31,9 @@ #ifndef ORDERED_HASH_MAP_H #define ORDERED_HASH_MAP_H -#include "core/hash_map.h" -#include "core/list.h" -#include "core/pair.h" +#include "core/templates/hash_map.h" +#include "core/templates/list.h" +#include "core/templates/pair.h" /** * A hash map which allows to iterate elements in insertion order. diff --git a/core/pair.h b/core/templates/pair.h index 89ea2b9fd9..89ea2b9fd9 100644 --- a/core/pair.h +++ b/core/templates/pair.h diff --git a/core/rid.h b/core/templates/rid.h index a475d166d5..a475d166d5 100644 --- a/core/rid.h +++ b/core/templates/rid.h diff --git a/core/rid_owner.cpp b/core/templates/rid_owner.cpp index a5065f29f8..a5065f29f8 100644 --- a/core/rid_owner.cpp +++ b/core/templates/rid_owner.cpp diff --git a/core/rid_owner.h b/core/templates/rid_owner.h index 30f1e41733..d1bcb92010 100644 --- a/core/rid_owner.h +++ b/core/templates/rid_owner.h @@ -31,14 +31,14 @@ #ifndef RID_OWNER_H #define RID_OWNER_H -#include "core/list.h" -#include "core/oa_hash_map.h" #include "core/os/memory.h" -#include "core/print_string.h" -#include "core/rid.h" -#include "core/safe_refcount.h" -#include "core/set.h" -#include "core/spin_lock.h" +#include "core/os/spin_lock.h" +#include "core/string/print_string.h" +#include "core/templates/list.h" +#include "core/templates/oa_hash_map.h" +#include "core/templates/rid.h" +#include "core/templates/safe_refcount.h" +#include "core/templates/set.h" #include <stdio.h> #include <typeinfo> diff --git a/core/ring_buffer.h b/core/templates/ring_buffer.h index 6b71d12cf3..12ec047fb6 100644 --- a/core/ring_buffer.h +++ b/core/templates/ring_buffer.h @@ -31,7 +31,7 @@ #ifndef RING_BUFFER_H #define RING_BUFFER_H -#include "core/vector.h" +#include "core/templates/vector.h" template <typename T> class RingBuffer { diff --git a/core/safe_refcount.cpp b/core/templates/safe_refcount.cpp index d5ee778ef7..d5ee778ef7 100644 --- a/core/safe_refcount.cpp +++ b/core/templates/safe_refcount.cpp diff --git a/core/safe_refcount.h b/core/templates/safe_refcount.h index dc4e62354a..dc4e62354a 100644 --- a/core/safe_refcount.h +++ b/core/templates/safe_refcount.h diff --git a/core/self_list.h b/core/templates/self_list.h index 3104bcb714..2a037d109c 100644 --- a/core/self_list.h +++ b/core/templates/self_list.h @@ -31,7 +31,7 @@ #ifndef SELF_LIST_H #define SELF_LIST_H -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include "core/typedefs.h" template <class T> diff --git a/core/set.h b/core/templates/set.h index 1bc0a3f41e..1bc0a3f41e 100644 --- a/core/set.h +++ b/core/templates/set.h diff --git a/core/simple_type.h b/core/templates/simple_type.h index 841ab9f384..841ab9f384 100644 --- a/core/simple_type.h +++ b/core/templates/simple_type.h diff --git a/core/sort_array.h b/core/templates/sort_array.h index 93cc6f727d..a4326ac565 100644 --- a/core/sort_array.h +++ b/core/templates/sort_array.h @@ -31,7 +31,7 @@ #ifndef SORT_ARRAY_H #define SORT_ARRAY_H -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include "core/typedefs.h" #define ERR_BAD_COMPARE(cond) \ diff --git a/core/thread_work_pool.cpp b/core/templates/thread_work_pool.cpp index 3a95e83ffc..3a95e83ffc 100644 --- a/core/thread_work_pool.cpp +++ b/core/templates/thread_work_pool.cpp diff --git a/core/thread_work_pool.h b/core/templates/thread_work_pool.h index 661060aa3f..661060aa3f 100644 --- a/core/thread_work_pool.h +++ b/core/templates/thread_work_pool.h diff --git a/core/vector.h b/core/templates/vector.h index 8ba46ed686..9d45f7c30a 100644 --- a/core/vector.h +++ b/core/templates/vector.h @@ -37,11 +37,11 @@ * Vector container. Regular Vector Container. Use with care and for smaller arrays when possible. Use Vector for large arrays. */ -#include "core/cowdata.h" -#include "core/error_macros.h" +#include "core/error/error_macros.h" #include "core/os/copymem.h" #include "core/os/memory.h" -#include "core/sort_array.h" +#include "core/templates/cowdata.h" +#include "core/templates/sort_array.h" template <class T> class VectorWriteProxy { diff --git a/core/vmap.h b/core/templates/vmap.h index c91ea9b3c9..8d2a3d2a9c 100644 --- a/core/vmap.h +++ b/core/templates/vmap.h @@ -31,7 +31,7 @@ #ifndef VMAP_H #define VMAP_H -#include "core/cowdata.h" +#include "core/templates/cowdata.h" #include "core/typedefs.h" template <class T, class V> diff --git a/core/vset.h b/core/templates/vset.h index 034b8fe851..4c0b8717b6 100644 --- a/core/vset.h +++ b/core/templates/vset.h @@ -31,8 +31,8 @@ #ifndef VSET_H #define VSET_H +#include "core/templates/vector.h" #include "core/typedefs.h" -#include "core/vector.h" template <class T> class VSet { diff --git a/core/typedefs.h b/core/typedefs.h index f0c32f2c95..d7ee5ee40e 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -41,8 +41,8 @@ #include "platform_config.h" // Should be available everywhere. -#include "core/error_list.h" -#include "core/int_types.h" +#include "core/error/error_list.h" +#include <cstdint> // Turn argument to string constant: // https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html#Stringizing diff --git a/core/variant/SCsub b/core/variant/SCsub new file mode 100644 index 0000000000..7f4c8b7788 --- /dev/null +++ b/core/variant/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import("env") + +env_variant = env.Clone() + +env_variant.add_source_files(env.core_sources, "*.cpp") diff --git a/core/array.cpp b/core/variant/array.cpp index 514f5a5dad..79bc01b89c 100644 --- a/core/array.cpp +++ b/core/variant/array.cpp @@ -31,11 +31,11 @@ #include "array.h" #include "container_type_validate.h" -#include "core/class_db.h" -#include "core/hashfuncs.h" -#include "core/script_language.h" -#include "core/variant.h" -#include "core/vector.h" +#include "core/object/class_db.h" +#include "core/object/script_language.h" +#include "core/templates/hashfuncs.h" +#include "core/templates/vector.h" +#include "core/variant/variant.h" class ArrayPrivate { public: @@ -165,7 +165,7 @@ void Array::_assign(const Array &p_array) { } else if (Variant::can_convert_strict(src_val.get_type(), _p->typed.type)) { Variant *ptr = &src_val; Callable::CallError ce; - new_array.write[i] = Variant::construct(_p->typed.type, (const Variant **)&ptr, 1, ce, true); + Variant::construct(_p->typed.type, new_array.write[i], (const Variant **)&ptr, 1, ce); if (ce.error != Callable::CallError::CALL_OK) { ERR_FAIL_MSG("Unable to convert array index " + itos(i) + " from '" + Variant::get_type_name(src_val.get_type()) + "' to '" + Variant::get_type_name(_p->typed.type) + "'."); } @@ -192,6 +192,11 @@ void Array::push_back(const Variant &p_value) { _p->array.push_back(p_value); } +void Array::append_array(const Array &p_array) { + ERR_FAIL_COND(!_p->typed.validate(p_array, "append_array")); + _p->array.append_array(p_array._p->array); +} + Error Array::resize(int p_new_size) { return _p->array.resize(p_new_size); } diff --git a/core/array.h b/core/variant/array.h index b37d600abd..e01ac13168 100644 --- a/core/array.h +++ b/core/variant/array.h @@ -68,6 +68,7 @@ public: void push_back(const Variant &p_value); _FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } //for python compatibility + void append_array(const Array &p_array); Error resize(int p_new_size); void insert(int p_pos, const Variant &p_value); diff --git a/core/binder_common.h b/core/variant/binder_common.h index 0fbfa56230..2e38ce5b06 100644 --- a/core/binder_common.h +++ b/core/variant/binder_common.h @@ -31,14 +31,14 @@ #ifndef BINDER_COMMON_H #define BINDER_COMMON_H -#include "core/list.h" -#include "core/method_ptrcall.h" -#include "core/object.h" -#include "core/simple_type.h" -#include "core/type_info.h" +#include "core/object/object.h" +#include "core/templates/list.h" +#include "core/templates/simple_type.h" #include "core/typedefs.h" -#include "core/variant.h" -#include "core/variant_internal.h" +#include "core/variant/method_ptrcall.h" +#include "core/variant/type_info.h" +#include "core/variant/variant.h" +#include "core/variant/variant_internal.h" #include <stdio.h> @@ -650,6 +650,39 @@ void call_with_variant_args_retc_static_helper(T *p_instance, R (*p_method)(T *, (void)p_args; } +template <class T, class R, class... P> +void call_with_variant_args_retc_static_helper_dv(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &default_values, Callable::CallError &r_error) { +#ifdef DEBUG_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; + + int32_t dvs = default_values.size(); +#ifdef DEBUG_ENABLED + if (missing > dvs) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array + for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { + if (i < p_argcount) { + args[i] = p_args[i]; + } else { + args[i] = &default_values[i - p_argcount + (dvs - missing)]; + } + } + + call_with_variant_args_retc_static_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + #if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop #endif diff --git a/core/callable.cpp b/core/variant/callable.cpp index c368565687..e504fd05e3 100644 --- a/core/callable.cpp +++ b/core/variant/callable.cpp @@ -31,10 +31,10 @@ #include "callable.h" #include "callable_bind.h" -#include "core/script_language.h" -#include "message_queue.h" -#include "object.h" -#include "reference.h" +#include "core/object/message_queue.h" +#include "core/object/object.h" +#include "core/object/reference.h" +#include "core/object/script_language.h" void Callable::call_deferred(const Variant **p_arguments, int p_argcount) const { MessageQueue::get_singleton()->push_callable(*this, p_arguments, p_argcount); diff --git a/core/callable.h b/core/variant/callable.h index 936272a681..40621fbde3 100644 --- a/core/callable.h +++ b/core/variant/callable.h @@ -31,9 +31,9 @@ #ifndef CALLABLE_H #define CALLABLE_H -#include "core/list.h" -#include "core/object_id.h" -#include "core/string_name.h" +#include "core/object/object_id.h" +#include "core/string/string_name.h" +#include "core/templates/list.h" class Object; class Variant; diff --git a/core/callable_bind.cpp b/core/variant/callable_bind.cpp index da08d3ccbd..da08d3ccbd 100644 --- a/core/callable_bind.cpp +++ b/core/variant/callable_bind.cpp diff --git a/core/callable_bind.h b/core/variant/callable_bind.h index 21b9228be3..fc5659e412 100644 --- a/core/callable_bind.h +++ b/core/variant/callable_bind.h @@ -31,8 +31,8 @@ #ifndef CALLABLE_BIND_H #define CALLABLE_BIND_H -#include "core/callable.h" -#include "core/variant.h" +#include "core/variant/callable.h" +#include "core/variant/variant.h" class CallableCustomBind : public CallableCustom { Callable callable; diff --git a/core/container_type_validate.h b/core/variant/container_type_validate.h index 8a361aa0ef..4d3a5f683b 100644 --- a/core/container_type_validate.h +++ b/core/variant/container_type_validate.h @@ -31,8 +31,8 @@ #ifndef CONTAINER_TYPE_VALIDATE_H #define CONTAINER_TYPE_VALIDATE_H -#include "core/script_language.h" -#include "core/variant.h" +#include "core/object/script_language.h" +#include "core/variant/variant.h" struct ContainerTypeValidate { Variant::Type type = Variant::NIL; diff --git a/core/dictionary.cpp b/core/variant/dictionary.cpp index 052e1bdae1..2bc1f7a86d 100644 --- a/core/dictionary.cpp +++ b/core/variant/dictionary.cpp @@ -30,9 +30,9 @@ #include "dictionary.h" -#include "core/ordered_hash_map.h" -#include "core/safe_refcount.h" -#include "core/variant.h" +#include "core/templates/ordered_hash_map.h" +#include "core/templates/safe_refcount.h" +#include "core/variant/variant.h" struct DictionaryPrivate { SafeRefCount refcount; diff --git a/core/dictionary.h b/core/variant/dictionary.h index a01d96ba01..bbe94122ad 100644 --- a/core/dictionary.h +++ b/core/variant/dictionary.h @@ -31,9 +31,9 @@ #ifndef DICTIONARY_H #define DICTIONARY_H -#include "core/array.h" -#include "core/list.h" -#include "core/ustring.h" +#include "core/string/ustring.h" +#include "core/templates/list.h" +#include "core/variant/array.h" class Variant; diff --git a/core/method_ptrcall.h b/core/variant/method_ptrcall.h index 022ed2a5d6..936de145f8 100644 --- a/core/method_ptrcall.h +++ b/core/variant/method_ptrcall.h @@ -32,9 +32,9 @@ #define METHOD_PTRCALL_H #include "core/math/transform_2d.h" -#include "core/object_id.h" +#include "core/object/object_id.h" #include "core/typedefs.h" -#include "core/variant.h" +#include "core/variant/variant.h" #ifdef PTRCALL_ENABLED diff --git a/core/type_info.h b/core/variant/type_info.h index b9ae88d97c..ce7c2bfe14 100644 --- a/core/type_info.h +++ b/core/variant/type_info.h @@ -153,7 +153,7 @@ MAKE_TYPE_INFO(Transform, Variant::TRANSFORM) MAKE_TYPE_INFO(Color, Variant::COLOR) MAKE_TYPE_INFO(StringName, Variant::STRING_NAME) MAKE_TYPE_INFO(NodePath, Variant::NODE_PATH) -MAKE_TYPE_INFO(RID, Variant::_RID) +MAKE_TYPE_INFO(RID, Variant::RID) MAKE_TYPE_INFO(Callable, Variant::CALLABLE) MAKE_TYPE_INFO(Signal, Variant::SIGNAL) MAKE_TYPE_INFO(Dictionary, Variant::DICTIONARY) diff --git a/core/typed_array.h b/core/variant/typed_array.h index 86f26d7550..ff42cb687e 100644 --- a/core/typed_array.h +++ b/core/variant/typed_array.h @@ -31,9 +31,9 @@ #ifndef TYPED_ARRAY_H #define TYPED_ARRAY_H -#include "core/array.h" -#include "core/method_ptrcall.h" -#include "core/variant.h" +#include "core/variant/array.h" +#include "core/variant/method_ptrcall.h" +#include "core/variant/variant.h" template <class T> class TypedArray : public Array { @@ -105,7 +105,7 @@ MAKE_TYPED_ARRAY(Transform, Variant::TRANSFORM) MAKE_TYPED_ARRAY(Color, Variant::COLOR) MAKE_TYPED_ARRAY(StringName, Variant::STRING_NAME) MAKE_TYPED_ARRAY(NodePath, Variant::NODE_PATH) -MAKE_TYPED_ARRAY(RID, Variant::_RID) +MAKE_TYPED_ARRAY(RID, Variant::RID) MAKE_TYPED_ARRAY(Callable, Variant::CALLABLE) MAKE_TYPED_ARRAY(Signal, Variant::SIGNAL) MAKE_TYPED_ARRAY(Dictionary, Variant::DICTIONARY) @@ -207,7 +207,7 @@ MAKE_TYPED_ARRAY_INFO(Transform, Variant::TRANSFORM) MAKE_TYPED_ARRAY_INFO(Color, Variant::COLOR) MAKE_TYPED_ARRAY_INFO(StringName, Variant::STRING_NAME) MAKE_TYPED_ARRAY_INFO(NodePath, Variant::NODE_PATH) -MAKE_TYPED_ARRAY_INFO(RID, Variant::_RID) +MAKE_TYPED_ARRAY_INFO(RID, Variant::RID) MAKE_TYPED_ARRAY_INFO(Callable, Variant::CALLABLE) MAKE_TYPED_ARRAY_INFO(Signal, Variant::SIGNAL) MAKE_TYPED_ARRAY_INFO(Dictionary, Variant::DICTIONARY) diff --git a/core/variant.cpp b/core/variant/variant.cpp index 181ced0f32..741d05c139 100644 --- a/core/variant.cpp +++ b/core/variant/variant.cpp @@ -33,10 +33,10 @@ #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" #include "core/io/marshalls.h" +#include "core/io/resource.h" #include "core/math/math_funcs.h" -#include "core/print_string.h" -#include "core/resource.h" -#include "core/variant_parser.h" +#include "core/string/print_string.h" +#include "core/variant/variant_parser.h" #include "scene/gui/control.h" #include "scene/main/node.h" @@ -109,7 +109,7 @@ String Variant::get_type_name(Variant::Type p_type) { return "Color"; } break; - case _RID: { + case RID: { return "RID"; } break; case OBJECT: { @@ -342,7 +342,7 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { } break; - case _RID: { + case RID: { static const Type valid[] = { OBJECT, NIL @@ -649,7 +649,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type } break; - case _RID: { + case RID: { static const Type valid[] = { OBJECT, NIL @@ -891,8 +891,8 @@ bool Variant::is_zero() const { return *reinterpret_cast<const Color *>(_data._mem) == Color(); } break; - case _RID: { - return *reinterpret_cast<const RID *>(_data._mem) == RID(); + case RID: { + return *reinterpret_cast<const ::RID *>(_data._mem) == ::RID(); } break; case OBJECT: { return _get_obj().obj == nullptr; @@ -1109,8 +1109,8 @@ void Variant::reference(const Variant &p_variant) { memnew_placement(_data._mem, Color(*reinterpret_cast<const Color *>(p_variant._data._mem))); } break; - case _RID: { - memnew_placement(_data._mem, RID(*reinterpret_cast<const RID *>(p_variant._data._mem))); + case RID: { + memnew_placement(_data._mem, ::RID(*reinterpret_cast<const ::RID *>(p_variant._data._mem))); } break; case OBJECT: { memnew_placement(_data._mem, ObjData); @@ -1266,7 +1266,7 @@ void Variant::zero() { } } -void Variant::clear() { +void Variant::_clear_internal() { switch (type) { case STRING: { reinterpret_cast<String *>(_data._mem)->~String(); @@ -1311,9 +1311,11 @@ void Variant::clear() { _get_obj().obj = nullptr; _get_obj().id = ObjectID(); } break; - case _RID: { + case RID: { // not much need probably - reinterpret_cast<RID *>(_data._mem)->~RID(); + // Can't seem to use destructor + scoping operator, so hack. + typedef ::RID RID_Class; + reinterpret_cast<RID_Class *>(_data._mem)->~RID_Class(); } break; case CALLABLE: { reinterpret_cast<Callable *>(_data._mem)->~Callable(); @@ -1358,8 +1360,6 @@ void Variant::clear() { default: { } /* not needed */ } - - type = NIL; } Variant::operator signed int() const { @@ -1849,8 +1849,8 @@ String Variant::stringify(List<const void *> &stack) const { const Signal &s = *reinterpret_cast<const Signal *>(_data._mem); return s; } break; - case _RID: { - const RID &s = *reinterpret_cast<const RID *>(_data._mem); + case RID: { + const ::RID &s = *reinterpret_cast<const ::RID *>(_data._mem); return "RID(" + itos(s.get_id()) + ")"; } break; default: { @@ -2041,25 +2041,25 @@ Variant::operator NodePath() const { } } -Variant::operator RID() const { - if (type == _RID) { - return *reinterpret_cast<const RID *>(_data._mem); +Variant::operator ::RID() const { + if (type == RID) { + return *reinterpret_cast<const ::RID *>(_data._mem); } else if (type == OBJECT && _get_obj().obj == nullptr) { - return RID(); + return ::RID(); } else if (type == OBJECT && _get_obj().obj) { #ifdef DEBUG_ENABLED if (EngineDebugger::is_active()) { - ERR_FAIL_COND_V_MSG(ObjectDB::get_instance(_get_obj().id) == nullptr, RID(), "Invalid pointer (object was freed)."); + ERR_FAIL_COND_V_MSG(ObjectDB::get_instance(_get_obj().id) == nullptr, ::RID(), "Invalid pointer (object was freed)."); } #endif Callable::CallError ce; Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->get_rid, nullptr, 0, ce); - if (ce.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::_RID) { + if (ce.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::RID) { return ret; } - return RID(); + return ::RID(); } else { - return RID(); + return ::RID(); } } @@ -2263,9 +2263,9 @@ Variant::operator Vector<Color>() const { /* helpers */ -Variant::operator Vector<RID>() const { +Variant::operator Vector<::RID>() const { Array va = operator Array(); - Vector<RID> rids; + Vector<::RID> rids; rids.resize(va.size()); for (int i = 0; i < rids.size(); i++) { rids.write[i] = va[i]; @@ -2520,9 +2520,9 @@ Variant::Variant(const NodePath &p_node_path) { memnew_placement(_data._mem, NodePath(p_node_path)); } -Variant::Variant(const RID &p_rid) { - type = _RID; - memnew_placement(_data._mem, RID(p_rid)); +Variant::Variant(const ::RID &p_rid) { + type = RID; + memnew_placement(_data._mem, ::RID(p_rid)); } Variant::Variant(const Object *p_object) { @@ -2580,7 +2580,7 @@ Variant::Variant(const Vector<Plane> &p_array) { } } -Variant::Variant(const Vector<RID> &p_array) { +Variant::Variant(const Vector<::RID> &p_array) { type = ARRAY; Array *rid_array = memnew_placement(_data._mem, Array); @@ -2753,8 +2753,8 @@ void Variant::operator=(const Variant &p_variant) { case COLOR: { *reinterpret_cast<Color *>(_data._mem) = *reinterpret_cast<const Color *>(p_variant._data._mem); } break; - case _RID: { - *reinterpret_cast<RID *>(_data._mem) = *reinterpret_cast<const RID *>(p_variant._data._mem); + case RID: { + *reinterpret_cast<::RID *>(_data._mem) = *reinterpret_cast<const ::RID *>(p_variant._data._mem); } break; case OBJECT: { if (_get_obj().id.is_reference()) { @@ -2955,8 +2955,8 @@ uint32_t Variant::hash() const { return hash_djb2_one_float(reinterpret_cast<const Color *>(_data._mem)->a, hash); } break; - case _RID: { - return hash_djb2_one_64(reinterpret_cast<const RID *>(_data._mem)->get_id()); + case RID: { + return hash_djb2_one_64(reinterpret_cast<const ::RID *>(_data._mem)->get_id()); } break; case OBJECT: { return hash_djb2_one_64(make_uint64_t(_get_obj().obj)); @@ -3401,7 +3401,8 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) { Callable::CallError error; - Variant ret = call(p_method, argptr, argc, error); + Variant ret; + call(p_method, argptr, argc, ret, error); switch (error.error) { case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: { @@ -3435,6 +3436,30 @@ String Variant::get_construct_string() const { return vars; } +String Variant::get_call_error_text(const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) { + String err_text; + + if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) { + int errorarg = ce.argument; + if (p_argptrs) { + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; + } else { + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; + } + } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) { + err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; + } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) { + err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; + } else if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) { + err_text = "Method not found."; + } else if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) { + err_text = "Instance is null"; + } else if (ce.error == Callable::CallError::CALL_OK) { + return "Call OK"; + } + return "'" + String(p_method) + "': " + err_text; +} + String Variant::get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) { String err_text; @@ -3519,3 +3544,18 @@ String vformat(const String &p_text, const Variant &p1, const Variant &p2, const return fmt; } + +void Variant::register_types() { + _register_variant_operators(); + _register_variant_methods(); + _register_variant_setters_getters(); + _register_variant_constructors(); + _register_variant_utility_functions(); +} +void Variant::unregister_types() { + _unregister_variant_operators(); + _unregister_variant_methods(); + _unregister_variant_setters_getters(); + _unregister_variant_constructors(); + _unregister_variant_utility_functions(); +} diff --git a/core/variant.h b/core/variant/variant.h index 3b6205a093..1a684eeea0 100644 --- a/core/variant.h +++ b/core/variant/variant.h @@ -31,13 +31,10 @@ #ifndef VARIANT_H #define VARIANT_H -#include "core/array.h" -#include "core/callable.h" -#include "core/color.h" -#include "core/dictionary.h" #include "core/io/ip_address.h" #include "core/math/aabb.h" #include "core/math/basis.h" +#include "core/math/color.h" #include "core/math/face3.h" #include "core/math/plane.h" #include "core/math/quat.h" @@ -45,10 +42,13 @@ #include "core/math/transform_2d.h" #include "core/math/vector3.h" #include "core/math/vector3i.h" -#include "core/node_path.h" -#include "core/object_id.h" -#include "core/rid.h" -#include "core/ustring.h" +#include "core/object/object_id.h" +#include "core/string/node_path.h" +#include "core/string/ustring.h" +#include "core/templates/rid.h" +#include "core/variant/array.h" +#include "core/variant/callable.h" +#include "core/variant/dictionary.h" class Object; class Node; // helper @@ -97,7 +97,7 @@ public: COLOR, STRING_NAME, NODE_PATH, - _RID, + RID, OBJECT, CALLABLE, SIGNAL, @@ -207,7 +207,68 @@ private: } _data alignas(8); void reference(const Variant &p_variant); - void clear(); + + void _clear_internal(); + + _FORCE_INLINE_ void clear() { + static const bool needs_deinit[Variant::VARIANT_MAX] = { + false, //NIL, + false, //BOOL, + false, //INT, + false, //FLOAT, + true, //STRING, + false, //VECTOR2, + false, //VECTOR2I, + false, //RECT2, + false, //RECT2I, + false, //VECTOR3, + false, //VECTOR3I, + true, //TRANSFORM2D, + false, //PLANE, + false, //QUAT, + true, //AABB, + true, //BASIS, + true, //TRANSFORM, + + // misc types + false, //COLOR, + true, //STRING_NAME, + true, //NODE_PATH, + false, //RID, + true, //OBJECT, + true, //CALLABLE, + true, //SIGNAL, + true, //DICTIONARY, + true, //ARRAY, + + // typed arrays + true, //PACKED_BYTE_ARRAY, + true, //PACKED_INT32_ARRAY, + true, //PACKED_INT64_ARRAY, + true, //PACKED_FLOAT32_ARRAY, + true, //PACKED_FLOAT64_ARRAY, + true, //PACKED_STRING_ARRAY, + true, //PACKED_VECTOR2_ARRAY, + true, //PACKED_VECTOR3_ARRAY, + true, //PACKED_COLOR_ARRAY, + }; + + if (unlikely(needs_deinit[type])) { //make it fast for types that dont need deinit + _clear_internal(); + } + type = NIL; + } + + static void _register_variant_operators(); + static void _unregister_variant_operators(); + static void _register_variant_methods(); + static void _unregister_variant_methods(); + static void _register_variant_setters_getters(); + static void _unregister_variant_setters_getters(); + static void _register_variant_constructors(); + static void _unregister_variant_constructors(); + static void _register_variant_utility_functions(); + static void _unregister_variant_utility_functions(); public: _FORCE_INLINE_ Type get_type() const { @@ -266,7 +327,7 @@ public: operator Color() const; operator NodePath() const; - operator RID() const; + operator ::RID() const; operator Object *() const; operator Node *() const; @@ -291,7 +352,7 @@ public: operator Vector<Variant>() const; operator Vector<StringName>() const; - operator Vector<RID>() const; + operator Vector<::RID>() const; operator Vector<Vector2>() const; // some core type enums to convert to @@ -338,7 +399,7 @@ public: Variant(const Transform &p_transform); Variant(const Color &p_color); Variant(const NodePath &p_node_path); - Variant(const RID &p_rid); + Variant(const ::RID &p_rid); Variant(const Object *p_object); Variant(const Callable &p_callable); Variant(const Signal &p_signal); @@ -358,7 +419,7 @@ public: Variant(const Vector<Variant> &p_array); Variant(const Vector<StringName> &p_array); - Variant(const Vector<RID> &p_array); // helper + Variant(const Vector<::RID> &p_array); // helper Variant(const Vector<Vector2> &p_array); // helper Variant(const IP_Address &p_address); @@ -408,7 +469,7 @@ public: return res; } - Variant::Type get_operator_return_type(Operator p_operator, Type p_type_a, Type p_type_b); + static Variant::Type get_operator_return_type(Operator p_operator, Type p_type_a, Type p_type_b); typedef void (*ValidatedOperatorEvaluator)(const Variant *left, const Variant *right, Variant *r_ret); static ValidatedOperatorEvaluator get_validated_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b); #ifdef PTRCALL_ENABLED @@ -421,61 +482,53 @@ public: static void blend(const Variant &a, const Variant &b, float c, Variant &r_dst); static void interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst); - class InternalMethod { -#ifdef DEBUG_ENABLED - protected: - StringName method_name; - Variant::Type base_type; -#endif - public: - enum Flags { - FLAG_IS_CONST = 1, - FLAG_RETURNS_VARIANT = 2, - FLAG_NO_PTRCALL = 4, - FLAG_VARARGS = 8 - }; + /* Built-In Methods */ - virtual int get_argument_count() const = 0; - virtual Type get_argument_type(int p_arg) const = 0; - virtual Type get_return_type() const = 0; - virtual uint32_t get_flags() const = 0; + typedef void (*ValidatedBuiltInMethod)(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret); + typedef void (*PTRBuiltInMethod)(void *p_base, const void **p_args, void *r_ret, int p_argcount); -#ifdef DEBUG_ENABLED - virtual String get_argument_name(int p_arg) const = 0; - StringName get_name() const { - return method_name; - } - Variant::Type get_base_type() const { - return base_type; - } -#endif - virtual Vector<Variant> get_default_arguments() const = 0; - virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) = 0; - virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) = 0; -#ifdef PTRCALL_ENABLED - virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) = 0; -#endif - virtual ~InternalMethod() {} - }; + static bool has_builtin_method(Variant::Type p_type, const StringName &p_method); + + static ValidatedBuiltInMethod get_validated_builtin_method(Variant::Type p_type, const StringName &p_method); + static PTRBuiltInMethod get_ptr_builtin_method(Variant::Type p_type, const StringName &p_method); - static InternalMethod *get_internal_method(Type p_type, const StringName &p_method_name); + static int get_builtin_method_argument_count(Variant::Type p_type, const StringName &p_method); + static Variant::Type get_builtin_method_argument_type(Variant::Type p_type, const StringName &p_method, int p_argument); + static String get_builtin_method_argument_name(Variant::Type p_type, const StringName &p_method, int p_argument); + static Vector<Variant> get_builtin_method_default_arguments(Variant::Type p_type, const StringName &p_method); + static bool has_builtin_method_return_value(Variant::Type p_type, const StringName &p_method); + static Variant::Type get_builtin_method_return_type(Variant::Type p_type, const StringName &p_method); + static bool is_builtin_method_const(Variant::Type p_type, const StringName &p_method); + static bool is_builtin_method_vararg(Variant::Type p_type, const StringName &p_method); + static void get_builtin_method_list(Variant::Type p_type, List<StringName> *p_list); - void call_ptr(const StringName &p_method, const Variant **p_args, int p_argcount, Variant *r_ret, Callable::CallError &r_error); - Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); + void call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error); Variant call(const StringName &p_method, 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()); + static String get_call_error_text(const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce); static String get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce); static String get_callable_error_text(const Callable &p_callable, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce); - static Variant construct(const Variant::Type, const Variant **p_args, int p_argcount, Callable::CallError &r_error, bool p_strict = true); - + //dynamic (includes Object) void get_method_list(List<MethodInfo> *p_list) const; bool has_method(const StringName &p_method) const; - static Vector<Variant::Type> get_method_argument_types(Variant::Type p_type, const StringName &p_method); - static Vector<Variant> get_method_default_arguments(Variant::Type p_type, const StringName &p_method); - static Variant::Type get_method_return_type(Variant::Type p_type, const StringName &p_method, bool *r_has_return = nullptr); - static Vector<StringName> get_method_argument_names(Variant::Type p_type, const StringName &p_method); - static bool is_method_const(Variant::Type p_type, const StringName &p_method); + + /* Constructors */ + + typedef void (*ValidatedConstructor)(Variant &r_base, const Variant **p_args); + typedef void (*PTRConstructor)(void *base, const void **p_args); + + static int get_constructor_count(Variant::Type p_type); + static ValidatedConstructor get_validated_constructor(Variant::Type p_type, int p_constructor); + static PTRConstructor get_ptr_constructor(Variant::Type p_type, int p_constructor); + static int get_constructor_argument_count(Variant::Type p_type, int p_constructor); + static Variant::Type get_constructor_argument_type(Variant::Type p_type, int p_constructor, int p_argument); + static String get_constructor_argument_name(Variant::Type p_type, int p_constructor, int p_argument); + static void construct(Variant::Type, Variant &base, const Variant **p_args, int p_argcount, Callable::CallError &r_error); + + static void get_constructor_list(Type p_type, List<MethodInfo> *r_list); //convenience + + /* Properties */ void set_named(const StringName &p_member, const Variant &p_value, bool &r_valid); Variant get_named(const StringName &p_member, bool &r_valid) const; @@ -496,6 +549,8 @@ public: static PTRSetter get_member_ptr_setter(Variant::Type p_type, const StringName &p_member); static PTRGetter get_member_ptr_getter(Variant::Type p_type, const StringName &p_member); + /* Indexing */ + static bool has_indexing(Variant::Type p_type); static Variant::Type get_indexed_element_type(Variant::Type p_type); @@ -516,6 +571,8 @@ public: uint64_t get_indexed_size() const; + /* Keying */ + static bool is_keyed(Variant::Type p_type); typedef void (*ValidatedKeyedSetter)(Variant *base, const Variant *key, const Variant *value, bool &valid); @@ -538,6 +595,8 @@ public: Variant get_keyed(const Variant &p_key, bool &r_valid) const; bool has_key(const Variant &p_key, bool &r_valid) const; + /* Generic */ + void set(const Variant &p_index, const Variant &p_value, bool *r_valid = nullptr); Variant get(const Variant &p_index, bool *r_valid = nullptr) const; bool in(const Variant &p_index, bool *r_valid = nullptr) const; @@ -548,6 +607,32 @@ public: void get_property_list(List<PropertyInfo> *p_list) const; + static void call_utility_function(const StringName &p_name, Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error); + static bool has_utility_function(const StringName &p_name); + + typedef void (*ValidatedUtilityFunction)(Variant *r_ret, const Variant **p_args, int p_argcount); + typedef void (*PTRUtilityFunction)(void *r_ret, const void **p_args, int p_argcount); + + static ValidatedUtilityFunction get_validated_utility_function(const StringName &p_name); + static PTRUtilityFunction get_ptr_utility_function(const StringName &p_name); + + enum UtilityFunctionType { + UTILITY_FUNC_TYPE_MATH, + UTILITY_FUNC_TYPE_RANDOM, + UTILITY_FUNC_TYPE_GENERAL, + }; + + static UtilityFunctionType get_utility_function_type(const StringName &p_name); + + static int get_utility_function_argument_count(const StringName &p_name); + static Variant::Type get_utility_function_argument_type(const StringName &p_name, int p_arg); + static String get_utility_function_argument_name(const StringName &p_name, int p_arg); + static bool has_utility_function_return_value(const StringName &p_name); + static Variant::Type get_utility_function_return_type(const StringName &p_name); + static bool is_utility_function_vararg(const StringName &p_name); + + static void get_utility_function_list(List<StringName> *r_functions); + //argsVariant call() bool operator==(const Variant &p_variant) const; @@ -560,7 +645,6 @@ public: String stringify(List<const void *> &stack) const; void static_assign(const Variant &p_variant); - static void get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list); static void get_constants_for_type(Variant::Type p_type, List<StringName> *p_constants); static bool has_constant(Variant::Type p_type, const StringName &p_value); static Variant get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid = nullptr); @@ -573,12 +657,13 @@ public: void operator=(const Variant &p_variant); // only this is enough for all the other types + static void register_types(); + static void unregister_types(); + Variant(const Variant &p_variant); _FORCE_INLINE_ Variant() {} _FORCE_INLINE_ ~Variant() { - if (type != Variant::NIL) { - clear(); - } + clear(); } }; diff --git a/core/variant_call.cpp b/core/variant/variant_call.cpp index d2b626a942..4cb8457ccd 100644 --- a/core/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -30,528 +30,363 @@ #include "variant.h" -#include "core/class_db.h" -#include "core/color_names.inc" #include "core/core_string_names.h" #include "core/crypto/crypto_core.h" #include "core/debugger/engine_debugger.h" #include "core/io/compression.h" -#include "core/oa_hash_map.h" +#include "core/object/class_db.h" #include "core/os/os.h" - -_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr) { -} - -_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str) { - arr.push_back(p_str); -} - -template <class... P> -_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str, P... p_args) { - arr.push_back(p_str); - sarray_add_str(arr, p_args...); -} - -template <class... P> -_FORCE_INLINE_ Vector<String> sarray(P... p_args) { - Vector<String> arr; - sarray_add_str(arr, p_args...); - return arr; -} +#include "core/templates/local_vector.h" +#include "core/templates/oa_hash_map.h" typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args); typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args); -struct _VariantCall { - template <class T, class... P> - class InternalMethod : public Variant::InternalMethod { - public: - void (T::*method)(P...); - Vector<Variant> default_values; -#ifdef DEBUG_ENABLED - Vector<String> argument_names; -#endif - - virtual int get_argument_count() const { - return sizeof...(P); - } - virtual Variant::Type get_argument_type(int p_arg) const { - return call_get_argument_type<P...>(p_arg); - } -#ifdef DEBUG_ENABLED - virtual String get_argument_name(int p_arg) const { - ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); - return argument_names[p_arg]; - } -#endif - virtual Vector<Variant> get_default_arguments() const { - return default_values; - } - - virtual Variant::Type get_return_type() const { - return Variant::NIL; - } - virtual uint32_t get_flags() const { - return 0; - } - - virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { - call_with_variant_args_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, default_values); - } - - virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { - call_with_validated_variant_args(base, method, p_args); - } +template <class T> +struct TypeAdjust { + _FORCE_INLINE_ static void adjust(Variant *r_ret) { + VariantTypeChanger<typename GetSimpleTypeT<T>::type_t>::change(r_ret); + } +}; -#ifdef PTRCALL_ENABLED - virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { - call_with_ptr_args<T, P...>(reinterpret_cast<T *>(p_base), method, p_args); - } -#endif - InternalMethod(void (T::*p_method)(P...), const Vector<Variant> &p_default_args -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type -#endif - ) { - method = p_method; - default_values = p_default_args; -#ifdef DEBUG_ENABLED - argument_names = p_arg_names; - method_name = p_method_name; - base_type = p_base_type; -#endif - } - }; +template <> //do nothing for variant +struct TypeAdjust<Variant> { + _FORCE_INLINE_ static void adjust(Variant *r_ret) { + } +}; - template <class T, class R, class... P> - class InternalMethodR : public Variant::InternalMethod { - public: - R(T::*method) - (P...); - Vector<Variant> default_values; -#ifdef DEBUG_ENABLED - Vector<String> argument_names; -#endif +template <> //do nothing for variant +struct TypeAdjust<Object *> { + _FORCE_INLINE_ static void adjust(Variant *r_ret) { + VariantInternal::clear(r_ret); + *r_ret = (Object *)nullptr; + } +}; - virtual int get_argument_count() const { - return sizeof...(P); - } - virtual Variant::Type get_argument_type(int p_arg) const { - return call_get_argument_type<P...>(p_arg); - return Variant::NIL; - } -#ifdef DEBUG_ENABLED - virtual String get_argument_name(int p_arg) const { - ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); - return argument_names[p_arg]; - } -#endif - virtual Vector<Variant> get_default_arguments() const { - return default_values; - } +template <class R, class T, class... P> +static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals); +} - virtual Variant::Type get_return_type() const { - return GetTypeInfo<R>::VARIANT_TYPE; - } - virtual uint32_t get_flags() const { - uint32_t f = 0; - if (get_return_type() == Variant::NIL) { - f |= FLAG_RETURNS_VARIANT; - } - return f; - } +template <class R, class T, class... P> +static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + call_with_variant_args_retc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals); +} - virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { - call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, default_values); - } +template <class T, class... P> +static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + call_with_variant_args_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals); +} - virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { - call_with_validated_variant_args_ret(base, method, p_args, r_ret); - } -#ifdef PTRCALL_ENABLED - virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { - call_with_ptr_args_ret<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret); - } -#endif - InternalMethodR(R (T::*p_method)(P...), const Vector<Variant> &p_default_args -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type -#endif - ) { - method = p_method; - default_values = p_default_args; -#ifdef DEBUG_ENABLED - argument_names = p_arg_names; - method_name = p_method_name; - base_type = p_base_type; -#endif - } - }; +template <class T, class... P> +static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + call_with_variant_argsc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals); +} - template <class T, class R, class... P> - class InternalMethodRC : public Variant::InternalMethod { - public: - R(T::*method) - (P...) const; - Vector<Variant> default_values; -#ifdef DEBUG_ENABLED - Vector<String> argument_names; -#endif +template <class R, class T, class... P> +static _FORCE_INLINE_ void vc_validated_call(R (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_ret(base, method, p_args, r_ret); +} - virtual int get_argument_count() const { - return sizeof...(P); - } - virtual Variant::Type get_argument_type(int p_arg) const { - return call_get_argument_type<P...>(p_arg); - } -#ifdef DEBUG_ENABLED - virtual String get_argument_name(int p_arg) const { - ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); - return argument_names[p_arg]; - } -#endif - virtual Vector<Variant> get_default_arguments() const { - return default_values; - } +template <class R, class T, class... P> +static _FORCE_INLINE_ void vc_validated_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_retc(base, method, p_args, r_ret); +} +template <class T, class... P> +static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args(base, method, p_args); +} - virtual Variant::Type get_return_type() const { - return GetTypeInfo<R>::VARIANT_TYPE; - } - virtual uint32_t get_flags() const { - uint32_t f = FLAG_IS_CONST; - if (get_return_type() == Variant::NIL) { - f |= FLAG_RETURNS_VARIANT; - } - return f; - } +template <class T, class... P> +static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_argsc(base, method, p_args); +} - virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { - call_with_variant_args_retc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, default_values); - } +template <class R, class T, class... P> +static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args_ret(reinterpret_cast<T *>(p_base), method, p_args, r_ret); +} - virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { - call_with_validated_variant_args_retc(base, method, p_args, r_ret); - } -#ifdef PTRCALL_ENABLED - virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { - call_with_ptr_args_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret); - } -#endif - InternalMethodRC(R (T::*p_method)(P...) const, const Vector<Variant> &p_default_args -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type -#endif - ) { - method = p_method; - default_values = p_default_args; -#ifdef DEBUG_ENABLED - argument_names = p_arg_names; - method_name = p_method_name; - base_type = p_base_type; -#endif - } - }; +template <class R, class T, class... P> +static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args_retc(reinterpret_cast<T *>(p_base), method, p_args, r_ret); +} - template <class T, class R, class... P> - class InternalMethodRS : public Variant::InternalMethod { - public: - R(*method) - (T *, P...); - Vector<Variant> default_values; -#ifdef DEBUG_ENABLED - Vector<String> argument_names; -#endif +template <class T, class... P> +static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args(reinterpret_cast<T *>(p_base), method, p_args); +} - virtual int get_argument_count() const { - return sizeof...(P); - } - virtual Variant::Type get_argument_type(int p_arg) const { - return call_get_argument_type<P...>(p_arg); - } -#ifdef DEBUG_ENABLED - virtual String get_argument_name(int p_arg) const { - ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); - return argument_names[p_arg]; - } -#endif - virtual Vector<Variant> get_default_arguments() const { - return default_values; - } +template <class T, class... P> +static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_argsc(reinterpret_cast<T *>(p_base), method, p_args); +} - virtual Variant::Type get_return_type() const { - return GetTypeInfo<R>::VARIANT_TYPE; - } - virtual uint32_t get_flags() const { - uint32_t f = 0; - if (get_return_type() == Variant::NIL) { - f |= FLAG_RETURNS_VARIANT; - } - return f; - } +template <class R, class T, class... P> +static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...)) { + return sizeof...(P); +} +template <class R, class T, class... P> +static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...) const) { + return sizeof...(P); +} - virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { - const Variant **args = p_args; -#ifdef DEBUG_ENABLED - if ((size_t)p_argcount > sizeof...(P)) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); - return; - } -#endif - if ((size_t)p_argcount < sizeof...(P)) { - size_t missing = sizeof...(P) - (size_t)p_argcount; - if (missing <= (size_t)default_values.size()) { - args = (const Variant **)alloca(sizeof...(P) * sizeof(const Variant *)); - // GCC fails to see that `sizeof...(P)` cannot be 0 here given the previous - // conditions, so it raises a warning on the potential use of `i < 0` as the - // execution condition. -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wtype-limits" -#endif - for (size_t i = 0; i < sizeof...(P); i++) { - if (i < (size_t)p_argcount) { - args[i] = p_args[i]; - } else { - args[i] = &default_values[i - p_argcount + (default_values.size() - missing)]; - } - } -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif - } else { -#ifdef DEBUG_ENABLED - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); -#endif - return; - } - } - call_with_variant_args_retc_static_helper(VariantGetInternalPtr<T>::get_ptr(base), method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); - } +template <class T, class... P> +static _FORCE_INLINE_ int vc_get_argument_count(void (T::*method)(P...)) { + return sizeof...(P); +} - virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { - call_with_validated_variant_args_static_retc(base, method, p_args, r_ret); - } -#ifdef PTRCALL_ENABLED - virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { - call_with_ptr_args_static_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret); - } -#endif - InternalMethodRS(R (*p_method)(T *, P...), const Vector<Variant> &p_default_args -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type -#endif - ) { - method = p_method; - default_values = p_default_args; -#ifdef DEBUG_ENABLED - argument_names = p_arg_names; - method_name = p_method_name; - base_type = p_base_type; -#endif - } - }; +template <class T, class... P> +static _FORCE_INLINE_ int vc_get_argument_count(void (T::*method)(P...) const) { + return sizeof...(P); +} - class InternalMethodVC : public Variant::InternalMethod { - public: - typedef void (*MethodVC)(Variant *, const Variant **, int, Variant &r_ret, Callable::CallError &); - MethodVC methodvc = nullptr; - uint32_t base_flags = 0; - Vector<String> argument_names; - Vector<Variant::Type> argument_types; - Variant::Type return_type = Variant::NIL; - - virtual int get_argument_count() const { - return argument_names.size(); - } - virtual Variant::Type get_argument_type(int p_arg) const { - ERR_FAIL_INDEX_V(p_arg, argument_types.size(), Variant::NIL); - return argument_types[p_arg]; - } -#ifdef DEBUG_ENABLED - virtual String get_argument_name(int p_arg) const { - ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); - return argument_names[p_arg]; - } -#endif - virtual Vector<Variant> get_default_arguments() const { - return Vector<Variant>(); - } +template <class R, class T, class... P> +static _FORCE_INLINE_ int vc_get_argument_count(R (*method)(T *, P...)) { + return sizeof...(P); +} - virtual Variant::Type get_return_type() const { - return return_type; - } - virtual uint32_t get_flags() const { - return base_flags | FLAG_NO_PTRCALL; - } +template <class R, class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (T::*method)(P...), int p_arg) { + return call_get_argument_type<P...>(p_arg); +} +template <class R, class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (T::*method)(P...) const, int p_arg) { + return call_get_argument_type<P...>(p_arg); +} - virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { - methodvc(base, p_args, p_argcount, r_ret, r_error); - } +template <class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_argument_type(void (T::*method)(P...), int p_arg) { + return call_get_argument_type<P...>(p_arg); +} - virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { - ERR_FAIL_MSG("No support for validated call"); - } -#ifdef PTRCALL_ENABLED - virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { - ERR_FAIL_MSG("No support for ptrcall call"); - } -#endif - InternalMethodVC(MethodVC p_method, uint32_t p_flags, const Vector<Variant::Type> &p_argument_types, const Variant::Type &p_return_type -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type -#endif - ) { - methodvc = p_method; - argument_types = p_argument_types; - return_type = p_return_type; - base_flags = p_flags; -#ifdef DEBUG_ENABLED - argument_names = p_arg_names; - method_name = p_method_name; - base_type = p_base_type; -#endif - } - }; +template <class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_argument_type(void (T::*method)(P...) const, int p_arg) { + return call_get_argument_type<P...>(p_arg); +} - typedef OAHashMap<StringName, Variant::InternalMethod *> MethodMap; - static MethodMap *type_internal_methods; - static List<StringName> *type_internal_method_names; +template <class R, class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (*method)(T *, P...), int p_arg) { + return call_get_argument_type<P...>(p_arg); +} - template <class T, class... P> - static void _bind_method(const StringName &p_name, void (T::*p_method)(P...), const Vector<Variant> &p_default_args = Vector<Variant>() -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_argument_names = Vector<String>() -#endif - ) { +template <class R, class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (T::*method)(P...)) { + return GetTypeInfo<R>::VARIANT_TYPE; +} -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); - ERR_FAIL_COND(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name)); -#endif -#ifdef DEBUG_ENABLED - Variant::InternalMethod *m = memnew((InternalMethod<T, P...>)(p_method, p_default_args, p_argument_names, p_name, GetTypeInfo<T>::VARIANT_TYPE)); -#else - Variant::InternalMethod *m = memnew((InternalMethod<T, P...>)(p_method, p_default_args)); -#endif +template <class R, class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (T::*method)(P...) const) { + return GetTypeInfo<R>::VARIANT_TYPE; +} - type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m); - type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name); - } +template <class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (T::*method)(P...)) { + return Variant::NIL; +} - template <class T, class R, class... P> - static void _bind_method(const StringName &p_name, R (T::*p_method)(P...) const, const Vector<Variant> &p_default_args = Vector<Variant>() -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_argument_names = Vector<String>() -#endif - ) { -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); - ERR_FAIL_COND_MSG(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name), " Method already registered: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); +template <class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (T::*method)(P...) const) { + return Variant::NIL; +} -#endif -#ifdef DEBUG_ENABLED - Variant::InternalMethod *m = memnew((InternalMethodRC<T, R, P...>)(p_method, p_default_args, p_argument_names, p_name, GetTypeInfo<T>::VARIANT_TYPE)); -#else - Variant::InternalMethod *m = memnew((InternalMethodRC<T, R, P...>)(p_method, p_default_args)); -#endif +template <class R, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (*method)(P...)) { + return GetTypeInfo<R>::VARIANT_TYPE; +} - type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m); - type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name); - } +template <class R, class T, class... P> +static _FORCE_INLINE_ bool vc_has_return_type(R (T::*method)(P...)) { + return true; +} +template <class R, class T, class... P> +static _FORCE_INLINE_ bool vc_has_return_type(R (T::*method)(P...) const) { + return true; +} - template <class T, class R, class... P> - static void _bind_method(const StringName &p_name, R (T::*p_method)(P...), const Vector<Variant> &p_default_args = Vector<Variant>() -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_argument_names = Vector<String>() -#endif - ) { -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); - ERR_FAIL_COND_MSG(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name), " Method already registered: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); -#endif +template <class T, class... P> +static _FORCE_INLINE_ bool vc_has_return_type(void (T::*method)(P...)) { + return false; +} -#ifdef DEBUG_ENABLED - Variant::InternalMethod *m = memnew((InternalMethodR<T, R, P...>)(p_method, p_default_args, p_argument_names, p_name, GetTypeInfo<T>::VARIANT_TYPE)); -#else - Variant::InternalMethod *m = memnew((InternalMethodR<T, R, P...>)(p_method, p_default_args)); -#endif - type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m); - type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name); - } +template <class T, class... P> +static _FORCE_INLINE_ bool vc_has_return_type(void (T::*method)(P...) const) { + return false; +} -#ifdef DEBUG_ENABLED -#define bind_method(m_type, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_method, &m_type ::m_method, m_default_args, m_arg_names) -#else -#define bind_method(m_type, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_method, &m_type ::m_method, m_default_args) -#endif +template <class R, class T, class... P> +static _FORCE_INLINE_ bool vc_is_const(R (T::*method)(P...)) { + return false; +} +template <class R, class T, class... P> +static _FORCE_INLINE_ bool vc_is_const(R (T::*method)(P...) const) { + return true; +} -#ifdef DEBUG_ENABLED -#define bind_methodv(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_name, m_method, m_default_args, m_arg_names) -#else -#define bind_methodv(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_name, m_method, m_default_args) -#endif +template <class T, class... P> +static _FORCE_INLINE_ bool vc_is_const(void (T::*method)(P...)) { + return false; +} - template <class T, class R, class... P> - static void _bind_function(const StringName &p_name, R (*p_method)(T *, P...), const Vector<Variant> &p_default_args = Vector<Variant>() -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_argument_names = Vector<String>() -#endif - ) { -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); - ERR_FAIL_COND_MSG(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name), " Method already registered: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); -#endif +template <class T, class... P> +static _FORCE_INLINE_ bool vc_is_const(void (T::*method)(P...) const) { + return true; +} -#ifdef DEBUG_ENABLED - Variant::InternalMethod *m = memnew((InternalMethodRS<T, R, P...>)(p_method, p_default_args, p_argument_names, p_name, GetTypeInfo<T>::VARIANT_TYPE)); -#else - Variant::InternalMethod *m = memnew((InternalMethodRS<T, R, P...>)(p_method, p_default_args)); -#endif +template <class R, class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_base_type(R (T::*method)(P...)) { + return GetTypeInfo<T>::VARIANT_TYPE; +} +template <class R, class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_base_type(R (T::*method)(P...) const) { + return GetTypeInfo<T>::VARIANT_TYPE; +} - type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m); - type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name); - } +template <class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...)) { + return GetTypeInfo<T>::VARIANT_TYPE; +} -#ifdef DEBUG_ENABLED -#define bind_function(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_function(m_name, m_method, m_default_args, m_arg_names) -#else -#define bind_function(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_function(m_name, m_method, m_default_args) -#endif +template <class T, class... P> +static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) const) { + return GetTypeInfo<T>::VARIANT_TYPE; +} - static void _bind_custom(Variant::Type p_type, const StringName &p_name, InternalMethodVC::MethodVC p_method, uint32_t p_flags, const Vector<Variant::Type> &p_argument_types, const Variant::Type &p_return_type -#ifdef DEBUG_ENABLED - , - const Vector<String> &p_argument_names = Vector<String>() -#endif - ) { +#define METHOD_CLASS(m_class, m_method_name, m_method_ptr) \ + struct Method_##m_class##_##m_method_name { \ + static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \ + vc_method_call(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \ + } \ + static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \ + TypeAdjust<m_class>::adjust(r_ret); \ + vc_validated_call(m_method_ptr, base, p_args, r_ret); \ + } \ + static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \ + vc_ptrcall(m_method_ptr, p_base, p_args, r_ret); \ + } \ + static int get_argument_count() { \ + return vc_get_argument_count(m_method_ptr); \ + } \ + static Variant::Type get_argument_type(int p_arg) { \ + return vc_get_argument_type(m_method_ptr, p_arg); \ + } \ + static Variant::Type get_return_type() { \ + return vc_get_return_type(m_method_ptr); \ + } \ + static bool has_return_type() { \ + return vc_has_return_type(m_method_ptr); \ + } \ + static bool is_const() { \ + return vc_is_const(m_method_ptr); \ + } \ + static bool is_vararg() { \ + return false; \ + } \ + static Variant::Type get_base_type() { \ + return vc_get_base_type(m_method_ptr); \ + } \ + static StringName get_name() { \ + return #m_method_name; \ + } \ + }; -#ifdef DEBUG_ENABLED - Variant::InternalMethod *m = memnew(InternalMethodVC(p_method, p_flags, p_argument_types, p_return_type, p_argument_names, p_name, p_type)); -#else - Variant::InternalMethod *m = memnew(InternalMethodVC(p_method, p_flags, p_argument_types, p_return_type)); -#endif +template <class R, class T, class... P> +static _FORCE_INLINE_ void vc_ptrcall(R (*method)(T *, P...), void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args_static_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret); +} - type_internal_methods[p_type].insert(p_name, m); - type_internal_method_names[p_type].push_back(p_name); - } +#define FUNCTION_CLASS(m_class, m_method_name, m_method_ptr) \ + struct Method_##m_class##_##m_method_name { \ + static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \ + call_with_variant_args_retc_static_helper_dv(VariantGetInternalPtr<m_class>::get_ptr(base), m_method_ptr, p_args, p_argcount, r_ret, p_defvals, r_error); \ + } \ + static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \ + TypeAdjust<m_class>::adjust(r_ret); \ + call_with_validated_variant_args_static_retc(base, m_method_ptr, p_args, r_ret); \ + } \ + static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \ + vc_ptrcall(m_method_ptr, p_base, p_args, r_ret); \ + } \ + static int get_argument_count() { \ + return vc_get_argument_count(m_method_ptr); \ + } \ + static Variant::Type get_argument_type(int p_arg) { \ + return vc_get_argument_type(m_method_ptr, p_arg); \ + } \ + static Variant::Type get_return_type() { \ + return vc_get_return_type(m_method_ptr); \ + } \ + static bool has_return_type() { \ + return true; \ + } \ + static bool is_const() { \ + return true; \ + } \ + static bool is_vararg() { \ + return false; \ + } \ + static Variant::Type get_base_type() { \ + return GetTypeInfo<m_class>::VARIANT_TYPE; \ + } \ + static StringName get_name() { \ + return #m_method_name; \ + } \ + }; -#ifdef DEBUG_ENABLED -#define bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names) _VariantCall::_bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names) -#else -#define bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names) _VariantCall::_bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type) -#endif +#define VARARG_CLASS(m_class, m_method_name, m_method_ptr, m_has_return, m_return_type) \ + struct Method_##m_class##_##m_method_name { \ + static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \ + m_method_ptr(base, p_args, p_argcount, r_ret, r_error); \ + } \ + static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \ + Callable::CallError ce; \ + m_method_ptr(base, p_args, p_argcount, *r_ret, ce); \ + } \ + static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \ + LocalVector<Variant> vars; \ + vars.resize(p_argcount); \ + LocalVector<const Variant *> vars_ptrs; \ + vars_ptrs.resize(p_argcount); \ + for (int i = 0; i < p_argcount; i++) { \ + vars[i] = PtrToArg<Variant>::convert(p_args[i]); \ + vars_ptrs[i] = &vars[i]; \ + } \ + Variant base = PtrToArg<m_class>::convert(p_base); \ + Variant ret; \ + Callable::CallError ce; \ + m_method_ptr(&base, (const Variant **)&vars_ptrs[0], p_argcount, ret, ce); \ + if (m_has_return) { \ + m_return_type r = ret; \ + PtrToArg<m_return_type>::encode(ret, r_ret); \ + } \ + } \ + static int get_argument_count() { \ + return 0; \ + } \ + static Variant::Type get_argument_type(int p_arg) { \ + return Variant::NIL; \ + } \ + static Variant::Type get_return_type() { \ + return GetTypeInfo<m_return_type>::VARIANT_TYPE; \ + } \ + static bool has_return_type() { \ + return m_has_return; \ + } \ + static bool is_const() { \ + return true; \ + } \ + static bool is_vararg() { \ + return true; \ + } \ + static Variant::Type get_base_type() { \ + return GetTypeInfo<m_class>::VARIANT_TYPE; \ + } \ + static StringName get_name() { \ + return #m_method_name; \ + } \ + }; +struct _VariantCall { static String func_PackedByteArray_get_string_from_ascii(PackedByteArray *p_instance) { String s; if (p_instance->size() > 0) { @@ -671,190 +506,6 @@ struct _VariantCall { signal->emit(p_args, p_argcount); } - struct ConstructData { - int arg_count; - Vector<Variant::Type> arg_types; - Vector<String> arg_names; - VariantConstructFunc func; - }; - - struct ConstructFunc { - List<ConstructData> constructors; - }; - - static ConstructFunc *construct_funcs; - - static void Vector2_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Vector2(*p_args[0], *p_args[1]); - } - - static void Vector2i_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Vector2i(*p_args[0], *p_args[1]); - } - - static void Rect2_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Rect2(*p_args[0], *p_args[1]); - } - - static void Rect2_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Rect2(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); - } - - static void Rect2i_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Rect2i(*p_args[0], *p_args[1]); - } - - static void Rect2i_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Rect2i(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); - } - - static void Transform2D_init2(Variant &r_ret, const Variant **p_args) { - Transform2D m(*p_args[0], *p_args[1]); - r_ret = m; - } - - static void Transform2D_init3(Variant &r_ret, const Variant **p_args) { - Transform2D m; - m[0] = *p_args[0]; - m[1] = *p_args[1]; - m[2] = *p_args[2]; - r_ret = m; - } - - static void Vector3_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Vector3(*p_args[0], *p_args[1], *p_args[2]); - } - - static void Vector3i_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Vector3i(*p_args[0], *p_args[1], *p_args[2]); - } - - static void Plane_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Plane(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); - } - - static void Plane_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Plane(*p_args[0], *p_args[1], *p_args[2]); - } - - static void Plane_init3(Variant &r_ret, const Variant **p_args) { - r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator real_t()); - } - static void Plane_init4(Variant &r_ret, const Variant **p_args) { - r_ret = Plane(p_args[0]->operator Vector3(), p_args[1]->operator Vector3()); - } - - static void Quat_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Quat(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); - } - - static void Quat_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Quat(((Vector3)(*p_args[0])), ((real_t)(*p_args[1]))); - } - - static void Quat_init3(Variant &r_ret, const Variant **p_args) { - r_ret = Quat(((Vector3)(*p_args[0]))); - } - - static void Color_init1(Variant &r_ret, const Variant **p_args) { - r_ret = Color(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); - } - - static void Color_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Color(*p_args[0], *p_args[1], *p_args[2]); - } - - static void Color_init3(Variant &r_ret, const Variant **p_args) { - r_ret = Color::html(*p_args[0]); - } - - static void Color_init4(Variant &r_ret, const Variant **p_args) { - r_ret = Color::hex(*p_args[0]); - } - - static void Color_init5(Variant &r_ret, const Variant **p_args) { - r_ret = Color(((Color)(*p_args[0])), *p_args[1]); - } - - static void AABB_init1(Variant &r_ret, const Variant **p_args) { - r_ret = ::AABB(*p_args[0], *p_args[1]); - } - - static void Basis_init1(Variant &r_ret, const Variant **p_args) { - Basis m; - m.set_axis(0, *p_args[0]); - m.set_axis(1, *p_args[1]); - m.set_axis(2, *p_args[2]); - r_ret = m; - } - - static void Basis_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Basis(p_args[0]->operator Vector3(), p_args[1]->operator real_t()); - } - - static void Transform_init1(Variant &r_ret, const Variant **p_args) { - Transform t; - t.basis.set_axis(0, *p_args[0]); - t.basis.set_axis(1, *p_args[1]); - t.basis.set_axis(2, *p_args[2]); - t.origin = *p_args[3]; - r_ret = t; - } - - static void Transform_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Transform(p_args[0]->operator Basis(), p_args[1]->operator Vector3()); - } - - static void Callable_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Callable(p_args[0]->operator ObjectID(), p_args[1]->operator String()); - } - - static void Signal_init2(Variant &r_ret, const Variant **p_args) { - r_ret = Signal(p_args[0]->operator ObjectID(), p_args[1]->operator String()); - } - - static void add_constructor(VariantConstructFunc p_func, const Variant::Type p_type, - const String &p_name1 = "", const Variant::Type p_type1 = Variant::NIL, - const String &p_name2 = "", const Variant::Type p_type2 = Variant::NIL, - const String &p_name3 = "", const Variant::Type p_type3 = Variant::NIL, - const String &p_name4 = "", const Variant::Type p_type4 = Variant::NIL) { - ConstructData cd; - cd.func = p_func; - cd.arg_count = 0; - - if (p_name1 == "") { - goto end; - } - cd.arg_count++; - cd.arg_names.push_back(p_name1); - cd.arg_types.push_back(p_type1); - - if (p_name2 == "") { - goto end; - } - cd.arg_count++; - cd.arg_names.push_back(p_name2); - cd.arg_types.push_back(p_type2); - - if (p_name3 == "") { - goto end; - } - cd.arg_count++; - cd.arg_names.push_back(p_name3); - cd.arg_types.push_back(p_type3); - - if (p_name4 == "") { - goto end; - } - cd.arg_count++; - cd.arg_names.push_back(p_name4); - cd.arg_types.push_back(p_type4); - - end: - - construct_funcs[p_type].constructors.push_back(cd); - } - struct ConstantData { Map<StringName, int> value; #ifdef DEBUG_ENABLED @@ -883,20 +534,62 @@ struct _VariantCall { } }; -_VariantCall::ConstructFunc *_VariantCall::construct_funcs = nullptr; _VariantCall::ConstantData *_VariantCall::constant_data = nullptr; -_VariantCall::MethodMap *_VariantCall::type_internal_methods = nullptr; -List<StringName> *_VariantCall::type_internal_method_names = nullptr; -Variant Variant::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - Variant ret; - call_ptr(p_method, p_args, p_argcount, &ret, r_error); - return ret; -} +struct VariantBuiltInMethodInfo { + void (*call)(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error); + Variant::ValidatedBuiltInMethod validated_call; + Variant::PTRBuiltInMethod ptrcall; + + Vector<Variant> default_arguments; + Vector<String> argument_names; + + bool is_const; + bool has_return_type; + bool is_vararg; + Variant::Type return_type; + int argument_count; + Variant::Type (*get_argument_type)(int p_arg); +}; + +typedef OAHashMap<StringName, VariantBuiltInMethodInfo> BuiltinMethodMap; +static BuiltinMethodMap *builtin_method_info; +static List<StringName> *builtin_method_names; + +template <class T> +static void register_builtin_method(const Vector<String> &p_argnames, const Vector<Variant> &p_def_args) { + StringName name = T::get_name(); + + ERR_FAIL_COND(builtin_method_info[T::get_base_type()].has(name)); + + VariantBuiltInMethodInfo imi; + + imi.call = T::call; + imi.validated_call = T::validated_call; + if (T::is_vararg()) { + imi.ptrcall = nullptr; + } else { + imi.ptrcall = T::ptrcall; + } -void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p_argcount, Variant *r_ret, Callable::CallError &r_error) { - Variant ret; + imi.default_arguments = p_def_args; + imi.argument_names = p_argnames; + imi.is_const = T::is_const(); + imi.is_vararg = T::is_vararg(); + imi.has_return_type = T::has_return_type(); + imi.return_type = T::get_return_type(); + imi.argument_count = T::get_argument_count(); + imi.get_argument_type = T::get_argument_type; +#ifdef DEBUG_METHODS_ENABLED + ERR_FAIL_COND(!imi.is_vararg && imi.argument_count != imi.argument_names.size()); +#endif + + builtin_method_info[T::get_base_type()].insert(name, imi); + builtin_method_names[T::get_base_type()].push_back(name); +} + +void Variant::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { if (type == Variant::OBJECT) { //call object Object *obj = _get_obj().obj; @@ -911,236 +604,22 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p } #endif - ret = _get_obj().obj->call(p_method, p_args, p_argcount, r_error); + r_ret = _get_obj().obj->call(p_method, p_args, p_argcount, r_error); //else if (type==Variant::METHOD) { } else { r_error.error = Callable::CallError::CALL_OK; - Variant::InternalMethod **m = _VariantCall::type_internal_methods[type].lookup_ptr(p_method); + const VariantBuiltInMethodInfo *imf = builtin_method_info[type].lookup_ptr(p_method); - if (m) { - (*m)->call((Variant *)this, p_args, p_argcount, ret, r_error); - } else { - //ok fail because not found + if (!imf) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; return; } - } - - if (r_error.error == Callable::CallError::CALL_OK && r_ret) { - *r_ret = ret; - } -} - -#define VCALL(m_type, m_method) _VariantCall::_call_##m_type##_##m_method - -Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, int p_argcount, Callable::CallError &r_error, bool p_strict) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; - ERR_FAIL_INDEX_V(p_type, VARIANT_MAX, Variant()); - - r_error.error = Callable::CallError::CALL_OK; - if (p_argcount == 0) { //generic construct - - switch (p_type) { - case NIL: - return Variant(); - - // atomic types - case BOOL: - return Variant(false); - case INT: - return 0; - case FLOAT: - return 0.0f; - case STRING: - return String(); - - // math types - case VECTOR2: - return Vector2(); - case VECTOR2I: - return Vector2i(); - case RECT2: - return Rect2(); - case RECT2I: - return Rect2i(); - case VECTOR3: - return Vector3(); - case VECTOR3I: - return Vector3i(); - case TRANSFORM2D: - return Transform2D(); - case PLANE: - return Plane(); - case QUAT: - return Quat(); - case AABB: - return ::AABB(); - case BASIS: - return Basis(); - case TRANSFORM: - return Transform(); - - // misc types - case COLOR: - return Color(); - case STRING_NAME: - return StringName(); - case NODE_PATH: - return NodePath(); - case _RID: - return RID(); - case OBJECT: - return (Object *)nullptr; - case CALLABLE: - return Callable(); - case SIGNAL: - return Signal(); - case DICTIONARY: - return Dictionary(); - case ARRAY: - return Array(); - case PACKED_BYTE_ARRAY: - return PackedByteArray(); - case PACKED_INT32_ARRAY: - return PackedInt32Array(); - case PACKED_INT64_ARRAY: - return PackedInt64Array(); - case PACKED_FLOAT32_ARRAY: - return PackedFloat32Array(); - case PACKED_FLOAT64_ARRAY: - return PackedFloat64Array(); - case PACKED_STRING_ARRAY: - return PackedStringArray(); - case PACKED_VECTOR2_ARRAY: - return PackedVector2Array(); - case PACKED_VECTOR3_ARRAY: - return PackedVector3Array(); - case PACKED_COLOR_ARRAY: - return PackedColorArray(); - default: - return Variant(); - } - - } else if (p_argcount == 1 && p_args[0]->type == p_type) { - return *p_args[0]; //copy construct - } else if (p_argcount == 1 && (!p_strict || Variant::can_convert(p_args[0]->type, p_type))) { - //near match construct - - switch (p_type) { - case NIL: { - return Variant(); - } break; - case BOOL: { - return Variant(bool(*p_args[0])); - } - case INT: { - return (int64_t(*p_args[0])); - } - case FLOAT: { - return double(*p_args[0]); - } - case STRING: { - return String(*p_args[0]); - } - case VECTOR2: { - return Vector2(*p_args[0]); - } - case VECTOR2I: { - return Vector2i(*p_args[0]); - } - case RECT2: - return (Rect2(*p_args[0])); - case RECT2I: - return (Rect2i(*p_args[0])); - case VECTOR3: - return (Vector3(*p_args[0])); - case VECTOR3I: - return (Vector3i(*p_args[0])); - case TRANSFORM2D: - return (Transform2D(p_args[0]->operator Transform2D())); - case PLANE: - return (Plane(*p_args[0])); - case QUAT: - return (p_args[0]->operator Quat()); - case AABB: - return (::AABB(*p_args[0])); - case BASIS: - return (Basis(p_args[0]->operator Basis())); - case TRANSFORM: - return (Transform(p_args[0]->operator Transform())); - - // misc types - case COLOR: - return p_args[0]->type == Variant::STRING ? Color::html(*p_args[0]) : Color::hex(*p_args[0]); - case STRING_NAME: - return (StringName(p_args[0]->operator StringName())); - case NODE_PATH: - return (NodePath(p_args[0]->operator NodePath())); - case _RID: - return (RID(*p_args[0])); - case OBJECT: - return ((Object *)(p_args[0]->operator Object *())); - case CALLABLE: - return ((Callable)(p_args[0]->operator Callable())); - case SIGNAL: - return ((Signal)(p_args[0]->operator Signal())); - case DICTIONARY: - return p_args[0]->operator Dictionary(); - case ARRAY: - return p_args[0]->operator Array(); - - // arrays - case PACKED_BYTE_ARRAY: - return (PackedByteArray(*p_args[0])); - case PACKED_INT32_ARRAY: - return (PackedInt32Array(*p_args[0])); - case PACKED_INT64_ARRAY: - return (PackedInt64Array(*p_args[0])); - case PACKED_FLOAT32_ARRAY: - return (PackedFloat32Array(*p_args[0])); - case PACKED_FLOAT64_ARRAY: - return (PackedFloat64Array(*p_args[0])); - case PACKED_STRING_ARRAY: - return (PackedStringArray(*p_args[0])); - case PACKED_VECTOR2_ARRAY: - return (PackedVector2Array(*p_args[0])); - case PACKED_VECTOR3_ARRAY: - return (PackedVector3Array(*p_args[0])); - case PACKED_COLOR_ARRAY: - return (PackedColorArray(*p_args[0])); - default: - return Variant(); - } - } else if (p_argcount >= 1) { - _VariantCall::ConstructFunc &c = _VariantCall::construct_funcs[p_type]; - - for (List<_VariantCall::ConstructData>::Element *E = c.constructors.front(); E; E = E->next()) { - const _VariantCall::ConstructData &cd = E->get(); - if (cd.arg_count != p_argcount) { - continue; - } - - //validate parameters - for (int i = 0; i < cd.arg_count; i++) { - if (!Variant::can_convert(p_args[i]->type, cd.arg_types[i])) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; //no such constructor - r_error.argument = i; - r_error.expected = cd.arg_types[i]; - return Variant(); - } - } - - Variant v; - cd.func(v, p_args); - return v; - } + imf->call(this, p_args, p_argcount, r_ret, imf->default_arguments, r_error); } - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; //no such constructor - return Variant(); } bool Variant::has_method(const StringName &p_method) const { @@ -1153,134 +632,143 @@ bool Variant::has_method(const StringName &p_method) const { return obj->has_method(p_method); } - return _VariantCall::type_internal_methods[type].has(p_method); + return builtin_method_info[type].has(p_method); } -Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, const StringName &p_method) { - Vector<Variant::Type> types; +bool Variant::has_builtin_method(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); + return builtin_method_info[p_type].has(p_method); +} - Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); - if (*m) { - types.resize((*m)->get_argument_count()); - for (int i = 0; i < (*m)->get_argument_count(); i++) { - types.write[i] = (*m)->get_argument_type(i); - } - } +Variant::ValidatedBuiltInMethod Variant::get_validated_builtin_method(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, nullptr); + return method->validated_call; +} - return types; +Variant::PTRBuiltInMethod Variant::get_ptr_builtin_method(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, nullptr); + return method->ptrcall; } -bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) { - Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); - if (*m) { - return (*m)->get_flags() & Variant::InternalMethod::FLAG_IS_CONST; - } - return false; +int Variant::get_builtin_method_argument_count(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, 0); + return method->argument_count; } -Vector<StringName> Variant::get_method_argument_names(Variant::Type p_type, const StringName &p_method) { - Vector<StringName> argnames; +Variant::Type Variant::get_builtin_method_argument_type(Variant::Type p_type, const StringName &p_method, int p_argument) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::NIL); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, Variant::NIL); + ERR_FAIL_INDEX_V(p_argument, method->argument_count, Variant::NIL); + return method->get_argument_type(p_argument); +} -#ifdef DEBUG_ENABLED - Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); - if (*m) { - argnames.resize((*m)->get_argument_count()); - for (int i = 0; i < (*m)->get_argument_count(); i++) { - argnames.write[i] = (*m)->get_argument_name(i); - } - } +String Variant::get_builtin_method_argument_name(Variant::Type p_type, const StringName &p_method, int p_argument) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, String()); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, String()); +#ifdef DEBUG_METHODS_ENABLED + ERR_FAIL_INDEX_V(p_argument, method->argument_count, String()); + return method->argument_names[p_argument]; +#else + return "arg" + itos(p_argument + 1); #endif - return argnames; } -Variant::Type Variant::get_method_return_type(Variant::Type p_type, const StringName &p_method, bool *r_has_return) { - Variant::Type rt = Variant::NIL; - Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); - if (*m) { - rt = (*m)->get_return_type(); - if (r_has_return) { - *r_has_return = ((*m)->get_flags() & Variant::InternalMethod::FLAG_RETURNS_VARIANT) || rt != Variant::NIL; - } - } - return rt; +Vector<Variant> Variant::get_builtin_method_default_arguments(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Vector<Variant>()); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, Vector<Variant>()); + return method->default_arguments; } -Vector<Variant> Variant::get_method_default_arguments(Variant::Type p_type, const StringName &p_method) { - Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); - if (*m) { - return (*m)->get_default_arguments(); +bool Variant::has_builtin_method_return_value(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, false); + return method->has_return_type; +} + +void Variant::get_builtin_method_list(Variant::Type p_type, List<StringName> *p_list) { + ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX); + for (List<StringName>::Element *E = builtin_method_names[p_type].front(); E; E = E->next()) { + p_list->push_back(E->get()); } - return Vector<Variant>(); +} + +Variant::Type Variant::get_builtin_method_return_type(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::NIL); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, Variant::NIL); + return method->return_type; +} + +bool Variant::is_builtin_method_const(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, false); + return method->is_const; +} + +bool Variant::is_builtin_method_vararg(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); + const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(p_method); + ERR_FAIL_COND_V(!method, false); + return method->is_vararg; } void Variant::get_method_list(List<MethodInfo> *p_list) const { - for (List<StringName>::Element *E = _VariantCall::type_internal_method_names[type].front(); E; E = E->next()) { - Variant::InternalMethod **m = _VariantCall::type_internal_methods[type].lookup_ptr(E->get()); - ERR_CONTINUE(!*m); - - MethodInfo mi; - mi.name = E->get(); - mi.return_val.type = (*m)->get_return_type(); - if ((*m)->get_flags() & Variant::InternalMethod::FLAG_RETURNS_VARIANT) { - mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - } - if ((*m)->get_flags() & Variant::InternalMethod::FLAG_IS_CONST) { - mi.flags |= METHOD_FLAG_CONST; - } - if ((*m)->get_flags() & Variant::InternalMethod::FLAG_VARARGS) { - mi.flags |= METHOD_FLAG_VARARG; + if (type == OBJECT) { + Object *obj = get_validated_object(); + if (obj) { + obj->get_method_list(p_list); } + } else { + for (List<StringName>::Element *E = builtin_method_names[type].front(); E; E = E->next()) { + const VariantBuiltInMethodInfo *method = builtin_method_info[type].lookup_ptr(E->get()); + ERR_CONTINUE(!method); + + MethodInfo mi; + mi.name = E->get(); + + //return type + if (method->has_return_type) { + mi.return_val.type = method->return_type; + if (mi.return_val.type == Variant::NIL) { + mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + } + } - for (int i = 0; i < (*m)->get_argument_count(); i++) { - PropertyInfo arg; -#ifdef DEBUG_ENABLED - arg.name = (*m)->get_argument_name(i); + if (method->is_const) { + mi.flags |= METHOD_FLAG_CONST; + } + if (method->is_vararg) { + mi.flags |= METHOD_FLAG_VARARG; + } + + for (int i = 0; i < method->argument_count; i++) { + PropertyInfo pi; +#ifdef DEBUG_METHODS_ENABLED + pi.name = method->argument_names[i]; #else - arg.name = "arg" + itos(i + 1); + pi.name = "arg" + itos(i + 1); #endif - arg.type = (*m)->get_argument_type(i); - mi.arguments.push_back(arg); - } - - mi.default_arguments = (*m)->get_default_arguments(); - p_list->push_back(mi); - } -} + pi.type = method->get_argument_type(i); + if (pi.type == Variant::NIL) { + pi.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + } + mi.arguments.push_back(pi); + } -void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list) { - ERR_FAIL_INDEX(p_type, VARIANT_MAX); - - //custom constructors - for (const List<_VariantCall::ConstructData>::Element *E = _VariantCall::construct_funcs[p_type].constructors.front(); E; E = E->next()) { - const _VariantCall::ConstructData &cd = E->get(); - MethodInfo mi; - mi.name = Variant::get_type_name(p_type); - mi.return_val.type = p_type; - for (int i = 0; i < cd.arg_count; i++) { - PropertyInfo pi; - pi.name = cd.arg_names[i]; - pi.type = cd.arg_types[i]; - mi.arguments.push_back(pi); + mi.default_arguments = method->default_arguments; + p_list->push_back(mi); } - p_list->push_back(mi); - } - //default constructors - for (int i = 0; i < VARIANT_MAX; i++) { - if (i == p_type) { - continue; - } - if (!Variant::can_convert(Variant::Type(i), p_type)) { - continue; - } - - MethodInfo mi; - mi.name = Variant::get_type_name(p_type); - PropertyInfo pi; - pi.name = "from"; - pi.type = Variant::Type(i); - mi.arguments.push_back(pi); - mi.return_val.type = p_type; - p_list->push_back(mi); } } @@ -1341,21 +829,44 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va return E->get(); } -Variant::InternalMethod *Variant::get_internal_method(Type p_type, const StringName &p_method_name) { - ERR_FAIL_INDEX_V(p_type, VARIANT_MAX, nullptr); +#ifdef DEBUG_METHODS_ENABLED +#define bind_method(m_type, m_method, m_arg_names, m_default_args) \ + METHOD_CLASS(m_type, m_method, &m_type::m_method); \ + register_builtin_method<Method_##m_type##_##m_method>(m_arg_names, m_default_args); +#else +#define bind_method(m_type, m_method, m_arg_names, m_default_args) \ + METHOD_CLASS(m_type, m_method, &m_type ::m_method); \ + register_builtin_method<Method_##m_type##_##m_method>(sarray(), m_default_args); +#endif - Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method_name); - if (*m) { - return *m; - } - return nullptr; -} +#ifdef DEBUG_METHODS_ENABLED +#define bind_methodv(m_type, m_name, m_method, m_arg_names, m_default_args) \ + METHOD_CLASS(m_type, m_name, m_method); \ + register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args); +#else +#define bind_methodv(m_type, m_name, m_method, m_arg_names, m_default_args) \ + METHOD_CLASS(m_type, m_name, m_method); \ + register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args); +#endif -void register_variant_methods() { - _VariantCall::type_internal_methods = memnew_arr(_VariantCall::MethodMap, Variant::VARIANT_MAX); - _VariantCall::type_internal_method_names = memnew_arr(List<StringName>, Variant::VARIANT_MAX); - _VariantCall::construct_funcs = memnew_arr(_VariantCall::ConstructFunc, Variant::VARIANT_MAX); +#ifdef DEBUG_METHODS_ENABLED +#define bind_function(m_type, m_name, m_method, m_arg_names, m_default_args) \ + FUNCTION_CLASS(m_type, m_name, m_method); \ + register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args); +#else +#define bind_function(m_type, m_name, m_method, m_arg_names, m_default_args) \ + FUNCTION_CLASS(m_type, m_name, m_method); \ + register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args); +#endif + +#define bind_custom(m_type, m_name, m_method, m_has_return, m_ret_type) \ + VARARG_CLASS(m_type, m_name, m_method, m_has_return, m_ret_type) \ + register_builtin_method<Method_##m_type##_##m_name>(sarray(), Vector<Variant>()); + +static void _register_variant_builtin_methods() { _VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX); + builtin_method_info = memnew_arr(BuiltinMethodMap, Variant::VARIANT_MAX); + builtin_method_names = memnew_arr(List<StringName>, Variant::VARIANT_MAX); /* String */ @@ -1364,7 +875,7 @@ void register_variant_methods() { bind_method(String, naturalnocasecmp_to, sarray("to"), varray()); bind_method(String, length, sarray(), varray()); bind_method(String, substr, sarray("from", "len"), varray(-1)); - bind_methodv(find, static_cast<int (String::*)(const String &, int) const>(&String::find), sarray("what", "from"), varray(0)); + bind_methodv(String, find, static_cast<int (String::*)(const String &, int) const>(&String::find), sarray("what", "from"), varray(0)); bind_method(String, count, sarray("what", "from", "to"), varray(0, 0)); bind_method(String, countn, sarray("what", "from", "to"), varray(0, 0)); bind_method(String, findn, sarray("what", "from"), varray(0)); @@ -1372,7 +883,7 @@ void register_variant_methods() { bind_method(String, rfindn, sarray("what", "from"), varray(-1)); bind_method(String, match, sarray("expr"), varray()); bind_method(String, matchn, sarray("expr"), varray()); - bind_methodv(begins_with, static_cast<bool (String::*)(const String &) const>(&String::begins_with), sarray("text"), varray()); + bind_methodv(String, begins_with, static_cast<bool (String::*)(const String &) const>(&String::begins_with), sarray("text"), varray()); bind_method(String, ends_with, sarray("text"), varray()); bind_method(String, is_subsequence_of, sarray("text"), varray()); bind_method(String, is_subsequence_ofi, sarray("text"), varray()); @@ -1380,7 +891,7 @@ void register_variant_methods() { bind_method(String, similarity, sarray("text"), varray()); bind_method(String, format, sarray("values", "placeholder"), varray("{_}")); - bind_methodv(replace, static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray()); + bind_methodv(String, replace, static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray()); bind_method(String, replacen, sarray("what", "forwhat"), varray()); bind_method(String, repeat, sarray("count"), varray()); bind_method(String, insert, sarray("position", "what"), varray()); @@ -1511,7 +1022,7 @@ void register_variant_methods() { bind_method(Rect2, merge, sarray("b"), varray()); bind_method(Rect2, expand, sarray("to"), varray()); bind_method(Rect2, grow, sarray("by"), varray()); - bind_methodv(grow_margin, &Rect2::grow_margin_bind, sarray("margin", "by"), varray()); + bind_methodv(Rect2, grow_margin, &Rect2::grow_margin_bind, sarray("margin", "by"), varray()); bind_method(Rect2, grow_individual, sarray("left", "top", "right", "bottom"), varray()); bind_method(Rect2, abs, sarray(), varray()); @@ -1526,7 +1037,7 @@ void register_variant_methods() { bind_method(Rect2i, merge, sarray("b"), varray()); bind_method(Rect2i, expand, sarray("to"), varray()); bind_method(Rect2i, grow, sarray("by"), varray()); - bind_methodv(grow_margin, &Rect2i::grow_margin_bind, sarray("margin", "by"), varray()); + bind_methodv(Rect2i, grow_margin, &Rect2i::grow_margin_bind, sarray("margin", "by"), varray()); bind_method(Rect2i, grow_individual, sarray("left", "top", "right", "bottom"), varray()); bind_method(Rect2i, abs, sarray(), varray()); @@ -1582,9 +1093,9 @@ void register_variant_methods() { bind_method(Plane, distance_to, sarray("point"), varray()); bind_method(Plane, has_point, sarray("point", "epsilon"), varray(CMP_EPSILON)); bind_method(Plane, project, sarray("point"), varray()); - bind_methodv(intersect_3, &Plane::intersect_3_bind, sarray("b", "c"), varray()); - bind_methodv(intersects_ray, &Plane::intersects_ray_bind, sarray("from", "dir"), varray()); - bind_methodv(intersects_segment, &Plane::intersects_segment_bind, sarray("from", "to"), varray()); + bind_methodv(Plane, intersect_3, &Plane::intersect_3_bind, sarray("b", "c"), varray()); + bind_methodv(Plane, intersects_ray, &Plane::intersects_ray_bind, sarray("from", "dir"), varray()); + bind_methodv(Plane, intersects_segment, &Plane::intersects_segment_bind, sarray("from", "to"), varray()); /* Quat */ @@ -1650,9 +1161,9 @@ void register_variant_methods() { bind_method(Callable, hash, sarray(), varray()); bind_method(Callable, unbind, sarray("argcount"), varray()); - bind_custom(Variant::CALLABLE, "call", _VariantCall::func_Callable_call, Variant::InternalMethod::FLAG_VARARGS | Variant::InternalMethod::FLAG_RETURNS_VARIANT, Vector<Variant::Type>(), Variant::NIL, sarray()); - bind_custom(Variant::CALLABLE, "call_deferred", _VariantCall::func_Callable_call_deferred, Variant::InternalMethod::FLAG_VARARGS, Vector<Variant::Type>(), Variant::NIL, sarray()); - bind_custom(Variant::CALLABLE, "bind", _VariantCall::func_Callable_bind, Variant::InternalMethod::FLAG_VARARGS, Vector<Variant::Type>(), Variant::CALLABLE, sarray()); + bind_custom(Callable, call, _VariantCall::func_Callable_call, true, Variant); + bind_custom(Callable, call_deferred, _VariantCall::func_Callable_call_deferred, false, Variant); + bind_custom(Callable, bind, _VariantCall::func_Callable_bind, true, Callable); /* Signal */ @@ -1666,7 +1177,7 @@ void register_variant_methods() { bind_method(Signal, is_connected, sarray("callable"), varray()); bind_method(Signal, get_connections, sarray(), varray()); - bind_custom(Variant::SIGNAL, "emit", _VariantCall::func_Signal_emit, Variant::InternalMethod::FLAG_VARARGS, Vector<Variant::Type>(), Variant::NIL, sarray()); + bind_custom(Signal, emit, _VariantCall::func_Signal_emit, false, Variant); /* Transform2D */ @@ -1690,7 +1201,7 @@ void register_variant_methods() { bind_method(Basis, transposed, sarray(), varray()); bind_method(Basis, orthonormalized, sarray(), varray()); bind_method(Basis, determinant, sarray(), varray()); - bind_methodv(rotated, static_cast<Basis (Basis::*)(const Vector3 &, float) const>(&Basis::rotated), sarray("axis", "phi"), varray()); + bind_methodv(Basis, rotated, static_cast<Basis (Basis::*)(const Vector3 &, float) const>(&Basis::rotated), sarray("axis", "phi"), varray()); bind_method(Basis, scaled, sarray("scale"), varray()); bind_method(Basis, get_scale, sarray(), varray()); bind_method(Basis, get_euler, sarray(), varray()); @@ -1704,29 +1215,29 @@ void register_variant_methods() { /* AABB */ - bind_method(::AABB, abs, sarray(), varray()); - bind_method(::AABB, get_area, sarray(), varray()); - bind_method(::AABB, has_no_area, sarray(), varray()); - bind_method(::AABB, has_no_surface, sarray(), varray()); - bind_method(::AABB, has_point, sarray("point"), varray()); - bind_method(::AABB, is_equal_approx, sarray("aabb"), varray()); - bind_method(::AABB, intersects, sarray("with"), varray()); - bind_method(::AABB, encloses, sarray("with"), varray()); - bind_method(::AABB, intersects_plane, sarray("plane"), varray()); - bind_method(::AABB, intersection, sarray("with"), varray()); - bind_method(::AABB, merge, sarray("with"), varray()); - bind_method(::AABB, expand, sarray("to_point"), varray()); - bind_method(::AABB, grow, sarray("by"), varray()); - bind_method(::AABB, get_support, sarray("dir"), varray()); - bind_method(::AABB, get_longest_axis, sarray(), varray()); - bind_method(::AABB, get_longest_axis_index, sarray(), varray()); - bind_method(::AABB, get_longest_axis_size, sarray(), varray()); - bind_method(::AABB, get_shortest_axis, sarray(), varray()); - bind_method(::AABB, get_shortest_axis_index, sarray(), varray()); - bind_method(::AABB, get_shortest_axis_size, sarray(), varray()); - bind_method(::AABB, get_endpoint, sarray("idx"), varray()); - bind_methodv(intersects_segment, &AABB::intersects_segment_bind, sarray("from", "to"), varray()); - bind_methodv(intersects_ray, &AABB::intersects_ray_bind, sarray("from", "dir"), varray()); + bind_method(AABB, abs, sarray(), varray()); + bind_method(AABB, get_area, sarray(), varray()); + bind_method(AABB, has_no_area, sarray(), varray()); + bind_method(AABB, has_no_surface, sarray(), varray()); + bind_method(AABB, has_point, sarray("point"), varray()); + bind_method(AABB, is_equal_approx, sarray("aabb"), varray()); + bind_method(AABB, intersects, sarray("with"), varray()); + bind_method(AABB, encloses, sarray("with"), varray()); + bind_method(AABB, intersects_plane, sarray("plane"), varray()); + bind_method(AABB, intersection, sarray("with"), varray()); + bind_method(AABB, merge, sarray("with"), varray()); + bind_method(AABB, expand, sarray("to_point"), varray()); + bind_method(AABB, grow, sarray("by"), varray()); + bind_method(AABB, get_support, sarray("dir"), varray()); + bind_method(AABB, get_longest_axis, sarray(), varray()); + bind_method(AABB, get_longest_axis_index, sarray(), varray()); + bind_method(AABB, get_longest_axis_size, sarray(), varray()); + bind_method(AABB, get_shortest_axis, sarray(), varray()); + bind_method(AABB, get_shortest_axis_index, sarray(), varray()); + bind_method(AABB, get_shortest_axis_size, sarray(), varray()); + bind_method(AABB, get_endpoint, sarray("idx"), varray()); + bind_methodv(AABB, intersects_segment, &AABB::intersects_segment_bind, sarray("from", "to"), varray()); + bind_methodv(AABB, intersects_ray, &AABB::intersects_ray_bind, sarray("from", "dir"), varray()); /* Transform */ @@ -1763,6 +1274,7 @@ void register_variant_methods() { bind_method(Array, push_back, sarray("value"), varray()); bind_method(Array, push_front, sarray("value"), varray()); bind_method(Array, append, sarray("value"), varray()); + bind_method(Array, append_array, sarray("array"), varray()); bind_method(Array, resize, sarray("size"), varray()); bind_method(Array, insert, sarray("position", "value"), varray()); bind_method(Array, remove, sarray("position"), varray()); @@ -1802,14 +1314,14 @@ void register_variant_methods() { bind_method(PackedByteArray, subarray, sarray("from", "to"), varray()); bind_method(PackedByteArray, sort, sarray(), varray()); - bind_function("get_string_from_ascii", _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray()); - bind_function("get_string_from_utf8", _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray()); - bind_function("get_string_from_utf16", _VariantCall::func_PackedByteArray_get_string_from_utf16, sarray(), varray()); - bind_function("get_string_from_utf32", _VariantCall::func_PackedByteArray_get_string_from_utf32, sarray(), varray()); - bind_function("hex_encode", _VariantCall::func_PackedByteArray_hex_encode, sarray(), varray()); - bind_function("compress", _VariantCall::func_PackedByteArray_compress, sarray("compression_mode"), varray(0)); - bind_function("decompress", _VariantCall::func_PackedByteArray_decompress, sarray("buffer_size", "compression_mode"), varray(0)); - bind_function("decompress_dynamic", _VariantCall::func_PackedByteArray_decompress_dynamic, sarray("max_output_size", "compression_mode"), varray(0)); + bind_function(PackedByteArray, get_string_from_ascii, _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray()); + bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray()); + bind_function(PackedByteArray, get_string_from_utf16, _VariantCall::func_PackedByteArray_get_string_from_utf16, sarray(), varray()); + bind_function(PackedByteArray, get_string_from_utf32, _VariantCall::func_PackedByteArray_get_string_from_utf32, sarray(), varray()); + bind_function(PackedByteArray, hex_encode, _VariantCall::func_PackedByteArray_hex_encode, sarray(), varray()); + bind_function(PackedByteArray, compress, _VariantCall::func_PackedByteArray_compress, sarray("compression_mode"), varray(0)); + bind_function(PackedByteArray, decompress, _VariantCall::func_PackedByteArray_decompress, sarray("buffer_size", "compression_mode"), varray(0)); + bind_function(PackedByteArray, decompress_dynamic, _VariantCall::func_PackedByteArray_decompress_dynamic, sarray("max_output_size", "compression_mode"), varray(0)); /* Int32 Array */ @@ -1947,52 +1459,11 @@ void register_variant_methods() { bind_method(PackedColorArray, to_byte_array, sarray(), varray()); bind_method(PackedColorArray, sort, sarray(), varray()); - /* Register constructors */ - - _VariantCall::add_constructor(_VariantCall::Vector2_init1, Variant::VECTOR2, "x", Variant::FLOAT, "y", Variant::FLOAT); - _VariantCall::add_constructor(_VariantCall::Vector2i_init1, Variant::VECTOR2I, "x", Variant::INT, "y", Variant::INT); - - _VariantCall::add_constructor(_VariantCall::Rect2_init1, Variant::RECT2, "position", Variant::VECTOR2, "size", Variant::VECTOR2); - _VariantCall::add_constructor(_VariantCall::Rect2_init2, Variant::RECT2, "x", Variant::FLOAT, "y", Variant::FLOAT, "width", Variant::FLOAT, "height", Variant::FLOAT); - - _VariantCall::add_constructor(_VariantCall::Rect2i_init1, Variant::RECT2I, "position", Variant::VECTOR2I, "size", Variant::VECTOR2I); - _VariantCall::add_constructor(_VariantCall::Rect2i_init2, Variant::RECT2I, "x", Variant::INT, "y", Variant::INT, "width", Variant::INT, "height", Variant::INT); - - _VariantCall::add_constructor(_VariantCall::Transform2D_init2, Variant::TRANSFORM2D, "rotation", Variant::FLOAT, "position", Variant::VECTOR2); - _VariantCall::add_constructor(_VariantCall::Transform2D_init3, Variant::TRANSFORM2D, "x_axis", Variant::VECTOR2, "y_axis", Variant::VECTOR2, "origin", Variant::VECTOR2); - - _VariantCall::add_constructor(_VariantCall::Vector3_init1, Variant::VECTOR3, "x", Variant::FLOAT, "y", Variant::FLOAT, "z", Variant::FLOAT); - _VariantCall::add_constructor(_VariantCall::Vector3i_init1, Variant::VECTOR3I, "x", Variant::INT, "y", Variant::INT, "z", Variant::INT); - - _VariantCall::add_constructor(_VariantCall::Plane_init1, Variant::PLANE, "a", Variant::FLOAT, "b", Variant::FLOAT, "c", Variant::FLOAT, "d", Variant::FLOAT); - _VariantCall::add_constructor(_VariantCall::Plane_init2, Variant::PLANE, "v1", Variant::VECTOR3, "v2", Variant::VECTOR3, "v3", Variant::VECTOR3); - _VariantCall::add_constructor(_VariantCall::Plane_init3, Variant::PLANE, "normal", Variant::VECTOR3, "d", Variant::FLOAT); - - _VariantCall::add_constructor(_VariantCall::Quat_init1, Variant::QUAT, "x", Variant::FLOAT, "y", Variant::FLOAT, "z", Variant::FLOAT, "w", Variant::FLOAT); - _VariantCall::add_constructor(_VariantCall::Quat_init2, Variant::QUAT, "axis", Variant::VECTOR3, "angle", Variant::FLOAT); - _VariantCall::add_constructor(_VariantCall::Quat_init3, Variant::QUAT, "euler", Variant::VECTOR3); - - _VariantCall::add_constructor(_VariantCall::Color_init1, Variant::COLOR, "r", Variant::FLOAT, "g", Variant::FLOAT, "b", Variant::FLOAT, "a", Variant::FLOAT); - _VariantCall::add_constructor(_VariantCall::Color_init2, Variant::COLOR, "r", Variant::FLOAT, "g", Variant::FLOAT, "b", Variant::FLOAT); - // init3 and init4 are the constructors for HTML hex strings and integers respectively which don't need binding here, so we skip to init5. - _VariantCall::add_constructor(_VariantCall::Color_init5, Variant::COLOR, "c", Variant::COLOR, "a", Variant::FLOAT); - - _VariantCall::add_constructor(_VariantCall::AABB_init1, Variant::AABB, "position", Variant::VECTOR3, "size", Variant::VECTOR3); - - _VariantCall::add_constructor(_VariantCall::Basis_init1, Variant::BASIS, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3); - _VariantCall::add_constructor(_VariantCall::Basis_init2, Variant::BASIS, "axis", Variant::VECTOR3, "phi", Variant::FLOAT); - - _VariantCall::add_constructor(_VariantCall::Transform_init1, Variant::TRANSFORM, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3, "origin", Variant::VECTOR3); - _VariantCall::add_constructor(_VariantCall::Transform_init2, Variant::TRANSFORM, "basis", Variant::BASIS, "origin", Variant::VECTOR3); - - _VariantCall::add_constructor(_VariantCall::Callable_init2, Variant::CALLABLE, "object", Variant::OBJECT, "method_name", Variant::STRING_NAME); - _VariantCall::add_constructor(_VariantCall::Signal_init2, Variant::SIGNAL, "object", Variant::OBJECT, "signal_name", Variant::STRING_NAME); - /* Register constants */ - _populate_named_colors(); - for (Map<String, Color>::Element *color = _named_colors.front(); color; color = color->next()) { - _VariantCall::add_variant_constant(Variant::COLOR, color->key(), color->value()); + int ncc = Color::get_named_color_count(); + for (int i = 0; i < ncc; i++) { + _VariantCall::add_variant_constant(Variant::COLOR, Color::get_named_color_name(i), Color::get_named_color(i)); } _VariantCall::add_constant(Variant::VECTOR3, "AXIS_X", Vector3::AXIS_X); @@ -2072,19 +1543,13 @@ void register_variant_methods() { _VariantCall::add_variant_constant(Variant::QUAT, "IDENTITY", Quat(0, 0, 0, 1)); } -void unregister_variant_methods() { - //clear methods - for (int i = 0; i < Variant::VARIANT_MAX; i++) { - for (List<StringName>::Element *E = _VariantCall::type_internal_method_names[i].front(); E; E = E->next()) { - Variant::InternalMethod **m = _VariantCall::type_internal_methods[i].lookup_ptr(E->get()); - if (*m) { - memdelete(*m); - } - } - } +void Variant::_register_variant_methods() { + _register_variant_builtin_methods(); //needs to be out due to namespace +} - memdelete_arr(_VariantCall::type_internal_methods); - memdelete_arr(_VariantCall::type_internal_method_names); - memdelete_arr(_VariantCall::construct_funcs); +void Variant::_unregister_variant_methods() { + //clear methods + memdelete_arr(builtin_method_names); + memdelete_arr(builtin_method_info); memdelete_arr(_VariantCall::constant_data); } diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp new file mode 100644 index 0000000000..01f5b7df59 --- /dev/null +++ b/core/variant/variant_construct.cpp @@ -0,0 +1,812 @@ +/*************************************************************************/ +/* variant_construct.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 "variant.h" + +#include "core/core_string_names.h" +#include "core/crypto/crypto_core.h" +#include "core/debugger/engine_debugger.h" +#include "core/io/compression.h" +#include "core/object/class_db.h" +#include "core/os/os.h" +#include "core/templates/local_vector.h" +#include "core/templates/oa_hash_map.h" + +template <class T, class... P> +class VariantConstructor { + template <size_t... Is> + static _FORCE_INLINE_ void construct_helper(T &base, const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + base = T(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + base = T(VariantCaster<P>::cast(*p_args[Is])...); +#endif + } + + template <size_t... Is> + static _FORCE_INLINE_ void validated_construct_helper(T &base, const Variant **p_args, IndexSequence<Is...>) { + base = T((*VariantGetInternalPtr<P>::get_ptr(p_args[Is]))...); + } + + template <size_t... Is> + static _FORCE_INLINE_ void ptr_construct_helper(void *base, const void **p_args, IndexSequence<Is...>) { + PtrToArg<T>::encode(T(PtrToArg<P>::convert(p_args[Is])...), base); + } + +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + r_error.error = Callable::CallError::CALL_OK; + VariantTypeChanger<T>::change(&r_ret); + construct_helper(*VariantGetInternalPtr<T>::get_ptr(&r_ret), p_args, r_error, BuildIndexSequence<sizeof...(P)>{}); + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantTypeChanger<T>::change(&r_ret); + validated_construct_helper(*VariantGetInternalPtr<T>::get_ptr(&r_ret), p_args, BuildIndexSequence<sizeof...(P)>{}); + } + static void ptr_construct(void *base, const void **p_args) { + ptr_construct_helper(base, p_args, BuildIndexSequence<sizeof...(P)>{}); + } + + static int get_argument_count() { + return sizeof...(P); + } + + static Variant::Type get_argument_type(int p_arg) { + return call_get_argument_type<P...>(p_arg); + } + + static Variant::Type get_base_type() { + return GetTypeInfo<T>::VARIANT_TYPE; + } +}; + +class VariantConstructorObject { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + VariantInternal::clear(&r_ret); + if (p_args[0]->get_type() == Variant::NIL) { + VariantInternal::object_assign_null(&r_ret); + r_error.error = Callable::CallError::CALL_OK; + } else if (p_args[0]->get_type() == Variant::OBJECT) { + VariantInternal::object_assign(&r_ret, p_args[0]); + r_error.error = Callable::CallError::CALL_OK; + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::OBJECT; + } + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantInternal::clear(&r_ret); + VariantInternal::object_assign(&r_ret, p_args[0]); + } + static void ptr_construct(void *base, const void **p_args) { + PtrToArg<Object *>::encode(PtrToArg<Object *>::convert(p_args[0]), base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::OBJECT; + } + + static Variant::Type get_base_type() { + return Variant::OBJECT; + } +}; + +class VariantConstructorNilObject { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + if (p_args[0]->get_type() != Variant::NIL) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::NIL; + } + + VariantInternal::clear(&r_ret); + VariantInternal::object_assign_null(&r_ret); + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantInternal::clear(&r_ret); + VariantInternal::object_assign_null(&r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + PtrToArg<Object *>::encode(nullptr, base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return Variant::OBJECT; + } +}; + +class VariantConstructorCallableArgs { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + ObjectID object_id; + StringName method; + + if (p_args[0]->get_type() == Variant::NIL) { + // leave as is + } else if (p_args[0]->get_type() == Variant::OBJECT) { + object_id = VariantInternal::get_object_id(p_args[0]); + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::OBJECT; + return; + } + + if (p_args[1]->get_type() == Variant::STRING_NAME) { + method = *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]); + } else if (p_args[1]->get_type() == Variant::STRING) { + method = *VariantGetInternalPtr<String>::get_ptr(p_args[1]); + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 1; + r_error.expected = Variant::STRING_NAME; + return; + } + + VariantTypeChanger<Callable>::change(&r_ret); + *VariantGetInternalPtr<Callable>::get_ptr(&r_ret) = Callable(object_id, method); + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantTypeChanger<Callable>::change(&r_ret); + *VariantGetInternalPtr<Callable>::get_ptr(&r_ret) = Callable(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1])); + } + static void ptr_construct(void *base, const void **p_args) { + PtrToArg<Callable>::encode(Callable(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base); + } + + static int get_argument_count() { + return 2; + } + + static Variant::Type get_argument_type(int p_arg) { + if (p_arg == 0) { + return Variant::OBJECT; + } else { + return Variant::STRING_NAME; + } + } + + static Variant::Type get_base_type() { + return Variant::CALLABLE; + } +}; + +class VariantConstructorSignalArgs { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + ObjectID object_id; + StringName method; + + if (p_args[0]->get_type() == Variant::NIL) { + // leave as is + } else if (p_args[0]->get_type() == Variant::OBJECT) { + object_id = VariantInternal::get_object_id(p_args[0]); + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::OBJECT; + return; + } + + if (p_args[1]->get_type() == Variant::STRING_NAME) { + method = *VariantGetInternalPtr<StringName>::get_ptr(p_args[1]); + } else if (p_args[1]->get_type() == Variant::STRING) { + method = *VariantGetInternalPtr<String>::get_ptr(p_args[1]); + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 1; + r_error.expected = Variant::STRING_NAME; + return; + } + + VariantTypeChanger<Signal>::change(&r_ret); + *VariantGetInternalPtr<Signal>::get_ptr(&r_ret) = Signal(object_id, method); + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantTypeChanger<Signal>::change(&r_ret); + *VariantGetInternalPtr<Signal>::get_ptr(&r_ret) = Signal(VariantInternal::get_object_id(p_args[0]), *VariantGetInternalPtr<StringName>::get_ptr(p_args[1])); + } + static void ptr_construct(void *base, const void **p_args) { + PtrToArg<Signal>::encode(Signal(PtrToArg<Object *>::convert(p_args[0]), PtrToArg<StringName>::convert(p_args[1])), base); + } + + static int get_argument_count() { + return 2; + } + + static Variant::Type get_argument_type(int p_arg) { + if (p_arg == 0) { + return Variant::OBJECT; + } else { + return Variant::STRING_NAME; + } + } + + static Variant::Type get_base_type() { + return Variant::SIGNAL; + } +}; + +template <class T> +class VariantConstructorToArray { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + if (p_args[0]->get_type() != GetTypeInfo<T>::VARIANT_TYPE) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = GetTypeInfo<T>::VARIANT_TYPE; + return; + } + + VariantTypeChanger<Array>::change(&r_ret); + Array &dst_arr = *VariantGetInternalPtr<Array>::get_ptr(&r_ret); + const T &src_arr = *VariantGetInternalPtr<T>::get_ptr(p_args[0]); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr[i] = src_arr[i]; + } + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantTypeChanger<Array>::change(&r_ret); + Array &dst_arr = *VariantGetInternalPtr<Array>::get_ptr(&r_ret); + const T &src_arr = *VariantGetInternalPtr<T>::get_ptr(p_args[0]); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr[i] = src_arr[i]; + } + } + static void ptr_construct(void *base, const void **p_args) { + Array dst_arr; + T src_arr = PtrToArg<T>::convert(p_args[0]); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr[i] = src_arr[i]; + } + + PtrToArg<Array>::encode(dst_arr, base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return GetTypeInfo<T>::VARIANT_TYPE; + } + + static Variant::Type get_base_type() { + return Variant::ARRAY; + } +}; + +template <class T> +class VariantConstructorFromArray { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + if (p_args[0]->get_type() != Variant::ARRAY) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::ARRAY; + return; + } + + VariantTypeChanger<T>::change(&r_ret); + const Array &src_arr = *VariantGetInternalPtr<Array>::get_ptr(p_args[0]); + T &dst_arr = *VariantGetInternalPtr<T>::get_ptr(&r_ret); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr.write[i] = src_arr[i]; + } + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantTypeChanger<T>::change(&r_ret); + const Array &src_arr = *VariantGetInternalPtr<Array>::get_ptr(p_args[0]); + T &dst_arr = *VariantGetInternalPtr<T>::get_ptr(&r_ret); + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr.write[i] = src_arr[i]; + } + } + static void ptr_construct(void *base, const void **p_args) { + Array src_arr = PtrToArg<Array>::convert(p_args[0]); + T dst_arr; + + int size = src_arr.size(); + dst_arr.resize(size); + for (int i = 0; i < size; i++) { + dst_arr.write[i] = src_arr[i]; + } + + PtrToArg<T>::encode(dst_arr, base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::ARRAY; + } + + static Variant::Type get_base_type() { + return GetTypeInfo<T>::VARIANT_TYPE; + } +}; + +class VariantConstructorNil { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + if (p_args[0]->get_type() != Variant::NIL) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::NIL; + return; + } + + r_error.error = Callable::CallError::CALL_OK; + VariantInternal::clear(&r_ret); + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantInternal::clear(&r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + PtrToArg<Variant>::encode(Variant(), base); + } + + static int get_argument_count() { + return 1; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return Variant::NIL; + } +}; + +template <class T> +class VariantConstructNoArgs { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + VariantTypeChanger<T>::change_and_reset(&r_ret); + r_error.error = Callable::CallError::CALL_OK; + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantTypeChanger<T>::change_and_reset(&r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + PtrToArg<T>::encode(T(), base); + } + + static int get_argument_count() { + return 0; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return GetTypeInfo<T>::VARIANT_TYPE; + } +}; + +class VariantConstructNoArgsNil { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + VariantInternal::clear(&r_ret); + r_error.error = Callable::CallError::CALL_OK; + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantInternal::clear(&r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + ERR_FAIL_MSG("can't ptrcall nil constructor"); + } + + static int get_argument_count() { + return 0; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return Variant::NIL; + } +}; + +class VariantConstructNoArgsObject { +public: + static void construct(Variant &r_ret, const Variant **p_args, Callable::CallError &r_error) { + VariantInternal::clear(&r_ret); + VariantInternal::object_assign_null(&r_ret); + r_error.error = Callable::CallError::CALL_OK; + } + + static void validated_construct(Variant &r_ret, const Variant **p_args) { + VariantInternal::clear(&r_ret); + VariantInternal::object_assign_null(&r_ret); + } + static void ptr_construct(void *base, const void **p_args) { + PtrToArg<Object *>::encode(nullptr, base); + } + + static int get_argument_count() { + return 0; + } + + static Variant::Type get_argument_type(int p_arg) { + return Variant::NIL; + } + + static Variant::Type get_base_type() { + return Variant::OBJECT; + } +}; + +struct VariantConstructData { + void (*construct)(Variant &r_base, const Variant **p_args, Callable::CallError &r_error); + Variant::ValidatedConstructor validated_construct; + Variant::PTRConstructor ptr_construct; + Variant::Type (*get_argument_type)(int); + int argument_count; + Vector<String> arg_names; +}; + +static LocalVector<VariantConstructData> construct_data[Variant::VARIANT_MAX]; + +template <class T> +static void add_constructor(const Vector<String> &arg_names) { + ERR_FAIL_COND_MSG(arg_names.size() != T::get_argument_count(), "Argument names size mismatch for " + Variant::get_type_name(T::get_base_type()) + "."); + + VariantConstructData cd; + cd.construct = T::construct; + cd.validated_construct = T::validated_construct; + cd.ptr_construct = T::ptr_construct; + cd.get_argument_type = T::get_argument_type; + cd.argument_count = T::get_argument_count(); + cd.arg_names = arg_names; + construct_data[T::get_base_type()].push_back(cd); +} + +void Variant::_register_variant_constructors() { + add_constructor<VariantConstructNoArgsNil>(sarray()); + add_constructor<VariantConstructorNil>(sarray("from")); + + add_constructor<VariantConstructNoArgs<bool>>(sarray()); + add_constructor<VariantConstructor<bool, bool>>(sarray("from")); + add_constructor<VariantConstructor<bool, int64_t>>(sarray("from")); + add_constructor<VariantConstructor<bool, double>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<int64_t>>(sarray()); + add_constructor<VariantConstructor<int64_t, int64_t>>(sarray("from")); + add_constructor<VariantConstructor<int64_t, double>>(sarray("from")); + add_constructor<VariantConstructor<int64_t, bool>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<double>>(sarray()); + add_constructor<VariantConstructor<double, double>>(sarray("from")); + add_constructor<VariantConstructor<double, int64_t>>(sarray("from")); + add_constructor<VariantConstructor<double, bool>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<String>>(sarray()); + add_constructor<VariantConstructor<String, String>>(sarray("from")); + add_constructor<VariantConstructor<String, StringName>>(sarray("from")); + add_constructor<VariantConstructor<String, NodePath>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<Vector2>>(sarray()); + add_constructor<VariantConstructor<Vector2, Vector2>>(sarray("from")); + add_constructor<VariantConstructor<Vector2, Vector2i>>(sarray("from")); + add_constructor<VariantConstructor<Vector2, double, double>>(sarray("x", "y")); + + add_constructor<VariantConstructNoArgs<Vector2i>>(sarray()); + add_constructor<VariantConstructor<Vector2i, Vector2i>>(sarray("from")); + add_constructor<VariantConstructor<Vector2i, Vector2>>(sarray("from")); + add_constructor<VariantConstructor<Vector2i, int64_t, int64_t>>(sarray("x", "y")); + + add_constructor<VariantConstructNoArgs<Rect2>>(sarray()); + add_constructor<VariantConstructor<Rect2, Rect2>>(sarray("from")); + add_constructor<VariantConstructor<Rect2, Rect2i>>(sarray("from")); + add_constructor<VariantConstructor<Rect2, Vector2, Vector2>>(sarray("position", "size")); + add_constructor<VariantConstructor<Rect2, double, double, double, double>>(sarray("x", "y", "width", "height")); + + add_constructor<VariantConstructNoArgs<Rect2i>>(sarray()); + add_constructor<VariantConstructor<Rect2i, Rect2i>>(sarray("from")); + add_constructor<VariantConstructor<Rect2i, Rect2>>(sarray("from")); + add_constructor<VariantConstructor<Rect2i, Vector2i, Vector2i>>(sarray("position", "size")); + add_constructor<VariantConstructor<Rect2i, int64_t, int64_t, int64_t, int64_t>>(sarray("x", "y", "width", "height")); + + add_constructor<VariantConstructNoArgs<Vector3>>(sarray()); + add_constructor<VariantConstructor<Vector3, Vector3>>(sarray("from")); + add_constructor<VariantConstructor<Vector3, Vector3i>>(sarray("from")); + add_constructor<VariantConstructor<Vector3, double, double, double>>(sarray("x", "y", "z")); + + add_constructor<VariantConstructNoArgs<Vector3i>>(sarray()); + add_constructor<VariantConstructor<Vector3i, Vector3i>>(sarray("from")); + add_constructor<VariantConstructor<Vector3i, Vector3>>(sarray("from")); + add_constructor<VariantConstructor<Vector3i, int64_t, int64_t, int64_t>>(sarray("x", "y", "z")); + + add_constructor<VariantConstructNoArgs<Transform2D>>(sarray()); + add_constructor<VariantConstructor<Transform2D, Transform2D>>(sarray("from")); + add_constructor<VariantConstructor<Transform2D, float, Vector2>>(sarray("rotation", "position")); + add_constructor<VariantConstructor<Transform2D, Vector2, Vector2, Vector2>>(sarray("x_axis", "y_axis", "origin")); + + add_constructor<VariantConstructNoArgs<Plane>>(sarray()); + add_constructor<VariantConstructor<Plane, Plane>>(sarray("from")); + add_constructor<VariantConstructor<Plane, Vector3, double>>(sarray("normal", "d")); + add_constructor<VariantConstructor<Plane, Vector3, Vector3>>(sarray("point", "normal")); + add_constructor<VariantConstructor<Plane, Vector3, Vector3, Vector3>>(sarray("point1", "point2", "point3")); + add_constructor<VariantConstructor<Plane, double, double, double, double>>(sarray("a", "b", "c", "d")); + + add_constructor<VariantConstructNoArgs<Quat>>(sarray()); + add_constructor<VariantConstructor<Quat, Quat>>(sarray("from")); + add_constructor<VariantConstructor<Quat, Basis>>(sarray("from")); + add_constructor<VariantConstructor<Quat, Vector3>>(sarray("euler")); + add_constructor<VariantConstructor<Quat, Vector3, double>>(sarray("axis", "angle")); + add_constructor<VariantConstructor<Quat, Vector3, Vector3>>(sarray("arc_from", "arc_to")); + add_constructor<VariantConstructor<Quat, double, double, double, double>>(sarray("x", "y", "z", "w")); + + add_constructor<VariantConstructNoArgs<::AABB>>(sarray()); + add_constructor<VariantConstructor<::AABB, ::AABB>>(sarray("from")); + add_constructor<VariantConstructor<::AABB, Vector3, Vector3>>(sarray("position", "size")); + + add_constructor<VariantConstructNoArgs<Basis>>(sarray()); + add_constructor<VariantConstructor<Basis, Basis>>(sarray("from")); + add_constructor<VariantConstructor<Basis, Quat>>(sarray("from")); + add_constructor<VariantConstructor<Basis, Vector3>>(sarray("euler")); + add_constructor<VariantConstructor<Basis, Vector3, double>>(sarray("axis", "phi")); + add_constructor<VariantConstructor<Basis, Vector3, Vector3, Vector3>>(sarray("x_axis", "y_axis", "z_axis")); + + add_constructor<VariantConstructNoArgs<Transform>>(sarray()); + add_constructor<VariantConstructor<Transform, Transform>>(sarray("from")); + add_constructor<VariantConstructor<Transform, Basis, Vector3>>(sarray("basis", "origin")); + add_constructor<VariantConstructor<Transform, Vector3, Vector3, Vector3, Vector3>>(sarray("x_axis", "y_axis", "z_axis", "origin")); + + add_constructor<VariantConstructNoArgs<Color>>(sarray()); + add_constructor<VariantConstructor<Color, Color>>(sarray("from")); + add_constructor<VariantConstructor<Color, Color, double>>(sarray("from", "alpha")); + add_constructor<VariantConstructor<Color, double, double, double>>(sarray("r", "g", "b")); + add_constructor<VariantConstructor<Color, double, double, double, double>>(sarray("r", "g", "b", "a")); + + add_constructor<VariantConstructNoArgs<StringName>>(sarray()); + add_constructor<VariantConstructor<StringName, StringName>>(sarray("from")); + add_constructor<VariantConstructor<StringName, String>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<NodePath>>(sarray()); + add_constructor<VariantConstructor<NodePath, NodePath>>(sarray("from")); + add_constructor<VariantConstructor<NodePath, String>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<::RID>>(sarray()); + add_constructor<VariantConstructor<::RID, ::RID>>(sarray("from")); + + add_constructor<VariantConstructNoArgsObject>(sarray()); + add_constructor<VariantConstructorObject>(sarray("from")); + add_constructor<VariantConstructorNilObject>(sarray("from")); + + add_constructor<VariantConstructNoArgs<Callable>>(sarray()); + add_constructor<VariantConstructor<Callable, Callable>>(sarray("from")); + add_constructor<VariantConstructorCallableArgs>(sarray("object", "method")); + + add_constructor<VariantConstructNoArgs<Signal>>(sarray()); + add_constructor<VariantConstructor<Signal, Signal>>(sarray("from")); + add_constructor<VariantConstructorSignalArgs>(sarray("object", "signal")); + + add_constructor<VariantConstructNoArgs<Dictionary>>(sarray()); + add_constructor<VariantConstructor<Dictionary, Dictionary>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<Array>>(sarray()); + add_constructor<VariantConstructor<Array, Array>>(sarray("from")); + add_constructor<VariantConstructorToArray<PackedByteArray>>(sarray("from")); + add_constructor<VariantConstructorToArray<PackedInt32Array>>(sarray("from")); + add_constructor<VariantConstructorToArray<PackedInt64Array>>(sarray("from")); + add_constructor<VariantConstructorToArray<PackedFloat32Array>>(sarray("from")); + add_constructor<VariantConstructorToArray<PackedFloat64Array>>(sarray("from")); + add_constructor<VariantConstructorToArray<PackedStringArray>>(sarray("from")); + add_constructor<VariantConstructorToArray<PackedVector2Array>>(sarray("from")); + add_constructor<VariantConstructorToArray<PackedVector3Array>>(sarray("from")); + add_constructor<VariantConstructorToArray<PackedColorArray>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<PackedByteArray>>(sarray()); + add_constructor<VariantConstructor<PackedByteArray, PackedByteArray>>(sarray("from")); + add_constructor<VariantConstructorFromArray<PackedByteArray>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<PackedInt32Array>>(sarray()); + add_constructor<VariantConstructor<PackedInt32Array, PackedInt32Array>>(sarray("from")); + add_constructor<VariantConstructorFromArray<PackedInt32Array>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<PackedInt64Array>>(sarray()); + add_constructor<VariantConstructor<PackedInt64Array, PackedInt64Array>>(sarray("from")); + add_constructor<VariantConstructorFromArray<PackedInt64Array>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<PackedFloat32Array>>(sarray()); + add_constructor<VariantConstructor<PackedFloat32Array, PackedFloat32Array>>(sarray("from")); + add_constructor<VariantConstructorFromArray<PackedFloat32Array>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<PackedFloat64Array>>(sarray()); + add_constructor<VariantConstructor<PackedFloat64Array, PackedFloat64Array>>(sarray("from")); + add_constructor<VariantConstructorFromArray<PackedFloat64Array>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<PackedStringArray>>(sarray()); + add_constructor<VariantConstructor<PackedStringArray, PackedStringArray>>(sarray("from")); + add_constructor<VariantConstructorFromArray<PackedStringArray>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<PackedVector2Array>>(sarray()); + add_constructor<VariantConstructor<PackedVector2Array, PackedVector2Array>>(sarray("from")); + add_constructor<VariantConstructorFromArray<PackedVector2Array>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<PackedVector3Array>>(sarray()); + add_constructor<VariantConstructor<PackedVector3Array, PackedVector3Array>>(sarray("from")); + add_constructor<VariantConstructorFromArray<PackedVector3Array>>(sarray("from")); + + add_constructor<VariantConstructNoArgs<PackedColorArray>>(sarray()); + add_constructor<VariantConstructor<PackedColorArray, PackedColorArray>>(sarray("from")); + add_constructor<VariantConstructorFromArray<PackedColorArray>>(sarray("from")); +} + +void Variant::_unregister_variant_constructors() { + for (int i = 0; i < Variant::VARIANT_MAX; i++) { + construct_data[i].clear(); + } +} + +void Variant::construct(Variant::Type p_type, Variant &base, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { + uint32_t s = construct_data[p_type].size(); + for (uint32_t i = 0; i < s; i++) { + int argc = construct_data[p_type][i].argument_count; + if (argc != p_argcount) { + continue; + } + bool args_match = true; + for (int j = 0; j < argc; j++) { + if (!Variant::can_convert_strict(p_args[j]->get_type(), construct_data[p_type][i].get_argument_type(j))) { + args_match = false; + break; + } + } + + if (!args_match) { + continue; + } + + construct_data[p_type][i].construct(base, p_args, r_error); + return; + } + + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; +} + +int Variant::get_constructor_count(Variant::Type p_type) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, -1); + return construct_data[p_type].size(); +} + +Variant::ValidatedConstructor Variant::get_validated_constructor(Variant::Type p_type, int p_constructor) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr); + ERR_FAIL_INDEX_V(p_constructor, (int)construct_data[p_type].size(), nullptr); + return construct_data[p_type][p_constructor].validated_construct; +} + +Variant::PTRConstructor Variant::get_ptr_constructor(Variant::Type p_type, int p_constructor) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr); + ERR_FAIL_INDEX_V(p_constructor, (int)construct_data[p_type].size(), nullptr); + return construct_data[p_type][p_constructor].ptr_construct; +} + +int Variant::get_constructor_argument_count(Variant::Type p_type, int p_constructor) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, -1); + ERR_FAIL_INDEX_V(p_constructor, (int)construct_data[p_type].size(), -1); + return construct_data[p_type][p_constructor].argument_count; +} + +Variant::Type Variant::get_constructor_argument_type(Variant::Type p_type, int p_constructor, int p_argument) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::VARIANT_MAX); + ERR_FAIL_INDEX_V(p_constructor, (int)construct_data[p_type].size(), Variant::VARIANT_MAX); + return construct_data[p_type][p_constructor].get_argument_type(p_argument); +} + +String Variant::get_constructor_argument_name(Variant::Type p_type, int p_constructor, int p_argument) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, String()); + ERR_FAIL_INDEX_V(p_constructor, (int)construct_data[p_type].size(), String()); + return construct_data[p_type][p_constructor].arg_names[p_argument]; +} + +void VariantInternal::object_assign(Variant *v, const Variant *o) { + if (o->_get_obj().obj && o->_get_obj().id.is_reference()) { + Reference *reference = static_cast<Reference *>(o->_get_obj().obj); + if (!reference->reference()) { + v->_get_obj().obj = nullptr; + v->_get_obj().id = ObjectID(); + return; + } + } + + v->_get_obj().obj = const_cast<Object *>(o->_get_obj().obj); + v->_get_obj().id = o->_get_obj().id; +} + +void Variant::get_constructor_list(Type p_type, List<MethodInfo> *r_list) { + ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX); + + MethodInfo mi; + mi.return_val.type = p_type; + mi.name = get_type_name(p_type); + + for (int i = 0; i < get_constructor_count(p_type); i++) { + int ac = get_constructor_argument_count(p_type, i); + mi.arguments.clear(); + for (int j = 0; j < ac; j++) { + PropertyInfo arg; + arg.name = get_constructor_argument_name(p_type, i, j); + arg.type = get_constructor_argument_type(p_type, i, j); + mi.arguments.push_back(arg); + } + r_list->push_back(mi); + } +} diff --git a/core/variant_internal.h b/core/variant/variant_internal.h index 7893c6d382..3ac7f32dec 100644 --- a/core/variant_internal.h +++ b/core/variant/variant_internal.h @@ -83,8 +83,8 @@ public: _FORCE_INLINE_ static const StringName *get_string_name(const Variant *v) { return reinterpret_cast<const StringName *>(v->_data._mem); } _FORCE_INLINE_ static NodePath *get_node_path(Variant *v) { return reinterpret_cast<NodePath *>(v->_data._mem); } _FORCE_INLINE_ static const NodePath *get_node_path(const Variant *v) { return reinterpret_cast<const NodePath *>(v->_data._mem); } - _FORCE_INLINE_ static RID *get_rid(Variant *v) { return reinterpret_cast<RID *>(v->_data._mem); } - _FORCE_INLINE_ static const RID *get_rid(const Variant *v) { return reinterpret_cast<const RID *>(v->_data._mem); } + _FORCE_INLINE_ static ::RID *get_rid(Variant *v) { return reinterpret_cast<::RID *>(v->_data._mem); } + _FORCE_INLINE_ static const ::RID *get_rid(const Variant *v) { return reinterpret_cast<const ::RID *>(v->_data._mem); } _FORCE_INLINE_ static Callable *get_callable(Variant *v) { return reinterpret_cast<Callable *>(v->_data._mem); } _FORCE_INLINE_ static const Callable *get_callable(const Variant *v) { return reinterpret_cast<const Callable *>(v->_data._mem); } _FORCE_INLINE_ static Signal *get_signal(Variant *v) { return reinterpret_cast<Signal *>(v->_data._mem); } @@ -116,6 +116,106 @@ public: _FORCE_INLINE_ static Object **get_object(Variant *v) { return (Object **)&v->_get_obj().obj; } _FORCE_INLINE_ static const Object **get_object(const Variant *v) { return (const Object **)&v->_get_obj().obj; } + + _FORCE_INLINE_ static const ObjectID get_object_id(const Variant *v) { return v->_get_obj().id; } + + template <class T> + _FORCE_INLINE_ static void init_generic(Variant *v) { + v->type = GetTypeInfo<T>::VARIANT_TYPE; + } + + _FORCE_INLINE_ static void init_string(Variant *v) { + memnew_placement(v->_data._mem, String); + v->type = Variant::STRING; + } + + _FORCE_INLINE_ static void init_transform2d(Variant *v) { + v->_data._transform2d = memnew(Transform2D); + v->type = Variant::TRANSFORM2D; + } + _FORCE_INLINE_ static void init_aabb(Variant *v) { + v->_data._aabb = memnew(AABB); + v->type = Variant::AABB; + } + _FORCE_INLINE_ static void init_basis(Variant *v) { + v->_data._basis = memnew(Basis); + v->type = Variant::BASIS; + } + _FORCE_INLINE_ static void init_transform(Variant *v) { + v->_data._transform = memnew(Transform); + v->type = Variant::TRANSFORM; + } + _FORCE_INLINE_ static void init_string_name(Variant *v) { + memnew_placement(v->_data._mem, StringName); + v->type = Variant::STRING_NAME; + } + _FORCE_INLINE_ static void init_node_path(Variant *v) { + memnew_placement(v->_data._mem, NodePath); + v->type = Variant::NODE_PATH; + } + _FORCE_INLINE_ static void init_callable(Variant *v) { + memnew_placement(v->_data._mem, Callable); + v->type = Variant::CALLABLE; + } + _FORCE_INLINE_ static void init_signal(Variant *v) { + memnew_placement(v->_data._mem, Signal); + v->type = Variant::SIGNAL; + } + _FORCE_INLINE_ static void init_dictionary(Variant *v) { + memnew_placement(v->_data._mem, Dictionary); + v->type = Variant::DICTIONARY; + } + _FORCE_INLINE_ static void init_array(Variant *v) { + memnew_placement(v->_data._mem, Array); + v->type = Variant::ARRAY; + } + _FORCE_INLINE_ static void init_byte_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef<uint8_t>::create(Vector<uint8_t>()); + v->type = Variant::PACKED_BYTE_ARRAY; + } + _FORCE_INLINE_ static void init_int32_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef<int32_t>::create(Vector<int32_t>()); + v->type = Variant::PACKED_INT32_ARRAY; + } + _FORCE_INLINE_ static void init_int64_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef<int64_t>::create(Vector<int64_t>()); + v->type = Variant::PACKED_INT64_ARRAY; + } + _FORCE_INLINE_ static void init_float32_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef<float>::create(Vector<float>()); + v->type = Variant::PACKED_FLOAT32_ARRAY; + } + _FORCE_INLINE_ static void init_float64_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef<double>::create(Vector<double>()); + v->type = Variant::PACKED_FLOAT64_ARRAY; + } + _FORCE_INLINE_ static void init_string_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef<String>::create(Vector<String>()); + v->type = Variant::PACKED_STRING_ARRAY; + } + _FORCE_INLINE_ static void init_vector2_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef<Vector2>::create(Vector<Vector2>()); + v->type = Variant::PACKED_VECTOR2_ARRAY; + } + _FORCE_INLINE_ static void init_vector3_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef<Vector3>::create(Vector<Vector3>()); + v->type = Variant::PACKED_VECTOR3_ARRAY; + } + _FORCE_INLINE_ static void init_color_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef<Color>::create(Vector<Color>()); + v->type = Variant::PACKED_COLOR_ARRAY; + } + + _FORCE_INLINE_ static void clear(Variant *v) { + v->clear(); + } + + static void object_assign(Variant *v, const Variant *o); //needs to use reference, do away + + _FORCE_INLINE_ static void object_assign_null(Variant *v) { + v->_get_obj().obj = nullptr; + v->_get_obj().id = ObjectID(); + } }; template <class T> @@ -305,9 +405,9 @@ struct VariantGetInternalPtr<NodePath> { }; template <> -struct VariantGetInternalPtr<RID> { - static RID *get_ptr(Variant *v) { return VariantInternal::get_rid(v); } - static const RID *get_ptr(const Variant *v) { return VariantInternal::get_rid(v); } +struct VariantGetInternalPtr<::RID> { + static ::RID *get_ptr(Variant *v) { return VariantInternal::get_rid(v); } + static const ::RID *get_ptr(const Variant *v) { return VariantInternal::get_rid(v); } }; template <> @@ -532,9 +632,9 @@ struct VariantInternalAccessor<NodePath> { }; template <> -struct VariantInternalAccessor<RID> { - static _FORCE_INLINE_ const RID &get(const Variant *v) { return *VariantInternal::get_rid(v); } - static _FORCE_INLINE_ void set(Variant *v, const RID &p_value) { *VariantInternal::get_rid(v) = p_value; } +struct VariantInternalAccessor<::RID> { + static _FORCE_INLINE_ const ::RID &get(const Variant *v) { return *VariantInternal::get_rid(v); } + static _FORCE_INLINE_ void set(Variant *v, const ::RID &p_value) { *VariantInternal::get_rid(v) = p_value; } }; template <> @@ -649,4 +749,383 @@ struct VariantInternalAccessor<Vector<Variant>> { } }; +template <class T> +struct VariantInitializer { +}; + +template <> +struct VariantInitializer<bool> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<bool>(v); } +}; + +#define INITIALIZER_INT(m_type) \ + template <> \ + struct VariantInitializer<m_type> { \ + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<int64_t>(v); } \ + }; + +INITIALIZER_INT(uint8_t) +INITIALIZER_INT(int8_t) +INITIALIZER_INT(uint16_t) +INITIALIZER_INT(int16_t) +INITIALIZER_INT(uint32_t) +INITIALIZER_INT(int32_t) +INITIALIZER_INT(uint64_t) +INITIALIZER_INT(int64_t) +INITIALIZER_INT(char32_t) +INITIALIZER_INT(Error) +INITIALIZER_INT(ObjectID) + +template <> +struct VariantInitializer<double> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<double>(v); } +}; + +template <> +struct VariantInitializer<float> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<double>(v); } +}; + +template <> +struct VariantInitializer<String> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string(v); } +}; + +template <> +struct VariantInitializer<Vector2> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector2>(v); } +}; + +template <> +struct VariantInitializer<Vector2i> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector2i>(v); } +}; + +template <> +struct VariantInitializer<Rect2> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Rect2>(v); } +}; + +template <> +struct VariantInitializer<Rect2i> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Rect2i>(v); } +}; + +template <> +struct VariantInitializer<Vector3> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector3>(v); } +}; + +template <> +struct VariantInitializer<Vector3i> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector3i>(v); } +}; + +template <> +struct VariantInitializer<Transform2D> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform2d(v); } +}; + +template <> +struct VariantInitializer<Plane> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Plane>(v); } +}; + +template <> +struct VariantInitializer<Quat> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Quat>(v); } +}; + +template <> +struct VariantInitializer<AABB> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_aabb(v); } +}; + +template <> +struct VariantInitializer<Basis> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_basis(v); } +}; + +template <> +struct VariantInitializer<Transform> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform(v); } +}; + +template <> +struct VariantInitializer<Color> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Color>(v); } +}; + +template <> +struct VariantInitializer<StringName> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string_name(v); } +}; + +template <> +struct VariantInitializer<NodePath> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_node_path(v); } +}; + +template <> +struct VariantInitializer<::RID> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<::RID>(v); } +}; + +template <> +struct VariantInitializer<Callable> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_callable(v); } +}; + +template <> +struct VariantInitializer<Signal> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_signal(v); } +}; + +template <> +struct VariantInitializer<Dictionary> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_dictionary(v); } +}; + +template <> +struct VariantInitializer<Array> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_array(v); } +}; + +template <> +struct VariantInitializer<PackedByteArray> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_byte_array(v); } +}; + +template <> +struct VariantInitializer<PackedInt32Array> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_int32_array(v); } +}; + +template <> +struct VariantInitializer<PackedInt64Array> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_int64_array(v); } +}; + +template <> +struct VariantInitializer<PackedFloat32Array> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_float32_array(v); } +}; + +template <> +struct VariantInitializer<PackedFloat64Array> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_float64_array(v); } +}; + +template <> +struct VariantInitializer<PackedStringArray> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string_array(v); } +}; + +template <> +struct VariantInitializer<PackedVector2Array> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_vector2_array(v); } +}; + +template <> +struct VariantInitializer<PackedVector3Array> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_vector3_array(v); } +}; + +template <> +struct VariantInitializer<PackedColorArray> { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_color_array(v); } +}; + +template <class T> +struct VariantZeroAssigner { +}; + +template <> +struct VariantZeroAssigner<bool> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_bool(v) = false; } +}; + +template <> +struct VariantZeroAssigner<int64_t> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_int(v) = 0; } +}; + +template <> +struct VariantZeroAssigner<double> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_float(v) = 0.0; } +}; + +template <> +struct VariantZeroAssigner<float> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_float(v) = 0.0; } +}; + +template <> +struct VariantZeroAssigner<String> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<Vector2> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector2(v) = Vector2(); } +}; + +template <> +struct VariantZeroAssigner<Vector2i> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector2i(v) = Vector2i(); } +}; + +template <> +struct VariantZeroAssigner<Rect2> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_rect2(v) = Rect2(); } +}; + +template <> +struct VariantZeroAssigner<Rect2i> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_rect2i(v) = Rect2i(); } +}; + +template <> +struct VariantZeroAssigner<Vector3> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector3(v) = Vector3(); } +}; + +template <> +struct VariantZeroAssigner<Vector3i> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_vector3i(v) = Vector3i(); } +}; + +template <> +struct VariantZeroAssigner<Transform2D> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_transform2d(v) = Transform2D(); } +}; + +template <> +struct VariantZeroAssigner<Plane> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_plane(v) = Plane(); } +}; + +template <> +struct VariantZeroAssigner<Quat> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_quat(v) = Quat(); } +}; + +template <> +struct VariantZeroAssigner<AABB> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_aabb(v) = AABB(); } +}; + +template <> +struct VariantZeroAssigner<Basis> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_basis(v) = Basis(); } +}; + +template <> +struct VariantZeroAssigner<Transform> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_transform(v) = Transform(); } +}; + +template <> +struct VariantZeroAssigner<Color> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_color(v) = Color(); } +}; + +template <> +struct VariantZeroAssigner<StringName> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<NodePath> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<::RID> { + static _FORCE_INLINE_ void zero(Variant *v) { *VariantInternal::get_rid(v) = RID(); } +}; + +template <> +struct VariantZeroAssigner<Callable> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<Signal> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<Dictionary> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<Array> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<PackedByteArray> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<PackedInt32Array> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<PackedInt64Array> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<PackedFloat32Array> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<PackedFloat64Array> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<PackedStringArray> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<PackedVector2Array> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<PackedVector3Array> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <> +struct VariantZeroAssigner<PackedColorArray> { + static _FORCE_INLINE_ void zero(Variant *v) {} +}; + +template <class T> +struct VariantTypeChanger { + static _FORCE_INLINE_ void change(Variant *v) { + if (v->get_type() != GetTypeInfo<T>::VARIANT_TYPE || GetTypeInfo<T>::VARIANT_TYPE >= Variant::PACKED_BYTE_ARRAY) { //second condition removed by optimizer + VariantInternal::clear(v); + VariantInitializer<T>::init(v); + } + } + static _FORCE_INLINE_ void change_and_reset(Variant *v) { + if (v->get_type() != GetTypeInfo<T>::VARIANT_TYPE || GetTypeInfo<T>::VARIANT_TYPE >= Variant::PACKED_BYTE_ARRAY) { //second condition removed by optimizer + VariantInternal::clear(v); + VariantInitializer<T>::init(v); + } + + VariantZeroAssigner<T>::zero(v); + } +}; + #endif // VARIANT_INTERNAL_H diff --git a/core/variant_op.cpp b/core/variant/variant_op.cpp index 82722ea088..8e55c1d6cd 100644 --- a/core/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -30,9 +30,9 @@ #include "variant.h" -#include "core/class_db.h" #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" +#include "core/object/class_db.h" template <class R, class A, class B> class OperatorEvaluatorAdd { @@ -44,6 +44,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) + *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -64,6 +65,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) - *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -84,6 +86,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) * *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -104,6 +107,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<A>::get_ptr(left)->xform(*VariantGetInternalPtr<B>::get_ptr(right)); } #ifdef PTRCALL_ENABLED @@ -124,6 +128,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<B>::get_ptr(right)->xform_inv(*VariantGetInternalPtr<A>::get_ptr(left)); } #ifdef PTRCALL_ENABLED @@ -144,6 +149,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -169,6 +175,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -189,6 +196,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -214,6 +222,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -233,6 +242,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = -*VariantGetInternalPtr<A>::get_ptr(left); } #ifdef PTRCALL_ENABLED @@ -252,6 +262,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left); } #ifdef PTRCALL_ENABLED @@ -272,6 +283,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) << *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -292,6 +304,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >> *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -312,6 +325,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) | *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -352,6 +366,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) ^ *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -371,6 +386,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<R>::change(r_ret); *VariantGetInternalPtr<R>::get_ptr(r_ret) = ~*VariantGetInternalPtr<A>::get_ptr(left); } #ifdef PTRCALL_ENABLED @@ -391,6 +407,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) == *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -412,6 +429,7 @@ public: static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const Object *a = left->get_validated_object(); const Object *b = right->get_validated_object(); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == b; } #ifdef PTRCALL_ENABLED @@ -431,6 +449,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const Object *a = left->get_validated_object(); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == nullptr; } #ifdef PTRCALL_ENABLED @@ -450,6 +469,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const Object *b = right->get_validated_object(); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr == b; } #ifdef PTRCALL_ENABLED @@ -470,6 +490,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) != *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -491,6 +512,7 @@ public: static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { Object *a = left->get_validated_object(); Object *b = right->get_validated_object(); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != b; } #ifdef PTRCALL_ENABLED @@ -510,6 +532,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { Object *a = left->get_validated_object(); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != nullptr; } #ifdef PTRCALL_ENABLED @@ -529,6 +552,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { Object *b = right->get_validated_object(); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr != b; } #ifdef PTRCALL_ENABLED @@ -549,6 +573,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) < *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -569,6 +594,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) <= *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -589,6 +615,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) > *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -609,6 +636,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >= *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -629,6 +657,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) && *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -650,6 +679,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) || *VariantGetInternalPtr<B>::get_ptr(right); } #ifdef PTRCALL_ENABLED @@ -675,6 +705,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = xor_op(*VariantGetInternalPtr<A>::get_ptr(left), *VariantGetInternalPtr<B>::get_ptr(right)); } #ifdef PTRCALL_ENABLED @@ -695,6 +726,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<A>::get_ptr(left); } #ifdef PTRCALL_ENABLED @@ -729,6 +761,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<Array>::change(r_ret); _add_arrays(*VariantGetInternalPtr<Array>::get_ptr(r_ret), *VariantGetInternalPtr<Array>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right)); } #ifdef PTRCALL_ENABLED @@ -754,6 +787,7 @@ public: r_valid = true; } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<Vector<T>>::change(r_ret); *VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector<T>>::get_ptr(left); VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret)->append_array(*VariantGetInternalPtr<Vector<T>>::get_ptr(right)); } @@ -787,6 +821,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<String>::change(r_ret); *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), nullptr); } #ifdef PTRCALL_ENABLED @@ -813,6 +848,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<String>::change(r_ret); *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), nullptr); } #ifdef PTRCALL_ENABLED @@ -842,6 +878,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<String>::change(r_ret); *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), right->get_validated_object(), nullptr); } #ifdef PTRCALL_ENABLED @@ -871,6 +908,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<String>::change(r_ret); *VariantGetInternalPtr<String>::get_ptr(r_ret) = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), nullptr); } #ifdef PTRCALL_ENABLED @@ -890,6 +928,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = true; } #ifdef PTRCALL_ENABLED @@ -909,6 +948,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = false; } #ifdef PTRCALL_ENABLED @@ -962,6 +1002,7 @@ _FORCE_INLINE_ static bool _operate_get_object(const Variant *p_ptr) { } \ \ static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { \ + VariantTypeChanger<bool>::change(r_ret); \ *VariantGetInternalPtr<bool>::get_ptr(r_ret) = m_op(_operate_get_##m_left(left), _operate_get_##m_right(right)); \ } \ \ @@ -1002,6 +1043,7 @@ _FORCE_INLINE_ static bool _operate_get_ptr_object(const void *p_ptr) { } \ \ static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { \ + VariantTypeChanger<bool>::change(r_ret); \ *VariantGetInternalPtr<bool>::get_ptr(r_ret) = m_op(_operate_get_##m_left(left), _operate_get_##m_right(right)); \ } \ \ @@ -1168,6 +1210,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<bool>::get_ptr(left); } #ifdef PTRCALL_ENABLED @@ -1187,6 +1230,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<int64_t>::get_ptr(left); } #ifdef PTRCALL_ENABLED @@ -1206,6 +1250,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<double>::get_ptr(left); } #ifdef PTRCALL_ENABLED @@ -1225,6 +1270,7 @@ public: } static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = left->get_validated_object() == nullptr; } #ifdef PTRCALL_ENABLED @@ -1251,6 +1297,7 @@ public: static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const String &str_a = *VariantGetInternalPtr<String>::get_ptr(left); const String &str_b = *VariantGetInternalPtr<String>::get_ptr(right); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = str_b.find(str_a) != -1; } #ifdef PTRCALL_ENABLED @@ -1275,6 +1322,7 @@ public: static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const A &a = *VariantGetInternalPtr<A>::get_ptr(left); const B &b = *VariantGetInternalPtr<B>::get_ptr(right); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(a) != -1; } #ifdef PTRCALL_ENABLED @@ -1295,6 +1343,7 @@ public: static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(Variant()) != -1; } #ifdef PTRCALL_ENABLED @@ -1315,6 +1364,7 @@ public: static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(*left) != -1; } #ifdef PTRCALL_ENABLED @@ -1339,6 +1389,7 @@ public: static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); const A &a = *VariantGetInternalPtr<A>::get_ptr(left); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(a); } #ifdef PTRCALL_ENABLED @@ -1360,6 +1411,7 @@ public: static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(Variant()); } #ifdef PTRCALL_ENABLED @@ -1381,6 +1433,7 @@ public: static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(*left); } #ifdef PTRCALL_ENABLED @@ -1414,6 +1467,7 @@ public: bool valid; l->get(a, &valid); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid; } #ifdef PTRCALL_ENABLED @@ -1449,6 +1503,7 @@ public: bool valid; l->get(a, &valid); + VariantTypeChanger<bool>::change(r_ret); *VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid; } #ifdef PTRCALL_ENABLED @@ -1480,7 +1535,7 @@ void register_op(Variant::Operator p_op, Variant::Type p_type_a, Variant::Type p #endif } -void register_variant_operators() { +void Variant::_register_variant_operators() { zeromem(operator_return_type_table, sizeof(operator_return_type_table)); zeromem(operator_evaluator_table, sizeof(operator_evaluator_table)); zeromem(validated_operator_evaluator_table, sizeof(validated_operator_evaluator_table)); @@ -1568,8 +1623,8 @@ void register_variant_operators() { register_op<OperatorEvaluatorMul<Transform, Transform, Transform>>(Variant::OP_MULTIPLY, Variant::TRANSFORM, Variant::TRANSFORM); register_op<OperatorEvaluatorXForm<Vector3, Transform, Vector3>>(Variant::OP_MULTIPLY, Variant::TRANSFORM, Variant::VECTOR3); register_op<OperatorEvaluatorXFormInv<Vector3, Vector3, Transform>>(Variant::OP_MULTIPLY, Variant::VECTOR3, Variant::TRANSFORM); - register_op<OperatorEvaluatorXForm<AABB, Transform, AABB>>(Variant::OP_MULTIPLY, Variant::TRANSFORM, Variant::AABB); - register_op<OperatorEvaluatorXFormInv<AABB, AABB, Transform>>(Variant::OP_MULTIPLY, Variant::AABB, Variant::TRANSFORM); + register_op<OperatorEvaluatorXForm<::AABB, Transform, ::AABB>>(Variant::OP_MULTIPLY, Variant::TRANSFORM, Variant::AABB); + register_op<OperatorEvaluatorXFormInv<::AABB, ::AABB, Transform>>(Variant::OP_MULTIPLY, Variant::AABB, Variant::TRANSFORM); register_op<OperatorEvaluatorXForm<Vector<Vector3>, Transform, Vector<Vector3>>>(Variant::OP_MULTIPLY, Variant::TRANSFORM, Variant::PACKED_VECTOR3_ARRAY); register_op<OperatorEvaluatorXFormInv<Vector<Vector3>, Vector<Vector3>, Transform>>(Variant::OP_MULTIPLY, Variant::PACKED_VECTOR3_ARRAY, Variant::TRANSFORM); @@ -1645,7 +1700,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorStringModT<Transform2D>>(Variant::OP_MODULE, Variant::STRING, Variant::TRANSFORM2D); register_op<OperatorEvaluatorStringModT<Plane>>(Variant::OP_MODULE, Variant::STRING, Variant::PLANE); register_op<OperatorEvaluatorStringModT<Quat>>(Variant::OP_MODULE, Variant::STRING, Variant::QUAT); - register_op<OperatorEvaluatorStringModT<AABB>>(Variant::OP_MODULE, Variant::STRING, Variant::AABB); + register_op<OperatorEvaluatorStringModT<::AABB>>(Variant::OP_MODULE, Variant::STRING, Variant::AABB); register_op<OperatorEvaluatorStringModT<Basis>>(Variant::OP_MODULE, Variant::STRING, Variant::BASIS); register_op<OperatorEvaluatorStringModT<Transform>>(Variant::OP_MODULE, Variant::STRING, Variant::TRANSFORM); @@ -1713,7 +1768,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorEqual<Transform2D, Transform2D>>(Variant::OP_EQUAL, Variant::TRANSFORM2D, Variant::TRANSFORM2D); register_op<OperatorEvaluatorEqual<Plane, Plane>>(Variant::OP_EQUAL, Variant::PLANE, Variant::PLANE); register_op<OperatorEvaluatorEqual<Quat, Quat>>(Variant::OP_EQUAL, Variant::QUAT, Variant::QUAT); - register_op<OperatorEvaluatorEqual<AABB, AABB>>(Variant::OP_EQUAL, Variant::AABB, Variant::AABB); + register_op<OperatorEvaluatorEqual<::AABB, ::AABB>>(Variant::OP_EQUAL, Variant::AABB, Variant::AABB); register_op<OperatorEvaluatorEqual<Basis, Basis>>(Variant::OP_EQUAL, Variant::BASIS, Variant::BASIS); register_op<OperatorEvaluatorEqual<Transform, Transform>>(Variant::OP_EQUAL, Variant::TRANSFORM, Variant::TRANSFORM); register_op<OperatorEvaluatorEqual<Color, Color>>(Variant::OP_EQUAL, Variant::COLOR, Variant::COLOR); @@ -1723,7 +1778,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorEqual<StringName, StringName>>(Variant::OP_EQUAL, Variant::STRING_NAME, Variant::STRING_NAME); register_op<OperatorEvaluatorEqual<NodePath, NodePath>>(Variant::OP_EQUAL, Variant::NODE_PATH, Variant::NODE_PATH); - register_op<OperatorEvaluatorEqual<RID, RID>>(Variant::OP_EQUAL, Variant::_RID, Variant::_RID); + register_op<OperatorEvaluatorEqual<::RID, ::RID>>(Variant::OP_EQUAL, Variant::RID, Variant::RID); register_op<OperatorEvaluatorEqualObject>(Variant::OP_EQUAL, Variant::OBJECT, Variant::OBJECT); register_op<OperatorEvaluatorEqualObjectNil>(Variant::OP_EQUAL, Variant::OBJECT, Variant::NIL); @@ -1759,7 +1814,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorNotEqual<Transform2D, Transform2D>>(Variant::OP_NOT_EQUAL, Variant::TRANSFORM2D, Variant::TRANSFORM2D); register_op<OperatorEvaluatorNotEqual<Plane, Plane>>(Variant::OP_NOT_EQUAL, Variant::PLANE, Variant::PLANE); register_op<OperatorEvaluatorNotEqual<Quat, Quat>>(Variant::OP_NOT_EQUAL, Variant::QUAT, Variant::QUAT); - register_op<OperatorEvaluatorNotEqual<AABB, AABB>>(Variant::OP_NOT_EQUAL, Variant::AABB, Variant::AABB); + register_op<OperatorEvaluatorNotEqual<::AABB, ::AABB>>(Variant::OP_NOT_EQUAL, Variant::AABB, Variant::AABB); register_op<OperatorEvaluatorNotEqual<Basis, Basis>>(Variant::OP_NOT_EQUAL, Variant::BASIS, Variant::BASIS); register_op<OperatorEvaluatorNotEqual<Transform, Transform>>(Variant::OP_NOT_EQUAL, Variant::TRANSFORM, Variant::TRANSFORM); register_op<OperatorEvaluatorNotEqual<Color, Color>>(Variant::OP_NOT_EQUAL, Variant::COLOR, Variant::COLOR); @@ -1769,7 +1824,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorNotEqual<StringName, StringName>>(Variant::OP_NOT_EQUAL, Variant::STRING_NAME, Variant::STRING_NAME); register_op<OperatorEvaluatorNotEqual<NodePath, NodePath>>(Variant::OP_NOT_EQUAL, Variant::NODE_PATH, Variant::NODE_PATH); - register_op<OperatorEvaluatorNotEqual<RID, RID>>(Variant::OP_NOT_EQUAL, Variant::_RID, Variant::_RID); + register_op<OperatorEvaluatorNotEqual<::RID, ::RID>>(Variant::OP_NOT_EQUAL, Variant::RID, Variant::RID); register_op<OperatorEvaluatorNotEqualObject>(Variant::OP_NOT_EQUAL, Variant::OBJECT, Variant::OBJECT); register_op<OperatorEvaluatorNotEqualObjectNil>(Variant::OP_NOT_EQUAL, Variant::OBJECT, Variant::NIL); @@ -1799,7 +1854,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorLess<Vector2i, Vector2i>>(Variant::OP_LESS, Variant::VECTOR2I, Variant::VECTOR2I); register_op<OperatorEvaluatorLess<Vector3, Vector3>>(Variant::OP_LESS, Variant::VECTOR3, Variant::VECTOR3); register_op<OperatorEvaluatorLess<Vector3i, Vector3i>>(Variant::OP_LESS, Variant::VECTOR3I, Variant::VECTOR3I); - register_op<OperatorEvaluatorLess<RID, RID>>(Variant::OP_LESS, Variant::_RID, Variant::_RID); + register_op<OperatorEvaluatorLess<::RID, ::RID>>(Variant::OP_LESS, Variant::RID, Variant::RID); register_op<OperatorEvaluatorLess<Array, Array>>(Variant::OP_LESS, Variant::ARRAY, Variant::ARRAY); register_op<OperatorEvaluatorLessEqual<int64_t, int64_t>>(Variant::OP_LESS_EQUAL, Variant::INT, Variant::INT); @@ -1811,7 +1866,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorLessEqual<Vector2i, Vector2i>>(Variant::OP_LESS_EQUAL, Variant::VECTOR2I, Variant::VECTOR2I); register_op<OperatorEvaluatorLessEqual<Vector3, Vector3>>(Variant::OP_LESS_EQUAL, Variant::VECTOR3, Variant::VECTOR3); register_op<OperatorEvaluatorLessEqual<Vector3i, Vector3i>>(Variant::OP_LESS_EQUAL, Variant::VECTOR3I, Variant::VECTOR3I); - register_op<OperatorEvaluatorLessEqual<RID, RID>>(Variant::OP_LESS_EQUAL, Variant::_RID, Variant::_RID); + register_op<OperatorEvaluatorLessEqual<::RID, ::RID>>(Variant::OP_LESS_EQUAL, Variant::RID, Variant::RID); register_op<OperatorEvaluatorLessEqual<Array, Array>>(Variant::OP_LESS_EQUAL, Variant::ARRAY, Variant::ARRAY); register_op<OperatorEvaluatorGreater<bool, bool>>(Variant::OP_GREATER, Variant::BOOL, Variant::BOOL); @@ -1824,7 +1879,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorGreater<Vector2i, Vector2i>>(Variant::OP_GREATER, Variant::VECTOR2I, Variant::VECTOR2I); register_op<OperatorEvaluatorGreater<Vector3, Vector3>>(Variant::OP_GREATER, Variant::VECTOR3, Variant::VECTOR3); register_op<OperatorEvaluatorGreater<Vector3i, Vector3i>>(Variant::OP_GREATER, Variant::VECTOR3I, Variant::VECTOR3I); - register_op<OperatorEvaluatorGreater<RID, RID>>(Variant::OP_GREATER, Variant::_RID, Variant::_RID); + register_op<OperatorEvaluatorGreater<::RID, ::RID>>(Variant::OP_GREATER, Variant::RID, Variant::RID); register_op<OperatorEvaluatorGreater<Array, Array>>(Variant::OP_GREATER, Variant::ARRAY, Variant::ARRAY); register_op<OperatorEvaluatorGreaterEqual<int64_t, int64_t>>(Variant::OP_GREATER_EQUAL, Variant::INT, Variant::INT); @@ -1836,7 +1891,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorGreaterEqual<Vector2i, Vector2i>>(Variant::OP_GREATER_EQUAL, Variant::VECTOR2I, Variant::VECTOR2I); register_op<OperatorEvaluatorGreaterEqual<Vector3, Vector3>>(Variant::OP_GREATER_EQUAL, Variant::VECTOR3, Variant::VECTOR3); register_op<OperatorEvaluatorGreaterEqual<Vector3i, Vector3i>>(Variant::OP_GREATER_EQUAL, Variant::VECTOR3I, Variant::VECTOR3I); - register_op<OperatorEvaluatorGreaterEqual<RID, RID>>(Variant::OP_GREATER_EQUAL, Variant::_RID, Variant::_RID); + register_op<OperatorEvaluatorGreaterEqual<::RID, ::RID>>(Variant::OP_GREATER_EQUAL, Variant::RID, Variant::RID); register_op<OperatorEvaluatorGreaterEqual<Array, Array>>(Variant::OP_GREATER_EQUAL, Variant::ARRAY, Variant::ARRAY); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_OR, Variant::NIL, Variant::NIL>>(Variant::OP_OR, Variant::NIL, Variant::NIL); @@ -1948,7 +2003,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorInDictionaryHas<Transform2D>>(Variant::OP_IN, Variant::TRANSFORM2D, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHas<Plane>>(Variant::OP_IN, Variant::PLANE, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHas<Quat>>(Variant::OP_IN, Variant::QUAT, Variant::DICTIONARY); - register_op<OperatorEvaluatorInDictionaryHas<AABB>>(Variant::OP_IN, Variant::AABB, Variant::DICTIONARY); + register_op<OperatorEvaluatorInDictionaryHas<::AABB>>(Variant::OP_IN, Variant::AABB, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHas<Basis>>(Variant::OP_IN, Variant::BASIS, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHas<Transform>>(Variant::OP_IN, Variant::TRANSFORM, Variant::DICTIONARY); @@ -1985,7 +2040,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorInArrayFind<Transform2D, Array>>(Variant::OP_IN, Variant::TRANSFORM2D, Variant::ARRAY); register_op<OperatorEvaluatorInArrayFind<Plane, Array>>(Variant::OP_IN, Variant::PLANE, Variant::ARRAY); register_op<OperatorEvaluatorInArrayFind<Quat, Array>>(Variant::OP_IN, Variant::QUAT, Variant::ARRAY); - register_op<OperatorEvaluatorInArrayFind<AABB, Array>>(Variant::OP_IN, Variant::AABB, Variant::ARRAY); + register_op<OperatorEvaluatorInArrayFind<::AABB, Array>>(Variant::OP_IN, Variant::AABB, Variant::ARRAY); register_op<OperatorEvaluatorInArrayFind<Basis, Array>>(Variant::OP_IN, Variant::BASIS, Variant::ARRAY); register_op<OperatorEvaluatorInArrayFind<Transform, Array>>(Variant::OP_IN, Variant::TRANSFORM, Variant::ARRAY); @@ -2034,7 +2089,7 @@ void register_variant_operators() { register_op<OperatorEvaluatorObjectHasPropertyStringName>(Variant::OP_IN, Variant::STRING_NAME, Variant::OBJECT); } -void unregister_variant_operators() { +void Variant::_unregister_variant_operators() { } void Variant::evaluate(const Operator &p_op, const Variant &p_a, @@ -2090,8 +2145,8 @@ static const char *_op_names[Variant::OP_MAX] = { "-", "*", "/", - "- (negation)", - "+ (positive)", + "-", + "+", "%", "<<", ">>", diff --git a/core/variant_parser.cpp b/core/variant/variant_parser.cpp index 04cd4c1b9b..5a0bbf041b 100644 --- a/core/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -33,7 +33,7 @@ #include "core/input/input_event.h" #include "core/io/resource_loader.h" #include "core/os/keyboard.h" -#include "core/string_buffer.h" +#include "core/string/string_buffer.h" char32_t VariantParser::StreamFile::get_char() { return f->get_8(); diff --git a/core/variant_parser.h b/core/variant/variant_parser.h index 12329e2db6..59d18a8b9f 100644 --- a/core/variant_parser.h +++ b/core/variant/variant_parser.h @@ -31,9 +31,9 @@ #ifndef VARIANT_PARSER_H #define VARIANT_PARSER_H +#include "core/io/resource.h" #include "core/os/file_access.h" -#include "core/resource.h" -#include "core/variant.h" +#include "core/variant/variant.h" class VariantParser { public: diff --git a/core/variant_setget.cpp b/core/variant/variant_setget.cpp index 7e7f6c998f..05fe2b80d9 100644 --- a/core/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -30,11 +30,11 @@ #include "variant.h" -#include "core/class_db.h" #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" -#include "core/local_vector.h" -#include "core/variant_internal.h" +#include "core/object/class_db.h" +#include "core/templates/local_vector.h" +#include "core/variant/variant_internal.h" /**** NAMED SETTERS AND GETTERS ****/ @@ -2385,7 +2385,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & r_dst = a; } return; - case _RID: { + case RID: { r_dst = a; } return; @@ -2576,12 +2576,12 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } } -void register_variant_setters_getters() { +void Variant::_register_variant_setters_getters() { register_named_setters_getters(); register_indexed_setters_getters(); register_keyed_setters_getters(); } -void unregister_variant_setters_getters() { +void Variant::_unregister_variant_setters_getters() { unregister_named_setters_getters(); unregister_indexed_setters_getters(); } diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp new file mode 100644 index 0000000000..91a1b0262c --- /dev/null +++ b/core/variant/variant_utility.cpp @@ -0,0 +1,1392 @@ +/*************************************************************************/ +/* variant_utility.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 "variant.h" + +#include "core/core_string_names.h" +#include "core/io/marshalls.h" +#include "core/object/reference.h" +#include "core/os/os.h" +#include "core/templates/oa_hash_map.h" +#include "core/variant/binder_common.h" +#include "core/variant/variant_parser.h" + +struct VariantUtilityFunctions { + // Math + static inline double sin(double arg) { + return Math::sin(arg); + } + static inline double cos(double arg) { + return Math::cos(arg); + } + static inline double tan(double arg) { + return Math::tan(arg); + } + + static inline double sinh(double arg) { + return Math::sinh(arg); + } + static inline double cosh(double arg) { + return Math::cosh(arg); + } + static inline double tanh(double arg) { + return Math::tanh(arg); + } + + static inline double asin(double arg) { + return Math::asin(arg); + } + static inline double acos(double arg) { + return Math::acos(arg); + } + static inline double atan(double arg) { + return Math::atan(arg); + } + + static inline double atan2(double y, double x) { + return Math::atan2(y, x); + } + + static inline double sqrt(double x) { + return Math::sqrt(x); + } + + static inline double fmod(double b, double r) { + return Math::fmod(b, r); + } + + static inline double fposmod(double b, double r) { + return Math::fposmod(b, r); + } + + static inline double floor(double x) { + return Math::floor(x); + } + + static inline double ceil(double x) { + return Math::ceil(x); + } + + static inline double round(double x) { + return Math::round(x); + } + + static inline Variant abs(const Variant &x, Callable::CallError &r_error) { + r_error.error = Callable::CallError::CALL_OK; + switch (x.get_type()) { + case Variant::INT: { + return ABS(VariantInternalAccessor<int64_t>::get(&x)); + } break; + case Variant::FLOAT: { + return Math::absd(VariantInternalAccessor<double>::get(&x)); + } break; + case Variant::VECTOR2: { + return VariantInternalAccessor<Vector2>::get(&x).abs(); + } break; + case Variant::VECTOR2I: { + return VariantInternalAccessor<Vector2i>::get(&x).abs(); + } break; + case Variant::VECTOR3: { + return VariantInternalAccessor<Vector3>::get(&x).abs(); + } break; + case Variant::VECTOR3I: { + return VariantInternalAccessor<Vector3i>::get(&x).abs(); + } break; + default: { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; + return Variant(); + } + } + } + + static inline double absf(double x) { + return Math::absd(x); + } + + static inline int64_t absi(int64_t x) { + return ABS(x); + } + + static inline Variant sign(const Variant &x, Callable::CallError &r_error) { + r_error.error = Callable::CallError::CALL_OK; + switch (x.get_type()) { + case Variant::INT: { + return SGN(VariantInternalAccessor<int64_t>::get(&x)); + } break; + case Variant::FLOAT: { + return SGN(VariantInternalAccessor<double>::get(&x)); + } break; + case Variant::VECTOR2: { + return VariantInternalAccessor<Vector2>::get(&x).sign(); + } break; + case Variant::VECTOR2I: { + return VariantInternalAccessor<Vector2i>::get(&x).sign(); + } break; + case Variant::VECTOR3: { + return VariantInternalAccessor<Vector3>::get(&x).sign(); + } break; + case Variant::VECTOR3I: { + return VariantInternalAccessor<Vector3i>::get(&x).sign(); + } break; + default: { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; + return Variant(); + } + } + } + + static inline double signf(double x) { + return SGN(x); + } + + static inline int64_t signi(int64_t x) { + return SGN(x); + } + + static inline double pow(double x, double y) { + return Math::pow(x, y); + } + static inline double log(double x) { + return Math::log(x); + } + + static inline double exp(double x) { + return Math::exp(x); + } + + static inline double is_nan(double x) { + return Math::is_nan(x); + } + + static inline double is_inf(double x) { + return Math::is_inf(x); + } + + static inline double is_equal_approx(double x, double y) { + return Math::is_equal_approx(x, y); + } + + static inline double is_zero_approx(double x) { + return Math::is_zero_approx(x); + } + + static inline double ease(float x, float c) { + return Math::ease(x, c); + } + + static inline int step_decimals(float step) { + return Math::step_decimals(step); + } + + static inline int range_step_decimals(float step) { + return Math::range_step_decimals(step); + } + + static inline double stepify(double value, double step) { + return Math::stepify(value, step); + } + + static inline double lerp(double from, double to, double weight) { + return Math::lerp(from, to, weight); + } + + static inline double lerp_angle(double from, double to, double weight) { + return Math::lerp_angle(from, to, weight); + } + + static inline double inverse_lerp(double from, double to, double weight) { + return Math::inverse_lerp(from, to, weight); + } + + static inline double range_lerp(double value, double istart, double istop, double ostart, double ostop) { + return Math::range_lerp(value, istart, istop, ostart, ostop); + } + + static inline double smoothstep(double from, double to, double val) { + return Math::smoothstep(from, to, val); + } + + static inline double move_toward(double from, double to, double delta) { + return Math::move_toward(from, to, delta); + } + + static inline double dectime(double value, double amount, double step) { + return Math::dectime(value, amount, step); + } + + static inline double deg2rad(double angle_deg) { + return Math::deg2rad(angle_deg); + } + + static inline double rad2deg(double angle_rad) { + return Math::rad2deg(angle_rad); + } + + static inline double linear2db(double linear) { + return Math::linear2db(linear); + } + + static inline double db2linear(double db) { + return Math::db2linear(db); + } + + static inline Vector2 polar2cartesian(double r, double th) { + return Vector2(r * Math::cos(th), r * Math::sin(th)); + } + + static inline Vector2 cartesian2polar(double x, double y) { + return Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x)); + } + + static inline int64_t wrapi(int64_t value, int64_t min, int64_t max) { + return Math::wrapi(value, min, max); + } + static inline double wrapf(double value, double min, double max) { + return Math::wrapf(value, min, max); + } + + static inline Variant max(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { + if (p_argcount < 2) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.expected = 2; + return Variant(); + } + Variant base = *p_args[0]; + Variant ret; + for (int i = 1; i < p_argcount; i++) { + bool valid; + Variant::evaluate(Variant::OP_GREATER, base, *p_args[i], ret, valid); + if (!valid) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.expected = base.get_type(); + r_error.argument = i; + return Variant(); + } + if (ret.booleanize()) { + base = *p_args[i]; + } + } + r_error.error = Callable::CallError::CALL_OK; + return base; + } + + static inline double maxf(double x, double y) { + return MAX(x, y); + } + + static inline int64_t maxi(int64_t x, int64_t y) { + return MAX(x, y); + } + + static inline Variant min(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { + if (p_argcount < 2) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.expected = 2; + return Variant(); + } + Variant base = *p_args[0]; + Variant ret; + for (int i = 1; i < p_argcount; i++) { + bool valid; + Variant::evaluate(Variant::OP_LESS, base, *p_args[i], ret, valid); + if (!valid) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.expected = base.get_type(); + r_error.argument = i; + return Variant(); + } + if (ret.booleanize()) { + base = *p_args[i]; + } + } + r_error.error = Callable::CallError::CALL_OK; + return base; + } + + static inline double minf(double x, double y) { + return MIN(x, y); + } + + static inline int64_t mini(int64_t x, int64_t y) { + return MIN(x, y); + } + + static inline Variant clamp(const Variant &x, const Variant &min, const Variant &max, Callable::CallError &r_error) { + Variant value = x; + + Variant ret; + + bool valid; + Variant::evaluate(Variant::OP_LESS, value, min, ret, valid); + if (!valid) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.expected = value.get_type(); + r_error.argument = 1; + return Variant(); + } + if (ret.booleanize()) { + value = min; + } + Variant::evaluate(Variant::OP_GREATER, value, max, ret, valid); + if (!valid) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.expected = value.get_type(); + r_error.argument = 2; + return Variant(); + } + if (ret.booleanize()) { + value = max; + } + + r_error.error = Callable::CallError::CALL_OK; + + return value; + } + + static inline double clampf(double x, double min, double max) { + return CLAMP(x, min, max); + } + + static inline int64_t clampi(int64_t x, int64_t min, int64_t max) { + return CLAMP(x, min, max); + } + + static inline int64_t nearest_po2(int64_t x) { + return nearest_power_of_2_templated(uint64_t(x)); + } + + // Random + + static inline void randomize() { + Math::randomize(); + } + + static inline int64_t randi() { + return Math::rand(); + } + + static inline double randf() { + return Math::randf(); + } + + static inline int64_t randi_range(int64_t from, int64_t to) { + return Math::random((int32_t)from, (int32_t)to); + } + + static inline double randf_range(double from, double to) { + return Math::random(from, to); + } + + static inline void seed(int64_t s) { + return Math::seed(s); + } + + static inline PackedInt64Array rand_from_seed(int64_t seed) { + uint64_t s = seed; + PackedInt64Array arr; + arr.resize(2); + arr.write[0] = Math::rand_from_seed(&s); + arr.write[1] = s; + return arr; + } + + // Utility + + static inline Variant weakref(const Variant &obj, Callable::CallError &r_error) { + if (obj.get_type() == Variant::OBJECT) { + r_error.error = Callable::CallError::CALL_OK; + if (obj.is_ref()) { + Ref<WeakRef> wref = memnew(WeakRef); + REF r = obj; + if (r.is_valid()) { + wref->set_ref(r); + } + return wref; + } else { + Ref<WeakRef> wref = memnew(WeakRef); + Object *o = obj.get_validated_object(); + if (o) { + wref->set_obj(o); + } + return wref; + } + } else if (obj.get_type() == Variant::NIL) { + r_error.error = Callable::CallError::CALL_OK; + Ref<WeakRef> wref = memnew(WeakRef); + return wref; + } else { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::OBJECT; + return Variant(); + } + } + + static inline int64_t _typeof(const Variant &obj) { + return obj.get_type(); + } + + static inline String str(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + if (p_arg_count < 1) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 1; + return String(); + } + String str; + for (int i = 0; i < p_arg_count; i++) { + String os = p_args[i]->operator String(); + + if (i == 0) { + str = os; + } else { + str += os; + } + } + + r_error.error = Callable::CallError::CALL_OK; + + return str; + } + + static inline void print(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + if (p_arg_count < 1) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 1; + } + String str; + for (int i = 0; i < p_arg_count; i++) { + String os = p_args[i]->operator String(); + + if (i == 0) { + str = os; + } else { + str += os; + } + } + + print_line(str); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void printerr(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + if (p_arg_count < 1) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 1; + } + String str; + for (int i = 0; i < p_arg_count; i++) { + String os = p_args[i]->operator String(); + + if (i == 0) { + str = os; + } else { + str += os; + } + } + + print_error(str); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void printt(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + if (p_arg_count < 1) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 1; + } + String str; + for (int i = 0; i < p_arg_count; i++) { + if (i) { + str += "\t"; + } + str += p_args[i]->operator String(); + } + + print_error(str); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void prints(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + if (p_arg_count < 1) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 1; + } + String str; + for (int i = 0; i < p_arg_count; i++) { + if (i) { + str += " "; + } + str += p_args[i]->operator String(); + } + + print_error(str); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void printraw(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + if (p_arg_count < 1) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 1; + } + String str; + for (int i = 0; i < p_arg_count; i++) { + String os = p_args[i]->operator String(); + + if (i == 0) { + str = os; + } else { + str += os; + } + } + + OS::get_singleton()->print("%s", str.utf8().get_data()); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void push_error(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + if (p_arg_count < 1) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 1; + } + String str; + for (int i = 0; i < p_arg_count; i++) { + String os = p_args[i]->operator String(); + + if (i == 0) { + str = os; + } else { + str += os; + } + } + + ERR_PRINT(str); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline void push_warning(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + if (p_arg_count < 1) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 1; + } + String str; + for (int i = 0; i < p_arg_count; i++) { + String os = p_args[i]->operator String(); + + if (i == 0) { + str = os; + } else { + str += os; + } + } + + WARN_PRINT(str); + r_error.error = Callable::CallError::CALL_OK; + } + + static inline String var2str(const Variant &p_var) { + String vars; + VariantWriter::write_to_string(p_var, vars); + return vars; + } + + static inline Variant str2var(const String &p_var) { + VariantParser::StreamString ss; + ss.s = p_var; + + String errs; + int line; + Variant ret; + (void)VariantParser::parse(&ss, ret, errs, line); + + return ret; + } + + static inline PackedByteArray var2bytes(const Variant &p_var) { + int len; + Error err = encode_variant(p_var, nullptr, len, false); + if (err != OK) { + return PackedByteArray(); + } + + PackedByteArray barr; + barr.resize(len); + { + uint8_t *w = barr.ptrw(); + err = encode_variant(p_var, w, len, false); + if (err != OK) { + return PackedByteArray(); + } + } + + return barr; + } + + static inline PackedByteArray var2bytes_with_objects(const Variant &p_var) { + int len; + Error err = encode_variant(p_var, nullptr, len, true); + if (err != OK) { + return PackedByteArray(); + } + + PackedByteArray barr; + barr.resize(len); + { + uint8_t *w = barr.ptrw(); + err = encode_variant(p_var, w, len, true); + if (err != OK) { + return PackedByteArray(); + } + } + + return barr; + } + + static inline Variant bytes2var(const PackedByteArray &p_arr) { + Variant ret; + { + const uint8_t *r = p_arr.ptr(); + Error err = decode_variant(ret, r, p_arr.size(), nullptr, false); + if (err != OK) { + return Variant(); + } + } + return ret; + } + + static inline Variant bytes2var_with_objects(const PackedByteArray &p_arr) { + Variant ret; + { + const uint8_t *r = p_arr.ptr(); + Error err = decode_variant(ret, r, p_arr.size(), nullptr, true); + if (err != OK) { + return Variant(); + } + } + return ret; + } + + static inline int64_t hash(const Variant &p_arr) { + return p_arr.hash(); + } + + static inline Variant instance_from_id(int64_t p_id) { + ObjectID id = ObjectID((uint64_t)p_id); + Variant ret = ObjectDB::get_instance(id); + return ret; + } + + static inline bool is_instance_id_valid(int64_t p_id) { + return ObjectDB::get_instance(ObjectID((uint64_t)p_id)) != nullptr; + } + + static inline bool is_instance_valid(const Variant &p_instance) { + if (p_instance.get_type() != Variant::OBJECT) { + return false; + } + return p_instance.get_validated_object() != nullptr; + } +}; + +#ifdef DEBUG_METHODS_ENABLED +#define VCALLR *ret = p_func(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...) +#define VCALL p_func(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...) +#else +#define VCALLR *ret = p_func(VariantCaster<P>::cast(*p_args[Is])...) +#define VCALL p_func(VariantCaster<P>::cast(*p_args[Is])...) +#endif + +template <class R, class... P, size_t... Is> +static _FORCE_INLINE_ void call_helperpr(R (*p_func)(P...), Variant *ret, const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + VCALLR; + (void)p_args; // avoid gcc warning + (void)r_error; +} + +template <class R, class... P, size_t... Is> +static _FORCE_INLINE_ void validated_call_helperpr(R (*p_func)(P...), Variant *ret, const Variant **p_args, IndexSequence<Is...>) { + *ret = p_func(VariantCaster<P>::cast(*p_args[Is])...); + (void)p_args; +} + +template <class R, class... P, size_t... Is> +static _FORCE_INLINE_ void ptr_call_helperpr(R (*p_func)(P...), void *ret, const void **p_args, IndexSequence<Is...>) { + PtrToArg<R>::encode(p_func(PtrToArg<P>::convert(p_args[Is])...), ret); + (void)p_args; +} + +template <class R, class... P> +static _FORCE_INLINE_ void call_helperr(R (*p_func)(P...), Variant *ret, const Variant **p_args, Callable::CallError &r_error) { + call_helperpr(p_func, ret, p_args, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class R, class... P> +static _FORCE_INLINE_ void validated_call_helperr(R (*p_func)(P...), Variant *ret, const Variant **p_args) { + validated_call_helperpr(p_func, ret, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class R, class... P> +static _FORCE_INLINE_ void ptr_call_helperr(R (*p_func)(P...), void *ret, const void **p_args) { + ptr_call_helperpr(p_func, ret, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class R, class... P> +static _FORCE_INLINE_ int get_arg_count_helperr(R (*p_func)(P...)) { + return sizeof...(P); +} + +template <class R, class... P> +static _FORCE_INLINE_ Variant::Type get_arg_type_helperr(R (*p_func)(P...), int p_arg) { + return call_get_argument_type<P...>(p_arg); +} + +template <class R, class... P> +static _FORCE_INLINE_ Variant::Type get_ret_type_helperr(R (*p_func)(P...)) { + return GetTypeInfo<R>::VARIANT_TYPE; +} + +// WITHOUT RET + +template <class... P, size_t... Is> +static _FORCE_INLINE_ void call_helperp(void (*p_func)(P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + VCALL; + (void)p_args; + (void)r_error; +} + +template <class... P, size_t... Is> +static _FORCE_INLINE_ void validated_call_helperp(void (*p_func)(P...), const Variant **p_args, IndexSequence<Is...>) { + p_func(VariantCaster<P>::cast(*p_args[Is])...); + (void)p_args; +} + +template <class... P, size_t... Is> +static _FORCE_INLINE_ void ptr_call_helperp(void (*p_func)(P...), const void **p_args, IndexSequence<Is...>) { + p_func(PtrToArg<P>::convert(p_args[Is])...); + (void)p_args; +} + +template <class... P> +static _FORCE_INLINE_ void call_helper(void (*p_func)(P...), const Variant **p_args, Callable::CallError &r_error) { + call_helperp(p_func, p_args, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class... P> +static _FORCE_INLINE_ void validated_call_helper(void (*p_func)(P...), const Variant **p_args) { + validated_call_helperp(p_func, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class... P> +static _FORCE_INLINE_ void ptr_call_helper(void (*p_func)(P...), const void **p_args) { + ptr_call_helperp(p_func, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class... P> +static _FORCE_INLINE_ int get_arg_count_helper(void (*p_func)(P...)) { + return sizeof...(P); +} + +template <class... P> +static _FORCE_INLINE_ Variant::Type get_arg_type_helper(void (*p_func)(P...), int p_arg) { + return call_get_argument_type<P...>(p_arg); +} + +template <class... P> +static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) { + return Variant::NIL; +} + +#define FUNCBINDR(m_func, m_args, m_category) \ + class Func_##m_func { \ + public: \ + static void call(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { \ + call_helperr(VariantUtilityFunctions::m_func, r_ret, p_args, r_error); \ + } \ + \ + static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \ + validated_call_helperr(VariantUtilityFunctions::m_func, r_ret, p_args); \ + } \ + static void ptrcall(void *ret, const void **p_args, int p_argcount) { \ + ptr_call_helperr(VariantUtilityFunctions::m_func, ret, p_args); \ + } \ + \ + static int get_argument_count() { \ + return get_arg_count_helperr(VariantUtilityFunctions::m_func); \ + } \ + \ + static Variant::Type get_argument_type(int p_arg) { \ + return get_arg_type_helperr(VariantUtilityFunctions::m_func, p_arg); \ + } \ + \ + static Variant::Type get_return_type() { \ + return get_ret_type_helperr(VariantUtilityFunctions::m_func); \ + } \ + static bool has_return_type() { \ + return true; \ + } \ + static bool is_vararg() { return false; } \ + static Variant::UtilityFunctionType get_type() { return m_category; } \ + }; \ + register_utility_function<Func_##m_func>(#m_func, m_args) + +#define FUNCBINDVR(m_func, m_args, m_category) \ + class Func_##m_func { \ + public: \ + static void call(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { \ + r_error.error = Callable::CallError::CALL_OK; \ + *r_ret = VariantUtilityFunctions::m_func(*p_args[0], r_error); \ + } \ + \ + static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \ + Callable::CallError ce; \ + *r_ret = VariantUtilityFunctions::m_func(*p_args[0], ce); \ + } \ + static void ptrcall(void *ret, const void **p_args, int p_argcount) { \ + Callable::CallError ce; \ + PtrToArg<Variant>::encode(VariantUtilityFunctions::m_func(PtrToArg<Variant>::convert(p_args[0]), ce), ret); \ + } \ + \ + static int get_argument_count() { \ + return 1; \ + } \ + \ + static Variant::Type get_argument_type(int p_arg) { \ + return Variant::NIL; \ + } \ + \ + static Variant::Type get_return_type() { \ + return Variant::NIL; \ + } \ + static bool has_return_type() { \ + return true; \ + } \ + static bool is_vararg() { return false; } \ + static Variant::UtilityFunctionType get_type() { return m_category; } \ + }; \ + register_utility_function<Func_##m_func>(#m_func, m_args) + +#define FUNCBINDVR3(m_func, m_args, m_category) \ + class Func_##m_func { \ + public: \ + static void call(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { \ + r_error.error = Callable::CallError::CALL_OK; \ + *r_ret = VariantUtilityFunctions::m_func(*p_args[0], *p_args[1], *p_args[2], r_error); \ + } \ + \ + static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \ + Callable::CallError ce; \ + *r_ret = VariantUtilityFunctions::m_func(*p_args[0], *p_args[1], *p_args[2], ce); \ + } \ + static void ptrcall(void *ret, const void **p_args, int p_argcount) { \ + Callable::CallError ce; \ + Variant r; \ + r = VariantUtilityFunctions::m_func(PtrToArg<Variant>::convert(p_args[0]), PtrToArg<Variant>::convert(p_args[1]), PtrToArg<Variant>::convert(p_args[2]), ce); \ + PtrToArg<Variant>::encode(r, ret); \ + } \ + \ + static int get_argument_count() { \ + return 3; \ + } \ + \ + static Variant::Type get_argument_type(int p_arg) { \ + return Variant::NIL; \ + } \ + \ + static Variant::Type get_return_type() { \ + return Variant::NIL; \ + } \ + static bool has_return_type() { \ + return true; \ + } \ + static bool is_vararg() { return false; } \ + static Variant::UtilityFunctionType get_type() { return m_category; } \ + }; \ + register_utility_function<Func_##m_func>(#m_func, m_args) + +#define FUNCBINDVARARG(m_func, m_args, m_category) \ + class Func_##m_func { \ + public: \ + static void call(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { \ + r_error.error = Callable::CallError::CALL_OK; \ + *r_ret = VariantUtilityFunctions::m_func(p_args, p_argcount, r_error); \ + } \ + \ + static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \ + Callable::CallError c; \ + *r_ret = VariantUtilityFunctions::m_func(p_args, p_argcount, c); \ + } \ + static void ptrcall(void *ret, const void **p_args, int p_argcount) { \ + Vector<Variant> args; \ + for (int i = 0; i < p_argcount; i++) { \ + args.push_back(PtrToArg<Variant>::convert(p_args[i])); \ + } \ + Vector<const Variant *> argsp; \ + for (int i = 0; i < p_argcount; i++) { \ + argsp.push_back(&args[i]); \ + } \ + Variant r; \ + validated_call(&r, (const Variant **)argsp.ptr(), p_argcount); \ + PtrToArg<Variant>::encode(r, ret); \ + } \ + \ + static int get_argument_count() { \ + return 2; \ + } \ + \ + static Variant::Type get_argument_type(int p_arg) { \ + return Variant::NIL; \ + } \ + \ + static Variant::Type get_return_type() { \ + return Variant::NIL; \ + } \ + static bool has_return_type() { \ + return true; \ + } \ + static bool is_vararg() { \ + return true; \ + } \ + static Variant::UtilityFunctionType get_type() { \ + return m_category; \ + } \ + }; \ + register_utility_function<Func_##m_func>(#m_func, m_args) + +#define FUNCBINDVARARGS(m_func, m_args, m_category) \ + class Func_##m_func { \ + public: \ + static void call(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { \ + r_error.error = Callable::CallError::CALL_OK; \ + *r_ret = VariantUtilityFunctions::m_func(p_args, p_argcount, r_error); \ + } \ + \ + static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \ + Callable::CallError c; \ + *r_ret = VariantUtilityFunctions::m_func(p_args, p_argcount, c); \ + } \ + static void ptrcall(void *ret, const void **p_args, int p_argcount) { \ + Vector<Variant> args; \ + for (int i = 0; i < p_argcount; i++) { \ + args.push_back(PtrToArg<Variant>::convert(p_args[i])); \ + } \ + Vector<const Variant *> argsp; \ + for (int i = 0; i < p_argcount; i++) { \ + argsp.push_back(&args[i]); \ + } \ + Variant r; \ + validated_call(&r, (const Variant **)argsp.ptr(), p_argcount); \ + PtrToArg<String>::encode(r.operator String(), ret); \ + } \ + \ + static int get_argument_count() { \ + return 1; \ + } \ + \ + static Variant::Type get_argument_type(int p_arg) { \ + return Variant::NIL; \ + } \ + \ + static Variant::Type get_return_type() { \ + return Variant::STRING; \ + } \ + static bool has_return_type() { \ + return true; \ + } \ + static bool is_vararg() { \ + return true; \ + } \ + static Variant::UtilityFunctionType get_type() { \ + return m_category; \ + } \ + }; \ + register_utility_function<Func_##m_func>(#m_func, m_args) + +#define FUNCBINDVARARGV(m_func, m_args, m_category) \ + class Func_##m_func { \ + public: \ + static void call(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { \ + r_error.error = Callable::CallError::CALL_OK; \ + VariantUtilityFunctions::m_func(p_args, p_argcount, r_error); \ + } \ + \ + static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \ + Callable::CallError c; \ + VariantUtilityFunctions::m_func(p_args, p_argcount, c); \ + } \ + static void ptrcall(void *ret, const void **p_args, int p_argcount) { \ + Vector<Variant> args; \ + for (int i = 0; i < p_argcount; i++) { \ + args.push_back(PtrToArg<Variant>::convert(p_args[i])); \ + } \ + Vector<const Variant *> argsp; \ + for (int i = 0; i < p_argcount; i++) { \ + argsp.push_back(&args[i]); \ + } \ + Variant r; \ + validated_call(&r, (const Variant **)argsp.ptr(), p_argcount); \ + } \ + \ + static int get_argument_count() { \ + return 1; \ + } \ + \ + static Variant::Type get_argument_type(int p_arg) { \ + return Variant::NIL; \ + } \ + \ + static Variant::Type get_return_type() { \ + return Variant::NIL; \ + } \ + static bool has_return_type() { \ + return false; \ + } \ + static bool is_vararg() { \ + return true; \ + } \ + static Variant::UtilityFunctionType get_type() { \ + return m_category; \ + } \ + }; \ + register_utility_function<Func_##m_func>(#m_func, m_args) + +#define FUNCBIND(m_func, m_args, m_category) \ + class Func_##m_func { \ + public: \ + static void call(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { \ + call_helper(VariantUtilityFunctions::m_func, p_args, r_error); \ + } \ + \ + static void validated_call(Variant *r_ret, const Variant **p_args, int p_argcount) { \ + validated_call_helper(VariantUtilityFunctions::m_func, p_args); \ + } \ + static void ptrcall(void *ret, const void **p_args, int p_argcount) { \ + ptr_call_helper(VariantUtilityFunctions::m_func, p_args); \ + } \ + \ + static int get_argument_count() { \ + return get_arg_count_helper(VariantUtilityFunctions::m_func); \ + } \ + \ + static Variant::Type get_argument_type(int p_arg) { \ + return get_arg_type_helper(VariantUtilityFunctions::m_func, p_arg); \ + } \ + \ + static Variant::Type get_return_type() { \ + return get_ret_type_helper(VariantUtilityFunctions::m_func); \ + } \ + static bool has_return_type() { \ + return false; \ + } \ + static bool is_vararg() { return false; } \ + static Variant::UtilityFunctionType get_type() { return m_category; } \ + }; \ + register_utility_function<Func_##m_func>(#m_func, m_args) + +struct VariantUtilityFunctionInfo { + void (*call_utility)(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error); + Variant::ValidatedUtilityFunction validated_call_utility; + Variant::PTRUtilityFunction ptr_call_utility; + Vector<String> argnames; + bool is_vararg; + bool returns_value; + int argcount; + Variant::Type (*get_arg_type)(int); + Variant::Type return_type; + Variant::UtilityFunctionType type; +}; + +static OAHashMap<StringName, VariantUtilityFunctionInfo> utility_function_table; +static List<StringName> utility_function_name_table; + +template <class T> +static void register_utility_function(const String &p_name, const Vector<String> &argnames) { + String name = p_name; + if (name.begins_with("_")) { + name = name.substr(1, name.length() - 1); + } + StringName sname = name; + ERR_FAIL_COND(utility_function_table.has(sname)); + + VariantUtilityFunctionInfo bfi; + bfi.call_utility = T::call; + bfi.validated_call_utility = T::validated_call; + bfi.ptr_call_utility = T::ptrcall; + bfi.is_vararg = T::is_vararg(); + bfi.argnames = argnames; + bfi.argcount = T::get_argument_count(); + if (!bfi.is_vararg) { + ERR_FAIL_COND_MSG(argnames.size() != bfi.argcount, "wrong number of arguments binding utility function: " + name); + } + bfi.get_arg_type = T::get_argument_type; + bfi.return_type = T::get_return_type(); + bfi.type = T::get_type(); + bfi.returns_value = T::has_return_type(); + + utility_function_table.insert(sname, bfi); + utility_function_name_table.push_back(sname); +} + +void Variant::_register_variant_utility_functions() { + // Math + + FUNCBINDR(sin, sarray("angle_rad"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(cos, sarray("angle_rad"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(tan, sarray("angle_rad"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(sinh, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(cosh, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(tanh, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(asin, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(acos, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(atan, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(atan2, sarray("y", "x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(sqrt, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(fmod, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(fposmod, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(floor, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(ceil, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(round, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDVR(abs, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(absf, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(absi, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDVR(sign, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(signf, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(signi, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(pow, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(log, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(exp, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(is_nan, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(is_inf, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(is_equal_approx, sarray("a", "b"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(is_zero_approx, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(ease, sarray("x", "c"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(step_decimals, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(range_step_decimals, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(stepify, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(lerp, sarray("from", "to", "c"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(lerp_angle, sarray("from", "to", "c"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(inverse_lerp, sarray("from", "to", "c"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(range_lerp, sarray("value", "istart", "istop", "ostart", "ostop"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(smoothstep, sarray("from", "to", "c"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(move_toward, sarray("from", "to", "delta"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(dectime, sarray("value", "amount", "step"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(deg2rad, sarray("deg"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(rad2deg, sarray("rad"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(linear2db, sarray("lin"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(db2linear, sarray("db"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(polar2cartesian, sarray("r", "th"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(cartesian2polar, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(wrapi, sarray("value", "min", "max"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(wrapf, sarray("value", "min", "max"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDVARARG(max, sarray(), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(maxi, sarray("a", "b"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(maxf, sarray("a", "b"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDVARARG(min, sarray(), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(mini, sarray("a", "b"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(minf, sarray("a", "b"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDVR3(clamp, sarray("value", "min", "max"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(clampi, sarray("value", "min", "max"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(clampf, sarray("value", "min", "max"), Variant::UTILITY_FUNC_TYPE_MATH); + + FUNCBINDR(nearest_po2, sarray("value"), Variant::UTILITY_FUNC_TYPE_MATH); + + //Random + + FUNCBIND(randomize, sarray(), Variant::UTILITY_FUNC_TYPE_RANDOM); + FUNCBINDR(randi, sarray(), Variant::UTILITY_FUNC_TYPE_RANDOM); + FUNCBINDR(randf, sarray(), Variant::UTILITY_FUNC_TYPE_RANDOM); + FUNCBINDR(randi_range, sarray("from", "to"), Variant::UTILITY_FUNC_TYPE_RANDOM); + FUNCBINDR(randf_range, sarray("from", "to"), Variant::UTILITY_FUNC_TYPE_RANDOM); + FUNCBIND(seed, sarray("base"), Variant::UTILITY_FUNC_TYPE_RANDOM); + FUNCBINDR(rand_from_seed, sarray("seed"), Variant::UTILITY_FUNC_TYPE_RANDOM); + + // Utility + FUNCBINDVR(weakref, sarray("from"), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDR(_typeof, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDVARARGS(str, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDVARARGV(print, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDVARARGV(printerr, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDVARARGV(printt, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDVARARGV(prints, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDVARARGV(printraw, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDVARARGV(push_error, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDVARARGV(push_warning, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); + + FUNCBINDR(var2str, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDR(str2var, sarray("string"), Variant::UTILITY_FUNC_TYPE_GENERAL); + + FUNCBINDR(var2bytes, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDR(bytes2var, sarray("bytes"), Variant::UTILITY_FUNC_TYPE_GENERAL); + + FUNCBINDR(var2bytes_with_objects, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDR(bytes2var_with_objects, sarray("bytes"), Variant::UTILITY_FUNC_TYPE_GENERAL); + + FUNCBINDR(hash, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL); + + FUNCBINDR(instance_from_id, sarray("id"), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDR(is_instance_id_valid, sarray("id"), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDR(is_instance_valid, sarray("instance"), Variant::UTILITY_FUNC_TYPE_GENERAL); +} +void Variant::_unregister_variant_utility_functions() { + utility_function_table.clear(); + utility_function_name_table.clear(); +} + +void Variant::call_utility_function(const StringName &p_name, Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; + r_error.argument = 0; + r_error.expected = 0; + return; + } + + if (unlikely(!bfi->is_vararg && p_argcount < bfi->argcount)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 0; + r_error.expected = bfi->argcount; + return; + } + + if (unlikely(!bfi->is_vararg && p_argcount > bfi->argcount)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = 0; + r_error.expected = bfi->argcount; + return; + } + + bfi->call_utility(r_ret, p_args, p_argcount, r_error); +} + +bool Variant::has_utility_function(const StringName &p_name) { + return utility_function_table.has(p_name); +} + +Variant::ValidatedUtilityFunction Variant::get_validated_utility_function(const StringName &p_name) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + return nullptr; + } + + return bfi->validated_call_utility; +} +Variant::PTRUtilityFunction Variant::get_ptr_utility_function(const StringName &p_name) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + return nullptr; + } + + return bfi->ptr_call_utility; +} + +Variant::UtilityFunctionType Variant::get_utility_function_type(const StringName &p_name) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + return Variant::UTILITY_FUNC_TYPE_MATH; + } + + return bfi->type; +} + +int Variant::get_utility_function_argument_count(const StringName &p_name) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + return 0; + } + + return bfi->argcount; +} +Variant::Type Variant::get_utility_function_argument_type(const StringName &p_name, int p_arg) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + return Variant::NIL; + } + + return bfi->get_arg_type(p_arg); +} +String Variant::get_utility_function_argument_name(const StringName &p_name, int p_arg) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + return String(); + } + ERR_FAIL_COND_V(bfi->is_vararg, String()); + ERR_FAIL_INDEX_V(p_arg, bfi->argnames.size(), String()); + return bfi->argnames[p_arg]; +} +bool Variant::has_utility_function_return_value(const StringName &p_name) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + return false; + } + return bfi->returns_value; +} +Variant::Type Variant::get_utility_function_return_type(const StringName &p_name) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + return Variant::NIL; + } + + return bfi->return_type; +} +bool Variant::is_utility_function_vararg(const StringName &p_name) { + const VariantUtilityFunctionInfo *bfi = utility_function_table.lookup_ptr(p_name); + if (!bfi) { + return false; + } + + return bfi->is_vararg; +} + +void Variant::get_utility_function_list(List<StringName> *r_functions) { + for (List<StringName>::Element *E = utility_function_name_table.front(); E; E = E->next()) { + r_functions->push_back(E->get()); + } +} |