summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub21
-rw-r--r--core/color.h34
-rw-r--r--core/command_queue_mt.h83
-rw-r--r--core/global_config.cpp77
-rw-r--r--core/global_constants.cpp6
-rw-r--r--core/helper/math_fieldwise.cpp10
-rw-r--r--core/image.cpp837
-rw-r--r--core/image.h50
-rw-r--r--core/input_map.cpp138
-rw-r--r--core/input_map.h18
-rw-r--r--core/io/compression.cpp20
-rw-r--r--core/io/compression.h9
-rw-r--r--core/io/file_access_compressed.cpp2
-rw-r--r--core/io/file_access_compressed.h2
-rw-r--r--core/io/image_loader.cpp4
-rw-r--r--core/io/image_loader.h4
-rw-r--r--core/io/marshalls.cpp157
-rw-r--r--core/io/resource_format_binary.cpp34
-rw-r--r--core/io/resource_import.h1
-rw-r--r--core/math/a_star.cpp16
-rw-r--r--core/math/a_star.h2
-rw-r--r--core/math/bsp_tree.cpp6
-rw-r--r--core/math/camera_matrix.cpp8
-rw-r--r--core/math/face3.cpp28
-rw-r--r--core/math/face3.h54
-rw-r--r--core/math/geometry.cpp6
-rw-r--r--core/math/math_2d.cpp2
-rw-r--r--core/math/math_2d.h229
-rw-r--r--core/math/math_funcs.h8
-rw-r--r--core/math/octree.h26
-rw-r--r--core/math/quick_hull.cpp2
-rw-r--r--core/math/rect3.cpp92
-rw-r--r--core/math/rect3.h118
-rw-r--r--core/math/transform.h38
-rw-r--r--core/math/triangle_mesh.cpp6
-rw-r--r--core/method_bind.h1
-rw-r--r--core/method_ptrcall.h2
-rw-r--r--core/object.cpp12
-rw-r--r--core/object.h12
-rw-r--r--core/os/file_access.cpp21
-rw-r--r--core/os/file_access.h1
-rw-r--r--core/os/input.h4
-rw-r--r--core/os/input_event.cpp984
-rw-r--r--core/os/input_event.h315
-rw-r--r--core/os/main_loop.cpp4
-rw-r--r--core/os/main_loop.h2
-rw-r--r--core/os/os.h2
-rw-r--r--core/packed_data_container.cpp1
-rw-r--r--core/register_core_types.cpp12
-rw-r--r--core/ustring.cpp12
-rw-r--r--core/variant.cpp51
-rw-r--r--core/variant.h6
-rw-r--r--core/variant_call.cpp31
-rw-r--r--core/variant_op.cpp748
-rw-r--r--core/variant_parser.cpp344
55 files changed, 2404 insertions, 2309 deletions
diff --git a/core/SCsub b/core/SCsub
index fd3f57dd7c..da2403f1d3 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -83,6 +83,25 @@ thirdparty_minizip_sources = [
thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
env.add_source_files(env.core_sources, thirdparty_minizip_sources)
+thirdparty_zstd_dir = "#thirdparty/zstd/"
+thirdparty_zstd_sources = [
+ "common/entropy_common.c",
+ "common/error_private.c",
+ "common/fse_decompress.c",
+ "common/pool.c",
+ "common/threading.c",
+ "common/xxhash.c",
+ "common/zstd_common.c",
+ "compress/fse_compress.c",
+ "compress/huf_compress.c",
+ "compress/zstd_compress.c",
+ "compress/zstdmt_compress.c",
+ "decompress/huf_decompress.c",
+ "decompress/zstd_decompress.c",
+]
+thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
+env.add_source_files(env.core_sources, thirdparty_zstd_sources)
+
# Godot's own sources
env.add_source_files(env.core_sources, "*.cpp")
@@ -104,5 +123,5 @@ SConscript('helper/SCsub')
# Build it all as a library
lib = env.Library("core", env.core_sources)
env.Prepend(LIBS=[lib])
-
+env.Append(CPPPATH=["#thirdparty/zstd", "#thirdparty/zstd/common"])
Export('env')
diff --git a/core/color.h b/core/color.h
index 46386fac64..c83dcda4b4 100644
--- a/core/color.h
+++ b/core/color.h
@@ -83,6 +83,40 @@ struct Color {
return res;
}
+ _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 cRed = MAX(0.0f, MIN(sharedexp, r));
+ float cGreen = MAX(0.0f, MIN(sharedexp, g));
+ float cBlue = MAX(0.0f, MIN(sharedexp, b));
+
+ 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);
+
+ float exps = expp + 1.0f;
+
+ if (0.0 <= sMax && sMax < pow2to9) {
+ exps = expp;
+ }
+
+ float sRed = Math::floor((cRed / pow(2.0f, exps - B - N)) + 0.5f);
+ float sGreen = Math::floor((cGreen / pow(2.0f, exps - B - N)) + 0.5f);
+ float sBlue = Math::floor((cBlue / pow(2.0f, exps - B - N)) + 0.5f);
+
+ return (uint32_t(Math::fast_ftoi(sRed)) & 0x1FF) | ((uint32_t(Math::fast_ftoi(sGreen)) & 0x1FF) << 9) | ((uint32_t(Math::fast_ftoi(sBlue)) & 0x1FF) << 18) | ((uint32_t(Math::fast_ftoi(exps)) & 0x1F) << 27);
+ }
+
_FORCE_INLINE_ Color blend(const Color &p_over) const {
Color res;
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index bae8cf7fca..83c90a925c 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -170,6 +170,43 @@ class CommandQueueMT {
virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8); }
};
+ template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9>
+ struct Command9 : public CommandBase {
+
+ T *instance;
+ M method;
+ typename GetSimpleTypeT<P1>::type_t p1;
+ typename GetSimpleTypeT<P2>::type_t p2;
+ typename GetSimpleTypeT<P3>::type_t p3;
+ typename GetSimpleTypeT<P4>::type_t p4;
+ typename GetSimpleTypeT<P5>::type_t p5;
+ typename GetSimpleTypeT<P6>::type_t p6;
+ typename GetSimpleTypeT<P7>::type_t p7;
+ typename GetSimpleTypeT<P8>::type_t p8;
+ typename GetSimpleTypeT<P9>::type_t p9;
+
+ virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9); }
+ };
+
+ template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10>
+ struct Command10 : public CommandBase {
+
+ T *instance;
+ M method;
+ typename GetSimpleTypeT<P1>::type_t p1;
+ typename GetSimpleTypeT<P2>::type_t p2;
+ typename GetSimpleTypeT<P3>::type_t p3;
+ typename GetSimpleTypeT<P4>::type_t p4;
+ typename GetSimpleTypeT<P5>::type_t p5;
+ typename GetSimpleTypeT<P6>::type_t p6;
+ typename GetSimpleTypeT<P7>::type_t p7;
+ typename GetSimpleTypeT<P8>::type_t p8;
+ typename GetSimpleTypeT<P9>::type_t p9;
+ typename GetSimpleTypeT<P10>::type_t p10;
+
+ virtual void call() { (instance->*method)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); }
+ };
+
/* comands that return */
template <class T, class M, class R>
@@ -779,6 +816,52 @@ public:
if (sync) sync->post();
}
+
+ template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9>
+ void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) {
+
+ Command9<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9> *cmd = allocate_and_lock<Command9<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9> >();
+
+ cmd->instance = p_instance;
+ cmd->method = p_method;
+ cmd->p1 = p1;
+ cmd->p2 = p2;
+ cmd->p3 = p3;
+ cmd->p4 = p4;
+ cmd->p5 = p5;
+ cmd->p6 = p6;
+ cmd->p7 = p7;
+ cmd->p8 = p8;
+ cmd->p9 = p9;
+
+ unlock();
+
+ if (sync) sync->post();
+ }
+
+ template <class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9, class P10>
+ void push(T *p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) {
+
+ Command10<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> *cmd = allocate_and_lock<Command10<T, M, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10> >();
+
+ cmd->instance = p_instance;
+ cmd->method = p_method;
+ cmd->p1 = p1;
+ cmd->p2 = p2;
+ cmd->p3 = p3;
+ cmd->p4 = p4;
+ cmd->p5 = p5;
+ cmd->p6 = p6;
+ cmd->p7 = p7;
+ cmd->p8 = p8;
+ cmd->p9 = p9;
+ cmd->p10 = p10;
+
+ unlock();
+
+ if (sync) sync->post();
+ }
+
/*** PUSH AND RET COMMANDS ***/
template <class T, class M, class R>
diff --git a/core/global_config.cpp b/core/global_config.cpp
index 81b923f01e..0729d4c482 100644
--- a/core/global_config.cpp
+++ b/core/global_config.cpp
@@ -39,6 +39,8 @@
#include "os/os.h"
#include "variant_parser.h"
+#include <zlib.h>
+
#define FORMAT_VERSION 3
GlobalConfig *GlobalConfig::singleton = NULL;
@@ -846,10 +848,8 @@ GlobalConfig::GlobalConfig() {
registering_order = true;
Array va;
- InputEvent key;
- key.type = InputEvent::KEY;
- InputEvent joyb;
- joyb.type = InputEvent::JOYPAD_BUTTON;
+ Ref<InputEventKey> key;
+ Ref<InputEventJoypadButton> joyb;
GLOBAL_DEF("application/name", "");
GLOBAL_DEF("application/main_scene", "");
@@ -858,87 +858,106 @@ GlobalConfig::GlobalConfig() {
GLOBAL_DEF("application/disable_stderr", false);
GLOBAL_DEF("application/use_shared_user_dir", true);
- key.key.scancode = KEY_RETURN;
+ key.instance();
+ key->set_scancode(KEY_RETURN);
va.push_back(key);
- key.key.scancode = KEY_ENTER;
+ key.instance();
+ key->set_scancode(KEY_ENTER);
va.push_back(key);
- key.key.scancode = KEY_SPACE;
+ key.instance();
+ key->set_scancode(KEY_SPACE);
va.push_back(key);
- joyb.joy_button.button_index = JOY_BUTTON_0;
+ joyb.instance();
+ joyb->set_button_index(JOY_BUTTON_0);
va.push_back(joyb);
GLOBAL_DEF("input/ui_accept", va);
input_presets.push_back("input/ui_accept");
va = Array();
- key.key.scancode = KEY_SPACE;
+ key.instance();
+ key->set_scancode(KEY_SPACE);
va.push_back(key);
- joyb.joy_button.button_index = JOY_BUTTON_3;
+ joyb.instance();
+ joyb->set_button_index(JOY_BUTTON_3);
va.push_back(joyb);
GLOBAL_DEF("input/ui_select", va);
input_presets.push_back("input/ui_select");
va = Array();
- key.key.scancode = KEY_ESCAPE;
+ key.instance();
+ key->set_scancode(KEY_ESCAPE);
va.push_back(key);
- joyb.joy_button.button_index = JOY_BUTTON_1;
+ joyb.instance();
+ joyb->set_button_index(JOY_BUTTON_1);
va.push_back(joyb);
GLOBAL_DEF("input/ui_cancel", va);
input_presets.push_back("input/ui_cancel");
va = Array();
- key.key.scancode = KEY_TAB;
+ key.instance();
+ key->set_scancode(KEY_TAB);
va.push_back(key);
GLOBAL_DEF("input/ui_focus_next", va);
input_presets.push_back("input/ui_focus_next");
va = Array();
- key.key.scancode = KEY_TAB;
- key.key.mod.shift = true;
+ key.instance();
+ key->set_scancode(KEY_TAB);
+ key->set_shift(true);
va.push_back(key);
GLOBAL_DEF("input/ui_focus_prev", va);
input_presets.push_back("input/ui_focus_prev");
- key.key.mod.shift = false;
va = Array();
- key.key.scancode = KEY_LEFT;
+ key.instance();
+ key->set_scancode(KEY_LEFT);
va.push_back(key);
- joyb.joy_button.button_index = JOY_DPAD_LEFT;
+ joyb.instance();
+ joyb->set_button_index(JOY_DPAD_LEFT);
va.push_back(joyb);
GLOBAL_DEF("input/ui_left", va);
input_presets.push_back("input/ui_left");
va = Array();
- key.key.scancode = KEY_RIGHT;
+ key.instance();
+ key->set_scancode(KEY_RIGHT);
va.push_back(key);
- joyb.joy_button.button_index = JOY_DPAD_RIGHT;
+ joyb.instance();
+ joyb->set_button_index(JOY_DPAD_RIGHT);
va.push_back(joyb);
GLOBAL_DEF("input/ui_right", va);
input_presets.push_back("input/ui_right");
va = Array();
- key.key.scancode = KEY_UP;
+ key.instance();
+ key->set_scancode(KEY_UP);
va.push_back(key);
- joyb.joy_button.button_index = JOY_DPAD_UP;
+ joyb.instance();
+ joyb->set_button_index(JOY_DPAD_UP);
va.push_back(joyb);
GLOBAL_DEF("input/ui_up", va);
input_presets.push_back("input/ui_up");
va = Array();
- key.key.scancode = KEY_DOWN;
+ key.instance();
+ key->set_scancode(KEY_DOWN);
va.push_back(key);
- joyb.joy_button.button_index = JOY_DPAD_DOWN;
+ joyb.instance();
+ joyb->set_button_index(JOY_DPAD_DOWN);
va.push_back(joyb);
GLOBAL_DEF("input/ui_down", va);
input_presets.push_back("input/ui_down");
va = Array();
- key.key.scancode = KEY_PAGEUP;
+ key.instance();
+ key->set_scancode(KEY_PAGEUP);
va.push_back(key);
GLOBAL_DEF("input/ui_page_up", va);
input_presets.push_back("input/ui_page_up");
va = Array();
- key.key.scancode = KEY_PAGEDOWN;
+ key.instance();
+ key->set_scancode(KEY_PAGEDOWN);
va.push_back(key);
GLOBAL_DEF("input/ui_page_down", va);
input_presets.push_back("input/ui_page_down");
@@ -950,6 +969,12 @@ GlobalConfig::GlobalConfig() {
custom_prop_info["physics/2d/thread_model"] = PropertyInfo(Variant::INT, "physics/2d/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
GLOBAL_DEF("debug/profiler/max_functions", 16384);
+
+ GLOBAL_DEF("compression/zstd_compression_level", 3);
+ custom_prop_info["compression/zstd_compression_level"] = PropertyInfo(Variant::INT, "compression/zstd_compression_level", PROPERTY_HINT_RANGE, "1,22,1");
+ GLOBAL_DEF("compression/zlib_compression_level", Z_DEFAULT_COMPRESSION);
+ custom_prop_info["compression/zlib_compression_level"] = PropertyInfo(Variant::INT, "compression/zlib_compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
+
using_datapack = false;
}
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index 18f34b5d37..4f535fb05e 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -30,6 +30,7 @@
#include "global_constants.h"
#include "object.h"
+#include "os/input_event.h"
#include "os/keyboard.h"
#include "variant.h"
@@ -513,9 +514,8 @@ static _GlobalConstant _global_constants[] = {
{ "TYPE_NODE_PATH", Variant::NODE_PATH }, // 15
{ "TYPE_RID", Variant::_RID },
{ "TYPE_OBJECT", Variant::OBJECT },
- { "TYPE_INPUT_EVENT", Variant::INPUT_EVENT },
- { "TYPE_DICTIONARY", Variant::DICTIONARY },
- { "TYPE_ARRAY", Variant::ARRAY }, // 20
+ { "TYPE_DICTIONARY", Variant::DICTIONARY }, // 20
+ { "TYPE_ARRAY", Variant::ARRAY },
{ "TYPE_RAW_ARRAY", Variant::POOL_BYTE_ARRAY },
{ "TYPE_INT_ARRAY", Variant::POOL_INT_ARRAY },
{ "TYPE_REAL_ARRAY", Variant::POOL_REAL_ARRAY },
diff --git a/core/helper/math_fieldwise.cpp b/core/helper/math_fieldwise.cpp
index 2f176fb9bf..5545c2d642 100644
--- a/core/helper/math_fieldwise.cpp
+++ b/core/helper/math_fieldwise.cpp
@@ -63,8 +63,8 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
SETUP_TYPE(Rect2)
- /**/ TRY_TRANSFER_FIELD("x", pos.x)
- else TRY_TRANSFER_FIELD("y", pos.y)
+ /**/ TRY_TRANSFER_FIELD("x", position.x)
+ else TRY_TRANSFER_FIELD("y", position.y)
else TRY_TRANSFER_FIELD("w", size.x)
else TRY_TRANSFER_FIELD("h", size.y)
@@ -110,9 +110,9 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
SETUP_TYPE(Rect3)
- /**/ TRY_TRANSFER_FIELD("px", pos.x)
- else TRY_TRANSFER_FIELD("py", pos.y)
- else TRY_TRANSFER_FIELD("pz", pos.z)
+ /**/ TRY_TRANSFER_FIELD("px", position.x)
+ else TRY_TRANSFER_FIELD("py", position.y)
+ else TRY_TRANSFER_FIELD("pz", position.z)
else TRY_TRANSFER_FIELD("sx", size.x)
else TRY_TRANSFER_FIELD("sy", size.y)
else TRY_TRANSFER_FIELD("sz", size.z)
diff --git a/core/image.cpp b/core/image.cpp
index 85ca63be5e..686735c906 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -45,7 +45,6 @@ const char *Image::format_names[Image::FORMAT_MAX] = {
"RedGreen",
"RGB8",
"RGBA8",
- "RGB565", //16 bit
"RGBA4444",
"RGBA5551",
"RFloat", //float
@@ -56,11 +55,12 @@ const char *Image::format_names[Image::FORMAT_MAX] = {
"RGHalf",
"RGBHalf",
"RGBAHalf",
- "DXT1", //s3tc
- "DXT3",
- "DXT5",
- "ATI1",
- "ATI2",
+ "RGBE9995",
+ "DXT1 RGB8", //s3tc
+ "DXT3 RGBA8",
+ "DXT5 RGBA8",
+ "RGTC Red8",
+ "RGTC RedGreen8",
"BPTC_RGBA",
"BPTC_RGBF",
"BPTC_RGBFU",
@@ -81,21 +81,21 @@ const char *Image::format_names[Image::FORMAT_MAX] = {
SavePNGFunc Image::save_png_func = NULL;
-void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_dst, const uint8_t *p_src) {
+void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel) {
uint32_t ofs = (p_y * width + p_x) * p_pixelsize;
for (uint32_t i = 0; i < p_pixelsize; i++) {
- p_dst[ofs + i] = p_src[i];
+ p_data[ofs + i] = p_pixel[i];
}
}
-void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_src, uint8_t *p_dst) {
+void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_data, uint8_t *p_pixel) {
uint32_t ofs = (p_y * width + p_x) * p_pixelsize;
for (uint32_t i = 0; i < p_pixelsize; i++) {
- p_dst[i] = p_src[ofs + i];
+ p_pixel[i] = p_data[ofs + i];
}
}
@@ -110,8 +110,6 @@ int Image::get_format_pixel_size(Format p_format) {
case FORMAT_RG8: return 2;
case FORMAT_RGB8: return 3;
case FORMAT_RGBA8: return 4;
- case FORMAT_RGB565:
- return 2; //16 bit
case FORMAT_RGBA4444: return 2;
case FORMAT_RGBA5551: return 2;
case FORMAT_RF:
@@ -122,17 +120,18 @@ int Image::get_format_pixel_size(Format p_format) {
case FORMAT_RH:
return 2; //half float
case FORMAT_RGH: return 4;
- case FORMAT_RGBH: return 8;
- case FORMAT_RGBAH: return 12;
+ case FORMAT_RGBH: return 6;
+ case FORMAT_RGBAH: return 8;
+ case FORMAT_RGBE9995: return 4;
case FORMAT_DXT1:
return 1; //s3tc bc1
case FORMAT_DXT3:
return 1; //bc2
case FORMAT_DXT5:
return 1; //bc3
- case FORMAT_ATI1:
+ case FORMAT_RGTC_R:
return 1; //bc4
- case FORMAT_ATI2:
+ case FORMAT_RGTC_RG:
return 1; //bc5
case FORMAT_BPTC_RGBA:
return 1; //btpc bc6h
@@ -168,8 +167,8 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
case FORMAT_DXT1: //s3tc bc1
case FORMAT_DXT3: //bc2
case FORMAT_DXT5: //bc3
- case FORMAT_ATI1: //bc4
- case FORMAT_ATI2: { //bc5 case case FORMAT_DXT1:
+ case FORMAT_RGTC_R: //bc4
+ case FORMAT_RGTC_RG: { //bc5 case case FORMAT_DXT1:
r_w = 4;
r_h = 4;
@@ -220,7 +219,7 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
int Image::get_format_pixel_rshift(Format p_format) {
- if (p_format == FORMAT_DXT1 || p_format == FORMAT_ATI1 || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1)
+ if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1)
return 1;
else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A)
return 2;
@@ -228,6 +227,54 @@ int Image::get_format_pixel_rshift(Format p_format) {
return 0;
}
+int Image::get_format_block_size(Format p_format) {
+
+ switch (p_format) {
+ case FORMAT_DXT1: //s3tc bc1
+ case FORMAT_DXT3: //bc2
+ case FORMAT_DXT5: //bc3
+ case FORMAT_RGTC_R: //bc4
+ case FORMAT_RGTC_RG: { //bc5 case case FORMAT_DXT1:
+
+ return 4;
+ } break;
+ case FORMAT_PVRTC2:
+ case FORMAT_PVRTC2A: {
+
+ return 4;
+ } break;
+ case FORMAT_PVRTC4A:
+ case FORMAT_PVRTC4: {
+
+ return 4;
+ } break;
+ case FORMAT_ETC: {
+
+ return 4;
+ } break;
+ case FORMAT_BPTC_RGBA:
+ case FORMAT_BPTC_RGBF:
+ case FORMAT_BPTC_RGBFU: {
+
+ return 4;
+ } break;
+ case FORMAT_ETC2_R11: //etc2
+ case FORMAT_ETC2_R11S: //signed: NOT srgb.
+ case FORMAT_ETC2_RG11:
+ case FORMAT_ETC2_RG11S:
+ case FORMAT_ETC2_RGB8:
+ case FORMAT_ETC2_RGBA8:
+ case FORMAT_ETC2_RGB8A1: {
+
+ return 4;
+ } break;
+ default: {
+ }
+ }
+
+ return 1;
+}
+
void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_width, int &r_height) const {
int w = width;
@@ -236,11 +283,16 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_widt
int pixel_size = get_format_pixel_size(format);
int pixel_rshift = get_format_pixel_rshift(format);
+ int block = get_format_block_size(format);
int minw, minh;
get_format_min_pixel_size(format, minw, minh);
for (int i = 0; i < p_mipmap; i++) {
- int s = w * h;
+ int bw = w % block != 0 ? w + (block - w % block) : w;
+ int bh = h % block != 0 ? h + (block - h % block) : h;
+
+ int s = bw * bh;
+
s *= pixel_size;
s >>= pixel_rshift;
ofs += s;
@@ -356,10 +408,35 @@ void Image::convert(Format p_new_format) {
if (p_new_format == format)
return;
- if (format >= FORMAT_RGB565 || p_new_format >= FORMAT_RGB565) {
+ if (format > FORMAT_RGBE9995 || p_new_format > FORMAT_RGBE9995) {
- ERR_EXPLAIN("Cannot convert to <-> from non byte formats.");
+ ERR_EXPLAIN("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead.");
ERR_FAIL();
+
+ } else if (format > FORMAT_RGBA8 || p_new_format > FORMAT_RGBA8) {
+
+ //use put/set pixel which is slower but works with non byte formats
+ Image new_img(width, height, 0, p_new_format);
+ lock();
+ new_img.lock();
+
+ for (int i = 0; i < width; i++) {
+ for (int j = 0; j < height; j++) {
+
+ new_img.put_pixel(i, j, get_pixel(i, j));
+ }
+ }
+
+ unlock();
+ new_img.unlock();
+
+ if (has_mipmaps()) {
+ new_img.generate_mipmaps();
+ }
+
+ _copy_internals_from(new_img);
+
+ return;
}
Image new_img(width, height, 0, p_new_format);
@@ -741,7 +818,7 @@ void Image::flip_y() {
uint8_t down[16];
uint32_t pixel_size = get_format_pixel_size(format);
- for (int y = 0; y < height; y++) {
+ for (int y = 0; y < height / 2; y++) {
for (int x = 0; x < width; x++) {
@@ -777,7 +854,7 @@ void Image::flip_x() {
for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
+ for (int x = 0; x < width / 2; x++) {
_get_pixelb(x, y, pixel_size, w.ptr(), up);
_get_pixelb(width - x - 1, y, pixel_size, w.ptr(), down);
@@ -801,12 +878,17 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &
int pixsize = get_format_pixel_size(p_format);
int pixshift = get_format_pixel_rshift(p_format);
+ int block = get_format_block_size(p_format);
int minw, minh;
get_format_min_pixel_size(p_format, minw, minh);
while (true) {
- int s = w * h;
+ int bw = w % block != 0 ? w + (block - w % block) : w;
+ int bh = h % block != 0 ? h + (block - h % block) : h;
+
+ int s = bw * bh;
+
s *= pixsize;
s >>= pixshift;
@@ -834,7 +916,7 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &
bool Image::_can_modify(Format p_format) const {
- return p_format < FORMAT_RGB565;
+ return p_format <= FORMAT_RGBE9995;
}
template <int CC>
@@ -1370,12 +1452,12 @@ Error Image::load(const String &p_path) {
return ImageLoader::load_image(p_path, this);
}
-Error Image::save_png(const String &p_path) {
+Error Image::save_png(const String &p_path) const {
if (save_png_func == NULL)
return ERR_UNAVAILABLE;
- return save_png_func(p_path, Ref<Image>(this));
+ return save_png_func(p_path, Ref<Image>((Image *)this));
}
int Image::get_image_data_size(int p_width, int p_height, Format p_format, int p_mipmaps) {
@@ -1391,337 +1473,14 @@ int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format
return mm;
}
-Error Image::_decompress_bc() {
-
- int wd = width, ht = height;
- if (wd % 4 != 0) {
- wd += 4 - (wd % 4);
- }
- if (ht % 4 != 0) {
- ht += 4 - (ht % 4);
- }
-
- int mm;
- int size = _get_dst_image_size(wd, ht, FORMAT_RGBA8, mm);
-
- PoolVector<uint8_t> newdata;
- newdata.resize(size);
-
- PoolVector<uint8_t>::Write w = newdata.write();
- PoolVector<uint8_t>::Read r = data.read();
-
- int rofs = 0;
- int wofs = 0;
-
- //print_line("width: "+itos(wd)+" height: "+itos(ht));
-
- for (int i = 0; i <= mm; i++) {
-
- switch (format) {
-
- case FORMAT_DXT1: {
-
- int len = (wd * ht) / 16;
- uint8_t *dst = &w[wofs];
-
- uint32_t ofs_table[16];
- for (int x = 0; x < 4; x++) {
-
- for (int y = 0; y < 4; y++) {
-
- ofs_table[15 - (y * 4 + (3 - x))] = (x + y * wd) * 4;
- }
- }
-
- for (int j = 0; j < len; j++) {
-
- const uint8_t *src = &r[rofs + j * 8];
- uint16_t col_a = src[1];
- col_a <<= 8;
- col_a |= src[0];
- uint16_t col_b = src[3];
- col_b <<= 8;
- col_b |= src[2];
-
- uint8_t table[4][4] = {
- { uint8_t((col_a >> 11) << 3), uint8_t(((col_a >> 5) & 0x3f) << 2), uint8_t(((col_a)&0x1f) << 3), 255 },
- { uint8_t((col_b >> 11) << 3), uint8_t(((col_b >> 5) & 0x3f) << 2), uint8_t(((col_b)&0x1f) << 3), 255 },
- { 0, 0, 0, 255 },
- { 0, 0, 0, 255 }
- };
-
- if (col_a < col_b) {
- //punchrough
- table[2][0] = (int(table[0][0]) + int(table[1][0])) >> 1;
- table[2][1] = (int(table[0][1]) + int(table[1][1])) >> 1;
- table[2][2] = (int(table[0][2]) + int(table[1][2])) >> 1;
- table[3][3] = 0; //premul alpha black
- } else {
- //gradient
- table[2][0] = (int(table[0][0]) * 2 + int(table[1][0])) / 3;
- table[2][1] = (int(table[0][1]) * 2 + int(table[1][1])) / 3;
- table[2][2] = (int(table[0][2]) * 2 + int(table[1][2])) / 3;
- table[3][0] = (int(table[0][0]) + int(table[1][0]) * 2) / 3;
- table[3][1] = (int(table[0][1]) + int(table[1][1]) * 2) / 3;
- table[3][2] = (int(table[0][2]) + int(table[1][2]) * 2) / 3;
- }
-
- uint32_t block = src[4];
- block <<= 8;
- block |= src[5];
- block <<= 8;
- block |= src[6];
- block <<= 8;
- block |= src[7];
-
- int y = (j / (wd / 4)) * 4;
- int x = (j % (wd / 4)) * 4;
- int pixofs = (y * wd + x) * 4;
-
- for (int k = 0; k < 16; k++) {
- int idx = pixofs + ofs_table[k];
- dst[idx + 0] = table[block & 0x3][0];
- dst[idx + 1] = table[block & 0x3][1];
- dst[idx + 2] = table[block & 0x3][2];
- dst[idx + 3] = table[block & 0x3][3];
- block >>= 2;
- }
- }
-
- rofs += len * 8;
- wofs += wd * ht * 4;
-
- wd /= 2;
- ht /= 2;
-
- } break;
- case FORMAT_DXT3: {
-
- int len = (wd * ht) / 16;
- uint8_t *dst = &w[wofs];
-
- uint32_t ofs_table[16];
- for (int x = 0; x < 4; x++) {
-
- for (int y = 0; y < 4; y++) {
-
- ofs_table[15 - (y * 4 + (3 - x))] = (x + y * wd) * 4;
- }
- }
-
- for (int j = 0; j < len; j++) {
-
- const uint8_t *src = &r[rofs + j * 16];
-
- uint64_t ablock = src[1];
- ablock <<= 8;
- ablock |= src[0];
- ablock <<= 8;
- ablock |= src[3];
- ablock <<= 8;
- ablock |= src[2];
- ablock <<= 8;
- ablock |= src[5];
- ablock <<= 8;
- ablock |= src[4];
- ablock <<= 8;
- ablock |= src[7];
- ablock <<= 8;
- ablock |= src[6];
-
- uint16_t col_a = src[8 + 1];
- col_a <<= 8;
- col_a |= src[8 + 0];
- uint16_t col_b = src[8 + 3];
- col_b <<= 8;
- col_b |= src[8 + 2];
-
- uint8_t table[4][4] = {
- { uint8_t((col_a >> 11) << 3), uint8_t(((col_a >> 5) & 0x3f) << 2), uint8_t(((col_a)&0x1f) << 3), 255 },
- { uint8_t((col_b >> 11) << 3), uint8_t(((col_b >> 5) & 0x3f) << 2), uint8_t(((col_b)&0x1f) << 3), 255 },
-
- { 0, 0, 0, 255 },
- { 0, 0, 0, 255 }
- };
-
- //always gradient
- table[2][0] = (int(table[0][0]) * 2 + int(table[1][0])) / 3;
- table[2][1] = (int(table[0][1]) * 2 + int(table[1][1])) / 3;
- table[2][2] = (int(table[0][2]) * 2 + int(table[1][2])) / 3;
- table[3][0] = (int(table[0][0]) + int(table[1][0]) * 2) / 3;
- table[3][1] = (int(table[0][1]) + int(table[1][1]) * 2) / 3;
- table[3][2] = (int(table[0][2]) + int(table[1][2]) * 2) / 3;
-
- uint32_t block = src[4 + 8];
- block <<= 8;
- block |= src[5 + 8];
- block <<= 8;
- block |= src[6 + 8];
- block <<= 8;
- block |= src[7 + 8];
-
- int y = (j / (wd / 4)) * 4;
- int x = (j % (wd / 4)) * 4;
- int pixofs = (y * wd + x) * 4;
-
- for (int k = 0; k < 16; k++) {
- uint8_t alpha = ablock & 0xf;
- alpha = int(alpha) * 255 / 15; //right way for alpha
- int idx = pixofs + ofs_table[k];
- dst[idx + 0] = table[block & 0x3][0];
- dst[idx + 1] = table[block & 0x3][1];
- dst[idx + 2] = table[block & 0x3][2];
- dst[idx + 3] = alpha;
- block >>= 2;
- ablock >>= 4;
- }
- }
-
- rofs += len * 16;
- wofs += wd * ht * 4;
-
- wd /= 2;
- ht /= 2;
-
- } break;
- case FORMAT_DXT5: {
-
- int len = (wd * ht) / 16;
- uint8_t *dst = &w[wofs];
-
- uint32_t ofs_table[16];
- for (int x = 0; x < 4; x++) {
-
- for (int y = 0; y < 4; y++) {
-
- ofs_table[15 - (y * 4 + (3 - x))] = (x + y * wd) * 4;
- }
- }
-
- for (int j = 0; j < len; j++) {
-
- const uint8_t *src = &r[rofs + j * 16];
-
- uint8_t a_start = src[1];
- uint8_t a_end = src[0];
-
- uint64_t ablock = src[3];
- ablock <<= 8;
- ablock |= src[2];
- ablock <<= 8;
- ablock |= src[5];
- ablock <<= 8;
- ablock |= src[4];
- ablock <<= 8;
- ablock |= src[7];
- ablock <<= 8;
- ablock |= src[6];
-
- uint8_t atable[8];
-
- if (a_start > a_end) {
-
- atable[0] = (int(a_start) * 7 + int(a_end) * 0) / 7;
- atable[1] = (int(a_start) * 6 + int(a_end) * 1) / 7;
- atable[2] = (int(a_start) * 5 + int(a_end) * 2) / 7;
- atable[3] = (int(a_start) * 4 + int(a_end) * 3) / 7;
- atable[4] = (int(a_start) * 3 + int(a_end) * 4) / 7;
- atable[5] = (int(a_start) * 2 + int(a_end) * 5) / 7;
- atable[6] = (int(a_start) * 1 + int(a_end) * 6) / 7;
- atable[7] = (int(a_start) * 0 + int(a_end) * 7) / 7;
- } else {
-
- atable[0] = (int(a_start) * 5 + int(a_end) * 0) / 5;
- atable[1] = (int(a_start) * 4 + int(a_end) * 1) / 5;
- atable[2] = (int(a_start) * 3 + int(a_end) * 2) / 5;
- atable[3] = (int(a_start) * 2 + int(a_end) * 3) / 5;
- atable[4] = (int(a_start) * 1 + int(a_end) * 4) / 5;
- atable[5] = (int(a_start) * 0 + int(a_end) * 5) / 5;
- atable[6] = 0;
- atable[7] = 255;
- }
-
- uint16_t col_a = src[8 + 1];
- col_a <<= 8;
- col_a |= src[8 + 0];
- uint16_t col_b = src[8 + 3];
- col_b <<= 8;
- col_b |= src[8 + 2];
-
- uint8_t table[4][4] = {
- { uint8_t((col_a >> 11) << 3), uint8_t(((col_a >> 5) & 0x3f) << 2), uint8_t(((col_a)&0x1f) << 3), 255 },
- { uint8_t((col_b >> 11) << 3), uint8_t(((col_b >> 5) & 0x3f) << 2), uint8_t(((col_b)&0x1f) << 3), 255 },
-
- { 0, 0, 0, 255 },
- { 0, 0, 0, 255 }
- };
-
- //always gradient
- table[2][0] = (int(table[0][0]) * 2 + int(table[1][0])) / 3;
- table[2][1] = (int(table[0][1]) * 2 + int(table[1][1])) / 3;
- table[2][2] = (int(table[0][2]) * 2 + int(table[1][2])) / 3;
- table[3][0] = (int(table[0][0]) + int(table[1][0]) * 2) / 3;
- table[3][1] = (int(table[0][1]) + int(table[1][1]) * 2) / 3;
- table[3][2] = (int(table[0][2]) + int(table[1][2]) * 2) / 3;
-
- uint32_t block = src[4 + 8];
- block <<= 8;
- block |= src[5 + 8];
- block <<= 8;
- block |= src[6 + 8];
- block <<= 8;
- block |= src[7 + 8];
-
- int y = (j / (wd / 4)) * 4;
- int x = (j % (wd / 4)) * 4;
- int pixofs = (y * wd + x) * 4;
-
- for (int k = 0; k < 16; k++) {
- uint8_t alpha = ablock & 0x7;
- int idx = pixofs + ofs_table[k];
- dst[idx + 0] = table[block & 0x3][0];
- dst[idx + 1] = table[block & 0x3][1];
- dst[idx + 2] = table[block & 0x3][2];
- dst[idx + 3] = atable[alpha];
- block >>= 2;
- ablock >>= 3;
- }
- }
-
- rofs += len * 16;
- wofs += wd * ht * 4;
-
- wd /= 2;
- ht /= 2;
-
- } break;
- default: {}
- }
- }
-
- w = PoolVector<uint8_t>::Write();
- r = PoolVector<uint8_t>::Read();
-
- data = newdata;
- format = FORMAT_RGBA8;
- if (wd != width || ht != height) {
-
- SWAP(width, wd);
- SWAP(height, ht);
- crop(wd, ht);
- }
-
- return OK;
-}
-
bool Image::is_compressed() const {
- return format >= FORMAT_RGB565;
+ return format > FORMAT_RGBE9995;
}
Error Image::decompress() {
- if (format >= FORMAT_DXT1 && format <= FORMAT_ATI2)
- _decompress_bc(); //_image_decompress_bc(this);
+ if (format >= FORMAT_DXT1 && format <= FORMAT_BPTC_RGBFU && _image_decompress_bc)
+ _image_decompress_bc(this);
else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc)
_image_decompress_pvrtc(this);
else if (format == FORMAT_ETC && _image_decompress_etc)
@@ -1733,19 +1492,14 @@ Error Image::decompress() {
return OK;
}
-Error Image::compress(CompressMode p_mode) {
+Error Image::compress(CompressMode p_mode, bool p_for_srgb) {
switch (p_mode) {
- case COMPRESS_16BIT: {
-
- //ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
- //_image_compress_bc_func(this);
- } break;
case COMPRESS_S3TC: {
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
- _image_compress_bc_func(this);
+ _image_compress_bc_func(this, p_for_srgb);
} break;
case COMPRESS_PVRTC2: {
@@ -1845,7 +1599,7 @@ Rect2 Image::get_used_rect() const {
Ref<Image> Image::get_rect(const Rect2 &p_area) const {
Ref<Image> img = memnew(Image(p_area.size.x, p_area.size.y, mipmaps, format));
- img->blit_rect(Ref<Image>(this), p_area, Point2(0, 0));
+ img->blit_rect(Ref<Image>((Image *)this), p_area, Point2(0, 0));
return img;
}
@@ -1858,11 +1612,11 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po
ERR_FAIL_COND(srcdsize == 0);
ERR_FAIL_COND(format != p_src->format);
- Rect2i local_src_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest + p_src_rect.pos, p_src_rect.size));
+ Rect2i local_src_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest + p_src_rect.position, p_src_rect.size));
if (local_src_rect.size.x <= 0 || local_src_rect.size.y <= 0)
return;
- Rect2i src_rect(p_src_rect.pos + (local_src_rect.pos - p_dest), local_src_rect.size);
+ Rect2i src_rect(p_src_rect.position + (local_src_rect.position - p_dest), local_src_rect.size);
PoolVector<uint8_t>::Write wp = data.write();
uint8_t *dst_data_ptr = wp.ptr();
@@ -1876,11 +1630,11 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po
for (int j = 0; j < src_rect.size.x; j++) {
- int src_x = src_rect.pos.x + j;
- int src_y = src_rect.pos.y + i;
+ int src_x = src_rect.position.x + j;
+ int src_y = src_rect.position.y + i;
- int dst_x = local_src_rect.pos.x + j;
- int dst_y = local_src_rect.pos.y + i;
+ int dst_x = local_src_rect.position.x + j;
+ int dst_y = local_src_rect.position.y + i;
const uint8_t *src = &src_data_ptr[(src_y * p_src->width + src_x) * pixel_size];
uint8_t *dst = &dst_data_ptr[(dst_y * width + dst_x) * pixel_size];
@@ -1895,7 +1649,7 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po
Ref<Image> (*Image::_png_mem_loader_func)(const uint8_t *, int) = NULL;
Ref<Image> (*Image::_jpg_mem_loader_func)(const uint8_t *, int) = NULL;
-void (*Image::_image_compress_bc_func)(Image *) = NULL;
+void (*Image::_image_compress_bc_func)(Image *, bool) = NULL;
void (*Image::_image_compress_pvrtc2_func)(Image *) = NULL;
void (*Image::_image_compress_pvrtc4_func)(Image *) = NULL;
void (*Image::_image_compress_etc_func)(Image *) = NULL;
@@ -1947,6 +1701,333 @@ Dictionary Image::_get_data() const {
return d;
}
+void Image::lock() {
+
+ ERR_FAIL_COND(data.size() == 0);
+ write_lock = data.write();
+}
+
+void Image::unlock() {
+
+ write_lock = PoolVector<uint8_t>::Write();
+}
+
+Color Image::get_pixel(int p_x, int p_y) {
+
+ uint8_t *ptr = write_lock.ptr();
+#ifdef DEBUG_ENABLED
+ if (!ptr) {
+ ERR_EXPLAIN("Image must be locked with 'lock()' before using get_pixel()");
+ ERR_FAIL_COND_V(!ptr, Color());
+ }
+
+ ERR_FAIL_INDEX_V(p_x, width, Color());
+ ERR_FAIL_INDEX_V(p_y, height, Color());
+
+#endif
+
+ uint32_t ofs = p_y * width + p_x;
+
+ switch (format) {
+ case FORMAT_L8: {
+ float l = ptr[ofs] / 255.0;
+ return Color(l, l, l, 1);
+ } break;
+ case FORMAT_LA8: {
+ float l = ptr[ofs * 2 + 0] / 255.0;
+ float a = ptr[ofs * 2 + 1] / 255.0;
+ return Color(l, l, l, a);
+ } break;
+ case FORMAT_R8: {
+
+ float r = ptr[ofs] / 255.0;
+ return Color(r, 0, 0, 1);
+ } break;
+ case FORMAT_RG8: {
+
+ float r = ptr[ofs * 2 + 0] / 255.0;
+ float g = ptr[ofs * 2 + 1] / 255.0;
+ return Color(r, g, 0, 1);
+ } break;
+ case FORMAT_RGB8: {
+ float r = ptr[ofs * 3 + 0] / 255.0;
+ float g = ptr[ofs * 3 + 1] / 255.0;
+ float b = ptr[ofs * 3 + 2] / 255.0;
+ return Color(r, g, b, 1);
+
+ } break;
+ case FORMAT_RGBA8: {
+ float r = ptr[ofs * 4 + 0] / 255.0;
+ float g = ptr[ofs * 4 + 1] / 255.0;
+ float b = ptr[ofs * 4 + 2] / 255.0;
+ float a = ptr[ofs * 4 + 3] / 255.0;
+ return Color(r, g, b, a);
+
+ } break;
+ case FORMAT_RGBA4444: {
+ uint16_t u = ((uint16_t *)ptr)[ofs];
+ float r = (u & 0xF) / 15.0;
+ float g = ((u >> 4) & 0xF) / 15.0;
+ float b = ((u >> 8) & 0xF) / 15.0;
+ float a = ((u >> 12) & 0xF) / 15.0;
+ return Color(r, g, b, a);
+
+ } break;
+ case FORMAT_RGBA5551: {
+
+ uint16_t u = ((uint16_t *)ptr)[ofs];
+ float r = (u & 0x1F) / 15.0;
+ float g = ((u >> 5) & 0x1F) / 15.0;
+ float b = ((u >> 10) & 0x1F) / 15.0;
+ float a = ((u >> 15) & 0x1) / 1.0;
+ return Color(r, g, b, a);
+ } break;
+ case FORMAT_RF: {
+
+ float r = ((float *)ptr)[ofs];
+ return Color(r, 0, 0, 1);
+ } break;
+ case FORMAT_RGF: {
+
+ float r = ((float *)ptr)[ofs * 2 + 0];
+ float g = ((float *)ptr)[ofs * 2 + 1];
+ return Color(r, g, 0, 1);
+ } break;
+ case FORMAT_RGBF: {
+
+ float r = ((float *)ptr)[ofs * 3 + 0];
+ float g = ((float *)ptr)[ofs * 3 + 1];
+ float b = ((float *)ptr)[ofs * 3 + 2];
+ return Color(r, g, b, 1);
+ } break;
+ case FORMAT_RGBAF: {
+
+ float r = ((float *)ptr)[ofs * 4 + 0];
+ float g = ((float *)ptr)[ofs * 4 + 1];
+ float b = ((float *)ptr)[ofs * 4 + 2];
+ float a = ((float *)ptr)[ofs * 4 + 3];
+ return Color(r, g, b, a);
+ } break;
+ case FORMAT_RH: {
+
+ uint16_t r = ((uint16_t *)ptr)[ofs];
+ return Color(Math::half_to_float(r), 0, 0, 1);
+ } break;
+ case FORMAT_RGH: {
+
+ uint16_t r = ((uint16_t *)ptr)[ofs * 2 + 0];
+ uint16_t g = ((uint16_t *)ptr)[ofs * 2 + 1];
+ return Color(Math::half_to_float(r), Math::half_to_float(g), 0, 1);
+ } break;
+ case FORMAT_RGBH: {
+
+ uint16_t r = ((uint16_t *)ptr)[ofs * 3 + 0];
+ uint16_t g = ((uint16_t *)ptr)[ofs * 3 + 1];
+ uint16_t b = ((uint16_t *)ptr)[ofs * 3 + 2];
+ return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), 1);
+ } break;
+ case FORMAT_RGBAH: {
+
+ uint16_t r = ((uint16_t *)ptr)[ofs * 4 + 0];
+ uint16_t g = ((uint16_t *)ptr)[ofs * 4 + 1];
+ uint16_t b = ((uint16_t *)ptr)[ofs * 4 + 2];
+ uint16_t a = ((uint16_t *)ptr)[ofs * 4 + 3];
+ return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), Math::half_to_float(a));
+ } break;
+ case FORMAT_RGBE9995: {
+ uint32_t rgbe = ((uint32_t *)ptr)[ofs];
+ float r = rgbe & 0x1ff;
+ float g = (rgbe >> 9) & 0x1ff;
+ float b = (rgbe >> 18) & 0x1ff;
+ float e = (rgbe >> 27);
+ float m = Math::pow(2, e - 15.0 - 9.0);
+ ;
+ float rd = r * m;
+ float gd = g * m;
+ float bd = b * m;
+
+ return Color(rd, gd, bd, 1.0);
+
+ } break;
+ default: {
+ ERR_EXPLAIN("Can't get_pixel() on compressed image, sorry.");
+ ERR_FAIL_V(Color());
+ }
+ }
+
+ return Color();
+}
+
+void Image::put_pixel(int p_x, int p_y, const Color &p_color) {
+
+ uint8_t *ptr = write_lock.ptr();
+#ifdef DEBUG_ENABLED
+ if (!ptr) {
+ ERR_EXPLAIN("Image must be locked with 'lock()' before using put_pixel()");
+ ERR_FAIL_COND(!ptr);
+ }
+
+ ERR_FAIL_INDEX(p_x, width);
+ ERR_FAIL_INDEX(p_y, height);
+
+#endif
+
+ uint32_t ofs = p_y * width + p_x;
+
+ switch (format) {
+ case FORMAT_L8: {
+ ptr[ofs] = uint8_t(CLAMP(p_color.gray() * 255.0, 0, 255));
+ } break;
+ case FORMAT_LA8: {
+ ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.gray() * 255.0, 0, 255));
+ ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.a * 255.0, 0, 255));
+ } break;
+ case FORMAT_R8: {
+
+ ptr[ofs] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
+ } break;
+ case FORMAT_RG8: {
+
+ ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
+ ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.g * 255.0, 0, 255));
+ } break;
+ case FORMAT_RGB8: {
+ ptr[ofs * 3 + 0] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
+ ptr[ofs * 3 + 1] = uint8_t(CLAMP(p_color.g * 255.0, 0, 255));
+ ptr[ofs * 3 + 2] = uint8_t(CLAMP(p_color.b * 255.0, 0, 255));
+ } break;
+ case FORMAT_RGBA8: {
+ ptr[ofs * 4 + 0] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255));
+ ptr[ofs * 4 + 1] = uint8_t(CLAMP(p_color.g * 255.0, 0, 255));
+ ptr[ofs * 4 + 2] = uint8_t(CLAMP(p_color.b * 255.0, 0, 255));
+ ptr[ofs * 4 + 3] = uint8_t(CLAMP(p_color.a * 255.0, 0, 255));
+
+ } break;
+ case FORMAT_RGBA4444: {
+
+ uint16_t rgba = 0;
+
+ rgba = uint16_t(CLAMP(p_color.r * 15.0, 0, 15));
+ rgba |= uint16_t(CLAMP(p_color.g * 15.0, 0, 15)) << 4;
+ rgba |= uint16_t(CLAMP(p_color.b * 15.0, 0, 15)) << 8;
+ rgba |= uint16_t(CLAMP(p_color.a * 15.0, 0, 15)) << 12;
+
+ ((uint16_t *)ptr)[ofs] = rgba;
+
+ } break;
+ case FORMAT_RGBA5551: {
+
+ uint16_t rgba = 0;
+
+ rgba = uint16_t(CLAMP(p_color.r * 31.0, 0, 31));
+ rgba |= uint16_t(CLAMP(p_color.g * 31.0, 0, 31)) << 5;
+ rgba |= uint16_t(CLAMP(p_color.b * 31.0, 0, 31)) << 10;
+ rgba |= uint16_t(p_color.a > 0.5 ? 1 : 0) << 15;
+
+ ((uint16_t *)ptr)[ofs] = rgba;
+
+ } break;
+ case FORMAT_RF: {
+
+ ((float *)ptr)[ofs] = p_color.r;
+ } break;
+ case FORMAT_RGF: {
+
+ ((float *)ptr)[ofs * 2 + 0] = p_color.r;
+ ((float *)ptr)[ofs * 2 + 1] = p_color.g;
+ } break;
+ case FORMAT_RGBF: {
+
+ ((float *)ptr)[ofs * 3 + 0] = p_color.r;
+ ((float *)ptr)[ofs * 3 + 1] = p_color.g;
+ ((float *)ptr)[ofs * 3 + 2] = p_color.b;
+ } break;
+ case FORMAT_RGBAF: {
+
+ ((float *)ptr)[ofs * 4 + 0] = p_color.r;
+ ((float *)ptr)[ofs * 4 + 1] = p_color.g;
+ ((float *)ptr)[ofs * 4 + 2] = p_color.b;
+ ((float *)ptr)[ofs * 4 + 3] = p_color.a;
+ } break;
+ case FORMAT_RH: {
+
+ ((uint16_t *)ptr)[ofs] = Math::make_half_float(p_color.r);
+ } break;
+ case FORMAT_RGH: {
+
+ ((uint16_t *)ptr)[ofs * 2 + 0] = Math::make_half_float(p_color.r);
+ ((uint16_t *)ptr)[ofs * 2 + 1] = Math::make_half_float(p_color.g);
+ } break;
+ case FORMAT_RGBH: {
+
+ ((uint16_t *)ptr)[ofs * 3 + 0] = Math::make_half_float(p_color.r);
+ ((uint16_t *)ptr)[ofs * 3 + 1] = Math::make_half_float(p_color.g);
+ ((uint16_t *)ptr)[ofs * 3 + 2] = Math::make_half_float(p_color.b);
+ } break;
+ case FORMAT_RGBAH: {
+
+ ((uint16_t *)ptr)[ofs * 4 + 0] = Math::make_half_float(p_color.r);
+ ((uint16_t *)ptr)[ofs * 4 + 1] = Math::make_half_float(p_color.g);
+ ((uint16_t *)ptr)[ofs * 4 + 2] = Math::make_half_float(p_color.b);
+ ((uint16_t *)ptr)[ofs * 4 + 3] = Math::make_half_float(p_color.a);
+ } break;
+ case FORMAT_RGBE9995: {
+
+ ((uint32_t *)ptr)[ofs] = p_color.to_rgbe9995();
+
+ } break;
+ default: {
+ ERR_EXPLAIN("Can't put_pixel() on compressed image, sorry.");
+ ERR_FAIL();
+ }
+ }
+}
+
+Image::DetectChannels Image::get_detected_channels() {
+
+ ERR_FAIL_COND_V(data.size() == 0, DETECTED_RGBA);
+ ERR_FAIL_COND_V(is_compressed(), DETECTED_RGBA);
+ bool r = false, g = false, b = false, a = false, c = false;
+ lock();
+ for (int i = 0; i < width; i++) {
+ for (int j = 0; j < height; j++) {
+
+ Color col = get_pixel(i, j);
+
+ if (col.r > 0.001)
+ r = true;
+ if (col.g > 0.001)
+ g = true;
+ if (col.b > 0.001)
+ b = true;
+ if (col.a < 0.999)
+ a = true;
+
+ if (col.r != col.b || col.r != col.g || col.b != col.g) {
+ c = true;
+ }
+ }
+ }
+
+ unlock();
+
+ if (!c && !a)
+ return DETECTED_L;
+ if (!c && a)
+ return DETECTED_LA;
+
+ if (r && !g && !b && !a)
+ return DETECTED_R;
+
+ if (r && g && !b && !a)
+ return DETECTED_RG;
+
+ if (r && g && b && !a)
+ return DETECTED_RGB;
+
+ return DETECTED_RGBA;
+}
+
void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_width"), &Image::get_width);
@@ -2000,6 +2081,11 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_data", "data"), &Image::_set_data);
ClassDB::bind_method(D_METHOD("_get_data"), &Image::_get_data);
+ ClassDB::bind_method(D_METHOD("lock"), &Image::lock);
+ ClassDB::bind_method(D_METHOD("unlock"), &Image::unlock);
+ ClassDB::bind_method(D_METHOD("put_pixel", "x", "y", "color"), &Image::put_pixel);
+ ClassDB::bind_method(D_METHOD("get_pixel", "x", "y"), &Image::get_pixel);
+
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "_set_data", "_get_data");
BIND_CONSTANT(FORMAT_L8); //luminance
@@ -2008,7 +2094,6 @@ void Image::_bind_methods() {
BIND_CONSTANT(FORMAT_RG8);
BIND_CONSTANT(FORMAT_RGB8);
BIND_CONSTANT(FORMAT_RGBA8);
- BIND_CONSTANT(FORMAT_RGB565); //16 bit
BIND_CONSTANT(FORMAT_RGBA4444);
BIND_CONSTANT(FORMAT_RGBA5551);
BIND_CONSTANT(FORMAT_RF); //float
@@ -2019,11 +2104,12 @@ void Image::_bind_methods() {
BIND_CONSTANT(FORMAT_RGH);
BIND_CONSTANT(FORMAT_RGBH);
BIND_CONSTANT(FORMAT_RGBAH);
+ BIND_CONSTANT(FORMAT_RGBE9995);
BIND_CONSTANT(FORMAT_DXT1); //s3tc bc1
BIND_CONSTANT(FORMAT_DXT3); //bc2
BIND_CONSTANT(FORMAT_DXT5); //bc3
- BIND_CONSTANT(FORMAT_ATI1); //bc4
- BIND_CONSTANT(FORMAT_ATI2); //bc5
+ BIND_CONSTANT(FORMAT_RGTC_R);
+ BIND_CONSTANT(FORMAT_RGTC_RG);
BIND_CONSTANT(FORMAT_BPTC_RGBA); //btpc bc6h
BIND_CONSTANT(FORMAT_BPTC_RGBF); //float /
BIND_CONSTANT(FORMAT_BPTC_RGBFU); //unsigned float
@@ -2049,7 +2135,6 @@ void Image::_bind_methods() {
BIND_CONSTANT(ALPHA_BIT);
BIND_CONSTANT(ALPHA_BLEND);
- BIND_CONSTANT(COMPRESS_16BIT);
BIND_CONSTANT(COMPRESS_S3TC);
BIND_CONSTANT(COMPRESS_PVRTC2);
BIND_CONSTANT(COMPRESS_PVRTC4);
@@ -2057,7 +2142,7 @@ void Image::_bind_methods() {
BIND_CONSTANT(COMPRESS_ETC2);
}
-void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) {
+void Image::set_compress_bc_func(void (*p_compress_func)(Image *, bool)) {
_image_compress_bc_func = p_compress_func;
}
@@ -2247,4 +2332,8 @@ Image::Image() {
}
Image::~Image() {
+
+ if (write_lock.ptr()) {
+ unlock();
+ }
}
diff --git a/core/image.h b/core/image.h
index 4decaa3436..e3174a2899 100644
--- a/core/image.h
+++ b/core/image.h
@@ -66,7 +66,6 @@ public:
FORMAT_RG8,
FORMAT_RGB8,
FORMAT_RGBA8,
- FORMAT_RGB565, //16 bit
FORMAT_RGBA4444,
FORMAT_RGBA5551,
FORMAT_RF, //float
@@ -77,14 +76,15 @@ public:
FORMAT_RGH,
FORMAT_RGBH,
FORMAT_RGBAH,
+ FORMAT_RGBE9995,
FORMAT_DXT1, //s3tc bc1
FORMAT_DXT3, //bc2
FORMAT_DXT5, //bc3
- FORMAT_ATI1, //bc4
- FORMAT_ATI2, //bc5
- FORMAT_BPTC_RGBA, //btpc bc6h
- FORMAT_BPTC_RGBF, //float /
- FORMAT_BPTC_RGBFU, //unsigned float
+ FORMAT_RGTC_R,
+ FORMAT_RGTC_RG,
+ FORMAT_BPTC_RGBA, //btpc bc7
+ FORMAT_BPTC_RGBF, //float bc6h
+ FORMAT_BPTC_RGBFU, //unsigned float bc6hu
FORMAT_PVRTC2, //pvrtc
FORMAT_PVRTC2A,
FORMAT_PVRTC4,
@@ -114,7 +114,7 @@ public:
static Ref<Image> (*_png_mem_loader_func)(const uint8_t *p_png, int p_size);
static Ref<Image> (*_jpg_mem_loader_func)(const uint8_t *p_png, int p_size);
- static void (*_image_compress_bc_func)(Image *);
+ static void (*_image_compress_bc_func)(Image *, bool p_srgb);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
static void (*_image_compress_etc_func)(Image *);
@@ -125,13 +125,13 @@ public:
static void (*_image_decompress_etc)(Image *);
static void (*_image_decompress_etc2)(Image *);
- Error _decompress_bc();
-
static PoolVector<uint8_t> (*lossy_packer)(const Ref<Image> &p_image, float p_quality);
static Ref<Image> (*lossy_unpacker)(const PoolVector<uint8_t> &p_buffer);
static PoolVector<uint8_t> (*lossless_packer)(const Ref<Image> &p_image);
static Ref<Image> (*lossless_unpacker)(const PoolVector<uint8_t> &p_buffer);
+ PoolVector<uint8_t>::Write write_lock;
+
protected:
static void _bind_methods();
@@ -162,8 +162,8 @@ private:
static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1);
bool _can_modify(Format p_format) const;
- _FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_dst, const uint8_t *p_src);
- _FORCE_INLINE_ void _get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_src, uint8_t *p_dst);
+ _FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel);
+ _FORCE_INLINE_ void _get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_data, uint8_t *p_pixel);
void _set_data(const Dictionary &p_data);
Dictionary _get_data() const;
@@ -227,7 +227,7 @@ public:
PoolVector<uint8_t> get_data() const;
Error load(const String &p_path);
- Error save_png(const String &p_path);
+ Error save_png(const String &p_path) const;
/**
* create an empty image
@@ -253,21 +253,21 @@ public:
static int get_format_pixel_size(Format p_format);
static int get_format_pixel_rshift(Format p_format);
+ static int get_format_block_size(Format p_format);
static void get_format_min_pixel_size(Format p_format, int &r_w, int &r_h);
static int get_image_data_size(int p_width, int p_height, Format p_format, int p_mipmaps = 0);
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
enum CompressMode {
- COMPRESS_16BIT,
COMPRESS_S3TC,
COMPRESS_PVRTC2,
COMPRESS_PVRTC4,
COMPRESS_ETC,
- COMPRESS_ETC2
+ COMPRESS_ETC2,
};
- Error compress(CompressMode p_mode = COMPRESS_S3TC);
+ Error compress(CompressMode p_mode = COMPRESS_S3TC, bool p_for_srgb = false);
Error decompress();
bool is_compressed() const;
@@ -281,7 +281,7 @@ public:
Rect2 get_used_rect() const;
Ref<Image> get_rect(const Rect2 &p_area) const;
- static void set_compress_bc_func(void (*p_compress_func)(Image *));
+ static void set_compress_bc_func(void (*p_compress_func)(Image *, bool));
static String get_format_name(Format p_format);
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
@@ -289,6 +289,24 @@ public:
virtual Ref<Resource> duplicate(bool p_subresources = false) const;
+ void lock();
+ void unlock();
+
+ //this is used for compression
+ enum DetectChannels {
+ DETECTED_L,
+ DETECTED_LA,
+ DETECTED_R,
+ DETECTED_RG,
+ DETECTED_RGB,
+ DETECTED_RGBA,
+ };
+
+ DetectChannels get_detected_channels();
+
+ Color get_pixel(int p_x, int p_y);
+ void put_pixel(int p_x, int p_y, const Color &p_color);
+
void copy_internals_from(const Ref<Image> &p_image) {
ERR_FAIL_COND(p_image.is_null());
format = p_image->format;
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 9f9eba01c7..1307c467e6 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -37,8 +37,6 @@ InputMap *InputMap::singleton = NULL;
void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
- ClassDB::bind_method(D_METHOD("get_action_id", "action"), &InputMap::get_action_id);
- ClassDB::bind_method(D_METHOD("get_action_from_id", "id"), &InputMap::get_action_from_id);
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
ClassDB::bind_method(D_METHOD("add_action", "action"), &InputMap::add_action);
ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action);
@@ -57,23 +55,15 @@ void InputMap::add_action(const StringName &p_action) {
input_map[p_action] = Action();
static int last_id = 1;
input_map[p_action].id = last_id;
- input_id_map[last_id] = p_action;
last_id++;
}
void InputMap::erase_action(const StringName &p_action) {
ERR_FAIL_COND(!input_map.has(p_action));
- input_id_map.erase(input_map[p_action].id);
input_map.erase(p_action);
}
-StringName InputMap::get_action_from_id(int p_id) const {
-
- ERR_FAIL_COND_V(!input_id_map.has(p_id), StringName());
- return input_id_map[p_id];
-}
-
Array InputMap::_get_actions() {
Array ret;
@@ -103,49 +93,18 @@ List<StringName> InputMap::get_actions() const {
return actions;
}
-List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list, const InputEvent &p_event, bool p_action_test) const {
-
- for (List<InputEvent>::Element *E = p_list.front(); E; E = E->next()) {
-
- const InputEvent &e = E->get();
- if (e.type != p_event.type)
- continue;
- if (e.type != InputEvent::KEY && e.device != p_event.device)
- continue;
-
- bool same = false;
-
- switch (p_event.type) {
-
- case InputEvent::KEY: {
-
- if (p_action_test) {
- uint32_t code = e.key.get_scancode_with_modifiers();
- uint32_t event_code = p_event.key.get_scancode_with_modifiers();
- same = (e.key.scancode == p_event.key.scancode && (!p_event.key.pressed || ((code & event_code) == code)));
- } else {
- same = (e.key.scancode == p_event.key.scancode && e.key.mod == p_event.key.mod);
- }
-
- } break;
- case InputEvent::JOYPAD_BUTTON: {
+List<Ref<InputEvent> >::Element *InputMap::_find_event(List<Ref<InputEvent> > &p_list, const Ref<InputEvent> &p_event, bool p_action_test) const {
- same = (e.joy_button.button_index == p_event.joy_button.button_index);
+ for (List<Ref<InputEvent> >::Element *E = p_list.front(); E; E = E->next()) {
- } break;
- case InputEvent::MOUSE_BUTTON: {
+ const Ref<InputEvent> e = E->get();
- same = (e.mouse_button.button_index == p_event.mouse_button.button_index);
+ //if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here?
+ // continue;
- } break;
- case InputEvent::JOYPAD_MOTION: {
-
- same = (e.joy_motion.axis == p_event.joy_motion.axis && (e.joy_motion.axis_value < 0) == (p_event.joy_motion.axis_value < 0));
-
- } break;
- }
-
- if (same)
+ if (e->get_device() != p_event->get_device())
+ continue;
+ if (e->action_match(p_event))
return E;
}
@@ -157,9 +116,9 @@ bool InputMap::has_action(const StringName &p_action) const {
return input_map.has(p_action);
}
-void InputMap::action_add_event(const StringName &p_action, const InputEvent &p_event) {
+void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
- ERR_FAIL_COND(p_event.type == InputEvent::ACTION);
+ ERR_FAIL_COND(p_event.is_null());
ERR_FAIL_COND(!input_map.has(p_action));
if (_find_event(input_map[p_action].inputs, p_event))
return; //already gots
@@ -167,23 +126,17 @@ void InputMap::action_add_event(const StringName &p_action, const InputEvent &p_
input_map[p_action].inputs.push_back(p_event);
}
-int InputMap::get_action_id(const StringName &p_action) const {
-
- ERR_FAIL_COND_V(!input_map.has(p_action), -1);
- return input_map[p_action].id;
-}
-
-bool InputMap::action_has_event(const StringName &p_action, const InputEvent &p_event) {
+bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_V(!input_map.has(p_action), false);
return (_find_event(input_map[p_action].inputs, p_event) != NULL);
}
-void InputMap::action_erase_event(const StringName &p_action, const InputEvent &p_event) {
+void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(!input_map.has(p_action));
- List<InputEvent>::Element *E = _find_event(input_map[p_action].inputs, p_event);
+ List<Ref<InputEvent> >::Element *E = _find_event(input_map[p_action].inputs, p_event);
if (E)
input_map[p_action].inputs.erase(E);
}
@@ -191,9 +144,9 @@ void InputMap::action_erase_event(const StringName &p_action, const InputEvent &
Array InputMap::_get_action_list(const StringName &p_action) {
Array ret;
- const List<InputEvent> *al = get_action_list(p_action);
+ const List<Ref<InputEvent> > *al = get_action_list(p_action);
if (al) {
- for (const List<InputEvent>::Element *E = al->front(); E; E = E->next()) {
+ for (const List<Ref<InputEvent> >::Element *E = al->front(); E; E = E->next()) {
ret.push_back(E->get());
}
@@ -202,7 +155,7 @@ Array InputMap::_get_action_list(const StringName &p_action) {
return ret;
}
-const List<InputEvent> *InputMap::get_action_list(const StringName &p_action) {
+const List<Ref<InputEvent> > *InputMap::get_action_list(const StringName &p_action) {
const Map<StringName, Action>::Element *E = input_map.find(p_action);
if (!E)
@@ -211,7 +164,7 @@ const List<InputEvent> *InputMap::get_action_list(const StringName &p_action) {
return &E->get().inputs;
}
-bool InputMap::event_is_action(const InputEvent &p_event, const StringName &p_action) const {
+bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const {
Map<StringName, Action>::Element *E = input_map.find(p_action);
if (!E) {
@@ -219,9 +172,9 @@ bool InputMap::event_is_action(const InputEvent &p_event, const StringName &p_ac
ERR_FAIL_COND_V(!E, false);
}
- if (p_event.type == InputEvent::ACTION) {
-
- return p_event.action.action == E->get().id;
+ Ref<InputEventAction> iea = p_event;
+ if (iea.is_valid()) {
+ return iea->get_action() == p_action;
}
return _find_event(E->get().inputs, p_event, true) != NULL;
@@ -252,8 +205,8 @@ void InputMap::load_from_globals() {
for (int i = 0; i < va.size(); i++) {
- InputEvent ie = va[i];
- if (ie.type == InputEvent::NONE)
+ Ref<InputEvent> ie = va[i];
+ if (ie.is_null())
continue;
action_add_event(name, ie);
}
@@ -262,57 +215,70 @@ void InputMap::load_from_globals() {
void InputMap::load_default() {
- InputEvent key;
- key.type = InputEvent::KEY;
+ Ref<InputEventKey> key;
add_action("ui_accept");
- key.key.scancode = KEY_RETURN;
+ key.instance();
+ key->set_scancode(KEY_RETURN);
action_add_event("ui_accept", key);
- key.key.scancode = KEY_ENTER;
+
+ key.instance();
+ key->set_scancode(KEY_ENTER);
action_add_event("ui_accept", key);
- key.key.scancode = KEY_SPACE;
+
+ key.instance();
+ key->set_scancode(KEY_SPACE);
action_add_event("ui_accept", key);
add_action("ui_select");
- key.key.scancode = KEY_SPACE;
+ key.instance();
+ key->set_scancode(KEY_SPACE);
action_add_event("ui_select", key);
add_action("ui_cancel");
- key.key.scancode = KEY_ESCAPE;
+ key.instance();
+ key->set_scancode(KEY_ESCAPE);
action_add_event("ui_cancel", key);
add_action("ui_focus_next");
- key.key.scancode = KEY_TAB;
+ key.instance();
+ key->set_scancode(KEY_TAB);
action_add_event("ui_focus_next", key);
add_action("ui_focus_prev");
- key.key.scancode = KEY_TAB;
- key.key.mod.shift = true;
+ key.instance();
+ key->set_scancode(KEY_TAB);
+ key->set_shift(true);
action_add_event("ui_focus_prev", key);
- key.key.mod.shift = false;
add_action("ui_left");
- key.key.scancode = KEY_LEFT;
+ key.instance();
+ key->set_scancode(KEY_LEFT);
action_add_event("ui_left", key);
add_action("ui_right");
- key.key.scancode = KEY_RIGHT;
+ key.instance();
+ key->set_scancode(KEY_RIGHT);
action_add_event("ui_right", key);
add_action("ui_up");
- key.key.scancode = KEY_UP;
+ key.instance();
+ key->set_scancode(KEY_UP);
action_add_event("ui_up", key);
add_action("ui_down");
- key.key.scancode = KEY_DOWN;
+ key.instance();
+ key->set_scancode(KEY_DOWN);
action_add_event("ui_down", key);
add_action("ui_page_up");
- key.key.scancode = KEY_PAGEUP;
+ key.instance();
+ key->set_scancode(KEY_PAGEUP);
action_add_event("ui_page_up", key);
add_action("ui_page_down");
- key.key.scancode = KEY_PAGEDOWN;
+ key.instance();
+ key->set_scancode(KEY_PAGEDOWN);
action_add_event("ui_page_down", key);
//set("display/handheld/orientation", "landscape");
diff --git a/core/input_map.h b/core/input_map.h
index a25255da2d..ba93e61f5f 100644
--- a/core/input_map.h
+++ b/core/input_map.h
@@ -31,6 +31,7 @@
#define INPUT_MAP_H
#include "object.h"
+#include "os/input_event.h"
class InputMap : public Object {
@@ -39,16 +40,15 @@ class InputMap : public Object {
public:
struct Action {
int id;
- List<InputEvent> inputs;
+ List<Ref<InputEvent> > inputs;
};
private:
static InputMap *singleton;
mutable Map<StringName, Action> input_map;
- mutable Map<int, StringName> input_id_map;
- List<InputEvent>::Element *_find_event(List<InputEvent> &p_list, const InputEvent &p_event, bool p_action_test = false) const;
+ List<Ref<InputEvent> >::Element *_find_event(List<Ref<InputEvent> > &p_list, const Ref<InputEvent> &p_event, bool p_action_test = false) const;
Array _get_action_list(const StringName &p_action);
Array _get_actions();
@@ -60,18 +60,16 @@ public:
static _FORCE_INLINE_ InputMap *get_singleton() { return singleton; }
bool has_action(const StringName &p_action) const;
- int get_action_id(const StringName &p_action) const;
- StringName get_action_from_id(int p_id) const;
List<StringName> get_actions() const;
void add_action(const StringName &p_action);
void erase_action(const StringName &p_action);
- void action_add_event(const StringName &p_action, const InputEvent &p_event);
- bool action_has_event(const StringName &p_action, const InputEvent &p_event);
- void action_erase_event(const StringName &p_action, const InputEvent &p_event);
+ 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);
+ void action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event);
- const List<InputEvent> *get_action_list(const StringName &p_action);
- bool event_is_action(const InputEvent &p_event, const StringName &p_action) const;
+ const List<Ref<InputEvent> > *get_action_list(const StringName &p_action);
+ bool event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const;
const Map<StringName, Action> &get_action_map() const;
void load_from_globals();
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index 662411a62e..9ae54c38af 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -28,11 +28,12 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "compression.h"
-
+#include "global_config.h"
#include "os/copymem.h"
#include "zip_io.h"
#include "thirdparty/misc/fastlz.h"
+#include "thirdparty/zstd/zstd.h"
#include <zlib.h>
@@ -57,7 +58,8 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
strm.zalloc = zipio_alloc;
strm.zfree = zipio_free;
strm.opaque = Z_NULL;
- int err = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
+ int level = GLOBAL_GET("compression/zlib_compression_level");
+ int err = deflateInit(&strm, level);
if (err != Z_OK)
return -1;
@@ -76,6 +78,12 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
return aout;
} break;
+ case MODE_ZSTD: {
+
+ int max_dst_size = get_max_compressed_buffer_size(p_src_size, MODE_ZSTD);
+ int level = GLOBAL_GET("compression/zstd_compression_level");
+ return ZSTD_compress(p_dst, max_dst_size, p_src, p_src_size, level);
+ } break;
}
ERR_FAIL_V(-1);
@@ -105,6 +113,10 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
deflateEnd(&strm);
return aout;
} break;
+ case MODE_ZSTD: {
+
+ return ZSTD_compressBound(p_src_size);
+ } break;
}
ERR_FAIL_V(-1);
@@ -148,6 +160,10 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
ERR_FAIL_COND_V(err != Z_STREAM_END, -1);
return total;
} break;
+ case MODE_ZSTD: {
+
+ return ZSTD_decompress(p_dst, p_dst_max_size, p_src, p_src_size);
+ } break;
}
ERR_FAIL_V(-1);
diff --git a/core/io/compression.h b/core/io/compression.h
index a982a074b1..742f0f4d68 100644
--- a/core/io/compression.h
+++ b/core/io/compression.h
@@ -36,12 +36,13 @@ class Compression {
public:
enum Mode {
MODE_FASTLZ,
- MODE_DEFLATE
+ MODE_DEFLATE,
+ MODE_ZSTD
};
- static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_FASTLZ);
- static int get_max_compressed_buffer_size(int p_src_size, Mode p_mode = MODE_FASTLZ);
- static int decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_FASTLZ);
+ static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_ZSTD);
+ static int get_max_compressed_buffer_size(int p_src_size, Mode p_mode = MODE_ZSTD);
+ static int decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_ZSTD);
Compression();
};
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 4c6e8f5507..4e802579c6 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -369,7 +369,7 @@ FileAccessCompressed::FileAccessCompressed() {
f = NULL;
magic = "GCMP";
block_size = 16384;
- cmode = Compression::MODE_DEFLATE;
+ cmode = Compression::MODE_ZSTD;
writing = false;
write_ptr = 0;
write_buffer_size = 0;
diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h
index 6af9d9b6ca..340c298a0f 100644
--- a/core/io/file_access_compressed.h
+++ b/core/io/file_access_compressed.h
@@ -64,7 +64,7 @@ class FileAccessCompressed : public FileAccess {
FileAccess *f;
public:
- void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_FASTLZ, int p_block_size = 4096);
+ void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_ZSTD, int p_block_size = 4096);
Error open_after_magic(FileAccess *p_base);
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index 6ed20ac015..23719940be 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -43,7 +43,7 @@ bool ImageFormatLoader::recognize(const String &p_extension) const {
return false;
}
-Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom) {
+Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom, bool p_force_linear) {
ERR_FAIL_COND_V(p_image.is_null(), ERR_INVALID_PARAMETER);
FileAccess *f = p_custom;
@@ -62,7 +62,7 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
if (!loader[i]->recognize(extension))
continue;
- Error err = loader[i]->load_image(p_image, f);
+ Error err = loader[i]->load_image(p_image, f, p_force_linear);
if (err != ERR_FILE_UNRECOGNIZED) {
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index 7114cbf8ad..e528d1423b 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -56,7 +56,7 @@ class ImageFormatLoader {
friend class ImageLoader;
protected:
- virtual Error load_image(Ref<Image> p_image, FileAccess *p_fileaccess) = 0;
+ virtual Error load_image(Ref<Image> p_image, FileAccess *p_fileaccess, bool p_force_linear) = 0;
virtual void get_recognized_extensions(List<String> *p_extensions) const = 0;
bool recognize(const String &p_extension) const;
@@ -75,7 +75,7 @@ class ImageLoader {
protected:
public:
- static Error load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom = NULL);
+ static Error load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom = NULL, bool p_force_linear = false);
static void get_recognized_extensions(List<String> *p_extensions);
static bool recognize(const String &p_extension);
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index fd14011a81..75dfd563dd 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -139,8 +139,8 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
ERR_FAIL_COND_V(len < (int)4 * 4, ERR_INVALID_DATA);
Rect2 val;
- val.pos.x = decode_float(&buf[0]);
- val.pos.y = decode_float(&buf[4]);
+ val.position.x = decode_float(&buf[0]);
+ val.position.y = decode_float(&buf[4]);
val.size.x = decode_float(&buf[8]);
val.size.y = decode_float(&buf[12]);
r_variant = val;
@@ -211,9 +211,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
ERR_FAIL_COND_V(len < (int)4 * 6, ERR_INVALID_DATA);
Rect3 val;
- val.pos.x = decode_float(&buf[0]);
- val.pos.y = decode_float(&buf[4]);
- val.pos.z = decode_float(&buf[8]);
+ val.position.x = decode_float(&buf[0]);
+ val.position.y = decode_float(&buf[4]);
+ val.position.z = decode_float(&buf[8]);
val.size.x = decode_float(&buf[12]);
val.size.y = decode_float(&buf[16]);
val.size.z = decode_float(&buf[20]);
@@ -365,66 +365,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = (Object *)NULL;
} break;
- case Variant::INPUT_EVENT: {
-
- InputEvent ie;
-
- ie.type = decode_uint32(&buf[0]);
- ie.device = decode_uint32(&buf[4]);
-
- if (r_len)
- (*r_len) += 12;
-
- switch (ie.type) {
-
- case InputEvent::KEY: {
-
- uint32_t mods = decode_uint32(&buf[12]);
- if (mods & KEY_MASK_SHIFT)
- ie.key.mod.shift = true;
- if (mods & KEY_MASK_CTRL)
- ie.key.mod.control = true;
- if (mods & KEY_MASK_ALT)
- ie.key.mod.alt = true;
- if (mods & KEY_MASK_META)
- ie.key.mod.meta = true;
- ie.key.scancode = decode_uint32(&buf[16]);
-
- if (r_len)
- (*r_len) += 8;
-
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- ie.mouse_button.button_index = decode_uint32(&buf[12]);
- if (r_len)
- (*r_len) += 4;
-
- } break;
- case InputEvent::JOYPAD_BUTTON: {
-
- ie.joy_button.button_index = decode_uint32(&buf[12]);
- if (r_len)
- (*r_len) += 4;
- } break;
- case InputEvent::SCREEN_TOUCH: {
-
- ie.screen_touch.index = decode_uint32(&buf[12]);
- if (r_len)
- (*r_len) += 4;
- } break;
- case InputEvent::JOYPAD_MOTION: {
-
- ie.joy_motion.axis = decode_uint32(&buf[12]);
- ie.joy_motion.axis_value = decode_float(&buf[16]);
- if (r_len)
- (*r_len) += 8;
- } break;
- }
-
- r_variant = ie;
-
- } break;
case Variant::DICTIONARY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
@@ -921,8 +861,8 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
if (buf) {
Rect2 r2 = p_variant;
- encode_float(r2.pos.x, &buf[0]);
- encode_float(r2.pos.y, &buf[4]);
+ encode_float(r2.position.x, &buf[0]);
+ encode_float(r2.position.y, &buf[4]);
encode_float(r2.size.x, &buf[8]);
encode_float(r2.size.y, &buf[12]);
}
@@ -986,9 +926,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
if (buf) {
Rect3 aabb = p_variant;
- encode_float(aabb.pos.x, &buf[0]);
- encode_float(aabb.pos.y, &buf[4]);
- encode_float(aabb.pos.z, &buf[8]);
+ encode_float(aabb.position.x, &buf[0]);
+ encode_float(aabb.position.y, &buf[4]);
+ encode_float(aabb.position.z, &buf[8]);
encode_float(aabb.size.x, &buf[12]);
encode_float(aabb.size.y, &buf[16]);
encode_float(aabb.size.z, &buf[20]);
@@ -1055,83 +995,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
case Variant::OBJECT: {
} break;
- case Variant::INPUT_EVENT: {
-
- InputEvent ie = p_variant;
-
- if (buf) {
-
- encode_uint32(ie.type, &buf[0]);
- encode_uint32(ie.device, &buf[4]);
- encode_uint32(0, &buf[8]);
- }
-
- int llen = 12;
-
- switch (ie.type) {
-
- case InputEvent::KEY: {
-
- if (buf) {
-
- uint32_t mods = 0;
- if (ie.key.mod.shift)
- mods |= KEY_MASK_SHIFT;
- if (ie.key.mod.control)
- mods |= KEY_MASK_CTRL;
- if (ie.key.mod.alt)
- mods |= KEY_MASK_ALT;
- if (ie.key.mod.meta)
- mods |= KEY_MASK_META;
-
- encode_uint32(mods, &buf[llen]);
- encode_uint32(ie.key.scancode, &buf[llen + 4]);
- }
- llen += 8;
-
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- if (buf) {
-
- encode_uint32(ie.mouse_button.button_index, &buf[llen]);
- }
- llen += 4;
- } break;
- case InputEvent::JOYPAD_BUTTON: {
-
- if (buf) {
-
- encode_uint32(ie.joy_button.button_index, &buf[llen]);
- }
- llen += 4;
- } break;
- case InputEvent::SCREEN_TOUCH: {
-
- if (buf) {
-
- encode_uint32(ie.screen_touch.index, &buf[llen]);
- }
- llen += 4;
- } break;
- case InputEvent::JOYPAD_MOTION: {
-
- if (buf) {
-
- int axis = ie.joy_motion.axis;
- encode_uint32(axis, &buf[llen]);
- encode_float(ie.joy_motion.axis_value, &buf[llen + 4]);
- }
- llen += 8;
- } break;
- }
-
- if (buf)
- encode_uint32(llen, &buf[8]);
- r_len += llen;
-
- // not supported
- } break;
case Variant::DICTIONARY: {
Dictionary d = p_variant;
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 4ad3d261b2..0373176cd2 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -155,8 +155,8 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
case VARIANT_RECT2: {
Rect2 v;
- v.pos.x = f->get_real();
- v.pos.y = f->get_real();
+ v.position.x = f->get_real();
+ v.position.y = f->get_real();
v.size.x = f->get_real();
v.size.y = f->get_real();
r_v = v;
@@ -191,9 +191,9 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
case VARIANT_RECT3: {
Rect3 v;
- v.pos.x = f->get_real();
- v.pos.y = f->get_real();
- v.pos.z = f->get_real();
+ v.position.x = f->get_real();
+ v.position.y = f->get_real();
+ v.position.z = f->get_real();
v.size.x = f->get_real();
v.size.y = f->get_real();
v.size.z = f->get_real();
@@ -359,13 +359,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
}
} break;
- case VARIANT_INPUT_EVENT: {
-
- InputEvent ev;
- ev.type = f->get_32(); //will only work for null though.
- r_v = ev;
-
- } break;
case VARIANT_DICTIONARY: {
uint32_t len = f->get_32();
@@ -1295,8 +1288,8 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant &p_property,
f->store_32(VARIANT_RECT2);
Rect2 val = p_property;
- f->store_real(val.pos.x);
- f->store_real(val.pos.y);
+ f->store_real(val.position.x);
+ f->store_real(val.position.y);
f->store_real(val.size.x);
f->store_real(val.size.y);
@@ -1334,9 +1327,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant &p_property,
f->store_32(VARIANT_RECT3);
Rect3 val = p_property;
- f->store_real(val.pos.x);
- f->store_real(val.pos.y);
- f->store_real(val.pos.z);
+ f->store_real(val.position.x);
+ f->store_real(val.position.y);
+ f->store_real(val.position.z);
f->store_real(val.size.x);
f->store_real(val.size.y);
f->store_real(val.size.z);
@@ -1446,13 +1439,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant &p_property,
}
} break;
- case Variant::INPUT_EVENT: {
-
- f->store_32(VARIANT_INPUT_EVENT);
- InputEvent event = p_property;
- f->store_32(0); //event type none, nothing else suported for now.
-
- } break;
case Variant::DICTIONARY: {
f->store_32(VARIANT_DICTIONARY);
diff --git a/core/io/resource_import.h b/core/io/resource_import.h
index 25b7a534b2..9d2a5180dc 100644
--- a/core/io/resource_import.h
+++ b/core/io/resource_import.h
@@ -61,6 +61,7 @@ public:
String get_internal_resource_path(const String &p_path) const;
void add_importer(const Ref<ResourceImporter> &p_importer) { importers.insert(p_importer); }
+ void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); }
Ref<ResourceImporter> get_importer_by_name(const String &p_name);
Ref<ResourceImporter> get_importer_by_extension(const String &p_extension);
void get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers);
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index c327f7ca44..320990cc50 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -43,6 +43,7 @@ int AStar::get_available_point_id() const {
void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
ERR_FAIL_COND(p_id < 0);
+ ERR_FAIL_COND(p_weight_scale < 1);
if (!points.has(p_id)) {
Point *pt = memnew(Point);
pt->id = p_id;
@@ -86,7 +87,7 @@ void AStar::remove_point(int p_id) {
points.erase(p_id);
}
-void AStar::connect_points(int p_id, int p_with_id) {
+void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
ERR_FAIL_COND(!points.has(p_id));
ERR_FAIL_COND(!points.has(p_with_id));
@@ -95,7 +96,9 @@ void AStar::connect_points(int p_id, int p_with_id) {
Point *a = points[p_id];
Point *b = points[p_with_id];
a->neighbours.push_back(b);
- b->neighbours.push_back(a);
+
+ if (bidirectional)
+ b->neighbours.push_back(a);
Segment s(p_id, p_with_id);
if (s.from == p_id) {
@@ -190,8 +193,7 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
Point *n = begin_point->neighbours[i];
n->prev_point = begin_point;
- n->distance = _compute_cost(n->id, begin_point->id);
- n->distance *= n->weight_scale;
+ n->distance = _compute_cost(begin_point->id, n->id) * n->weight_scale;
n->last_pass = pass;
open_list.add(&n->list);
@@ -219,7 +221,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
real_t cost = p->distance;
cost += _estimate_cost(p->id, end_point->id);
- cost *= p->weight_scale;
if (cost < least_cost) {
@@ -236,8 +237,7 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
Point *e = p->neighbours[i];
- real_t distance = _compute_cost(p->id, e->id) + p->distance;
- distance *= e->weight_scale;
+ real_t distance = _compute_cost(p->id, e->id) * e->weight_scale + p->distance;
if (e->last_pass == pass) {
//oh this was visited already, can we win the cost?
@@ -401,7 +401,7 @@ void AStar::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_point_weight_scale", "id"), &AStar::get_point_weight_scale);
ClassDB::bind_method(D_METHOD("remove_point", "id"), &AStar::remove_point);
- ClassDB::bind_method(D_METHOD("connect_points", "id", "to_id"), &AStar::connect_points);
+ ClassDB::bind_method(D_METHOD("connect_points", "id", "to_id"), &AStar::connect_points, DEFVAL(true));
ClassDB::bind_method(D_METHOD("disconnect_points", "id", "to_id"), &AStar::disconnect_points);
ClassDB::bind_method(D_METHOD("are_points_connected", "id", "to_id"), &AStar::are_points_connected);
diff --git a/core/math/a_star.h b/core/math/a_star.h
index b9c8833386..34a5358344 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -105,7 +105,7 @@ public:
real_t get_point_weight_scale(int p_id) const;
void remove_point(int p_id);
- void connect_points(int p_id, int p_with_id);
+ void connect_points(int p_id, int p_with_id, bool bidirectional = true);
void disconnect_points(int p_id, int p_with_id);
bool are_points_connected(int p_id, int p_with_id) const;
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index 9bbce752c0..327a6017c3 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -39,8 +39,8 @@ void BSP_Tree::from_aabb(const Rect3 &p_aabb) {
Vector3 n;
n[i] = 1;
- planes.push_back(Plane(n, p_aabb.pos[i] + p_aabb.size[i]));
- planes.push_back(Plane(-n, -p_aabb.pos[i]));
+ planes.push_back(Plane(n, p_aabb.position[i] + p_aabb.size[i]));
+ planes.push_back(Plane(-n, -p_aabb.position[i]));
}
nodes.clear();
@@ -552,7 +552,7 @@ BSP_Tree::BSP_Tree(const PoolVector<Face3> &p_faces, real_t p_error_radius) {
if (first) {
- aabb.pos = f.vertex[0];
+ aabb.position = f.vertex[0];
first = false;
} else {
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 5b072b7c53..33ad522315 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -507,8 +507,8 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) {
m[9] = 0.0,
m[10] = 1.0,
m[11] = 0.0,
- m[12] = p_rect.pos.x,
- m[13] = p_rect.pos.y,
+ m[12] = p_rect.position.x,
+ m[13] = p_rect.position.y,
m[14] = 0.0,
m[15] = 1.0;
}
@@ -559,8 +559,8 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) {
void CameraMatrix::scale_translate_to_fit(const Rect3 &p_aabb) {
- Vector3 min = p_aabb.pos;
- Vector3 max = p_aabb.pos + p_aabb.size;
+ Vector3 min = p_aabb.position;
+ Vector3 max = p_aabb.position + p_aabb.size;
matrix[0][0] = 2 / (max.x - min.x);
matrix[1][0] = 0;
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index 6d772cf08c..5b66e1999a 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -197,20 +197,20 @@ bool Face3::intersects_aabb(const Rect3 &p_aabb) const {
/** TEST FACE AXIS */
-#define TEST_AXIS(m_ax) \
- { \
- real_t aabb_min = p_aabb.pos.m_ax; \
- real_t aabb_max = p_aabb.pos.m_ax + p_aabb.size.m_ax; \
- real_t tri_min, tri_max; \
- for (int i = 0; i < 3; i++) { \
- if (i == 0 || vertex[i].m_ax > tri_max) \
- tri_max = vertex[i].m_ax; \
- if (i == 0 || vertex[i].m_ax < tri_min) \
- tri_min = vertex[i].m_ax; \
- } \
- \
- if (tri_max < aabb_min || aabb_max < tri_min) \
- return false; \
+#define TEST_AXIS(m_ax) \
+ { \
+ real_t aabb_min = p_aabb.position.m_ax; \
+ real_t aabb_max = p_aabb.position.m_ax + p_aabb.size.m_ax; \
+ real_t tri_min, tri_max; \
+ for (int i = 0; i < 3; i++) { \
+ if (i == 0 || vertex[i].m_ax > tri_max) \
+ tri_max = vertex[i].m_ax; \
+ if (i == 0 || vertex[i].m_ax < tri_min) \
+ tri_min = vertex[i].m_ax; \
+ } \
+ \
+ if (tri_max < aabb_min || aabb_max < tri_min) \
+ return false; \
}
TEST_AXIS(x);
diff --git a/core/math/face3.h b/core/math/face3.h
index 31ab72b925..1cc94321c3 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -101,7 +101,7 @@ bool Face3::intersects_aabb2(const Rect3 &p_aabb) const {
Vector3 perp = (vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]);
Vector3 half_extents = p_aabb.size * 0.5;
- Vector3 ofs = p_aabb.pos + half_extents;
+ Vector3 ofs = p_aabb.position + half_extents;
Vector3 sup = Vector3(
(perp.x > 0) ? -half_extents.x : half_extents.x,
@@ -117,8 +117,8 @@ bool Face3::intersects_aabb2(const Rect3 &p_aabb) const {
#define TEST_AXIS(m_ax) \
{ \
- real_t aabb_min = p_aabb.pos.m_ax; \
- real_t aabb_max = p_aabb.pos.m_ax + p_aabb.size.m_ax; \
+ real_t aabb_min = p_aabb.position.m_ax; \
+ real_t aabb_max = p_aabb.position.m_ax + p_aabb.size.m_ax; \
real_t tri_min, tri_max; \
for (int i = 0; i < 3; i++) { \
if (i == 0 || vertex[i].m_ax > tri_max) \
@@ -150,68 +150,68 @@ bool Face3::intersects_aabb2(const Rect3 &p_aabb) const {
case 0: {
- from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z);
- to = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z);
+ from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z);
+ to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z);
} break;
case 1: {
- from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z);
- to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z);
+ from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
+ to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z);
} break;
case 2: {
- from = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z);
- to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z);
+ from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
+ to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
} break;
case 3: {
- from = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z);
- to = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z);
+ from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z);
+ to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
} break;
case 4: {
- from = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z);
- to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z);
+ from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
+ to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
} break;
case 5: {
- from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z);
- to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z);
+ from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
+ to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
} break;
case 6: {
- from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z);
- to = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z);
+ from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
+ to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
} break;
case 7: {
- from = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z);
- to = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z);
+ from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
+ to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
} break;
case 8: {
- from = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z);
- to = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z);
+ from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
+ to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
} break;
case 9: {
- from = Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z);
- to = Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z);
+ from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z);
+ to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
} break;
case 10: {
- from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z);
- to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z);
+ from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z);
+ to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z);
} break;
case 11: {
- from = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z);
- to = Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z);
+ from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z);
+ to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z);
} break;
}
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index 618017f8b3..2bea514d37 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -301,7 +301,7 @@ enum _CellFlags {
static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, const Vector3 &voxelsize, const Face3 &p_face) {
Rect3 aabb(Vector3(x, y, z), Vector3(len_x, len_y, len_z));
- aabb.pos = aabb.pos * voxelsize;
+ aabb.position = aabb.position * voxelsize;
aabb.size = aabb.size * voxelsize;
if (!p_face.intersects_aabb(aabb))
@@ -640,7 +640,7 @@ PoolVector<Face3> Geometry::wrap_geometry(PoolVector<Face3> p_array, real_t *p_e
Face3 f = faces[i];
for (int j = 0; j < 3; j++) {
- f.vertex[j] -= global_aabb.pos;
+ f.vertex[j] -= global_aabb.position;
}
_plot_face(cell_status, 0, 0, 0, div_x, div_y, div_z, voxelsize, f);
}
@@ -707,7 +707,7 @@ PoolVector<Face3> Geometry::wrap_geometry(PoolVector<Face3> p_array, real_t *p_e
Vector3 &v = wrapped_faces_ptr[i].vertex[j];
v = v * voxelsize;
- v += global_aabb.pos;
+ v += global_aabb.position;
}
}
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp
index 962a42acb9..52e240ed47 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -308,7 +308,7 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
for (int i = 0; i < 2; i++) {
real_t seg_from = p_from[i];
real_t seg_to = p_to[i];
- real_t box_begin = pos[i];
+ real_t box_begin = position[i];
real_t box_end = box_begin + size[i];
real_t cmin, cmax;
real_t csign;
diff --git a/core/math/math_2d.h b/core/math/math_2d.h
index 128b74baf6..780bb532d7 100644
--- a/core/math/math_2d.h
+++ b/core/math/math_2d.h
@@ -207,24 +207,24 @@ struct Transform2D;
struct Rect2 {
- Point2 pos;
+ Point2 position;
Size2 size;
- const Vector2 &get_pos() const { return pos; }
- void set_pos(const Vector2 &p_pos) { pos = p_pos; }
+ const Vector2 &get_position() const { return position; }
+ void set_position(const Vector2 &p_pos) { position = p_pos; }
const Vector2 &get_size() const { return size; }
void set_size(const Vector2 &p_size) { size = p_size; }
real_t get_area() const { return size.width * size.height; }
inline bool intersects(const Rect2 &p_rect) const {
- if (pos.x >= (p_rect.pos.x + p_rect.size.width))
+ if (position.x >= (p_rect.position.x + p_rect.size.width))
return false;
- if ((pos.x + size.width) <= p_rect.pos.x)
+ if ((position.x + size.width) <= p_rect.position.x)
return false;
- if (pos.y >= (p_rect.pos.y + p_rect.size.height))
+ if (position.y >= (p_rect.position.y + p_rect.size.height))
return false;
- if ((pos.y + size.height) <= p_rect.pos.y)
+ if ((position.y + size.height) <= p_rect.position.y)
return false;
return true;
@@ -234,17 +234,17 @@ struct Rect2 {
real_t dist = 1e20;
- if (p_point.x < pos.x) {
- dist = MIN(dist, pos.x - p_point.x);
+ if (p_point.x < position.x) {
+ dist = MIN(dist, position.x - p_point.x);
}
- if (p_point.y < pos.y) {
- dist = MIN(dist, pos.y - p_point.y);
+ if (p_point.y < position.y) {
+ dist = MIN(dist, position.y - p_point.y);
}
- if (p_point.x >= (pos.x + size.x)) {
- dist = MIN(p_point.x - (pos.x + size.x), dist);
+ if (p_point.x >= (position.x + size.x)) {
+ dist = MIN(p_point.x - (position.x + size.x), dist);
}
- if (p_point.y >= (pos.y + size.y)) {
- dist = MIN(p_point.y - (pos.y + size.y), dist);
+ if (p_point.y >= (position.y + size.y)) {
+ dist = MIN(p_point.y - (position.y + size.y), dist);
}
if (dist == 1e20)
@@ -259,9 +259,9 @@ struct Rect2 {
inline bool encloses(const Rect2 &p_rect) const {
- return (p_rect.pos.x >= pos.x) && (p_rect.pos.y >= pos.y) &&
- ((p_rect.pos.x + p_rect.size.x) < (pos.x + size.x)) &&
- ((p_rect.pos.y + p_rect.size.y) < (pos.y + size.y));
+ return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) &&
+ ((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) &&
+ ((p_rect.position.y + p_rect.size.y) < (position.y + size.y));
}
inline bool has_no_area() const {
@@ -275,14 +275,14 @@ struct Rect2 {
if (!intersects(new_rect))
return Rect2();
- new_rect.pos.x = MAX(p_rect.pos.x, pos.x);
- new_rect.pos.y = MAX(p_rect.pos.y, pos.y);
+ new_rect.position.x = MAX(p_rect.position.x, position.x);
+ new_rect.position.y = MAX(p_rect.position.y, position.y);
- Point2 p_rect_end = p_rect.pos + p_rect.size;
- Point2 end = pos + size;
+ Point2 p_rect_end = p_rect.position + p_rect.size;
+ Point2 end = position + size;
- new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.pos.x;
- new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.pos.y;
+ new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.position.x;
+ new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.position.y;
return new_rect;
}
@@ -291,25 +291,25 @@ struct Rect2 {
Rect2 new_rect;
- new_rect.pos.x = MIN(p_rect.pos.x, pos.x);
- new_rect.pos.y = MIN(p_rect.pos.y, pos.y);
+ new_rect.position.x = MIN(p_rect.position.x, position.x);
+ new_rect.position.y = MIN(p_rect.position.y, position.y);
- new_rect.size.x = MAX(p_rect.pos.x + p_rect.size.x, pos.x + size.x);
- new_rect.size.y = MAX(p_rect.pos.y + p_rect.size.y, pos.y + size.y);
+ new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x);
+ new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y);
- new_rect.size = new_rect.size - new_rect.pos; //make relative again
+ new_rect.size = new_rect.size - new_rect.position; //make relative again
return new_rect;
};
inline bool has_point(const Point2 &p_point) const {
- if (p_point.x < pos.x)
+ if (p_point.x < position.x)
return false;
- if (p_point.y < pos.y)
+ if (p_point.y < position.y)
return false;
- if (p_point.x >= (pos.x + size.x))
+ if (p_point.x >= (position.x + size.x))
return false;
- if (p_point.y >= (pos.y + size.y))
+ if (p_point.y >= (position.y + size.y))
return false;
return true;
@@ -317,18 +317,37 @@ struct Rect2 {
inline bool no_area() const { return (size.width <= 0 || size.height <= 0); }
- bool operator==(const Rect2 &p_rect) const { return pos == p_rect.pos && size == p_rect.size; }
- bool operator!=(const Rect2 &p_rect) const { return pos != p_rect.pos || size != p_rect.size; }
+ bool operator==(const Rect2 &p_rect) const { return position == p_rect.position && size == p_rect.size; }
+ bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; }
inline Rect2 grow(real_t p_by) const {
Rect2 g = *this;
- g.pos.x -= p_by;
- g.pos.y -= p_by;
+ g.position.x -= p_by;
+ g.position.y -= p_by;
g.size.width += p_by * 2;
g.size.height += p_by * 2;
return g;
}
+ inline Rect2 grow_margin(Margin p_margin, real_t p_amount) const {
+ Rect2 g = *this;
+ g.grow_individual((MARGIN_LEFT == p_margin) ? p_amount : 0,
+ (MARGIN_TOP == p_margin) ? p_amount : 0,
+ (MARGIN_RIGHT == p_margin) ? p_amount : 0,
+ (MARGIN_BOTTOM == p_margin) ? p_amount : 0);
+ return g;
+ }
+
+ inline Rect2 grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom) const {
+
+ Rect2 g = *this;
+ g.position.x -= p_left;
+ g.position.y -= p_top;
+ g.size.width += p_left + p_right;
+ g.size.height += p_top + p_bottom;
+
+ return g;
+ }
inline Rect2 expand(const Vector2 &p_vector) const {
@@ -339,8 +358,8 @@ struct Rect2 {
inline void expand_to(const Vector2 &p_vector) { //in place function for speed
- Vector2 begin = pos;
- Vector2 end = pos + size;
+ Vector2 begin = position;
+ Vector2 end = position + size;
if (p_vector.x < begin.x)
begin.x = p_vector.x;
@@ -352,19 +371,19 @@ struct Rect2 {
if (p_vector.y > end.y)
end.y = p_vector.y;
- pos = begin;
+ position = begin;
size = end - begin;
}
- operator String() const { return String(pos) + ", " + String(size); }
+ operator String() const { return String(position) + ", " + String(size); }
Rect2() {}
Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) {
- pos = Point2(p_x, p_y);
+ position = Point2(p_x, p_y);
size = Size2(p_width, p_height);
}
Rect2(const Point2 &p_pos, const Size2 &p_size) {
- pos = p_pos;
+ position = p_pos;
size = p_size;
}
};
@@ -434,24 +453,24 @@ typedef Point2i Size2i;
struct Rect2i {
- Point2i pos;
+ Point2i position;
Size2i size;
- const Point2i &get_pos() const { return pos; }
- void set_pos(const Point2i &p_pos) { pos = p_pos; }
+ const Point2i &get_position() const { return position; }
+ void set_position(const Point2i &p_pos) { position = p_pos; }
const Point2i &get_size() const { return size; }
void set_size(const Point2i &p_size) { size = p_size; }
int get_area() const { return size.width * size.height; }
inline bool intersects(const Rect2i &p_rect) const {
- if (pos.x > (p_rect.pos.x + p_rect.size.width))
+ if (position.x > (p_rect.position.x + p_rect.size.width))
return false;
- if ((pos.x + size.width) < p_rect.pos.x)
+ if ((position.x + size.width) < p_rect.position.x)
return false;
- if (pos.y > (p_rect.pos.y + p_rect.size.height))
+ if (position.y > (p_rect.position.y + p_rect.size.height))
return false;
- if ((pos.y + size.height) < p_rect.pos.y)
+ if ((position.y + size.height) < p_rect.position.y)
return false;
return true;
@@ -459,9 +478,9 @@ struct Rect2i {
inline bool encloses(const Rect2i &p_rect) const {
- return (p_rect.pos.x >= pos.x) && (p_rect.pos.y >= pos.y) &&
- ((p_rect.pos.x + p_rect.size.x) < (pos.x + size.x)) &&
- ((p_rect.pos.y + p_rect.size.y) < (pos.y + size.y));
+ return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) &&
+ ((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) &&
+ ((p_rect.position.y + p_rect.size.y) < (position.y + size.y));
}
inline bool has_no_area() const {
@@ -475,14 +494,14 @@ struct Rect2i {
if (!intersects(new_rect))
return Rect2i();
- new_rect.pos.x = MAX(p_rect.pos.x, pos.x);
- new_rect.pos.y = MAX(p_rect.pos.y, pos.y);
+ new_rect.position.x = MAX(p_rect.position.x, position.x);
+ new_rect.position.y = MAX(p_rect.position.y, position.y);
- Point2 p_rect_end = p_rect.pos + p_rect.size;
- Point2 end = pos + size;
+ Point2 p_rect_end = p_rect.position + p_rect.size;
+ Point2 end = position + size;
- new_rect.size.x = (int)(MIN(p_rect_end.x, end.x) - new_rect.pos.x);
- new_rect.size.y = (int)(MIN(p_rect_end.y, end.y) - new_rect.pos.y);
+ new_rect.size.x = (int)(MIN(p_rect_end.x, end.x) - new_rect.position.x);
+ new_rect.size.y = (int)(MIN(p_rect_end.y, end.y) - new_rect.position.y);
return new_rect;
}
@@ -491,25 +510,25 @@ struct Rect2i {
Rect2i new_rect;
- new_rect.pos.x = MIN(p_rect.pos.x, pos.x);
- new_rect.pos.y = MIN(p_rect.pos.y, pos.y);
+ new_rect.position.x = MIN(p_rect.position.x, position.x);
+ new_rect.position.y = MIN(p_rect.position.y, position.y);
- new_rect.size.x = MAX(p_rect.pos.x + p_rect.size.x, pos.x + size.x);
- new_rect.size.y = MAX(p_rect.pos.y + p_rect.size.y, pos.y + size.y);
+ new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x);
+ new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y);
- new_rect.size = new_rect.size - new_rect.pos; //make relative again
+ new_rect.size = new_rect.size - new_rect.position; //make relative again
return new_rect;
};
bool has_point(const Point2 &p_point) const {
- if (p_point.x < pos.x)
+ if (p_point.x < position.x)
return false;
- if (p_point.y < pos.y)
+ if (p_point.y < position.y)
return false;
- if (p_point.x >= (pos.x + size.x))
+ if (p_point.x >= (position.x + size.x))
return false;
- if (p_point.y >= (pos.y + size.y))
+ if (p_point.y >= (position.y + size.y))
return false;
return true;
@@ -517,14 +536,14 @@ struct Rect2i {
bool no_area() { return (size.width <= 0 || size.height <= 0); }
- bool operator==(const Rect2i &p_rect) const { return pos == p_rect.pos && size == p_rect.size; }
- bool operator!=(const Rect2i &p_rect) const { return pos != p_rect.pos || size != p_rect.size; }
+ bool operator==(const Rect2i &p_rect) const { return position == p_rect.position && size == p_rect.size; }
+ bool operator!=(const Rect2i &p_rect) const { return position != p_rect.position || size != p_rect.size; }
Rect2i grow(int p_by) const {
Rect2i g = *this;
- g.pos.x -= p_by;
- g.pos.y -= p_by;
+ g.position.x -= p_by;
+ g.position.y -= p_by;
g.size.width += p_by * 2;
g.size.height += p_by * 2;
return g;
@@ -532,8 +551,8 @@ struct Rect2i {
inline void expand_to(const Point2i &p_vector) {
- Point2i begin = pos;
- Point2i end = pos + size;
+ Point2i begin = position;
+ Point2i end = position + size;
if (p_vector.x < begin.x)
begin.x = p_vector.x;
@@ -545,24 +564,24 @@ struct Rect2i {
if (p_vector.y > end.y)
end.y = p_vector.y;
- pos = begin;
+ position = begin;
size = end - begin;
}
- operator String() const { return String(pos) + ", " + String(size); }
+ operator String() const { return String(position) + ", " + String(size); }
- operator Rect2() const { return Rect2(pos, size); }
+ operator Rect2() const { return Rect2(position, size); }
Rect2i(const Rect2 &p_r2) {
- pos = p_r2.pos;
+ position = p_r2.position;
size = p_r2.size;
}
Rect2i() {}
Rect2i(int p_x, int p_y, int p_width, int p_height) {
- pos = Point2(p_x, p_y);
+ position = Point2(p_x, p_y);
size = Size2(p_width, p_height);
}
Rect2i(const Point2 &p_pos, const Size2 &p_size) {
- pos = p_pos;
+ position = p_pos;
size = p_size;
}
};
@@ -668,30 +687,30 @@ bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_re
//SAT intersection between local and transformed rect2
Vector2 xf_points[4] = {
- p_xform.xform(p_rect.pos),
- p_xform.xform(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y)),
- p_xform.xform(Vector2(p_rect.pos.x, p_rect.pos.y + p_rect.size.y)),
- p_xform.xform(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y + p_rect.size.y)),
+ p_xform.xform(p_rect.position),
+ p_xform.xform(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y)),
+ p_xform.xform(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)),
+ p_xform.xform(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y + p_rect.size.y)),
};
real_t low_limit;
//base rect2 first (faster)
- if (xf_points[0].y > pos.y)
+ if (xf_points[0].y > position.y)
goto next1;
- if (xf_points[1].y > pos.y)
+ if (xf_points[1].y > position.y)
goto next1;
- if (xf_points[2].y > pos.y)
+ if (xf_points[2].y > position.y)
goto next1;
- if (xf_points[3].y > pos.y)
+ if (xf_points[3].y > position.y)
goto next1;
return false;
next1:
- low_limit = pos.y + size.y;
+ low_limit = position.y + size.y;
if (xf_points[0].y < low_limit)
goto next2;
@@ -706,20 +725,20 @@ next1:
next2:
- if (xf_points[0].x > pos.x)
+ if (xf_points[0].x > position.x)
goto next3;
- if (xf_points[1].x > pos.x)
+ if (xf_points[1].x > position.x)
goto next3;
- if (xf_points[2].x > pos.x)
+ if (xf_points[2].x > position.x)
goto next3;
- if (xf_points[3].x > pos.x)
+ if (xf_points[3].x > position.x)
goto next3;
return false;
next3:
- low_limit = pos.x + size.x;
+ low_limit = position.x + size.x;
if (xf_points[0].x < low_limit)
goto next4;
@@ -735,10 +754,10 @@ next3:
next4:
Vector2 xf_points2[4] = {
- pos,
- Vector2(pos.x + size.x, pos.y),
- Vector2(pos.x, pos.y + size.y),
- Vector2(pos.x + size.x, pos.y + size.y),
+ position,
+ Vector2(position.x + size.x, position.y),
+ Vector2(position.x, position.y + size.y),
+ Vector2(position.x + size.x, position.y + size.y),
};
real_t maxa = p_xform.elements[0].dot(xf_points2[0]);
@@ -847,10 +866,10 @@ Rect2 Transform2D::xform(const Rect2 &p_rect) const {
Vector2 x = elements[0] * p_rect.size.x;
Vector2 y = elements[1] * p_rect.size.y;
- Vector2 pos = xform(p_rect.pos);
+ Vector2 pos = xform(p_rect.position);
Rect2 new_rect;
- new_rect.pos = pos;
+ new_rect.position = pos;
new_rect.expand_to(pos + x);
new_rect.expand_to(pos + y);
new_rect.expand_to(pos + x + y);
@@ -868,14 +887,14 @@ void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) {
Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const {
Vector2 ends[4] = {
- xform_inv(p_rect.pos),
- xform_inv(Vector2(p_rect.pos.x, p_rect.pos.y + p_rect.size.y)),
- xform_inv(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y + p_rect.size.y)),
- xform_inv(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y))
+ xform_inv(p_rect.position),
+ xform_inv(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)),
+ xform_inv(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y + p_rect.size.y)),
+ xform_inv(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y))
};
Rect2 new_rect;
- new_rect.pos = ends[0];
+ new_rect.position = ends[0];
new_rect.expand_to(ends[1]);
new_rect.expand_to(ends[2]);
new_rect.expand_to(ends[3]);
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 06ec77daae..ca960aabad 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -51,9 +51,7 @@ class Math {
public:
Math() {} // useless to instance
- enum {
- RANDOM_MAX = 4294967295L
- };
+ static const uint64_t RANDOM_MAX = 4294967295;
static _ALWAYS_INLINE_ double sin(double p_x) { return ::sin(p_x); }
static _ALWAYS_INLINE_ float sin(float p_x) { return ::sinf(p_x); }
@@ -278,6 +276,10 @@ public:
return u.f32;
}
+ static _ALWAYS_INLINE_ float half_to_float(const uint16_t h) {
+ return halfptr_to_float(&h);
+ }
+
static _ALWAYS_INLINE_ uint16_t make_half_float(float f) {
union {
diff --git a/core/math/octree.h b/core/math/octree.h
index 4cc046ddf4..010c1b18f7 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -483,11 +483,11 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
aabb.size *= 0.5;
if (i & 1)
- aabb.pos.x += aabb.size.x;
+ aabb.position.x += aabb.size.x;
if (i & 2)
- aabb.pos.y += aabb.size.y;
+ aabb.position.y += aabb.size.y;
if (i & 4)
- aabb.pos.z += aabb.size.z;
+ aabb.position.z += aabb.size.z;
if (aabb.intersects_inclusive(p_element->aabb)) {
/* if actually intersects, create the child */
@@ -544,11 +544,11 @@ void Octree<T, use_pairs, AL>::_ensure_valid_root(const Rect3 &p_aabb) {
while (!base.encloses(p_aabb)) {
- if (ABS(base.pos.x + base.size.x) <= ABS(base.pos.x)) {
+ if (ABS(base.position.x + base.size.x) <= ABS(base.position.x)) {
/* grow towards positive */
base.size *= 2.0;
} else {
- base.pos -= base.size;
+ base.position -= base.size;
base.size *= 2.0;
}
}
@@ -576,14 +576,14 @@ void Octree<T, use_pairs, AL>::_ensure_valid_root(const Rect3 &p_aabb) {
octant_count++;
root->parent = gp;
- if (ABS(base.pos.x + base.size.x) <= ABS(base.pos.x)) {
+ if (ABS(base.position.x + base.size.x) <= ABS(base.position.x)) {
/* grow towards positive */
base.size *= 2.0;
gp->aabb = base;
gp->children[0] = root;
root->parent_index = 0;
} else {
- base.pos -= base.size;
+ base.position -= base.size;
base.size *= 2.0;
gp->aabb = base;
gp->children[(1 << 0) | (1 << 1) | (1 << 2)] = root; // add at all-positive
@@ -797,9 +797,9 @@ OctreeElementID Octree<T, use_pairs, AL>::create(T *p_userdata, const Rect3 &p_a
// check for AABB validity
#ifdef DEBUG_ENABLED
- ERR_FAIL_COND_V(p_aabb.pos.x > 1e15 || p_aabb.pos.x < -1e15, 0);
- ERR_FAIL_COND_V(p_aabb.pos.y > 1e15 || p_aabb.pos.y < -1e15, 0);
- ERR_FAIL_COND_V(p_aabb.pos.z > 1e15 || p_aabb.pos.z < -1e15, 0);
+ ERR_FAIL_COND_V(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15, 0);
+ ERR_FAIL_COND_V(p_aabb.position.y > 1e15 || p_aabb.position.y < -1e15, 0);
+ ERR_FAIL_COND_V(p_aabb.position.z > 1e15 || p_aabb.position.z < -1e15, 0);
ERR_FAIL_COND_V(p_aabb.size.x > 1e15 || p_aabb.size.x < 0.0, 0);
ERR_FAIL_COND_V(p_aabb.size.y > 1e15 || p_aabb.size.y < 0.0, 0);
ERR_FAIL_COND_V(p_aabb.size.z > 1e15 || p_aabb.size.z < 0.0, 0);
@@ -837,9 +837,9 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const Rect3 &p_aabb) {
#ifdef DEBUG_ENABLED
// check for AABB validity
- ERR_FAIL_COND(p_aabb.pos.x > 1e15 || p_aabb.pos.x < -1e15);
- ERR_FAIL_COND(p_aabb.pos.y > 1e15 || p_aabb.pos.y < -1e15);
- ERR_FAIL_COND(p_aabb.pos.z > 1e15 || p_aabb.pos.z < -1e15);
+ ERR_FAIL_COND(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15);
+ ERR_FAIL_COND(p_aabb.position.y > 1e15 || p_aabb.position.y < -1e15);
+ ERR_FAIL_COND(p_aabb.position.z > 1e15 || p_aabb.position.z < -1e15);
ERR_FAIL_COND(p_aabb.size.x > 1e15 || p_aabb.size.x < 0.0);
ERR_FAIL_COND(p_aabb.size.y > 1e15 || p_aabb.size.y < 0.0);
ERR_FAIL_COND(p_aabb.size.z > 1e15 || p_aabb.size.z < 0.0);
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index ce93720067..9f594ba4fa 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -42,7 +42,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
for (int i = 0; i < p_points.size(); i++) {
if (i == 0) {
- aabb.pos = p_points[i];
+ aabb.position = p_points[i];
} else {
aabb.expand_to(p_points[i]);
}
diff --git a/core/math/rect3.cpp b/core/math/rect3.cpp
index 39b0beb071..973607f565 100644
--- a/core/math/rect3.cpp
+++ b/core/math/rect3.cpp
@@ -38,11 +38,11 @@ real_t Rect3::get_area() const {
bool Rect3::operator==(const Rect3 &p_rval) const {
- return ((pos == p_rval.pos) && (size == p_rval.size));
+ return ((position == p_rval.position) && (size == p_rval.size));
}
bool Rect3::operator!=(const Rect3 &p_rval) const {
- return ((pos != p_rval.pos) || (size != p_rval.size));
+ return ((position != p_rval.position) || (size != p_rval.size));
}
void Rect3::merge_with(const Rect3 &p_aabb) {
@@ -51,8 +51,8 @@ void Rect3::merge_with(const Rect3 &p_aabb) {
Vector3 end_1, end_2;
Vector3 min, max;
- beg_1 = pos;
- beg_2 = p_aabb.pos;
+ beg_1 = position;
+ beg_2 = p_aabb.position;
end_1 = Vector3(size.x, size.y, size.z) + beg_1;
end_2 = Vector3(p_aabb.size.x, p_aabb.size.y, p_aabb.size.z) + beg_2;
@@ -64,16 +64,16 @@ void Rect3::merge_with(const Rect3 &p_aabb) {
max.y = (end_1.y > end_2.y) ? end_1.y : end_2.y;
max.z = (end_1.z > end_2.z) ? end_1.z : end_2.z;
- pos = min;
+ position = min;
size = max - min;
}
Rect3 Rect3::intersection(const Rect3 &p_aabb) const {
- Vector3 src_min = pos;
- Vector3 src_max = pos + size;
- Vector3 dst_min = p_aabb.pos;
- Vector3 dst_max = p_aabb.pos + p_aabb.size;
+ Vector3 src_min = position;
+ Vector3 src_max = position + size;
+ Vector3 dst_min = p_aabb.position;
+ Vector3 dst_max = p_aabb.position + p_aabb.size;
Vector3 min, max;
@@ -107,18 +107,18 @@ Rect3 Rect3::intersection(const Rect3 &p_aabb) const {
bool Rect3::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const {
Vector3 c1, c2;
- Vector3 end = pos + size;
+ Vector3 end = position + size;
real_t near = -1e20;
real_t far = 1e20;
int axis = 0;
for (int i = 0; i < 3; i++) {
if (p_dir[i] == 0) {
- if ((p_from[i] < pos[i]) || (p_from[i] > end[i])) {
+ if ((p_from[i] < position[i]) || (p_from[i] > end[i])) {
return false;
}
} else { // ray not parallel to planes in this direction
- c1[i] = (pos[i] - p_from[i]) / p_dir[i];
+ c1[i] = (position[i] - p_from[i]) / p_dir[i];
c2[i] = (end[i] - p_from[i]) / p_dir[i];
if (c1[i] > c2[i]) {
@@ -156,7 +156,7 @@ bool Rect3::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vecto
for (int i = 0; i < 3; i++) {
real_t seg_from = p_from[i];
real_t seg_to = p_to[i];
- real_t box_begin = pos[i];
+ real_t box_begin = position[i];
real_t box_end = box_begin + size[i];
real_t cmin, cmax;
real_t csign;
@@ -208,14 +208,14 @@ bool Rect3::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vecto
bool Rect3::intersects_plane(const Plane &p_plane) const {
Vector3 points[8] = {
- Vector3(pos.x, pos.y, pos.z),
- Vector3(pos.x, pos.y, pos.z + size.z),
- Vector3(pos.x, pos.y + size.y, pos.z),
- Vector3(pos.x, pos.y + size.y, pos.z + size.z),
- Vector3(pos.x + size.x, pos.y, pos.z),
- Vector3(pos.x + size.x, pos.y, pos.z + size.z),
- Vector3(pos.x + size.x, pos.y + size.y, pos.z),
- Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z),
+ Vector3(position.x, position.y, position.z),
+ Vector3(position.x, position.y, position.z + size.z),
+ Vector3(position.x, position.y + size.y, position.z),
+ Vector3(position.x, position.y + size.y, position.z + size.z),
+ Vector3(position.x + size.x, position.y, position.z),
+ Vector3(position.x + size.x, position.y, position.z + size.z),
+ Vector3(position.x + size.x, position.y + size.y, position.z),
+ Vector3(position.x + size.x, position.y + size.y, position.z + size.z),
};
bool over = false;
@@ -327,68 +327,68 @@ void Rect3::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
case 0: {
- r_from = Vector3(pos.x + size.x, pos.y, pos.z);
- r_to = Vector3(pos.x, pos.y, pos.z);
+ r_from = Vector3(position.x + size.x, position.y, position.z);
+ r_to = Vector3(position.x, position.y, position.z);
} break;
case 1: {
- r_from = Vector3(pos.x + size.x, pos.y, pos.z + size.z);
- r_to = Vector3(pos.x + size.x, pos.y, pos.z);
+ r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
+ r_to = Vector3(position.x + size.x, position.y, position.z);
} break;
case 2: {
- r_from = Vector3(pos.x, pos.y, pos.z + size.z);
- r_to = Vector3(pos.x + size.x, pos.y, pos.z + size.z);
+ r_from = Vector3(position.x, position.y, position.z + size.z);
+ r_to = Vector3(position.x + size.x, position.y, position.z + size.z);
} break;
case 3: {
- r_from = Vector3(pos.x, pos.y, pos.z);
- r_to = Vector3(pos.x, pos.y, pos.z + size.z);
+ r_from = Vector3(position.x, position.y, position.z);
+ r_to = Vector3(position.x, position.y, position.z + size.z);
} break;
case 4: {
- r_from = Vector3(pos.x, pos.y + size.y, pos.z);
- r_to = Vector3(pos.x + size.x, pos.y + size.y, pos.z);
+ r_from = Vector3(position.x, position.y + size.y, position.z);
+ r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 5: {
- r_from = Vector3(pos.x + size.x, pos.y + size.y, pos.z);
- r_to = Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z);
+ r_from = Vector3(position.x + size.x, position.y + size.y, position.z);
+ r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
} break;
case 6: {
- r_from = Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z);
- r_to = Vector3(pos.x, pos.y + size.y, pos.z + size.z);
+ r_from = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
+ r_to = Vector3(position.x, position.y + size.y, position.z + size.z);
} break;
case 7: {
- r_from = Vector3(pos.x, pos.y + size.y, pos.z + size.z);
- r_to = Vector3(pos.x, pos.y + size.y, pos.z);
+ r_from = Vector3(position.x, position.y + size.y, position.z + size.z);
+ r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 8: {
- r_from = Vector3(pos.x, pos.y, pos.z + size.z);
- r_to = Vector3(pos.x, pos.y + size.y, pos.z + size.z);
+ r_from = Vector3(position.x, position.y, position.z + size.z);
+ r_to = Vector3(position.x, position.y + size.y, position.z + size.z);
} break;
case 9: {
- r_from = Vector3(pos.x, pos.y, pos.z);
- r_to = Vector3(pos.x, pos.y + size.y, pos.z);
+ r_from = Vector3(position.x, position.y, position.z);
+ r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 10: {
- r_from = Vector3(pos.x + size.x, pos.y, pos.z);
- r_to = Vector3(pos.x + size.x, pos.y + size.y, pos.z);
+ r_from = Vector3(position.x + size.x, position.y, position.z);
+ r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 11: {
- r_from = Vector3(pos.x + size.x, pos.y, pos.z + size.z);
- r_to = Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z);
+ r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
+ r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
} break;
}
@@ -396,5 +396,5 @@ void Rect3::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
Rect3::operator String() const {
- return String() + pos + " - " + size;
+ return String() + position + " - " + size;
}
diff --git a/core/math/rect3.h b/core/math/rect3.h
index 136a156151..b7c94ad9f7 100644
--- a/core/math/rect3.h
+++ b/core/math/rect3.h
@@ -36,12 +36,12 @@
/**
* AABB / AABB (Axis Aligned Bounding Box)
- * This is implemented by a point (pos) and the box size
+ * This is implemented by a point (position) and the box size
*/
class Rect3 {
public:
- Vector3 pos;
+ Vector3 position;
Vector3 size;
real_t get_area() const; /// get area
@@ -55,8 +55,8 @@ public:
return (size.x <= CMP_EPSILON && size.y <= CMP_EPSILON && size.z <= CMP_EPSILON);
}
- const Vector3 &get_pos() const { return pos; }
- void set_pos(const Vector3 &p_pos) { pos = p_pos; }
+ const Vector3 &get_position() const { return position; }
+ void set_position(const Vector3 &p_pos) { position = p_pos; }
const Vector3 &get_size() const { return size; }
void set_size(const Vector3 &p_size) { size = p_size; }
@@ -102,24 +102,24 @@ public:
_FORCE_INLINE_ Rect3() {}
inline Rect3(const Vector3 &p_pos, const Vector3 &p_size) {
- pos = p_pos;
+ position = p_pos;
size = p_size;
}
};
inline bool Rect3::intersects(const Rect3 &p_aabb) const {
- if (pos.x >= (p_aabb.pos.x + p_aabb.size.x))
+ if (position.x >= (p_aabb.position.x + p_aabb.size.x))
return false;
- if ((pos.x + size.x) <= p_aabb.pos.x)
+ if ((position.x + size.x) <= p_aabb.position.x)
return false;
- if (pos.y >= (p_aabb.pos.y + p_aabb.size.y))
+ if (position.y >= (p_aabb.position.y + p_aabb.size.y))
return false;
- if ((pos.y + size.y) <= p_aabb.pos.y)
+ if ((position.y + size.y) <= p_aabb.position.y)
return false;
- if (pos.z >= (p_aabb.pos.z + p_aabb.size.z))
+ if (position.z >= (p_aabb.position.z + p_aabb.size.z))
return false;
- if ((pos.z + size.z) <= p_aabb.pos.z)
+ if ((position.z + size.z) <= p_aabb.position.z)
return false;
return true;
@@ -127,17 +127,17 @@ inline bool Rect3::intersects(const Rect3 &p_aabb) const {
inline bool Rect3::intersects_inclusive(const Rect3 &p_aabb) const {
- if (pos.x > (p_aabb.pos.x + p_aabb.size.x))
+ if (position.x > (p_aabb.position.x + p_aabb.size.x))
return false;
- if ((pos.x + size.x) < p_aabb.pos.x)
+ if ((position.x + size.x) < p_aabb.position.x)
return false;
- if (pos.y > (p_aabb.pos.y + p_aabb.size.y))
+ if (position.y > (p_aabb.position.y + p_aabb.size.y))
return false;
- if ((pos.y + size.y) < p_aabb.pos.y)
+ if ((position.y + size.y) < p_aabb.position.y)
return false;
- if (pos.z > (p_aabb.pos.z + p_aabb.size.z))
+ if (position.z > (p_aabb.position.z + p_aabb.size.z))
return false;
- if ((pos.z + size.z) < p_aabb.pos.z)
+ if ((position.z + size.z) < p_aabb.position.z)
return false;
return true;
@@ -145,10 +145,10 @@ inline bool Rect3::intersects_inclusive(const Rect3 &p_aabb) const {
inline bool Rect3::encloses(const Rect3 &p_aabb) const {
- Vector3 src_min = pos;
- Vector3 src_max = pos + size;
- Vector3 dst_min = p_aabb.pos;
- Vector3 dst_max = p_aabb.pos + p_aabb.size;
+ Vector3 src_min = position;
+ Vector3 src_max = position + size;
+ Vector3 dst_min = p_aabb.position;
+ Vector3 dst_max = p_aabb.position + p_aabb.size;
return (
(src_min.x <= dst_min.x) &&
@@ -162,7 +162,7 @@ inline bool Rect3::encloses(const Rect3 &p_aabb) const {
Vector3 Rect3::get_support(const Vector3 &p_normal) const {
Vector3 half_extents = size * 0.5;
- Vector3 ofs = pos + half_extents;
+ Vector3 ofs = position + half_extents;
return Vector3(
(p_normal.x > 0) ? -half_extents.x : half_extents.x,
@@ -174,14 +174,14 @@ Vector3 Rect3::get_support(const Vector3 &p_normal) const {
Vector3 Rect3::get_endpoint(int p_point) const {
switch (p_point) {
- case 0: return Vector3(pos.x, pos.y, pos.z);
- case 1: return Vector3(pos.x, pos.y, pos.z + size.z);
- case 2: return Vector3(pos.x, pos.y + size.y, pos.z);
- case 3: return Vector3(pos.x, pos.y + size.y, pos.z + size.z);
- case 4: return Vector3(pos.x + size.x, pos.y, pos.z);
- case 5: return Vector3(pos.x + size.x, pos.y, pos.z + size.z);
- case 6: return Vector3(pos.x + size.x, pos.y + size.y, pos.z);
- case 7: return Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z);
+ case 0: return Vector3(position.x, position.y, position.z);
+ case 1: return Vector3(position.x, position.y, position.z + size.z);
+ case 2: return Vector3(position.x, position.y + size.y, position.z);
+ case 3: return Vector3(position.x, position.y + size.y, position.z + size.z);
+ case 4: return Vector3(position.x + size.x, position.y, position.z);
+ case 5: return Vector3(position.x + size.x, position.y, position.z + size.z);
+ case 6: return Vector3(position.x + size.x, position.y + size.y, position.z);
+ case 7: return Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
};
ERR_FAIL_V(Vector3());
@@ -192,7 +192,7 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co
#if 1
Vector3 half_extents = size * 0.5;
- Vector3 ofs = pos + half_extents;
+ Vector3 ofs = position + half_extents;
for (int i = 0; i < p_plane_count; i++) {
const Plane &p = p_planes[i];
@@ -210,14 +210,14 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co
//cache all points to check against!
// #warning should be easy to optimize, just use the same as when taking the support and use only that point
Vector3 points[8] = {
- Vector3(pos.x, pos.y, pos.z),
- Vector3(pos.x, pos.y, pos.z + size.z),
- Vector3(pos.x, pos.y + size.y, pos.z),
- Vector3(pos.x, pos.y + size.y, pos.z + size.z),
- Vector3(pos.x + size.x, pos.y, pos.z),
- Vector3(pos.x + size.x, pos.y, pos.z + size.z),
- Vector3(pos.x + size.x, pos.y + size.y, pos.z),
- Vector3(pos.x + size.x, pos.y + size.y, pos.z + size.z),
+ Vector3(position.x, position.y, position.z),
+ Vector3(position.x, position.y, position.z + size.z),
+ Vector3(position.x, position.y + size.y, position.z),
+ Vector3(position.x, position.y + size.y, position.z + size.z),
+ Vector3(position.x + size.x, position.y, position.z),
+ Vector3(position.x + size.x, position.y, position.z + size.z),
+ Vector3(position.x + size.x, position.y + size.y, position.z),
+ Vector3(position.x + size.x, position.y + size.y, position.z + size.z),
};
for (int i = 0; i < p_plane_count; i++) { //for each plane
@@ -246,17 +246,17 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co
bool Rect3::has_point(const Vector3 &p_point) const {
- if (p_point.x < pos.x)
+ if (p_point.x < position.x)
return false;
- if (p_point.y < pos.y)
+ if (p_point.y < position.y)
return false;
- if (p_point.z < pos.z)
+ if (p_point.z < position.z)
return false;
- if (p_point.x > pos.x + size.x)
+ if (p_point.x > position.x + size.x)
return false;
- if (p_point.y > pos.y + size.y)
+ if (p_point.y > position.y + size.y)
return false;
- if (p_point.z > pos.z + size.z)
+ if (p_point.z > position.z + size.z)
return false;
return true;
@@ -264,8 +264,8 @@ bool Rect3::has_point(const Vector3 &p_point) const {
inline void Rect3::expand_to(const Vector3 &p_vector) {
- Vector3 begin = pos;
- Vector3 end = pos + size;
+ Vector3 begin = position;
+ Vector3 end = position + size;
if (p_vector.x < begin.x)
begin.x = p_vector.x;
@@ -281,14 +281,14 @@ inline void Rect3::expand_to(const Vector3 &p_vector) {
if (p_vector.z > end.z)
end.z = p_vector.z;
- pos = begin;
+ position = begin;
size = end - begin;
}
void Rect3::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const {
Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5);
- Vector3 center(pos.x + half_extents.x, pos.y + half_extents.y, pos.z + half_extents.z);
+ Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z);
real_t length = p_plane.normal.abs().dot(half_extents);
real_t distance = p_plane.distance_to(center);
@@ -332,21 +332,21 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t
real_t divy = 1.0 / dir.y;
real_t divz = 1.0 / dir.z;
- Vector3 upbound = pos + size;
+ Vector3 upbound = position + size;
real_t tmin, tmax, tymin, tymax, tzmin, tzmax;
if (dir.x >= 0) {
- tmin = (pos.x - from.x) * divx;
+ tmin = (position.x - from.x) * divx;
tmax = (upbound.x - from.x) * divx;
} else {
tmin = (upbound.x - from.x) * divx;
- tmax = (pos.x - from.x) * divx;
+ tmax = (position.x - from.x) * divx;
}
if (dir.y >= 0) {
- tymin = (pos.y - from.y) * divy;
+ tymin = (position.y - from.y) * divy;
tymax = (upbound.y - from.y) * divy;
} else {
tymin = (upbound.y - from.y) * divy;
- tymax = (pos.y - from.y) * divy;
+ tymax = (position.y - from.y) * divy;
}
if ((tmin > tymax) || (tymin > tmax))
return false;
@@ -355,11 +355,11 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t
if (tymax < tmax)
tmax = tymax;
if (dir.z >= 0) {
- tzmin = (pos.z - from.z) * divz;
+ tzmin = (position.z - from.z) * divz;
tzmax = (upbound.z - from.z) * divz;
} else {
tzmin = (upbound.z - from.z) * divz;
- tzmax = (pos.z - from.z) * divz;
+ tzmax = (position.z - from.z) * divz;
}
if ((tmin > tzmax) || (tzmin > tmax))
return false;
@@ -372,9 +372,9 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t
void Rect3::grow_by(real_t p_amount) {
- pos.x -= p_amount;
- pos.y -= p_amount;
- pos.z -= p_amount;
+ position.x -= p_amount;
+ position.y -= p_amount;
+ position.z -= p_amount;
size.x += 2.0 * p_amount;
size.y += 2.0 * p_amount;
size.z += 2.0 * p_amount;
diff --git a/core/math/transform.h b/core/math/transform.h
index 4731496bf3..c39ea7826f 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -167,10 +167,10 @@ _FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const {
Vector3 x = basis.get_axis(0) * p_aabb.size.x;
Vector3 y = basis.get_axis(1) * p_aabb.size.y;
Vector3 z = basis.get_axis(2) * p_aabb.size.z;
- Vector3 pos = xform(p_aabb.pos);
+ Vector3 pos = xform(p_aabb.position);
//could be even further optimized
Rect3 new_aabb;
- new_aabb.pos = pos;
+ new_aabb.position = pos;
new_aabb.expand_to(pos + x);
new_aabb.expand_to(pos + y);
new_aabb.expand_to(pos + z);
@@ -182,14 +182,14 @@ _FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const {
#else
Vector3 vertices[8] = {
- Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z),
- Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z),
- Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z),
- Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z),
- Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z),
- Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z),
- Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z),
- Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z)
+ Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
+ Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
+ Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
+ Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z),
+ Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
+ Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
+ Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
+ Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z)
};
AABB ret;
@@ -208,19 +208,19 @@ _FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3 &p_aabb) const {
/* define vertices */
Vector3 vertices[8] = {
- Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z),
- Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z),
- Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z),
- Vector3(p_aabb.pos.x + p_aabb.size.x, p_aabb.pos.y, p_aabb.pos.z),
- Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z + p_aabb.size.z),
- Vector3(p_aabb.pos.x, p_aabb.pos.y + p_aabb.size.y, p_aabb.pos.z),
- Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z + p_aabb.size.z),
- Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z)
+ Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
+ Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
+ Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
+ Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z),
+ Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
+ Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
+ Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
+ Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z)
};
Rect3 ret;
- ret.pos = xform_inv(vertices[0]);
+ ret.position = xform_inv(vertices[0]);
for (int i = 1; i < 8; i++) {
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index 1cf1351646..08ac08d776 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -79,7 +79,7 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in
int index = max_alloc++;
BVH *_new = &p_bvh[index];
_new->aabb = aabb;
- _new->center = aabb.pos + aabb.size * 0.5;
+ _new->center = aabb.position + aabb.size * 0.5;
_new->face_index = -1;
_new->left = left;
_new->right = right;
@@ -128,7 +128,7 @@ void TriangleMesh::create(const PoolVector<Vector3> &p_faces) {
f.indices[j] = vidx;
if (j == 0)
- bw[i].aabb.pos = vs;
+ bw[i].aabb.position = vs;
else
bw[i].aabb.expand_to(vs);
}
@@ -138,7 +138,7 @@ void TriangleMesh::create(const PoolVector<Vector3> &p_faces) {
bw[i].left = -1;
bw[i].right = -1;
bw[i].face_index = i;
- bw[i].center = bw[i].aabb.pos + bw[i].aabb.size * 0.5;
+ bw[i].center = bw[i].aabb.position + bw[i].aabb.size * 0.5;
}
vertices.resize(db.size());
diff --git a/core/method_bind.h b/core/method_bind.h
index 5b8a458736..8d72c8573a 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -154,7 +154,6 @@ VARIANT_ENUM_CAST(Orientation);
VARIANT_ENUM_CAST(HAlign);
VARIANT_ENUM_CAST(Variant::Type);
VARIANT_ENUM_CAST(Variant::Operator);
-VARIANT_ENUM_CAST(InputEvent::Type);
class MethodBind {
diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h
index d3f6143638..c6dbfc2a7a 100644
--- a/core/method_ptrcall.h
+++ b/core/method_ptrcall.h
@@ -105,7 +105,6 @@ MAKE_PTRARG(Transform);
MAKE_PTRARG(Color);
MAKE_PTRARG(NodePath);
MAKE_PTRARG(RID);
-MAKE_PTRARG(InputEvent);
MAKE_PTRARG(Dictionary);
MAKE_PTRARG(Array);
MAKE_PTRARG(PoolByteArray);
@@ -116,7 +115,6 @@ MAKE_PTRARG(PoolVector2Array);
MAKE_PTRARG(PoolVector3Array);
MAKE_PTRARG(PoolColorArray);
MAKE_PTRARG(Variant);
-MAKE_PTRARG(PowerState);
//this is for Object
diff --git a/core/object.cpp b/core/object.cpp
index 7aee936a2d..f20e93f9d7 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1831,10 +1831,10 @@ void postinitialize_handler(Object *p_object) {
p_object->_postinitialize();
}
-HashMap<uint32_t, Object *> ObjectDB::instances;
-uint32_t ObjectDB::instance_counter = 1;
+HashMap<ObjectID, Object *> ObjectDB::instances;
+ObjectID ObjectDB::instance_counter = 1;
HashMap<Object *, ObjectID, ObjectDB::ObjectPtrHash> ObjectDB::instance_checks;
-uint32_t ObjectDB::add_instance(Object *p_object) {
+ObjectID ObjectDB::add_instance(Object *p_object) {
ERR_FAIL_COND_V(p_object->get_instance_ID() != 0, 0);
@@ -1859,7 +1859,7 @@ void ObjectDB::remove_instance(Object *p_object) {
rw_lock->write_unlock();
}
-Object *ObjectDB::get_instance(uint32_t p_instance_ID) {
+Object *ObjectDB::get_instance(ObjectID p_instance_ID) {
rw_lock->read_lock();
Object **obj = instances.getptr(p_instance_ID);
@@ -1874,7 +1874,7 @@ void ObjectDB::debug_objects(DebugFunc p_func) {
rw_lock->read_lock();
- const uint32_t *K = NULL;
+ const ObjectID *K = NULL;
while ((K = instances.next(K))) {
p_func(instances[*K]);
@@ -1909,7 +1909,7 @@ void ObjectDB::cleanup() {
WARN_PRINT("ObjectDB Instances still exist!");
if (OS::get_singleton()->is_stdout_verbose()) {
- const uint32_t *K = NULL;
+ const ObjectID *K = NULL;
while ((K = instances.next(K))) {
String node_name;
diff --git a/core/object.h b/core/object.h
index 3b39224af0..83b03b9239 100644
--- a/core/object.h
+++ b/core/object.h
@@ -350,7 +350,7 @@ public: \
private:
class ScriptInstance;
-typedef uint32_t ObjectID;
+typedef uint64_t ObjectID;
class Object {
public:
@@ -423,7 +423,7 @@ private:
bool _block_signals;
int _predelete_ok;
Set<Object *> change_receptors;
- uint32_t _instance_ID;
+ ObjectID _instance_ID;
bool _predelete();
void _postinitialize();
bool _can_translate;
@@ -690,16 +690,16 @@ class ObjectDB {
}
};
- static HashMap<uint32_t, Object *> instances;
+ static HashMap<ObjectID, Object *> instances;
static HashMap<Object *, ObjectID, ObjectPtrHash> instance_checks;
- static uint32_t instance_counter;
+ static ObjectID instance_counter;
friend class Object;
friend void unregister_core_types();
static RWLock *rw_lock;
static void cleanup();
- static uint32_t add_instance(Object *p_object);
+ static ObjectID add_instance(Object *p_object);
static void remove_instance(Object *p_object);
friend void register_core_types();
static void setup();
@@ -707,7 +707,7 @@ class ObjectDB {
public:
typedef void (*DebugFunc)(Object *p_obj);
- static Object *get_instance(uint32_t p_instance_ID);
+ static Object *get_instance(ObjectID p_instance_ID);
static void debug_objects(DebugFunc p_func);
static int get_object_count();
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 375121c0cc..805b66b983 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -252,6 +252,27 @@ double FileAccess::get_double() const {
return m.d;
};
+String FileAccess::get_token() const {
+
+ CharString token;
+
+ CharType c = get_8();
+
+ while (!eof_reached()) {
+
+ if (c <= ' ') {
+ if (!token.empty())
+ break;
+ } else {
+ token.push_back(c);
+ }
+ c = get_8();
+ }
+
+ token.push_back(0);
+ return String::utf8(token.get_data());
+}
+
String FileAccess::get_line() const {
CharString line;
diff --git a/core/os/file_access.h b/core/os/file_access.h
index da15ddc544..6d3e491167 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -106,6 +106,7 @@ public:
virtual int get_buffer(uint8_t *p_dst, int p_length) const; ///< get an array of bytes
virtual String get_line() const;
+ virtual String get_token() const;
virtual Vector<String> get_csv_line(String delim = ",") const;
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
diff --git a/core/os/input.h b/core/os/input.h
index 4f26f097c2..6759c624e3 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -82,7 +82,7 @@ public:
virtual int get_mouse_button_mask() const = 0;
virtual void warp_mouse_pos(const Vector2 &p_to) = 0;
- virtual Point2i warp_mouse_motion(const InputEventMouseMotion &p_motion, const Rect2 &p_rect) = 0;
+ virtual Point2i warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) = 0;
virtual Vector3 get_gravity() const = 0;
virtual Vector3 get_accelerometer() const = 0;
@@ -104,7 +104,7 @@ public:
virtual int get_joy_button_index_from_string(String p_button) = 0;
virtual int get_joy_axis_index_from_string(String p_axis) = 0;
- virtual void parse_input_event(const InputEvent &p_event) = 0;
+ virtual void parse_input_event(const Ref<InputEvent> &p_event) = 0;
Input();
};
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 474bc33b41..dbdf9628e3 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -34,275 +34,797 @@
*
*/
-bool InputEvent::operator==(const InputEvent &p_event) const {
- if (type != p_event.type) {
- return false;
- }
+void InputEvent::set_id(uint32_t p_id) {
+ id = p_id;
+}
- switch (type) {
- /** Current clang-format style doesn't play well with the aligned return values of that switch. */
- /* clang-format off */
- case NONE:
- return true;
- case KEY:
- return key.unicode == p_event.key.unicode
- && key.scancode == p_event.key.scancode
- && key.echo == p_event.key.echo
- && key.pressed == p_event.key.pressed
- && key.mod == p_event.key.mod;
- case MOUSE_MOTION:
- return mouse_motion.x == p_event.mouse_motion.x
- && mouse_motion.y == p_event.mouse_motion.y
- && mouse_motion.relative_x == p_event.mouse_motion.relative_x
- && mouse_motion.relative_y == p_event.mouse_motion.relative_y
- && mouse_motion.button_mask == p_event.mouse_motion.button_mask
- && key.mod == p_event.key.mod;
- case MOUSE_BUTTON:
- return mouse_button.pressed == p_event.mouse_button.pressed
- && mouse_button.x == p_event.mouse_button.x
- && mouse_button.y == p_event.mouse_button.y
- && mouse_button.button_index == p_event.mouse_button.button_index
- && mouse_button.button_mask == p_event.mouse_button.button_mask
- && key.mod == p_event.key.mod;
- case JOYPAD_MOTION:
- return joy_motion.axis == p_event.joy_motion.axis
- && joy_motion.axis_value == p_event.joy_motion.axis_value;
- case JOYPAD_BUTTON:
- return joy_button.pressed == p_event.joy_button.pressed
- && joy_button.button_index == p_event.joy_button.button_index
- && joy_button.pressure == p_event.joy_button.pressure;
- case SCREEN_TOUCH:
- return screen_touch.pressed == p_event.screen_touch.pressed
- && screen_touch.index == p_event.screen_touch.index
- && screen_touch.x == p_event.screen_touch.x
- && screen_touch.y == p_event.screen_touch.y;
- case SCREEN_DRAG:
- return screen_drag.index == p_event.screen_drag.index
- && screen_drag.x == p_event.screen_drag.x
- && screen_drag.y == p_event.screen_drag.y;
- case ACTION:
- return action.action == p_event.action.action
- && action.pressed == p_event.action.pressed;
- /* clang-format on */
- default:
- ERR_PRINT("No logic to compare InputEvents of this type, this shouldn't happen.");
- }
+uint32_t InputEvent::get_id() const {
+ return id;
+}
+
+void InputEvent::set_device(int p_device) {
+ device = p_device;
+}
+
+int InputEvent::get_device() const {
+ return device;
+}
+
+bool InputEvent::is_pressed() const {
return false;
}
-InputEvent::operator String() const {
-
- String str = "Device " + itos(device) + " ID " + itos(ID) + " ";
-
- switch (type) {
-
- case NONE: {
-
- return "Event: None";
- } break;
- case KEY: {
-
- str += "Event: Key ";
- str = str + "Unicode: " + String::chr(key.unicode) + " Scan: " + itos(key.scancode) + " Echo: " + String(key.echo ? "True" : "False") + " Pressed" + String(key.pressed ? "True" : "False") + " Mod: ";
- if (key.mod.shift)
- str += "S";
- if (key.mod.control)
- str += "C";
- if (key.mod.alt)
- str += "A";
- if (key.mod.meta)
- str += "M";
-
- return str;
- } break;
- case MOUSE_MOTION: {
-
- str += "Event: Motion ";
- str = str + " Pos: " + itos(mouse_motion.x) + "," + itos(mouse_motion.y) + " Rel: " + itos(mouse_motion.relative_x) + "," + itos(mouse_motion.relative_y) + " Mask: ";
- for (int i = 0; i < 8; i++) {
-
- if ((1 << i) & mouse_motion.button_mask)
- str += itos(i + 1);
- }
- str += " Mod: ";
- if (key.mod.shift)
- str += "S";
- if (key.mod.control)
- str += "C";
- if (key.mod.alt)
- str += "A";
- if (key.mod.meta)
- str += "M";
-
- return str;
- } break;
- case MOUSE_BUTTON: {
- str += "Event: Button ";
- str = str + "Pressed: " + itos(mouse_button.pressed) + " Pos: " + itos(mouse_button.x) + "," + itos(mouse_button.y) + " Button: " + itos(mouse_button.button_index) + " Mask: ";
- for (int i = 0; i < 8; i++) {
-
- if ((1 << i) & mouse_button.button_mask)
- str += itos(i + 1);
- }
- str += " Mod: ";
- if (key.mod.shift)
- str += "S";
- if (key.mod.control)
- str += "C";
- if (key.mod.alt)
- str += "A";
- if (key.mod.meta)
- str += "M";
-
- str += String(" DoubleClick: ") + (mouse_button.doubleclick ? "Yes" : "No");
-
- return str;
-
- } break;
- case JOYPAD_MOTION: {
- str += "Event: JoypadMotion ";
- str = str + "Axis: " + itos(joy_motion.axis) + " Value: " + rtos(joy_motion.axis_value);
- return str;
-
- } break;
- case JOYPAD_BUTTON: {
- str += "Event: JoypadButton ";
- str = str + "Pressed: " + itos(joy_button.pressed) + " Index: " + itos(joy_button.button_index) + " pressure " + rtos(joy_button.pressure);
- return str;
-
- } break;
- case SCREEN_TOUCH: {
- str += "Event: ScreenTouch ";
- str = str + "Pressed: " + itos(screen_touch.pressed) + " Index: " + itos(screen_touch.index) + " pos " + rtos(screen_touch.x) + "," + rtos(screen_touch.y);
- return str;
-
- } break;
- case SCREEN_DRAG: {
- str += "Event: ScreenDrag ";
- str = str + " Index: " + itos(screen_drag.index) + " pos " + rtos(screen_drag.x) + "," + rtos(screen_drag.y);
- return str;
-
- } break;
- case ACTION: {
- str += "Event: Action: " + InputMap::get_singleton()->get_action_from_id(action.action) + " Pressed: " + itos(action.pressed);
- return str;
-
- } break;
- }
- return "";
+bool InputEvent::is_action(const StringName &p_action) const {
+
+ return InputMap::get_singleton()->event_is_action(Ref<InputEvent>((InputEvent *)this), p_action);
}
-void InputEvent::set_as_action(const String &p_action, bool p_pressed) {
+bool InputEvent::is_action_pressed(const StringName &p_action) const {
- type = ACTION;
- action.action = InputMap::get_singleton()->get_action_id(p_action);
- action.pressed = p_pressed;
+ return (is_pressed() && !is_echo() && is_action(p_action));
}
+bool InputEvent::is_action_released(const StringName &p_action) const {
-bool InputEvent::is_pressed() const {
+ return (!is_pressed() && is_action(p_action));
+}
- switch (type) {
+bool InputEvent::is_echo() const {
- case KEY: return key.pressed;
- case MOUSE_BUTTON: return mouse_button.pressed;
- case JOYPAD_BUTTON: return joy_button.pressed;
- case SCREEN_TOUCH: return screen_touch.pressed;
- case JOYPAD_MOTION: return ABS(joy_motion.axis_value) > 0.5;
- case ACTION: return action.pressed;
- default: {}
- }
+ return false;
+}
+
+Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ return Ref<InputEvent>((InputEvent *)this);
+}
+
+String InputEvent::as_text() const {
+
+ return String();
+}
+
+bool InputEvent::action_match(const Ref<InputEvent> &p_event) const {
return false;
}
-bool InputEvent::is_echo() const {
+bool InputEvent::is_action_type() const {
+
+ return false;
+}
+
+#if 0
+if (String(p_method) == "is_action" && p_argidx == 0) {
+
+ List<PropertyInfo> pinfo;
+ GlobalConfig::get_singleton()->get_property_list(&pinfo);
+
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ const PropertyInfo &pi = E->get();
+
+ if (!pi.name.begins_with("input/"))
+ continue;
+
+ String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
+ result.insert("\"" + name + "\"");
+ }
+
+} else
+#endif
+
+void InputEvent::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_id", "id"), &InputEvent::set_id);
+ ClassDB::bind_method(D_METHOD("get_id"), &InputEvent::get_id);
+
+ ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device);
+ ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
+
+ ClassDB::bind_method(D_METHOD("is_pressed"), &InputEvent::is_pressed);
+ ClassDB::bind_method(D_METHOD("is_action", "action"), &InputEvent::is_action);
+ ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &InputEvent::is_action_pressed);
+ ClassDB::bind_method(D_METHOD("is_action_released", "action"), &InputEvent::is_action_released);
+ ClassDB::bind_method(D_METHOD("is_echo"), &InputEvent::is_echo);
+
+ ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text);
+
+ ClassDB::bind_method(D_METHOD("action_match", "event:InputEvent"), &InputEvent::action_match);
+
+ ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type);
+
+ ClassDB::bind_method(D_METHOD("xformed_by:InputEvent", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2()));
+}
+
+InputEvent::InputEvent() {
+
+ id = 0;
+ device = 0;
+}
+
+//////////////////
+
+void InputEventWithModifiers::set_shift(bool p_enabled) {
+
+ shift = p_enabled;
+}
+
+bool InputEventWithModifiers::get_shift() const {
+
+ return shift;
+}
+
+void InputEventWithModifiers::set_alt(bool p_enabled) {
+
+ alt = p_enabled;
+}
+bool InputEventWithModifiers::get_alt() const {
+
+ return alt;
+}
+
+void InputEventWithModifiers::set_control(bool p_enabled) {
+
+ control = p_enabled;
+}
+bool InputEventWithModifiers::get_control() const {
+
+ return control;
+}
+
+void InputEventWithModifiers::set_metakey(bool p_enabled) {
+
+ meta = p_enabled;
+}
+bool InputEventWithModifiers::get_metakey() const {
+
+ return meta;
+}
+
+void InputEventWithModifiers::set_command(bool p_enabled) {
+
+ command = p_enabled;
+}
+bool InputEventWithModifiers::get_command() const {
+
+ return command;
+}
+
+void InputEventWithModifiers::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
+ ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
+
+ ClassDB::bind_method(D_METHOD("set_shift", "enable"), &InputEventWithModifiers::set_shift);
+ ClassDB::bind_method(D_METHOD("get_shift"), &InputEventWithModifiers::get_shift);
+
+ ClassDB::bind_method(D_METHOD("set_control", "enable"), &InputEventWithModifiers::set_control);
+ ClassDB::bind_method(D_METHOD("get_control"), &InputEventWithModifiers::get_control);
+
+ ClassDB::bind_method(D_METHOD("set_metakey", "enable"), &InputEventWithModifiers::set_metakey);
+ ClassDB::bind_method(D_METHOD("get_metakey"), &InputEventWithModifiers::get_metakey);
+
+ ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command);
+ ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command);
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta"), "set_metakey", "get_metakey");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
+}
+
+InputEventWithModifiers::InputEventWithModifiers() {
+
+ alt = false;
+ shift = false;
+ control = false;
+ meta = false;
+}
+
+//////////////////////////////////
+
+void InputEventKey::set_pressed(bool p_pressed) {
- return (type == KEY && key.echo);
+ pressed = p_pressed;
}
-bool InputEvent::is_action(const String &p_action) const {
+bool InputEventKey::is_pressed() const {
- return InputMap::get_singleton()->event_is_action(*this, p_action);
+ return pressed;
}
-bool InputEvent::is_action_pressed(const String &p_action) const {
+void InputEventKey::set_scancode(uint32_t p_scancode) {
- return is_action(p_action) && is_pressed() && !is_echo();
+ scancode = p_scancode;
}
+uint32_t InputEventKey::get_scancode() const {
-bool InputEvent::is_action_released(const String &p_action) const {
+ return scancode;
+}
+
+void InputEventKey::set_unicode(uint32_t p_unicode) {
+
+ unicode = p_unicode;
+}
+uint32_t InputEventKey::get_unicode() const {
+
+ return unicode;
+}
- return is_action(p_action) && !is_pressed();
+void InputEventKey::set_echo(bool p_enable) {
+
+ echo = p_enable;
+}
+bool InputEventKey::is_echo() const {
+
+ return echo;
}
uint32_t InputEventKey::get_scancode_with_modifiers() const {
uint32_t sc = scancode;
- if (mod.control)
+ if (get_control())
sc |= KEY_MASK_CTRL;
- if (mod.alt)
+ if (get_alt())
sc |= KEY_MASK_ALT;
- if (mod.shift)
+ if (get_shift())
sc |= KEY_MASK_SHIFT;
- if (mod.meta)
+ if (get_metakey())
sc |= KEY_MASK_META;
return sc;
}
-InputEvent InputEvent::xform_by(const Transform2D &p_xform) const {
-
- InputEvent ev = *this;
-
- switch (ev.type) {
-
- case InputEvent::MOUSE_BUTTON: {
-
- Vector2 g = p_xform.xform(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y));
- Vector2 l = p_xform.xform(Vector2(ev.mouse_button.x, ev.mouse_button.y));
- ev.mouse_button.x = l.x;
- ev.mouse_button.y = l.y;
- ev.mouse_button.global_x = g.x;
- ev.mouse_button.global_y = g.y;
-
- } break;
- case InputEvent::MOUSE_MOTION: {
-
- Vector2 g = p_xform.xform(Vector2(ev.mouse_motion.global_x, ev.mouse_motion.global_y));
- Vector2 l = p_xform.xform(Vector2(ev.mouse_motion.x, ev.mouse_motion.y));
- Vector2 r = p_xform.basis_xform(Vector2(ev.mouse_motion.relative_x, ev.mouse_motion.relative_y));
- Vector2 s = p_xform.basis_xform(Vector2(ev.mouse_motion.speed_x, ev.mouse_motion.speed_y));
- ev.mouse_motion.x = l.x;
- ev.mouse_motion.y = l.y;
- ev.mouse_motion.global_x = g.x;
- ev.mouse_motion.global_y = g.y;
- ev.mouse_motion.relative_x = r.x;
- ev.mouse_motion.relative_y = r.y;
- ev.mouse_motion.speed_x = s.x;
- ev.mouse_motion.speed_y = s.y;
-
- } break;
- case InputEvent::SCREEN_TOUCH: {
-
- Vector2 t = p_xform.xform(Vector2(ev.screen_touch.x, ev.screen_touch.y));
- ev.screen_touch.x = t.x;
- ev.screen_touch.y = t.y;
-
- } break;
- case InputEvent::SCREEN_DRAG: {
-
- Vector2 t = p_xform.xform(Vector2(ev.screen_drag.x, ev.screen_drag.y));
- Vector2 r = p_xform.basis_xform(Vector2(ev.screen_drag.relative_x, ev.screen_drag.relative_y));
- Vector2 s = p_xform.basis_xform(Vector2(ev.screen_drag.speed_x, ev.screen_drag.speed_y));
- ev.screen_drag.x = t.x;
- ev.screen_drag.y = t.y;
- ev.screen_drag.relative_x = r.x;
- ev.screen_drag.relative_y = r.y;
- ev.screen_drag.speed_x = s.x;
- ev.screen_drag.speed_y = s.y;
- } break;
- }
+bool InputEventKey::action_match(const Ref<InputEvent> &p_event) const {
+
+ Ref<InputEventKey> key = p_event;
+ if (key.is_null())
+ return false;
+
+ uint32_t code = get_scancode_with_modifiers();
+ uint32_t event_code = key->get_scancode_with_modifiers();
+
+ return get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code);
+}
+
+void InputEventKey::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
+
+ ClassDB::bind_method(D_METHOD("set_scancode", "scancode"), &InputEventKey::set_scancode);
+ ClassDB::bind_method(D_METHOD("get_scancode"), &InputEventKey::get_scancode);
+
+ ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
+ ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
+
+ ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo);
+
+ ClassDB::bind_method(D_METHOD("get_scancode_with_modifiers"), &InputEventKey::get_scancode_with_modifiers);
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "scancode"), "set_scancode", "get_scancode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "echo"), "set_echo", "is_echo");
+}
+
+InputEventKey::InputEventKey() {
+
+ pressed = false;
+ scancode = 0;
+ unicode = 0; ///unicode
+ echo = false;
+}
+
+////////////////////////////////////////
+
+void InputEventMouse::set_button_mask(int p_mask) {
+
+ button_mask = p_mask;
+}
+int InputEventMouse::get_button_mask() const {
+
+ return button_mask;
+}
+
+void InputEventMouse::set_position(const Vector2 &p_pos) {
+
+ pos = p_pos;
+}
+Vector2 InputEventMouse::get_position() const {
+
+ return pos;
+}
+
+void InputEventMouse::set_global_position(const Vector2 &p_global_pos) {
+
+ global_pos = p_global_pos;
+}
+Vector2 InputEventMouse::get_global_position() const {
+
+ return global_pos;
+}
+
+void InputEventMouse::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask);
+ ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask);
+
+ ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventMouse::set_position);
+ ClassDB::bind_method(D_METHOD("get_position"), &InputEventMouse::get_position);
+
+ ClassDB::bind_method(D_METHOD("set_global_position", "global_position"), &InputEventMouse::set_global_position);
+ ClassDB::bind_method(D_METHOD("get_global_position"), &InputEventMouse::get_global_position);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask"), "set_button_mask", "get_button_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position"), "set_global_position", "get_global_position");
+}
+
+InputEventMouse::InputEventMouse() {
+
+ button_mask = 0;
+}
+
+///////////////////////////////////////
+
+void InputEventMouseButton::set_factor(float p_factor) {
+
+ factor = p_factor;
+}
+
+float InputEventMouseButton::get_factor() {
+
+ return factor;
+}
+
+void InputEventMouseButton::set_button_index(int p_index) {
+
+ button_index = p_index;
+}
+int InputEventMouseButton::get_button_index() const {
+
+ return button_index;
+}
+
+void InputEventMouseButton::set_pressed(bool p_pressed) {
+
+ pressed = p_pressed;
+}
+bool InputEventMouseButton::is_pressed() const {
+
+ return pressed;
+}
+
+void InputEventMouseButton::set_doubleclick(bool p_doubleclick) {
+
+ doubleclick = p_doubleclick;
+}
+bool InputEventMouseButton::is_doubleclick() const {
+
+ return doubleclick;
+}
+
+Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ Vector2 g = p_xform.xform(get_global_position());
+ Vector2 l = p_xform.xform(get_position() + p_local_ofs);
+
+ Ref<InputEventMouseButton> mb;
+ mb.instance();
+
+ mb->set_id(get_id());
+ mb->set_device(get_device());
+
+ mb->set_alt(get_alt());
+ mb->set_shift(get_shift());
+ mb->set_control(get_control());
+ mb->set_metakey(get_metakey());
+
+ mb->set_position(l);
+ mb->set_global_position(g);
+
+ mb->set_button_mask(get_button_mask());
+ mb->set_pressed(pressed);
+ mb->set_doubleclick(doubleclick);
+ mb->set_factor(factor);
+ mb->set_button_index(button_index);
+
+ return mb;
+}
+
+bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event) const {
+
+ Ref<InputEventMouseButton> mb = p_event;
+ if (mb.is_null())
+ return false;
+
+ return mb->button_index == button_index;
+}
+
+void InputEventMouseButton::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
+ ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor);
+
+ ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventMouseButton::set_button_index);
+ ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventMouseButton::get_button_index);
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventMouseButton::set_pressed);
+ // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventMouseButton::is_pressed);
+
+ ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick);
+ ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick);
+
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick");
+}
+
+InputEventMouseButton::InputEventMouseButton() {
+
+ factor = 1;
+ button_index = 0;
+ pressed = false;
+ doubleclick = false;
+}
+
+////////////////////////////////////////////
+
+void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
+
+ relative = p_relative;
+}
+Vector2 InputEventMouseMotion::get_relative() const {
+
+ return relative;
+}
+
+void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
+
+ speed = p_speed;
+}
+Vector2 InputEventMouseMotion::get_speed() const {
+
+ return speed;
+}
+
+Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ Vector2 g = p_xform.xform(get_global_position());
+ Vector2 l = p_xform.xform(get_position() + p_local_ofs);
+ Vector2 r = p_xform.basis_xform(get_relative());
+ Vector2 s = p_xform.basis_xform(get_speed());
+
+ Ref<InputEventMouseMotion> mm;
+ mm.instance();
+
+ mm->set_id(get_id());
+ mm->set_device(get_device());
+
+ mm->set_alt(get_alt());
+ mm->set_shift(get_shift());
+ mm->set_control(get_control());
+ mm->set_metakey(get_metakey());
+
+ mm->set_position(l);
+ mm->set_global_position(g);
+
+ mm->set_button_mask(get_button_mask());
+ mm->set_relative(r);
+ mm->set_speed(s);
+
+ return mm;
+}
+
+void InputEventMouseMotion::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
+ ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
+
+ ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
+ ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
+}
+
+InputEventMouseMotion::InputEventMouseMotion() {
+}
+
+////////////////////////////////////////
+
+void InputEventJoypadMotion::set_axis(int p_axis) {
+
+ axis = p_axis;
+}
+
+int InputEventJoypadMotion::get_axis() const {
+
+ return axis;
+}
+
+void InputEventJoypadMotion::set_axis_value(float p_value) {
+
+ axis_value = p_value;
+}
+float InputEventJoypadMotion::get_axis_value() const {
+
+ return axis_value;
+}
+
+bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event) const {
+
+ Ref<InputEventJoypadMotion> jm = p_event;
+ if (jm.is_null())
+ return false;
+
+ return (axis == jm->axis && (axis_value < 0) == (jm->axis_value < 0));
+}
+
+void InputEventJoypadMotion::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
+ ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
+
+ ClassDB::bind_method(D_METHOD("set_axis_value", "axis_value"), &InputEventJoypadMotion::set_axis_value);
+ ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value");
+}
+
+InputEventJoypadMotion::InputEventJoypadMotion() {
+
+ axis = 0;
+ axis_value = 0;
+}
+/////////////////////////////////
+
+void InputEventJoypadButton::set_button_index(int p_index) {
+
+ button_index = p_index;
+}
+
+int InputEventJoypadButton::get_button_index() const {
+
+ return button_index;
+}
+
+void InputEventJoypadButton::set_pressed(bool p_pressed) {
+
+ pressed = p_pressed;
+}
+bool InputEventJoypadButton::is_pressed() const {
+
+ return pressed;
+}
+
+void InputEventJoypadButton::set_pressure(float p_pressure) {
+
+ pressure = p_pressure;
+}
+float InputEventJoypadButton::get_pressure() const {
+
+ return pressure;
+}
+
+bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event) const {
+
+ Ref<InputEventJoypadButton> jb = p_event;
+ if (jb.is_null())
+ return false;
+
+ return button_index == jb->button_index;
+}
+
+void InputEventJoypadButton::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
+ ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
+
+ ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventJoypadButton::set_pressure);
+ ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventJoypadButton::get_pressure);
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventJoypadButton::set_pressed);
+ // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventJoypadButton::is_pressed);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+}
+
+InputEventJoypadButton::InputEventJoypadButton() {
+
+ button_index = 0;
+ pressure = 0;
+ pressed = false;
+}
+
+//////////////////////////////////////////////
+
+void InputEventScreenTouch::set_index(int p_index) {
+
+ index = p_index;
+}
+int InputEventScreenTouch::get_index() const {
+
+ return index;
+}
+
+void InputEventScreenTouch::set_position(const Vector2 &p_pos) {
+
+ pos = p_pos;
+}
+Vector2 InputEventScreenTouch::get_position() const {
+
+ return pos;
+}
+
+void InputEventScreenTouch::set_pressed(bool p_pressed) {
+
+ pressed = p_pressed;
+}
+bool InputEventScreenTouch::is_pressed() const {
+
+ return pressed;
+}
+
+Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ Ref<InputEventScreenTouch> st;
+ st.instance();
+ st->set_id(get_id());
+ st->set_device(get_device());
+ st->set_index(index);
+ st->set_position(p_xform.xform(pos + p_local_ofs));
+ st->set_pressed(pressed);
+
+ return st;
+}
+
+void InputEventScreenTouch::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
+ ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
+
+ ClassDB::bind_method(D_METHOD("set_position", "pos"), &InputEventScreenTouch::set_position);
+ ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenTouch::get_position);
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
+ //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+}
+
+InputEventScreenTouch::InputEventScreenTouch() {
+
+ index = 0;
+ pressed = false;
+}
+
+/////////////////////////////
+
+void InputEventScreenDrag::set_index(int p_index) {
+
+ index = p_index;
+}
+
+int InputEventScreenDrag::get_index() const {
+
+ return index;
+}
+
+void InputEventScreenDrag::set_position(const Vector2 &p_pos) {
+
+ pos = p_pos;
+}
+Vector2 InputEventScreenDrag::get_position() const {
+
+ return pos;
+}
+
+void InputEventScreenDrag::set_relative(const Vector2 &p_relative) {
+
+ relative = p_relative;
+}
+Vector2 InputEventScreenDrag::get_relative() const {
+
+ return relative;
+}
+
+void InputEventScreenDrag::set_speed(const Vector2 &p_speed) {
+
+ speed = p_speed;
+}
+Vector2 InputEventScreenDrag::get_speed() const {
+
+ return speed;
+}
+
+Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ Ref<InputEventScreenDrag> sd;
+
+ sd.instance();
+
+ sd->set_id(get_id());
+ sd->set_device(get_device());
+
+ sd->set_index(index);
+ sd->set_position(p_xform.xform(pos + p_local_ofs));
+ sd->set_relative(p_xform.basis_xform(relative));
+ sd->set_speed(p_xform.basis_xform(speed));
+
+ return sd;
+}
+
+void InputEventScreenDrag::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
+ ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
+
+ ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenDrag::set_position);
+ ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenDrag::get_position);
+
+ ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative);
+ ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative);
+
+ ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventScreenDrag::set_speed);
+ ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
+}
+
+InputEventScreenDrag::InputEventScreenDrag() {
+
+ index = 0;
+}
+/////////////////////////////
+
+void InputEventAction::set_action(const StringName &p_action) {
+
+ action = p_action;
+}
+StringName InputEventAction::get_action() const {
+
+ return action;
+}
+
+void InputEventAction::set_pressed(bool p_pressed) {
+
+ pressed = p_pressed;
+}
+bool InputEventAction::is_pressed() const {
+
+ return pressed;
+}
+
+bool InputEventAction::is_action(const StringName &p_action) const {
+
+ return action == p_action;
+}
+
+void InputEventAction::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
+ ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
+ //ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
+
+ // ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
+
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+}
- return ev;
+InputEventAction::InputEventAction() {
+ pressed = false;
}
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 93cceac27c..6a694df345 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -32,6 +32,7 @@
#include "math_2d.h"
#include "os/copymem.h"
+#include "resource.h"
#include "typedefs.h"
#include "ustring.h"
/**
@@ -137,7 +138,40 @@ enum {
* Input Modifier Status
* for keyboard/mouse events.
*/
-struct InputModifierState {
+
+class InputEvent : public Resource {
+ GDCLASS(InputEvent, Resource)
+
+ uint32_t id;
+ int device;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_id(uint32_t p_id);
+ uint32_t get_id() const;
+
+ void set_device(int p_device);
+ int get_device() const;
+
+ virtual bool is_pressed() const;
+ virtual bool is_action(const StringName &p_action) const;
+ virtual bool is_action_pressed(const StringName &p_action) const;
+ virtual bool is_action_released(const StringName &p_action) const;
+ virtual bool is_echo() const;
+ virtual String as_text() const;
+
+ 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) const;
+ virtual bool is_action_type() const;
+
+ InputEvent();
+};
+
+class InputEventWithModifiers : public InputEvent {
+ GDCLASS(InputEventWithModifiers, InputEvent)
bool shift;
bool alt;
@@ -157,126 +191,267 @@ struct InputModifierState {
#endif
- bool operator==(const InputModifierState &rvalue) const {
+protected:
+ static void _bind_methods();
+
+public:
+ void set_shift(bool p_enabled);
+ bool get_shift() const;
+
+ void set_alt(bool p_enabled);
+ bool get_alt() const;
+
+ void set_control(bool p_enabled);
+ bool get_control() const;
+
+ void set_metakey(bool p_enabled);
+ bool get_metakey() const;
- return ((shift == rvalue.shift) && (alt == rvalue.alt) && (control == rvalue.control) && (meta == rvalue.meta));
- }
+ void set_command(bool p_enabled);
+ bool get_command() const;
+
+ InputEventWithModifiers();
};
-struct InputEventKey {
+class InputEventKey : public InputEventWithModifiers {
- InputModifierState mod;
+ GDCLASS(InputEventKey, InputEventWithModifiers)
bool pressed; /// otherwise release
uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks
uint32_t unicode; ///unicode
+ bool echo; /// true if this is an echo key
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ void set_scancode(uint32_t p_scancode);
+ uint32_t get_scancode() const;
+
+ void set_unicode(uint32_t p_unicode);
+ uint32_t get_unicode() const;
+
+ void set_echo(bool p_enable);
+ virtual bool is_echo() const;
+
uint32_t get_scancode_with_modifiers() const;
- bool echo; /// true if this is an echo key
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventKey();
};
-struct InputEventMouse {
+class InputEventMouse : public InputEventWithModifiers {
+
+ GDCLASS(InputEventMouse, InputEventWithModifiers)
- InputModifierState mod;
int button_mask;
- float x, y;
- float global_x, global_y;
- int pointer_index;
+
+ Vector2 pos;
+ Vector2 global_pos;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_button_mask(int p_mask);
+ int get_button_mask() const;
+
+ void set_position(const Vector2 &p_pos);
+ Vector2 get_position() const;
+
+ void set_global_position(const Vector2 &p_global_pos);
+ Vector2 get_global_position() const;
+
+ InputEventMouse();
};
-struct InputEventMouseButton : public InputEventMouse {
+class InputEventMouseButton : public InputEventMouse {
+
+ GDCLASS(InputEventMouseButton, InputEventMouse)
- double factor;
+ float factor;
int button_index;
bool pressed; //otherwise released
bool doubleclick; //last even less than doubleclick time
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_factor(float p_factor);
+ float get_factor();
+
+ void set_button_index(int p_index);
+ int get_button_index() const;
+
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ void set_doubleclick(bool p_doubleclick);
+ bool is_doubleclick() const;
+
+ 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) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventMouseButton();
};
-struct InputEventMouseMotion : public InputEventMouse {
+class InputEventMouseMotion : public InputEventMouse {
+
+ GDCLASS(InputEventMouseMotion, InputEventMouse)
+ Vector2 relative;
+ Vector2 speed;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_relative(const Vector2 &p_relative);
+ Vector2 get_relative() const;
+
+ void set_speed(const Vector2 &p_speed);
+ Vector2 get_speed() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- float relative_x, relative_y;
- float speed_x, speed_y;
+ InputEventMouseMotion();
};
-struct InputEventJoypadMotion {
+class InputEventJoypadMotion : public InputEvent {
+ GDCLASS(InputEventJoypadMotion, InputEvent)
int axis; ///< Joypad axis
float axis_value; ///< -1 to 1
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_axis(int p_axis);
+ int get_axis() const;
+
+ void set_axis_value(float p_value);
+ float get_axis_value() const;
+
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventJoypadMotion();
};
-struct InputEventJoypadButton {
+class InputEventJoypadButton : public InputEvent {
+ GDCLASS(InputEventJoypadButton, InputEvent)
int button_index;
bool pressed;
float pressure; //0 to 1
-};
+protected:
+ static void _bind_methods();
+
+public:
+ void set_button_index(int p_index);
+ int get_button_index() const;
+
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ void set_pressure(float p_pressure);
+ float get_pressure() const;
-struct InputEventScreenTouch {
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+ virtual bool is_action_type() const { return true; }
+
+ InputEventJoypadButton();
+};
+
+class InputEventScreenTouch : public InputEvent {
+ GDCLASS(InputEventScreenTouch, InputEvent)
int index;
- float x, y;
+ Vector2 pos;
bool pressed;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_index(int p_index);
+ int get_index() const;
+
+ void set_position(const Vector2 &p_pos);
+ Vector2 get_position() const;
+
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+
+ InputEventScreenTouch();
};
-struct InputEventScreenDrag {
+class InputEventScreenDrag : public InputEvent {
+
+ GDCLASS(InputEventScreenDrag, InputEvent)
int index;
- float x, y;
- float relative_x, relative_y;
- float speed_x, speed_y;
+ Vector2 pos;
+ Vector2 relative;
+ Vector2 speed;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_index(int p_index);
+ int get_index() const;
+
+ void set_position(const Vector2 &p_pos);
+ Vector2 get_position() const;
+
+ void set_relative(const Vector2 &p_relative);
+ Vector2 get_relative() const;
+
+ void set_speed(const Vector2 &p_speed);
+ Vector2 get_speed() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+
+ InputEventScreenDrag();
};
-struct InputEventAction {
+class InputEventAction : public InputEvent {
+
+ GDCLASS(InputEventAction, InputEvent)
- int action;
+ StringName action;
bool pressed;
-};
-struct InputEvent {
-
- enum Type {
- NONE,
- KEY,
- MOUSE_MOTION,
- MOUSE_BUTTON,
- JOYPAD_MOTION,
- JOYPAD_BUTTON,
- SCREEN_TOUCH,
- SCREEN_DRAG,
- ACTION,
- TYPE_MAX
- };
+protected:
+ static void _bind_methods();
- uint32_t ID;
- int type;
- int device;
+public:
+ void set_action(const StringName &p_action);
+ StringName get_action() const;
- union {
- InputEventMouseMotion mouse_motion;
- InputEventMouseButton mouse_button;
- InputEventJoypadMotion joy_motion;
- InputEventJoypadButton joy_button;
- InputEventKey key;
- InputEventScreenTouch screen_touch;
- InputEventScreenDrag screen_drag;
- InputEventAction action;
- };
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ virtual bool is_action(const StringName &p_action) const;
+
+ virtual bool is_action_type() const { return true; }
- bool is_pressed() const;
- bool is_action(const String &p_action) const;
- bool is_action_pressed(const String &p_action) const;
- bool is_action_released(const String &p_action) const;
- bool is_echo() const;
- void set_as_action(const String &p_action, bool p_pressed);
-
- InputEvent xform_by(const Transform2D &p_xform) const;
- bool operator==(const InputEvent &p_event) const;
- operator String() const;
- InputEvent() {
- zeromem(this, sizeof(InputEvent));
- mouse_button.factor = 1;
- }
+ InputEventAction();
};
#endif
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index 9f8fcccd82..248f5537c6 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -39,7 +39,7 @@ void MainLoop::_bind_methods() {
ClassDB::bind_method(D_METHOD("idle", "delta"), &MainLoop::idle);
ClassDB::bind_method(D_METHOD("finish"), &MainLoop::finish);
- BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::INPUT_EVENT, "ev")));
+ BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
BIND_VMETHOD(MethodInfo("_input_text", PropertyInfo(Variant::STRING, "text")));
BIND_VMETHOD(MethodInfo("_initialize"));
BIND_VMETHOD(MethodInfo("_iteration", PropertyInfo(Variant::REAL, "delta")));
@@ -73,7 +73,7 @@ void MainLoop::input_text(const String &p_text) {
get_script_instance()->call("_input_text", p_text);
}
-void MainLoop::input_event(const InputEvent &p_event) {
+void MainLoop::input_event(const Ref<InputEvent> &p_event) {
if (get_script_instance())
get_script_instance()->call("_input_event", p_event);
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index a53137afa4..23b352468e 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -59,7 +59,7 @@ public:
NOTIFICATION_TRANSLATION_CHANGED = 10,
};
- virtual void input_event(const InputEvent &p_event);
+ virtual void input_event(const Ref<InputEvent> &p_event);
virtual void input_text(const String &p_text);
virtual void init();
diff --git a/core/os/os.h b/core/os/os.h
index 037ce436c1..11fe8b44e3 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -413,4 +413,6 @@ public:
virtual ~OS();
};
+VARIANT_ENUM_CAST(PowerState);
+
#endif
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index 836bcb7287..0565d0d3f5 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -237,7 +237,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
case Variant::RECT3:
case Variant::BASIS:
case Variant::TRANSFORM:
- case Variant::INPUT_EVENT:
case Variant::POOL_BYTE_ARRAY:
case Variant::POOL_INT_ARRAY:
case Variant::POOL_REAL_ARRAY:
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 634751b0bb..b089ba9129 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -110,6 +110,18 @@ void register_core_types() {
ClassDB::register_class<Resource>();
ClassDB::register_class<Image>();
+ ClassDB::register_virtual_class<InputEvent>();
+ ClassDB::register_virtual_class<InputEventWithModifiers>();
+ ClassDB::register_class<InputEventKey>();
+ ClassDB::register_virtual_class<InputEventMouse>();
+ ClassDB::register_class<InputEventMouseButton>();
+ ClassDB::register_class<InputEventMouseMotion>();
+ ClassDB::register_class<InputEventJoypadButton>();
+ ClassDB::register_class<InputEventJoypadMotion>();
+ ClassDB::register_class<InputEventScreenDrag>();
+ ClassDB::register_class<InputEventScreenTouch>();
+ ClassDB::register_class<InputEventAction>();
+
ClassDB::register_class<FuncRef>();
ClassDB::register_virtual_class<StreamPeer>();
ClassDB::register_class<StreamPeerBuffer>();
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 7a5129962b..6a93d7789e 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -489,6 +489,18 @@ signed char String::naturalnocasecmp_to(const String &p_str) const {
const CharType *that_str = p_str.c_str();
if (this_str && that_str) {
+
+ while (*this_str == '.' || *that_str == '.') {
+ if (*this_str++ != '.')
+ return 1;
+ if (*that_str++ != '.')
+ return -1;
+ if (!*that_str)
+ return 1;
+ if (!*this_str)
+ return -1;
+ }
+
while (*this_str) {
if (!*that_str)
diff --git a/core/variant.cpp b/core/variant.cpp
index 9c05dbaca0..0807a33788 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -133,11 +133,6 @@ String Variant::get_type_name(Variant::Type p_type) {
return "NodePath";
} break;
- case INPUT_EVENT: {
-
- return "InputEvent";
-
- } break;
case DICTIONARY: {
return "Dictionary";
@@ -798,11 +793,6 @@ bool Variant::is_zero() const {
return reinterpret_cast<const NodePath *>(_data._mem)->is_empty();
} break;
- case INPUT_EVENT: {
-
- return _data._input_event->type == InputEvent::NONE;
-
- } break;
case DICTIONARY: {
return reinterpret_cast<const Dictionary *>(_data._mem)->empty();
@@ -1018,11 +1008,6 @@ void Variant::reference(const Variant &p_variant) {
memnew_placement(_data._mem, NodePath(*reinterpret_cast<const NodePath *>(p_variant._data._mem)));
} break;
- case INPUT_EVENT: {
-
- _data._input_event = memnew(InputEvent(*p_variant._data._input_event));
-
- } break;
case DICTIONARY: {
memnew_placement(_data._mem, Dictionary(*reinterpret_cast<const Dictionary *>(p_variant._data._mem)));
@@ -1149,12 +1134,6 @@ void Variant::clear() {
reinterpret_cast<Array *>(_data._mem)->~Array();
} break;
- case INPUT_EVENT: {
-
- memdelete(_data._input_event);
-
- } break;
-
// arrays
case POOL_BYTE_ARRAY: {
@@ -1503,7 +1482,6 @@ Variant::operator String() const {
} break;
case TRANSFORM: return operator Transform();
case NODE_PATH: return operator NodePath();
- case INPUT_EVENT: return operator InputEvent();
case COLOR: return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a);
case DICTIONARY: {
@@ -1798,14 +1776,6 @@ Variant::operator Control *() const {
return NULL;
}
-Variant::operator InputEvent() const {
-
- if (type == INPUT_EVENT)
- return *reinterpret_cast<const InputEvent *>(_data._input_event);
- else
- return InputEvent();
-}
-
Variant::operator Dictionary() const {
if (type == DICTIONARY)
@@ -2285,12 +2255,6 @@ Variant::Variant(const NodePath &p_node_path) {
memnew_placement(_data._mem, NodePath(p_node_path));
}
-Variant::Variant(const InputEvent &p_input_event) {
-
- type = INPUT_EVENT;
- _data._input_event = memnew(InputEvent(p_input_event));
-}
-
Variant::Variant(const RefPtr &p_resource) {
type = OBJECT;
@@ -2585,8 +2549,8 @@ uint32_t Variant::hash() const {
} break;
case RECT2: {
- uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->pos.x);
- hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->pos.y, hash);
+ uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.x);
+ hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.y, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.x, hash);
return hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.y, hash);
} break;
@@ -2626,7 +2590,7 @@ uint32_t Variant::hash() const {
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
- hash = hash_djb2_one_float(_data._rect3->pos[i], hash);
+ hash = hash_djb2_one_float(_data._rect3->position[i], hash);
hash = hash_djb2_one_float(_data._rect3->size[i], hash);
}
@@ -2690,11 +2654,6 @@ uint32_t Variant::hash() const {
return reinterpret_cast<const NodePath *>(_data._mem)->hash();
} break;
- case INPUT_EVENT: {
-
- return hash_djb2_buffer((uint8_t *)_data._input_event, sizeof(InputEvent));
-
- } break;
case DICTIONARY: {
return reinterpret_cast<const Dictionary *>(_data._mem)->hash();
@@ -2861,7 +2820,7 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Rect2 *l = reinterpret_cast<const Rect2 *>(_data._mem);
const Rect2 *r = reinterpret_cast<const Rect2 *>(p_variant._data._mem);
- return (hash_compare_vector2(l->pos, r->pos)) &&
+ return (hash_compare_vector2(l->position, r->position)) &&
(hash_compare_vector2(l->size, r->size));
} break;
@@ -2896,7 +2855,7 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Rect3 *l = _data._rect3;
const Rect3 *r = p_variant._data._rect3;
- return (hash_compare_vector3(l->pos, r->pos) &&
+ return (hash_compare_vector3(l->position, r->position) &&
(hash_compare_vector3(l->size, r->size)));
} break;
diff --git a/core/variant.h b/core/variant.h
index 76097dfbdd..661d31cf16 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -42,7 +42,6 @@
#include "io/ip_address.h"
#include "math_2d.h"
#include "matrix3.h"
-#include "os/input_event.h"
#include "os/power.h"
#include "path_db.h"
#include "plane.h"
@@ -100,7 +99,6 @@ public:
NODE_PATH, // 15
_RID,
OBJECT,
- INPUT_EVENT,
DICTIONARY,
ARRAY, // 20
@@ -143,7 +141,6 @@ private:
Basis *_basis;
Transform *_transform;
RefPtr *_resource;
- InputEvent *_input_event;
void *_ptr; //generic pointer
uint8_t _mem[sizeof(ObjData) > (sizeof(real_t) * 4) ? sizeof(ObjData) : (sizeof(real_t) * 4)];
} _data;
@@ -207,7 +204,7 @@ public:
operator NodePath() const;
operator RefPtr() const;
operator RID() const;
- operator InputEvent() const;
+
operator Object *() const;
operator Node *() const;
operator Control *() const;
@@ -276,7 +273,6 @@ public:
Variant(const RefPtr &p_resource);
Variant(const RID &p_rid);
Variant(const Object *p_object);
- Variant(const InputEvent &p_input_event);
Variant(const Dictionary &p_dictionary);
Variant(const Array &p_array);
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 8bc9f085ad..9ead727a80 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -354,6 +354,8 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Rect2, merge);
VCALL_LOCALMEM1R(Rect2, has_point);
VCALL_LOCALMEM1R(Rect2, grow);
+ VCALL_LOCALMEM2R(Rect2, grow_margin);
+ VCALL_LOCALMEM4R(Rect2, grow_individual);
VCALL_LOCALMEM1R(Rect2, expand);
VCALL_LOCALMEM0R(Vector3, min_axis);
@@ -737,13 +739,6 @@ struct _VariantCall {
VCALL_PTR1( Transform, translate );
VCALL_PTR0( Transform, orthonormalize ); */
- VCALL_PTR0R(InputEvent, is_pressed);
- VCALL_PTR1R(InputEvent, is_action);
- VCALL_PTR1R(InputEvent, is_action_pressed);
- VCALL_PTR1R(InputEvent, is_action_released);
- VCALL_PTR0R(InputEvent, is_echo);
- VCALL_PTR2(InputEvent, set_as_action);
-
struct ConstructData {
int arg_count;
@@ -1036,7 +1031,6 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
return NodePath(); // 15
case _RID: return RID();
case OBJECT: return (Object *)NULL;
- case INPUT_EVENT: return InputEvent();
case DICTIONARY: return Dictionary();
case ARRAY:
return Array(); // 20
@@ -1117,7 +1111,6 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
return (NodePath(p_args[0]->operator NodePath())); // 15
case _RID: return (RID(*p_args[0]));
case OBJECT: return ((Object *)(p_args[0]->operator Object *()));
- case INPUT_EVENT: return (InputEvent(*p_args[0]));
case DICTIONARY: return p_args[0]->operator Dictionary();
case ARRAY:
return p_args[0]->operator Array(); // 20
@@ -1442,6 +1435,8 @@ void register_variant_methods() {
ADDFUNC1(RECT2, RECT2, Rect2, merge, RECT2, "b", varray());
ADDFUNC1(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray());
ADDFUNC1(RECT2, RECT2, Rect2, grow, REAL, "by", varray());
+ ADDFUNC2(RECT2, RECT2, Rect2, grow_margin, INT, "margin", REAL, "by", varray());
+ ADDFUNC4(RECT2, RECT2, Rect2, grow_individual, REAL, "left", REAL, "top", REAL, "right", REAL, " bottom", varray());
ADDFUNC1(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray());
ADDFUNC0(VECTOR3, INT, Vector3, min_axis, varray());
@@ -1460,7 +1455,6 @@ void register_variant_methods() {
ADDFUNC1(VECTOR3, BASIS, Vector3, outer, VECTOR3, "b", varray());
ADDFUNC0(VECTOR3, BASIS, Vector3, to_diagonal_matrix, varray());
ADDFUNC0(VECTOR3, VECTOR3, Vector3, abs, varray());
- ADDFUNC0(VECTOR3, VECTOR3, Vector3, abs, varray());
ADDFUNC0(VECTOR3, VECTOR3, Vector3, floor, varray());
ADDFUNC0(VECTOR3, VECTOR3, Vector3, ceil, varray());
ADDFUNC1(VECTOR3, REAL, Vector3, distance_to, VECTOR3, "b", varray());
@@ -1691,13 +1685,6 @@ void register_variant_methods() {
_VariantCall::type_funcs[Variant::TRANSFORM].functions["xform_inv"].returns = true;
#endif
- ADDFUNC0(INPUT_EVENT, BOOL, InputEvent, is_pressed, varray());
- ADDFUNC1(INPUT_EVENT, BOOL, InputEvent, is_action, STRING, "action", varray());
- ADDFUNC1(INPUT_EVENT, BOOL, InputEvent, is_action_pressed, STRING, "action", varray());
- ADDFUNC1(INPUT_EVENT, BOOL, InputEvent, is_action_released, STRING, "action", varray());
- ADDFUNC0(INPUT_EVENT, BOOL, InputEvent, is_echo, varray());
- ADDFUNC2(INPUT_EVENT, NIL, InputEvent, set_as_action, STRING, "action", BOOL, "pressed", varray());
-
/* REGISTER CONSTRUCTORS */
_VariantCall::add_constructor(_VariantCall::Vector2_init1, Variant::VECTOR2, "x", Variant::REAL, "y", Variant::REAL);
@@ -1734,16 +1721,6 @@ void register_variant_methods() {
_VariantCall::add_constant(Variant::VECTOR3, "AXIS_X", Vector3::AXIS_X);
_VariantCall::add_constant(Variant::VECTOR3, "AXIS_Y", Vector3::AXIS_Y);
_VariantCall::add_constant(Variant::VECTOR3, "AXIS_Z", Vector3::AXIS_Z);
-
- _VariantCall::add_constant(Variant::INPUT_EVENT, "NONE", InputEvent::NONE);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "KEY", InputEvent::KEY);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "MOUSE_MOTION", InputEvent::MOUSE_MOTION);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "MOUSE_BUTTON", InputEvent::MOUSE_BUTTON);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "JOYPAD_MOTION", InputEvent::JOYPAD_MOTION);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "JOYPAD_BUTTON", InputEvent::JOYPAD_BUTTON);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "SCREEN_TOUCH", InputEvent::SCREEN_TOUCH);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "SCREEN_DRAG", InputEvent::SCREEN_DRAG);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "ACTION", InputEvent::ACTION);
}
void unregister_variant_methods() {
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 8bae6a168b..7b2d0f6886 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -61,7 +61,6 @@ bool Variant::booleanize(bool &r_valid) const {
case _RID: return (*reinterpret_cast<const RID *>(_data._mem)).is_valid();
case OBJECT: return _get_obj().obj;
case NODE_PATH: return (*reinterpret_cast<const NodePath *>(_data._mem)) != NodePath();
- case INPUT_EVENT:
case DICTIONARY:
case ARRAY:
case POOL_BYTE_ARRAY:
@@ -291,7 +290,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
if (p_b.type == NIL)
_RETURN(!p_a._get_obj().obj);
} break;
- DEFAULT_OP_PTRREF(==, INPUT_EVENT, _input_event);
case DICTIONARY: {
@@ -378,7 +376,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
if (p_b.type == OBJECT)
_RETURN((p_a._get_obj().obj < p_b._get_obj().obj));
} break;
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
case ARRAY: {
@@ -443,7 +440,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
if (p_b.type == OBJECT)
_RETURN((p_a._get_obj().obj <= p_b._get_obj().obj));
} break;
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -502,7 +498,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
case ARRAY: {
@@ -559,7 +554,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -656,7 +650,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -729,7 +722,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -771,7 +763,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -811,7 +802,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -1141,9 +1131,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Rect2 *v = reinterpret_cast<Rect2 *>(_data._mem);
- if (*str == "pos") {
+ if (*str == "position") {
valid = true;
- v->pos = p_value;
+ v->position = p_value;
return;
} else if (*str == "size") {
valid = true;
@@ -1151,7 +1141,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
return;
} else if (*str == "end") {
valid = true;
- v->size = Vector2(p_value) - v->pos;
+ v->size = Vector2(p_value) - v->position;
return;
}
}
@@ -1314,9 +1304,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Rect3 *v = _data._rect3;
- if (*str == "pos") {
+ if (*str == "position") {
valid = true;
- v->pos = p_value;
+ v->position = p_value;
return;
} else if (*str == "size") {
valid = true;
@@ -1324,7 +1314,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
return;
} else if (*str == "end") {
valid = true;
- v->size = Vector3(p_value) - v->pos;
+ v->size = Vector3(p_value) - v->position;
return;
}
}
@@ -1507,389 +1497,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
return obj->set(p_index, p_value, r_valid);
}
} break;
- case INPUT_EVENT: {
-
- InputEvent &ie = *_data._input_event;
-
- if (p_index.get_type() != Variant::STRING)
- return;
-
- const String &str = *reinterpret_cast<const String *>(p_index._data._mem);
-
- if (str == "type") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
-
- int type = p_value;
- if (type < 0 || type >= InputEvent::TYPE_MAX)
- return; //fail
- valid = true;
- ie.type = InputEvent::Type(type);
- return;
- } else if (str == "device") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
-
- valid = true;
- ie.device = p_value;
- return;
- } else if (str == "ID") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
-
- valid = true;
- ie.ID = p_value;
- return;
- }
-
- if (ie.type == InputEvent::KEY || ie.type == InputEvent::MOUSE_BUTTON || ie.type == InputEvent::MOUSE_MOTION) {
-
- if (str == "shift") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.mod.shift = p_value;
- return;
- }
- if (str == "alt") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.mod.alt = p_value;
- return;
- }
- if (str == "control") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.mod.control = p_value;
- return;
- }
- if (str == "meta") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.mod.meta = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::KEY) {
-
- if (str == "pressed") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.pressed = p_value;
- return;
- } else if (str == "scancode") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
-
- valid = true;
- ie.key.scancode = p_value;
- return;
- } else if (str == "unicode") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.key.unicode = p_value;
- return;
- } else if (str == "echo") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.echo = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::MOUSE_MOTION || ie.type == InputEvent::MOUSE_BUTTON) {
-
- if (str == "button_mask") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.button_mask = p_value;
- return;
- } else if (str == "x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.x = p_value;
- return;
- } else if (str == "y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.y = p_value;
- return;
- } else if (str == "pos") {
- if (p_value.type != Variant::VECTOR2)
- return;
- valid = true;
- Point2 value = p_value;
- ie.mouse_button.x = value.x;
- ie.mouse_button.y = value.y;
- return;
- } else if (str == "global_x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.global_x = p_value;
- return;
- } else if (str == "global_y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.global_y = p_value;
- return;
- } else if (str == "global_pos") {
- if (p_value.type != Variant::VECTOR2)
- return;
- valid = true;
- Point2 value = p_value;
- ie.mouse_button.global_x = value.x;
- ie.mouse_button.global_y = value.y;
- return;
- } /*else if (str=="pointer_index") {
- valid=true;
- return ie.mouse_button.pointer_index;
- }*/
-
- if (ie.type == InputEvent::MOUSE_MOTION) {
-
- if (str == "relative_x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_motion.relative_x = p_value;
- return;
- } else if (str == "relative_y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_motion.relative_y = p_value;
- return;
- } else if (str == "relative_pos") {
- if (p_value.type != Variant::VECTOR2)
- return;
- valid = true;
- Point2 value = p_value;
- ie.mouse_motion.relative_x = value.x;
- ie.mouse_motion.relative_y = value.y;
- return;
- }
-
- if (str == "speed_x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_motion.speed_x = p_value;
- return;
- } else if (str == "speed_y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_motion.speed_y = p_value;
- return;
- } else if (str == "speed") {
- if (p_value.type != Variant::VECTOR2)
- return;
- valid = true;
- Point2 value = p_value;
- ie.mouse_motion.speed_x = value.x;
- ie.mouse_motion.speed_y = value.y;
- return;
- }
-
- } else if (ie.type == InputEvent::MOUSE_BUTTON) {
-
- if (str == "button_index") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.button_index = p_value;
- return;
- } else if (str == "pressed") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
- valid = true;
- ie.mouse_button.pressed = p_value;
- return;
- } else if (str == "doubleclick") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
- valid = true;
- ie.mouse_button.doubleclick = p_value;
- return;
- }
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_BUTTON) {
-
- if (str == "button_index") {
- if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
- return;
- valid = true;
- ie.joy_button.button_index = p_value;
- return;
- }
- if (str == "pressed") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.joy_button.pressed = p_value;
- return;
- }
- if (str == "pressure") {
- if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
- return;
- valid = true;
- ie.joy_button.pressure = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_MOTION) {
-
- if (str == "axis") {
- if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
- return;
- valid = true;
- ie.joy_motion.axis = p_value;
- return;
- }
- if (str == "value") {
- if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
- return;
- valid = true;
- ie.joy_motion.axis_value = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::SCREEN_TOUCH) {
-
- if (str == "index") {
- valid = true;
- ie.screen_touch.index = p_value;
- return;
- }
- if (str == "x") {
- valid = true;
- ie.screen_touch.x = p_value;
- return;
- }
- if (str == "y") {
- valid = true;
- ie.screen_touch.y = p_value;
- return;
- }
- if (str == "pos") {
- valid = true;
- Vector2 v = p_value;
- ie.screen_touch.x = v.x;
- ie.screen_touch.y = v.y;
- return;
- }
- if (str == "pressed") {
- valid = true;
- ie.screen_touch.pressed = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::SCREEN_DRAG) {
-
- if (str == "index") {
- valid = true;
- ie.screen_drag.index = p_value;
- return;
- }
- if (str == "x") {
- valid = true;
- ie.screen_drag.x = p_value;
- return;
- }
- if (str == "y") {
- valid = true;
- ie.screen_drag.y = p_value;
- return;
- }
- if (str == "pos") {
- valid = true;
- Vector2 v = p_value;
- ie.screen_drag.x = v.x;
- ie.screen_drag.y = v.y;
- return;
- }
- if (str == "relative_x") {
- valid = true;
- ie.screen_drag.relative_x = p_value;
- return;
- }
- if (str == "relative_y") {
- valid = true;
- ie.screen_drag.relative_y = p_value;
- return;
- }
- if (str == "relative_pos") {
- valid = true;
- Vector2 v = p_value;
- ie.screen_drag.relative_x = v.x;
- ie.screen_drag.relative_y = v.y;
- return;
- }
- if (str == "speed_x") {
- valid = true;
- ie.screen_drag.speed_x = p_value;
- return;
- }
- if (str == "speed_y") {
- valid = true;
- ie.screen_drag.speed_y = p_value;
- return;
- }
- if (str == "speed") {
- valid = true;
- Vector2 v = p_value;
- ie.screen_drag.speed_x = v.x;
- ie.screen_drag.speed_y = v.y;
- return;
- }
- }
- if (ie.type == InputEvent::ACTION) {
-
- if (str == "action") {
- valid = true;
- ie.action.action = p_value;
- return;
- } else if (str == "pressed") {
- valid = true;
- ie.action.pressed = p_value;
- return;
- }
- }
-
- } break;
case DICTIONARY: {
Dictionary *dic = reinterpret_cast<Dictionary *>(_data._mem);
@@ -1982,15 +1589,15 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem);
- if (*str == "pos") {
+ if (*str == "position") {
valid = true;
- return v->pos;
+ return v->position;
} else if (*str == "size") {
valid = true;
return v->size;
} else if (*str == "end") {
valid = true;
- return v->size + v->pos;
+ return v->size + v->position;
}
}
} break;
@@ -2111,15 +1718,15 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
const Rect3 *v = _data._rect3;
- if (*str == "pos") {
+ if (*str == "position") {
valid = true;
- return v->pos;
+ return v->position;
} else if (*str == "size") {
valid = true;
return v->size;
} else if (*str == "end") {
valid = true;
- return v->size + v->pos;
+ return v->size + v->position;
}
}
} break;
@@ -2261,235 +1868,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
}
} break;
- case INPUT_EVENT: {
-
- InputEvent ie = operator InputEvent();
-
- if (p_index.get_type() != Variant::STRING)
- break;
-
- const String &str = *reinterpret_cast<const String *>(p_index._data._mem);
-
- if (str == "type") {
- valid = true;
- return ie.type;
- } else if (str == "device") {
- valid = true;
- return ie.device;
- } else if (str == "ID") {
- valid = true;
- return ie.ID;
- }
-
- if (ie.type == InputEvent::KEY || ie.type == InputEvent::MOUSE_BUTTON || ie.type == InputEvent::MOUSE_MOTION) {
-
- if (str == "shift") {
- valid = true;
- return ie.key.mod.shift;
- }
- if (str == "alt") {
- valid = true;
- return ie.key.mod.alt;
- }
- if (str == "control") {
- valid = true;
- return ie.key.mod.control;
- }
- if (str == "meta") {
- valid = true;
- return ie.key.mod.meta;
- }
- }
-
- if (ie.type == InputEvent::KEY) {
-
- if (str == "pressed") {
- valid = true;
- return ie.key.pressed;
- } else if (str == "scancode") {
- valid = true;
- return ie.key.scancode;
- } else if (str == "unicode") {
- valid = true;
- return ie.key.unicode;
- } else if (str == "echo") {
- valid = true;
- return ie.key.echo;
- }
- }
-
- if (ie.type == InputEvent::MOUSE_MOTION || ie.type == InputEvent::MOUSE_BUTTON) {
-
- if (str == "button_mask") {
- valid = true;
- return ie.mouse_button.button_mask;
- } else if (str == "x") {
- valid = true;
- return ie.mouse_button.x;
- } else if (str == "y") {
- valid = true;
- return ie.mouse_button.y;
- } else if (str == "pos") {
- valid = true;
- return Point2(ie.mouse_button.x, ie.mouse_button.y);
- } else if (str == "global_x") {
- valid = true;
- return ie.mouse_button.global_x;
- } else if (str == "global_y") {
- valid = true;
- return ie.mouse_button.global_y;
- } else if (str == "global_pos") {
- valid = true;
- return Point2(ie.mouse_button.global_x, ie.mouse_button.global_y);
- } /*else if (str=="pointer_index") {
- valid=true;
- return ie.mouse_button.pointer_index;
- }*/
-
- if (ie.type == InputEvent::MOUSE_MOTION) {
-
- if (str == "relative_x") {
- valid = true;
- return ie.mouse_motion.relative_x;
- } else if (str == "relative_y") {
- valid = true;
- return ie.mouse_motion.relative_y;
- } else if (str == "relative_pos") {
- valid = true;
- return Point2(ie.mouse_motion.relative_x, ie.mouse_motion.relative_y);
- } else if (str == "speed_x") {
- valid = true;
- return ie.mouse_motion.speed_x;
- } else if (str == "speed_y") {
- valid = true;
- return ie.mouse_motion.speed_y;
- } else if (str == "speed") {
- valid = true;
- return Point2(ie.mouse_motion.speed_x, ie.mouse_motion.speed_y);
- }
-
- } else if (ie.type == InputEvent::MOUSE_BUTTON) {
-
- if (str == "button_index") {
- valid = true;
- return ie.mouse_button.button_index;
- } else if (str == "pressed") {
- valid = true;
- return ie.mouse_button.pressed;
- } else if (str == "doubleclick") {
- valid = true;
- return ie.mouse_button.doubleclick;
- }
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_BUTTON) {
-
- if (str == "button_index") {
- valid = true;
- return ie.joy_button.button_index;
- }
- if (str == "pressed") {
- valid = true;
- return ie.joy_button.pressed;
- }
- if (str == "pressure") {
- valid = true;
- return ie.joy_button.pressure;
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_MOTION) {
-
- if (str == "axis") {
- valid = true;
- return ie.joy_motion.axis;
- }
- if (str == "value") {
- valid = true;
- return ie.joy_motion.axis_value;
- }
- }
-
- if (ie.type == InputEvent::SCREEN_TOUCH) {
-
- if (str == "index") {
- valid = true;
- return ie.screen_touch.index;
- }
- if (str == "x") {
- valid = true;
- return ie.screen_touch.x;
- }
- if (str == "y") {
- valid = true;
- return ie.screen_touch.y;
- }
- if (str == "pos") {
- valid = true;
- return Vector2(ie.screen_touch.x, ie.screen_touch.y);
- }
- if (str == "pressed") {
- valid = true;
- return ie.screen_touch.pressed;
- }
- }
-
- if (ie.type == InputEvent::SCREEN_DRAG) {
-
- if (str == "index") {
- valid = true;
- return ie.screen_drag.index;
- }
- if (str == "x") {
- valid = true;
- return ie.screen_drag.x;
- }
- if (str == "y") {
- valid = true;
- return ie.screen_drag.y;
- }
- if (str == "pos") {
- valid = true;
- return Vector2(ie.screen_drag.x, ie.screen_drag.y);
- }
- if (str == "relative_x") {
- valid = true;
- return ie.screen_drag.relative_x;
- }
- if (str == "relative_y") {
- valid = true;
- return ie.screen_drag.relative_y;
- }
- if (str == "relative_pos") {
- valid = true;
- return Vector2(ie.screen_drag.relative_x, ie.screen_drag.relative_y);
- }
- if (str == "speed_x") {
- valid = true;
- return ie.screen_drag.speed_x;
- }
- if (str == "speed_y") {
- valid = true;
- return ie.screen_drag.speed_y;
- }
- if (str == "speed") {
- valid = true;
- return Vector2(ie.screen_drag.speed_x, ie.screen_drag.speed_y);
- }
- }
- if (ie.type == InputEvent::ACTION) {
-
- if (str == "action") {
- valid = true;
- return ie.action.action;
- } else if (str == "pressed") {
- valid = true;
- return ie.action.pressed;
- }
- }
-
- } break;
case DICTIONARY: {
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
@@ -2733,7 +2111,7 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
} break; // 5
case RECT2: {
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
+ p_list->push_back(PropertyInfo(Variant::VECTOR2, "position"));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "size"));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "end"));
@@ -2823,94 +2201,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
}
} break;
- case INPUT_EVENT: {
-
- InputEvent ie = operator InputEvent();
-
- p_list->push_back(PropertyInfo(Variant::INT, "type"));
- p_list->push_back(PropertyInfo(Variant::INT, "device"));
- p_list->push_back(PropertyInfo(Variant::INT, "ID"));
-
- if (ie.type == InputEvent::KEY || ie.type == InputEvent::MOUSE_BUTTON || ie.type == InputEvent::MOUSE_MOTION) {
-
- p_list->push_back(PropertyInfo(Variant::BOOL, "shift"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "alt"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "control"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "meta"));
- }
-
- if (ie.type == InputEvent::KEY) {
-
- p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "echo"));
- p_list->push_back(PropertyInfo(Variant::INT, "scancode"));
- p_list->push_back(PropertyInfo(Variant::INT, "unicode"));
- }
-
- if (ie.type == InputEvent::MOUSE_MOTION || ie.type == InputEvent::MOUSE_BUTTON) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "button_mask"));
- p_list->push_back(PropertyInfo(Variant::REAL, "x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
- p_list->push_back(PropertyInfo(Variant::REAL, "global_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "global_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "global_pos"));
-
- if (ie.type == InputEvent::MOUSE_MOTION) {
-
- p_list->push_back(PropertyInfo(Variant::REAL, "relative_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "relative_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "relative_pos"));
- p_list->push_back(PropertyInfo(Variant::REAL, "speed_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "speed_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "speed"));
-
- } else if (ie.type == InputEvent::MOUSE_BUTTON) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "button_index"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "doubleclick"));
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_BUTTON) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "button_index"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
- p_list->push_back(PropertyInfo(Variant::REAL, "pressure"));
- }
-
- if (ie.type == InputEvent::JOYPAD_MOTION) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "axis"));
- p_list->push_back(PropertyInfo(Variant::REAL, "value"));
- }
-
- if (ie.type == InputEvent::SCREEN_TOUCH) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "index"));
- p_list->push_back(PropertyInfo(Variant::REAL, "x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
- }
-
- if (ie.type == InputEvent::SCREEN_DRAG) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "index"));
- p_list->push_back(PropertyInfo(Variant::REAL, "x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
- p_list->push_back(PropertyInfo(Variant::REAL, "relative_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "relative_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "relative_pos"));
- p_list->push_back(PropertyInfo(Variant::REAL, "speed_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "speed_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "speed"));
- }
-
- } break;
case DICTIONARY: {
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
@@ -3469,7 +2759,7 @@ void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst)
case RECT2: {
const Rect2 *ra = reinterpret_cast<const Rect2 *>(a._data._mem);
const Rect2 *rb = reinterpret_cast<const Rect2 *>(b._data._mem);
- r_dst = Rect2(ra->pos + rb->pos * c, ra->size + rb->size * c);
+ r_dst = Rect2(ra->position + rb->position * c, ra->size + rb->size * c);
}
return;
case VECTOR3: {
@@ -3479,7 +2769,7 @@ void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst)
case RECT3: {
const Rect3 *ra = reinterpret_cast<const Rect3 *>(a._data._mem);
const Rect3 *rb = reinterpret_cast<const Rect3 *>(b._data._mem);
- r_dst = Rect3(ra->pos + rb->pos * c, ra->size + rb->size * c);
+ r_dst = Rect3(ra->position + rb->position * c, ra->size + rb->size * c);
}
return;
case QUAT: {
@@ -3589,7 +2879,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
}
return;
case RECT2: {
- r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->pos.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->pos, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c));
+ r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->position.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->position, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c));
}
return;
case VECTOR3: {
@@ -3609,7 +2899,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
}
return;
case RECT3: {
- r_dst = Rect3(a._data._rect3->pos.linear_interpolate(b._data._rect3->pos, c), a._data._rect3->size.linear_interpolate(b._data._rect3->size, c));
+ r_dst = Rect3(a._data._rect3->position.linear_interpolate(b._data._rect3->position, c), a._data._rect3->size.linear_interpolate(b._data._rect3->size, c));
}
return;
case BASIS: {
@@ -3636,10 +2926,6 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
r_dst = a;
}
return;
- case INPUT_EVENT: {
- r_dst = a;
- }
- return;
case DICTIONARY: {
}
return;
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 798a830dd0..26a6a05a30 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -30,6 +30,7 @@
#include "variant_parser.h"
#include "io/resource_loader.h"
+#include "os/input_event.h"
#include "os/keyboard.h"
CharType VariantParser::StreamFile::get_char() {
@@ -694,6 +695,110 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
return OK;
+ } else if (id == "Object") {
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_PARENTHESIS_OPEN) {
+ r_err_str = "Expected '('";
+ return ERR_PARSE_ERROR;
+ }
+
+ get_token(p_stream, token, line, r_err_str);
+
+ if (token.type != TK_IDENTIFIER) {
+ r_err_str = "Expected identifier with type of object";
+ return ERR_PARSE_ERROR;
+ }
+
+ String type = token.value;
+
+ Object *obj = ClassDB::instance(type);
+
+ if (!obj) {
+ r_err_str = "Can't instance Object() of type: " + type;
+ return ERR_PARSE_ERROR;
+ }
+
+ get_token(p_stream, token, line, r_err_str);
+ if (token.type != TK_COMMA) {
+ r_err_str = "Expected ',' after object type";
+ return ERR_PARSE_ERROR;
+ }
+
+ bool at_key = true;
+ String key;
+ Token token;
+ bool need_comma = false;
+
+ while (true) {
+
+ if (p_stream->is_eof()) {
+ r_err_str = "Unexpected End of File while parsing Object()";
+ return ERR_FILE_CORRUPT;
+ }
+
+ if (at_key) {
+
+ Error err = get_token(p_stream, token, line, r_err_str);
+ if (err != OK)
+ return err;
+
+ if (token.type == TK_PARENTHESIS_CLOSE) {
+ Reference *reference = obj->cast_to<Reference>();
+ if (reference) {
+ value = REF(reference);
+ } else {
+ value = obj;
+ }
+ return OK;
+ }
+
+ if (need_comma) {
+
+ if (token.type != TK_COMMA) {
+
+ r_err_str = "Expected '}' or ','";
+ return ERR_PARSE_ERROR;
+ } else {
+ need_comma = false;
+ continue;
+ }
+ }
+
+ if (token.type != TK_STRING) {
+ r_err_str = "Expected property name as string";
+ return ERR_PARSE_ERROR;
+ }
+
+ key = token.value;
+
+ err = get_token(p_stream, token, line, r_err_str);
+
+ if (err != OK)
+ return err;
+ if (token.type != TK_COLON) {
+
+ r_err_str = "Expected ':'";
+ return ERR_PARSE_ERROR;
+ }
+ at_key = false;
+ } else {
+
+ Error err = get_token(p_stream, token, line, r_err_str);
+ if (err != OK)
+ return err;
+
+ Variant v;
+ err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser);
+ if (err)
+ return err;
+ obj->set(key, v);
+ need_comma = true;
+ at_key = true;
+ }
+ }
+
+ return OK;
} else if (id == "Resource" || id == "SubResource" || id == "ExtResource") {
@@ -760,7 +865,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
return OK;
-
+#ifndef DISABLE_DEPRECATED
} else if (id == "InputEvent") {
get_token(p_stream, token, line, r_err_str);
@@ -778,12 +883,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
String id = token.value;
- InputEvent ie;
+ Ref<InputEvent> ie;
if (id == "NONE") {
- ie.type = InputEvent::NONE;
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
@@ -793,21 +896,23 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "KEY") {
+ Ref<InputEventKey> key;
+ key.instance();
+ ie = key;
+
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_COMMA) {
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
}
- ie.type = InputEvent::KEY;
-
get_token(p_stream, token, line, r_err_str);
if (token.type == TK_IDENTIFIER) {
String name = token.value;
- ie.key.scancode = find_keycode(name);
+ key->set_scancode(find_keycode(name));
} else if (token.type == TK_NUMBER) {
- ie.key.scancode = token.value;
+ key->set_scancode(token.value);
} else {
r_err_str = "Expected string or integer for keycode";
@@ -828,13 +933,13 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
String mods = token.value;
if (mods.findn("C") != -1)
- ie.key.mod.control = true;
+ key->set_control(true);
if (mods.findn("A") != -1)
- ie.key.mod.alt = true;
+ key->set_alt(true);
if (mods.findn("S") != -1)
- ie.key.mod.shift = true;
+ key->set_shift(true);
if (mods.findn("M") != -1)
- ie.key.mod.meta = true;
+ key->set_metakey(true);
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
@@ -850,21 +955,23 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "MBUTTON") {
+ Ref<InputEventMouseButton> mb;
+ mb.instance();
+ ie = mb;
+
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_COMMA) {
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
}
- ie.type = InputEvent::MOUSE_BUTTON;
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_NUMBER) {
r_err_str = "Expected button index";
return ERR_PARSE_ERROR;
}
- ie.mouse_button.button_index = token.value;
+ mb->set_button_index(token.value);
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
@@ -874,21 +981,23 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "JBUTTON") {
+ Ref<InputEventJoypadButton> jb;
+ jb.instance();
+ ie = jb;
+
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_COMMA) {
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
}
- ie.type = InputEvent::JOYPAD_BUTTON;
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_NUMBER) {
r_err_str = "Expected button index";
return ERR_PARSE_ERROR;
}
- ie.joy_button.button_index = token.value;
+ jb->set_button_index(token.value);
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
@@ -898,21 +1007,23 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "JAXIS") {
+ Ref<InputEventJoypadMotion> jm;
+ jm.instance();
+ ie = jm;
+
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_COMMA) {
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
}
- ie.type = InputEvent::JOYPAD_MOTION;
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_NUMBER) {
r_err_str = "Expected axis index";
return ERR_PARSE_ERROR;
}
- ie.joy_motion.axis = token.value;
+ jm->set_axis(token.value);
get_token(p_stream, token, line, r_err_str);
@@ -927,7 +1038,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return ERR_PARSE_ERROR;
}
- ie.joy_motion.axis_value = token.value;
+ jm->set_axis_value(token.value);
get_token(p_stream, token, line, r_err_str);
@@ -945,7 +1056,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = ie;
return OK;
-
+#endif
} else if (id == "PoolByteArray" || id == "ByteArray") {
Vector<uint8_t> args;
@@ -1121,91 +1232,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = arr;
return OK;
- } else if (id == "key") { // compatibility with project.godot
-
- Vector<String> params;
- Error err = _parse_enginecfg(p_stream, params, line, r_err_str);
- if (err)
- return err;
- ERR_FAIL_COND_V(params.size() != 1 && params.size() != 2, ERR_PARSE_ERROR);
-
- int scode = 0;
-
- if (params[0].is_numeric()) {
- scode = params[0].to_int();
- if (scode < 10) {
- scode = KEY_0 + scode;
- }
- } else
- scode = find_keycode(params[0]);
-
- InputEvent ie;
- ie.type = InputEvent::KEY;
- ie.key.scancode = scode;
-
- if (params.size() == 2) {
- String mods = params[1];
- if (mods.findn("C") != -1)
- ie.key.mod.control = true;
- if (mods.findn("A") != -1)
- ie.key.mod.alt = true;
- if (mods.findn("S") != -1)
- ie.key.mod.shift = true;
- if (mods.findn("M") != -1)
- ie.key.mod.meta = true;
- }
- value = ie;
- return OK;
-
- } else if (id == "mbutton") { // compatibility with project.godot
-
- Vector<String> params;
- Error err = _parse_enginecfg(p_stream, params, line, r_err_str);
- if (err)
- return err;
- ERR_FAIL_COND_V(params.size() != 2, ERR_PARSE_ERROR);
-
- InputEvent ie;
- ie.type = InputEvent::MOUSE_BUTTON;
- ie.device = params[0].to_int();
- ie.mouse_button.button_index = params[1].to_int();
-
- value = ie;
- return OK;
- } else if (id == "jbutton") { // compatibility with project.godot
-
- Vector<String> params;
- Error err = _parse_enginecfg(p_stream, params, line, r_err_str);
- if (err)
- return err;
- ERR_FAIL_COND_V(params.size() != 2, ERR_PARSE_ERROR);
- InputEvent ie;
- ie.type = InputEvent::JOYPAD_BUTTON;
- ie.device = params[0].to_int();
- ie.joy_button.button_index = params[1].to_int();
-
- value = ie;
-
- return OK;
- } else if (id == "jaxis") { // compatibility with project.godot
-
- Vector<String> params;
- Error err = _parse_enginecfg(p_stream, params, line, r_err_str);
- if (err)
- return err;
- ERR_FAIL_COND_V(params.size() != 2, ERR_PARSE_ERROR);
-
- InputEvent ie;
- ie.type = InputEvent::JOYPAD_MOTION;
- ie.device = params[0].to_int();
- int axis = params[1].to_int();
- ie.joy_motion.axis = axis >> 1;
- ie.joy_motion.axis_value = axis & 1 ? 1 : -1;
-
- value = ie;
-
- return OK;
-
} else {
r_err_str = "Unexpected identifier: '" + id + "'.";
return ERR_PARSE_ERROR;
@@ -1594,7 +1620,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
case Variant::RECT2: {
Rect2 aabb = p_variant;
- p_store_string_func(p_store_string_ud, "Rect2( " + rtosfix(aabb.pos.x) + ", " + rtosfix(aabb.pos.y) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + " )");
+ p_store_string_func(p_store_string_ud, "Rect2( " + rtosfix(aabb.position.x) + ", " + rtosfix(aabb.position.y) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + " )");
} break;
case Variant::VECTOR3: {
@@ -1611,7 +1637,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
case Variant::RECT3: {
Rect3 aabb = p_variant;
- p_store_string_func(p_store_string_ud, "Rect3( " + rtosfix(aabb.pos.x) + ", " + rtosfix(aabb.pos.y) + ", " + rtosfix(aabb.pos.z) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + ", " + rtosfix(aabb.size.z) + " )");
+ p_store_string_func(p_store_string_ud, "Rect3( " + rtosfix(aabb.position.x) + ", " + rtosfix(aabb.position.y) + ", " + rtosfix(aabb.position.z) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + ", " + rtosfix(aabb.size.z) + " )");
} break;
case Variant::QUAT: {
@@ -1689,76 +1715,66 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
case Variant::OBJECT: {
- RES res = p_variant;
- if (res.is_null()) {
+ Object *obj = p_variant;
+
+ if (!obj) {
p_store_string_func(p_store_string_ud, "null");
break; // don't save it
}
- String res_text;
+ RES res = p_variant;
+ if (res.is_valid()) {
+ //is resource
+ String res_text;
- if (p_encode_res_func) {
+ //try external function
+ if (p_encode_res_func) {
- res_text = p_encode_res_func(p_encode_res_ud, res);
- }
+ res_text = p_encode_res_func(p_encode_res_ud, res);
+ }
- if (res_text == String() && res->get_path().is_resource_file()) {
+ //try path because it's a file
+ if (res_text == String() && res->get_path().is_resource_file()) {
- //external resource
- String path = res->get_path();
- res_text = "Resource( \"" + path + "\")";
+ //external resource
+ String path = res->get_path();
+ res_text = "Resource( \"" + path + "\")";
+ }
+
+ //could come up with some sort of text
+ if (res_text != String()) {
+ p_store_string_func(p_store_string_ud, res_text);
+ break;
+ }
}
- if (res_text == String())
- res_text = "null";
+ //store as generic object
- p_store_string_func(p_store_string_ud, res_text);
+ p_store_string_func(p_store_string_ud, "Object(" + obj->get_class() + ",");
- } break;
- case Variant::INPUT_EVENT: {
-
- String str = "InputEvent(";
-
- InputEvent ev = p_variant;
- switch (ev.type) {
- case InputEvent::KEY: {
-
- str += "KEY," + itos(ev.key.scancode);
- String mod;
- if (ev.key.mod.alt)
- mod += "A";
- if (ev.key.mod.shift)
- mod += "S";
- if (ev.key.mod.control)
- mod += "C";
- if (ev.key.mod.meta)
- mod += "M";
-
- if (mod != String())
- str += "," + mod;
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- str += "MBUTTON," + itos(ev.mouse_button.button_index);
- } break;
- case InputEvent::JOYPAD_BUTTON: {
- str += "JBUTTON," + itos(ev.joy_button.button_index);
-
- } break;
- case InputEvent::JOYPAD_MOTION: {
- str += "JAXIS," + itos(ev.joy_motion.axis) + "," + itos(ev.joy_motion.axis_value);
- } break;
- case InputEvent::NONE: {
- str += "NONE";
- } break;
- default: {}
- }
+ List<PropertyInfo> props;
+ obj->get_property_list(&props);
+ bool first = true;
+ for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
+
+ if (E->get().usage & PROPERTY_USAGE_STORAGE || E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE) {
+ //must be serialized
- str += ")";
+ if (first) {
+ first = false;
+ } else {
+ p_store_string_func(p_store_string_ud, ",");
+ }
- p_store_string_func(p_store_string_ud, str); //will be added later
+ p_store_string_func(p_store_string_ud, "\"" + E->get().name + "\":");
+ write(obj->get(E->get().name), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud);
+ }
+ }
+
+ p_store_string_func(p_store_string_ud, ")\n");
} break;
+
case Variant::DICTIONARY: {
Dictionary dict = p_variant;