diff options
Diffstat (limited to 'modules')
116 files changed, 5665 insertions, 4814 deletions
diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index f80e6e501e..71593ebfa9 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -76,8 +76,6 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = { { "DXT1", true, false, 4, 8, Image::FORMAT_DXT1 }, { "DXT3", true, false, 4, 16, Image::FORMAT_DXT3 }, { "DXT5", true, false, 4, 16, Image::FORMAT_DXT5 }, - { "ATI1", true, false, 4, 8, Image::FORMAT_ATI1 }, - { "ATI2", true, false, 4, 16, Image::FORMAT_ATI2 }, { "BGRA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, { "BGR8", false, false, 1, 3, Image::FORMAT_RGB8 }, { "RGBA8", false, false, 1, 4, Image::FORMAT_RGBA8 }, @@ -144,12 +142,14 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, f->get_32(); f->get_32(); - /*print_line("DDS width: "+itos(width)); + /* + print_line("DDS width: "+itos(width)); print_line("DDS height: "+itos(height)); - print_line("DDS mipmaps: "+itos(mipmaps));*/ + print_line("DDS mipmaps: "+itos(mipmaps)); - //printf("fourcc: %x fflags: %x, rgbbits: %x, fsize: %x\n",format_fourcc,format_flags,format_rgb_bits,format_size); - //printf("rmask: %x gmask: %x, bmask: %x, amask: %x\n",format_red_mask,format_green_mask,format_blue_mask,format_alpha_mask); + printf("fourcc: %x fflags: %x, rgbbits: %x, fsize: %x\n",format_fourcc,format_flags,format_rgb_bits,format_size); + printf("rmask: %x gmask: %x, bmask: %x, amask: %x\n",format_red_mask,format_green_mask,format_blue_mask,format_alpha_mask); + */ //must avoid this later while (f->get_pos() < 128) @@ -439,7 +439,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, wb = PoolVector<uint8_t>::Write(); } - Image img(width, height, mipmaps - 1, info.format, src_data); + Ref<Image> img = memnew(Image(width, height, mipmaps - 1, info.format, src_data)); Ref<ImageTexture> texture = memnew(ImageTexture); texture->create_from_image(img); diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index c05c86d9ae..738bd27ed3 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -575,6 +575,9 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer * case COMPRESS_ZLIB: { mode = Compression::MODE_DEFLATE; } break; + case COMPRESS_ZSTD: { + mode = Compression::MODE_ZSTD; + } break; default: { ERR_FAIL_V(0); } } @@ -608,6 +611,10 @@ size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_DEFLATE); } break; + case COMPRESS_ZSTD: { + + ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_ZSTD); + } break; default: {} } if (ret < 0) { @@ -629,7 +636,8 @@ void NetworkedMultiplayerENet::_setup_compressor() { enet_host_compress_with_range_coder(host); } break; case COMPRESS_FASTLZ: - case COMPRESS_ZLIB: { + case COMPRESS_ZLIB: + case COMPRESS_ZSTD: { enet_host_compress(host, &enet_compressor); } break; @@ -654,6 +662,7 @@ void NetworkedMultiplayerENet::_bind_methods() { BIND_CONSTANT(COMPRESS_RANGE_CODER); BIND_CONSTANT(COMPRESS_FASTLZ); BIND_CONSTANT(COMPRESS_ZLIB); + BIND_CONSTANT(COMPRESS_ZSTD); } NetworkedMultiplayerENet::NetworkedMultiplayerENet() { diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/networked_multiplayer_enet.h index c20c1af68e..8b971adf55 100644 --- a/modules/enet/networked_multiplayer_enet.h +++ b/modules/enet/networked_multiplayer_enet.h @@ -43,7 +43,8 @@ public: COMPRESS_NONE, COMPRESS_RANGE_CODER, COMPRESS_FASTLZ, - COMPRESS_ZLIB + COMPRESS_ZLIB, + COMPRESS_ZSTD }; private: diff --git a/modules/etc/SCsub b/modules/etc/SCsub new file mode 100644 index 0000000000..8f5937017e --- /dev/null +++ b/modules/etc/SCsub @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_etc = env_modules.Clone() + +# Thirdparty source files +# Not unbundled so far since not widespread as shared library +thirdparty_dir = "#thirdparty/etc2comp/" +thirdparty_sources = [ + "EtcBlock4x4.cpp", + "EtcBlock4x4Encoding.cpp", + "EtcBlock4x4Encoding_ETC1.cpp", + "EtcBlock4x4Encoding_R11.cpp", + "EtcBlock4x4Encoding_RG11.cpp", + "EtcBlock4x4Encoding_RGB8A1.cpp", + "EtcBlock4x4Encoding_RGB8.cpp", + "EtcBlock4x4Encoding_RGBA8.cpp", + "Etc.cpp", + "EtcDifferentialTrys.cpp", + "EtcFilter.cpp", + "EtcImage.cpp", + "EtcIndividualTrys.cpp", + "EtcMath.cpp", + "EtcSortedBlockList.cpp", +] +thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + +env_etc.add_source_files(env.modules_sources, thirdparty_sources) +env_etc.Append(CPPPATH=[thirdparty_dir]) + +# Godot source files +env_etc.add_source_files(env.modules_sources, "*.cpp") + +# upstream uses c++11 +env_etc.Append(CXXFLAGS="-std=gnu++11") diff --git a/modules/etc1/config.py b/modules/etc/config.py index fb920482f5..fb920482f5 100644 --- a/modules/etc1/config.py +++ b/modules/etc/config.py diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp new file mode 100644 index 0000000000..d9daffc59e --- /dev/null +++ b/modules/etc/image_etc.cpp @@ -0,0 +1,199 @@ +/*************************************************************************/ +/* image_etc.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "image_etc.h" +#include "Etc.h" +#include "EtcFilter.h" +#include "image.h" +#include "os/copymem.h" +#include "os/os.h" +#include "print_string.h" + +static Image::Format _get_etc2_mode(Image::DetectChannels format) { + switch (format) { + case Image::DETECTED_L: + case Image::DETECTED_R: + return Image::FORMAT_ETC2_R11; + + case Image::DETECTED_RG: + return Image::FORMAT_ETC2_RG11; + + case Image::DETECTED_RGB: + return Image::FORMAT_ETC2_RGB8; + + case Image::DETECTED_RGBA: + return Image::FORMAT_ETC2_RGBA8; + + // TODO: would be nice if we could use FORMAT_ETC2_RGB8A1 for FORMAT_RGBA5551 + } + + ERR_FAIL_COND_V(true, Image::FORMAT_MAX); +} + +static Etc::Image::Format _image_format_to_etc2comp_format(Image::Format format) { + switch (format) { + case Image::FORMAT_ETC: + return Etc::Image::Format::ETC1; + + case Image::FORMAT_ETC2_R11: + return Etc::Image::Format::R11; + + case Image::FORMAT_ETC2_R11S: + return Etc::Image::Format::SIGNED_R11; + + case Image::FORMAT_ETC2_RG11: + return Etc::Image::Format::RG11; + + case Image::FORMAT_ETC2_RG11S: + return Etc::Image::Format::SIGNED_RG11; + + case Image::FORMAT_ETC2_RGB8: + return Etc::Image::Format::RGB8; + + case Image::FORMAT_ETC2_RGBA8: + return Etc::Image::Format::RGBA8; + + case Image::FORMAT_ETC2_RGB8A1: + return Etc::Image::Format::RGB8A1; + } + + ERR_FAIL_COND_V(true, Etc::Image::Format::UNKNOWN); +} + +static void _decompress_etc1(Image *p_img) { + // not implemented, to be removed +} + +static void _decompress_etc2(Image *p_img) { + // not implemented, to be removed +} + +static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_format, Image::CompressSource p_source) { + Image::Format img_format = p_img->get_format(); + Image::DetectChannels detected_channels = p_img->get_detected_channels(); + + if (p_source == Image::COMPRESS_SOURCE_SRGB && (detected_channels == Image::DETECTED_R || detected_channels == Image::DETECTED_RG)) { + //R and RG do not support SRGB + detected_channels = Image::DETECTED_RGB; + } + + if (p_source == Image::COMPRESS_SOURCE_NORMAL) { + //use RG channels only for normal + detected_channels = Image::DETECTED_RG; + } + + if (img_format >= Image::FORMAT_DXT1) { + return; //do not compress, already compressed + } + + if (img_format > Image::FORMAT_RGBA8) { + // TODO: we should be able to handle FORMAT_RGBA4444 and FORMAT_RGBA5551 eventually + return; + } + + int imgw = p_img->get_width(), imgh = p_img->get_height(); + ERR_FAIL_COND(nearest_power_of_2(imgw) != imgw || nearest_power_of_2(imgh) != imgh); + + Image::Format etc_format = force_etc1_format ? Image::FORMAT_ETC : _get_etc2_mode(detected_channels); + + Ref<Image> img = p_img->duplicate(); + + if (img->get_format() != Image::FORMAT_RGBA8) + img->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert + + PoolVector<uint8_t>::Read r = img->get_data().read(); + + int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps() ? -1 : 0); + int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0; + + PoolVector<uint8_t> dst_data; + dst_data.resize(target_size); + + PoolVector<uint8_t>::Write w = dst_data.write(); + + // prepare parameters to be passed to etc2comp + int num_cpus = OS::get_singleton()->get_processor_count(); + int encoding_time = 0; + float effort = 0.0; //default, reasonable time + + if (p_lossy_quality > 0.75) + effort = 0.4; + else if (p_lossy_quality > 0.85) + effort = 0.6; + else if (p_lossy_quality > 0.95) + effort = 0.8; + + Etc::ErrorMetric error_metric = Etc::ErrorMetric::RGBX; // NOTE: we can experiment with other error metrics + Etc::Image::Format etc2comp_etc_format = _image_format_to_etc2comp_format(etc_format); + + int wofs = 0; + for (int i = 0; i < mmc + 1; i++) { + // convert source image to internal etc2comp format (which is equivalent to Image::FORMAT_RGBAF) + // NOTE: We can alternatively add a case to Image::convert to handle Image::FORMAT_RGBAF conversion. + int mipmap_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0; + img->get_mipmap_offset_size_and_dimensions(i, mipmap_ofs, mipmap_size, mipmap_w, mipmap_h); + const uint8_t *src = &r[mipmap_ofs]; + + Etc::ColorFloatRGBA *src_rgba_f = new Etc::ColorFloatRGBA[mipmap_w * mipmap_h]; + for (int i = 0; i < mipmap_w * mipmap_h; i++) { + int si = i * 4; // RGBA8 + src_rgba_f[i] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]); + } + + unsigned char *etc_data = NULL; + unsigned int etc_data_len = 0; + unsigned int extended_width = 0, extended_height = 0; + Etc::Encode((float *)src_rgba_f, mipmap_w, mipmap_h, etc2comp_etc_format, error_metric, effort, num_cpus, num_cpus, &etc_data, &etc_data_len, &extended_width, &extended_height, &encoding_time); + + memcpy(&w[wofs], etc_data, etc_data_len); + wofs += etc_data_len; + + delete[] etc_data; + delete[] src_rgba_f; + } + + p_img->create(imgw, imgh, mmc > 1 ? true : false, etc_format, dst_data); +} + +static void _compress_etc1(Image *p_img, float p_lossy_quality) { + _compress_etc(p_img, p_lossy_quality, true, Image::COMPRESS_SOURCE_GENERIC); +} + +static void _compress_etc2(Image *p_img, float p_lossy_quality, Image::CompressSource p_source) { + _compress_etc(p_img, p_lossy_quality, false, p_source); +} + +void _register_etc_compress_func() { + + Image::_image_compress_etc1_func = _compress_etc1; + //Image::_image_decompress_etc1 = _decompress_etc1; + + Image::_image_compress_etc2_func = _compress_etc2; + //Image::_image_decompress_etc2 = _decompress_etc2; +} diff --git a/modules/etc1/image_etc.h b/modules/etc/image_etc.h index 69e082bb87..3cbadef6fa 100644 --- a/modules/etc1/image_etc.h +++ b/modules/etc/image_etc.h @@ -30,6 +30,6 @@ #ifndef IMAGE_ETC1_H #define IMAGE_ETC1_H -void _register_etc1_compress_func(); +void _register_etc_compress_func(); #endif // IMAGE_ETC_H diff --git a/modules/etc1/register_types.cpp b/modules/etc/register_types.cpp index 859486222f..e777859a8f 100644 --- a/modules/etc1/register_types.cpp +++ b/modules/etc/register_types.cpp @@ -34,15 +34,15 @@ static ResourceFormatPKM *resource_loader_pkm = NULL; -void register_etc1_types() { +void register_etc_types() { resource_loader_pkm = memnew(ResourceFormatPKM); ResourceLoader::add_resource_format_loader(resource_loader_pkm); - _register_etc1_compress_func(); + _register_etc_compress_func(); } -void unregister_etc1_types() { +void unregister_etc_types() { memdelete(resource_loader_pkm); } diff --git a/modules/etc1/register_types.h b/modules/etc/register_types.h index 0552b87d65..44399376f3 100644 --- a/modules/etc1/register_types.h +++ b/modules/etc/register_types.h @@ -27,5 +27,5 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -void register_etc1_types(); -void unregister_etc1_types(); +void register_etc_types(); +void unregister_etc_types(); diff --git a/modules/etc1/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp index 9817de3a0f..c04528d2a0 100644 --- a/modules/etc1/texture_loader_pkm.cpp +++ b/modules/etc/texture_loader_pkm.cpp @@ -85,7 +85,7 @@ RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, int width = h.origWidth; int height = h.origHeight; - Image img(width, height, mipmaps, Image::FORMAT_ETC, src_data); + Ref<Image> img = memnew(Image(width, height, mipmaps, Image::FORMAT_ETC, src_data)); Ref<ImageTexture> texture = memnew(ImageTexture); texture->create_from_image(img); diff --git a/modules/etc1/texture_loader_pkm.h b/modules/etc/texture_loader_pkm.h index 8a0f06a51a..8a0f06a51a 100644 --- a/modules/etc1/texture_loader_pkm.h +++ b/modules/etc/texture_loader_pkm.h diff --git a/modules/etc1/SCsub b/modules/etc1/SCsub deleted file mode 100644 index 0c5dc66d2e..0000000000 --- a/modules/etc1/SCsub +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python - -Import('env') -Import('env_modules') - -env_etc1 = env_modules.Clone() - -# Thirdparty source files -# Not unbundled so far since not widespread as shared library -thirdparty_dir = "#thirdparty/rg-etc1/" -thirdparty_sources = [ - "rg_etc1.cpp", -] -thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] - -env_etc1.add_source_files(env.modules_sources, thirdparty_sources) -env_etc1.Append(CPPPATH=[thirdparty_dir]) - -# Godot source files -env_etc1.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp deleted file mode 100644 index 60544594f6..0000000000 --- a/modules/etc1/image_etc.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/*************************************************************************/ -/* image_etc.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "image_etc.h" -#include "image.h" -#include "os/copymem.h" -#include "print_string.h" -#include "rg_etc1.h" -static void _decompress_etc(Image *p_img) { - - ERR_FAIL_COND(p_img->get_format() != Image::FORMAT_ETC); - - int imgw = p_img->get_width(); - int imgh = p_img->get_height(); - PoolVector<uint8_t> src = p_img->get_data(); - PoolVector<uint8_t> dst; - - PoolVector<uint8_t>::Read r = src.read(); - - int mmc = p_img->get_mipmap_count(); - - for (int i = 0; i <= mmc; i++) { - - dst.resize(dst.size() + imgw * imgh * 3); - const uint8_t *srcbr = &r[p_img->get_mipmap_offset(i)]; - PoolVector<uint8_t>::Write w = dst.write(); - - uint8_t *wptr = &w[dst.size() - imgw * imgh * 3]; - - int bw = MAX(imgw / 4, 1); - int bh = MAX(imgh / 4, 1); - - for (int y = 0; y < bh; y++) { - - for (int x = 0; x < bw; x++) { - - uint8_t block[4 * 4 * 4]; - - rg_etc1::unpack_etc1_block(srcbr, (unsigned int *)block); - srcbr += 8; - - int maxx = MIN(imgw, 4); - int maxy = MIN(imgh, 4); - - for (int yy = 0; yy < maxy; yy++) { - - for (int xx = 0; xx < maxx; xx++) { - - uint32_t src_ofs = (yy * 4 + xx) * 4; - uint32_t dst_ofs = ((y * 4 + yy) * imgw + x * 4 + xx) * 3; - wptr[dst_ofs + 0] = block[src_ofs + 0]; - wptr[dst_ofs + 1] = block[src_ofs + 1]; - wptr[dst_ofs + 2] = block[src_ofs + 2]; - } - } - } - } - - imgw = MAX(1, imgw / 2); - imgh = MAX(1, imgh / 2); - } - - r = PoolVector<uint8_t>::Read(); - //print_line("Re Creating ETC into regular image: w "+itos(p_img->get_width())+" h "+itos(p_img->get_height())+" mm "+itos(p_img->get_mipmaps())); - *p_img = Image(p_img->get_width(), p_img->get_height(), p_img->has_mipmaps(), Image::FORMAT_RGB8, dst); - if (p_img->has_mipmaps()) - p_img->generate_mipmaps(); -} - -static void _compress_etc(Image *p_img) { - - Image img = *p_img; - - int imgw = img.get_width(), imgh = img.get_height(); - - ERR_FAIL_COND(nearest_power_of_2(imgw) != imgw || nearest_power_of_2(imgh) != imgh); - - if (img.get_format() != Image::FORMAT_RGB8) - img.convert(Image::FORMAT_RGB8); - - PoolVector<uint8_t> res_data; - PoolVector<uint8_t> dst_data; - PoolVector<uint8_t>::Read r = img.get_data().read(); - - int target_size = Image::get_image_data_size(p_img->get_width(), p_img->get_height(), Image::FORMAT_ETC, p_img->has_mipmaps() ? -1 : 0); - int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(p_img->get_width(), p_img->get_height(), Image::FORMAT_ETC) : 0; - - dst_data.resize(target_size); - int mc = 0; - int ofs = 0; - PoolVector<uint8_t>::Write w = dst_data.write(); - - rg_etc1::etc1_pack_params pp; - pp.m_quality = rg_etc1::cLowQuality; - for (int i = 0; i <= mmc; i++) { - - int bw = MAX(imgw / 4, 1); - int bh = MAX(imgh / 4, 1); - const uint8_t *src = &r[img.get_mipmap_offset(i)]; - int mmsize = MAX(bw, 1) * MAX(bh, 1) * 8; - - uint8_t *dst = &w[ofs]; - ofs += mmsize; - - //print_line("bh: "+itos(bh)+" bw: "+itos(bw)); - - for (int y = 0; y < bh; y++) { - - for (int x = 0; x < bw; x++) { - - //print_line("x: "+itos(x)+" y: "+itos(y)); - - uint8_t block[4 * 4 * 4]; - zeromem(block, 4 * 4 * 4); - uint8_t cblock[8]; - - int maxy = MIN(imgh, 4); - int maxx = MIN(imgw, 4); - - for (int yy = 0; yy < maxy; yy++) { - - for (int xx = 0; xx < maxx; xx++) { - - uint32_t dst_ofs = (yy * 4 + xx) * 4; - uint32_t src_ofs = ((y * 4 + yy) * imgw + x * 4 + xx) * 3; - block[dst_ofs + 0] = src[src_ofs + 0]; - block[dst_ofs + 1] = src[src_ofs + 1]; - block[dst_ofs + 2] = src[src_ofs + 2]; - block[dst_ofs + 3] = 255; - } - } - - rg_etc1::pack_etc1_block(cblock, (const unsigned int *)block, pp); - for (int j = 0; j < 8; j++) { - - dst[j] = cblock[j]; - } - - dst += 8; - } - } - - imgw = MAX(1, imgw / 2); - imgh = MAX(1, imgh / 2); - mc++; - } - - *p_img = Image(p_img->get_width(), p_img->get_height(), (mc - 1) ? true : false, Image::FORMAT_ETC, dst_data); -} - -void _register_etc1_compress_func() { - - rg_etc1::pack_etc1_block_init(); - Image::_image_compress_etc_func = _compress_etc; - Image::_image_decompress_etc = _decompress_etc; -} diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index b543a486d3..706b81f7a3 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -99,15 +99,15 @@ Error NativeLibrary::terminate(NativeLibrary *&p_native_lib) { Error error = OK; void *library_terminate; error = OS::get_singleton()->get_dynamic_library_symbol_handle(p_native_lib->handle, GDNativeScriptLanguage::get_terminate_symbol_name(), library_terminate); - if (error) - return OK; // no terminate? okay, not that important lol + if (!error) { - void (*library_terminate_pointer)(godot_native_terminate_options *) = (void (*)(godot_native_terminate_options *))library_terminate; + void (*library_terminate_pointer)(godot_native_terminate_options *) = (void (*)(godot_native_terminate_options *))library_terminate; - godot_native_terminate_options options; - options.in_editor = SceneTree::get_singleton()->is_editor_hint(); + godot_native_terminate_options options; + options.in_editor = SceneTree::get_singleton()->is_editor_hint(); - library_terminate_pointer(&options); + library_terminate_pointer(&options); + } GDNativeScriptLanguage::get_singleton()->initialized_libraries.erase(p_native_lib->path); @@ -391,6 +391,54 @@ void GDNativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { } } +Variant GDNativeScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { + + /* STEP 1, CREATE */ + + if (!library.is_valid() || ((String)script_name).empty() || !script_data) { + r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; + return Variant(); + } + + r_error.error = Variant::CallError::CALL_OK; + REF ref; + Object *owner = NULL; + + GDNativeScriptData *_baseptr = script_data; + while (_baseptr->base_data) { + _baseptr = _baseptr->base_data; + } + + if (!(_baseptr->base_native_type == "")) { + owner = ClassDB::instance(_baseptr->base_native_type); + } else { + owner = memnew(Reference); //by default, no base means use reference + } + + Reference *r = owner->cast_to<Reference>(); + if (r) { + ref = REF(r); + } + + // GDScript does it like this: _create_instance(p_args, p_argcount, owner, r != NULL, r_error); + // @Todo support varargs for constructors. + GDNativeInstance *instance = (GDNativeInstance *)instance_create(owner); + + owner->set_script_instance(instance); + if (!instance) { + if (ref.is_null()) { + memdelete(owner); //no owner, sorry + } + return Variant(); + } + + if (ref.is_valid()) { + return ref; + } else { + return owner; + } +} + Ref<GDNativeLibrary> GDNativeScript::get_library() const { return library; } @@ -438,6 +486,8 @@ void GDNativeScript::_bind_methods() { ClassDB::bind_method(D_METHOD("get_script_name"), &GDNativeScript::get_script_name); ClassDB::bind_method(D_METHOD("set_script_name", "script_name"), &GDNativeScript::set_script_name); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDNativeScript::_new, MethodInfo(Variant::OBJECT, "new")); + ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library"); ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "script_name"), "set_script_name", "get_script_name"); } @@ -465,11 +515,10 @@ static const char *_dl_platforms_info[] = { "unix|x11|so|X11", "unix|server|so|Server", "unix|android|so|Android", - "unix|blackberry|so|Blackberry 10", "unix|haiku|so|Haiku", // Right? - "|mac|dynlib|Mac", - "mac|ios|dynlib|iOS", - "mac|osx|dynlib|OSX", + "|mac|dylib|Mac", + "mac|ios|dylib|iOS", + "mac|osx|dylib|OSX", "|html5|js|HTML5", "|windows|dll|Windows", "windows|uwp|dll|UWP", @@ -565,7 +614,6 @@ Error GDNativeLibrary::_terminate() { } Error ret = NativeLibrary::terminate(native_library); - native_library->scripts.clear(); return ret; @@ -1168,6 +1216,7 @@ void GDNativeReloadNode::_notification(int p_what) { Set<GDNativeScript *> scripts; for (Set<GDNativeScript *>::Element *S = GDNativeScriptLanguage::get_singleton()->script_list.front(); S; S = S->next()) { + if (lib->native_library->scripts.has(S->get()->get_script_name())) { GDNativeScript *script = S->get(); script->script_data = lib->get_script_data(script->get_script_name()); diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index 89270b4e26..6716b684a0 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -40,7 +40,7 @@ #include "godot.h" -class GDNativeScriptData; +struct GDNativeScriptData; class GDNativeLibrary; struct NativeLibrary { @@ -127,8 +127,6 @@ struct GDNativeScriptData { } }; -class GDNativeLibrary; - class GDNativeScript : public Script { GDCLASS(GDNativeScript, Script); @@ -184,6 +182,8 @@ public: virtual void get_script_method_list(List<MethodInfo> *p_list) const; virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error); + Ref<GDNativeLibrary> get_library() const; void set_library(Ref<GDNativeLibrary> p_library); @@ -206,7 +206,7 @@ class GDNativeLibrary : public Resource { protected: friend class GDNativeScript; - friend class NativeLibrary; + friend struct NativeLibrary; friend class GDNativeReloadNode; GDNativeScriptData *get_script_data(const StringName p_name); diff --git a/modules/gdnative/godot.cpp b/modules/gdnative/godot.cpp index 7477a28db6..4dbb72bba1 100644 --- a/modules/gdnative/godot.cpp +++ b/modules/gdnative/godot.cpp @@ -30,6 +30,7 @@ #include "godot.h" #include "class_db.h" +#include "error_macros.h" #include "gdnative.h" #include "global_config.h" #include "global_constants.h" @@ -50,10 +51,8 @@ extern "C" void _basis_api_anchor(); extern "C" void _rect3_api_anchor(); extern "C" void _transform_api_anchor(); extern "C" void _color_api_anchor(); -extern "C" void _image_api_anchor(); extern "C" void _node_path_api_anchor(); extern "C" void _rid_api_anchor(); -extern "C" void _input_event_api_anchor(); extern "C" void _dictionary_api_anchor(); extern "C" void _array_api_anchor(); extern "C" void _pool_arrays_api_anchor(); @@ -72,10 +71,8 @@ void _api_anchor() { _basis_api_anchor(); _transform_api_anchor(); _color_api_anchor(); - _image_api_anchor(); _node_path_api_anchor(); _rid_api_anchor(); - _input_event_api_anchor(); _dictionary_api_anchor(); _array_api_anchor(); _pool_arrays_api_anchor(); @@ -115,6 +112,28 @@ void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_obj mb->ptrcall(o, p_args, p_ret); } +godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error) { + MethodBind *mb = (MethodBind *)p_method_bind; + Object *o = (Object *)p_instance; + const Variant **args = (const Variant **)p_args; + + godot_variant ret; + godot_variant_new_nil(&ret); + + Variant *ret_val = (Variant *)&ret; + + Variant::CallError r_error; + *ret_val = mb->call(o, args, p_arg_count, r_error); + + if (p_call_error) { + p_call_error->error = (godot_variant_call_error_error)r_error.error; + p_call_error->argument = r_error.argument; + p_call_error->expected = (godot_variant_type)r_error.expected; + } + + return ret; +} + // @Todo /* void GDAPI godot_method_bind_varcall(godot_method_bind *p_method_bind) @@ -215,6 +234,18 @@ void GDAPI godot_free(void *p_ptr) { memfree(p_ptr); } +void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line) { + _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_ERROR); +} + +void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line) { + _err_print_error(p_function, p_file, p_line, p_description, ERR_HANDLER_WARNING); +} + +void GDAPI godot_print(const godot_string *p_message) { + print_line(*(String *)p_message); +} + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/godot.h b/modules/gdnative/godot.h index 0d7aece23b..1d86998291 100644 --- a/modules/gdnative/godot.h +++ b/modules/gdnative/godot.h @@ -38,12 +38,33 @@ extern "C" { #define GDAPI_EXPORT #endif -#if !defined(_WIN32) && !defined(_MSC_VER) +#ifdef _WIN32 +#if defined(GDAPI_EXPORT) +#define GDCALLINGCONV +#define GDAPI __declspec(dllexport) GDCALLINGCONV +#else +#define GDCALLINGCONV +#define GDAPI __declspec(dllimport) GDCALLINGCONV +#endif +#elif defined(__APPLE__) +#include "TargetConditionals.h" +#if TARGET_OS_IPHONE +#define GDCALLINGCONV #define GDAPI -#elif defined(GDAPI_EXPORT) -#define GDAPI __declspec(dllexport) +#elif TARGET_OS_MAC +#define GDCALLINGCONV __attribute__((sysv_abi)) +#define GDAPI GDCALLINGCONV +#endif #else -#define GDAPI __declspec(dllimport) +#define GDCALLINGCONV __attribute__((sysv_abi)) +#define GDAPI GDCALLINGCONV +#endif + +// This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!! +#ifdef _WIN32 +#define GDN_EXPORT __declspec(dllexport) +#else +#define GDN_EXPORT #endif #include <stdbool.h> @@ -125,6 +146,31 @@ typedef float godot_real; /////// Object (forward declared) typedef void godot_object; +/////// Brute force forward declarations for the rest +typedef struct godot_variant godot_variant; +typedef struct godot_string godot_string; +typedef struct godot_vector2 godot_vector2; +typedef struct godot_rect2 godot_rect2; +typedef struct godot_vector3 godot_vector3; +typedef struct godot_transform2d godot_transform2d; +typedef struct godot_plane godot_plane; +typedef struct godot_quat godot_quat; +typedef struct godot_rect3 godot_rect3; +typedef struct godot_basis godot_basis; +typedef struct godot_transform godot_transform; +typedef struct godot_color godot_color; +typedef struct godot_node_path godot_node_path; +typedef struct godot_rid godot_rid; +typedef struct godot_dictionary godot_dictionary; +typedef struct godot_array godot_array; +typedef struct godot_pool_byte_array godot_pool_byte_array; +typedef struct godot_pool_int_array godot_pool_int_array; +typedef struct godot_pool_real_array godot_pool_real_array; +typedef struct godot_pool_string_array godot_pool_string_array; +typedef struct godot_pool_vector2_array godot_pool_vector2_array; +typedef struct godot_pool_vector3_array godot_pool_vector3_array; +typedef struct godot_pool_color_array godot_pool_color_array; + /////// String #include "godot/godot_string.h" @@ -169,10 +215,6 @@ typedef void godot_object; #include "godot/godot_color.h" -/////// Image - -#include "godot/godot_image.h" - /////// NodePath #include "godot/godot_node_path.h" @@ -181,10 +223,6 @@ typedef void godot_object; #include "godot/godot_rid.h" -/////// InputEvent - -#include "godot/godot_input_event.h" - /////// Dictionary #include "godot/godot_dictionary.h" @@ -214,7 +252,7 @@ typedef struct godot_method_bind { godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname); void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret); - +godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error); ////// Script API typedef struct godot_native_init_options { @@ -314,16 +352,16 @@ typedef struct godot_property_attributes { typedef struct godot_instance_create_func { // instance pointer, method_data - return user data - void *(*create_func)(godot_object *, void *); + GDCALLINGCONV void *(*create_func)(godot_object *, void *); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_instance_create_func; typedef struct godot_instance_destroy_func { // instance pointer, method data, user data - void (*destroy_func)(godot_object *, void *, void *); + GDCALLINGCONV void (*destroy_func)(godot_object *, void *, void *); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_instance_destroy_func; void GDAPI godot_script_register_class(const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func); @@ -332,25 +370,25 @@ void GDAPI godot_script_register_tool_class(const char *p_name, const char *p_ba typedef struct godot_instance_method { // instance pointer, method data, user data, num args, args - return result as varaint - godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **); + GDCALLINGCONV godot_variant (*method)(godot_object *, void *, void *, int, godot_variant **); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_instance_method; void GDAPI godot_script_register_method(const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method); typedef struct godot_property_set_func { // instance pointer, method data, user data, value - void (*set_func)(godot_object *, void *, void *, godot_variant); + GDCALLINGCONV void (*set_func)(godot_object *, void *, void *, godot_variant); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_property_set_func; typedef struct godot_property_get_func { // instance pointer, method data, user data, value - godot_variant (*get_func)(godot_object *, void *, void *); + GDCALLINGCONV godot_variant (*get_func)(godot_object *, void *, void *); void *method_data; - void (*free_func)(void *); + GDCALLINGCONV void (*free_func)(void *); } godot_property_get_func; void GDAPI godot_script_register_property(const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func); @@ -376,6 +414,7 @@ void GDAPI godot_script_register_signal(const char *p_name, const godot_signal * void GDAPI *godot_native_get_userdata(godot_object *p_instance); +// Calling convention? typedef godot_object *(*godot_class_constructor)(); godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname); @@ -389,6 +428,11 @@ void GDAPI *godot_alloc(int p_bytes); void GDAPI *godot_realloc(void *p_ptr, int p_bytes); void GDAPI godot_free(void *p_ptr); +//print using Godot's error handler list +void GDAPI godot_print_error(const char *p_description, const char *p_function, const char *p_file, int p_line); +void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line); +void GDAPI godot_print(const godot_string *p_message); + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/godot/godot_array.cpp b/modules/gdnative/godot/godot_array.cpp index 6c55c5d048..5497dde520 100644 --- a/modules/gdnative/godot/godot_array.cpp +++ b/modules/gdnative/godot/godot_array.cpp @@ -44,255 +44,264 @@ extern "C" { void _array_api_anchor() { } -void GDAPI godot_array_new(godot_array *p_arr) { - Array *a = (Array *)p_arr; - memnew_placement(a, Array); +void GDAPI godot_array_new(godot_array *r_dest) { + Array *dest = (Array *)r_dest; + memnew_placement(dest, Array); } -void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca) { - Array *a = (Array *)p_arr; +void GDAPI godot_array_new_copy(godot_array *r_dest, const godot_array *p_src) { + Array *dest = (Array *)r_dest; + const Array *src = (const Array *)p_src; + memnew_placement(dest, Array(*src)); +} + +void GDAPI godot_array_new_pool_color_array(godot_array *r_dest, const godot_pool_color_array *p_pca) { + Array *dest = (Array *)r_dest; PoolVector<Color> *pca = (PoolVector<Color> *)p_pca; - memnew_placement(a, Array); - a->resize(pca->size()); + memnew_placement(dest, Array); + dest->resize(pca->size()); - for (size_t i = 0; i < a->size(); i++) { + for (size_t i = 0; i < dest->size(); i++) { Variant v = pca->operator[](i); - a->operator[](i) = v; + dest->operator[](i) = v; } } -void GDAPI godot_array_new_pool_vector3_array(godot_array *p_arr, const godot_pool_vector3_array *p_pv3a) { - Array *a = (Array *)p_arr; +void GDAPI godot_array_new_pool_vector3_array(godot_array *r_dest, const godot_pool_vector3_array *p_pv3a) { + Array *dest = (Array *)r_dest; PoolVector<Vector3> *pca = (PoolVector<Vector3> *)p_pv3a; - memnew_placement(a, Array); - a->resize(pca->size()); + memnew_placement(dest, Array); + dest->resize(pca->size()); - for (size_t i = 0; i < a->size(); i++) { + for (size_t i = 0; i < dest->size(); i++) { Variant v = pca->operator[](i); - a->operator[](i) = v; + dest->operator[](i) = v; } } -void GDAPI godot_array_new_pool_vector2_array(godot_array *p_arr, const godot_pool_vector2_array *p_pv2a) { - Array *a = (Array *)p_arr; +void GDAPI godot_array_new_pool_vector2_array(godot_array *r_dest, const godot_pool_vector2_array *p_pv2a) { + Array *dest = (Array *)r_dest; PoolVector<Vector2> *pca = (PoolVector<Vector2> *)p_pv2a; - memnew_placement(a, Array); - a->resize(pca->size()); + memnew_placement(dest, Array); + dest->resize(pca->size()); - for (size_t i = 0; i < a->size(); i++) { + for (size_t i = 0; i < dest->size(); i++) { Variant v = pca->operator[](i); - a->operator[](i) = v; + dest->operator[](i) = v; } } -void GDAPI godot_array_new_pool_string_array(godot_array *p_arr, const godot_pool_string_array *p_psa) { - Array *a = (Array *)p_arr; +void GDAPI godot_array_new_pool_string_array(godot_array *r_dest, const godot_pool_string_array *p_psa) { + Array *dest = (Array *)r_dest; PoolVector<String> *pca = (PoolVector<String> *)p_psa; - memnew_placement(a, Array); - a->resize(pca->size()); + memnew_placement(dest, Array); + dest->resize(pca->size()); - for (size_t i = 0; i < a->size(); i++) { + for (size_t i = 0; i < dest->size(); i++) { Variant v = pca->operator[](i); - a->operator[](i) = v; + dest->operator[](i) = v; } } -void GDAPI godot_array_new_pool_real_array(godot_array *p_arr, const godot_pool_real_array *p_pra) { - Array *a = (Array *)p_arr; +void GDAPI godot_array_new_pool_real_array(godot_array *r_dest, const godot_pool_real_array *p_pra) { + Array *dest = (Array *)r_dest; PoolVector<godot_real> *pca = (PoolVector<godot_real> *)p_pra; - memnew_placement(a, Array); - a->resize(pca->size()); + memnew_placement(dest, Array); + dest->resize(pca->size()); - for (size_t i = 0; i < a->size(); i++) { + for (size_t i = 0; i < dest->size(); i++) { Variant v = pca->operator[](i); - a->operator[](i) = v; + dest->operator[](i) = v; } } -void GDAPI godot_array_new_pool_int_array(godot_array *p_arr, const godot_pool_int_array *p_pia) { - Array *a = (Array *)p_arr; +void GDAPI godot_array_new_pool_int_array(godot_array *r_dest, const godot_pool_int_array *p_pia) { + Array *dest = (Array *)r_dest; PoolVector<godot_int> *pca = (PoolVector<godot_int> *)p_pia; - memnew_placement(a, Array); - a->resize(pca->size()); + memnew_placement(dest, Array); + dest->resize(pca->size()); - for (size_t i = 0; i < a->size(); i++) { + for (size_t i = 0; i < dest->size(); i++) { Variant v = pca->operator[](i); - a->operator[](i) = v; + dest->operator[](i) = v; } } -void GDAPI godot_array_new_pool_byte_array(godot_array *p_arr, const godot_pool_byte_array *p_pba) { - Array *a = (Array *)p_arr; +void GDAPI godot_array_new_pool_byte_array(godot_array *r_dest, const godot_pool_byte_array *p_pba) { + Array *dest = (Array *)r_dest; PoolVector<uint8_t> *pca = (PoolVector<uint8_t> *)p_pba; - memnew_placement(a, Array); - a->resize(pca->size()); + memnew_placement(dest, Array); + dest->resize(pca->size()); - for (size_t i = 0; i < a->size(); i++) { + for (size_t i = 0; i < dest->size(); i++) { Variant v = pca->operator[](i); - a->operator[](i) = v; + dest->operator[](i) = v; } } -void GDAPI godot_array_set(godot_array *p_arr, const godot_int p_idx, const godot_variant *p_value) { - Array *a = (Array *)p_arr; +void GDAPI godot_array_set(godot_array *p_self, const godot_int p_idx, const godot_variant *p_value) { + Array *self = (Array *)p_self; Variant *val = (Variant *)p_value; - a->operator[](p_idx) = *val; + self->operator[](p_idx) = *val; +} + +godot_variant GDAPI godot_array_get(const godot_array *p_self, const godot_int p_idx) { + godot_variant raw_dest; + Variant *dest = (Variant *)&raw_dest; + const Array *self = (const Array *)p_self; + memnew_placement(dest, Variant(self->operator[](p_idx))); + return raw_dest; } -godot_variant GDAPI *godot_array_get(godot_array *p_arr, const godot_int p_idx) { - Array *a = (Array *)p_arr; - return (godot_variant *)&a->operator[](p_idx); +godot_variant GDAPI *godot_array_operator_index(godot_array *p_self, const godot_int p_idx) { + Array *self = (Array *)p_self; + return (godot_variant *)&self->operator[](p_idx); } -void GDAPI godot_array_append(godot_array *p_arr, const godot_variant *p_value) { - Array *a = (Array *)p_arr; +void GDAPI godot_array_append(godot_array *p_self, const godot_variant *p_value) { + Array *self = (Array *)p_self; Variant *val = (Variant *)p_value; - a->append(*val); + self->append(*val); } -void GDAPI godot_array_clear(godot_array *p_arr) { - Array *a = (Array *)p_arr; - a->clear(); +void GDAPI godot_array_clear(godot_array *p_self) { + Array *self = (Array *)p_self; + self->clear(); } -godot_int GDAPI godot_array_count(godot_array *p_arr, const godot_variant *p_value) { - Array *a = (Array *)p_arr; - Variant *val = (Variant *)p_value; - return a->count(*val); +godot_int GDAPI godot_array_count(const godot_array *p_self, const godot_variant *p_value) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_value; + return self->count(*val); } -godot_bool GDAPI godot_array_empty(const godot_array *p_arr) { - Array *a = (Array *)p_arr; - return a->empty(); +godot_bool GDAPI godot_array_empty(const godot_array *p_self) { + const Array *self = (const Array *)p_self; + return self->empty(); } -void GDAPI godot_array_erase(godot_array *p_arr, const godot_variant *p_value) { - Array *a = (Array *)p_arr; - Variant *val = (Variant *)p_value; - a->erase(*val); +void GDAPI godot_array_erase(godot_array *p_self, const godot_variant *p_value) { + Array *self = (Array *)p_self; + const Variant *val = (const Variant *)p_value; + self->erase(*val); } -godot_variant GDAPI godot_array_front(const godot_array *p_arr) { - Array *a = (Array *)p_arr; +godot_variant GDAPI godot_array_front(const godot_array *p_self) { + const Array *self = (const Array *)p_self; godot_variant v; Variant *val = (Variant *)&v; memnew_placement(val, Variant); - *val = a->front(); + *val = self->front(); return v; } -godot_variant GDAPI godot_array_back(const godot_array *p_arr) { - Array *a = (Array *)p_arr; +godot_variant GDAPI godot_array_back(const godot_array *p_self) { + const Array *self = (const Array *)p_self; godot_variant v; Variant *val = (Variant *)&v; memnew_placement(val, Variant); - *val = a->back(); + *val = self->back(); return v; } -godot_int GDAPI godot_array_find(const godot_array *p_arr, const godot_variant *p_what, const godot_int p_from) { - Array *a = (Array *)p_arr; - Variant *val = (Variant *)p_what; - return a->find(*val, p_from); +godot_int GDAPI godot_array_find(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_what; + return self->find(*val, p_from); } -godot_int GDAPI godot_array_find_last(const godot_array *p_arr, const godot_variant *p_what) { - Array *a = (Array *)p_arr; - Variant *val = (Variant *)p_what; - return a->find_last(*val); +godot_int GDAPI godot_array_find_last(const godot_array *p_self, const godot_variant *p_what) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_what; + return self->find_last(*val); } -godot_bool GDAPI godot_array_has(const godot_array *p_arr, const godot_variant *p_value) { - Array *a = (Array *)p_arr; - Variant *val = (Variant *)p_value; - return a->has(*val); -} - -uint32_t GDAPI godot_array_hash(const godot_array *p_arr) { - Array *a = (Array *)p_arr; - return a->hash(); +godot_bool GDAPI godot_array_has(const godot_array *p_self, const godot_variant *p_value) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_value; + return self->has(*val); } -void GDAPI godot_array_insert(godot_array *p_arr, const godot_int p_pos, const godot_variant *p_value) { - Array *a = (Array *)p_arr; - Variant *val = (Variant *)p_value; - a->insert(p_pos, *val); +godot_int GDAPI godot_array_hash(const godot_array *p_self) { + const Array *self = (const Array *)p_self; + return self->hash(); } -void GDAPI godot_array_invert(godot_array *p_arr) { - Array *a = (Array *)p_arr; - a->invert(); +void GDAPI godot_array_insert(godot_array *p_self, const godot_int p_pos, const godot_variant *p_value) { + Array *self = (Array *)p_self; + const Variant *val = (const Variant *)p_value; + self->insert(p_pos, *val); } -godot_bool GDAPI godot_array_is_shared(const godot_array *p_arr) { - Array *a = (Array *)p_arr; - return false; // @Todo how do I do it? +void GDAPI godot_array_invert(godot_array *p_self) { + Array *self = (Array *)p_self; + self->invert(); } -godot_variant GDAPI godot_array_pop_back(godot_array *p_arr) { - Array *a = (Array *)p_arr; +godot_variant GDAPI godot_array_pop_back(godot_array *p_self) { + Array *self = (Array *)p_self; godot_variant v; Variant *val = (Variant *)&v; memnew_placement(val, Variant); - *val = a->pop_back(); + *val = self->pop_back(); return v; } -godot_variant GDAPI godot_array_pop_front(godot_array *p_arr) { - Array *a = (Array *)p_arr; +godot_variant GDAPI godot_array_pop_front(godot_array *p_self) { + Array *self = (Array *)p_self; godot_variant v; Variant *val = (Variant *)&v; memnew_placement(val, Variant); - *val = a->pop_front(); + *val = self->pop_front(); return v; } -void GDAPI godot_array_push_back(godot_array *p_arr, const godot_variant *p_value) { - Array *a = (Array *)p_arr; - Variant *val = (Variant *)p_value; - a->push_back(*val); +void GDAPI godot_array_push_back(godot_array *p_self, const godot_variant *p_value) { + Array *self = (Array *)p_self; + const Variant *val = (const Variant *)p_value; + self->push_back(*val); } -void GDAPI godot_array_push_front(godot_array *p_arr, const godot_variant *p_value) { - Array *a = (Array *)p_arr; - Variant *val = (Variant *)p_value; - a->push_front(*val); +void GDAPI godot_array_push_front(godot_array *p_self, const godot_variant *p_value) { + Array *self = (Array *)p_self; + const Variant *val = (const Variant *)p_value; + self->push_front(*val); } -void GDAPI godot_array_remove(godot_array *p_arr, const godot_int p_idx) { - Array *a = (Array *)p_arr; - a->remove(p_idx); +void GDAPI godot_array_remove(godot_array *p_self, const godot_int p_idx) { + Array *self = (Array *)p_self; + self->remove(p_idx); } -void GDAPI godot_array_resize(godot_array *p_arr, const godot_int p_size) { - Array *a = (Array *)p_arr; - a->resize(p_size); +void GDAPI godot_array_resize(godot_array *p_self, const godot_int p_size) { + Array *self = (Array *)p_self; + self->resize(p_size); } -godot_int GDAPI godot_array_rfind(const godot_array *p_arr, const godot_variant *p_what, const godot_int p_from) { - Array *a = (Array *)p_arr; - Variant *val = (Variant *)p_what; - return a->rfind(*val, p_from); +godot_int GDAPI godot_array_rfind(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from) { + const Array *self = (const Array *)p_self; + const Variant *val = (const Variant *)p_what; + return self->rfind(*val, p_from); } -godot_int GDAPI godot_array_size(const godot_array *p_arr) { - Array *a = (Array *)p_arr; - return a->size(); +godot_int GDAPI godot_array_size(const godot_array *p_self) { + const Array *self = (const Array *)p_self; + return self->size(); } -void GDAPI godot_array_sort(godot_array *p_arr) { - Array *a = (Array *)p_arr; - a->sort(); +void GDAPI godot_array_sort(godot_array *p_self) { + Array *self = (Array *)p_self; + self->sort(); } -void GDAPI godot_array_sort_custom(godot_array *p_arr, godot_object *p_obj, const godot_string *p_func) { - Array *a = (Array *)p_arr; - String *func = (String *)p_func; - a->sort_custom((Object *)p_obj, *func); +void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func) { + Array *self = (Array *)p_self; + const String *func = (const String *)p_func; + self->sort_custom((Object *)p_obj, *func); } -void GDAPI godot_array_destroy(godot_array *p_arr) { - ((Array *)p_arr)->~Array(); +void GDAPI godot_array_destroy(godot_array *p_self) { + ((Array *)p_self)->~Array(); } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_array.h b/modules/gdnative/godot/godot_array.h index b92ebb834f..bf8bc61977 100644 --- a/modules/gdnative/godot/godot_array.h +++ b/modules/gdnative/godot/godot_array.h @@ -43,73 +43,74 @@ typedef struct godot_array { } godot_array; #endif -#include "../godot.h" - #include "godot_pool_arrays.h" #include "godot_variant.h" -void GDAPI godot_array_new(godot_array *p_arr); -void GDAPI godot_array_new_pool_color_array(godot_array *p_arr, const godot_pool_color_array *p_pca); -void GDAPI godot_array_new_pool_vector3_array(godot_array *p_arr, const godot_pool_vector3_array *p_pv3a); -void GDAPI godot_array_new_pool_vector2_array(godot_array *p_arr, const godot_pool_vector2_array *p_pv2a); -void GDAPI godot_array_new_pool_string_array(godot_array *p_arr, const godot_pool_string_array *p_psa); -void GDAPI godot_array_new_pool_real_array(godot_array *p_arr, const godot_pool_real_array *p_pra); -void GDAPI godot_array_new_pool_int_array(godot_array *p_arr, const godot_pool_int_array *p_pia); -void GDAPI godot_array_new_pool_byte_array(godot_array *p_arr, const godot_pool_byte_array *p_pba); +#include "../godot.h" + +void GDAPI godot_array_new(godot_array *r_dest); +void GDAPI godot_array_new_copy(godot_array *r_dest, const godot_array *p_src); +void GDAPI godot_array_new_pool_color_array(godot_array *r_dest, const godot_pool_color_array *p_pca); +void GDAPI godot_array_new_pool_vector3_array(godot_array *r_dest, const godot_pool_vector3_array *p_pv3a); +void GDAPI godot_array_new_pool_vector2_array(godot_array *r_dest, const godot_pool_vector2_array *p_pv2a); +void GDAPI godot_array_new_pool_string_array(godot_array *r_dest, const godot_pool_string_array *p_psa); +void GDAPI godot_array_new_pool_real_array(godot_array *r_dest, const godot_pool_real_array *p_pra); +void GDAPI godot_array_new_pool_int_array(godot_array *r_dest, const godot_pool_int_array *p_pia); +void GDAPI godot_array_new_pool_byte_array(godot_array *r_dest, const godot_pool_byte_array *p_pba); -void GDAPI godot_array_set(godot_array *p_arr, const godot_int p_idx, const godot_variant *p_value); +void GDAPI godot_array_set(godot_array *p_self, const godot_int p_idx, const godot_variant *p_value); -godot_variant GDAPI *godot_array_get(godot_array *p_arr, const godot_int p_idx); +godot_variant GDAPI godot_array_get(const godot_array *p_self, const godot_int p_idx); -void GDAPI godot_array_append(godot_array *p_arr, const godot_variant *p_value); +godot_variant GDAPI *godot_array_operator_index(godot_array *p_self, const godot_int p_idx); -void GDAPI godot_array_clear(godot_array *p_arr); +void GDAPI godot_array_append(godot_array *p_self, const godot_variant *p_value); -godot_int GDAPI godot_array_count(godot_array *p_arr, const godot_variant *p_value); +void GDAPI godot_array_clear(godot_array *p_self); -godot_bool GDAPI godot_array_empty(const godot_array *p_arr); +godot_int GDAPI godot_array_count(const godot_array *p_self, const godot_variant *p_value); -void GDAPI godot_array_erase(godot_array *p_arr, const godot_variant *p_value); +godot_bool GDAPI godot_array_empty(const godot_array *p_self); -godot_variant GDAPI godot_array_front(const godot_array *p_arr); +void GDAPI godot_array_erase(godot_array *p_self, const godot_variant *p_value); -godot_variant GDAPI godot_array_back(const godot_array *p_arr); +godot_variant GDAPI godot_array_front(const godot_array *p_self); -godot_int GDAPI godot_array_find(const godot_array *p_arr, const godot_variant *p_what, const godot_int p_from); +godot_variant GDAPI godot_array_back(const godot_array *p_self); -godot_int GDAPI godot_array_find_last(const godot_array *p_arr, const godot_variant *p_what); +godot_int GDAPI godot_array_find(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from); -godot_bool GDAPI godot_array_has(const godot_array *p_arr, const godot_variant *p_value); +godot_int GDAPI godot_array_find_last(const godot_array *p_self, const godot_variant *p_what); -uint32_t GDAPI godot_array_hash(const godot_array *p_arr); +godot_bool GDAPI godot_array_has(const godot_array *p_self, const godot_variant *p_value); -void GDAPI godot_array_insert(godot_array *p_arr, const godot_int p_pos, const godot_variant *p_value); +godot_int GDAPI godot_array_hash(const godot_array *p_self); -void GDAPI godot_array_invert(godot_array *p_arr); +void GDAPI godot_array_insert(godot_array *p_self, const godot_int p_pos, const godot_variant *p_value); -godot_bool GDAPI godot_array_is_shared(const godot_array *p_arr); +void GDAPI godot_array_invert(godot_array *p_self); -godot_variant GDAPI godot_array_pop_back(godot_array *p_arr); +godot_variant GDAPI godot_array_pop_back(godot_array *p_self); -godot_variant GDAPI godot_array_pop_front(godot_array *p_arr); +godot_variant GDAPI godot_array_pop_front(godot_array *p_self); -void GDAPI godot_array_push_back(godot_array *p_arr, const godot_variant *p_value); +void GDAPI godot_array_push_back(godot_array *p_self, const godot_variant *p_value); -void GDAPI godot_array_push_front(godot_array *p_arr, const godot_variant *p_value); +void GDAPI godot_array_push_front(godot_array *p_self, const godot_variant *p_value); -void GDAPI godot_array_remove(godot_array *p_arr, const godot_int p_idx); +void GDAPI godot_array_remove(godot_array *p_self, const godot_int p_idx); -void GDAPI godot_array_resize(godot_array *p_arr, const godot_int p_size); +void GDAPI godot_array_resize(godot_array *p_self, const godot_int p_size); -godot_int GDAPI godot_array_rfind(const godot_array *p_arr, const godot_variant *p_what, const godot_int p_from); +godot_int GDAPI godot_array_rfind(const godot_array *p_self, const godot_variant *p_what, const godot_int p_from); -godot_int GDAPI godot_array_size(const godot_array *p_arr); +godot_int GDAPI godot_array_size(const godot_array *p_self); -void GDAPI godot_array_sort(godot_array *p_arr); +void GDAPI godot_array_sort(godot_array *p_self); -void GDAPI godot_array_sort_custom(godot_array *p_arr, godot_object *p_obj, const godot_string *p_func); +void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func); -void GDAPI godot_array_destroy(godot_array *p_arr); +void GDAPI godot_array_destroy(godot_array *p_self); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_basis.cpp b/modules/gdnative/godot/godot_basis.cpp index 4322acc401..46464932c5 100644 --- a/modules/gdnative/godot/godot_basis.cpp +++ b/modules/gdnative/godot/godot_basis.cpp @@ -28,58 +28,243 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_basis.h" +#include "core/variant.h" -#include "math/matrix3.h" +#include "core/math/matrix3.h" #ifdef __cplusplus extern "C" { #endif -void _basis_api_anchor() { +void _basis_api_anchor() {} + +void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis) { + const Vector3 *x_axis = (const Vector3 *)p_x_axis; + const Vector3 *y_axis = (const Vector3 *)p_y_axis; + const Vector3 *z_axis = (const Vector3 *)p_z_axis; + Basis *dest = (Basis *)r_dest; + *dest = Basis(*x_axis, *y_axis, *z_axis); +} + +void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *r_dest, const godot_vector3 *p_axis, const godot_real p_phi) { + const Vector3 *axis = (const Vector3 *)p_axis; + Basis *dest = (Basis *)r_dest; + *dest = Basis(*axis, p_phi); +} + +void GDAPI godot_basis_new_with_euler(godot_basis *r_dest, const godot_vector3 *p_euler) { + const Vector3 *euler = (const Vector3 *)p_euler; + Basis *dest = (Basis *)r_dest; + *dest = Basis(*euler); +} + +godot_string GDAPI godot_basis_as_string(const godot_basis *p_self) { + godot_string ret; + const Basis *self = (const Basis *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_basis GDAPI godot_basis_inverse(const godot_basis *p_self) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + *((Basis *)&dest) = self->inverse(); + return dest; +} + +godot_basis GDAPI godot_basis_transposed(const godot_basis *p_self) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + *((Basis *)&dest) = self->transposed(); + return dest; +} + +godot_basis GDAPI godot_basis_orthonormalized(const godot_basis *p_self) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + *((Basis *)&dest) = self->orthonormalized(); + return dest; +} + +godot_real GDAPI godot_basis_determinant(const godot_basis *p_self) { + const Basis *self = (const Basis *)p_self; + return self->determinant(); +} + +godot_basis GDAPI godot_basis_rotated(const godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_phi) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + *((Basis *)&dest) = self->rotated(*axis, p_phi); + return dest; +} + +godot_basis GDAPI godot_basis_scaled(const godot_basis *p_self, const godot_vector3 *p_scale) { + godot_basis dest; + const Basis *self = (const Basis *)p_self; + const Vector3 *scale = (const Vector3 *)p_scale; + *((Basis *)&dest) = self->scaled(*scale); + return dest; +} + +void GDAPI godot_basis_set_scale(godot_basis *p_self, const godot_vector3 *p_scale) { + Basis *self = (Basis *)p_self; + const Vector3 *scale = (const Vector3 *)p_scale; + self->set_scale(*scale); +} + +void GDAPI godot_basis_set_rotation_euler(godot_basis *p_self, const godot_vector3 *p_euler) { + Basis *self = (Basis *)p_self; + const Vector3 *euler = (const Vector3 *)p_euler; + self->set_rotation_euler(*euler); +} + +void GDAPI godot_basis_set_rotation_axis_angle(godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_angle) { + Basis *self = (Basis *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + self->set_rotation_axis_angle(*axis, p_angle); +} + +godot_vector3 GDAPI godot_basis_get_scale(const godot_basis *p_self) { + godot_vector3 dest; + const Basis *self = (const Basis *)p_self; + *((Vector3 *)&dest) = self->get_scale(); + return dest; } -void GDAPI godot_basis_new(godot_basis *p_basis) { - Basis *basis = (Basis *)p_basis; - *basis = Basis(); +godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self) { + godot_vector3 dest; + const Basis *self = (const Basis *)p_self; + *((Vector3 *)&dest) = self->get_euler(); + return dest; } -void GDAPI godot_basis_new_with_euler_quat(godot_basis *p_basis, const godot_quat *p_euler) { - Basis *basis = (Basis *)p_basis; - Quat *euler = (Quat *)p_euler; - *basis = Basis(*euler); +godot_real GDAPI godot_basis_tdotx(const godot_basis *p_self, const godot_vector3 *p_with) { + const Basis *self = (const Basis *)p_self; + const Vector3 *with = (const Vector3 *)p_with; + return self->tdotx(*with); } -void GDAPI godot_basis_new_with_euler(godot_basis *p_basis, const godot_vector3 *p_euler) { - Basis *basis = (Basis *)p_basis; - Vector3 *euler = (Vector3 *)p_euler; - *basis = Basis(*euler); +godot_real GDAPI godot_basis_tdoty(const godot_basis *p_self, const godot_vector3 *p_with) { + const Basis *self = (const Basis *)p_self; + const Vector3 *with = (const Vector3 *)p_with; + return self->tdoty(*with); } -godot_quat GDAPI godot_basis_as_quat(const godot_basis *p_basis) { - const Basis *basis = (const Basis *)p_basis; - godot_quat quat; - Quat *p_quat = (Quat *)&quat; - *p_quat = basis->operator Quat(); - return quat; +godot_real GDAPI godot_basis_tdotz(const godot_basis *p_self, const godot_vector3 *p_with) { + const Basis *self = (const Basis *)p_self; + const Vector3 *with = (const Vector3 *)p_with; + return self->tdotz(*with); } -godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_basis) { - const Basis *basis = (const Basis *)p_basis; - godot_vector3 euler; - Vector3 *p_euler = (Vector3 *)&euler; - *p_euler = basis->get_euler(); - return euler; +godot_vector3 GDAPI godot_basis_xform(const godot_basis *p_self, const godot_vector3 *p_v) { + godot_vector3 dest; + const Basis *self = (const Basis *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *((Vector3 *)&dest) = self->xform(*v); + return dest; } -/* - * p_elements is a pointer to an array of 3 (!!) vector3 - */ -void GDAPI godot_basis_get_elements(godot_basis *p_basis, godot_vector3 *p_elements) { - Basis *basis = (Basis *)p_basis; +godot_vector3 GDAPI godot_basis_xform_inv(const godot_basis *p_self, const godot_vector3 *p_v) { + godot_vector3 dest; + const Basis *self = (const Basis *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *((Vector3 *)&dest) = self->xform_inv(*v); + return dest; +} + +godot_int GDAPI godot_basis_get_orthogonal_index(const godot_basis *p_self) { + const Basis *self = (const Basis *)p_self; + return self->get_orthogonal_index(); +} + +void GDAPI godot_basis_new(godot_basis *r_dest) { + Basis *dest = (Basis *)r_dest; + *dest = Basis(); +} + +void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler) { + Basis *dest = (Basis *)r_dest; + const Quat *euler = (const Quat *)p_euler; + *dest = Basis(*euler); +} + +// p_elements is a pointer to an array of 3 (!!) vector3 +void GDAPI godot_basis_get_elements(godot_basis *p_self, godot_vector3 *p_elements) { + const Basis *self = (const Basis *)p_self; Vector3 *elements = (Vector3 *)p_elements; - elements[0] = basis->elements[0]; - elements[1] = basis->elements[1]; - elements[2] = basis->elements[2]; + elements[0] = self->elements[0]; + elements[1] = self->elements[1]; + elements[2] = self->elements[2]; +} + +godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_self, const godot_int p_axis) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *self = (const Basis *)p_self; + *d = self->get_axis(p_axis); + return dest; +} + +void GDAPI godot_basis_set_axis(godot_basis *p_self, const godot_int p_axis, const godot_vector3 *p_value) { + Basis *self = (Basis *)p_self; + const Vector3 *value = (const Vector3 *)p_value; + self->set_axis(p_axis, *value); +} + +godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_self, const godot_int p_row) { + godot_vector3 dest; + Vector3 *d = (Vector3 *)&dest; + const Basis *self = (const Basis *)p_self; + *d = self->get_row(p_row); + return dest; +} + +void GDAPI godot_basis_set_row(godot_basis *p_self, const godot_int p_row, const godot_vector3 *p_value) { + Basis *self = (Basis *)p_self; + const Vector3 *value = (const Vector3 *)p_value; + self->set_row(p_row, *value); +} + +godot_bool GDAPI godot_basis_operator_equal(const godot_basis *p_self, const godot_basis *p_b) { + const Basis *self = (const Basis *)p_self; + const Basis *b = (const Basis *)p_b; + return *self == *b; +} + +godot_basis GDAPI godot_basis_operator_add(const godot_basis *p_self, const godot_basis *p_b) { + godot_basis raw_dest; + Basis *dest = (Basis *)&raw_dest; + const Basis *self = (const Basis *)p_self; + const Basis *b = (const Basis *)p_b; + *dest = *self + *b; + return raw_dest; +} + +godot_basis GDAPI godot_basis_operator_substract(const godot_basis *p_self, const godot_basis *p_b) { + godot_basis raw_dest; + Basis *dest = (Basis *)&raw_dest; + const Basis *self = (const Basis *)p_self; + const Basis *b = (const Basis *)p_b; + *dest = *self - *b; + return raw_dest; +} + +godot_basis GDAPI godot_basis_operator_multiply_vector(const godot_basis *p_self, const godot_basis *p_b) { + godot_basis raw_dest; + Basis *dest = (Basis *)&raw_dest; + const Basis *self = (const Basis *)p_self; + const Basis *b = (const Basis *)p_b; + *dest = *self * *b; + return raw_dest; +} + +godot_basis GDAPI godot_basis_operator_multiply_scalar(const godot_basis *p_self, const godot_real p_b) { + godot_basis raw_dest; + Basis *dest = (Basis *)&raw_dest; + const Basis *self = (const Basis *)p_self; + *dest = *self * p_b; + return raw_dest; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_basis.h b/modules/gdnative/godot/godot_basis.h index a8f19bfde5..a096a8cc08 100644 --- a/modules/gdnative/godot/godot_basis.h +++ b/modules/gdnative/godot/godot_basis.h @@ -37,24 +37,79 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED typedef struct godot_basis { uint8_t _dont_touch_that[36]; } godot_basis; #endif #include "../godot.h" +#include "godot_vector3.h" -void GDAPI godot_basis_new(godot_basis *p_basis); -void GDAPI godot_basis_new_with_euler_quat(godot_basis *p_basis, const godot_quat *p_euler); -void GDAPI godot_basis_new_with_euler(godot_basis *p_basis, const godot_vector3 *p_euler); +void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis); +void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *r_dest, const godot_vector3 *p_axis, const godot_real p_phi); +void GDAPI godot_basis_new_with_euler(godot_basis *r_dest, const godot_vector3 *p_euler); -godot_quat GDAPI godot_basis_as_quat(const godot_basis *p_basis); -godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_basis); +godot_string GDAPI godot_basis_as_string(const godot_basis *p_self); -/* - * p_elements is a pointer to an array of 3 (!!) vector3 - */ -void GDAPI godot_basis_get_elements(godot_basis *p_basis, godot_vector3 *p_elements); +godot_basis GDAPI godot_basis_inverse(const godot_basis *p_self); + +godot_basis GDAPI godot_basis_transposed(const godot_basis *p_self); + +godot_basis GDAPI godot_basis_orthonormalized(const godot_basis *p_self); + +godot_real GDAPI godot_basis_determinant(const godot_basis *p_self); + +godot_basis GDAPI godot_basis_rotated(const godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_phi); + +godot_basis GDAPI godot_basis_scaled(const godot_basis *p_self, const godot_vector3 *p_scale); + +void GDAPI godot_basis_set_scale(godot_basis *p_self, const godot_vector3 *p_scale); + +void GDAPI godot_basis_set_rotation_euler(godot_basis *p_self, const godot_vector3 *p_euler); + +void GDAPI godot_basis_set_rotation_axis_angle(godot_basis *p_self, const godot_vector3 *p_axis, const godot_real p_angle); + +godot_vector3 GDAPI godot_basis_get_scale(const godot_basis *p_self); + +godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self); + +godot_real GDAPI godot_basis_tdotx(const godot_basis *p_self, const godot_vector3 *p_with); + +godot_real GDAPI godot_basis_tdoty(const godot_basis *p_self, const godot_vector3 *p_with); + +godot_real GDAPI godot_basis_tdotz(const godot_basis *p_self, const godot_vector3 *p_with); + +godot_vector3 GDAPI godot_basis_xform(const godot_basis *p_self, const godot_vector3 *p_v); + +godot_vector3 GDAPI godot_basis_xform_inv(const godot_basis *p_self, const godot_vector3 *p_v); + +godot_int GDAPI godot_basis_get_orthogonal_index(const godot_basis *p_self); + +void GDAPI godot_basis_new(godot_basis *r_dest); + +void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler); + +// p_elements is a pointer to an array of 3 (!!) vector3 +void GDAPI godot_basis_get_elements(godot_basis *p_self, godot_vector3 *p_elements); + +godot_vector3 GDAPI godot_basis_get_axis(const godot_basis *p_self, const godot_int p_axis); + +void GDAPI godot_basis_set_axis(godot_basis *p_self, const godot_int p_axis, const godot_vector3 *p_value); + +godot_vector3 GDAPI godot_basis_get_row(const godot_basis *p_self, const godot_int p_row); + +void GDAPI godot_basis_set_row(godot_basis *p_self, const godot_int p_row, const godot_vector3 *p_value); + +godot_bool GDAPI godot_basis_operator_equal(const godot_basis *p_self, const godot_basis *p_b); + +godot_basis GDAPI godot_basis_operator_add(const godot_basis *p_self, const godot_basis *p_b); + +godot_basis GDAPI godot_basis_operator_substract(const godot_basis *p_self, const godot_basis *p_b); + +godot_basis GDAPI godot_basis_operator_multiply_vector(const godot_basis *p_self, const godot_basis *p_b); + +godot_basis GDAPI godot_basis_operator_multiply_scalar(const godot_basis *p_self, const godot_real p_b); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_color.cpp b/modules/gdnative/godot/godot_color.cpp index 203ce672fa..6dedf2ab10 100644 --- a/modules/gdnative/godot/godot_color.cpp +++ b/modules/gdnative/godot/godot_color.cpp @@ -28,34 +28,153 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_color.h" +#include "core/variant.h" -#include "color.h" +#include "core/color.h" #ifdef __cplusplus extern "C" { #endif -void _color_api_anchor() { +void _color_api_anchor() {} + +void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a) { + + Color *dest = (Color *)r_dest; + *dest = Color(p_r, p_g, p_b, p_a); +} + +void GDAPI godot_color_new_rgb(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b) { + + Color *dest = (Color *)r_dest; + *dest = Color(p_r, p_g, p_b); +} + +godot_real godot_color_get_r(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->r; +} + +void godot_color_set_r(godot_color *p_self, const godot_real val) { + Color *self = (Color *)p_self; + self->r = val; +} + +godot_real godot_color_get_g(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->g; +} + +void godot_color_set_g(godot_color *p_self, const godot_real val) { + Color *self = (Color *)p_self; + self->g = val; +} + +godot_real godot_color_get_b(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->b; +} + +void godot_color_set_b(godot_color *p_self, const godot_real val) { + Color *self = (Color *)p_self; + self->b = val; +} + +godot_real godot_color_get_a(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->a; +} + +void godot_color_set_a(godot_color *p_self, const godot_real val) { + Color *self = (Color *)p_self; + self->a = val; } -void GDAPI godot_color_new(godot_color *p_color) { - Color *color = (Color *)p_color; - *color = Color(); +godot_real godot_color_get_h(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->get_h(); } -void GDAPI godot_color_new_rgba(godot_color *p_color, const godot_real r, const godot_real g, const godot_real b, const godot_real a) { - Color *color = (Color *)p_color; - *color = Color(r, g, b, a); +godot_real godot_color_get_s(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->get_s(); +} + +godot_real godot_color_get_v(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->get_v(); +} + +godot_string GDAPI godot_color_as_string(const godot_color *p_self) { + godot_string ret; + const Color *self = (const Color *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_int GDAPI godot_color_to_32(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->to_32(); +} + +godot_int GDAPI godot_color_to_ARGB32(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->to_ARGB32(); +} + +godot_real GDAPI godot_color_gray(const godot_color *p_self) { + const Color *self = (const Color *)p_self; + return self->gray(); +} + +godot_color GDAPI godot_color_inverted(const godot_color *p_self) { + godot_color dest; + const Color *self = (const Color *)p_self; + *((Color *)&dest) = self->inverted(); + return dest; +} + +godot_color GDAPI godot_color_contrasted(const godot_color *p_self) { + godot_color dest; + const Color *self = (const Color *)p_self; + *((Color *)&dest) = self->contrasted(); + return dest; +} + +godot_color GDAPI godot_color_linear_interpolate(const godot_color *p_self, const godot_color *p_b, const godot_real p_t) { + godot_color dest; + const Color *self = (const Color *)p_self; + const Color *b = (const Color *)p_b; + *((Color *)&dest) = self->linear_interpolate(*b, p_t); + return dest; +} + +godot_color GDAPI godot_color_blend(const godot_color *p_self, const godot_color *p_over) { + godot_color dest; + const Color *self = (const Color *)p_self; + const Color *over = (const Color *)p_over; + *((Color *)&dest) = self->blend(*over); + return dest; +} + +godot_string GDAPI godot_color_to_html(const godot_color *p_self, const godot_bool p_with_alpha) { + godot_string dest; + const Color *self = (const Color *)p_self; + + memnew_placement(&dest, String(self->to_html(p_with_alpha))); + return dest; } -uint32_t GDAPI godot_color_get_32(const godot_color *p_color) { - const Color *color = (const Color *)p_color; - return color->to_32(); +godot_bool GDAPI godot_color_operator_equal(const godot_color *p_self, const godot_color *p_b) { + const Color *self = (const Color *)p_self; + const Color *b = (const Color *)p_b; + return *self == *b; } -float GDAPI *godot_color_index(godot_color *p_color, const godot_int idx) { - Color *color = (Color *)p_color; - return &color->operator[](idx); +godot_bool GDAPI godot_color_operator_less(const godot_color *p_self, const godot_color *p_b) { + const Color *self = (const Color *)p_self; + const Color *b = (const Color *)p_b; + return *self < *b; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_color.h b/modules/gdnative/godot/godot_color.h index b99a062a66..10dc228b1c 100644 --- a/modules/gdnative/godot/godot_color.h +++ b/modules/gdnative/godot/godot_color.h @@ -37,19 +37,55 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED typedef struct godot_color { uint8_t _dont_touch_that[16]; } godot_color; #endif #include "../godot.h" +#include "godot_string.h" -void GDAPI godot_color_new(godot_color *p_color); -void GDAPI godot_color_new_rgba(godot_color *p_color, const godot_real r, const godot_real g, const godot_real b, const godot_real a); +void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a); +void GDAPI godot_color_new_rgb(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b); -uint32_t GDAPI godot_color_get_32(const godot_color *p_color); +godot_real godot_color_get_r(const godot_color *p_self); +void godot_color_set_r(godot_color *p_self, const godot_real r); -float GDAPI *godot_color_index(godot_color *p_color, const godot_int idx); +godot_real godot_color_get_g(const godot_color *p_self); +void godot_color_set_g(godot_color *p_self, const godot_real g); + +godot_real godot_color_get_b(const godot_color *p_self); +void godot_color_set_b(godot_color *p_self, const godot_real b); + +godot_real godot_color_get_a(const godot_color *p_self); +void godot_color_set_a(godot_color *p_self, const godot_real a); + +godot_real godot_color_get_h(const godot_color *p_self); +godot_real godot_color_get_s(const godot_color *p_self); +godot_real godot_color_get_v(const godot_color *p_self); + +godot_string GDAPI godot_color_as_string(const godot_color *p_self); + +godot_int GDAPI godot_color_to_32(const godot_color *p_self); + +godot_int GDAPI godot_color_to_ARGB32(const godot_color *p_self); + +godot_real GDAPI godot_color_gray(const godot_color *p_self); + +godot_color GDAPI godot_color_inverted(const godot_color *p_self); + +godot_color GDAPI godot_color_contrasted(const godot_color *p_self); + +godot_color GDAPI godot_color_linear_interpolate(const godot_color *p_self, const godot_color *p_b, const godot_real p_t); + +godot_color GDAPI godot_color_blend(const godot_color *p_self, const godot_color *p_over); + +godot_string GDAPI godot_color_to_html(const godot_color *p_self, const godot_bool p_with_alpha); + +godot_bool GDAPI godot_color_operator_equal(const godot_color *p_self, const godot_color *p_b); + +godot_bool GDAPI godot_color_operator_less(const godot_color *p_self, const godot_color *p_b); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_dictionary.cpp b/modules/gdnative/godot/godot_dictionary.cpp index 16d08e58e2..12c40f0564 100644 --- a/modules/gdnative/godot/godot_dictionary.cpp +++ b/modules/gdnative/godot/godot_dictionary.cpp @@ -28,109 +28,119 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_dictionary.h" +#include "core/variant.h" #include "core/dictionary.h" - -#include "core/os/memory.h" - #include "core/io/json.h" #ifdef __cplusplus extern "C" { #endif -void _dictionary_api_anchor() { +void _dictionary_api_anchor() {} + +void GDAPI godot_dictionary_new(godot_dictionary *r_dest) { + Dictionary *dest = (Dictionary *)r_dest; + memnew_placement(dest, Dictionary); } -void GDAPI godot_dictionary_new(godot_dictionary *p_dict) { - Dictionary *dict = (Dictionary *)p_dict; - memnew_placement(dict, Dictionary); +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *p_src) { + Dictionary *dest = (Dictionary *)r_dest; + const Dictionary *src = (const Dictionary *)p_src; + memnew_placement(dest, Dictionary(*src)); } -void GDAPI godot_dictionary_clear(godot_dictionary *p_dict) { - Dictionary *dict = (Dictionary *)p_dict; - dict->clear(); +void GDAPI godot_dictionary_destroy(godot_dictionary *p_self) { + Dictionary *self = (Dictionary *)p_self; + self->~Dictionary(); } -godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_dict) { - const Dictionary *dict = (const Dictionary *)p_dict; - return dict->empty(); +godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self) { + const Dictionary *self = (const Dictionary *)p_self; + return self->size(); } -void GDAPI godot_dictionary_erase(godot_dictionary *p_dict, const godot_variant *p_key) { - Dictionary *dict = (Dictionary *)p_dict; - Variant *key = (Variant *)p_key; - dict->erase(*key); +godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_self) { + const Dictionary *self = (const Dictionary *)p_self; + return self->empty(); } -godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_dict, const godot_variant *p_key) { - const Dictionary *dict = (const Dictionary *)p_dict; +void GDAPI godot_dictionary_clear(godot_dictionary *p_self) { + Dictionary *self = (Dictionary *)p_self; + self->clear(); +} + +godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_self, const godot_variant *p_key) { + const Dictionary *self = (const Dictionary *)p_self; const Variant *key = (const Variant *)p_key; - return dict->has(*key); + return self->has(*key); } -godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_dict, const godot_array *p_keys) { - const Dictionary *dict = (const Dictionary *)p_dict; +godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_self, const godot_array *p_keys) { + const Dictionary *self = (const Dictionary *)p_self; const Array *keys = (const Array *)p_keys; - return dict->has_all(*keys); + return self->has_all(*keys); } -uint32_t GDAPI godot_dictionary_hash(const godot_dictionary *p_dict) { - const Dictionary *dict = (const Dictionary *)p_dict; - return dict->hash(); +void GDAPI godot_dictionary_erase(godot_dictionary *p_self, const godot_variant *p_key) { + Dictionary *self = (Dictionary *)p_self; + const Variant *key = (const Variant *)p_key; + self->erase(*key); } -godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_dict) { - godot_array a; - godot_array_new(&a); - const Dictionary *dict = (const Dictionary *)p_dict; - Array *array = (Array *)&a; - *array = dict->keys(); - return a; +godot_int GDAPI godot_dictionary_hash(const godot_dictionary *p_self) { + const Dictionary *self = (const Dictionary *)p_self; + return self->hash(); } -godot_int GDAPI godot_dictionary_parse_json(godot_dictionary *p_dict, const godot_string *p_json) { - Dictionary *dict = (Dictionary *)p_dict; - const String *json = (const String *)p_json; - Variant ret; - int err_line; - String err_str; - int err = (int)JSON::parse(*json, ret, err_str, err_line); - *dict = ret; - return err; +godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_self) { + godot_array dest; + const Dictionary *self = (const Dictionary *)p_self; + memnew_placement(&dest, Array(self->keys())); + return dest; } -godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_dict, const godot_variant *p_key) { - Dictionary *dict = (Dictionary *)p_dict; - Variant *key = (Variant *)p_key; - return (godot_variant *)&dict->operator[](*key); +godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_self) { + godot_array dest; + const Dictionary *self = (const Dictionary *)p_self; + memnew_placement(&dest, Array(self->values())); + return dest; } -godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_dict) { - const Dictionary *dict = (const Dictionary *)p_dict; - return dict->size(); +godot_variant GDAPI godot_dictionary_get(const godot_dictionary *p_self, const godot_variant *p_key) { + godot_variant raw_dest; + Variant *dest = (Variant *)&raw_dest; + const Dictionary *self = (const Dictionary *)p_self; + const Variant *key = (const Variant *)p_key; + memnew_placement(dest, Variant(self->operator[](*key))); + return raw_dest; } -godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_dict) { - const Dictionary *dict = (const Dictionary *)p_dict; - godot_string str; - godot_string_new(&str); - String *s = (String *)&str; - *s = JSON::print(Variant(*dict)); - return str; +void GDAPI godot_dictionary_set(godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_value) { + Dictionary *self = (Dictionary *)p_self; + const Variant *key = (const Variant *)p_key; + const Variant *value = (const Variant *)p_value; + self->operator[](*key) = *value; +} + +godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_self, const godot_variant *p_key) { + Array *self = (Array *)p_self; + const Variant *key = (const Variant *)p_key; + return (godot_variant *)&self->operator[](*key); } -godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_dict) { - godot_array a; - godot_array_new(&a); - const Dictionary *dict = (const Dictionary *)p_dict; - Array *array = (Array *)&a; - *array = dict->values(); - return a; +godot_bool GDAPI godot_dictionary_operator_equal(const godot_dictionary *p_self, const godot_dictionary *p_b) { + const Dictionary *self = (const Dictionary *)p_self; + const Dictionary *b = (const Dictionary *)p_b; + return *self == *b; } -void GDAPI godot_dictionary_destroy(godot_dictionary *p_dict) { - ((Dictionary *)p_dict)->~Dictionary(); +godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self) { + godot_string raw_dest; + String *dest = (String *)&raw_dest; + const Dictionary *self = (const Dictionary *)p_self; + memnew_placement(dest, String(JSON::print(Variant(*self)))); + return raw_dest; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_dictionary.h b/modules/gdnative/godot/godot_dictionary.h index 3f7c504880..0325670b15 100644 --- a/modules/gdnative/godot/godot_dictionary.h +++ b/modules/gdnative/godot/godot_dictionary.h @@ -36,42 +36,47 @@ extern "C" { #include <stdint.h> -#ifndef GODOT_CORE_API_GODOT_DICITIONARY_TYPE_DEFINED +#ifndef GODOT_CORE_API_GODOT_DICTIONARY_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_DICTIONARY_TYPE_DEFINED typedef struct godot_dictionary { uint8_t _dont_touch_that[8]; } godot_dictionary; #endif +#include "../godot.h" #include "godot_array.h" #include "godot_variant.h" -void GDAPI godot_dictionary_new(godot_dictionary *p_dict); +void GDAPI godot_dictionary_new(godot_dictionary *r_dest); +void GDAPI godot_dictionary_new_copy(godot_dictionary *r_dest, const godot_dictionary *p_src); +void GDAPI godot_dictionary_destroy(godot_dictionary *p_self); -void GDAPI godot_dictionary_clear(godot_dictionary *p_dict); +godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_self); -godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_dict); +godot_bool GDAPI godot_dictionary_empty(const godot_dictionary *p_self); -void GDAPI godot_dictionary_erase(godot_dictionary *p_dict, const godot_variant *p_key); +void GDAPI godot_dictionary_clear(godot_dictionary *p_self); -godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_dict, const godot_variant *p_key); +godot_bool GDAPI godot_dictionary_has(const godot_dictionary *p_self, const godot_variant *p_key); -godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_dict, const godot_array *p_keys); +godot_bool GDAPI godot_dictionary_has_all(const godot_dictionary *p_self, const godot_array *p_keys); -uint32_t GDAPI godot_dictionary_hash(const godot_dictionary *p_dict); +void GDAPI godot_dictionary_erase(godot_dictionary *p_self, const godot_variant *p_key); -godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_dict); +godot_int GDAPI godot_dictionary_hash(const godot_dictionary *p_self); -godot_int GDAPI godot_dictionary_parse_json(godot_dictionary *p_dict, const godot_string *p_json); +godot_array GDAPI godot_dictionary_keys(const godot_dictionary *p_self); -godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_dict, const godot_variant *p_key); +godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_self); -godot_int GDAPI godot_dictionary_size(const godot_dictionary *p_dict); +godot_variant GDAPI godot_dictionary_get(const godot_dictionary *p_self, const godot_variant *p_key); +void GDAPI godot_dictionary_set(godot_dictionary *p_self, const godot_variant *p_key, const godot_variant *p_value); -godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_dict); +godot_variant GDAPI *godot_dictionary_operator_index(godot_dictionary *p_self, const godot_variant *p_key); -godot_array GDAPI godot_dictionary_values(const godot_dictionary *p_dict); +godot_bool GDAPI godot_dictionary_operator_equal(const godot_dictionary *p_self, const godot_dictionary *p_b); -void GDAPI godot_dictionary_destroy(godot_dictionary *p_dict); +godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_image.cpp b/modules/gdnative/godot/godot_image.cpp deleted file mode 100644 index ae8290afc2..0000000000 --- a/modules/gdnative/godot/godot_image.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************/ -/* godot_image.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "godot_image.h" - -#include "image.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void _image_api_anchor() { -} - -#define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) - -void GDAPI godot_image_new(godot_image *p_img) { - Image *img = (Image *)p_img; - memnew_placement_custom(img, Image, Image()); -} - -void GDAPI godot_image_new_with_png_jpg(godot_image *p_img, const uint8_t *p_mem_png_jpg, int p_len) { - Image *img = (Image *)p_img; - memnew_placement_custom(img, Image, Image(p_mem_png_jpg, p_len)); -} - -void GDAPI godot_image_new_with_xpm(godot_image *p_img, const char **p_xpm) { - Image *img = (Image *)p_img; - memnew_placement_custom(img, Image, Image(p_xpm)); -} - -void GDAPI godot_image_new_with_size_format(godot_image *p_img, int p_width, int p_height, bool p_use_mipmaps, godot_image_format p_format) { - Image *img = (Image *)p_img; - memnew_placement_custom(img, Image, Image(p_width, p_height, p_use_mipmaps, (Image::Format)p_format)); -} - -void GDAPI godot_image_new_with_size_format_data(godot_image *p_img, int p_width, int p_height, bool p_use_mipmaps, godot_image_format p_format, godot_pool_byte_array *p_data) { - Image *img = (Image *)p_img; - PoolVector<uint8_t> *data = (PoolVector<uint8_t> *)p_data; - memnew_placement_custom(img, Image, Image(p_width, p_height, p_use_mipmaps, (Image::Format)p_format, *data)); -} - -godot_pool_byte_array GDAPI godot_image_get_data(godot_image *p_img) { - Image *img = (Image *)p_img; - PoolVector<uint8_t> cpp_data = img->get_data(); - godot_pool_byte_array *data = (godot_pool_byte_array *)&cpp_data; - return *data; -} - -godot_error GDAPI godot_image_load(godot_image *p_img, const godot_string *p_path) { - Image *img = (Image *)p_img; - String *path = (String *)p_path; - return (godot_error)img->load(*path); -} - -godot_error GDAPI godot_image_save_png(godot_image *p_img, const godot_string *p_path) { - Image *img = (Image *)p_img; - String *path = (String *)p_path; - return (godot_error)img->save_png(*path); -} - -int GDAPI godot_image_get_width(const godot_image *p_img) { - Image *img = (Image *)p_img; - return img->get_width(); -} - -int GDAPI godot_image_get_height(const godot_image *p_img) { - Image *img = (Image *)p_img; - return img->get_height(); -} - -godot_bool GDAPI godot_image_has_mipmaps(const godot_image *p_img) { - Image *img = (Image *)p_img; - return img->has_mipmaps(); -} - -int GDAPI godot_image_get_mipmap_count(const godot_image *p_img) { - Image *img = (Image *)p_img; - return img->get_mipmap_count(); -} - -void GDAPI godot_image_destroy(godot_image *p_img) { - ((Image *)p_img)->~Image(); -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/gdnative/godot/godot_image.h b/modules/gdnative/godot/godot_image.h deleted file mode 100644 index c43dd45148..0000000000 --- a/modules/gdnative/godot/godot_image.h +++ /dev/null @@ -1,124 +0,0 @@ -/*************************************************************************/ -/* godot_image.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef GODOT_IMAGE_H -#define GODOT_IMAGE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdint.h> - -#ifndef GODOT_CORE_API_GODOT_IMAGE_TYPE_DEFINED -typedef struct godot_image { - uint8_t _dont_touch_that[32]; -} godot_image; -#endif - -#include "godot_pool_arrays.h" - -#include "../godot.h" - -// This is a copypasta of the C++ enum inside the Image class -// There's no neat way of automatically updating the C enum / using the C++ enum directly -// if somebody knows a way feel free to open a PR or open an issue (or ask for Karroffel or bojidar-bg on IRC) - -enum godot_image_format { - - GODOT_IMAGE_FORMAT_L8, //luminance - GODOT_IMAGE_FORMAT_LA8, //luminance-alpha - GODOT_IMAGE_FORMAT_R8, - GODOT_IMAGE_FORMAT_RG8, - GODOT_IMAGE_FORMAT_RGB8, - GODOT_IMAGE_FORMAT_RGBA8, - GODOT_IMAGE_FORMAT_RGB565, //16 bit - GODOT_IMAGE_FORMAT_RGBA4444, - GODOT_IMAGE_FORMAT_RGBA5551, - GODOT_IMAGE_FORMAT_RF, //float - GODOT_IMAGE_FORMAT_RGF, - GODOT_IMAGE_FORMAT_RGBF, - GODOT_IMAGE_FORMAT_RGBAF, - GODOT_IMAGE_FORMAT_RH, //half float - GODOT_IMAGE_FORMAT_RGH, - GODOT_IMAGE_FORMAT_RGBH, - GODOT_IMAGE_FORMAT_RGBAH, - GODOT_IMAGE_FORMAT_DXT1, //s3tc bc1 - GODOT_IMAGE_FORMAT_DXT3, //bc2 - GODOT_IMAGE_FORMAT_DXT5, //bc3 - GODOT_IMAGE_FORMAT_ATI1, //bc4 - GODOT_IMAGE_FORMAT_ATI2, //bc5 - GODOT_IMAGE_FORMAT_BPTC_RGBA, //btpc bc6h - GODOT_IMAGE_FORMAT_BPTC_RGBF, //float / - GODOT_IMAGE_FORMAT_BPTC_RGBFU, //unsigned float - GODOT_IMAGE_FORMAT_PVRTC2, //pvrtc - GODOT_IMAGE_FORMAT_PVRTC2A, - GODOT_IMAGE_FORMAT_PVRTC4, - GODOT_IMAGE_FORMAT_PVRTC4A, - GODOT_IMAGE_FORMAT_ETC, //etc1 - GODOT_IMAGE_FORMAT_ETC2_R11, //etc2 - GODOT_IMAGE_FORMAT_ETC2_R11S, //signed, NOT srgb. - GODOT_IMAGE_FORMAT_ETC2_RG11, - GODOT_IMAGE_FORMAT_ETC2_RG11S, - GODOT_IMAGE_FORMAT_ETC2_RGB8, - GODOT_IMAGE_FORMAT_ETC2_RGBA8, - GODOT_IMAGE_FORMAT_ETC2_RGB8A1, - GODOT_IMAGE_FORMAT_MAX -}; -typedef enum godot_image_format godot_image_format; - -void GDAPI godot_image_new(godot_image *p_img); -// p_len can be -1 -void GDAPI godot_image_new_with_png_jpg(godot_image *p_img, const uint8_t *p_mem_png_jpg, int p_len); -void GDAPI godot_image_new_with_xpm(godot_image *p_img, const char **p_xpm); - -void GDAPI godot_image_new_with_size_format(godot_image *p_img, int p_width, int p_height, bool p_use_mipmaps, godot_image_format p_format); -void GDAPI godot_image_new_with_size_format_data(godot_image *p_img, int p_width, int p_height, bool p_use_mipmaps, godot_image_format p_format, godot_pool_byte_array *p_data); - -godot_pool_byte_array GDAPI godot_image_get_data(godot_image *p_img); - -godot_error GDAPI godot_image_load(godot_image *p_img, const godot_string *p_path); -godot_error GDAPI godot_image_save_png(godot_image *p_img, const godot_string *p_path); - -int GDAPI godot_image_get_width(const godot_image *p_img); -int GDAPI godot_image_get_height(const godot_image *p_img); -godot_bool GDAPI godot_image_has_mipmaps(const godot_image *p_img); -int GDAPI godot_image_get_mipmap_count(const godot_image *p_img); - -// @Incomplete -// I think it's too complex for the binding authors to implement the image class anew, so we should definitely -// export all methods here. That takes a while so it's on my @Todo list - -void GDAPI godot_image_destroy(godot_image *p_img); - -#ifdef __cplusplus -} -#endif - -#endif // GODOT_IMAGE_H diff --git a/modules/gdnative/godot/godot_input_event.cpp b/modules/gdnative/godot/godot_input_event.cpp deleted file mode 100644 index 0401c96a88..0000000000 --- a/modules/gdnative/godot/godot_input_event.cpp +++ /dev/null @@ -1,309 +0,0 @@ -/*************************************************************************/ -/* godot_input_event.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "godot_input_event.h" - -#include "os/input_event.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void _input_event_api_anchor() { -} - -void GDAPI godot_input_event_new(godot_input_event *p_ie) { - InputEvent *ie = (InputEvent *)p_ie; - *ie = InputEvent(); -} - -godot_bool GDAPI godot_input_event_is_pressed(const godot_input_event *p_ie) { - const InputEvent *ie = (const InputEvent *)p_ie; - return ie->is_pressed(); -} - -godot_bool GDAPI godot_input_event_is_action(const godot_input_event *p_ie, const godot_string *p_action) { - const InputEvent *ie = (const InputEvent *)p_ie; - const String *action = (const String *)p_action; - return ie->is_action(*action); -} - -godot_bool GDAPI godot_input_event_is_action_pressed(const godot_input_event *p_ie, const godot_string *p_action) { - const InputEvent *ie = (const InputEvent *)p_ie; - const String *action = (const String *)p_action; - return ie->is_action_pressed(*action); -} - -godot_bool GDAPI godot_input_event_is_action_released(const godot_input_event *p_ie, const godot_string *p_action) { - const InputEvent *ie = (const InputEvent *)p_ie; - const String *action = (const String *)p_action; - return ie->is_action_released(*action); -} - -godot_bool GDAPI godot_input_event_is_echo(const godot_input_event *p_ie) { - const InputEvent *ie = (const InputEvent *)p_ie; - return ie->is_echo(); -} - -void GDAPI godot_input_event_set_as_action(godot_input_event *p_ie, const godot_string *p_action, const godot_bool p_pressed) { - InputEvent *ie = (InputEvent *)p_ie; - const String *action = (const String *)p_action; - return ie->set_as_action(*action, p_pressed); -} - -godot_string GDAPI godot_input_event_as_string(const godot_input_event *p_ie) { - const InputEvent *ie = (const InputEvent *)p_ie; - godot_string str; - String *s = (String *)&str; - memnew_placement(s, String); - *s = (String)*ie; - return str; -} - -uint32_t GDAPI *godot_input_event_get_id(godot_input_event *p_ie) { - InputEvent *ie = (InputEvent *)p_ie; - return &ie->ID; -} - -godot_input_event_type GDAPI *godot_input_event_get_type(godot_input_event *p_ie) { - InputEvent *ie = (InputEvent *)p_ie; - return (godot_input_event_type *)&ie->type; -} - -godot_int GDAPI *godot_input_event_get_device(godot_input_event *p_ie) { - InputEvent *ie = (InputEvent *)p_ie; - return &ie->device; -} - -static InputModifierState *_get_mod_for_type(InputEvent *ie) { - switch (ie->type) { - case InputEvent::MOUSE_BUTTON: - return &ie->mouse_button.mod; - case InputEvent::MOUSE_MOTION: - return &ie->mouse_motion.mod; - case InputEvent::KEY: - return &ie->key.mod; - default: - return 0; - } -} - -godot_bool GDAPI *godot_input_event_mod_get_alt(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - InputModifierState *mod = _get_mod_for_type(ie); - return &mod->alt; -} - -godot_bool GDAPI *godot_input_event_mod_get_ctrl(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - InputModifierState *mod = _get_mod_for_type(ie); - return &mod->control; -} - -godot_bool GDAPI *godot_input_event_mod_get_command(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - InputModifierState *mod = _get_mod_for_type(ie); - return &mod->command; -} - -godot_bool GDAPI *godot_input_event_mod_get_shift(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - InputModifierState *mod = _get_mod_for_type(ie); - return &mod->shift; -} - -godot_bool GDAPI *godot_input_event_mod_get_meta(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - InputModifierState *mod = _get_mod_for_type(ie); - return &mod->meta; -} - -uint32_t GDAPI *godot_input_event_key_get_scancode(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->key.scancode; -} - -uint32_t GDAPI *godot_input_event_key_get_unicode(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->key.unicode; -} - -godot_bool GDAPI *godot_input_event_key_get_pressed(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->key.pressed; -} - -godot_bool GDAPI *godot_input_event_key_get_echo(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->key.echo; -} - -float GDAPI *godot_input_event_mouse_get_x(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_button.x; -} - -float GDAPI *godot_input_event_mouse_get_y(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_button.y; -} - -float GDAPI *godot_input_event_mouse_get_global_x(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_button.global_x; -} - -float GDAPI *godot_input_event_mouse_get_global_y(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_button.global_y; -} - -godot_int GDAPI *godot_input_event_mouse_get_button_mask(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_button.button_mask; -} - -godot_int GDAPI *godot_input_event_mouse_button_get_button_index(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_button.button_index; -} - -godot_bool GDAPI *godot_input_event_mouse_button_get_pressed(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_button.pressed; -} - -godot_bool GDAPI *godot_input_event_mouse_button_get_doubleclick(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_button.doubleclick; -} - -float GDAPI *godot_input_event_mouse_motion_get_relative_x(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_motion.relative_x; -} - -float GDAPI *godot_input_event_mouse_motion_get_relative_y(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_motion.relative_y; -} - -float GDAPI *godot_input_event_mouse_motion_get_speed_x(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_motion.speed_x; -} - -float GDAPI *godot_input_event_mouse_motion_get_speed_y(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->mouse_motion.speed_y; -} - -godot_int GDAPI *godot_input_event_joypad_motion_get_axis(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->joy_motion.axis; -} - -float GDAPI *godot_input_event_joypad_motion_get_axis_value(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->joy_motion.axis_value; -} - -godot_int GDAPI *godot_input_event_joypad_button_get_button_index(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->joy_button.button_index; -} - -godot_bool GDAPI *godot_input_event_joypad_button_get_pressed(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->joy_button.pressed; -} - -float GDAPI *godot_input_event_joypad_button_get_pressure(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->joy_button.pressure; -} - -godot_int GDAPI *godot_input_event_screen_touch_get_index(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_touch.index; -} - -float GDAPI *godot_input_event_screen_touch_get_x(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_touch.x; -} - -float GDAPI *godot_input_event_screen_touch_get_y(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_touch.y; -} - -godot_bool GDAPI *godot_input_event_screen_touch_get_pressed(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_touch.pressed; -} - -godot_int GDAPI *godot_input_event_screen_drag_get_index(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_drag.index; -} - -float GDAPI *godot_input_event_screen_drag_get_x(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_drag.x; -} - -float GDAPI *godot_input_event_screen_drag_get_y(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_drag.y; -} - -float GDAPI *godot_input_event_screen_drag_get_relative_x(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_drag.relative_x; -} - -float GDAPI *godot_input_event_screen_drag_get_relative_y(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_drag.relative_y; -} - -float GDAPI *godot_input_event_screen_drag_get_speed_x(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_drag.speed_x; -} - -float GDAPI *godot_input_event_screen_drag_get_speed_y(godot_input_event *p_event) { - InputEvent *ie = (InputEvent *)p_event; - return &ie->screen_drag.speed_y; -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/gdnative/godot/godot_input_event.h b/modules/gdnative/godot/godot_input_event.h deleted file mode 100644 index b0a133e3d9..0000000000 --- a/modules/gdnative/godot/godot_input_event.h +++ /dev/null @@ -1,235 +0,0 @@ -/*************************************************************************/ -/* godot_input_event.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef GODOT_INPUT_EVENT_H -#define GODOT_INPUT_EVENT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdint.h> - -#ifndef GODOT_CORE_API_GODOT_INPUT_EVENT_TYPE_DEFINED -typedef struct godot_input_event { - uint8_t _dont_touch_that[56]; -} godot_input_event; -#endif - -enum godot_input_event_type { - GODOT_INPUT_EVENT_TYPE_NONE, - GODOT_INPUT_EVENT_TYPE_KEY, - GODOT_INPUT_EVENT_TYPE_MOUSE_MOTION, - GODOT_INPUT_EVENT_TYPE_MOUSE_BUTTON, - GODOT_INPUT_EVENT_TYPE_JOYPAD_MOTION, - GODOT_INPUT_EVENT_TYPE_JOYPAD_BUTTON, - GODOT_INPUT_EVENT_TYPE_SCREEN_TOUCH, - GODOT_INPUT_EVENT_TYPE_SCREEN_DRAG, - GODOT_INPUT_EVENT_TYPE_ACTION, - GODOT_INPUT_EVENT_TYPE_TYPE_MAX -}; -typedef enum godot_input_event_type godot_input_event_type; - -enum { - GODOT_BUTTON_LEFT = 1, - GODOT_BUTTON_RIGHT = 2, - GODOT_BUTTON_MIDDLE = 3, - GODOT_BUTTON_WHEEL_UP = 4, - GODOT_BUTTON_WHEEL_DOWN = 5, - GODOT_BUTTON_WHEEL_LEFT = 6, - GODOT_BUTTON_WHEEL_RIGHT = 7, - GODOT_BUTTON_MASK_LEFT = (1 << (GODOT_BUTTON_LEFT - 1)), - GODOT_BUTTON_MASK_RIGHT = (1 << (GODOT_BUTTON_RIGHT - 1)), - GODOT_BUTTON_MASK_MIDDLE = (1 << (GODOT_BUTTON_MIDDLE - 1)), - -}; - -enum { - - GODOT_JOY_BUTTON_0 = 0, - GODOT_JOY_BUTTON_1 = 1, - GODOT_JOY_BUTTON_2 = 2, - GODOT_JOY_BUTTON_3 = 3, - GODOT_JOY_BUTTON_4 = 4, - GODOT_JOY_BUTTON_5 = 5, - GODOT_JOY_BUTTON_6 = 6, - GODOT_JOY_BUTTON_7 = 7, - GODOT_JOY_BUTTON_8 = 8, - GODOT_JOY_BUTTON_9 = 9, - GODOT_JOY_BUTTON_10 = 10, - GODOT_JOY_BUTTON_11 = 11, - GODOT_JOY_BUTTON_12 = 12, - GODOT_JOY_BUTTON_13 = 13, - GODOT_JOY_BUTTON_14 = 14, - GODOT_JOY_BUTTON_15 = 15, - GODOT_JOY_BUTTON_MAX = 16, - - GODOT_JOY_L = GODOT_JOY_BUTTON_4, - GODOT_JOY_R = GODOT_JOY_BUTTON_5, - GODOT_JOY_L2 = GODOT_JOY_BUTTON_6, - GODOT_JOY_R2 = GODOT_JOY_BUTTON_7, - GODOT_JOY_L3 = GODOT_JOY_BUTTON_8, - GODOT_JOY_R3 = GODOT_JOY_BUTTON_9, - GODOT_JOY_SELECT = GODOT_JOY_BUTTON_10, - GODOT_JOY_START = GODOT_JOY_BUTTON_11, - GODOT_JOY_DPAD_UP = GODOT_JOY_BUTTON_12, - GODOT_JOY_DPAD_DOWN = GODOT_JOY_BUTTON_13, - GODOT_JOY_DPAD_LEFT = GODOT_JOY_BUTTON_14, - GODOT_JOY_DPAD_RIGHT = GODOT_JOY_BUTTON_15, - - // a little history about game controllers (who copied who) - - GODOT_JOY_SNES_B = GODOT_JOY_BUTTON_0, - GODOT_JOY_SNES_A = GODOT_JOY_BUTTON_1, - GODOT_JOY_SNES_Y = GODOT_JOY_BUTTON_2, - GODOT_JOY_SNES_X = GODOT_JOY_BUTTON_3, - - GODOT_JOY_SONY_CIRCLE = GODOT_JOY_SNES_A, - GODOT_JOY_SONY_X = GODOT_JOY_SNES_B, - GODOT_JOY_SONY_SQUARE = GODOT_JOY_SNES_Y, - GODOT_JOY_SONY_TRIANGLE = GODOT_JOY_SNES_X, - - GODOT_JOY_SEGA_B = GODOT_JOY_SNES_A, - GODOT_JOY_SEGA_A = GODOT_JOY_SNES_B, - GODOT_JOY_SEGA_X = GODOT_JOY_SNES_Y, - GODOT_JOY_SEGA_Y = GODOT_JOY_SNES_X, - - GODOT_JOY_XBOX_B = GODOT_JOY_SEGA_B, - GODOT_JOY_XBOX_A = GODOT_JOY_SEGA_A, - GODOT_JOY_XBOX_X = GODOT_JOY_SEGA_X, - GODOT_JOY_XBOX_Y = GODOT_JOY_SEGA_Y, - - GODOT_JOY_DS_A = GODOT_JOY_SNES_A, - GODOT_JOY_DS_B = GODOT_JOY_SNES_B, - GODOT_JOY_DS_X = GODOT_JOY_SNES_X, - GODOT_JOY_DS_Y = GODOT_JOY_SNES_Y, - - GODOT_JOY_WII_C = GODOT_JOY_BUTTON_5, - GODOT_JOY_WII_Z = GODOT_JOY_BUTTON_6, - - GODOT_JOY_WII_MINUS = GODOT_JOY_BUTTON_9, - GODOT_JOY_WII_PLUS = GODOT_JOY_BUTTON_10, - - // end of history - - GODOT_JOY_AXIS_0 = 0, - GODOT_JOY_AXIS_1 = 1, - GODOT_JOY_AXIS_2 = 2, - GODOT_JOY_AXIS_3 = 3, - GODOT_JOY_AXIS_4 = 4, - GODOT_JOY_AXIS_5 = 5, - GODOT_JOY_AXIS_6 = 6, - GODOT_JOY_AXIS_7 = 7, - GODOT_JOY_AXIS_MAX = 8, - - GODOT_JOY_ANALOG_0_X = GODOT_JOY_AXIS_0, - GODOT_JOY_ANALOG_0_Y = GODOT_JOY_AXIS_1, - - GODOT_JOY_ANALOG_1_X = GODOT_JOY_AXIS_2, - GODOT_JOY_ANALOG_1_Y = GODOT_JOY_AXIS_3, - - GODOT_JOY_ANALOG_2_X = GODOT_JOY_AXIS_4, - GODOT_JOY_ANALOG_2_Y = GODOT_JOY_AXIS_5, - - GODOT_JOY_ANALOG_L2 = GODOT_JOY_AXIS_6, - GODOT_JOY_ANALOG_R2 = GODOT_JOY_AXIS_7, -}; - -#include "../godot.h" - -void GDAPI godot_input_event_new(godot_input_event *p_ie); - -godot_bool GDAPI godot_input_event_is_pressed(const godot_input_event *p_ie); -godot_bool GDAPI godot_input_event_is_action(const godot_input_event *p_ie, const godot_string *p_action); -godot_bool GDAPI godot_input_event_is_action_pressed(const godot_input_event *p_ie, const godot_string *p_action); -godot_bool GDAPI godot_input_event_is_action_released(const godot_input_event *p_ie, const godot_string *p_action); -godot_bool GDAPI godot_input_event_is_echo(const godot_input_event *p_ie); -void GDAPI godot_input_event_set_as_action(godot_input_event *p_ie, const godot_string *p_action, const godot_bool p_pressed); - -godot_string GDAPI godot_input_event_as_string(const godot_input_event *p_ie); - -// Note: -// We're returning pointers to the fields in the unions. -// This is because I'm too lazy to write setter functions - -uint32_t GDAPI *godot_input_event_get_id(godot_input_event *p_ie); -godot_input_event_type GDAPI *godot_input_event_get_type(godot_input_event *p_ie); -godot_int GDAPI *godot_input_event_get_device(godot_input_event *p_ie); - -godot_bool GDAPI *godot_input_event_mod_get_alt(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_mod_get_ctrl(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_mod_get_command(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_mod_get_shift(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_mod_get_meta(godot_input_event *p_event); - -uint32_t GDAPI *godot_input_event_key_get_scancode(godot_input_event *p_event); -uint32_t GDAPI *godot_input_event_key_get_unicode(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_key_get_pressed(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_key_get_echo(godot_input_event *p_event); - -float GDAPI *godot_input_event_mouse_get_x(godot_input_event *p_event); -float GDAPI *godot_input_event_mouse_get_y(godot_input_event *p_event); -float GDAPI *godot_input_event_mouse_get_global_x(godot_input_event *p_event); -float GDAPI *godot_input_event_mouse_get_global_y(godot_input_event *p_event); -godot_int GDAPI *godot_input_event_mouse_get_button_mask(godot_input_event *p_event); - -godot_int GDAPI *godot_input_event_mouse_button_get_button_index(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_mouse_button_get_pressed(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_mouse_button_get_doubleclick(godot_input_event *p_event); - -float GDAPI *godot_input_event_mouse_motion_get_relative_x(godot_input_event *p_event); -float GDAPI *godot_input_event_mouse_motion_get_relative_y(godot_input_event *p_event); -float GDAPI *godot_input_event_mouse_motion_get_speed_x(godot_input_event *p_event); -float GDAPI *godot_input_event_mouse_motion_get_speed_y(godot_input_event *p_event); - -godot_int GDAPI *godot_input_event_joypad_motion_get_axis(godot_input_event *p_event); -float GDAPI *godot_input_event_joypad_motion_get_axis_value(godot_input_event *p_event); - -godot_int GDAPI *godot_input_event_joypad_button_get_button_index(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_joypad_button_get_pressed(godot_input_event *p_event); -float GDAPI *godot_input_event_joypad_button_get_pressure(godot_input_event *p_event); - -godot_int GDAPI *godot_input_event_screen_touch_get_index(godot_input_event *p_event); -float GDAPI *godot_input_event_screen_touch_get_x(godot_input_event *p_event); -float GDAPI *godot_input_event_screen_touch_get_y(godot_input_event *p_event); -godot_bool GDAPI *godot_input_event_screen_touch_get_pressed(godot_input_event *p_event); - -godot_int GDAPI *godot_input_event_screen_drag_get_index(godot_input_event *p_event); -float GDAPI *godot_input_event_screen_drag_get_x(godot_input_event *p_event); -float GDAPI *godot_input_event_screen_drag_get_y(godot_input_event *p_event); -float GDAPI *godot_input_event_screen_drag_get_relative_x(godot_input_event *p_event); -float GDAPI *godot_input_event_screen_drag_get_relative_y(godot_input_event *p_event); -float GDAPI *godot_input_event_screen_drag_get_speed_x(godot_input_event *p_event); -float GDAPI *godot_input_event_screen_drag_get_speed_y(godot_input_event *p_event); - -#ifdef __cplusplus -} -#endif - -#endif // GODOT_INPUT_EVENT_H diff --git a/modules/gdnative/godot/godot_node_path.cpp b/modules/gdnative/godot/godot_node_path.cpp index a2c9e11699..c8eacd05af 100644 --- a/modules/gdnative/godot/godot_node_path.cpp +++ b/modules/gdnative/godot/godot_node_path.cpp @@ -28,91 +28,87 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_node_path.h" +#include "core/variant.h" -#include "path_db.h" +#include "core/path_db.h" #ifdef __cplusplus extern "C" { #endif -void _node_path_api_anchor() { -} - -#define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) +void _node_path_api_anchor() {} -// @Bug ? -// Do I need to memnew_placement when returning strings? +void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from) { + NodePath *dest = (NodePath *)r_dest; + const String *from = (const String *)p_from; + memnew_placement(dest, NodePath(*from)); +} -void GDAPI godot_node_path_new(godot_node_path *p_np, const godot_string *p_from) { - NodePath *np = (NodePath *)p_np; - String *from = (String *)p_from; - memnew_placement_custom(np, NodePath, NodePath(*from)); +void GDAPI godot_node_path_new_copy(godot_node_path *r_dest, const godot_node_path *p_src) { + NodePath *dest = (NodePath *)r_dest; + const NodePath *src = (const NodePath *)p_src; + memnew_placement(dest, NodePath(*src)); } -void GDAPI godot_node_path_copy(godot_node_path *p_np, const godot_node_path *p_from) { - NodePath *np = (NodePath *)p_np; - NodePath *from = (NodePath *)p_from; - *np = *from; +void GDAPI godot_node_path_destroy(godot_node_path *p_self) { + NodePath *self = (NodePath *)p_self; + self->~NodePath(); } -godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_np, const godot_int p_idx) { - const NodePath *np = (const NodePath *)p_np; - godot_string str; - String *s = (String *)&str; - memnew_placement(s, String); - *s = np->get_name(p_idx); - return str; +godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_self) { + godot_string ret; + const NodePath *self = (const NodePath *)p_self; + memnew_placement(&ret, String(*self)); + return ret; } -godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_np) { - const NodePath *np = (const NodePath *)p_np; - return np->get_name_count(); +godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_self) { + const NodePath *self = (const NodePath *)p_self; + return self->is_absolute(); } -godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_np) { - const NodePath *np = (const NodePath *)p_np; - godot_string str; - String *s = (String *)&str; - memnew_placement(s, String); - *s = np->get_property(); - return str; +godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_self) { + const NodePath *self = (const NodePath *)p_self; + return self->get_name_count(); } -godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_np, const godot_int p_idx) { - const NodePath *np = (const NodePath *)p_np; - godot_string str; - String *s = (String *)&str; - memnew_placement(s, String); - *s = np->get_subname(p_idx); - return str; +godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_self, const godot_int p_idx) { + godot_string dest; + const NodePath *self = (const NodePath *)p_self; + + memnew_placement(&dest, String(self->get_name(p_idx))); + return dest; } -godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_np) { - const NodePath *np = (const NodePath *)p_np; - return np->get_subname_count(); +godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_self) { + const NodePath *self = (const NodePath *)p_self; + return self->get_subname_count(); } -godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_np) { - const NodePath *np = (const NodePath *)p_np; - return np->is_absolute(); +godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, const godot_int p_idx) { + godot_string dest; + const NodePath *self = (const NodePath *)p_self; + + memnew_placement(&dest, String(self->get_subname(p_idx))); + return dest; } -godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_np) { - const NodePath *np = (const NodePath *)p_np; - return np->is_empty(); +godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self) { + godot_string dest; + const NodePath *self = (const NodePath *)p_self; + memnew_placement(&dest, String(self->get_property())); + return dest; } -godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_np) { - const NodePath *np = (const NodePath *)p_np; - godot_string str; - String *s = (String *)&str; - memnew_placement(s, String); - *s = *np; - return str; +godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_self) { + const NodePath *self = (const NodePath *)p_self; + return self->is_empty(); } -void GDAPI godot_node_path_destroy(godot_node_path *p_np) { - ((NodePath *)p_np)->~NodePath(); +godot_bool GDAPI godot_node_path_operator_equal(const godot_node_path *p_self, const godot_node_path *p_b) { + const NodePath *self = (const NodePath *)p_self; + const NodePath *b = (const NodePath *)p_b; + return *self == *b; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_node_path.h b/modules/gdnative/godot/godot_node_path.h index c5f313d190..b0c9d44859 100644 --- a/modules/gdnative/godot/godot_node_path.h +++ b/modules/gdnative/godot/godot_node_path.h @@ -37,29 +37,36 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_NODE_PATH_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_NODE_PATH_TYPE_DEFINED typedef struct godot_node_path { uint8_t _dont_touch_that[8]; } godot_node_path; #endif #include "../godot.h" +#include "godot_string.h" -void GDAPI godot_node_path_new(godot_node_path *p_np, const godot_string *p_from); -void GDAPI godot_node_path_copy(godot_node_path *p_np, const godot_node_path *p_from); +void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from); +void GDAPI godot_node_path_new_copy(godot_node_path *r_dest, const godot_node_path *p_src); +void GDAPI godot_node_path_destroy(godot_node_path *p_self); -godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_np, const godot_int p_idx); -godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_np); +godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_self); -godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_np); -godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_np, const godot_int p_idx); -godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_np); +godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_self); -godot_bool GDAPI godot_node_path_is_absolute(const godot_node_path *p_np); -godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_np); +godot_int GDAPI godot_node_path_get_name_count(const godot_node_path *p_self); -godot_string GDAPI godot_node_path_as_string(const godot_node_path *p_np); +godot_string GDAPI godot_node_path_get_name(const godot_node_path *p_self, const godot_int p_idx); -void GDAPI godot_node_path_destroy(godot_node_path *p_np); +godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_self); + +godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, const godot_int p_idx); + +godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self); + +godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_self); + +godot_bool GDAPI godot_node_path_operator_equal(const godot_node_path *p_self, const godot_node_path *p_b); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_plane.cpp b/modules/gdnative/godot/godot_plane.cpp index 38329ef709..68adbd4a98 100644 --- a/modules/gdnative/godot/godot_plane.cpp +++ b/modules/gdnative/godot/godot_plane.cpp @@ -28,48 +28,149 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_plane.h" +#include "core/variant.h" -#include "math/plane.h" +#include "core/math/plane.h" #ifdef __cplusplus extern "C" { #endif -void _plane_api_anchor() { +void _plane_api_anchor() {} + +void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d) { + + Plane *dest = (Plane *)r_dest; + *dest = Plane(p_a, p_b, p_c, p_d); } -void GDAPI godot_plane_new(godot_plane *p_pl) { - Plane *pl = (Plane *)p_pl; - *pl = Plane(); +void GDAPI godot_plane_new_with_vectors(godot_plane *r_dest, const godot_vector3 *p_v1, const godot_vector3 *p_v2, const godot_vector3 *p_v3) { + const Vector3 *v1 = (const Vector3 *)p_v1; + const Vector3 *v2 = (const Vector3 *)p_v2; + const Vector3 *v3 = (const Vector3 *)p_v3; + Plane *dest = (Plane *)r_dest; + *dest = Plane(*v1, *v2, *v3); } -void GDAPI godot_plane_new_with_normal(godot_plane *p_pl, const godot_vector3 *p_normal, const godot_real p_d) { - Plane *pl = (Plane *)p_pl; +void GDAPI godot_plane_new_with_normal(godot_plane *r_dest, const godot_vector3 *p_normal, const godot_real p_d) { const Vector3 *normal = (const Vector3 *)p_normal; - *pl = Plane(*normal, p_d); + Plane *dest = (Plane *)r_dest; + *dest = Plane(*normal, p_d); +} + +godot_string GDAPI godot_plane_as_string(const godot_plane *p_self) { + godot_string ret; + const Plane *self = (const Plane *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_plane GDAPI godot_plane_normalized(const godot_plane *p_self) { + godot_plane dest; + const Plane *self = (const Plane *)p_self; + *((Plane *)&dest) = self->normalized(); + return dest; +} + +godot_vector3 GDAPI godot_plane_center(const godot_plane *p_self) { + godot_vector3 dest; + const Plane *self = (const Plane *)p_self; + *((Vector3 *)&dest) = self->center(); + return dest; +} + +godot_vector3 GDAPI godot_plane_get_any_point(const godot_plane *p_self) { + godot_vector3 dest; + const Plane *self = (const Plane *)p_self; + *((Vector3 *)&dest) = self->get_any_point(); + return dest; +} + +godot_bool GDAPI godot_plane_is_point_over(const godot_plane *p_self, const godot_vector3 *p_point) { + const Plane *self = (const Plane *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + return self->is_point_over(*point); +} + +godot_real GDAPI godot_plane_distance_to(const godot_plane *p_self, const godot_vector3 *p_point) { + const Plane *self = (const Plane *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + return self->distance_to(*point); +} + +godot_bool GDAPI godot_plane_has_point(const godot_plane *p_self, const godot_vector3 *p_point, const godot_real p_epsilon) { + const Plane *self = (const Plane *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + return self->has_point(*point, p_epsilon); +} + +godot_vector3 GDAPI godot_plane_project(const godot_plane *p_self, const godot_vector3 *p_point) { + godot_vector3 dest; + const Plane *self = (const Plane *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + *((Vector3 *)&dest) = self->project(*point); + return dest; +} + +godot_bool GDAPI godot_plane_intersect_3(const godot_plane *p_self, godot_vector3 *r_dest, const godot_plane *p_b, const godot_plane *p_c) { + const Plane *self = (const Plane *)p_self; + const Plane *b = (const Plane *)p_b; + const Plane *c = (const Plane *)p_c; + Vector3 *dest = (Vector3 *)r_dest; + return self->intersect_3(*b, *c, dest); +} + +godot_bool GDAPI godot_plane_intersects_ray(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_from, const godot_vector3 *p_dir) { + const Plane *self = (const Plane *)p_self; + const Vector3 *from = (const Vector3 *)p_from; + const Vector3 *dir = (const Vector3 *)p_dir; + Vector3 *dest = (Vector3 *)r_dest; + return self->intersects_ray(*from, *dir, dest); +} + +godot_bool GDAPI godot_plane_intersects_segment(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_begin, const godot_vector3 *p_end) { + const Plane *self = (const Plane *)p_self; + const Vector3 *begin = (const Vector3 *)p_begin; + const Vector3 *end = (const Vector3 *)p_end; + Vector3 *dest = (Vector3 *)r_dest; + return self->intersects_segment(*begin, *end, dest); +} + +godot_plane GDAPI godot_plane_operator_neg(const godot_plane *p_self) { + godot_plane raw_dest; + Plane *dest = (Plane *)&raw_dest; + const Plane *self = (const Plane *)p_self; + *dest = -(*self); + return raw_dest; +} + +godot_bool GDAPI godot_plane_operator_equal(const godot_plane *p_self, const godot_plane *p_b) { + const Plane *self = (const Plane *)p_self; + const Plane *b = (const Plane *)p_b; + return *self == *b; } -void GDAPI godot_plane_set_normal(godot_plane *p_pl, const godot_vector3 *p_normal) { - Plane *pl = (Plane *)p_pl; +void GDAPI godot_plane_set_normal(godot_plane *p_self, const godot_vector3 *p_normal) { + Plane *self = (Plane *)p_self; const Vector3 *normal = (const Vector3 *)p_normal; - pl->set_normal(*normal); + self->set_normal(*normal); } -godot_vector3 godot_plane_get_normal(const godot_plane *p_pl) { - const Plane *pl = (const Plane *)p_pl; - const Vector3 normal = pl->get_normal(); +godot_vector3 GDAPI godot_plane_get_normal(const godot_plane *p_self) { + const Plane *self = (const Plane *)p_self; + const Vector3 normal = self->get_normal(); godot_vector3 *v3 = (godot_vector3 *)&normal; return *v3; } -void GDAPI godot_plane_set_d(godot_plane *p_pl, const godot_real p_d) { - Plane *pl = (Plane *)p_pl; - pl->d = p_d; +godot_real GDAPI godot_plane_get_d(const godot_plane *p_self) { + const Plane *self = (const Plane *)p_self; + return self->d; } -godot_real GDAPI godot_plane_get_d(const godot_plane *p_pl) { - const Plane *pl = (const Plane *)p_pl; - return pl->d; +void GDAPI godot_plane_set_d(godot_plane *p_self, const godot_real p_d) { + Plane *self = (Plane *)p_self; + self->d = p_d; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_plane.h b/modules/gdnative/godot/godot_plane.h index c98e45c9cb..cfc955f277 100644 --- a/modules/gdnative/godot/godot_plane.h +++ b/modules/gdnative/godot/godot_plane.h @@ -37,27 +37,52 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED typedef struct godot_plane { uint8_t _dont_touch_that[16]; } godot_plane; #endif +#include "../godot.h" #include "godot_vector3.h" -void GDAPI godot_plane_new(godot_plane *p_pl); -void GDAPI godot_plane_new_with_normal(godot_plane *p_pl, const godot_vector3 *p_normal, const godot_real p_d); +void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d); +void GDAPI godot_plane_new_with_vectors(godot_plane *r_dest, const godot_vector3 *p_v1, const godot_vector3 *p_v2, const godot_vector3 *p_v3); +void GDAPI godot_plane_new_with_normal(godot_plane *r_dest, const godot_vector3 *p_normal, const godot_real p_d); -// @Incomplete -// These are additional valid constructors -// _FORCE_INLINE_ Plane(const Vector3 &p_normal, real_t p_d); -// _FORCE_INLINE_ Plane(const Vector3 &p_point, const Vector3& p_normal); -// _FORCE_INLINE_ Plane(const Vector3 &p_point1, const Vector3 &p_point2,const Vector3 &p_point3,ClockDirection p_dir = CLOCKWISE); +godot_string GDAPI godot_plane_as_string(const godot_plane *p_self); -void GDAPI godot_plane_set_normal(godot_plane *p_pl, const godot_vector3 *p_normal); -godot_vector3 GDAPI godot_plane_get_normal(const godot_plane *p_pl); +godot_plane GDAPI godot_plane_normalized(const godot_plane *p_self); -godot_real GDAPI godot_plane_get_d(const godot_plane *p_pl); -void GDAPI godot_plane_set_d(godot_plane *p_pl, const godot_real p_d); +godot_vector3 GDAPI godot_plane_center(const godot_plane *p_self); + +godot_vector3 GDAPI godot_plane_get_any_point(const godot_plane *p_self); + +godot_bool GDAPI godot_plane_is_point_over(const godot_plane *p_self, const godot_vector3 *p_point); + +godot_real GDAPI godot_plane_distance_to(const godot_plane *p_self, const godot_vector3 *p_point); + +godot_bool GDAPI godot_plane_has_point(const godot_plane *p_self, const godot_vector3 *p_point, const godot_real p_epsilon); + +godot_vector3 GDAPI godot_plane_project(const godot_plane *p_self, const godot_vector3 *p_point); + +godot_bool GDAPI godot_plane_intersect_3(const godot_plane *p_self, godot_vector3 *r_dest, const godot_plane *p_b, const godot_plane *p_c); + +godot_bool GDAPI godot_plane_intersects_ray(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_from, const godot_vector3 *p_dir); + +godot_bool GDAPI godot_plane_intersects_segment(const godot_plane *p_self, godot_vector3 *r_dest, const godot_vector3 *p_begin, const godot_vector3 *p_end); + +godot_plane GDAPI godot_plane_operator_neg(const godot_plane *p_self); + +godot_bool GDAPI godot_plane_operator_equal(const godot_plane *p_self, const godot_plane *p_b); + +void GDAPI godot_plane_set_normal(godot_plane *p_self, const godot_vector3 *p_normal); + +godot_vector3 GDAPI godot_plane_get_normal(const godot_plane *p_self); + +godot_real GDAPI godot_plane_get_d(const godot_plane *p_self); + +void GDAPI godot_plane_set_d(godot_plane *p_self, const godot_real p_d); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_pool_arrays.cpp b/modules/gdnative/godot/godot_pool_arrays.cpp index 93e9a9e9dc..ea9aceea81 100644 --- a/modules/gdnative/godot/godot_pool_arrays.cpp +++ b/modules/gdnative/godot/godot_pool_arrays.cpp @@ -44,542 +44,584 @@ void _pool_arrays_api_anchor() { // byte -void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - memnew_placement(pba, PoolVector<uint8_t>); +void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *r_dest) { + PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)r_dest; + memnew_placement(dest, PoolVector<uint8_t>); } -void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *r_dest, const godot_pool_byte_array *p_src) { + PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)r_dest; + const PoolVector<uint8_t> *src = (const PoolVector<uint8_t> *)p_src; + memnew_placement(dest, PoolVector<uint8_t>(*src)); +} + +void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *r_dest, const godot_array *p_a) { + PoolVector<uint8_t> *dest = (PoolVector<uint8_t> *)r_dest; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<uint8_t>); + memnew_placement(dest, PoolVector<uint8_t>); - pba->resize(a->size()); + dest->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { - pba->set(i, (*a)[i]); + dest->set(i, (*a)[i]); } } -void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_pba, const uint8_t p_data) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - pba->append(p_data); +void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_self, const uint8_t p_data) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->append(p_data); } -void GDAPI godot_pool_byte_array_append_array(godot_pool_byte_array *p_pba, const godot_pool_byte_array *p_array) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; +void GDAPI godot_pool_byte_array_append_array(godot_pool_byte_array *p_self, const godot_pool_byte_array *p_array) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; PoolVector<uint8_t> *array = (PoolVector<uint8_t> *)p_array; - pba->append_array(*array); + self->append_array(*array); } -int GDAPI godot_pool_byte_array_insert(godot_pool_byte_array *p_pba, const godot_int p_idx, const uint8_t p_data) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - return pba->insert(p_idx, p_data); +godot_error GDAPI godot_pool_byte_array_insert(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + return (godot_error)self->insert(p_idx, p_data); } -void GDAPI godot_pool_byte_array_invert(godot_pool_byte_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - pba->invert(); +void GDAPI godot_pool_byte_array_invert(godot_pool_byte_array *p_self) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->invert(); } -void GDAPI godot_pool_byte_array_push_back(godot_pool_byte_array *p_pba, const uint8_t p_data) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - pba->push_back(p_data); +void GDAPI godot_pool_byte_array_push_back(godot_pool_byte_array *p_self, const uint8_t p_data) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->push_back(p_data); } -void GDAPI godot_pool_byte_array_remove(godot_pool_byte_array *p_pba, const godot_int p_idx) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - pba->remove(p_idx); +void GDAPI godot_pool_byte_array_remove(godot_pool_byte_array *p_self, const godot_int p_idx) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->remove(p_idx); } -void GDAPI godot_pool_byte_array_resize(godot_pool_byte_array *p_pba, const godot_int p_size) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - pba->resize(p_size); +void GDAPI godot_pool_byte_array_resize(godot_pool_byte_array *p_self, const godot_int p_size) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->resize(p_size); } -void GDAPI godot_pool_byte_array_set(godot_pool_byte_array *p_pba, const godot_int p_idx, const uint8_t p_data) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - pba->set(p_idx, p_data); +void GDAPI godot_pool_byte_array_set(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data) { + PoolVector<uint8_t> *self = (PoolVector<uint8_t> *)p_self; + self->set(p_idx, p_data); } -uint8_t GDAPI godot_pool_byte_array_get(godot_pool_byte_array *p_pba, const godot_int p_idx) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - return pba->get(p_idx); +uint8_t GDAPI godot_pool_byte_array_get(const godot_pool_byte_array *p_self, const godot_int p_idx) { + const PoolVector<uint8_t> *self = (const PoolVector<uint8_t> *)p_self; + return self->get(p_idx); } -godot_int GDAPI godot_pool_byte_array_size(godot_pool_byte_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - return pba->size(); +godot_int GDAPI godot_pool_byte_array_size(const godot_pool_byte_array *p_self) { + const PoolVector<uint8_t> *self = (const PoolVector<uint8_t> *)p_self; + return self->size(); } -void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba) { - ((PoolVector<uint8_t> *)p_pba)->~PoolVector(); +void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_self) { + ((PoolVector<uint8_t> *)p_self)->~PoolVector(); } // int -void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - memnew_placement(pba, PoolVector<uint8_t>); +void GDAPI godot_pool_int_array_new(godot_pool_int_array *r_dest) { + PoolVector<godot_int> *dest = (PoolVector<godot_int> *)r_dest; + memnew_placement(dest, PoolVector<godot_int>); +} + +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *r_dest, const godot_pool_int_array *p_src) { + PoolVector<godot_int> *dest = (PoolVector<godot_int> *)r_dest; + const PoolVector<godot_int> *src = (const PoolVector<godot_int> *)p_src; + memnew_placement(dest, PoolVector<godot_int>(*src)); } -void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pba, const godot_array *p_a) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; +void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *r_dest, const godot_array *p_a) { + PoolVector<godot_int> *dest = (PoolVector<godot_int> *)r_dest; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<uint8_t>); + memnew_placement(dest, PoolVector<godot_int>); - pba->resize(a->size()); + dest->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { - pba->set(i, (*a)[i]); + dest->set(i, (*a)[i]); } } -void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_pba, const godot_int p_data) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - pba->append(p_data); +void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_self, const godot_int p_data) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->append(p_data); } -void GDAPI godot_pool_int_array_append_array(godot_pool_int_array *p_pba, const godot_pool_int_array *p_array) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; +void GDAPI godot_pool_int_array_append_array(godot_pool_int_array *p_self, const godot_pool_int_array *p_array) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; PoolVector<godot_int> *array = (PoolVector<godot_int> *)p_array; - pba->append_array(*array); + self->append_array(*array); } -int GDAPI godot_pool_int_array_insert(godot_pool_int_array *p_pba, const godot_int p_idx, const godot_int p_data) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - return pba->insert(p_idx, p_data); +godot_error GDAPI godot_pool_int_array_insert(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + return (godot_error)self->insert(p_idx, p_data); } -void GDAPI godot_pool_int_array_invert(godot_pool_int_array *p_pba) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - pba->invert(); +void GDAPI godot_pool_int_array_invert(godot_pool_int_array *p_self) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->invert(); } -void GDAPI godot_pool_int_array_push_back(godot_pool_int_array *p_pba, const godot_int p_data) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - pba->push_back(p_data); +void GDAPI godot_pool_int_array_push_back(godot_pool_int_array *p_self, const godot_int p_data) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->push_back(p_data); } -void GDAPI godot_pool_int_array_remove(godot_pool_int_array *p_pba, const godot_int p_idx) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - pba->remove(p_idx); +void GDAPI godot_pool_int_array_remove(godot_pool_int_array *p_self, const godot_int p_idx) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->remove(p_idx); } -void GDAPI godot_pool_int_array_resize(godot_pool_int_array *p_pba, const godot_int p_size) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - pba->resize(p_size); +void GDAPI godot_pool_int_array_resize(godot_pool_int_array *p_self, const godot_int p_size) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->resize(p_size); } -void GDAPI godot_pool_int_array_set(godot_pool_int_array *p_pba, const godot_int p_idx, const godot_int p_data) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - pba->set(p_idx, p_data); +void GDAPI godot_pool_int_array_set(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->set(p_idx, p_data); } -godot_int GDAPI godot_pool_int_array_get(godot_pool_int_array *p_pba, const godot_int p_idx) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - return pba->get(p_idx); +godot_int GDAPI godot_pool_int_array_get(const godot_pool_int_array *p_self, const godot_int p_idx) { + const PoolVector<godot_int> *self = (const PoolVector<godot_int> *)p_self; + return self->get(p_idx); } -godot_int GDAPI godot_pool_int_array_size(godot_pool_int_array *p_pba) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - return pba->size(); +godot_int GDAPI godot_pool_int_array_size(const godot_pool_int_array *p_self) { + const PoolVector<godot_int> *self = (const PoolVector<godot_int> *)p_self; + return self->size(); } -void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pba) { - ((PoolVector<godot_int> *)p_pba)->~PoolVector(); +void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_self) { + ((PoolVector<godot_int> *)p_self)->~PoolVector(); } // real -void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pba) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; - memnew_placement(pba, PoolVector<uint8_t>); +void GDAPI godot_pool_real_array_new(godot_pool_real_array *r_dest) { + PoolVector<godot_real> *dest = (PoolVector<godot_real> *)r_dest; + memnew_placement(dest, PoolVector<godot_real>); } -void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pba, const godot_array *p_a) { - PoolVector<uint8_t> *pba = (PoolVector<uint8_t> *)p_pba; +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *r_dest, const godot_pool_real_array *p_src) { + PoolVector<godot_real> *dest = (PoolVector<godot_real> *)r_dest; + const PoolVector<godot_real> *src = (const PoolVector<godot_real> *)p_src; + memnew_placement(dest, PoolVector<godot_real>(*src)); +} + +void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *r_dest, const godot_array *p_a) { + PoolVector<godot_real> *dest = (PoolVector<godot_real> *)r_dest; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<uint8_t>); + memnew_placement(dest, PoolVector<godot_real>); - pba->resize(a->size()); + dest->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { - pba->set(i, (*a)[i]); + dest->set(i, (*a)[i]); } } -void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_pba, const godot_real p_data) { - PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; - pba->append(p_data); +void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_self, const godot_real p_data) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->append(p_data); } -void GDAPI godot_pool_real_array_append_array(godot_pool_real_array *p_pba, const godot_pool_real_array *p_array) { - PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; +void GDAPI godot_pool_real_array_append_array(godot_pool_real_array *p_self, const godot_pool_real_array *p_array) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; PoolVector<godot_real> *array = (PoolVector<godot_real> *)p_array; - pba->append_array(*array); + self->append_array(*array); } -int GDAPI godot_pool_real_array_insert(godot_pool_real_array *p_pba, const godot_int p_idx, const godot_real p_data) { - PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; - return pba->insert(p_idx, p_data); +godot_error GDAPI godot_pool_real_array_insert(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + return (godot_error)self->insert(p_idx, p_data); } -void GDAPI godot_pool_real_array_invert(godot_pool_real_array *p_pba) { - PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; - pba->invert(); +void GDAPI godot_pool_real_array_invert(godot_pool_real_array *p_self) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->invert(); } -void GDAPI godot_pool_real_array_push_back(godot_pool_real_array *p_pba, const godot_real p_data) { - PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; - pba->push_back(p_data); +void GDAPI godot_pool_real_array_push_back(godot_pool_real_array *p_self, const godot_real p_data) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->push_back(p_data); } -void GDAPI godot_pool_real_array_remove(godot_pool_real_array *p_pba, const godot_int p_idx) { - PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; - pba->remove(p_idx); +void GDAPI godot_pool_real_array_remove(godot_pool_real_array *p_self, const godot_int p_idx) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->remove(p_idx); } -void GDAPI godot_pool_real_array_resize(godot_pool_real_array *p_pba, const godot_int p_size) { - PoolVector<godot_int> *pba = (PoolVector<godot_int> *)p_pba; - pba->resize(p_size); +void GDAPI godot_pool_real_array_resize(godot_pool_real_array *p_self, const godot_int p_size) { + PoolVector<godot_int> *self = (PoolVector<godot_int> *)p_self; + self->resize(p_size); } -void GDAPI godot_pool_real_array_set(godot_pool_real_array *p_pba, const godot_int p_idx, const godot_real p_data) { - PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; - pba->set(p_idx, p_data); +void GDAPI godot_pool_real_array_set(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data) { + PoolVector<godot_real> *self = (PoolVector<godot_real> *)p_self; + self->set(p_idx, p_data); } -godot_real GDAPI godot_pool_real_array_get(godot_pool_real_array *p_pba, const godot_int p_idx) { - PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; - return pba->get(p_idx); +godot_real GDAPI godot_pool_real_array_get(const godot_pool_real_array *p_self, const godot_int p_idx) { + const PoolVector<godot_real> *self = (const PoolVector<godot_real> *)p_self; + return self->get(p_idx); } -godot_int GDAPI godot_pool_real_array_size(godot_pool_real_array *p_pba) { - PoolVector<godot_real> *pba = (PoolVector<godot_real> *)p_pba; - return pba->size(); +godot_int GDAPI godot_pool_real_array_size(const godot_pool_real_array *p_self) { + const PoolVector<godot_real> *self = (const PoolVector<godot_real> *)p_self; + return self->size(); } -void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_pba) { - ((PoolVector<godot_real> *)p_pba)->~PoolVector(); +void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_self) { + ((PoolVector<godot_real> *)p_self)->~PoolVector(); } // string -void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_pba) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; - memnew_placement(pba, PoolVector<String>); +void GDAPI godot_pool_string_array_new(godot_pool_string_array *r_dest) { + PoolVector<String> *dest = (PoolVector<String> *)r_dest; + memnew_placement(dest, PoolVector<String>); +} + +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *r_dest, const godot_pool_string_array *p_src) { + PoolVector<String> *dest = (PoolVector<String> *)r_dest; + const PoolVector<String> *src = (const PoolVector<String> *)p_src; + memnew_placement(dest, PoolVector<String>(*src)); } -void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_pba, const godot_array *p_a) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; +void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *r_dest, const godot_array *p_a) { + PoolVector<String> *dest = (PoolVector<String> *)r_dest; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<String>); + memnew_placement(dest, PoolVector<String>); - pba->resize(a->size()); + dest->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { - pba->set(i, (*a)[i]); + dest->set(i, (*a)[i]); } } -void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_pba, const godot_string *p_data) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; +void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_self, const godot_string *p_data) { + PoolVector<String> *self = (PoolVector<String> *)p_self; String &s = *(String *)p_data; - pba->append(s); + self->append(s); } -void GDAPI godot_pool_string_array_append_array(godot_pool_string_array *p_pba, const godot_pool_string_array *p_array) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; +void GDAPI godot_pool_string_array_append_array(godot_pool_string_array *p_self, const godot_pool_string_array *p_array) { + PoolVector<String> *self = (PoolVector<String> *)p_self; PoolVector<String> *array = (PoolVector<String> *)p_array; - pba->append_array(*array); + self->append_array(*array); } -int GDAPI godot_pool_string_array_insert(godot_pool_string_array *p_pba, const godot_int p_idx, const godot_string *p_data) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; +godot_error GDAPI godot_pool_string_array_insert(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data) { + PoolVector<String> *self = (PoolVector<String> *)p_self; String &s = *(String *)p_data; - return pba->insert(p_idx, s); + return (godot_error)self->insert(p_idx, s); } -void GDAPI godot_pool_string_array_invert(godot_pool_string_array *p_pba) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; - pba->invert(); +void GDAPI godot_pool_string_array_invert(godot_pool_string_array *p_self) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + self->invert(); } -void GDAPI godot_pool_string_array_push_back(godot_pool_string_array *p_pba, const godot_string *p_data) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; +void GDAPI godot_pool_string_array_push_back(godot_pool_string_array *p_self, const godot_string *p_data) { + PoolVector<String> *self = (PoolVector<String> *)p_self; String &s = *(String *)p_data; - pba->push_back(s); + self->push_back(s); } -void GDAPI godot_pool_string_array_remove(godot_pool_string_array *p_pba, const godot_int p_idx) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; - pba->remove(p_idx); +void GDAPI godot_pool_string_array_remove(godot_pool_string_array *p_self, const godot_int p_idx) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + self->remove(p_idx); } -void GDAPI godot_pool_string_array_resize(godot_pool_string_array *p_pba, const godot_int p_size) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; - pba->resize(p_size); +void GDAPI godot_pool_string_array_resize(godot_pool_string_array *p_self, const godot_int p_size) { + PoolVector<String> *self = (PoolVector<String> *)p_self; + self->resize(p_size); } -void GDAPI godot_pool_string_array_set(godot_pool_string_array *p_pba, const godot_int p_idx, const godot_string *p_data) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; +void GDAPI godot_pool_string_array_set(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data) { + PoolVector<String> *self = (PoolVector<String> *)p_self; String &s = *(String *)p_data; - pba->set(p_idx, s); + self->set(p_idx, s); } -godot_string GDAPI godot_pool_string_array_get(godot_pool_string_array *p_pba, const godot_int p_idx) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; +godot_string GDAPI godot_pool_string_array_get(const godot_pool_string_array *p_self, const godot_int p_idx) { + const PoolVector<String> *self = (const PoolVector<String> *)p_self; godot_string str; String *s = (String *)&str; memnew_placement(s, String); - *s = pba->get(p_idx); + *s = self->get(p_idx); return str; } -godot_int GDAPI godot_pool_string_array_size(godot_pool_string_array *p_pba) { - PoolVector<String> *pba = (PoolVector<String> *)p_pba; - return pba->size(); +godot_int GDAPI godot_pool_string_array_size(const godot_pool_string_array *p_self) { + const PoolVector<String> *self = (const PoolVector<String> *)p_self; + return self->size(); } -void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_pba) { - ((PoolVector<String> *)p_pba)->~PoolVector(); +void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_self) { + ((PoolVector<String> *)p_self)->~PoolVector(); } // vector2 -void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pba) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; - memnew_placement(pba, PoolVector<Vector2>); +void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *r_dest) { + PoolVector<Vector2> *dest = (PoolVector<Vector2> *)r_dest; + memnew_placement(dest, PoolVector<Vector2>); +} + +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *r_dest, const godot_pool_vector2_array *p_src) { + PoolVector<Vector2> *dest = (PoolVector<Vector2> *)r_dest; + const PoolVector<Vector2> *src = (const PoolVector<Vector2> *)p_src; + memnew_placement(dest, PoolVector<Vector2>(*src)); } -void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pba, const godot_array *p_a) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; +void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *r_dest, const godot_array *p_a) { + PoolVector<Vector2> *dest = (PoolVector<Vector2> *)r_dest; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<Vector2>); + memnew_placement(dest, PoolVector<Vector2>); - pba->resize(a->size()); + dest->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { - pba->set(i, (*a)[i]); + dest->set(i, (*a)[i]); } } -void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_pba, const godot_vector2 *p_data) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; +void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_self, const godot_vector2 *p_data) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; Vector2 &s = *(Vector2 *)p_data; - pba->append(s); + self->append(s); } -void GDAPI godot_pool_vector2_array_append_array(godot_pool_vector2_array *p_pba, const godot_pool_vector2_array *p_array) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; +void GDAPI godot_pool_vector2_array_append_array(godot_pool_vector2_array *p_self, const godot_pool_vector2_array *p_array) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; PoolVector<Vector2> *array = (PoolVector<Vector2> *)p_array; - pba->append_array(*array); + self->append_array(*array); } -int GDAPI godot_pool_vector2_array_insert(godot_pool_vector2_array *p_pba, const godot_int p_idx, const godot_vector2 *p_data) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; +godot_error GDAPI godot_pool_vector2_array_insert(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; Vector2 &s = *(Vector2 *)p_data; - return pba->insert(p_idx, s); + return (godot_error)self->insert(p_idx, s); } -void GDAPI godot_pool_vector2_array_invert(godot_pool_vector2_array *p_pba) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; - pba->invert(); +void GDAPI godot_pool_vector2_array_invert(godot_pool_vector2_array *p_self) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + self->invert(); } -void GDAPI godot_pool_vector2_array_push_back(godot_pool_vector2_array *p_pba, const godot_vector2 *p_data) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; +void GDAPI godot_pool_vector2_array_push_back(godot_pool_vector2_array *p_self, const godot_vector2 *p_data) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; Vector2 &s = *(Vector2 *)p_data; - pba->push_back(s); + self->push_back(s); } -void GDAPI godot_pool_vector2_array_remove(godot_pool_vector2_array *p_pba, const godot_int p_idx) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; - pba->remove(p_idx); +void GDAPI godot_pool_vector2_array_remove(godot_pool_vector2_array *p_self, const godot_int p_idx) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + self->remove(p_idx); } -void GDAPI godot_pool_vector2_array_resize(godot_pool_vector2_array *p_pba, const godot_int p_size) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; - pba->resize(p_size); +void GDAPI godot_pool_vector2_array_resize(godot_pool_vector2_array *p_self, const godot_int p_size) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; + self->resize(p_size); } -void GDAPI godot_pool_vector2_array_set(godot_pool_vector2_array *p_pba, const godot_int p_idx, const godot_vector2 *p_data) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; +void GDAPI godot_pool_vector2_array_set(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data) { + PoolVector<Vector2> *self = (PoolVector<Vector2> *)p_self; Vector2 &s = *(Vector2 *)p_data; - pba->set(p_idx, s); + self->set(p_idx, s); } -godot_vector2 GDAPI godot_pool_vector2_array_get(godot_pool_vector2_array *p_pba, const godot_int p_idx) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; +godot_vector2 GDAPI godot_pool_vector2_array_get(const godot_pool_vector2_array *p_self, const godot_int p_idx) { + const PoolVector<Vector2> *self = (const PoolVector<Vector2> *)p_self; godot_vector2 v; Vector2 *s = (Vector2 *)&v; - *s = pba->get(p_idx); + *s = self->get(p_idx); return v; } -godot_int GDAPI godot_pool_vector2_array_size(godot_pool_vector2_array *p_pba) { - PoolVector<Vector2> *pba = (PoolVector<Vector2> *)p_pba; - return pba->size(); +godot_int GDAPI godot_pool_vector2_array_size(const godot_pool_vector2_array *p_self) { + const PoolVector<Vector2> *self = (const PoolVector<Vector2> *)p_self; + return self->size(); } -void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_pba) { - ((PoolVector<Vector2> *)p_pba)->~PoolVector(); +void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_self) { + ((PoolVector<Vector2> *)p_self)->~PoolVector(); } // vector3 -void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pba) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; - memnew_placement(pba, PoolVector<Vector3>); +void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *r_dest) { + PoolVector<Vector3> *dest = (PoolVector<Vector3> *)r_dest; + memnew_placement(dest, PoolVector<Vector3>); } -void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pba, const godot_array *p_a) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *r_dest, const godot_pool_vector3_array *p_src) { + PoolVector<Vector3> *dest = (PoolVector<Vector3> *)r_dest; + const PoolVector<Vector3> *src = (const PoolVector<Vector3> *)p_src; + memnew_placement(dest, PoolVector<Vector3>(*src)); +} + +void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *r_dest, const godot_array *p_a) { + PoolVector<Vector3> *dest = (PoolVector<Vector3> *)r_dest; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<Vector3>); + memnew_placement(dest, PoolVector<Vector3>); - pba->resize(a->size()); + dest->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { - pba->set(i, (*a)[i]); + dest->set(i, (*a)[i]); } } -void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_pba, const godot_vector3 *p_data) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; +void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_self, const godot_vector3 *p_data) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; Vector3 &s = *(Vector3 *)p_data; - pba->append(s); + self->append(s); } -void GDAPI godot_pool_vector3_array_append_array(godot_pool_vector3_array *p_pba, const godot_pool_vector3_array *p_array) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; +void GDAPI godot_pool_vector3_array_append_array(godot_pool_vector3_array *p_self, const godot_pool_vector3_array *p_array) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; PoolVector<Vector3> *array = (PoolVector<Vector3> *)p_array; - pba->append_array(*array); + self->append_array(*array); } -int GDAPI godot_pool_vector3_array_insert(godot_pool_vector3_array *p_pba, const godot_int p_idx, const godot_vector3 *p_data) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; +godot_error GDAPI godot_pool_vector3_array_insert(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; Vector3 &s = *(Vector3 *)p_data; - return pba->insert(p_idx, s); + return (godot_error)self->insert(p_idx, s); } -void GDAPI godot_pool_vector3_array_invert(godot_pool_vector3_array *p_pba) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; - pba->invert(); +void GDAPI godot_pool_vector3_array_invert(godot_pool_vector3_array *p_self) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + self->invert(); } -void GDAPI godot_pool_vector3_array_push_back(godot_pool_vector3_array *p_pba, const godot_vector3 *p_data) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; +void GDAPI godot_pool_vector3_array_push_back(godot_pool_vector3_array *p_self, const godot_vector3 *p_data) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; Vector3 &s = *(Vector3 *)p_data; - pba->push_back(s); + self->push_back(s); } -void GDAPI godot_pool_vector3_array_remove(godot_pool_vector3_array *p_pba, const godot_int p_idx) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; - pba->remove(p_idx); +void GDAPI godot_pool_vector3_array_remove(godot_pool_vector3_array *p_self, const godot_int p_idx) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + self->remove(p_idx); } -void GDAPI godot_pool_vector3_array_resize(godot_pool_vector3_array *p_pba, const godot_int p_size) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; - pba->resize(p_size); +void GDAPI godot_pool_vector3_array_resize(godot_pool_vector3_array *p_self, const godot_int p_size) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; + self->resize(p_size); } -void GDAPI godot_pool_vector3_array_set(godot_pool_vector3_array *p_pba, const godot_int p_idx, const godot_vector3 *p_data) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; +void GDAPI godot_pool_vector3_array_set(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data) { + PoolVector<Vector3> *self = (PoolVector<Vector3> *)p_self; Vector3 &s = *(Vector3 *)p_data; - pba->set(p_idx, s); + self->set(p_idx, s); } -godot_vector3 GDAPI godot_pool_vector3_array_get(godot_pool_vector3_array *p_pba, const godot_int p_idx) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; +godot_vector3 GDAPI godot_pool_vector3_array_get(const godot_pool_vector3_array *p_self, const godot_int p_idx) { + const PoolVector<Vector3> *self = (const PoolVector<Vector3> *)p_self; godot_vector3 v; Vector3 *s = (Vector3 *)&v; - *s = pba->get(p_idx); + *s = self->get(p_idx); return v; } -godot_int GDAPI godot_pool_vector3_array_size(godot_pool_vector3_array *p_pba) { - PoolVector<Vector3> *pba = (PoolVector<Vector3> *)p_pba; - return pba->size(); +godot_int GDAPI godot_pool_vector3_array_size(const godot_pool_vector3_array *p_self) { + const PoolVector<Vector3> *self = (const PoolVector<Vector3> *)p_self; + return self->size(); } -void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_pba) { - ((PoolVector<Vector3> *)p_pba)->~PoolVector(); +void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_self) { + ((PoolVector<Vector3> *)p_self)->~PoolVector(); } // color -void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pba) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; - memnew_placement(pba, PoolVector<Color>); +void GDAPI godot_pool_color_array_new(godot_pool_color_array *r_dest) { + PoolVector<Color> *dest = (PoolVector<Color> *)r_dest; + memnew_placement(dest, PoolVector<Color>); +} + +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *r_dest, const godot_pool_color_array *p_src) { + PoolVector<Color> *dest = (PoolVector<Color> *)r_dest; + const PoolVector<Color> *src = (const PoolVector<Color> *)p_src; + memnew_placement(dest, PoolVector<Color>(*src)); } -void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pba, const godot_array *p_a) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; +void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *r_dest, const godot_array *p_a) { + PoolVector<Color> *dest = (PoolVector<Color> *)r_dest; Array *a = (Array *)p_a; - memnew_placement(pba, PoolVector<Color>); + memnew_placement(dest, PoolVector<Color>); - pba->resize(a->size()); + dest->resize(a->size()); for (size_t i = 0; i < a->size(); i++) { - pba->set(i, (*a)[i]); + dest->set(i, (*a)[i]); } } -void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_pba, const godot_color *p_data) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; +void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_self, const godot_color *p_data) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; Color &s = *(Color *)p_data; - pba->append(s); + self->append(s); } -void GDAPI godot_pool_color_array_append_array(godot_pool_color_array *p_pba, const godot_pool_color_array *p_array) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; +void GDAPI godot_pool_color_array_append_array(godot_pool_color_array *p_self, const godot_pool_color_array *p_array) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; PoolVector<Color> *array = (PoolVector<Color> *)p_array; - pba->append_array(*array); + self->append_array(*array); } -int GDAPI godot_pool_color_array_insert(godot_pool_color_array *p_pba, const godot_int p_idx, const godot_color *p_data) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; +godot_error GDAPI godot_pool_color_array_insert(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; Color &s = *(Color *)p_data; - return pba->insert(p_idx, s); + return (godot_error)self->insert(p_idx, s); } -void GDAPI godot_pool_color_array_invert(godot_pool_color_array *p_pba) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; - pba->invert(); +void GDAPI godot_pool_color_array_invert(godot_pool_color_array *p_self) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + self->invert(); } -void GDAPI godot_pool_color_array_push_back(godot_pool_color_array *p_pba, const godot_color *p_data) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; +void GDAPI godot_pool_color_array_push_back(godot_pool_color_array *p_self, const godot_color *p_data) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; Color &s = *(Color *)p_data; - pba->push_back(s); + self->push_back(s); } -void GDAPI godot_pool_color_array_remove(godot_pool_color_array *p_pba, const godot_int p_idx) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; - pba->remove(p_idx); +void GDAPI godot_pool_color_array_remove(godot_pool_color_array *p_self, const godot_int p_idx) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + self->remove(p_idx); } -void GDAPI godot_pool_color_array_resize(godot_pool_color_array *p_pba, const godot_int p_size) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; - pba->resize(p_size); +void GDAPI godot_pool_color_array_resize(godot_pool_color_array *p_self, const godot_int p_size) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; + self->resize(p_size); } -void GDAPI godot_pool_color_array_set(godot_pool_color_array *p_pba, const godot_int p_idx, const godot_color *p_data) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; +void GDAPI godot_pool_color_array_set(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data) { + PoolVector<Color> *self = (PoolVector<Color> *)p_self; Color &s = *(Color *)p_data; - pba->set(p_idx, s); + self->set(p_idx, s); } -godot_color GDAPI godot_pool_color_array_get(godot_pool_color_array *p_pba, const godot_int p_idx) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; +godot_color GDAPI godot_pool_color_array_get(const godot_pool_color_array *p_self, const godot_int p_idx) { + const PoolVector<Color> *self = (const PoolVector<Color> *)p_self; godot_color v; Color *s = (Color *)&v; - *s = pba->get(p_idx); + *s = self->get(p_idx); return v; } -godot_int GDAPI godot_pool_color_array_size(godot_pool_color_array *p_pba) { - PoolVector<Color> *pba = (PoolVector<Color> *)p_pba; - return pba->size(); +godot_int GDAPI godot_pool_color_array_size(const godot_pool_color_array *p_self) { + const PoolVector<Color> *self = (const PoolVector<Color> *)p_self; + return self->size(); } -void GDAPI godot_pool_color_array_destroy(godot_pool_color_array *p_pba) { - ((PoolVector<Color> *)p_pba)->~PoolVector(); +void GDAPI godot_pool_color_array_destroy(godot_pool_color_array *p_self) { + ((PoolVector<Color> *)p_self)->~PoolVector(); } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_pool_arrays.h b/modules/gdnative/godot/godot_pool_arrays.h index ec9185f6f3..a794d03f01 100644 --- a/modules/gdnative/godot/godot_pool_arrays.h +++ b/modules/gdnative/godot/godot_pool_arrays.h @@ -92,191 +92,201 @@ typedef struct godot_pool_color_array { } godot_pool_color_array; #endif -#include "../godot.h" - #include "godot_array.h" +#include "godot_color.h" +#include "godot_vector2.h" +#include "godot_vector3.h" + +#include "../godot.h" // byte -void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *p_pba); -void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *p_pba, const godot_array *p_a); +void GDAPI godot_pool_byte_array_new(godot_pool_byte_array *r_dest); +void GDAPI godot_pool_byte_array_new_copy(godot_pool_byte_array *r_dest, const godot_pool_byte_array *p_src); +void GDAPI godot_pool_byte_array_new_with_array(godot_pool_byte_array *r_dest, const godot_array *p_a); -void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_pba, const uint8_t p_data); +void GDAPI godot_pool_byte_array_append(godot_pool_byte_array *p_self, const uint8_t p_data); -void GDAPI godot_pool_byte_array_append_array(godot_pool_byte_array *p_pba, const godot_pool_byte_array *p_array); +void GDAPI godot_pool_byte_array_append_array(godot_pool_byte_array *p_self, const godot_pool_byte_array *p_array); -int GDAPI godot_pool_byte_array_insert(godot_pool_byte_array *p_pba, const godot_int p_idx, const uint8_t p_data); +godot_error GDAPI godot_pool_byte_array_insert(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data); -void GDAPI godot_pool_byte_array_invert(godot_pool_byte_array *p_pba); +void GDAPI godot_pool_byte_array_invert(godot_pool_byte_array *p_self); -void GDAPI godot_pool_byte_array_push_back(godot_pool_byte_array *p_pba, const uint8_t p_data); +void GDAPI godot_pool_byte_array_push_back(godot_pool_byte_array *p_self, const uint8_t p_data); -void GDAPI godot_pool_byte_array_remove(godot_pool_byte_array *p_pba, const godot_int p_idx); +void GDAPI godot_pool_byte_array_remove(godot_pool_byte_array *p_self, const godot_int p_idx); -void GDAPI godot_pool_byte_array_resize(godot_pool_byte_array *p_pba, const godot_int p_size); +void GDAPI godot_pool_byte_array_resize(godot_pool_byte_array *p_self, const godot_int p_size); -void GDAPI godot_pool_byte_array_set(godot_pool_byte_array *p_pba, const godot_int p_idx, const uint8_t p_data); -uint8_t GDAPI godot_pool_byte_array_get(godot_pool_byte_array *p_pba, const godot_int p_idx); +void GDAPI godot_pool_byte_array_set(godot_pool_byte_array *p_self, const godot_int p_idx, const uint8_t p_data); +uint8_t GDAPI godot_pool_byte_array_get(const godot_pool_byte_array *p_self, const godot_int p_idx); -godot_int GDAPI godot_pool_byte_array_size(godot_pool_byte_array *p_pba); +godot_int GDAPI godot_pool_byte_array_size(const godot_pool_byte_array *p_self); -void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_pba); +void GDAPI godot_pool_byte_array_destroy(godot_pool_byte_array *p_self); // int -void GDAPI godot_pool_int_array_new(godot_pool_int_array *p_pia); -void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *p_pia, const godot_array *p_a); +void GDAPI godot_pool_int_array_new(godot_pool_int_array *r_dest); +void GDAPI godot_pool_int_array_new_copy(godot_pool_int_array *r_dest, const godot_pool_int_array *p_src); +void GDAPI godot_pool_int_array_new_with_array(godot_pool_int_array *r_dest, const godot_array *p_a); -void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_pia, const godot_int p_data); +void GDAPI godot_pool_int_array_append(godot_pool_int_array *p_self, const godot_int p_data); -void GDAPI godot_pool_int_array_append_array(godot_pool_int_array *p_pia, const godot_pool_int_array *p_array); +void GDAPI godot_pool_int_array_append_array(godot_pool_int_array *p_self, const godot_pool_int_array *p_array); -int GDAPI godot_pool_int_array_insert(godot_pool_int_array *p_pia, const godot_int p_idx, const godot_int p_data); +godot_error GDAPI godot_pool_int_array_insert(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data); -void GDAPI godot_pool_int_array_invert(godot_pool_int_array *p_pia); +void GDAPI godot_pool_int_array_invert(godot_pool_int_array *p_self); -void GDAPI godot_pool_int_array_push_back(godot_pool_int_array *p_pia, const godot_int p_data); +void GDAPI godot_pool_int_array_push_back(godot_pool_int_array *p_self, const godot_int p_data); -void GDAPI godot_pool_int_array_remove(godot_pool_int_array *p_pia, const godot_int p_idx); +void GDAPI godot_pool_int_array_remove(godot_pool_int_array *p_self, const godot_int p_idx); -void GDAPI godot_pool_int_array_resize(godot_pool_int_array *p_pia, const godot_int p_size); +void GDAPI godot_pool_int_array_resize(godot_pool_int_array *p_self, const godot_int p_size); -void GDAPI godot_pool_int_array_set(godot_pool_int_array *p_pia, const godot_int p_idx, const godot_int p_data); -godot_int GDAPI godot_pool_int_array_get(godot_pool_int_array *p_pia, const godot_int p_idx); +void GDAPI godot_pool_int_array_set(godot_pool_int_array *p_self, const godot_int p_idx, const godot_int p_data); +godot_int GDAPI godot_pool_int_array_get(const godot_pool_int_array *p_self, const godot_int p_idx); -godot_int GDAPI godot_pool_int_array_size(godot_pool_int_array *p_pia); +godot_int GDAPI godot_pool_int_array_size(const godot_pool_int_array *p_self); -void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_pia); +void GDAPI godot_pool_int_array_destroy(godot_pool_int_array *p_self); // real -void GDAPI godot_pool_real_array_new(godot_pool_real_array *p_pra); -void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *p_pra, const godot_array *p_a); +void GDAPI godot_pool_real_array_new(godot_pool_real_array *r_dest); +void GDAPI godot_pool_real_array_new_copy(godot_pool_real_array *r_dest, const godot_pool_real_array *p_src); +void GDAPI godot_pool_real_array_new_with_array(godot_pool_real_array *r_dest, const godot_array *p_a); -void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_pra, const godot_real p_data); +void GDAPI godot_pool_real_array_append(godot_pool_real_array *p_self, const godot_real p_data); -void GDAPI godot_pool_real_array_append_array(godot_pool_real_array *p_pra, const godot_pool_real_array *p_array); +void GDAPI godot_pool_real_array_append_array(godot_pool_real_array *p_self, const godot_pool_real_array *p_array); -int GDAPI godot_pool_real_array_insert(godot_pool_real_array *p_pra, const godot_int p_idx, const godot_real p_data); +godot_error GDAPI godot_pool_real_array_insert(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data); -void GDAPI godot_pool_real_array_invert(godot_pool_real_array *p_pra); +void GDAPI godot_pool_real_array_invert(godot_pool_real_array *p_self); -void GDAPI godot_pool_real_array_push_back(godot_pool_real_array *p_pra, const godot_real p_data); +void GDAPI godot_pool_real_array_push_back(godot_pool_real_array *p_self, const godot_real p_data); -void GDAPI godot_pool_real_array_remove(godot_pool_real_array *p_pra, const godot_int p_idx); +void GDAPI godot_pool_real_array_remove(godot_pool_real_array *p_self, const godot_int p_idx); -void GDAPI godot_pool_real_array_resize(godot_pool_real_array *p_pra, const godot_int p_size); +void GDAPI godot_pool_real_array_resize(godot_pool_real_array *p_self, const godot_int p_size); -void GDAPI godot_pool_real_array_set(godot_pool_real_array *p_pra, const godot_int p_idx, const godot_real p_data); -godot_real GDAPI godot_pool_real_array_get(godot_pool_real_array *p_pra, const godot_int p_idx); +void GDAPI godot_pool_real_array_set(godot_pool_real_array *p_self, const godot_int p_idx, const godot_real p_data); +godot_real GDAPI godot_pool_real_array_get(const godot_pool_real_array *p_self, const godot_int p_idx); -godot_int GDAPI godot_pool_real_array_size(godot_pool_real_array *p_pra); +godot_int GDAPI godot_pool_real_array_size(const godot_pool_real_array *p_self); -void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_pra); +void GDAPI godot_pool_real_array_destroy(godot_pool_real_array *p_self); // string -void GDAPI godot_pool_string_array_new(godot_pool_string_array *p_psa); -void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *p_psa, const godot_array *p_a); +void GDAPI godot_pool_string_array_new(godot_pool_string_array *r_dest); +void GDAPI godot_pool_string_array_new_copy(godot_pool_string_array *r_dest, const godot_pool_string_array *p_src); +void GDAPI godot_pool_string_array_new_with_array(godot_pool_string_array *r_dest, const godot_array *p_a); -void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_psa, const godot_string *p_data); +void GDAPI godot_pool_string_array_append(godot_pool_string_array *p_self, const godot_string *p_data); -void GDAPI godot_pool_string_array_append_array(godot_pool_string_array *p_psa, const godot_pool_string_array *p_array); +void GDAPI godot_pool_string_array_append_array(godot_pool_string_array *p_self, const godot_pool_string_array *p_array); -int GDAPI godot_pool_string_array_insert(godot_pool_string_array *p_psa, const godot_int p_idx, const godot_string *p_data); +godot_error GDAPI godot_pool_string_array_insert(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data); -void GDAPI godot_pool_string_array_invert(godot_pool_string_array *p_psa); +void GDAPI godot_pool_string_array_invert(godot_pool_string_array *p_self); -void GDAPI godot_pool_string_array_push_back(godot_pool_string_array *p_psa, const godot_string *p_data); +void GDAPI godot_pool_string_array_push_back(godot_pool_string_array *p_self, const godot_string *p_data); -void GDAPI godot_pool_string_array_remove(godot_pool_string_array *p_psa, const godot_int p_idx); +void GDAPI godot_pool_string_array_remove(godot_pool_string_array *p_self, const godot_int p_idx); -void GDAPI godot_pool_string_array_resize(godot_pool_string_array *p_psa, const godot_int p_size); +void GDAPI godot_pool_string_array_resize(godot_pool_string_array *p_self, const godot_int p_size); -void GDAPI godot_pool_string_array_set(godot_pool_string_array *p_psa, const godot_int p_idx, const godot_string *p_data); -godot_string GDAPI godot_pool_string_array_get(godot_pool_string_array *p_psa, const godot_int p_idx); +void GDAPI godot_pool_string_array_set(godot_pool_string_array *p_self, const godot_int p_idx, const godot_string *p_data); +godot_string GDAPI godot_pool_string_array_get(const godot_pool_string_array *p_self, const godot_int p_idx); -godot_int GDAPI godot_pool_string_array_size(godot_pool_string_array *p_psa); +godot_int GDAPI godot_pool_string_array_size(const godot_pool_string_array *p_self); -void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_psa); +void GDAPI godot_pool_string_array_destroy(godot_pool_string_array *p_self); // vector2 -void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *p_pv2a); -void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *p_pv2a, const godot_array *p_a); +void GDAPI godot_pool_vector2_array_new(godot_pool_vector2_array *r_dest); +void GDAPI godot_pool_vector2_array_new_copy(godot_pool_vector2_array *r_dest, const godot_pool_vector2_array *p_src); +void GDAPI godot_pool_vector2_array_new_with_array(godot_pool_vector2_array *r_dest, const godot_array *p_a); -void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_pv2a, const godot_vector2 *p_data); +void GDAPI godot_pool_vector2_array_append(godot_pool_vector2_array *p_self, const godot_vector2 *p_data); -void GDAPI godot_pool_vector2_array_append_array(godot_pool_vector2_array *p_pv2a, const godot_pool_vector2_array *p_array); +void GDAPI godot_pool_vector2_array_append_array(godot_pool_vector2_array *p_self, const godot_pool_vector2_array *p_array); -int GDAPI godot_pool_vector2_array_insert(godot_pool_vector2_array *p_pv2a, const godot_int p_idx, const godot_vector2 *p_data); +godot_error GDAPI godot_pool_vector2_array_insert(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data); -void GDAPI godot_pool_vector2_array_invert(godot_pool_vector2_array *p_pv2a); +void GDAPI godot_pool_vector2_array_invert(godot_pool_vector2_array *p_self); -void GDAPI godot_pool_vector2_array_push_back(godot_pool_vector2_array *p_pv2a, const godot_vector2 *p_data); +void GDAPI godot_pool_vector2_array_push_back(godot_pool_vector2_array *p_self, const godot_vector2 *p_data); -void GDAPI godot_pool_vector2_array_remove(godot_pool_vector2_array *p_pv2a, const godot_int p_idx); +void GDAPI godot_pool_vector2_array_remove(godot_pool_vector2_array *p_self, const godot_int p_idx); -void GDAPI godot_pool_vector2_array_resize(godot_pool_vector2_array *p_pv2a, const godot_int p_size); +void GDAPI godot_pool_vector2_array_resize(godot_pool_vector2_array *p_self, const godot_int p_size); -void GDAPI godot_pool_vector2_array_set(godot_pool_vector2_array *p_pv2a, const godot_int p_idx, const godot_vector2 *p_data); -godot_vector2 GDAPI godot_pool_vector2_array_get(godot_pool_vector2_array *p_pv2a, const godot_int p_idx); +void GDAPI godot_pool_vector2_array_set(godot_pool_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data); +godot_vector2 GDAPI godot_pool_vector2_array_get(const godot_pool_vector2_array *p_self, const godot_int p_idx); -godot_int GDAPI godot_pool_vector2_array_size(godot_pool_vector2_array *p_pv2a); +godot_int GDAPI godot_pool_vector2_array_size(const godot_pool_vector2_array *p_self); -void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_pv2a); +void GDAPI godot_pool_vector2_array_destroy(godot_pool_vector2_array *p_self); // vector3 -void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *p_pv3a); -void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *p_pv3a, const godot_array *p_a); +void GDAPI godot_pool_vector3_array_new(godot_pool_vector3_array *r_dest); +void GDAPI godot_pool_vector3_array_new_copy(godot_pool_vector3_array *r_dest, const godot_pool_vector3_array *p_src); +void GDAPI godot_pool_vector3_array_new_with_array(godot_pool_vector3_array *r_dest, const godot_array *p_a); -void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_pv3a, const godot_vector3 *p_data); +void GDAPI godot_pool_vector3_array_append(godot_pool_vector3_array *p_self, const godot_vector3 *p_data); -void GDAPI godot_pool_vector3_array_append_array(godot_pool_vector3_array *p_pv3a, const godot_pool_vector3_array *p_array); +void GDAPI godot_pool_vector3_array_append_array(godot_pool_vector3_array *p_self, const godot_pool_vector3_array *p_array); -int GDAPI godot_pool_vector3_array_insert(godot_pool_vector3_array *p_pv3a, const godot_int p_idx, const godot_vector3 *p_data); +godot_error GDAPI godot_pool_vector3_array_insert(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data); -void GDAPI godot_pool_vector3_array_invert(godot_pool_vector3_array *p_pv3a); +void GDAPI godot_pool_vector3_array_invert(godot_pool_vector3_array *p_self); -void GDAPI godot_pool_vector3_array_push_back(godot_pool_vector3_array *p_pv3a, const godot_vector3 *p_data); +void GDAPI godot_pool_vector3_array_push_back(godot_pool_vector3_array *p_self, const godot_vector3 *p_data); -void GDAPI godot_pool_vector3_array_remove(godot_pool_vector3_array *p_pv3a, const godot_int p_idx); +void GDAPI godot_pool_vector3_array_remove(godot_pool_vector3_array *p_self, const godot_int p_idx); -void GDAPI godot_pool_vector3_array_resize(godot_pool_vector3_array *p_pv3a, const godot_int p_size); +void GDAPI godot_pool_vector3_array_resize(godot_pool_vector3_array *p_self, const godot_int p_size); -void GDAPI godot_pool_vector3_array_set(godot_pool_vector3_array *p_pv3a, const godot_int p_idx, const godot_vector3 *p_data); -godot_vector3 GDAPI godot_pool_vector3_array_get(godot_pool_vector3_array *p_pv3a, const godot_int p_idx); +void GDAPI godot_pool_vector3_array_set(godot_pool_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data); +godot_vector3 GDAPI godot_pool_vector3_array_get(const godot_pool_vector3_array *p_self, const godot_int p_idx); -godot_int GDAPI godot_pool_vector3_array_size(godot_pool_vector3_array *p_pv3a); +godot_int GDAPI godot_pool_vector3_array_size(const godot_pool_vector3_array *p_self); -void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_pv3a); +void GDAPI godot_pool_vector3_array_destroy(godot_pool_vector3_array *p_self); // color -void GDAPI godot_pool_color_array_new(godot_pool_color_array *p_pca); -void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *p_pca, const godot_array *p_a); +void GDAPI godot_pool_color_array_new(godot_pool_color_array *r_dest); +void GDAPI godot_pool_color_array_new_copy(godot_pool_color_array *r_dest, const godot_pool_color_array *p_src); +void GDAPI godot_pool_color_array_new_with_array(godot_pool_color_array *r_dest, const godot_array *p_a); -void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_pca, const godot_color *p_data); +void GDAPI godot_pool_color_array_append(godot_pool_color_array *p_self, const godot_color *p_data); -void GDAPI godot_pool_color_array_append_array(godot_pool_color_array *p_pca, const godot_pool_color_array *p_array); +void GDAPI godot_pool_color_array_append_array(godot_pool_color_array *p_self, const godot_pool_color_array *p_array); -int GDAPI godot_pool_color_array_insert(godot_pool_color_array *p_pca, const godot_int p_idx, const godot_color *p_data); +godot_error GDAPI godot_pool_color_array_insert(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data); -void GDAPI godot_pool_color_array_invert(godot_pool_color_array *p_pca); +void GDAPI godot_pool_color_array_invert(godot_pool_color_array *p_self); -void GDAPI godot_pool_color_array_push_back(godot_pool_color_array *p_pca, const godot_color *p_data); +void GDAPI godot_pool_color_array_push_back(godot_pool_color_array *p_self, const godot_color *p_data); -void GDAPI godot_pool_color_array_remove(godot_pool_color_array *p_pca, const godot_int p_idx); +void GDAPI godot_pool_color_array_remove(godot_pool_color_array *p_self, const godot_int p_idx); -void GDAPI godot_pool_color_array_resize(godot_pool_color_array *p_pca, const godot_int p_size); +void GDAPI godot_pool_color_array_resize(godot_pool_color_array *p_self, const godot_int p_size); -void GDAPI godot_pool_color_array_set(godot_pool_color_array *p_pca, const godot_int p_idx, const godot_color *p_data); -godot_color GDAPI godot_pool_color_array_get(godot_pool_color_array *p_pca, const godot_int p_idx); +void GDAPI godot_pool_color_array_set(godot_pool_color_array *p_self, const godot_int p_idx, const godot_color *p_data); +godot_color GDAPI godot_pool_color_array_get(const godot_pool_color_array *p_self, const godot_int p_idx); -godot_int GDAPI godot_pool_color_array_size(godot_pool_color_array *p_pca); +godot_int GDAPI godot_pool_color_array_size(const godot_pool_color_array *p_self); -void GDAPI godot_pool_color_array_destroy(godot_pool_color_array *p_pca); +void GDAPI godot_pool_color_array_destroy(godot_pool_color_array *p_self); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_quat.cpp b/modules/gdnative/godot/godot_quat.cpp index 7c3a71dfc0..7235e4fcec 100644 --- a/modules/gdnative/godot/godot_quat.cpp +++ b/modules/gdnative/godot/godot_quat.cpp @@ -28,77 +28,190 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_quat.h" +#include "core/variant.h" -#include "math/quat.h" +#include "core/math/quat.h" #ifdef __cplusplus extern "C" { #endif -void _quat_api_anchor() { +void _quat_api_anchor() {} + +void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w) { + + Quat *dest = (Quat *)r_dest; + *dest = Quat(p_x, p_y, p_z, p_w); } -void GDAPI godot_quat_new(godot_quat *p_quat) { - Quat *quat = (Quat *)p_quat; - *quat = Quat(); +void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector3 *p_axis, const godot_real p_angle) { + const Vector3 *axis = (const Vector3 *)p_axis; + Quat *dest = (Quat *)r_dest; + *dest = Quat(*axis, p_angle); } -void GDAPI godot_quat_new_with_elements(godot_quat *p_quat, const godot_real x, const godot_real y, const godot_real z, const godot_real w) { - Quat *quat = (Quat *)p_quat; - *quat = Quat(x, y, z, w); +godot_real GDAPI godot_quat_get_x(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->x; } -void GDAPI godot_quat_new_with_rotation(godot_quat *p_quat, const godot_vector3 *p_axis, const godot_real p_angle) { - Quat *quat = (Quat *)p_quat; - const Vector3 *axis = (const Vector3 *)p_axis; - *quat = Quat(*axis, p_angle); -} - -void GDAPI godot_quat_new_with_shortest_arc(godot_quat *p_quat, const godot_vector3 *p_v0, const godot_vector3 *p_v1) { - Quat *quat = (Quat *)p_quat; - const Vector3 *v0 = (const Vector3 *)p_v0; - const Vector3 *v1 = (const Vector3 *)p_v1; - *quat = Quat(*v0, *v1); -} - -godot_vector3 GDAPI godot_quat_get_euler(const godot_quat *p_quat) { - Quat *quat = (Quat *)p_quat; - Vector3 euler = quat->get_euler(); - return *(godot_vector3 *)&euler; -} - -void GDAPI godot_quat_set_euler(godot_quat *p_quat, const godot_vector3 *p_euler) { - Quat *quat = (Quat *)p_quat; - const Vector3 *euler = (const Vector3 *)p_euler; - quat->set_euler(*euler); -} - -godot_real GDAPI *godot_quat_index(godot_quat *p_quat, const godot_int p_idx) { - Quat *quat = (Quat *)p_quat; - switch (p_idx) { - case 0: - return &quat->x; - case 1: - return &quat->y; - case 2: - return &quat->z; - default: - return &quat->y; - } -} - -godot_real GDAPI godot_quat_const_index(const godot_quat *p_quat, const godot_int p_idx) { - const Quat *quat = (const Quat *)p_quat; - switch (p_idx) { - case 0: - return quat->x; - case 1: - return quat->y; - case 2: - return quat->z; - default: - return quat->y; - } +void GDAPI godot_quat_set_x(godot_quat *p_self, const godot_real val) { + Quat *self = (Quat *)p_self; + self->x = val; +} + +godot_real GDAPI godot_quat_get_y(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->y; +} + +void GDAPI godot_quat_set_y(godot_quat *p_self, const godot_real val) { + Quat *self = (Quat *)p_self; + self->y = val; +} + +godot_real GDAPI godot_quat_get_z(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->z; +} + +void GDAPI godot_quat_set_z(godot_quat *p_self, const godot_real val) { + Quat *self = (Quat *)p_self; + self->z = val; +} + +godot_real GDAPI godot_quat_get_w(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->w; +} + +void GDAPI godot_quat_set_w(godot_quat *p_self, const godot_real val) { + Quat *self = (Quat *)p_self; + self->w = val; +} + +godot_string GDAPI godot_quat_as_string(const godot_quat *p_self) { + godot_string ret; + const Quat *self = (const Quat *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_real GDAPI godot_quat_length(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->length(); +} + +godot_real GDAPI godot_quat_length_squared(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->length_squared(); +} + +godot_quat GDAPI godot_quat_normalized(const godot_quat *p_self) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + *((Quat *)&dest) = self->normalized(); + return dest; +} + +godot_bool GDAPI godot_quat_is_normalized(const godot_quat *p_self) { + const Quat *self = (const Quat *)p_self; + return self->is_normalized(); +} + +godot_quat GDAPI godot_quat_inverse(const godot_quat *p_self) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + *((Quat *)&dest) = self->inverse(); + return dest; +} + +godot_real GDAPI godot_quat_dot(const godot_quat *p_self, const godot_quat *p_b) { + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + return self->dot(*b); +} + +godot_vector3 GDAPI godot_quat_xform(const godot_quat *p_self, const godot_vector3 *p_v) { + godot_vector3 dest; + const Quat *self = (const Quat *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *((Vector3 *)&dest) = self->xform(*v); + return dest; +} + +godot_quat GDAPI godot_quat_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + *((Quat *)&dest) = self->slerp(*b, p_t); + return dest; +} + +godot_quat GDAPI godot_quat_slerpni(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + *((Quat *)&dest) = self->slerpni(*b, p_t); + return dest; +} + +godot_quat GDAPI godot_quat_cubic_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_quat *p_pre_a, const godot_quat *p_post_b, const godot_real p_t) { + godot_quat dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + const Quat *pre_a = (const Quat *)p_pre_a; + const Quat *post_b = (const Quat *)p_post_b; + *((Quat *)&dest) = self->cubic_slerp(*b, *pre_a, *post_b, p_t); + return dest; +} + +godot_quat GDAPI godot_quat_operator_multiply(const godot_quat *p_self, const godot_real p_b) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + *dest = *self * p_b; + return raw_dest; +} + +godot_quat GDAPI godot_quat_operator_add(const godot_quat *p_self, const godot_quat *p_b) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + *dest = *self + *b; + return raw_dest; +} + +godot_quat GDAPI godot_quat_operator_substract(const godot_quat *p_self, const godot_quat *p_b) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + *dest = *self - *b; + return raw_dest; +} + +godot_quat GDAPI godot_quat_operator_divide(const godot_quat *p_self, const godot_real p_b) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + *dest = *self / p_b; + return raw_dest; +} + +godot_bool GDAPI godot_quat_operator_equal(const godot_quat *p_self, const godot_quat *p_b) { + const Quat *self = (const Quat *)p_self; + const Quat *b = (const Quat *)p_b; + return *self == *b; +} + +godot_quat GDAPI godot_quat_operator_neg(const godot_quat *p_self) { + godot_quat raw_dest; + Quat *dest = (Quat *)&raw_dest; + const Quat *self = (const Quat *)p_self; + *dest = -(*self); + return raw_dest; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_quat.h b/modules/gdnative/godot/godot_quat.h index 35b1acd3ed..2289b6cbab 100644 --- a/modules/gdnative/godot/godot_quat.h +++ b/modules/gdnative/godot/godot_quat.h @@ -37,23 +37,63 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED typedef struct godot_quat { uint8_t _dont_touch_that[16]; } godot_quat; #endif #include "../godot.h" +#include "godot_vector3.h" -void GDAPI godot_quat_new(godot_quat *p_quat); -void GDAPI godot_quat_new_with_elements(godot_quat *p_quat, const godot_real x, const godot_real y, const godot_real z, const godot_real w); -void GDAPI godot_quat_new_with_rotation(godot_quat *p_quat, const godot_vector3 *p_axis, const godot_real p_angle); -void GDAPI godot_quat_new_with_shortest_arc(godot_quat *p_quat, const godot_vector3 *p_v0, const godot_vector3 *p_v1); +void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w); +void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector3 *p_axis, const godot_real p_angle); -godot_vector3 GDAPI godot_quat_get_euler(const godot_quat *p_quat); -void GDAPI godot_quat_set_euler(godot_quat *p_quat, const godot_vector3 *p_euler); +godot_real GDAPI godot_quat_get_x(const godot_quat *p_self); +void GDAPI godot_quat_set_x(godot_quat *p_self, const godot_real val); -godot_real GDAPI *godot_quat_index(godot_quat *p_quat, const godot_int p_idx); -godot_real GDAPI godot_quat_const_index(const godot_quat *p_quat, const godot_int p_idx); +godot_real GDAPI godot_quat_get_y(const godot_quat *p_self); +void GDAPI godot_quat_set_y(godot_quat *p_self, const godot_real val); + +godot_real GDAPI godot_quat_get_z(const godot_quat *p_self); +void GDAPI godot_quat_set_z(godot_quat *p_self, const godot_real val); + +godot_real GDAPI godot_quat_get_w(const godot_quat *p_self); +void GDAPI godot_quat_set_w(godot_quat *p_self, const godot_real val); + +godot_string GDAPI godot_quat_as_string(const godot_quat *p_self); + +godot_real GDAPI godot_quat_length(const godot_quat *p_self); + +godot_real GDAPI godot_quat_length_squared(const godot_quat *p_self); + +godot_quat GDAPI godot_quat_normalized(const godot_quat *p_self); + +godot_bool GDAPI godot_quat_is_normalized(const godot_quat *p_self); + +godot_quat GDAPI godot_quat_inverse(const godot_quat *p_self); + +godot_real GDAPI godot_quat_dot(const godot_quat *p_self, const godot_quat *p_b); + +godot_vector3 GDAPI godot_quat_xform(const godot_quat *p_self, const godot_vector3 *p_v); + +godot_quat GDAPI godot_quat_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t); + +godot_quat GDAPI godot_quat_slerpni(const godot_quat *p_self, const godot_quat *p_b, const godot_real p_t); + +godot_quat GDAPI godot_quat_cubic_slerp(const godot_quat *p_self, const godot_quat *p_b, const godot_quat *p_pre_a, const godot_quat *p_post_b, const godot_real p_t); + +godot_quat GDAPI godot_quat_operator_multiply(const godot_quat *p_self, const godot_real p_b); + +godot_quat GDAPI godot_quat_operator_add(const godot_quat *p_self, const godot_quat *p_b); + +godot_quat GDAPI godot_quat_operator_substract(const godot_quat *p_self, const godot_quat *p_b); + +godot_quat GDAPI godot_quat_operator_divide(const godot_quat *p_self, const godot_real p_b); + +godot_bool GDAPI godot_quat_operator_equal(const godot_quat *p_self, const godot_quat *p_b); + +godot_quat GDAPI godot_quat_operator_neg(const godot_quat *p_self); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_rect2.cpp b/modules/gdnative/godot/godot_rect2.cpp index b19096b79e..0e456ea3ba 100644 --- a/modules/gdnative/godot/godot_rect2.cpp +++ b/modules/gdnative/godot/godot_rect2.cpp @@ -28,48 +28,128 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_rect2.h" +#include "core/variant.h" -#include "math/math_2d.h" +#include "core/math/math_2d.h" #ifdef __cplusplus extern "C" { #endif -void _rect2_api_anchor() { +void _rect2_api_anchor() {} + +void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) { + const Vector2 *position = (const Vector2 *)p_pos; + const Vector2 *size = (const Vector2 *)p_size; + Rect2 *dest = (Rect2 *)r_dest; + *dest = Rect2(*position, *size); } -void GDAPI godot_rect2_new(godot_rect2 *p_rect) { - Rect2 *rect = (Rect2 *)p_rect; - *rect = Rect2(); +void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height) { + + Rect2 *dest = (Rect2 *)r_dest; + *dest = Rect2(p_x, p_y, p_width, p_height); } -void GDAPI godot_rect2_new_with_pos_and_size(godot_rect2 *p_rect, const godot_vector2 *p_pos, const godot_vector2 *p_size) { - Rect2 *rect = (Rect2 *)p_rect; - const Vector2 *pos = (const Vector2 *)p_pos; - const Vector2 *size = (const Vector2 *)p_size; - *rect = Rect2(*pos, *size); +godot_string GDAPI godot_rect2_as_string(const godot_rect2 *p_self) { + godot_string ret; + const Rect2 *self = (const Rect2 *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_real GDAPI godot_rect2_get_area(const godot_rect2 *p_self) { + const Rect2 *self = (const Rect2 *)p_self; + return self->get_area(); +} + +godot_bool GDAPI godot_rect2_intersects(const godot_rect2 *p_self, const godot_rect2 *p_b) { + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + return self->intersects(*b); +} + +godot_bool GDAPI godot_rect2_encloses(const godot_rect2 *p_self, const godot_rect2 *p_b) { + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + return self->encloses(*b); +} + +godot_bool GDAPI godot_rect2_has_no_area(const godot_rect2 *p_self) { + const Rect2 *self = (const Rect2 *)p_self; + return self->has_no_area(); +} + +godot_rect2 GDAPI godot_rect2_clip(const godot_rect2 *p_self, const godot_rect2 *p_b) { + godot_rect2 dest; + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + *((Rect2 *)&dest) = self->clip(*b); + return dest; +} + +godot_rect2 GDAPI godot_rect2_merge(const godot_rect2 *p_self, const godot_rect2 *p_b) { + godot_rect2 dest; + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + *((Rect2 *)&dest) = self->merge(*b); + return dest; +} + +godot_bool GDAPI godot_rect2_has_point(const godot_rect2 *p_self, const godot_vector2 *p_point) { + const Rect2 *self = (const Rect2 *)p_self; + const Vector2 *point = (const Vector2 *)p_point; + return self->has_point(*point); +} + +godot_rect2 GDAPI godot_rect2_grow(const godot_rect2 *p_self, const godot_real p_by) { + godot_rect2 dest; + const Rect2 *self = (const Rect2 *)p_self; + + *((Rect2 *)&dest) = self->grow(p_by); + return dest; +} + +godot_rect2 GDAPI godot_rect2_expand(const godot_rect2 *p_self, const godot_vector2 *p_to) { + godot_rect2 dest; + const Rect2 *self = (const Rect2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + *((Rect2 *)&dest) = self->expand(*to); + return dest; +} + +godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const godot_rect2 *p_b) { + const Rect2 *self = (const Rect2 *)p_self; + const Rect2 *b = (const Rect2 *)p_b; + return *self == *b; } -godot_vector2 GDAPI *godot_rect2_get_pos(godot_rect2 *p_rect) { - Rect2 *rect = (Rect2 *)p_rect; - return (godot_vector2 *)&rect->pos; +godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Rect2 *self = (const Rect2 *)p_self; + *d = self->get_position(); + return dest; } -void GDAPI godot_rect2_set_pos(godot_rect2 *p_rect, const godot_vector2 *p_pos) { - Rect2 *rect = (Rect2 *)p_rect; - const Vector2 *pos = (const Vector2 *)p_pos; - rect->pos = *pos; +godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self) { + godot_vector2 dest; + Vector2 *d = (Vector2 *)&dest; + const Rect2 *self = (const Rect2 *)p_self; + *d = self->get_size(); + return dest; } -godot_vector2 GDAPI *godot_rect2_get_size(godot_rect2 *p_rect) { - Rect2 *rect = (Rect2 *)p_rect; - return (godot_vector2 *)&rect->size; +void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos) { + Rect2 *self = (Rect2 *)p_self; + const Vector2 *position = (const Vector2 *)p_pos; + self->set_position(*position); } -void GDAPI godot_rect2_set_size(godot_rect2 *p_rect, const godot_vector2 *p_size) { - Rect2 *rect = (Rect2 *)p_rect; +void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size) { + Rect2 *self = (Rect2 *)p_self; const Vector2 *size = (const Vector2 *)p_size; - rect->size = *size; + self->set_size(*size); } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_rect2.h b/modules/gdnative/godot/godot_rect2.h index e9e4a26897..488a1204f7 100644 --- a/modules/gdnative/godot/godot_rect2.h +++ b/modules/gdnative/godot/godot_rect2.h @@ -37,24 +37,50 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED typedef struct godot_rect2 { uint8_t _dont_touch_that[16]; } godot_rect2; #endif #include "../godot.h" +#include "godot_vector2.h" -void GDAPI godot_rect2_new(godot_rect2 *p_rect); -void GDAPI godot_rect2_new_with_pos_and_size(godot_rect2 *p_rect, const godot_vector2 *p_pos, const godot_vector2 *p_size); +void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size); +void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height); -godot_vector2 GDAPI *godot_rect2_get_pos(godot_rect2 *p_rect); -void GDAPI godot_rect2_set_pos(godot_rect2 *p_rect, const godot_vector2 *p_pos); +godot_string GDAPI godot_rect2_as_string(const godot_rect2 *p_self); -godot_vector2 GDAPI *godot_rect2_get_size(godot_rect2 *p_rect); -void GDAPI godot_rect2_set_size(godot_rect2 *p_rect, const godot_vector2 *p_size); +godot_real GDAPI godot_rect2_get_area(const godot_rect2 *p_self); + +godot_bool GDAPI godot_rect2_intersects(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_bool GDAPI godot_rect2_encloses(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_bool GDAPI godot_rect2_has_no_area(const godot_rect2 *p_self); + +godot_rect2 GDAPI godot_rect2_clip(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_rect2 GDAPI godot_rect2_merge(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_bool GDAPI godot_rect2_has_point(const godot_rect2 *p_self, const godot_vector2 *p_point); + +godot_rect2 GDAPI godot_rect2_grow(const godot_rect2 *p_self, const godot_real p_by); + +godot_rect2 GDAPI godot_rect2_expand(const godot_rect2 *p_self, const godot_vector2 *p_to); + +godot_bool GDAPI godot_rect2_operator_equal(const godot_rect2 *p_self, const godot_rect2 *p_b); + +godot_vector2 GDAPI godot_rect2_get_position(const godot_rect2 *p_self); + +godot_vector2 GDAPI godot_rect2_get_size(const godot_rect2 *p_self); + +void GDAPI godot_rect2_set_position(godot_rect2 *p_self, const godot_vector2 *p_pos); + +void GDAPI godot_rect2_set_size(godot_rect2 *p_self, const godot_vector2 *p_size); #ifdef __cplusplus } #endif -#endif // GODOT_RECT3_H +#endif // GODOT_RECT2_H diff --git a/modules/gdnative/godot/godot_rect3.cpp b/modules/gdnative/godot/godot_rect3.cpp index 96c5d17b1a..e524fa8463 100644 --- a/modules/gdnative/godot/godot_rect3.cpp +++ b/modules/gdnative/godot/godot_rect3.cpp @@ -28,48 +28,190 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_rect3.h" +#include "core/variant.h" -#include "math/rect3.h" +#include "core/math/rect3.h" #ifdef __cplusplus extern "C" { #endif -void _rect3_api_anchor() { +void _rect3_api_anchor() {} + +void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size) { + const Vector3 *pos = (const Vector3 *)p_pos; + const Vector3 *size = (const Vector3 *)p_size; + Rect3 *dest = (Rect3 *)r_dest; + *dest = Rect3(*pos, *size); } -void GDAPI godot_rect3_new(godot_rect3 *p_rect) { - Rect3 *rect = (Rect3 *)p_rect; - *rect = Rect3(); +godot_vector3 GDAPI godot_rect3_get_position(const godot_rect3 *p_self) { + godot_vector3 raw_ret; + const Rect3 *self = (const Rect3 *)p_self; + Vector3 *ret = (Vector3 *)&raw_ret; + *ret = self->position; + return raw_ret; } -void GDAPI godot_rect3_new_with_pos_and_size(godot_rect3 *p_rect, const godot_vector3 *p_pos, const godot_vector3 *p_size) { - Rect3 *rect = (Rect3 *)p_rect; - const Vector3 *pos = (const Vector3 *)p_pos; - const Vector3 *size = (const Vector3 *)p_size; - *rect = Rect3(*pos, *size); +void GDAPI godot_rect3_set_position(const godot_rect3 *p_self, const godot_vector3 *p_v) { + Rect3 *self = (Rect3 *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + self->position = *v; } -godot_vector3 GDAPI *godot_rect3_get_pos(godot_rect3 *p_rect) { - Rect3 *rect = (Rect3 *)p_rect; - return (godot_vector3 *)&rect->pos; +godot_vector3 GDAPI godot_rect3_get_size(const godot_rect3 *p_self) { + godot_vector3 raw_ret; + const Rect3 *self = (const Rect3 *)p_self; + Vector3 *ret = (Vector3 *)&raw_ret; + *ret = self->size; + return raw_ret; } -void GDAPI godot_rect3_set_pos(godot_rect3 *p_rect, const godot_vector3 *p_pos) { - Rect3 *rect = (Rect3 *)p_rect; - const Vector3 *pos = (const Vector3 *)p_pos; - rect->pos = *pos; +void GDAPI godot_rect3_set_size(const godot_rect3 *p_self, const godot_vector3 *p_v) { + Rect3 *self = (Rect3 *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + self->size = *v; } -godot_vector3 GDAPI *godot_rect3_get_size(godot_rect3 *p_rect) { - Rect3 *rect = (Rect3 *)p_rect; - return (godot_vector3 *)&rect->size; +godot_string GDAPI godot_rect3_as_string(const godot_rect3 *p_self) { + godot_string ret; + const Rect3 *self = (const Rect3 *)p_self; + memnew_placement(&ret, String(*self)); + return ret; } -void GDAPI godot_rect3_set_size(godot_rect3 *p_rect, const godot_vector3 *p_size) { - Rect3 *rect = (Rect3 *)p_rect; - const Vector3 *size = (const Vector3 *)p_size; - rect->size = *size; +godot_real GDAPI godot_rect3_get_area(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_area(); +} + +godot_bool GDAPI godot_rect3_has_no_area(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->has_no_area(); +} + +godot_bool GDAPI godot_rect3_has_no_surface(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->has_no_surface(); +} + +godot_bool GDAPI godot_rect3_intersects(const godot_rect3 *p_self, const godot_rect3 *p_with) { + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *with = (const Rect3 *)p_with; + return self->intersects(*with); +} + +godot_bool GDAPI godot_rect3_encloses(const godot_rect3 *p_self, const godot_rect3 *p_with) { + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *with = (const Rect3 *)p_with; + return self->encloses(*with); +} + +godot_rect3 GDAPI godot_rect3_merge(const godot_rect3 *p_self, const godot_rect3 *p_with) { + godot_rect3 dest; + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *with = (const Rect3 *)p_with; + *((Rect3 *)&dest) = self->merge(*with); + return dest; +} + +godot_rect3 GDAPI godot_rect3_intersection(const godot_rect3 *p_self, const godot_rect3 *p_with) { + godot_rect3 dest; + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *with = (const Rect3 *)p_with; + *((Rect3 *)&dest) = self->intersection(*with); + return dest; +} + +godot_bool GDAPI godot_rect3_intersects_plane(const godot_rect3 *p_self, const godot_plane *p_plane) { + const Rect3 *self = (const Rect3 *)p_self; + const Plane *plane = (const Plane *)p_plane; + return self->intersects_plane(*plane); +} + +godot_bool GDAPI godot_rect3_intersects_segment(const godot_rect3 *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to) { + const Rect3 *self = (const Rect3 *)p_self; + const Vector3 *from = (const Vector3 *)p_from; + const Vector3 *to = (const Vector3 *)p_to; + return self->intersects_segment(*from, *to); +} + +godot_bool GDAPI godot_rect3_has_point(const godot_rect3 *p_self, const godot_vector3 *p_point) { + const Rect3 *self = (const Rect3 *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + return self->has_point(*point); +} + +godot_vector3 GDAPI godot_rect3_get_support(const godot_rect3 *p_self, const godot_vector3 *p_dir) { + godot_vector3 dest; + const Rect3 *self = (const Rect3 *)p_self; + const Vector3 *dir = (const Vector3 *)p_dir; + *((Vector3 *)&dest) = self->get_support(*dir); + return dest; +} + +godot_vector3 GDAPI godot_rect3_get_longest_axis(const godot_rect3 *p_self) { + godot_vector3 dest; + const Rect3 *self = (const Rect3 *)p_self; + *((Vector3 *)&dest) = self->get_longest_axis(); + return dest; +} + +godot_int GDAPI godot_rect3_get_longest_axis_index(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_longest_axis_index(); +} + +godot_real GDAPI godot_rect3_get_longest_axis_size(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_longest_axis_size(); +} + +godot_vector3 GDAPI godot_rect3_get_shortest_axis(const godot_rect3 *p_self) { + godot_vector3 dest; + const Rect3 *self = (const Rect3 *)p_self; + *((Vector3 *)&dest) = self->get_shortest_axis(); + return dest; +} + +godot_int GDAPI godot_rect3_get_shortest_axis_index(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_shortest_axis_index(); +} + +godot_real GDAPI godot_rect3_get_shortest_axis_size(const godot_rect3 *p_self) { + const Rect3 *self = (const Rect3 *)p_self; + return self->get_shortest_axis_size(); +} + +godot_rect3 GDAPI godot_rect3_expand(const godot_rect3 *p_self, const godot_vector3 *p_to_point) { + godot_rect3 dest; + const Rect3 *self = (const Rect3 *)p_self; + const Vector3 *to_point = (const Vector3 *)p_to_point; + *((Rect3 *)&dest) = self->expand(*to_point); + return dest; +} + +godot_rect3 GDAPI godot_rect3_grow(const godot_rect3 *p_self, const godot_real p_by) { + godot_rect3 dest; + const Rect3 *self = (const Rect3 *)p_self; + + *((Rect3 *)&dest) = self->grow(p_by); + return dest; +} + +godot_vector3 GDAPI godot_rect3_get_endpoint(const godot_rect3 *p_self, const godot_int p_idx) { + godot_vector3 dest; + const Rect3 *self = (const Rect3 *)p_self; + + *((Vector3 *)&dest) = self->get_endpoint(p_idx); + return dest; +} + +godot_bool GDAPI godot_rect3_operator_equal(const godot_rect3 *p_self, const godot_rect3 *p_b) { + const Rect3 *self = (const Rect3 *)p_self; + const Rect3 *b = (const Rect3 *)p_b; + return *self == *b; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_rect3.h b/modules/gdnative/godot/godot_rect3.h index 562ac8379e..9e9a49ac27 100644 --- a/modules/gdnative/godot/godot_rect3.h +++ b/modules/gdnative/godot/godot_rect3.h @@ -37,21 +37,67 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_RECT3_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_RECT3_TYPE_DEFINED typedef struct godot_rect3 { uint8_t _dont_touch_that[24]; } godot_rect3; #endif #include "../godot.h" +#include "godot_plane.h" +#include "godot_vector3.h" -void GDAPI godot_rect3_new(godot_rect3 *p_rect); -void GDAPI godot_rect3_new_with_pos_and_size(godot_rect3 *p_rect, const godot_vector3 *p_pos, const godot_vector3 *p_size); +void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size); -godot_vector3 GDAPI *godot_rect3_get_pos(godot_rect3 *p_rect); -void GDAPI godot_rect3_set_pos(godot_rect3 *p_rect, const godot_vector3 *p_pos); +godot_vector3 GDAPI godot_rect3_get_position(const godot_rect3 *p_self); +void GDAPI godot_rect3_set_position(const godot_rect3 *p_self, const godot_vector3 *p_v); -godot_vector3 GDAPI *godot_rect3_get_size(godot_rect3 *p_rect); -void GDAPI godot_rect3_set_size(godot_rect3 *p_rect, const godot_vector3 *p_size); +godot_vector3 GDAPI godot_rect3_get_size(const godot_rect3 *p_self); +void GDAPI godot_rect3_set_size(const godot_rect3 *p_self, const godot_vector3 *p_v); + +godot_string GDAPI godot_rect3_as_string(const godot_rect3 *p_self); + +godot_real GDAPI godot_rect3_get_area(const godot_rect3 *p_self); + +godot_bool GDAPI godot_rect3_has_no_area(const godot_rect3 *p_self); + +godot_bool GDAPI godot_rect3_has_no_surface(const godot_rect3 *p_self); + +godot_bool GDAPI godot_rect3_intersects(const godot_rect3 *p_self, const godot_rect3 *p_with); + +godot_bool GDAPI godot_rect3_encloses(const godot_rect3 *p_self, const godot_rect3 *p_with); + +godot_rect3 GDAPI godot_rect3_merge(const godot_rect3 *p_self, const godot_rect3 *p_with); + +godot_rect3 GDAPI godot_rect3_intersection(const godot_rect3 *p_self, const godot_rect3 *p_with); + +godot_bool GDAPI godot_rect3_intersects_plane(const godot_rect3 *p_self, const godot_plane *p_plane); + +godot_bool GDAPI godot_rect3_intersects_segment(const godot_rect3 *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to); + +godot_bool GDAPI godot_rect3_has_point(const godot_rect3 *p_self, const godot_vector3 *p_point); + +godot_vector3 GDAPI godot_rect3_get_support(const godot_rect3 *p_self, const godot_vector3 *p_dir); + +godot_vector3 GDAPI godot_rect3_get_longest_axis(const godot_rect3 *p_self); + +godot_int GDAPI godot_rect3_get_longest_axis_index(const godot_rect3 *p_self); + +godot_real GDAPI godot_rect3_get_longest_axis_size(const godot_rect3 *p_self); + +godot_vector3 GDAPI godot_rect3_get_shortest_axis(const godot_rect3 *p_self); + +godot_int GDAPI godot_rect3_get_shortest_axis_index(const godot_rect3 *p_self); + +godot_real GDAPI godot_rect3_get_shortest_axis_size(const godot_rect3 *p_self); + +godot_rect3 GDAPI godot_rect3_expand(const godot_rect3 *p_self, const godot_vector3 *p_to_point); + +godot_rect3 GDAPI godot_rect3_grow(const godot_rect3 *p_self, const godot_real p_by); + +godot_vector3 GDAPI godot_rect3_get_endpoint(const godot_rect3 *p_self, const godot_int p_idx); + +godot_bool GDAPI godot_rect3_operator_equal(const godot_rect3 *p_self, const godot_rect3 *p_b); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_rid.cpp b/modules/gdnative/godot/godot_rid.cpp index fff31e3992..343c004bff 100644 --- a/modules/gdnative/godot/godot_rid.cpp +++ b/modules/gdnative/godot/godot_rid.cpp @@ -28,36 +28,46 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_rid.h" +#include "core/variant.h" -#include "object.h" -#include "resource.h" +#include "core/resource.h" +#include "core/rid.h" #ifdef __cplusplus extern "C" { #endif -void _rid_api_anchor() { -} - -void GDAPI godot_rid_new(godot_rid *p_rid, godot_object *p_from) { +void _rid_api_anchor() {} - Resource *res_from = ((Object *)p_from)->cast_to<Resource>(); +void GDAPI godot_rid_new(godot_rid *r_dest) { + RID *dest = (RID *)r_dest; + memnew_placement(dest, RID); +} - RID *rid = (RID *)p_rid; - memnew_placement(rid, RID); +godot_int GDAPI godot_rid_get_id(const godot_rid *p_self) { + const RID *self = (const RID *)p_self; + return self->get_id(); +} +void GDAPI godot_rid_new_with_resource(godot_rid *r_dest, const godot_object *p_from) { + const Resource *res_from = ((const Object *)p_from)->cast_to<Resource>(); + godot_rid_new(r_dest); if (res_from) { - *rid = RID(res_from->get_rid()); + RID *dest = (RID *)r_dest; + *dest = RID(res_from->get_rid()); } } -uint32_t GDAPI godot_rid_get_rid(const godot_rid *p_rid) { - RID *rid = (RID *)p_rid; - return rid->get_id(); +godot_bool GDAPI godot_rid_operator_equal(const godot_rid *p_self, const godot_rid *p_b) { + const RID *self = (const RID *)p_self; + const RID *b = (const RID *)p_b; + return *self == *b; } -void GDAPI godot_rid_destroy(godot_rid *p_rid) { - ((RID *)p_rid)->~RID(); +godot_bool GDAPI godot_rid_operator_less(const godot_rid *p_self, const godot_rid *p_b) { + const RID *self = (const RID *)p_self; + const RID *b = (const RID *)p_b; + return *self < *b; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_rid.h b/modules/gdnative/godot/godot_rid.h index e00c8f89ad..25dc8d965e 100644 --- a/modules/gdnative/godot/godot_rid.h +++ b/modules/gdnative/godot/godot_rid.h @@ -37,6 +37,7 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_RID_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_RID_TYPE_DEFINED typedef struct godot_rid { uint8_t _dont_touch_that[8]; } godot_rid; @@ -44,11 +45,15 @@ typedef struct godot_rid { #include "../godot.h" -void GDAPI godot_rid_new(godot_rid *p_rid, godot_object *p_from); +void GDAPI godot_rid_new(godot_rid *r_dest); -uint32_t GDAPI godot_rid_get_rid(const godot_rid *p_rid); +godot_int GDAPI godot_rid_get_id(const godot_rid *p_self); -void GDAPI godot_rid_destroy(godot_rid *p_rid); +void GDAPI godot_rid_new_with_resource(godot_rid *r_dest, const godot_object *p_from); + +godot_bool GDAPI godot_rid_operator_equal(const godot_rid *p_self, const godot_rid *p_b); + +godot_bool GDAPI godot_rid_operator_less(const godot_rid *p_self, const godot_rid *p_b); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_string.cpp b/modules/gdnative/godot/godot_string.cpp index 757b8510cf..679011e715 100644 --- a/modules/gdnative/godot/godot_string.cpp +++ b/modules/gdnative/godot/godot_string.cpp @@ -41,70 +41,75 @@ extern "C" { void _string_api_anchor() { } -void GDAPI godot_string_new(godot_string *p_str) { - String *p = (String *)p_str; - memnew_placement(p, String); - // *p = String(); // useless here +void GDAPI godot_string_new(godot_string *r_dest) { + String *dest = (String *)r_dest; + memnew_placement(dest, String); } -void GDAPI godot_string_new_data(godot_string *p_str, const char *p_contents, const int p_size) { - String *p = (String *)p_str; - memnew_placement(p, String); - *p = String::utf8(p_contents, p_size); +void GDAPI godot_string_new_copy(godot_string *r_dest, const godot_string *p_src) { + String *dest = (String *)r_dest; + const String *src = (const String *)p_src; + memnew_placement(dest, String(*src)); } -void GDAPI godot_string_get_data(const godot_string *p_str, char *p_dest, int *p_size) { - String *p = (String *)p_str; +void GDAPI godot_string_new_data(godot_string *r_dest, const char *p_contents, const int p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String(String::utf8(p_contents, p_size))); +} + +void GDAPI godot_string_new_unicode_data(godot_string *r_dest, const wchar_t *p_contents, const int p_size) { + String *dest = (String *)r_dest; + memnew_placement(dest, String(p_contents, p_size)); +} + +void GDAPI godot_string_get_data(const godot_string *p_self, char *r_dest, int *p_size) { + String *self = (String *)p_self; if (p_size != NULL) { - *p_size = p->utf8().length(); + *p_size = self->utf8().length(); } - if (p_dest != NULL) { - memcpy(p_dest, p->utf8().get_data(), *p_size); + if (r_dest != NULL) { + memcpy(r_dest, self->utf8().get_data(), *p_size); } } -void GDAPI godot_string_copy_string(const godot_string *p_dest, const godot_string *p_src) { - String *dest = (String *)p_dest; - String *src = (String *)p_src; - - *dest = *src; +wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx) { + String *self = (String *)p_self; + return &(self->operator[](p_idx)); } -wchar_t GDAPI *godot_string_operator_index(godot_string *p_str, const godot_int p_idx) { - String *s = (String *)p_str; - return &(s->operator[](p_idx)); +const char GDAPI *godot_string_c_str(const godot_string *p_self) { + const String *self = (const String *)p_self; + return self->utf8().get_data(); } -const char GDAPI *godot_string_c_str(const godot_string *p_str) { - const String *s = (const String *)p_str; - return s->utf8().get_data(); +const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self) { + const String *self = (const String *)p_self; + return self->c_str(); } -godot_bool GDAPI godot_string_operator_equal(const godot_string *p_a, const godot_string *p_b) { - String *a = (String *)p_a; - String *b = (String *)p_b; - return *a == *b; +godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b) { + const String *self = (const String *)p_self; + const String *b = (const String *)p_b; + return *self == *b; } -godot_bool GDAPI godot_string_operator_less(const godot_string *p_a, const godot_string *p_b) { - String *a = (String *)p_a; - String *b = (String *)p_b; - return *a < *b; +godot_bool GDAPI godot_string_operator_less(const godot_string *p_self, const godot_string *p_b) { + const String *self = (const String *)p_self; + const String *b = (const String *)p_b; + return *self < *b; } -void GDAPI godot_string_operator_plus(godot_string *p_dest, const godot_string *p_a, const godot_string *p_b) { - String *dest = (String *)p_dest; - const String *a = (String *)p_a; - const String *b = (String *)p_b; - - String tmp = *a + *b; - godot_string_new(p_dest); - *dest = tmp; +godot_string GDAPI godot_string_operator_plus(const godot_string *p_self, const godot_string *p_b) { + godot_string ret; + const String *self = (const String *)p_self; + const String *b = (const String *)p_b; + memnew_placement(&ret, String(*self + *b)); + return ret; } -void GDAPI godot_string_destroy(godot_string *p_str) { - String *p = (String *)p_str; - p->~String(); +void GDAPI godot_string_destroy(godot_string *p_self) { + String *self = (String *)p_self; + self->~String(); } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_string.h b/modules/gdnative/godot/godot_string.h index 9289531c5e..df848abb76 100644 --- a/modules/gdnative/godot/godot_string.h +++ b/modules/gdnative/godot/godot_string.h @@ -35,6 +35,7 @@ extern "C" { #endif #include <stdint.h> +#include <wchar.h> #ifndef GODOT_CORE_API_GODOT_STRING_TYPE_DEFINED typedef struct godot_string { @@ -44,25 +45,26 @@ typedef struct godot_string { #include "../godot.h" -void GDAPI godot_string_new(godot_string *p_str); -void GDAPI godot_string_new_data(godot_string *p_str, const char *p_contents, const int p_size); +void GDAPI godot_string_new(godot_string *r_dest); +void GDAPI godot_string_new_copy(godot_string *r_dest, const godot_string *p_src); +void GDAPI godot_string_new_data(godot_string *r_dest, const char *p_contents, const int p_size); +void GDAPI godot_string_new_unicode_data(godot_string *r_dest, const wchar_t *p_contents, const int p_size); -void GDAPI godot_string_get_data(const godot_string *p_str, char *p_dest, int *p_size); +void GDAPI godot_string_get_data(const godot_string *p_self, char *p_dest, int *p_size); -void GDAPI godot_string_copy_string(const godot_string *p_dest, const godot_string *p_src); +wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx); +const char GDAPI *godot_string_c_str(const godot_string *p_self); +const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self); -wchar_t GDAPI *godot_string_operator_index(godot_string *p_str, const godot_int p_idx); -const char GDAPI *godot_string_c_str(const godot_string *p_str); - -godot_bool GDAPI godot_string_operator_equal(const godot_string *p_a, const godot_string *p_b); -godot_bool GDAPI godot_string_operator_less(const godot_string *p_a, const godot_string *p_b); -void GDAPI godot_string_operator_plus(godot_string *p_dest, const godot_string *p_a, const godot_string *p_b); +godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b); +godot_bool GDAPI godot_string_operator_less(const godot_string *p_self, const godot_string *p_b); +godot_string GDAPI godot_string_operator_plus(const godot_string *p_self, const godot_string *p_b); // @Incomplete // hmm, I guess exposing the whole API doesn't make much sense // since the language used in the library has its own string funcs -void GDAPI godot_string_destroy(godot_string *p_str); +void GDAPI godot_string_destroy(godot_string *p_self); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_transform.cpp b/modules/gdnative/godot/godot_transform.cpp index 681c2b049a..eb9e1e207b 100644 --- a/modules/gdnative/godot/godot_transform.cpp +++ b/modules/gdnative/godot/godot_transform.cpp @@ -28,42 +28,194 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_transform.h" +#include "core/variant.h" -#include "math/transform.h" +#include "core/math/transform.h" #ifdef __cplusplus extern "C" { #endif -void _transform_api_anchor() { -} +void _transform_api_anchor() {} -void GDAPI godot_transform_new(godot_transform *p_trans) { - Transform *trans = (Transform *)p_trans; - *trans = Transform(); +void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin) { + const Vector3 *x_axis = (const Vector3 *)p_x_axis; + const Vector3 *y_axis = (const Vector3 *)p_y_axis; + const Vector3 *z_axis = (const Vector3 *)p_z_axis; + const Vector3 *origin = (const Vector3 *)p_origin; + Transform *dest = (Transform *)r_dest; + dest->basis.set_axis(0, *x_axis); + dest->basis.set_axis(1, *y_axis); + dest->basis.set_axis(2, *z_axis); + dest->origin = *origin; } -void GDAPI godot_transform_new_with_basis(godot_transform *p_trans, const godot_basis *p_basis) { - Transform *trans = (Transform *)p_trans; +void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_basis, const godot_vector3 *p_origin) { const Basis *basis = (const Basis *)p_basis; - *trans = Transform(*basis); + const Vector3 *origin = (const Vector3 *)p_origin; + Transform *dest = (Transform *)r_dest; + *dest = Transform(*basis, *origin); } -void GDAPI godot_transform_new_with_basis_origin(godot_transform *p_trans, const godot_basis *p_basis, const godot_vector3 *p_origin) { - Transform *trans = (Transform *)p_trans; - const Basis *basis = (const Basis *)p_basis; - const Vector3 *origin = (const Vector3 *)p_origin; - *trans = Transform(*basis, *origin); +godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self) { + godot_basis dest; + const Transform *self = (const Transform *)p_self; + *((Basis *)&dest) = self->basis; + return dest; +} + +void GDAPI godot_transform_set_basis(godot_transform *p_self, godot_basis *p_v) { + Transform *self = (Transform *)p_self; + const Basis *v = (const Basis *)p_v; + self->basis = *v; +} + +godot_vector3 GDAPI godot_transform_get_origin(const godot_transform *p_self) { + godot_vector3 dest; + const Transform *self = (const Transform *)p_self; + *((Vector3 *)&dest) = self->origin; + return dest; +} + +void GDAPI godot_transform_set_origin(godot_transform *p_self, godot_vector3 *p_v) { + Transform *self = (Transform *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + self->origin = *v; +} + +godot_string GDAPI godot_transform_as_string(const godot_transform *p_self) { + godot_string ret; + const Transform *self = (const Transform *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_transform GDAPI godot_transform_inverse(const godot_transform *p_self) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + *((Transform *)&dest) = self->inverse(); + return dest; +} + +godot_transform GDAPI godot_transform_affine_inverse(const godot_transform *p_self) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + *((Transform *)&dest) = self->affine_inverse(); + return dest; +} + +godot_transform GDAPI godot_transform_orthonormalized(const godot_transform *p_self) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + *((Transform *)&dest) = self->orthonormalized(); + return dest; +} + +godot_transform GDAPI godot_transform_rotated(const godot_transform *p_self, const godot_vector3 *p_axis, const godot_real p_phi) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + *((Transform *)&dest) = self->rotated(*axis, p_phi); + return dest; +} + +godot_transform GDAPI godot_transform_scaled(const godot_transform *p_self, const godot_vector3 *p_scale) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *scale = (const Vector3 *)p_scale; + *((Transform *)&dest) = self->scaled(*scale); + return dest; +} + +godot_transform GDAPI godot_transform_translated(const godot_transform *p_self, const godot_vector3 *p_ofs) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *ofs = (const Vector3 *)p_ofs; + *((Transform *)&dest) = self->translated(*ofs); + return dest; +} + +godot_transform GDAPI godot_transform_looking_at(const godot_transform *p_self, const godot_vector3 *p_target, const godot_vector3 *p_up) { + godot_transform dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *target = (const Vector3 *)p_target; + const Vector3 *up = (const Vector3 *)p_up; + *((Transform *)&dest) = self->looking_at(*target, *up); + return dest; +} + +godot_plane GDAPI godot_transform_xform_plane(const godot_transform *p_self, const godot_plane *p_v) { + godot_plane raw_dest; + Plane *dest = (Plane *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Plane *v = (const Plane *)p_v; + *dest = self->xform(*v); + return raw_dest; +} + +godot_plane GDAPI godot_transform_xform_inv_plane(const godot_transform *p_self, const godot_plane *p_v) { + godot_plane raw_dest; + Plane *dest = (Plane *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Plane *v = (const Plane *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; +} + +void GDAPI godot_transform_new_identity(godot_transform *r_dest) { + Transform *dest = (Transform *)r_dest; + *dest = Transform(); +} + +godot_bool GDAPI godot_transform_operator_equal(const godot_transform *p_self, const godot_transform *p_b) { + const Transform *self = (const Transform *)p_self; + const Transform *b = (const Transform *)p_b; + return *self == *b; +} + +godot_transform GDAPI godot_transform_operator_multiply(const godot_transform *p_self, const godot_transform *p_b) { + godot_transform raw_dest; + Transform *dest = (Transform *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Transform *b = (const Transform *)p_b; + *dest = *self * *b; + return raw_dest; +} + +godot_vector3 GDAPI godot_transform_xform_vector3(const godot_transform *p_self, const godot_vector3 *p_v) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *dest = self->xform(*v); + return raw_dest; +} + +godot_vector3 GDAPI godot_transform_xform_inv_vector3(const godot_transform *p_self, const godot_vector3 *p_v) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; } -godot_basis GDAPI *godot_transform_get_basis(godot_transform *p_trans) { - Transform *trans = (Transform *)p_trans; - return (godot_basis *)&trans->basis; +godot_rect3 GDAPI godot_transform_xform_rect3(const godot_transform *p_self, const godot_rect3 *p_v) { + godot_rect3 raw_dest; + Rect3 *dest = (Rect3 *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Rect3 *v = (const Rect3 *)p_v; + *dest = self->xform(*v); + return raw_dest; } -godot_vector3 GDAPI *godot_transform_get_origin(godot_transform *p_trans) { - Transform *trans = (Transform *)p_trans; - return (godot_vector3 *)&trans->origin; +godot_rect3 GDAPI godot_transform_xform_inv_rect3(const godot_transform *p_self, const godot_rect3 *p_v) { + godot_rect3 raw_dest; + Rect3 *dest = (Rect3 *)&raw_dest; + const Transform *self = (const Transform *)p_self; + const Rect3 *v = (const Rect3 *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_transform.h b/modules/gdnative/godot/godot_transform.h index 93817ffbf2..ee87e1d33f 100644 --- a/modules/gdnative/godot/godot_transform.h +++ b/modules/gdnative/godot/godot_transform.h @@ -37,19 +37,59 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED typedef struct godot_transform { uint8_t _dont_touch_that[48]; } godot_transform; #endif #include "../godot.h" +#include "godot_basis.h" +#include "godot_variant.h" +#include "godot_vector3.h" -void GDAPI godot_transform_new(godot_transform *p_trans); -void GDAPI godot_transform_new_with_basis(godot_transform *p_trans, const godot_basis *p_basis); -void GDAPI godot_transform_new_with_basis_origin(godot_transform *p_trans, const godot_basis *p_basis, const godot_vector3 *p_origin); +void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin); +void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_basis, const godot_vector3 *p_origin); -godot_basis GDAPI *godot_transform_get_basis(godot_transform *p_trans); -godot_vector3 GDAPI *godot_transform_get_origin(godot_transform *p_trans); +godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self); +void GDAPI godot_transform_set_basis(godot_transform *p_self, godot_basis *p_v); + +godot_vector3 GDAPI godot_transform_get_origin(const godot_transform *p_self); +void GDAPI godot_transform_set_origin(godot_transform *p_self, godot_vector3 *p_v); + +godot_string GDAPI godot_transform_as_string(const godot_transform *p_self); + +godot_transform GDAPI godot_transform_inverse(const godot_transform *p_self); + +godot_transform GDAPI godot_transform_affine_inverse(const godot_transform *p_self); + +godot_transform GDAPI godot_transform_orthonormalized(const godot_transform *p_self); + +godot_transform GDAPI godot_transform_rotated(const godot_transform *p_self, const godot_vector3 *p_axis, const godot_real p_phi); + +godot_transform GDAPI godot_transform_scaled(const godot_transform *p_self, const godot_vector3 *p_scale); + +godot_transform GDAPI godot_transform_translated(const godot_transform *p_self, const godot_vector3 *p_ofs); + +godot_transform GDAPI godot_transform_looking_at(const godot_transform *p_self, const godot_vector3 *p_target, const godot_vector3 *p_up); + +godot_plane GDAPI godot_transform_xform_plane(const godot_transform *p_self, const godot_plane *p_v); + +godot_plane GDAPI godot_transform_xform_inv_plane(const godot_transform *p_self, const godot_plane *p_v); + +void GDAPI godot_transform_new_identity(godot_transform *r_dest); + +godot_bool GDAPI godot_transform_operator_equal(const godot_transform *p_self, const godot_transform *p_b); + +godot_transform GDAPI godot_transform_operator_multiply(const godot_transform *p_self, const godot_transform *p_b); + +godot_vector3 GDAPI godot_transform_xform_vector3(const godot_transform *p_self, const godot_vector3 *p_v); + +godot_vector3 GDAPI godot_transform_xform_inv_vector3(const godot_transform *p_self, const godot_vector3 *p_v); + +godot_rect3 GDAPI godot_transform_xform_rect3(const godot_transform *p_self, const godot_rect3 *p_v); + +godot_rect3 GDAPI godot_transform_xform_inv_rect3(const godot_transform *p_self, const godot_rect3 *p_v); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_transform2d.cpp b/modules/gdnative/godot/godot_transform2d.cpp index ffc7167559..bdb5476f7d 100644 --- a/modules/gdnative/godot/godot_transform2d.cpp +++ b/modules/gdnative/godot/godot_transform2d.cpp @@ -28,60 +28,182 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_transform2d.h" +#include "core/variant.h" -#include "../godot.h" - -#include "math/math_2d.h" +#include "core/math/math_2d.h" #ifdef __cplusplus extern "C" { #endif -void _transform2d_api_anchor() { +void _transform2d_api_anchor() {} + +void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos) { + const Vector2 *pos = (const Vector2 *)p_pos; + Transform2D *dest = (Transform2D *)r_dest; + *dest = Transform2D(p_rot, *pos); +} + +void GDAPI godot_transform2d_new_axis_origin(godot_transform2d *r_dest, const godot_vector2 *p_x_axis, const godot_vector2 *p_y_axis, const godot_vector2 *p_origin) { + const Vector2 *x_axis = (const Vector2 *)p_x_axis; + const Vector2 *y_axis = (const Vector2 *)p_y_axis; + const Vector2 *origin = (const Vector2 *)p_origin; + Transform2D *dest = (Transform2D *)r_dest; + *dest = Transform2D(x_axis->x, x_axis->y, y_axis->x, y_axis->y, origin->x, origin->y); +} + +godot_string GDAPI godot_transform2d_as_string(const godot_transform2d *p_self) { + godot_string ret; + const Transform2D *self = (const Transform2D *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_transform2d GDAPI godot_transform2d_inverse(const godot_transform2d *p_self) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Transform2D *)&dest) = self->inverse(); + return dest; +} + +godot_transform2d GDAPI godot_transform2d_affine_inverse(const godot_transform2d *p_self) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Transform2D *)&dest) = self->affine_inverse(); + return dest; +} + +godot_real GDAPI godot_transform2d_get_rotation(const godot_transform2d *p_self) { + const Transform2D *self = (const Transform2D *)p_self; + return self->get_rotation(); +} + +godot_vector2 GDAPI godot_transform2d_get_origin(const godot_transform2d *p_self) { + godot_vector2 dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Vector2 *)&dest) = self->get_origin(); + return dest; +} + +godot_vector2 GDAPI godot_transform2d_get_scale(const godot_transform2d *p_self) { + godot_vector2 dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Vector2 *)&dest) = self->get_scale(); + return dest; +} + +godot_transform2d GDAPI godot_transform2d_orthonormalized(const godot_transform2d *p_self) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + *((Transform2D *)&dest) = self->orthonormalized(); + return dest; +} + +godot_transform2d GDAPI godot_transform2d_rotated(const godot_transform2d *p_self, const godot_real p_phi) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + + *((Transform2D *)&dest) = self->rotated(p_phi); + return dest; +} + +godot_transform2d GDAPI godot_transform2d_scaled(const godot_transform2d *p_self, const godot_vector2 *p_scale) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *scale = (const Vector2 *)p_scale; + *((Transform2D *)&dest) = self->scaled(*scale); + return dest; } -void GDAPI godot_transform2d_new_identity(godot_transform2d *p_t) { - Transform2D *t = (Transform2D *)p_t; - *t = Transform2D(); +godot_transform2d GDAPI godot_transform2d_translated(const godot_transform2d *p_self, const godot_vector2 *p_offset) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *offset = (const Vector2 *)p_offset; + *((Transform2D *)&dest) = self->translated(*offset); + return dest; } -void GDAPI godot_transform2d_new_elements(godot_transform2d *p_t, const godot_vector2 *p_a, const godot_vector2 *p_b, const godot_vector2 *p_c) { - Transform2D *t = (Transform2D *)p_t; - Vector2 *a = (Vector2 *)p_a; - Vector2 *b = (Vector2 *)p_b; - Vector2 *c = (Vector2 *)p_c; - *t = Transform2D(a->x, a->y, b->x, b->y, c->x, c->y); +godot_vector2 GDAPI godot_transform2d_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *v = (const Vector2 *)p_v; + *dest = self->xform(*v); + return raw_dest; } -void GDAPI godot_transform2d_new(godot_transform2d *p_t, const godot_real p_rot, const godot_vector2 *p_pos) { - Transform2D *t = (Transform2D *)p_t; - Vector2 *pos = (Vector2 *)p_pos; - *t = Transform2D(p_rot, *pos); +godot_vector2 GDAPI godot_transform2d_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *v = (const Vector2 *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; } -godot_vector2 const GDAPI *godot_transform2d_const_index(const godot_transform2d *p_t, const godot_int p_idx) { - const Transform2D *t = (const Transform2D *)p_t; - const Vector2 *e = &t->operator[](p_idx); - return (godot_vector2 const *)e; +godot_vector2 GDAPI godot_transform2d_basis_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *v = (const Vector2 *)p_v; + *dest = self->basis_xform(*v); + return raw_dest; } -godot_vector2 GDAPI *godot_transform2d_index(godot_transform2d *p_t, const godot_int p_idx) { - Transform2D *t = (Transform2D *)p_t; - Vector2 *e = &t->operator[](p_idx); - return (godot_vector2 *)e; +godot_vector2 GDAPI godot_transform2d_basis_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Vector2 *v = (const Vector2 *)p_v; + *dest = self->basis_xform_inv(*v); + return raw_dest; } -godot_vector2 GDAPI godot_transform2d_get_axis(const godot_transform2d *p_t, const godot_int p_axis) { - return *godot_transform2d_const_index(p_t, p_axis); +godot_transform2d GDAPI godot_transform2d_interpolate_with(const godot_transform2d *p_self, const godot_transform2d *p_m, const godot_real p_c) { + godot_transform2d dest; + const Transform2D *self = (const Transform2D *)p_self; + const Transform2D *m = (const Transform2D *)p_m; + *((Transform2D *)&dest) = self->interpolate_with(*m, p_c); + return dest; } -void GDAPI godot_transform2d_set_axis(godot_transform2d *p_t, const godot_int p_axis, const godot_vector2 *p_vec) { - godot_vector2 *origin_v = godot_transform2d_index(p_t, p_axis); - *origin_v = *p_vec; +godot_bool GDAPI godot_transform2d_operator_equal(const godot_transform2d *p_self, const godot_transform2d *p_b) { + const Transform2D *self = (const Transform2D *)p_self; + const Transform2D *b = (const Transform2D *)p_b; + return *self == *b; } -// @Incomplete -// See header file +godot_transform2d GDAPI godot_transform2d_operator_multiply(const godot_transform2d *p_self, const godot_transform2d *p_b) { + godot_transform2d raw_dest; + Transform2D *dest = (Transform2D *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Transform2D *b = (const Transform2D *)p_b; + *dest = *self * *b; + return raw_dest; +} + +void GDAPI godot_transform2d_new_identity(godot_transform2d *r_dest) { + Transform2D *dest = (Transform2D *)r_dest; + *dest = Transform2D(); +} + +godot_rect2 GDAPI godot_transform2d_xform_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v) { + godot_rect2 raw_dest; + Rect2 *dest = (Rect2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Rect2 *v = (const Rect2 *)p_v; + *dest = self->xform(*v); + return raw_dest; +} + +godot_rect2 GDAPI godot_transform2d_xform_inv_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v) { + godot_rect2 raw_dest; + Rect2 *dest = (Rect2 *)&raw_dest; + const Transform2D *self = (const Transform2D *)p_self; + const Rect2 *v = (const Rect2 *)p_v; + *dest = self->xform_inv(*v); + return raw_dest; +} #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_transform2d.h b/modules/gdnative/godot/godot_transform2d.h index ae0569dbe8..c375e90af7 100644 --- a/modules/gdnative/godot/godot_transform2d.h +++ b/modules/gdnative/godot/godot_transform2d.h @@ -44,31 +44,51 @@ typedef struct godot_transform2d { #endif #include "../godot.h" - +#include "godot_variant.h" #include "godot_vector2.h" -void GDAPI godot_transform2d_new_identity(godot_transform2d *p_t); -void GDAPI godot_transform2d_new_elements(godot_transform2d *p_t, const godot_vector2 *p_a, const godot_vector2 *p_b, const godot_vector2 *p_c); -void GDAPI godot_transform2d_new(godot_transform2d *p_t, const godot_real p_rot, const godot_vector2 *p_pos); +void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos); +void GDAPI godot_transform2d_new_axis_origin(godot_transform2d *r_dest, const godot_vector2 *p_x_axis, const godot_vector2 *p_y_axis, const godot_vector2 *p_origin); + +godot_string GDAPI godot_transform2d_as_string(const godot_transform2d *p_self); + +godot_transform2d GDAPI godot_transform2d_inverse(const godot_transform2d *p_self); + +godot_transform2d GDAPI godot_transform2d_affine_inverse(const godot_transform2d *p_self); + +godot_real GDAPI godot_transform2d_get_rotation(const godot_transform2d *p_self); + +godot_vector2 GDAPI godot_transform2d_get_origin(const godot_transform2d *p_self); + +godot_vector2 GDAPI godot_transform2d_get_scale(const godot_transform2d *p_self); + +godot_transform2d GDAPI godot_transform2d_orthonormalized(const godot_transform2d *p_self); + +godot_transform2d GDAPI godot_transform2d_rotated(const godot_transform2d *p_self, const godot_real p_phi); + +godot_transform2d GDAPI godot_transform2d_scaled(const godot_transform2d *p_self, const godot_vector2 *p_scale); + +godot_transform2d GDAPI godot_transform2d_translated(const godot_transform2d *p_self, const godot_vector2 *p_offset); + +godot_vector2 GDAPI godot_transform2d_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v); + +godot_vector2 GDAPI godot_transform2d_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v); + +godot_vector2 GDAPI godot_transform2d_basis_xform_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v); + +godot_vector2 GDAPI godot_transform2d_basis_xform_inv_vector2(const godot_transform2d *p_self, const godot_vector2 *p_v); + +godot_transform2d GDAPI godot_transform2d_interpolate_with(const godot_transform2d *p_self, const godot_transform2d *p_m, const godot_real p_c); -/* -godot_real GDAPI godot_transform2d_tdotx(const godot_transform2d *p_t, const godot_vector2 *p_v); -godot_real GDAPI godot_transform2d_tdoty(const godot_transform2d *p_t, const godot_vector2 *p_v); -*/ +godot_bool GDAPI godot_transform2d_operator_equal(const godot_transform2d *p_self, const godot_transform2d *p_b); -godot_vector2 const GDAPI *godot_transform2d_const_index(const godot_transform2d *p_t, const godot_int p_idx); -godot_vector2 GDAPI *godot_transform2d_index(godot_transform2d *p_t, const godot_int p_idx); +godot_transform2d GDAPI godot_transform2d_operator_multiply(const godot_transform2d *p_self, const godot_transform2d *p_b); -godot_vector2 GDAPI godot_transform2d_get_axis(const godot_transform2d *p_t, const godot_int p_axis); -void GDAPI godot_transform2d_set_axis(godot_transform2d *p_t, const godot_int p_axis, const godot_vector2 *p_vec); +void GDAPI godot_transform2d_new_identity(godot_transform2d *r_dest); -/* -void GDAPI godot_transform2d_invert(godot_transform2d *p_t); -godot_transform2d GDAPI godot_transform2d_inverse(const godot_transform2d *p_t); -*/ +godot_rect2 GDAPI godot_transform2d_xform_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v); -// @Incomplete -// I feel like it should be enough to expose get and set, the whole logic can be done in the bindings. +godot_rect2 GDAPI godot_transform2d_xform_inv_rect2(const godot_transform2d *p_self, const godot_rect2 *p_v); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_variant.cpp b/modules/gdnative/godot/godot_variant.cpp index 2214f85056..c9607fb21a 100644 --- a/modules/gdnative/godot/godot_variant.cpp +++ b/modules/gdnative/godot/godot_variant.cpp @@ -28,476 +28,452 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_variant.h" - -#include "../godot.h" - -#include "variant.h" +#include "core/variant.h" #ifdef __cplusplus extern "C" { #endif -void _variant_api_anchor() { -} +void _variant_api_anchor() {} #define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) -godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - return (godot_variant_type)v->get_type(); +// Constructors + +godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return (godot_variant_type)self->get_type(); } -void GDAPI godot_variant_copy(godot_variant *p_dest, const godot_variant *p_src) { +void GDAPI godot_variant_new_copy(godot_variant *p_dest, const godot_variant *p_src) { Variant *dest = (Variant *)p_dest; Variant *src = (Variant *)p_src; - *dest = *src; + memnew_placement(dest, Variant(*src)); } -void GDAPI godot_variant_new_nil(godot_variant *p_v) { - Variant *v = (Variant *)p_v; - memnew_placement(v, Variant); +void GDAPI godot_variant_new_nil(godot_variant *r_dest) { + Variant *dest = (Variant *)r_dest; + memnew_placement(dest, Variant); } -void GDAPI godot_variant_new_bool(godot_variant *p_v, const godot_bool p_b) { - Variant *v = (Variant *)p_v; - memnew_placement_custom(v, Variant, Variant(p_b)); +void GDAPI godot_variant_new_bool(godot_variant *r_dest, const godot_bool p_b) { + Variant *dest = (Variant *)r_dest; + memnew_placement_custom(dest, Variant, Variant(p_b)); } -void GDAPI godot_variant_new_uint(godot_variant *p_v, const uint64_t p_i) { - Variant *v = (Variant *)p_v; - memnew_placement_custom(v, Variant, Variant(p_i)); +void GDAPI godot_variant_new_uint(godot_variant *r_dest, const uint64_t p_i) { + Variant *dest = (Variant *)r_dest; + memnew_placement_custom(dest, Variant, Variant(p_i)); } -void GDAPI godot_variant_new_int(godot_variant *p_v, const int64_t p_i) { - Variant *v = (Variant *)p_v; - memnew_placement_custom(v, Variant, Variant(p_i)); +void GDAPI godot_variant_new_int(godot_variant *r_dest, const int64_t p_i) { + Variant *dest = (Variant *)r_dest; + memnew_placement_custom(dest, Variant, Variant(p_i)); } -void GDAPI godot_variant_new_real(godot_variant *p_v, const double p_r) { - Variant *v = (Variant *)p_v; - memnew_placement_custom(v, Variant, Variant(p_r)); +void GDAPI godot_variant_new_real(godot_variant *r_dest, const double p_r) { + Variant *dest = (Variant *)r_dest; + memnew_placement_custom(dest, Variant, Variant(p_r)); } -void GDAPI godot_variant_new_string(godot_variant *p_v, const godot_string *p_s) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_string(godot_variant *r_dest, const godot_string *p_s) { + Variant *dest = (Variant *)r_dest; String *s = (String *)p_s; - memnew_placement_custom(v, Variant, Variant(*s)); + memnew_placement_custom(dest, Variant, Variant(*s)); } -void GDAPI godot_variant_new_vector2(godot_variant *p_v, const godot_vector2 *p_v2) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_vector2(godot_variant *r_dest, const godot_vector2 *p_v2) { + Variant *dest = (Variant *)r_dest; Vector2 *v2 = (Vector2 *)p_v2; - memnew_placement_custom(v, Variant, Variant(*v2)); + memnew_placement_custom(dest, Variant, Variant(*v2)); } -void GDAPI godot_variant_new_rect2(godot_variant *p_v, const godot_rect2 *p_rect2) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_rect2(godot_variant *r_dest, const godot_rect2 *p_rect2) { + Variant *dest = (Variant *)r_dest; Rect2 *rect2 = (Rect2 *)p_rect2; - memnew_placement_custom(v, Variant, Variant(*rect2)); + memnew_placement_custom(dest, Variant, Variant(*rect2)); } -void GDAPI godot_variant_new_vector3(godot_variant *p_v, const godot_vector3 *p_v3) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_vector3(godot_variant *r_dest, const godot_vector3 *p_v3) { + Variant *dest = (Variant *)r_dest; Vector3 *v3 = (Vector3 *)p_v3; - memnew_placement_custom(v, Variant, Variant(*v3)); + memnew_placement_custom(dest, Variant, Variant(*v3)); } -void GDAPI godot_variant_new_transform2d(godot_variant *p_v, const godot_transform2d *p_t2d) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_transform2d(godot_variant *r_dest, const godot_transform2d *p_t2d) { + Variant *dest = (Variant *)r_dest; Transform2D *t2d = (Transform2D *)p_t2d; - memnew_placement_custom(v, Variant, Variant(*t2d)); + memnew_placement_custom(dest, Variant, Variant(*t2d)); } -void GDAPI godot_variant_new_plane(godot_variant *p_v, const godot_plane *p_plane) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_plane(godot_variant *r_dest, const godot_plane *p_plane) { + Variant *dest = (Variant *)r_dest; Plane *plane = (Plane *)p_plane; - memnew_placement_custom(v, Variant, Variant(*plane)); + memnew_placement_custom(dest, Variant, Variant(*plane)); } -void GDAPI godot_variant_new_quat(godot_variant *p_v, const godot_quat *p_quat) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_quat) { + Variant *dest = (Variant *)r_dest; Quat *quat = (Quat *)p_quat; - memnew_placement_custom(v, Variant, Variant(*quat)); + memnew_placement_custom(dest, Variant, Variant(*quat)); } -void GDAPI godot_variant_new_rect3(godot_variant *p_v, const godot_rect3 *p_rect3) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_rect3(godot_variant *r_dest, const godot_rect3 *p_rect3) { + Variant *dest = (Variant *)r_dest; Rect3 *rect3 = (Rect3 *)p_rect3; - memnew_placement_custom(v, Variant, Variant(*rect3)); + memnew_placement_custom(dest, Variant, Variant(*rect3)); } -void GDAPI godot_variant_new_basis(godot_variant *p_v, const godot_basis *p_basis) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis) { + Variant *dest = (Variant *)r_dest; Basis *basis = (Basis *)p_basis; - memnew_placement_custom(v, Variant, Variant(*basis)); + memnew_placement_custom(dest, Variant, Variant(*basis)); } -void GDAPI godot_variant_new_transform(godot_variant *p_v, const godot_transform *p_trans) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_transform(godot_variant *r_dest, const godot_transform *p_trans) { + Variant *dest = (Variant *)r_dest; Transform *trans = (Transform *)p_trans; - memnew_placement_custom(v, Variant, Variant(*trans)); + memnew_placement_custom(dest, Variant, Variant(*trans)); } -void GDAPI godot_variant_new_color(godot_variant *p_v, const godot_color *p_color) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_color(godot_variant *r_dest, const godot_color *p_color) { + Variant *dest = (Variant *)r_dest; Color *color = (Color *)p_color; - memnew_placement_custom(v, Variant, Variant(*color)); + memnew_placement_custom(dest, Variant, Variant(*color)); } -void GDAPI godot_variant_new_image(godot_variant *p_v, const godot_image *p_img) { - Variant *v = (Variant *)p_v; - Image *img = (Image *)p_img; - memnew_placement_custom(v, Variant, Variant(*img)); -} - -void GDAPI godot_variant_new_node_path(godot_variant *p_v, const godot_node_path *p_np) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_node_path(godot_variant *r_dest, const godot_node_path *p_np) { + Variant *dest = (Variant *)r_dest; NodePath *np = (NodePath *)p_np; - memnew_placement_custom(v, Variant, Variant(*np)); + memnew_placement_custom(dest, Variant, Variant(*np)); } -void GDAPI godot_variant_new_rid(godot_variant *p_v, const godot_rid *p_rid) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid) { + Variant *dest = (Variant *)r_dest; RID *rid = (RID *)p_rid; - memnew_placement_custom(v, Variant, Variant(*rid)); + memnew_placement_custom(dest, Variant, Variant(*rid)); } -void GDAPI godot_variant_new_object(godot_variant *p_v, const godot_object *p_obj) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj) { + Variant *dest = (Variant *)r_dest; Object *obj = (Object *)p_obj; - memnew_placement_custom(v, Variant, Variant(obj)); -} - -void GDAPI godot_variant_new_input_event(godot_variant *p_v, const godot_input_event *p_event) { - Variant *v = (Variant *)p_v; - InputEvent *event = (InputEvent *)p_event; - memnew_placement_custom(v, Variant, Variant(*event)); + memnew_placement_custom(dest, Variant, Variant(obj)); } -void GDAPI godot_variant_new_dictionary(godot_variant *p_v, const godot_dictionary *p_dict) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict) { + Variant *dest = (Variant *)r_dest; Dictionary *dict = (Dictionary *)p_dict; - memnew_placement_custom(v, Variant, Variant(*dict)); + memnew_placement_custom(dest, Variant, Variant(*dict)); } -void GDAPI godot_variant_new_array(godot_variant *p_v, const godot_array *p_arr) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_array(godot_variant *r_dest, const godot_array *p_arr) { + Variant *dest = (Variant *)r_dest; Array *arr = (Array *)p_arr; - memnew_placement_custom(v, Variant, Variant(*arr)); + memnew_placement_custom(dest, Variant, Variant(*arr)); } -void GDAPI godot_variant_new_pool_byte_array(godot_variant *p_v, const godot_pool_byte_array *p_pba) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_pool_byte_array(godot_variant *r_dest, const godot_pool_byte_array *p_pba) { + Variant *dest = (Variant *)r_dest; PoolByteArray *pba = (PoolByteArray *)p_pba; - memnew_placement_custom(v, Variant, Variant(*pba)); + memnew_placement_custom(dest, Variant, Variant(*pba)); } -void GDAPI godot_variant_new_pool_int_array(godot_variant *p_v, const godot_pool_int_array *p_pia) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_pool_int_array(godot_variant *r_dest, const godot_pool_int_array *p_pia) { + Variant *dest = (Variant *)r_dest; PoolIntArray *pia = (PoolIntArray *)p_pia; - memnew_placement_custom(v, Variant, Variant(*pia)); + memnew_placement_custom(dest, Variant, Variant(*pia)); } -void GDAPI godot_variant_new_pool_real_array(godot_variant *p_v, const godot_pool_real_array *p_pra) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_pool_real_array(godot_variant *r_dest, const godot_pool_real_array *p_pra) { + Variant *dest = (Variant *)r_dest; PoolRealArray *pra = (PoolRealArray *)p_pra; - memnew_placement_custom(v, Variant, Variant(*pra)); + memnew_placement_custom(dest, Variant, Variant(*pra)); } -void GDAPI godot_variant_new_pool_string_array(godot_variant *p_v, const godot_pool_string_array *p_psa) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_pool_string_array(godot_variant *r_dest, const godot_pool_string_array *p_psa) { + Variant *dest = (Variant *)r_dest; PoolStringArray *psa = (PoolStringArray *)p_psa; - memnew_placement_custom(v, Variant, Variant(*psa)); + memnew_placement_custom(dest, Variant, Variant(*psa)); } -void GDAPI godot_variant_new_pool_vector2_array(godot_variant *p_v, const godot_pool_vector2_array *p_pv2a) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_pool_vector2_array(godot_variant *r_dest, const godot_pool_vector2_array *p_pv2a) { + Variant *dest = (Variant *)r_dest; PoolVector2Array *pv2a = (PoolVector2Array *)p_pv2a; - memnew_placement_custom(v, Variant, Variant(*pv2a)); + memnew_placement_custom(dest, Variant, Variant(*pv2a)); } -void GDAPI godot_variant_new_pool_vector3_array(godot_variant *p_v, const godot_pool_vector3_array *p_pv3a) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_pool_vector3_array(godot_variant *r_dest, const godot_pool_vector3_array *p_pv3a) { + Variant *dest = (Variant *)r_dest; PoolVector3Array *pv3a = (PoolVector3Array *)p_pv3a; - memnew_placement_custom(v, Variant, Variant(*pv3a)); + memnew_placement_custom(dest, Variant, Variant(*pv3a)); } -void GDAPI godot_variant_new_pool_color_array(godot_variant *p_v, const godot_pool_color_array *p_pca) { - Variant *v = (Variant *)p_v; +void GDAPI godot_variant_new_pool_color_array(godot_variant *r_dest, const godot_pool_color_array *p_pca) { + Variant *dest = (Variant *)r_dest; PoolColorArray *pca = (PoolColorArray *)p_pca; - memnew_placement_custom(v, Variant, Variant(*pca)); + memnew_placement_custom(dest, Variant, Variant(*pca)); } -godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - return v->operator bool(); +godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return self->operator bool(); } -uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - return v->operator uint64_t(); +uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return self->operator uint64_t(); } -int64_t GDAPI godot_variant_as_int(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - return v->operator int64_t(); +int64_t GDAPI godot_variant_as_int(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return self->operator int64_t(); } -double GDAPI godot_variant_as_real(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - return v->operator double(); +double GDAPI godot_variant_as_real(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + return self->operator double(); } -godot_string GDAPI godot_variant_as_string(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_string s; - godot_string_new(&s); - String *str = (String *)&s; - *str = v->operator String(); - return s; +godot_string GDAPI godot_variant_as_string(const godot_variant *p_self) { + godot_string raw_dest; + const Variant *self = (const Variant *)p_self; + String *dest = (String *)&raw_dest; + memnew_placement(dest, String(self->operator String())); // operator = is overloaded by String + return raw_dest; } -godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_vector2 v2; - Vector2 *vec2 = (Vector2 *)&v2; - *vec2 = *v; - return v2; +godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_self) { + godot_vector2 raw_dest; + const Variant *self = (const Variant *)p_self; + Vector2 *dest = (Vector2 *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_rect2 r2; - Rect2 *rect2 = (Rect2 *)&r2; - *rect2 = *v; - return r2; +godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_self) { + godot_rect2 raw_dest; + const Variant *self = (const Variant *)p_self; + Rect2 *dest = (Rect2 *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_vector3 v3; - Vector3 *vec3 = (Vector3 *)&v3; - *vec3 = *v; - return v3; +godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self) { + godot_vector3 raw_dest; + const Variant *self = (const Variant *)p_self; + Vector3 *dest = (Vector3 *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_transform2d t2; - Transform2D *t = (Transform2D *)&t2; - *t = *v; - return t2; +godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_self) { + godot_transform2d raw_dest; + const Variant *self = (const Variant *)p_self; + Transform2D *dest = (Transform2D *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_plane p; - Plane *pl = (Plane *)&p; - *pl = *v; - return p; +godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_self) { + godot_plane raw_dest; + const Variant *self = (const Variant *)p_self; + Plane *dest = (Plane *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_quat q; - Quat *qt = (Quat *)&q; - *qt = *v; - return q; +godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_self) { + godot_quat raw_dest; + const Variant *self = (const Variant *)p_self; + Quat *dest = (Quat *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_rect3 r; - Rect3 *r3 = (Rect3 *)&r; - *r3 = *v; - return r; +godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_self) { + godot_rect3 raw_dest; + const Variant *self = (const Variant *)p_self; + Rect3 *dest = (Rect3 *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_basis b; - Basis *bs = (Basis *)&b; - *bs = *v; - return b; +godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_self) { + godot_basis raw_dest; + const Variant *self = (const Variant *)p_self; + Basis *dest = (Basis *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_transform t; - Transform *tr = (Transform *)&t; - *tr = *v; - return t; +godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_self) { + godot_transform raw_dest; + const Variant *self = (const Variant *)p_self; + Transform *dest = (Transform *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_color GDAPI godot_variant_as_color(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_color c; - Color *col = (Color *)&c; - *col = *v; - return c; +godot_color GDAPI godot_variant_as_color(const godot_variant *p_self) { + godot_color raw_dest; + const Variant *self = (const Variant *)p_self; + Color *dest = (Color *)&raw_dest; + *dest = *self; + return raw_dest; } -godot_image GDAPI godot_variant_as_image(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_image img; - godot_image_new(&img); - Image *i = (Image *)&img; - *i = *v; - return img; -} - -godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_node_path np; - memnew_placement_custom((NodePath *)&np, NodePath, NodePath((String)*v)); - return np; -} - -godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_rid rid; - memnew_placement_custom((RID *)&rid, RID, RID(*v)); - return rid; -} - -godot_object GDAPI *godot_variant_as_object(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_object *p = NULL; - Object **op = (Object **)&p; - *op = *v; - return p; -} - -godot_input_event GDAPI godot_variant_as_input_event(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_input_event ev; - InputEvent *event = (InputEvent *)&ev; - *event = *v; - return ev; -} - -godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_dictionary dict; - godot_dictionary_new(&dict); - Dictionary *d = (Dictionary *)&dict; - *d = *v; - return dict; -} - -godot_array GDAPI godot_variant_as_array(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_array array; - godot_array_new(&array); - Array *a = (Array *)&array; - *a = *v; - return array; -} - -godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_pool_byte_array pba; - godot_pool_byte_array_new(&pba); - PoolByteArray *p = (PoolByteArray *)&pba; - *p = *v; - return pba; -} - -godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_pool_int_array pba; - godot_pool_int_array_new(&pba); - PoolIntArray *p = (PoolIntArray *)&pba; - *p = *v; - return pba; -} - -godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_pool_real_array pba; - godot_pool_real_array_new(&pba); - PoolRealArray *p = (PoolRealArray *)&pba; - *p = *v; - return pba; -} - -godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_pool_string_array pba; - godot_pool_string_array_new(&pba); - PoolStringArray *p = (PoolStringArray *)&pba; - *p = *v; - return pba; -} - -godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_pool_vector2_array pba; - godot_pool_vector2_array_new(&pba); - PoolVector2Array *p = (PoolVector2Array *)&pba; - *p = *v; - return pba; -} - -godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_pool_vector3_array pba; - godot_pool_vector3_array_new(&pba); - PoolVector3Array *p = (PoolVector3Array *)&pba; - *p = *v; - return pba; -} - -godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_v) { - const Variant *v = (const Variant *)p_v; - godot_pool_color_array pba; - godot_pool_color_array_new(&pba); - PoolColorArray *p = (PoolColorArray *)&pba; - *p = *v; - return pba; -} - -godot_variant GDAPI godot_variant_call(godot_variant *p_v, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount /*, godot_variant_call_error *r_error */) { - Variant *v = (Variant *)p_v; - String *method = (String *)p_method; - Variant **args = (Variant **)p_args; - godot_variant res; - memnew_placement_custom((Variant *)&res, Variant, Variant(v->call(*method, args, p_argcount))); - return res; +godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_self) { + godot_node_path raw_dest; + const Variant *self = (const Variant *)p_self; + NodePath *dest = (NodePath *)&raw_dest; + memnew_placement(dest, NodePath(self->operator NodePath())); // operator = is overloaded by NodePath + return raw_dest; +} + +godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_self) { + godot_rid raw_dest; + const Variant *self = (const Variant *)p_self; + RID *dest = (RID *)&raw_dest; + *dest = *self; + return raw_dest; +} + +godot_object GDAPI *godot_variant_as_object(const godot_variant *p_self) { + const Variant *self = (const Variant *)p_self; + Object *dest; + dest = *self; + return (godot_object *)dest; +} + +godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_self) { + godot_dictionary raw_dest; + const Variant *self = (const Variant *)p_self; + Dictionary *dest = (Dictionary *)&raw_dest; + memnew_placement(dest, Dictionary(self->operator Dictionary())); // operator = is overloaded by Dictionary + return raw_dest; +} + +godot_array GDAPI godot_variant_as_array(const godot_variant *p_self) { + godot_array raw_dest; + const Variant *self = (const Variant *)p_self; + Array *dest = (Array *)&raw_dest; + memnew_placement(dest, Array(self->operator Array())); // operator = is overloaded by Array + return raw_dest; +} + +godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_self) { + godot_pool_byte_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolByteArray *dest = (PoolByteArray *)&raw_dest; + memnew_placement(dest, PoolByteArray(self->operator PoolByteArray())); // operator = is overloaded by PoolByteArray + *dest = *self; + return raw_dest; +} + +godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_self) { + godot_pool_int_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolIntArray *dest = (PoolIntArray *)&raw_dest; + memnew_placement(dest, PoolIntArray(self->operator PoolIntArray())); // operator = is overloaded by PoolIntArray + *dest = *self; + return raw_dest; +} + +godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_self) { + godot_pool_real_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolRealArray *dest = (PoolRealArray *)&raw_dest; + memnew_placement(dest, PoolRealArray(self->operator PoolRealArray())); // operator = is overloaded by PoolRealArray + *dest = *self; + return raw_dest; +} + +godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_self) { + godot_pool_string_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolStringArray *dest = (PoolStringArray *)&raw_dest; + memnew_placement(dest, PoolStringArray(self->operator PoolStringArray())); // operator = is overloaded by PoolStringArray + *dest = *self; + return raw_dest; } -godot_bool GDAPI godot_variant_has_method(godot_variant *p_v, const godot_string *p_method) { - Variant *v = (Variant *)p_v; +godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_self) { + godot_pool_vector2_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolVector2Array *dest = (PoolVector2Array *)&raw_dest; + memnew_placement(dest, PoolVector2Array(self->operator PoolVector2Array())); // operator = is overloaded by PoolVector2Array + *dest = *self; + return raw_dest; +} + +godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_self) { + godot_pool_vector3_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolVector3Array *dest = (PoolVector3Array *)&raw_dest; + memnew_placement(dest, PoolVector3Array(self->operator PoolVector3Array())); // operator = is overloaded by PoolVector3Array + *dest = *self; + return raw_dest; +} + +godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_self) { + godot_pool_color_array raw_dest; + const Variant *self = (const Variant *)p_self; + PoolColorArray *dest = (PoolColorArray *)&raw_dest; + memnew_placement(dest, PoolColorArray(self->operator PoolColorArray())); // operator = is overloaded by PoolColorArray + *dest = *self; + return raw_dest; +} + +godot_variant GDAPI godot_variant_call(godot_variant *p_self, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant_call_error *r_error) { + Variant *self = (Variant *)p_self; String *method = (String *)p_method; - return v->has_method(*method); + const Variant **args = (const Variant **)p_args; + godot_variant raw_dest; + Variant *dest = (Variant *)&raw_dest; + Variant::CallError error; + memnew_placement_custom(dest, Variant, Variant(self->call(*method, args, p_argcount, error))); + *dest = self->call(StringName(*method), args, p_argcount, r_error); + if (r_error) { + r_error->error = (godot_variant_call_error_error)error.error; + r_error->argument = error.argument; + r_error->expected = (godot_variant_type)error.expected; + } + return raw_dest; +} + +godot_bool GDAPI godot_variant_has_method(const godot_variant *p_self, const godot_string *p_method) { + const Variant *self = (const Variant *)p_self; + const String *method = (const String *)p_method; + return self->has_method(*method); } -godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_a, const godot_variant *p_b) { - const Variant *a = (const Variant *)p_a; - const Variant *b = (const Variant *)p_b; - return a->operator==(*b); +godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_self, const godot_variant *p_other) { + const Variant *self = (const Variant *)p_self; + const Variant *other = (const Variant *)p_other; + return self->operator==(*other); } -godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_a, const godot_variant *p_b) { - const Variant *a = (const Variant *)p_a; - const Variant *b = (const Variant *)p_b; - return a->operator<(*b); +godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_self, const godot_variant *p_other) { + const Variant *self = (const Variant *)p_self; + const Variant *other = (const Variant *)p_other; + return self->operator<(*other); } -godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_a, const godot_variant *p_b) { - const Variant *a = (const Variant *)p_a; - const Variant *b = (const Variant *)p_b; - return a->hash_compare(*b); +godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_self, const godot_variant *p_other) { + const Variant *self = (const Variant *)p_self; + const Variant *other = (const Variant *)p_other; + return self->hash_compare(*other); } -godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_v, godot_bool *p_valid) { - const Variant *v = (const Variant *)p_v; - bool &valid = *p_valid; - return v->booleanize(valid); +godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_self, godot_bool *r_valid) { + const Variant *self = (const Variant *)p_self; + bool &valid = *r_valid; + return self->booleanize(valid); } -void GDAPI godot_variant_destroy(godot_variant *p_v) { - ((Variant *)p_v)->~Variant(); +void GDAPI godot_variant_destroy(godot_variant *p_self) { + Variant *self = (Variant *)p_self; + self->~Variant(); } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_variant.h b/modules/gdnative/godot/godot_variant.h index 6f98b32363..9b6d287249 100644 --- a/modules/gdnative/godot/godot_variant.h +++ b/modules/gdnative/godot/godot_variant.h @@ -42,16 +42,6 @@ typedef struct godot_variant { } godot_variant; #endif -struct godot_transform2d; -typedef struct godot_transform2d godot_transform2d; - -#include "godot_array.h" -#include "godot_dictionary.h" -#include "godot_input_event.h" -#include "godot_node_path.h" -#include "godot_rid.h" -#include "godot_transform2d.h" - typedef enum godot_variant_type { GODOT_VARIANT_TYPE_NIL, @@ -69,108 +59,137 @@ typedef enum godot_variant_type { GODOT_VARIANT_TYPE_TRANSFORM2D, GODOT_VARIANT_TYPE_PLANE, GODOT_VARIANT_TYPE_QUAT, // 10 - GODOT_VARIANT_TYPE_RECT3, //sorry naming convention fail :( not like it's used often + GODOT_VARIANT_TYPE_RECT3, GODOT_VARIANT_TYPE_BASIS, GODOT_VARIANT_TYPE_TRANSFORM, // misc types GODOT_VARIANT_TYPE_COLOR, - GODOT_VARIANT_TYPE_IMAGE, // 15 - GODOT_VARIANT_TYPE_NODE_PATH, + GODOT_VARIANT_TYPE_NODE_PATH, // 15 GODOT_VARIANT_TYPE_RID, GODOT_VARIANT_TYPE_OBJECT, - GODOT_VARIANT_TYPE_INPUT_EVENT, - GODOT_VARIANT_TYPE_DICTIONARY, // 20 - GODOT_VARIANT_TYPE_ARRAY, + GODOT_VARIANT_TYPE_DICTIONARY, + GODOT_VARIANT_TYPE_ARRAY, // 20 // arrays GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY, GODOT_VARIANT_TYPE_POOL_INT_ARRAY, GODOT_VARIANT_TYPE_POOL_REAL_ARRAY, - GODOT_VARIANT_TYPE_POOL_STRING_ARRAY, // 25 - GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY, + GODOT_VARIANT_TYPE_POOL_STRING_ARRAY, + GODOT_VARIANT_TYPE_POOL_VECTOR2_ARRAY, // 25 GODOT_VARIANT_TYPE_POOL_VECTOR3_ARRAY, GODOT_VARIANT_TYPE_POOL_COLOR_ARRAY, } godot_variant_type; +typedef enum godot_variant_call_error_error { + GODOT_CALL_ERROR_CALL_OK, + GODOT_CALL_ERROR_CALL_ERROR_INVALID_METHOD, + GODOT_CALL_ERROR_CALL_ERROR_INVALID_ARGUMENT, + GODOT_CALL_ERROR_CALL_ERROR_TOO_MANY_ARGUMENTS, + GODOT_CALL_ERROR_CALL_ERROR_TOO_FEW_ARGUMENTS, + GODOT_CALL_ERROR_CALL_ERROR_INSTANCE_IS_NULL, +} godot_variant_call_error_error; + +typedef struct godot_variant_call_error { + godot_variant_call_error_error error; + int argument; + godot_variant_type expected; +} godot_variant_call_error; + +#include "godot_array.h" +#include "godot_basis.h" +#include "godot_color.h" +#include "godot_dictionary.h" +#include "godot_node_path.h" +#include "godot_plane.h" +#include "godot_pool_arrays.h" +#include "godot_quat.h" +#include "godot_rect2.h" +#include "godot_rect3.h" +#include "godot_rid.h" +#include "godot_string.h" +#include "godot_transform.h" +#include "godot_transform2d.h" +#include "godot_variant.h" +#include "godot_vector2.h" +#include "godot_vector3.h" + +#include "../godot.h" + godot_variant_type GDAPI godot_variant_get_type(const godot_variant *p_v); -void GDAPI godot_variant_copy(godot_variant *p_dest, const godot_variant *p_src); +void GDAPI godot_variant_new_copy(godot_variant *r_dest, const godot_variant *p_src); -void GDAPI godot_variant_new_nil(godot_variant *p_v); +void GDAPI godot_variant_new_nil(godot_variant *r_dest); void GDAPI godot_variant_new_bool(godot_variant *p_v, const godot_bool p_b); -void GDAPI godot_variant_new_uint(godot_variant *p_v, const uint64_t p_i); -void GDAPI godot_variant_new_int(godot_variant *p_v, const int64_t p_i); -void GDAPI godot_variant_new_real(godot_variant *p_v, const double p_r); -void GDAPI godot_variant_new_string(godot_variant *p_v, const godot_string *p_s); -void GDAPI godot_variant_new_vector2(godot_variant *p_v, const godot_vector2 *p_v2); -void GDAPI godot_variant_new_rect2(godot_variant *p_v, const godot_rect2 *p_rect2); -void GDAPI godot_variant_new_vector3(godot_variant *p_v, const godot_vector3 *p_v3); -void GDAPI godot_variant_new_transform2d(godot_variant *p_v, const godot_transform2d *p_t2d); -void GDAPI godot_variant_new_plane(godot_variant *p_v, const godot_plane *p_plane); -void GDAPI godot_variant_new_quat(godot_variant *p_v, const godot_quat *p_quat); -void GDAPI godot_variant_new_rect3(godot_variant *p_v, const godot_rect3 *p_rect3); -void GDAPI godot_variant_new_basis(godot_variant *p_v, const godot_basis *p_basis); -void GDAPI godot_variant_new_transform(godot_variant *p_v, const godot_transform *p_trans); -void GDAPI godot_variant_new_color(godot_variant *p_v, const godot_color *p_color); -void GDAPI godot_variant_new_image(godot_variant *p_v, const godot_image *p_img); -void GDAPI godot_variant_new_node_path(godot_variant *p_v, const godot_node_path *p_np); -void GDAPI godot_variant_new_rid(godot_variant *p_v, const godot_rid *p_rid); -void GDAPI godot_variant_new_object(godot_variant *p_v, const godot_object *p_obj); -void GDAPI godot_variant_new_input_event(godot_variant *p_v, const godot_input_event *p_event); -void GDAPI godot_variant_new_dictionary(godot_variant *p_v, const godot_dictionary *p_dict); -void GDAPI godot_variant_new_array(godot_variant *p_v, const godot_array *p_arr); -void GDAPI godot_variant_new_pool_byte_array(godot_variant *p_v, const godot_pool_byte_array *p_pba); -void GDAPI godot_variant_new_pool_int_array(godot_variant *p_v, const godot_pool_int_array *p_pia); -void GDAPI godot_variant_new_pool_real_array(godot_variant *p_v, const godot_pool_real_array *p_pra); -void GDAPI godot_variant_new_pool_string_array(godot_variant *p_v, const godot_pool_string_array *p_psa); -void GDAPI godot_variant_new_pool_vector2_array(godot_variant *p_v, const godot_pool_vector2_array *p_pv2a); -void GDAPI godot_variant_new_pool_vector3_array(godot_variant *p_v, const godot_pool_vector3_array *p_pv3a); -void GDAPI godot_variant_new_pool_color_array(godot_variant *p_v, const godot_pool_color_array *p_pca); - -godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_v); -uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_v); -int64_t GDAPI godot_variant_as_int(const godot_variant *p_v); -double GDAPI godot_variant_as_real(const godot_variant *p_v); -godot_string GDAPI godot_variant_as_string(const godot_variant *p_v); -godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_v); -godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_v); -godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_v); -godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_v); -godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_v); -godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_v); -godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_v); -godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_v); -godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_v); -godot_color GDAPI godot_variant_as_color(const godot_variant *p_v); -godot_image GDAPI godot_variant_as_image(const godot_variant *p_v); -godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_v); -godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_v); -godot_object GDAPI *godot_variant_as_object(const godot_variant *p_v); -godot_input_event GDAPI godot_variant_as_input_event(const godot_variant *p_v); -godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_v); -godot_array GDAPI godot_variant_as_array(const godot_variant *p_v); -godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_v); -godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_v); -godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_v); -godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_v); -godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_v); -godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_v); -godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_v); - -godot_variant GDAPI godot_variant_call(godot_variant *p_v, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount /*, godot_variant_call_error *r_error */); - -godot_bool GDAPI godot_variant_has_method(godot_variant *p_v, const godot_string *p_method); - -godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_a, const godot_variant *p_b); -godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_a, const godot_variant *p_b); - -godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_a, const godot_variant *p_b); - -godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_v, godot_bool *p_valid); - -void GDAPI godot_variant_destroy(godot_variant *p_v); +void GDAPI godot_variant_new_uint(godot_variant *r_dest, const uint64_t p_i); +void GDAPI godot_variant_new_int(godot_variant *r_dest, const int64_t p_i); +void GDAPI godot_variant_new_real(godot_variant *r_dest, const double p_r); +void GDAPI godot_variant_new_string(godot_variant *r_dest, const godot_string *p_s); +void GDAPI godot_variant_new_vector2(godot_variant *r_dest, const godot_vector2 *p_v2); +void GDAPI godot_variant_new_rect2(godot_variant *r_dest, const godot_rect2 *p_rect2); +void GDAPI godot_variant_new_vector3(godot_variant *r_dest, const godot_vector3 *p_v3); +void GDAPI godot_variant_new_transform2d(godot_variant *r_dest, const godot_transform2d *p_t2d); +void GDAPI godot_variant_new_plane(godot_variant *r_dest, const godot_plane *p_plane); +void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_quat); +void GDAPI godot_variant_new_rect3(godot_variant *r_dest, const godot_rect3 *p_rect3); +void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis); +void GDAPI godot_variant_new_transform(godot_variant *r_dest, const godot_transform *p_trans); +void GDAPI godot_variant_new_color(godot_variant *r_dest, const godot_color *p_color); +void GDAPI godot_variant_new_node_path(godot_variant *r_dest, const godot_node_path *p_np); +void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid); +void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj); +void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict); +void GDAPI godot_variant_new_array(godot_variant *r_dest, const godot_array *p_arr); +void GDAPI godot_variant_new_pool_byte_array(godot_variant *r_dest, const godot_pool_byte_array *p_pba); +void GDAPI godot_variant_new_pool_int_array(godot_variant *r_dest, const godot_pool_int_array *p_pia); +void GDAPI godot_variant_new_pool_real_array(godot_variant *r_dest, const godot_pool_real_array *p_pra); +void GDAPI godot_variant_new_pool_string_array(godot_variant *r_dest, const godot_pool_string_array *p_psa); +void GDAPI godot_variant_new_pool_vector2_array(godot_variant *r_dest, const godot_pool_vector2_array *p_pv2a); +void GDAPI godot_variant_new_pool_vector3_array(godot_variant *r_dest, const godot_pool_vector3_array *p_pv3a); +void GDAPI godot_variant_new_pool_color_array(godot_variant *r_dest, const godot_pool_color_array *p_pca); + +godot_bool GDAPI godot_variant_as_bool(const godot_variant *p_self); +uint64_t GDAPI godot_variant_as_uint(const godot_variant *p_self); +int64_t GDAPI godot_variant_as_int(const godot_variant *p_self); +double GDAPI godot_variant_as_real(const godot_variant *p_self); +godot_string GDAPI godot_variant_as_string(const godot_variant *p_self); +godot_vector2 GDAPI godot_variant_as_vector2(const godot_variant *p_self); +godot_rect2 GDAPI godot_variant_as_rect2(const godot_variant *p_self); +godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self); +godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_self); +godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_self); +godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_self); +godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_self); +godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_self); +godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_self); +godot_color GDAPI godot_variant_as_color(const godot_variant *p_self); +godot_node_path GDAPI godot_variant_as_node_path(const godot_variant *p_self); +godot_rid GDAPI godot_variant_as_rid(const godot_variant *p_self); +godot_object GDAPI *godot_variant_as_object(const godot_variant *p_self); +godot_dictionary GDAPI godot_variant_as_dictionary(const godot_variant *p_self); +godot_array GDAPI godot_variant_as_array(const godot_variant *p_self); +godot_pool_byte_array GDAPI godot_variant_as_pool_byte_array(const godot_variant *p_self); +godot_pool_int_array GDAPI godot_variant_as_pool_int_array(const godot_variant *p_self); +godot_pool_real_array GDAPI godot_variant_as_pool_real_array(const godot_variant *p_self); +godot_pool_string_array GDAPI godot_variant_as_pool_string_array(const godot_variant *p_self); +godot_pool_vector2_array GDAPI godot_variant_as_pool_vector2_array(const godot_variant *p_self); +godot_pool_vector3_array GDAPI godot_variant_as_pool_vector3_array(const godot_variant *p_self); +godot_pool_color_array GDAPI godot_variant_as_pool_color_array(const godot_variant *p_self); + +godot_variant GDAPI godot_variant_call(godot_variant *p_self, const godot_string *p_method, const godot_variant **p_args, const godot_int p_argcount, godot_variant_call_error *r_error); + +godot_bool GDAPI godot_variant_has_method(const godot_variant *p_self, const godot_string *p_method); + +godot_bool GDAPI godot_variant_operator_equal(const godot_variant *p_self, const godot_variant *p_other); +godot_bool GDAPI godot_variant_operator_less(const godot_variant *p_self, const godot_variant *p_other); + +godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_self, const godot_variant *p_other); + +godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_self, godot_bool *r_valid); + +void GDAPI godot_variant_destroy(godot_variant *p_self); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_vector2.cpp b/modules/gdnative/godot/godot_vector2.cpp index dce4c03b5d..0ced800872 100644 --- a/modules/gdnative/godot/godot_vector2.cpp +++ b/modules/gdnative/godot/godot_vector2.cpp @@ -28,124 +28,268 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_vector2.h" +#include "core/variant.h" -#include "math/math_2d.h" +#include "core/math/math_2d.h" #ifdef __cplusplus extern "C" { #endif -void _vector2_api_anchor() { +void _vector2_api_anchor() {} + +void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y) { + + Vector2 *dest = (Vector2 *)r_dest; + *dest = Vector2(p_x, p_y); +} + +godot_string GDAPI godot_vector2_as_string(const godot_vector2 *p_self) { + godot_string ret; + const Vector2 *self = (const Vector2 *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_self) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + *((Vector2 *)&dest) = self->normalized(); + return dest; +} + +godot_real GDAPI godot_vector2_length(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->length(); +} + +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->angle(); } -void GDAPI godot_vector2_new(godot_vector2 *p_v, godot_real p_x, godot_real p_y) { - Vector2 *v = (Vector2 *)p_v; - v->x = p_x; - v->y = p_y; +godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->length_squared(); } -void GDAPI godot_vector2_set_x(godot_vector2 *p_v, const godot_real p_x) { - Vector2 *v = (Vector2 *)p_v; - v->x = p_x; +godot_bool GDAPI godot_vector2_is_normalized(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->is_normalized(); } -void GDAPI godot_vector2_set_y(godot_vector2 *p_v, const godot_real p_y) { - Vector2 *v = (Vector2 *)p_v; - v->y = p_y; +godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_self, const godot_vector2 *p_to) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + return self->distance_to(*to); } -godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_v) { - Vector2 *v = (Vector2 *)p_v; - return v->x; +godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_self, const godot_vector2 *p_to) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + return self->distance_squared_to(*to); } -godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_v) { - Vector2 *v = (Vector2 *)p_v; - return v->y; + +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_self, const godot_vector2 *p_to) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + return self->angle_to(*to); +} + +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_self, const godot_vector2 *p_to) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *to = (const Vector2 *)p_to; + return self->angle_to_point(*to); +} + +godot_vector2 GDAPI godot_vector2_linear_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_real p_t) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *((Vector2 *)&dest) = self->linear_interpolate(*b, p_t); + return dest; +} + +godot_vector2 GDAPI godot_vector2_cubic_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_vector2 *p_pre_a, const godot_vector2 *p_post_b, const godot_real p_t) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + const Vector2 *pre_a = (const Vector2 *)p_pre_a; + const Vector2 *post_b = (const Vector2 *)p_post_b; + *((Vector2 *)&dest) = self->cubic_interpolate(*b, *pre_a, *post_b, p_t); + return dest; +} + +godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_self, const godot_real p_phi) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + + *((Vector2 *)&dest) = self->rotated(p_phi); + return dest; } -void GDAPI godot_vector2_normalize(godot_vector2 *p_v) { - Vector2 *v = (Vector2 *)p_v; - v->normalize(); +godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_self) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + *((Vector2 *)&dest) = self->tangent(); + return dest; +} + +godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_self) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + *((Vector2 *)&dest) = self->floor(); + return dest; +} + +godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_self, const godot_vector2 *p_by) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *by = (const Vector2 *)p_by; + *((Vector2 *)&dest) = self->snapped(*by); + return dest; +} + +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->aspect(); +} + +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_self, const godot_vector2 *p_with) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *with = (const Vector2 *)p_with; + return self->dot(*with); +} + +godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_self, const godot_vector2 *p_n) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *n = (const Vector2 *)p_n; + *((Vector2 *)&dest) = self->slide(*n); + return dest; +} + +godot_vector2 GDAPI godot_vector2_bounce(const godot_vector2 *p_self, const godot_vector2 *p_n) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *n = (const Vector2 *)p_n; + *((Vector2 *)&dest) = self->bounce(*n); + return dest; +} + +godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_self, const godot_vector2 *p_n) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *n = (const Vector2 *)p_n; + *((Vector2 *)&dest) = self->reflect(*n); + return dest; +} + +godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_self) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + *((Vector2 *)&dest) = self->abs(); + return dest; +} + +godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_self, const godot_real p_length) { + godot_vector2 dest; + const Vector2 *self = (const Vector2 *)p_self; + + *((Vector2 *)&dest) = self->clamped(p_length); + return dest; } -void GDAPI godot_vector2_normalized(godot_vector2 *p_dest, const godot_vector2 *p_src) { - Vector2 *v = (Vector2 *)p_src; - Vector2 *d = (Vector2 *)p_dest; - *d = v->normalized(); +godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_self, const godot_vector2 *p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *dest = *self + *b; + return raw_dest; } -godot_real GDAPI godot_vector2_length(const godot_vector2 *p_v) { - Vector2 *v = (Vector2 *)p_v; - return v->length(); +godot_vector2 GDAPI godot_vector2_operator_substract(const godot_vector2 *p_self, const godot_vector2 *p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *dest = *self - *b; + return raw_dest; } -godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_v) { - Vector2 *v = (Vector2 *)p_v; - return v->length_squared(); +godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_self, const godot_vector2 *p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *dest = *self * *b; + return raw_dest; } -godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *a = (Vector2 *)p_a; - Vector2 *b = (Vector2 *)p_b; - return a->distance_to(*b); +godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_self, const godot_real p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + *dest = *self * p_b; + return raw_dest; } -godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *a = (Vector2 *)p_a; - Vector2 *b = (Vector2 *)p_b; - return a->distance_squared_to(*b); +godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_self, const godot_vector2 *p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + *dest = *self / *b; + return raw_dest; } -void GDAPI godot_vector2_operator_add(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - *dest = *a + *b; +godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_self, const godot_real p_b) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + *dest = *self / p_b; + return raw_dest; } -void GDAPI godot_vector2_operator_subtract(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - *dest = *a - *b; +godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_self, const godot_vector2 *p_b) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + return *self == *b; } -void GDAPI godot_vector2_operator_multiply_vector(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - *dest = *a * *b; +godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_self, const godot_vector2 *p_b) { + const Vector2 *self = (const Vector2 *)p_self; + const Vector2 *b = (const Vector2 *)p_b; + return *self < *b; } -void GDAPI godot_vector2_operator_multiply_scalar(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_real p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - *dest = *a * p_b; +godot_vector2 GDAPI godot_vector2_operator_neg(const godot_vector2 *p_self) { + godot_vector2 raw_dest; + Vector2 *dest = (Vector2 *)&raw_dest; + const Vector2 *self = (const Vector2 *)p_self; + *dest = -(*self); + return raw_dest; } -void GDAPI godot_vector2_operator_divide_vector(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - *dest = *a / *b; +void GDAPI godot_vector2_set_x(godot_vector2 *p_self, const godot_real p_x) { + Vector2 *self = (Vector2 *)p_self; + self->x = p_x; } -void GDAPI godot_vector2_operator_divide_scalar(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_real p_b) { - Vector2 *dest = (Vector2 *)p_dest; - const Vector2 *a = (Vector2 *)p_a; - *dest = *a / p_b; +void GDAPI godot_vector2_set_y(godot_vector2 *p_self, const godot_real p_y) { + Vector2 *self = (Vector2 *)p_self; + self->y = p_y; } -godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_a, const godot_vector2 *p_b) { - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - return *a == *b; +godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->x; } -godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_a, const godot_vector2 *p_b) { - const Vector2 *a = (Vector2 *)p_a; - const Vector2 *b = (Vector2 *)p_b; - return *a < *b; +godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_self) { + const Vector2 *self = (const Vector2 *)p_self; + return self->y; } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_vector2.h b/modules/gdnative/godot/godot_vector2.h index afda8aa10b..9c7590fedf 100644 --- a/modules/gdnative/godot/godot_vector2.h +++ b/modules/gdnative/godot/godot_vector2.h @@ -45,60 +45,79 @@ typedef struct godot_vector2 { #include "../godot.h" -void GDAPI godot_vector2_new(godot_vector2 *p_v, const godot_real p_x, const godot_real p_y); - -void GDAPI godot_vector2_set_x(godot_vector2 *p_v, const godot_real p_x); -void GDAPI godot_vector2_set_y(godot_vector2 *p_v, const godot_real p_y); -godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_v); -godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_v); - -void GDAPI godot_vector2_normalize(godot_vector2 *p_v); -void GDAPI godot_vector2_normalized(godot_vector2 *p_dest, const godot_vector2 *p_src); - -godot_real GDAPI godot_vector2_length(const godot_vector2 *p_v); -godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_v); - -godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_a, const godot_vector2 *p_b); -godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_a, const godot_vector2 *p_b); - -// @Incomplete -/* - * missing: - * - * angle_to - * angle_to_point - * dot - * cross_vector - * cross_scalar - * project - * plane_project - * clamped - * linear_interpolate - * cubic_interpolate - * cubic_interpolate_soft - * slide - * reflect - * angle - * abs - * rotated - * tangent - * floor - * snapped - * aspect - * - * - * to_string - */ - -void GDAPI godot_vector2_operator_add(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); -void GDAPI godot_vector2_operator_subtract(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); -void GDAPI godot_vector2_operator_multiply_vector(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); -void GDAPI godot_vector2_operator_multiply_scalar(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_real p_b); -void GDAPI godot_vector2_operator_divide_vector(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_vector2 *p_b); -void GDAPI godot_vector2_operator_divide_scalar(godot_vector2 *p_dest, const godot_vector2 *p_a, const godot_real p_b); - -godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_a, const godot_vector2 *p_b); -godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_a, const godot_vector2 *p_b); +void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y); + +godot_string GDAPI godot_vector2_as_string(const godot_vector2 *p_self); + +godot_vector2 GDAPI godot_vector2_normalized(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_length(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_angle(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_length_squared(const godot_vector2 *p_self); + +godot_bool GDAPI godot_vector2_is_normalized(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_distance_to(const godot_vector2 *p_self, const godot_vector2 *p_to); + +godot_real GDAPI godot_vector2_distance_squared_to(const godot_vector2 *p_self, const godot_vector2 *p_to); + +godot_real GDAPI godot_vector2_angle_to(const godot_vector2 *p_self, const godot_vector2 *p_to); + +godot_real GDAPI godot_vector2_angle_to_point(const godot_vector2 *p_self, const godot_vector2 *p_to); + +godot_vector2 GDAPI godot_vector2_linear_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_real p_t); + +godot_vector2 GDAPI godot_vector2_cubic_interpolate(const godot_vector2 *p_self, const godot_vector2 *p_b, const godot_vector2 *p_pre_a, const godot_vector2 *p_post_b, const godot_real p_t); + +godot_vector2 GDAPI godot_vector2_rotated(const godot_vector2 *p_self, const godot_real p_phi); + +godot_vector2 GDAPI godot_vector2_tangent(const godot_vector2 *p_self); + +godot_vector2 GDAPI godot_vector2_floor(const godot_vector2 *p_self); + +godot_vector2 GDAPI godot_vector2_snapped(const godot_vector2 *p_self, const godot_vector2 *p_by); + +godot_real GDAPI godot_vector2_aspect(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_dot(const godot_vector2 *p_self, const godot_vector2 *p_with); + +godot_vector2 GDAPI godot_vector2_slide(const godot_vector2 *p_self, const godot_vector2 *p_n); + +godot_vector2 GDAPI godot_vector2_bounce(const godot_vector2 *p_self, const godot_vector2 *p_n); + +godot_vector2 GDAPI godot_vector2_reflect(const godot_vector2 *p_self, const godot_vector2 *p_n); + +godot_vector2 GDAPI godot_vector2_abs(const godot_vector2 *p_self); + +godot_vector2 GDAPI godot_vector2_clamped(const godot_vector2 *p_self, const godot_real p_length); + +godot_vector2 GDAPI godot_vector2_operator_add(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_substract(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_multiply_vector(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_multiply_scalar(const godot_vector2 *p_self, const godot_real p_b); + +godot_vector2 GDAPI godot_vector2_operator_divide_vector(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_divide_scalar(const godot_vector2 *p_self, const godot_real p_b); + +godot_bool GDAPI godot_vector2_operator_equal(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_bool GDAPI godot_vector2_operator_less(const godot_vector2 *p_self, const godot_vector2 *p_b); + +godot_vector2 GDAPI godot_vector2_operator_neg(const godot_vector2 *p_self); + +void GDAPI godot_vector2_set_x(godot_vector2 *p_self, const godot_real p_x); + +void GDAPI godot_vector2_set_y(godot_vector2 *p_self, const godot_real p_y); + +godot_real GDAPI godot_vector2_get_x(const godot_vector2 *p_self); + +godot_real GDAPI godot_vector2_get_y(const godot_vector2 *p_self); #ifdef __cplusplus } diff --git a/modules/gdnative/godot/godot_vector3.cpp b/modules/gdnative/godot/godot_vector3.cpp index f08bfbcf06..f9942af6e5 100644 --- a/modules/gdnative/godot/godot_vector3.cpp +++ b/modules/gdnative/godot/godot_vector3.cpp @@ -28,150 +28,274 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "godot_vector3.h" +#include "core/variant.h" -#include "math/vector3.h" +#include "core/vector.h" #ifdef __cplusplus extern "C" { #endif -void _vector3_api_anchor() { +void _vector3_api_anchor() {} + +void GDAPI godot_vector3_new(godot_vector3 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z) { + + Vector3 *dest = (Vector3 *)r_dest; + *dest = Vector3(p_x, p_y, p_z); +} + +godot_string GDAPI godot_vector3_as_string(const godot_vector3 *p_self) { + godot_string ret; + const Vector3 *self = (const Vector3 *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->min_axis(); +} + +godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->max_axis(); +} + +godot_real GDAPI godot_vector3_length(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->length(); } -void GDAPI godot_vector3_new(godot_vector3 *p_v, const godot_real p_x, const godot_real p_y, const godot_real p_z) { - Vector3 *v = (Vector3 *)p_v; - *v = Vector3(p_x, p_y, p_z); +godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->length_squared(); } -void GDAPI godot_vector3_set_axis(godot_vector3 *p_v, const godot_int p_axis, const godot_real p_val) { - Vector3 *v = (Vector3 *)p_v; - v->set_axis(p_axis, p_val); +godot_bool GDAPI godot_vector3_is_normalized(const godot_vector3 *p_self) { + const Vector3 *self = (const Vector3 *)p_self; + return self->is_normalized(); } -godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_v, const godot_int p_axis) { - Vector3 *v = (Vector3 *)p_v; - return v->get_axis(p_axis); +godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->normalized(); + return dest; } -godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_v) { - Vector3 *v = (Vector3 *)p_v; - return v->min_axis(); +godot_vector3 GDAPI godot_vector3_inverse(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->inverse(); + return dest; } -godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_v) { - Vector3 *v = (Vector3 *)p_v; - return v->max_axis(); +godot_vector3 GDAPI godot_vector3_snapped(const godot_vector3 *p_self, const godot_real p_by) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + + *((Vector3 *)&dest) = self->snapped(p_by); + return dest; } -godot_real GDAPI godot_vector3_length(const godot_vector3 *p_v) { - Vector3 *v = (Vector3 *)p_v; - return v->length(); +godot_vector3 GDAPI godot_vector3_rotated(const godot_vector3 *p_self, const godot_vector3 *p_axis, const godot_real p_phi) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *axis = (const Vector3 *)p_axis; + *((Vector3 *)&dest) = self->rotated(*axis, p_phi); + return dest; } -godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_v) { - Vector3 *v = (Vector3 *)p_v; - return v->length_squared(); +godot_vector3 GDAPI godot_vector3_linear_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_real p_t) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *((Vector3 *)&dest) = self->linear_interpolate(*b, p_t); + return dest; } -void GDAPI godot_vector3_normalize(godot_vector3 *p_v) { - Vector3 *v = (Vector3 *)p_v; - v->normalize(); +godot_vector3 GDAPI godot_vector3_cubic_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_vector3 *p_pre_a, const godot_vector3 *p_post_b, const godot_real p_t) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + const Vector3 *pre_a = (const Vector3 *)p_pre_a; + const Vector3 *post_b = (const Vector3 *)p_post_b; + *((Vector3 *)&dest) = self->cubic_interpolate(*b, *pre_a, *post_b, p_t); + return dest; } -void GDAPI godot_vector3_normalized(godot_vector3 *p_dest, const godot_vector3 *p_src) { - Vector3 *src = (Vector3 *)p_src; - Vector3 *dest = (Vector3 *)p_dest; - *dest = src->normalized(); +godot_real GDAPI godot_vector3_dot(const godot_vector3 *p_self, const godot_vector3 *p_b) { + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return self->dot(*b); } -/* - * inverse - * zero - * snap - * snapped - * rotate - * rotated - * - * - * linear_interpolate - * cubic_interpolate - * cubic_interpolaten - * cross - * dot - * outer - * to_diagonal_matrix - * abs - * floor - * ceil - */ +godot_vector3 GDAPI godot_vector3_cross(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *((Vector3 *)&dest) = self->cross(*b); + return dest; +} + +godot_basis GDAPI godot_vector3_outer(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_basis dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *((Basis *)&dest) = self->outer(*b); + return dest; +} + +godot_basis GDAPI godot_vector3_to_diagonal_matrix(const godot_vector3 *p_self) { + godot_basis dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Basis *)&dest) = self->to_diagonal_matrix(); + return dest; +} + +godot_vector3 GDAPI godot_vector3_abs(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->abs(); + return dest; +} -godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - return a->distance_to(*b); +godot_vector3 GDAPI godot_vector3_floor(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->floor(); + return dest; } -godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - return a->distance_squared_to(*b); +godot_vector3 GDAPI godot_vector3_ceil(const godot_vector3 *p_self) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + *((Vector3 *)&dest) = self->ceil(); + return dest; } -/* - * slide - * reflect - */ +godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_self, const godot_vector3 *p_b) { + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return self->distance_to(*b); +} + +godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_self, const godot_vector3 *p_b) { + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return self->distance_squared_to(*b); +} + +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_self, const godot_vector3 *p_to) { + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *to = (const Vector3 *)p_to; + return self->angle_to(*to); +} + +godot_vector3 GDAPI godot_vector3_slide(const godot_vector3 *p_self, const godot_vector3 *p_n) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *n = (const Vector3 *)p_n; + *((Vector3 *)&dest) = self->slide(*n); + return dest; +} + +godot_vector3 GDAPI godot_vector3_bounce(const godot_vector3 *p_self, const godot_vector3 *p_n) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *n = (const Vector3 *)p_n; + *((Vector3 *)&dest) = self->bounce(*n); + return dest; +} + +godot_vector3 GDAPI godot_vector3_reflect(const godot_vector3 *p_self, const godot_vector3 *p_n) { + godot_vector3 dest; + const Vector3 *self = (const Vector3 *)p_self; + const Vector3 *n = (const Vector3 *)p_n; + *((Vector3 *)&dest) = self->reflect(*n); + return dest; +} + +godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *dest = *self + *b; + return raw_dest; +} + +godot_vector3 GDAPI godot_vector3_operator_substract(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *dest = *self - *b; + return raw_dest; +} + +godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *dest = *self * *b; + return raw_dest; +} -void GDAPI godot_vector3_operator_add(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - *dest = *a + *b; +godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_self, const godot_real p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + *dest = *self * p_b; + return raw_dest; } -void GDAPI godot_vector3_operator_subtract(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - *dest = *a - *b; +godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_self, const godot_vector3 *p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + *dest = *self / *b; + return raw_dest; } -void GDAPI godot_vector3_operator_multiply_vector(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - *dest = *a * *b; +godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_self, const godot_real p_b) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + Vector3 *self = (Vector3 *)p_self; + *dest = *self / p_b; + return raw_dest; } -void GDAPI godot_vector3_operator_multiply_scalar(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_real p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - *dest = *a * p_b; +godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_self, const godot_vector3 *p_b) { + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return *self == *b; } -void GDAPI godot_vector3_operator_divide_vector(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - *dest = *a / *b; +godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_self, const godot_vector3 *p_b) { + Vector3 *self = (Vector3 *)p_self; + const Vector3 *b = (const Vector3 *)p_b; + return *self < *b; } -void GDAPI godot_vector3_operator_divide_scalar(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_real p_b) { - Vector3 *dest = (Vector3 *)p_dest; - Vector3 *a = (Vector3 *)p_a; - *dest = *a / p_b; +godot_vector3 GDAPI godot_vector3_operator_neg(const godot_vector3 *p_self) { + godot_vector3 raw_dest; + Vector3 *dest = (Vector3 *)&raw_dest; + const Vector3 *self = (const Vector3 *)p_self; + *dest = -(*self); + return raw_dest; } -godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - return *a == *b; +void GDAPI godot_vector3_set_axis(godot_vector3 *p_self, const godot_vector3_axis p_axis, const godot_real p_val) { + Vector3 *self = (Vector3 *)p_self; + self->set_axis(p_axis, p_val); } -godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_a, const godot_vector3 *p_b) { - Vector3 *a = (Vector3 *)p_a; - Vector3 *b = (Vector3 *)p_b; - return *a < *b; +godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_self, const godot_vector3_axis p_axis) { + const Vector3 *self = (const Vector3 *)p_self; + return self->get_axis(p_axis); } #ifdef __cplusplus diff --git a/modules/gdnative/godot/godot_vector3.h b/modules/gdnative/godot/godot_vector3.h index b7dc40965d..8e2aed8173 100644 --- a/modules/gdnative/godot/godot_vector3.h +++ b/modules/gdnative/godot/godot_vector3.h @@ -37,72 +37,94 @@ extern "C" { #include <stdint.h> #ifndef GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED typedef struct godot_vector3 { uint8_t _dont_touch_that[12]; } godot_vector3; #endif #include "../godot.h" +#include "godot_basis.h" -void GDAPI godot_vector3_new(godot_vector3 *p_v, const godot_real p_x, const godot_real p_y, const godot_real p_z); - -void GDAPI godot_vector3_set_axis(godot_vector3 *p_v, const godot_int p_axis, const godot_real p_val); -godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_v, const godot_int p_axis); - -godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_v); -godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_v); - -godot_real GDAPI godot_vector3_length(const godot_vector3 *p_v); -godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_v); - -void GDAPI godot_vector3_normalize(godot_vector3 *p_v); -void GDAPI godot_vector3_normalized(godot_vector3 *p_dest, const godot_vector3 *p_src); - -// @Incomplete - -/* - * inverse - * zero - * snap - * snapped - * rotate - * rotated - * - * - * linear_interpolate - * cubic_interpolate - * cubic_interpolaten - * cross - * dot - * outer - * to_diagonal_matrix - * abs - * floor - * ceil - */ - -godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_a, const godot_vector3 *p_b); -godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_a, const godot_vector3 *p_b); - -// @Incomplete -/* - * slide - * reflect - */ - -void GDAPI godot_vector3_operator_add(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); -void GDAPI godot_vector3_operator_subtract(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); -void GDAPI godot_vector3_operator_multiply_vector(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); -void GDAPI godot_vector3_operator_multiply_scalar(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_real p_b); -void GDAPI godot_vector3_operator_divide_vector(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_vector3 *p_b); -void GDAPI godot_vector3_operator_divide_scalar(godot_vector3 *p_dest, const godot_vector3 *p_a, const godot_real p_b); - -godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_a, const godot_vector3 *p_b); -godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_a, const godot_vector3 *p_b); - -/* - * to_string - */ +typedef enum { + GODOT_VECTOR3_AXIS_X, + GODOT_VECTOR3_AXIS_Y, + GODOT_VECTOR3_AXIS_Z, +} godot_vector3_axis; + +void GDAPI godot_vector3_new(godot_vector3 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z); + +godot_string GDAPI godot_vector3_as_string(const godot_vector3 *p_self); + +godot_int GDAPI godot_vector3_min_axis(const godot_vector3 *p_self); + +godot_int GDAPI godot_vector3_max_axis(const godot_vector3 *p_self); + +godot_real GDAPI godot_vector3_length(const godot_vector3 *p_self); + +godot_real GDAPI godot_vector3_length_squared(const godot_vector3 *p_self); + +godot_bool GDAPI godot_vector3_is_normalized(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_normalized(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_inverse(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_snapped(const godot_vector3 *p_self, const godot_real p_by); + +godot_vector3 GDAPI godot_vector3_rotated(const godot_vector3 *p_self, const godot_vector3 *p_axis, const godot_real p_phi); + +godot_vector3 GDAPI godot_vector3_linear_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_real p_t); + +godot_vector3 GDAPI godot_vector3_cubic_interpolate(const godot_vector3 *p_self, const godot_vector3 *p_b, const godot_vector3 *p_pre_a, const godot_vector3 *p_post_b, const godot_real p_t); + +godot_real GDAPI godot_vector3_dot(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_cross(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_basis GDAPI godot_vector3_outer(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_basis GDAPI godot_vector3_to_diagonal_matrix(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_abs(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_floor(const godot_vector3 *p_self); + +godot_vector3 GDAPI godot_vector3_ceil(const godot_vector3 *p_self); + +godot_real GDAPI godot_vector3_distance_to(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_real GDAPI godot_vector3_distance_squared_to(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_real GDAPI godot_vector3_angle_to(const godot_vector3 *p_self, const godot_vector3 *p_to); + +godot_vector3 GDAPI godot_vector3_slide(const godot_vector3 *p_self, const godot_vector3 *p_n); + +godot_vector3 GDAPI godot_vector3_bounce(const godot_vector3 *p_self, const godot_vector3 *p_n); + +godot_vector3 GDAPI godot_vector3_reflect(const godot_vector3 *p_self, const godot_vector3 *p_n); + +godot_vector3 GDAPI godot_vector3_operator_add(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_substract(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_multiply_vector(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_multiply_scalar(const godot_vector3 *p_self, const godot_real p_b); + +godot_vector3 GDAPI godot_vector3_operator_divide_vector(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_divide_scalar(const godot_vector3 *p_self, const godot_real p_b); + +godot_bool GDAPI godot_vector3_operator_equal(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_bool GDAPI godot_vector3_operator_less(const godot_vector3 *p_self, const godot_vector3 *p_b); + +godot_vector3 GDAPI godot_vector3_operator_neg(const godot_vector3 *p_self); + +void GDAPI godot_vector3_set_axis(godot_vector3 *p_self, const godot_vector3_axis p_axis, const godot_real p_val); + +godot_real GDAPI godot_vector3_get_axis(const godot_vector3 *p_self, const godot_vector3_axis p_axis); #ifdef __cplusplus } diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 12b43d6060..d4ede4cb17 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1014,7 +1014,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr } } break; - case GDParser::OperatorNode::OP_EXTENDS: { + case GDParser::OperatorNode::OP_IS: { ERR_FAIL_COND_V(on->arguments.size() != 2, false); diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index ae5bb5694c..5e3ce31dd6 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -27,10 +27,15 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "editor/editor_settings.h" #include "gd_compiler.h" #include "gd_script.h" #include "global_config.h" #include "os/file_access.h" +#ifdef TOOLS_ENABLED +#include "editor/editor_file_system.h" +#include "editor/editor_settings.h" +#endif void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { @@ -50,11 +55,12 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str "# var a = 2\n" + "# var b = \"textvar\"\n\n" + "func _ready():\n" + - "\t# Called every time the node is added to the scene.\n" + - "\t# Initialization here\n" + - "\tpass\n"; + "%TS%# Called every time the node is added to the scene.\n" + + "%TS%# Initialization here\n" + + "%TS%pass\n"; _template = _template.replace("%BASE%", p_base_class_name); + _template = _template.replace("%TS%", _get_indentation()); Ref<GDScript> script; script.instance(); @@ -63,6 +69,19 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str return script; } +bool GDScriptLanguage::is_using_templates() { + + return true; +} + +void GDScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) { + + String src = p_script->get_source_code(); + src = src.replace("%BASE%", p_base_class_name); + src = src.replace("%TS%", _get_indentation()); + p_script->set_source_code(src); +} + bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const { GDParser parser; @@ -1315,7 +1334,7 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o static const char *_type_names[Variant::VARIANT_MAX] = { "null", "bool", "int", "float", "String", "Vector2", "Rect2", "Vector3", "Transform2D", "Plane", "Quat", "AABB", "Basis", "Transform", - "Color", "Image", "NodePath", "RID", "Object", "InputEvent", "Dictionary", "Array", "RawArray", "IntArray", "FloatArray", "StringArray", + "Color", "NodePath", "RID", "Object", "Dictionary", "Array", "RawArray", "IntArray", "FloatArray", "StringArray", "Vector2Array", "Vector3Array", "ColorArray" }; @@ -1405,25 +1424,21 @@ static void _make_function_hint(const GDParser::FunctionNode *p_func, int p_argi arghint += ")"; } -static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) { - - //print_line("find type arguments?"); - if (id.type == Variant::INPUT_EVENT && String(p_method) == "is_action" && p_argidx == 0) { - - List<PropertyInfo> pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); +void get_directory_contents(EditorFileSystemDirectory *p_dir, Set<String> &r_list) { - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - const PropertyInfo &pi = E->get(); + for (int i = 0; i < p_dir->get_subdir_count(); i++) { + get_directory_contents(p_dir->get_subdir(i), r_list); + } - if (!pi.name.begins_with("input/")) - continue; + for (int i = 0; i < p_dir->get_file_count(); i++) { + r_list.insert("\"" + p_dir->get_file_path(i) + "\""); + } +} - String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); - result.insert("\"" + name + "\""); - } +static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) { - } else if (id.type == Variant::OBJECT && id.obj_type != StringName()) { + //print_line("find type arguments?"); + if (id.type == Variant::OBJECT && id.obj_type != StringName()) { MethodBind *m = ClassDB::get_method(id.obj_type, p_method); if (!m) { @@ -1753,6 +1768,10 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]); MethodInfo mi = GDFunctions::get_info(fn->function); + if (mi.name == "load" && bool(EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths"))) { + get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), result); + } + arghint = _get_visual_datatype(mi.return_val, false) + " " + GDFunctions::get_func_name(fn->function) + String("("); for (int i = 0; i < mi.arguments.size(); i++) { if (i > 0) @@ -2245,54 +2264,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } else { - if (t.type == Variant::INPUT_EVENT) { - - //this is hardcoded otherwise it's not obvious - Set<String> exclude; - - for (int i = 0; i < InputEvent::TYPE_MAX; i++) { - - InputEvent ie; - ie.type = InputEvent::Type(i); - static const char *evnames[] = { - "# Common", - "# Key", - "# MouseMotion", - "# MouseButton", - "# JoypadMotion", - "# JoypadButton", - "# ScreenTouch", - "# ScreenDrag", - "# Action" - }; - - r_options->push_back(evnames[i]); - - Variant v = ie; - - if (i == 0) { - List<MethodInfo> mi; - v.get_method_list(&mi); - for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) { - r_options->push_back(E->get().name + "("); - } - } - - List<PropertyInfo> pi; - v.get_property_list(&pi); - - for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - - if (i == 0) - exclude.insert(E->get().name); - else if (exclude.has(E->get().name)) - continue; - - r_options->push_back(E->get().name); - } - } - return OK; - } else { + //check InputEvent hint + { if (t.value.get_type() == Variant::NIL) { Variant::CallError ce; t.value = Variant::construct(t.type, NULL, 0, ce); @@ -2374,6 +2347,11 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } break; + case GDParser::COMPLETION_RESOURCE_PATH: { + + if (EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths")) + get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), options); + } break; } for (Set<String>::Element *E = options.front(); E; E = E->next()) { @@ -2391,8 +2369,29 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base #endif +String GDScriptLanguage::_get_indentation() const { +#ifdef TOOLS_ENABLED + if (SceneTree::get_singleton()->is_editor_hint()) { + bool use_space_indentation = EDITOR_DEF("text_editor/indent/type", 0); + + if (use_space_indentation) { + int indent_size = EDITOR_DEF("text_editor/indent/size", 4); + + String space_indent = ""; + for (int i = 0; i < indent_size; i++) { + space_indent += " "; + } + return space_indent; + } + } +#endif + return "\t"; +} + void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { + String indent = _get_indentation(); + Vector<String> lines = p_code.split("\n"); List<int> indent_stack; @@ -2432,8 +2431,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t if (i >= p_from_line) { l = ""; - for (int j = 0; j < indent_stack.size(); j++) - l += "\t"; + for (int j = 0; j < indent_stack.size(); j++) { + l += indent; + } l += st; } else if (i > p_to_line) { diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index 608256c88a..e8a8e20927 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -358,12 +358,12 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (a->get_type() != Variant::OBJECT || a->operator Object *() == NULL) { - err_text = "Left operand of 'extends' is not an instance of anything."; + err_text = "Left operand of 'is' is not an instance of anything."; break; } if (b->get_type() != Variant::OBJECT || b->operator Object *() == NULL) { - err_text = "Right operand of 'extends' is not a class."; + err_text = "Right operand of 'is' is not a class."; break; } #endif @@ -401,7 +401,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (!nc) { - err_text = "Right operand of 'extends' is not a class (type: '" + obj_B->get_class() + "')."; + err_text = "Right operand of 'is' is not a class (type: '" + obj_B->get_class() + "')."; break; } @@ -1433,9 +1433,21 @@ Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount return ret; } -bool GDFunctionState::is_valid() const { +bool GDFunctionState::is_valid(bool p_extended_check) const { - return function != NULL; + if (function == NULL) + return false; + + if (p_extended_check) { + //class instance gone? + if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) + return false; + //script gone? + if (state.script_id && !ObjectDB::get_instance(state.script_id)) + return false; + } + + return true; } Variant GDFunctionState::resume(const Variant &p_arg) { @@ -1464,7 +1476,7 @@ Variant GDFunctionState::resume(const Variant &p_arg) { void GDFunctionState::_bind_methods() { ClassDB::bind_method(D_METHOD("resume:Variant", "arg"), &GDFunctionState::resume, DEFVAL(Variant())); - ClassDB::bind_method(D_METHOD("is_valid"), &GDFunctionState::is_valid); + ClassDB::bind_method(D_METHOD("is_valid", "extended_check"), &GDFunctionState::is_valid, DEFVAL(false)); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &GDFunctionState::_signal_callback, MethodInfo("_signal_callback")); } diff --git a/modules/gdscript/gd_function.h b/modules/gdscript/gd_function.h index f0bf33147b..6d20b19777 100644 --- a/modules/gdscript/gd_function.h +++ b/modules/gdscript/gd_function.h @@ -237,7 +237,7 @@ protected: static void _bind_methods(); public: - bool is_valid() const; + bool is_valid(bool p_extended_check = false) const; Variant resume(const Variant &p_arg = Variant()); GDFunctionState(); ~GDFunctionState(); diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index cd16fef6b3..d64cd86de6 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -389,6 +389,19 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool } tokenizer->advance(); + if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { + completion_cursor = StringName(); + completion_node = p_parent; + completion_type = COMPLETION_RESOURCE_PATH; + completion_class = current_class; + completion_function = current_function; + completion_line = tokenizer->get_token_line(); + completion_block = current_block; + completion_argument = 0; + completion_found = true; + tokenizer->advance(); + } + String path; bool found_constant = false; bool valid = false; @@ -460,10 +473,10 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool _set_error("Expected ')' after 'preload' path"); return NULL; } + tokenizer->advance(); ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = res; - tokenizer->advance(); expr = constant; } else if (tokenizer->get_token() == GDTokenizer::TK_PR_YIELD) { @@ -1064,7 +1077,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool case GDTokenizer::TK_OP_BIT_AND: op = OperatorNode::OP_BIT_AND; break; case GDTokenizer::TK_OP_BIT_OR: op = OperatorNode::OP_BIT_OR; break; case GDTokenizer::TK_OP_BIT_XOR: op = OperatorNode::OP_BIT_XOR; break; - case GDTokenizer::TK_PR_EXTENDS: op = OperatorNode::OP_EXTENDS; break; + case GDTokenizer::TK_PR_IS: op = OperatorNode::OP_IS; break; case GDTokenizer::TK_CF_IF: op = OperatorNode::OP_TERNARY_IF; break; case GDTokenizer::TK_CF_ELSE: op = OperatorNode::OP_TERNARY_ELSE; break; default: valid = false; break; @@ -1104,7 +1117,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool switch (expression[i].op) { - case OperatorNode::OP_EXTENDS: + case OperatorNode::OP_IS: priority = -1; break; //before anything @@ -1407,7 +1420,7 @@ GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) { } } - if (op->op == OperatorNode::OP_EXTENDS) { + if (op->op == OperatorNode::OP_IS) { //nothing much return op; } diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index 445ad7361c..3ad3466624 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -216,7 +216,7 @@ public: OP_CALL, OP_PARENT_CALL, OP_YIELD, - OP_EXTENDS, + OP_IS, //indexing operator OP_INDEX, OP_INDEX_NAMED, @@ -437,6 +437,7 @@ public: COMPLETION_PARENT_FUNCTION, COMPLETION_METHOD, COMPLETION_CALL_ARGUMENTS, + COMPLETION_RESOURCE_PATH, COMPLETION_INDEX, COMPLETION_VIRTUAL_FUNC, COMPLETION_YIELD, diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 2367f60740..1dcc442234 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -615,6 +615,11 @@ Error GDScript::reload(bool p_keep_state) { if (basedir != "") basedir = basedir.get_base_dir(); + if (basedir.find("res://") == -1 && basedir.find("user://") == -1) { + //loading a template, don't parse + return OK; + } + valid = false; GDParser parser; Error err = parser.parse(source, basedir, false, path); @@ -1697,8 +1702,8 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so #ifdef TOOLS_ENABLED while (E->get()->placeholders.size()) { - Object *obj = E->get()->placeholders.front()->get()->get_owner(); + //save instance info List<Pair<StringName, Variant> > state; if (obj->get_script_instance()) { @@ -1706,6 +1711,9 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so obj->get_script_instance()->get_property_state(state); map[obj->get_instance_ID()] = state; obj->set_script(RefPtr()); + } else { + // no instance found. Let's remove it so we don't loop forever + E->get()->placeholders.erase(E->get()->placeholders.front()->get()); } } #endif @@ -1809,6 +1817,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { "breakpoint", "class", "extends", + "is", "func", "preload", "setget", diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 93f8ee8721..ebef4fed74 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -381,15 +381,19 @@ public: virtual void get_comment_delimiters(List<String> *p_delimiters) const; virtual void get_string_delimiters(List<String> *p_delimiters) const; virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const; + virtual bool is_using_templates(); + virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script); virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const; virtual Script *create_script() const; virtual bool has_named_classes() const; + virtual bool can_inherit_from_file() { return true; } virtual int find_function(const String &p_function, const String &p_code) const; virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const; virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, String &r_call_hint); #ifdef TOOLS_ENABLED virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result); #endif + virtual String _get_indentation() const; virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const; virtual void add_global_constant(const StringName &p_variable, const Variant &p_value); diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 13674f1f9a..f4e0cc8e29 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -90,6 +90,7 @@ const char *GDTokenizer::token_names[TK_MAX] = { "func", "class", "extends", + "is", "onready", "tool", "static", @@ -800,10 +801,8 @@ void GDTokenizerText::_advance() { { Variant::BASIS, "Basis" }, { Variant::TRANSFORM, "Transform" }, { Variant::COLOR, "Color" }, - { Variant::IMAGE, "Image" }, { Variant::_RID, "RID" }, { Variant::OBJECT, "Object" }, - { Variant::INPUT_EVENT, "InputEvent" }, { Variant::NODE_PATH, "NodePath" }, { Variant::DICTIONARY, "Dictionary" }, { Variant::ARRAY, "Array" }, @@ -866,6 +865,7 @@ void GDTokenizerText::_advance() { { TK_PR_FUNCTION, "func" }, { TK_PR_CLASS, "class" }, { TK_PR_EXTENDS, "extends" }, + { TK_PR_IS, "is" }, { TK_PR_ONREADY, "onready" }, { TK_PR_TOOL, "tool" }, { TK_PR_STATIC, "static" }, diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index ea7629b661..c051176097 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gd_tokenizer.h @@ -96,6 +96,7 @@ public: TK_PR_FUNCTION, TK_PR_CLASS, TK_PR_EXTENDS, + TK_PR_IS, TK_PR_ONREADY, TK_PR_TOOL, TK_PR_STATIC, diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index d1f54e021f..9d3da8227c 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -1057,12 +1057,12 @@ Error GridMap::create_area(int p_id, const Rect3 &p_bounds) { // FIRST VALIDATE AREA IndexKey from, to; - from.x = p_bounds.pos.x; - from.y = p_bounds.pos.y; - from.z = p_bounds.pos.z; - to.x = p_bounds.pos.x + p_bounds.size.x; - to.y = p_bounds.pos.y + p_bounds.size.y; - to.z = p_bounds.pos.z + p_bounds.size.z; + from.x = p_bounds.position.x; + from.y = p_bounds.position.y; + from.z = p_bounds.position.z; + to.x = p_bounds.position.x + p_bounds.size.x; + to.y = p_bounds.position.y + p_bounds.size.y; + to.z = p_bounds.position.z + p_bounds.size.z; for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { //this should somehow be faster... @@ -1101,8 +1101,8 @@ Rect3 GridMap::area_get_bounds(int p_area) const { const Area *a = area_map[p_area]; Rect3 aabb; - aabb.pos = Vector3(a->from.x, a->from.y, a->from.z); - aabb.size = Vector3(a->to.x, a->to.y, a->to.z) - aabb.pos; + aabb.position = Vector3(a->from.x, a->from.y, a->from.z); + aabb.size = Vector3(a->to.x, a->to.y, a->to.z) - aabb.position; return aabb; } diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 39fe0a1675..954e865bcd 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -508,146 +508,150 @@ void GridMapEditor::_duplicate_paste() { } } -bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { +bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) { if (!node) { return false; } if (edit_mode->get_selected() == 0) { // regular click - switch (p_event.type) { - case InputEvent::MOUSE_BUTTON: { - if (p_event.mouse_button.button_index == BUTTON_WHEEL_UP && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { - if (p_event.mouse_button.pressed) - floor->set_value(floor->get_value() + 1); + Ref<InputEventMouseButton> mb = p_event; - return true; //eaten - } else if (p_event.mouse_button.button_index == BUTTON_WHEEL_DOWN && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { - if (p_event.mouse_button.pressed) - floor->set_value(floor->get_value() - 1); - return true; - } + if (mb.is_valid()) { - if (p_event.mouse_button.pressed) { + if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) { + if (mb->is_pressed()) + floor->set_value(floor->get_value() + mb->get_factor()); - if (p_event.mouse_button.button_index == BUTTON_LEFT) { + return true; //eaten + } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) { + if (mb->is_pressed()) + floor->set_value(floor->get_value() - mb->get_factor()); + return true; + } - if (input_action == INPUT_DUPLICATE) { + if (mb->is_pressed()) { - //paste - _duplicate_paste(); - input_action = INPUT_NONE; - _update_duplicate_indicator(); - } else if (p_event.mouse_button.mod.shift) { - input_action = INPUT_SELECT; - } else if (p_event.mouse_button.mod.command) - input_action = INPUT_COPY; - else { - input_action = INPUT_PAINT; - set_items.clear(); - } - } else if (p_event.mouse_button.button_index == BUTTON_RIGHT) - if (input_action == INPUT_DUPLICATE) { - - input_action = INPUT_NONE; - _update_duplicate_indicator(); - } else { - input_action = INPUT_ERASE; - set_items.clear(); - } - else - return false; + if (mb->get_button_index() == BUTTON_LEFT) { - return do_input_action(p_camera, Point2(p_event.mouse_button.x, p_event.mouse_button.y), true); - } else { + if (input_action == INPUT_DUPLICATE) { - if ( - (p_event.mouse_button.button_index == BUTTON_RIGHT && input_action == INPUT_ERASE) || - (p_event.mouse_button.button_index == BUTTON_LEFT && input_action == INPUT_PAINT)) { + //paste + _duplicate_paste(); + input_action = INPUT_NONE; + _update_duplicate_indicator(); + } else if (mb->get_shift()) { + input_action = INPUT_SELECT; + } else if (mb->get_command()) + input_action = INPUT_COPY; + else { + input_action = INPUT_PAINT; + set_items.clear(); + } + } else if (mb->get_button_index() == BUTTON_RIGHT) + if (input_action == INPUT_DUPLICATE) { - if (set_items.size()) { - undo_redo->create_action("GridMap Paint"); - for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { + input_action = INPUT_NONE; + _update_duplicate_indicator(); + } else { + input_action = INPUT_ERASE; + set_items.clear(); + } + else + return false; + + return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); + } else { - const SetItem &si = E->get(); - undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); - } - for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { + if ( + (mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || + (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) { - const SetItem &si = E->get(); - undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); - } + if (set_items.size()) { + undo_redo->create_action("GridMap Paint"); + for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { - undo_redo->commit_action(); + const SetItem &si = E->get(); + undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); } - set_items.clear(); - input_action = INPUT_NONE; - return true; - } + for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { - if (p_event.mouse_button.button_index == BUTTON_LEFT && input_action != INPUT_NONE) { + const SetItem &si = E->get(); + undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); + } - set_items.clear(); - input_action = INPUT_NONE; - return true; - } - if (p_event.mouse_button.button_index == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) { - input_action = INPUT_NONE; - return true; + undo_redo->commit_action(); } + set_items.clear(); + input_action = INPUT_NONE; + return true; + } + + if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) { + + set_items.clear(); + input_action = INPUT_NONE; + return true; + } + if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) { + input_action = INPUT_NONE; + return true; } - } break; - case InputEvent::MOUSE_MOTION: { + } + } + + Ref<InputEventMouseMotion> mm = p_event; - return do_input_action(p_camera, Point2(p_event.mouse_motion.x, p_event.mouse_motion.y), false); - } break; + if (mm.is_valid()) { + + return do_input_action(p_camera, mm->get_position(), false); } } else if (edit_mode->get_selected() == 1) { //area mode, select an area - switch (p_event.type) { - case InputEvent::MOUSE_BUTTON: { + Ref<InputEventMouseButton> mb = p_event; - if (p_event.mouse_button.button_index == BUTTON_LEFT && p_event.mouse_button.pressed) { + if (mb.is_valid()) { - Point2 point = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y); + if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - Camera *camera = p_camera; - Vector3 from = camera->project_ray_origin(point); - Vector3 normal = camera->project_ray_normal(point); - Transform local_xform = node->get_global_transform().affine_inverse(); - from = local_xform.xform(from); - normal = local_xform.basis.xform(normal).normalized(); + Point2 point = mb->get_position(); - List<int> areas; - node->get_area_list(&areas); + Camera *camera = p_camera; + Vector3 from = camera->project_ray_origin(point); + Vector3 normal = camera->project_ray_normal(point); + Transform local_xform = node->get_global_transform().affine_inverse(); + from = local_xform.xform(from); + normal = local_xform.basis.xform(normal).normalized(); - float min_d = 1e10; - int min_area = -1; + List<int> areas; + node->get_area_list(&areas); - for (List<int>::Element *E = areas.front(); E; E = E->next()) { + float min_d = 1e10; + int min_area = -1; - int area = E->get(); - Rect3 aabb = node->area_get_bounds(area); - aabb.pos *= node->get_cell_size(); - aabb.size *= node->get_cell_size(); + for (List<int>::Element *E = areas.front(); E; E = E->next()) { - Vector3 rclip, rnormal; - if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal)) - continue; + int area = E->get(); + Rect3 aabb = node->area_get_bounds(area); + aabb.position *= node->get_cell_size(); + aabb.size *= node->get_cell_size(); - float d = normal.dot(rclip); - if (d < min_d) { - min_d = d; - min_area = area; - } - } + Vector3 rclip, rnormal; + if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal)) + continue; - selected_area = min_area; - update_areas(); + float d = normal.dot(rclip); + if (d < min_d) { + min_d = d; + min_area = area; + } } - } break; + + selected_area = min_area; + update_areas(); + } } } diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index d928e6afac..1572f4fbe5 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -220,7 +220,7 @@ protected: static void _bind_methods(); public: - bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event); + bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event); void edit(GridMap *p_gridmap); GridMapEditor() {} @@ -236,7 +236,7 @@ class GridMapEditorPlugin : public EditorPlugin { EditorNode *editor; public: - virtual bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); } + virtual bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); } virtual String get_name() const { return "GridMap"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); diff --git a/modules/hdr/SCsub b/modules/hdr/SCsub new file mode 100644 index 0000000000..c960e8126b --- /dev/null +++ b/modules/hdr/SCsub @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_hdr = env_modules.Clone() + +# Godot's own source files +env_hdr.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/hdr/config.py b/modules/hdr/config.py new file mode 100644 index 0000000000..fb920482f5 --- /dev/null +++ b/modules/hdr/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp new file mode 100644 index 0000000000..19df27b962 --- /dev/null +++ b/modules/hdr/image_loader_hdr.cpp @@ -0,0 +1,161 @@ +/*************************************************************************/ +/* image_loader_jpegd.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "image_loader_hdr.h" + +#include "os/os.h" +#include "print_string.h" + +#include "thirdparty/tinyexr/tinyexr.h" + +Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + String header = f->get_token(); + + print_line("HEADER: " + header); + ERR_FAIL_COND_V(header != "#?RADIANCE" && header != "#?RGBE", ERR_FILE_UNRECOGNIZED); + + while (true) { + String format = f->get_token(); + ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_UNRECOGNIZED); + if (format.begins_with("FORMAT=") && format != "FORMAT=32-bit_rle_rgbe") { + ERR_EXPLAIN("Only 32-bit_rle_rgbe is supported for .hdr files."); + return ERR_FILE_UNRECOGNIZED; + } + if (format == "FORMAT=32-bit_rle_rgbe") + break; + } + + String token = f->get_token(); + + ERR_FAIL_COND_V(token != "-Y", ERR_FILE_CORRUPT); + + int height = f->get_token().to_int(); + + token = f->get_token(); + + ERR_FAIL_COND_V(token != "+X", ERR_FILE_CORRUPT); + + int width = f->get_line().to_int(); + + print_line("HDR w: " + itos(width) + " h:" + itos(height)); + + PoolVector<uint8_t> imgdata; + + imgdata.resize(height * width * sizeof(uint32_t)); + + { + + PoolVector<uint8_t>::Write w = imgdata.write(); + + uint8_t *ptr = (uint8_t *)w.ptr(); + + if (width < 8 || width >= 32768) { + // Read flat data + + f->get_buffer(ptr, width * height * 4); + } else { + // Read RLE-encoded data + + for (int j = 0; j < height; ++j) { + int c1 = f->get_8(); + int c2 = f->get_8(); + int len = f->get_8(); + if (c1 != 2 || c2 != 2 || (len & 0x80)) { + // not run-length encoded, so we have to actually use THIS data as a decoded + // pixel (note this can't be a valid pixel--one of RGB must be >= 128) + + ptr[(j * width) * 4 + 0] = uint8_t(c1); + ptr[(j * width) * 4 + 1] = uint8_t(c2); + ptr[(j * width) * 4 + 2] = uint8_t(len); + ptr[(j * width) * 4 + 3] = f->get_8(); + + f->get_buffer(&ptr[(j * width + 1) * 4], (width - 1) * 4); + continue; + } + len <<= 8; + len |= f->get_8(); + + print_line("line: " + itos(len)); + if (len != width) { + ERR_EXPLAIN("invalid decoded scanline length, corrupt HDR"); + ERR_FAIL_V(ERR_FILE_CORRUPT); + } + + for (int k = 0; k < 4; ++k) { + int i = 0; + while (i < width) { + int count = f->get_8(); + if (count > 128) { + // Run + int value = f->get_8(); + count -= 128; + for (int z = 0; z < count; ++z) + ptr[(j * width + i++) * 4 + k] = uint8_t(value); + } else { + // Dump + for (int z = 0; z < count; ++z) + ptr[(j * width + i++) * 4 + k] = f->get_8(); + } + } + } + } + } + + //convert + for (int i = 0; i < width * height; i++) { + + float exp = pow(2.0f, ptr[3] - 128.0f); + + Color c( + ptr[0] * exp / 255.0, + ptr[1] * exp / 255.0, + ptr[2] * exp / 255.0); + + if (p_force_linear) { + c = c.to_linear(); + } + + *(uint32_t *)ptr = c.to_rgbe9995(); + ptr += 4; + } + } + + p_image->create(width, height, false, Image::FORMAT_RGBE9995, imgdata); + + return OK; +} + +void ImageLoaderHDR::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("hdr"); +} + +ImageLoaderHDR::ImageLoaderHDR() { +} diff --git a/modules/hdr/image_loader_hdr.h b/modules/hdr/image_loader_hdr.h new file mode 100644 index 0000000000..127833ebd0 --- /dev/null +++ b/modules/hdr/image_loader_hdr.h @@ -0,0 +1,46 @@ +/*************************************************************************/ +/* image_loader_jpegd.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef IMAGE_LOADER_HDR_H +#define IMAGE_LOADER_HDR_H + +#include "io/image_loader.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class ImageLoaderHDR : public ImageFormatLoader { + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderHDR(); +}; + +#endif diff --git a/modules/hdr/register_types.cpp b/modules/hdr/register_types.cpp new file mode 100644 index 0000000000..e4f7c14aa7 --- /dev/null +++ b/modules/hdr/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "register_types.h" + +#include "image_loader_hdr.h" + +static ImageLoaderHDR *image_loader_hdr = NULL; + +void register_hdr_types() { + + image_loader_hdr = memnew(ImageLoaderHDR); + ImageLoader::add_image_format_loader(image_loader_hdr); +} + +void unregister_hdr_types() { + + memdelete(image_loader_hdr); +} diff --git a/modules/hdr/register_types.h b/modules/hdr/register_types.h new file mode 100644 index 0000000000..3d901ea003 --- /dev/null +++ b/modules/hdr/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +void register_hdr_types(); +void unregister_hdr_types(); diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp index 83685d6446..8c73b69f1b 100644 --- a/modules/jpg/image_loader_jpegd.cpp +++ b/modules/jpg/image_loader_jpegd.cpp @@ -89,7 +89,7 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p return OK; } -Error ImageLoaderJPG::load_image(Image *p_image, FileAccess *f) { +Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { PoolVector<uint8_t> src_image; int src_image_len = f->get_len(); @@ -102,7 +102,7 @@ Error ImageLoaderJPG::load_image(Image *p_image, FileAccess *f) { f->close(); - Error err = jpeg_load_image_from_buffer(p_image, w.ptr(), src_image_len); + Error err = jpeg_load_image_from_buffer(p_image.ptr(), w.ptr(), src_image_len); w = PoolVector<uint8_t>::Write(); @@ -115,10 +115,11 @@ void ImageLoaderJPG::get_recognized_extensions(List<String> *p_extensions) const p_extensions->push_back("jpeg"); } -static Image _jpegd_mem_loader_func(const uint8_t *p_png, int p_size) { +static Ref<Image> _jpegd_mem_loader_func(const uint8_t *p_png, int p_size) { - Image img; - Error err = jpeg_load_image_from_buffer(&img, p_png, p_size); + Ref<Image> img; + img.instance(); + Error err = jpeg_load_image_from_buffer(img.ptr(), p_png, p_size); if (err) ERR_PRINT("Couldn't initialize ImageLoaderJPG with the given resource."); diff --git a/modules/jpg/image_loader_jpegd.h b/modules/jpg/image_loader_jpegd.h index d23e8a7d48..aa073b493d 100644 --- a/modules/jpg/image_loader_jpegd.h +++ b/modules/jpg/image_loader_jpegd.h @@ -38,7 +38,7 @@ class ImageLoaderJPG : public ImageFormatLoader { public: - virtual Error load_image(Image *p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderJPG(); }; diff --git a/modules/openssl/SCsub b/modules/openssl/SCsub index 0e811ce8c9..add7d4dcfc 100644 --- a/modules/openssl/SCsub +++ b/modules/openssl/SCsub @@ -677,7 +677,16 @@ if (env['builtin_openssl'] != 'no'): # Module sources env_openssl.add_source_files(env.modules_sources, "*.cpp") -env_openssl.add_source_files(env.modules_sources, "*.c") + + +# Other thirdparty dependencies +thirdparty_misc_dir = "#thirdparty/misc/" +thirdparty_misc_sources = [ + "curl_hostcheck.c", +] +thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources] +env_openssl.add_source_files(env.modules_sources, thirdparty_misc_sources) + # platform/uwp need to know openssl is available, pass to main env if "platform" in env and env["platform"] == "uwp": diff --git a/modules/openssl/curl_hostcheck.c b/modules/openssl/curl_hostcheck.c deleted file mode 100644 index feef232619..0000000000 --- a/modules/openssl/curl_hostcheck.c +++ /dev/null @@ -1,217 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ***************************************************************************/ - -/* This file is an amalgamation of hostcheck.c and most of rawstr.c - from cURL. The contents of the COPYING file mentioned above are: - -COPYRIGHT AND PERMISSION NOTICE - -Copyright (c) 1996 - 2013, Daniel Stenberg, <daniel@haxx.se>. - -All rights reserved. - -Permission to use, copy, modify, and distribute this software for any purpose -with or without fee is hereby granted, provided that the above copyright -notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN -NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE -OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of a copyright holder shall not -be used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization of the copyright holder. -*/ - -#include "curl_hostcheck.h" -#include <string.h> - -/* Portable, consistent toupper (remember EBCDIC). Do not use toupper() because - its behavior is altered by the current locale. */ -static char Curl_raw_toupper(char in) -{ - switch (in) { - case 'a': - return 'A'; - case 'b': - return 'B'; - case 'c': - return 'C'; - case 'd': - return 'D'; - case 'e': - return 'E'; - case 'f': - return 'F'; - case 'g': - return 'G'; - case 'h': - return 'H'; - case 'i': - return 'I'; - case 'j': - return 'J'; - case 'k': - return 'K'; - case 'l': - return 'L'; - case 'm': - return 'M'; - case 'n': - return 'N'; - case 'o': - return 'O'; - case 'p': - return 'P'; - case 'q': - return 'Q'; - case 'r': - return 'R'; - case 's': - return 'S'; - case 't': - return 'T'; - case 'u': - return 'U'; - case 'v': - return 'V'; - case 'w': - return 'W'; - case 'x': - return 'X'; - case 'y': - return 'Y'; - case 'z': - return 'Z'; - } - return in; -} - -/* - * Curl_raw_equal() is for doing "raw" case insensitive strings. This is meant - * to be locale independent and only compare strings we know are safe for - * this. See http://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for - * some further explanation to why this function is necessary. - * - * The function is capable of comparing a-z case insensitively even for - * non-ascii. - */ - -static int Curl_raw_equal(const char *first, const char *second) -{ - while(*first && *second) { - if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second)) - /* get out of the loop as soon as they don't match */ - break; - first++; - second++; - } - /* we do the comparison here (possibly again), just to make sure that if the - loop above is skipped because one of the strings reached zero, we must not - return this as a successful match */ - return (Curl_raw_toupper(*first) == Curl_raw_toupper(*second)); -} - -static int Curl_raw_nequal(const char *first, const char *second, size_t max) -{ - while(*first && *second && max) { - if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second)) { - break; - } - max--; - first++; - second++; - } - if(0 == max) - return 1; /* they are equal this far */ - - return Curl_raw_toupper(*first) == Curl_raw_toupper(*second); -} - -/* - * Match a hostname against a wildcard pattern. - * E.g. - * "foo.host.com" matches "*.host.com". - * - * We use the matching rule described in RFC6125, section 6.4.3. - * http://tools.ietf.org/html/rfc6125#section-6.4.3 - */ - -static int hostmatch(const char *hostname, const char *pattern) -{ - const char *pattern_label_end, *pattern_wildcard, *hostname_label_end; - int wildcard_enabled; - size_t prefixlen, suffixlen; - pattern_wildcard = strchr(pattern, '*'); - if(pattern_wildcard == NULL) - return Curl_raw_equal(pattern, hostname) ? - CURL_HOST_MATCH : CURL_HOST_NOMATCH; - - /* We require at least 2 dots in pattern to avoid too wide wildcard - match. */ - wildcard_enabled = 1; - pattern_label_end = strchr(pattern, '.'); - if(pattern_label_end == NULL || strchr(pattern_label_end+1, '.') == NULL || - pattern_wildcard > pattern_label_end || - Curl_raw_nequal(pattern, "xn--", 4)) { - wildcard_enabled = 0; - } - if(!wildcard_enabled) - return Curl_raw_equal(pattern, hostname) ? - CURL_HOST_MATCH : CURL_HOST_NOMATCH; - - hostname_label_end = strchr(hostname, '.'); - if(hostname_label_end == NULL || - !Curl_raw_equal(pattern_label_end, hostname_label_end)) - return CURL_HOST_NOMATCH; - - /* The wildcard must match at least one character, so the left-most - label of the hostname is at least as large as the left-most label - of the pattern. */ - if(hostname_label_end - hostname < pattern_label_end - pattern) - return CURL_HOST_NOMATCH; - - prefixlen = pattern_wildcard - pattern; - suffixlen = pattern_label_end - (pattern_wildcard+1); - return Curl_raw_nequal(pattern, hostname, prefixlen) && - Curl_raw_nequal(pattern_wildcard+1, hostname_label_end - suffixlen, - suffixlen) ? - CURL_HOST_MATCH : CURL_HOST_NOMATCH; -} - -int Tool_Curl_cert_hostcheck(const char *match_pattern, const char *hostname) -{ - if(!match_pattern || !*match_pattern || - !hostname || !*hostname) /* sanity check */ - return 0; - - if(Curl_raw_equal(hostname, match_pattern)) /* trivial case */ - return 1; - - if(hostmatch(hostname,match_pattern) == CURL_HOST_MATCH) - return 1; - return 0; -} diff --git a/modules/openssl/curl_hostcheck.h b/modules/openssl/curl_hostcheck.h deleted file mode 100644 index 1b7fbe81e3..0000000000 --- a/modules/openssl/curl_hostcheck.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef HEADER_TOOL_CURL_HOSTCHECK_H -#define HEADER_TOOL_CURL_HOSTCHECK_H - -#ifdef __cplusplus -extern "C" { -#endif - -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. - * - * This software is licensed as described in the file COPYING, which - * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. - * - * You may opt to use, copy, modify, merge, publish, distribute and/or sell - * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ***************************************************************************/ - -#define CURL_HOST_NOMATCH 0 -#define CURL_HOST_MATCH 1 -int Tool_Curl_cert_hostcheck(const char *match_pattern, const char *hostname); - -#ifdef __cplusplus -} -#endif - -#endif /* HEADER_CURL_HOSTCHECK_H */ - diff --git a/modules/openssl/stream_peer_openssl.h b/modules/openssl/stream_peer_openssl.h index 12262da94a..5c830ebf37 100644 --- a/modules/openssl/stream_peer_openssl.h +++ b/modules/openssl/stream_peer_openssl.h @@ -30,17 +30,19 @@ #ifndef STREAM_PEER_OPEN_SSL_H #define STREAM_PEER_OPEN_SSL_H -#include "curl_hostcheck.h" #include "global_config.h" #include "io/stream_peer_ssl.h" #include "os/file_access.h" -#include <stdio.h> // If you don't know what this is for stop reading now. + +#include "thirdparty/misc/curl_hostcheck.h" #include <openssl/bio.h> // BIO objects for I/O #include <openssl/err.h> // Error reporting #include <openssl/ssl.h> // SSL and SSL_CTX for SSL connections #include <openssl/x509v3.h> +#include <stdio.h> + class StreamPeerOpenSSL : public StreamPeerSSL { private: static int _bio_create(BIO *b); diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 62cbd9cd8d..bdd4779e28 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -164,8 +164,8 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, print_line("flip: " + itos(flags & PVR_VFLIP)); - Image image(width, height, mipmaps, format, data); - ERR_FAIL_COND_V(image.empty(), RES()); + Ref<Image> image = memnew(Image(width, height, mipmaps, format, data)); + ERR_FAIL_COND_V(image->empty(), RES()); Ref<ImageTexture> texture = memnew(ImageTexture); texture->create_from_image(image, tex_flags); @@ -193,30 +193,32 @@ String ResourceFormatPVR::get_resource_type(const String &p_path) const { static void _compress_pvrtc4(Image *p_img) { - Image img = *p_img; + Ref<Image> img = p_img->duplicate(); bool make_mipmaps = false; - if (img.get_width() % 8 || img.get_height() % 8) { - make_mipmaps = img.has_mipmaps(); - img.resize(img.get_width() + (8 - (img.get_width() % 8)), img.get_height() + (8 - (img.get_height() % 8))); + if (img->get_width() % 8 || img->get_height() % 8) { + make_mipmaps = img->has_mipmaps(); + img->resize(img->get_width() + (8 - (img->get_width() % 8)), img->get_height() + (8 - (img->get_height() % 8))); } - img.convert(Image::FORMAT_RGBA8); - if (!img.has_mipmaps() && make_mipmaps) - img.generate_mipmaps(); + img->convert(Image::FORMAT_RGBA8); + if (!img->has_mipmaps() && make_mipmaps) + img->generate_mipmaps(); - bool use_alpha = img.detect_alpha(); + bool use_alpha = img->detect_alpha(); - Image new_img; - new_img.create(img.get_width(), img.get_height(), true, use_alpha ? Image::FORMAT_PVRTC4A : Image::FORMAT_PVRTC4); - PoolVector<uint8_t> data = new_img.get_data(); + Ref<Image> new_img; + new_img.instance(); + new_img->create(img->get_width(), img->get_height(), true, use_alpha ? Image::FORMAT_PVRTC4A : Image::FORMAT_PVRTC4); + + PoolVector<uint8_t> data = new_img->get_data(); { PoolVector<uint8_t>::Write wr = data.write(); - PoolVector<uint8_t>::Read r = img.get_data().read(); + PoolVector<uint8_t>::Read r = img->get_data().read(); - for (int i = 0; i <= new_img.get_mipmap_count(); i++) { + for (int i = 0; i <= new_img->get_mipmap_count(); i++) { int ofs, size, w, h; - img.get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); + img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); Javelin::RgbaBitmap bm(w, h); copymem(bm.GetData(), &r[ofs], size); { @@ -226,12 +228,12 @@ static void _compress_pvrtc4(Image *p_img) { } } - new_img.get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); + new_img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); Javelin::PvrTcEncoder::EncodeRgba4Bpp(&wr[ofs], bm); } } - *p_img = Image(new_img.get_width(), new_img.get_height(), new_img.has_mipmaps(), new_img.get_format(), data); + p_img->create(new_img->get_width(), new_img->get_height(), new_img->has_mipmaps(), new_img->get_format(), data); } ResourceFormatPVR::ResourceFormatPVR() { @@ -676,8 +678,7 @@ static void _pvrtc_decompress(Image *p_img) { r = PoolVector<uint8_t>::Read(); bool make_mipmaps = p_img->has_mipmaps(); - Image newimg(p_img->get_width(), p_img->get_height(), false, Image::FORMAT_RGBA8, newdata); + p_img->create(p_img->get_width(), p_img->get_height(), false, Image::FORMAT_RGBA8, newdata); if (make_mipmaps) - newimg.generate_mipmaps(); - *p_img = newimg; + p_img->generate_mipmaps(); } diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index c6835d4b62..efce76c805 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -31,65 +31,143 @@ #include "print_string.h" -#include <squish.h> +#if defined(__SSE2__) +#define SQUISH_USE_SSE 2 +#elif defined(__SSE__) +#define SQUISH_USE_SSE 1 +#endif -void image_compress_squish(Image *p_image) { +#include <squish.h> +void image_decompress_squish(Image *p_image) { int w = p_image->get_width(); int h = p_image->get_height(); - if (!p_image->has_mipmaps()) { - ERR_FAIL_COND(!w || w % 4 != 0); - ERR_FAIL_COND(!h || h % 4 != 0); + Image::Format target_format = Image::FORMAT_RGBA8; + PoolVector<uint8_t> data; + int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps() ? -1 : 0); + int mm_count = p_image->get_mipmap_count(); + data.resize(target_size); + + PoolVector<uint8_t>::Read rb = p_image->get_data().read(); + PoolVector<uint8_t>::Write wb = data.write(); + + int squish_flags = Image::FORMAT_MAX; + if (p_image->get_format() == Image::FORMAT_DXT1) { + squish_flags = squish::kDxt1; + } else if (p_image->get_format() == Image::FORMAT_DXT3) { + squish_flags = squish::kDxt3; + } else if (p_image->get_format() == Image::FORMAT_DXT5) { + squish_flags = squish::kDxt5; + } else if (p_image->get_format() == Image::FORMAT_RGTC_R) { + squish_flags = squish::kBc4; + } else if (p_image->get_format() == Image::FORMAT_RGTC_RG) { + squish_flags = squish::kBc5; } else { - ERR_FAIL_COND(!w || w != nearest_power_of_2(w)); - ERR_FAIL_COND(!h || h != nearest_power_of_2(h)); - }; + print_line("wtf askd to decompress.. " + itos(p_image->get_format())); + ERR_FAIL_COND(true); + return; + } + + int dst_ofs = 0; + + for (int i = 0; i <= mm_count; i++) { + int src_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0; + p_image->get_mipmap_offset_size_and_dimensions(i, src_ofs, mipmap_size, mipmap_w, mipmap_h); + squish::DecompressImage(&wb[dst_ofs], mipmap_w, mipmap_h, &rb[src_ofs], squish_flags); + } + + p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); +} + +void image_compress_squish(Image *p_image, Image::CompressSource p_source) { if (p_image->get_format() >= Image::FORMAT_DXT1) return; //do not compress, already compressed - int shift = 0; - int squish_comp = squish::kColourRangeFit; - Image::Format target_format; + int w = p_image->get_width(); + int h = p_image->get_height(); - if (p_image->get_format() == Image::FORMAT_LA8) { - //compressed normalmap - target_format = Image::FORMAT_DXT5; - squish_comp |= squish::kDxt5; - } else if (p_image->detect_alpha() != Image::ALPHA_NONE) { + if (p_image->get_format() <= Image::FORMAT_RGBA8) { - target_format = Image::FORMAT_DXT3; - squish_comp |= squish::kDxt3; - } else { - target_format = Image::FORMAT_DXT1; - shift = 1; - squish_comp |= squish::kDxt1; - } + int squish_comp = squish::kColourRangeFit; + Image::Format target_format; - p_image->convert(Image::FORMAT_RGBA8); //always expects rgba + Image::DetectChannels dc = p_image->get_detected_channels(); - PoolVector<uint8_t> data; - int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps() ? -1 : 0); - int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w, h, target_format) : 0; - data.resize(target_size); + p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert - PoolVector<uint8_t>::Read rb = p_image->get_data().read(); - PoolVector<uint8_t>::Write wb = data.write(); + if (p_source == Image::COMPRESS_SOURCE_SRGB && (dc == Image::DETECTED_R || dc == Image::DETECTED_RG)) { + //R and RG do not support SRGB + dc = Image::DETECTED_RGB; + } - int dst_ofs = 0; + if (p_source == Image::COMPRESS_SOURCE_NORMAL) { + //R and RG do not support SRGB + dc = Image::DETECTED_RG; + } - for (int i = 0; i <= mm_count; i++) { + switch (dc) { + case Image::DETECTED_L: { - int src_ofs = p_image->get_mipmap_offset(i); - squish::CompressImage(&rb[src_ofs], w, h, &wb[dst_ofs], squish_comp); - dst_ofs += (MAX(4, w) * MAX(4, h)) >> shift; - w >>= 1; - h >>= 1; - } + target_format = Image::FORMAT_DXT1; + squish_comp |= squish::kDxt1; + } break; + case Image::DETECTED_LA: { - rb = PoolVector<uint8_t>::Read(); - wb = PoolVector<uint8_t>::Write(); + target_format = Image::FORMAT_DXT5; + squish_comp |= squish::kDxt5; + } break; + case Image::DETECTED_R: { - p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); + target_format = Image::FORMAT_RGTC_R; + squish_comp |= squish::kBc4; + } break; + case Image::DETECTED_RG: { + + target_format = Image::FORMAT_RGTC_RG; + squish_comp |= squish::kBc5; + } break; + case Image::DETECTED_RGB: { + + target_format = Image::FORMAT_DXT1; + squish_comp |= squish::kDxt1; + } break; + case Image::DETECTED_RGBA: { + + //TODO, should convert both, then measure which one does a better job + target_format = Image::FORMAT_DXT5; + squish_comp |= squish::kDxt5; + + } break; + } + + PoolVector<uint8_t> data; + int target_size = Image::get_image_data_size(w, h, target_format, p_image->has_mipmaps() ? -1 : 0); + int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w, h, target_format) : 0; + data.resize(target_size); + int shift = Image::get_format_pixel_rshift(target_format); + + PoolVector<uint8_t>::Read rb = p_image->get_data().read(); + PoolVector<uint8_t>::Write wb = data.write(); + + int dst_ofs = 0; + + for (int i = 0; i <= mm_count; i++) { + + int bw = w % 4 != 0 ? w + (4 - w % 4) : w; + int bh = h % 4 != 0 ? h + (4 - h % 4) : h; + + int src_ofs = p_image->get_mipmap_offset(i); + squish::CompressImage(&rb[src_ofs], w, h, &wb[dst_ofs], squish_comp); + dst_ofs += (MAX(4, bw) * MAX(4, bh)) >> shift; + w >>= 1; + h >>= 1; + } + + rb = PoolVector<uint8_t>::Read(); + wb = PoolVector<uint8_t>::Write(); + + p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data); + } } diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h index 81f57c6822..68aaeefc30 100644 --- a/modules/squish/image_compress_squish.h +++ b/modules/squish/image_compress_squish.h @@ -32,6 +32,7 @@ #include "image.h" -void image_compress_squish(Image *p_image); +void image_compress_squish(Image *p_image, Image::CompressSource p_source); +void image_decompress_squish(Image *p_image); #endif // IMAGE_COMPRESS_SQUISH_H diff --git a/modules/squish/register_types.cpp b/modules/squish/register_types.cpp index 41341db93b..2eeea59836 100644 --- a/modules/squish/register_types.cpp +++ b/modules/squish/register_types.cpp @@ -36,6 +36,7 @@ void register_squish_types() { Image::set_compress_bc_func(image_compress_squish); + Image::_image_decompress_bc = image_decompress_squish; } void unregister_squish_types() {} diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 227e5e61b6..c645a55703 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -30,7 +30,8 @@ #include "audio_stream_ogg_vorbis.h" #include "os/file_access.h" -#include "thirdparty/stb_vorbis/stb_vorbis.c" + +#include "thirdparty/misc/stb_vorbis.c" void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { @@ -42,6 +43,7 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, (float *)p_buffer, todo * 2); todo -= mixed; + frames_mixed += mixed; if (todo) { //end of file! @@ -66,8 +68,8 @@ float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() { void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) { - seek_pos(p_from_pos); active = true; + seek_pos(p_from_pos); loops = 0; _begin_resample(); } @@ -95,7 +97,12 @@ void AudioStreamPlaybackOGGVorbis::seek_pos(float p_time) { if (!active) return; - stb_vorbis_seek(ogg_stream, uint32_t(p_time * vorbis_stream->sample_rate)); + if (p_time >= get_length()) { + p_time = 0; + } + frames_mixed = uint32_t(vorbis_stream->sample_rate * p_time); + + stb_vorbis_seek(ogg_stream, frames_mixed); } float AudioStreamPlaybackOGGVorbis::get_length() const { diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index bb895c4dfa..46cdfd3f2d 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -34,7 +34,7 @@ #include "servers/audio/audio_stream.h" #define STB_VORBIS_HEADER_ONLY -#include "thirdparty/stb_vorbis/stb_vorbis.c" +#include "thirdparty/misc/stb_vorbis.c" #undef STB_VORBIS_HEADER_ONLY class AudioStreamOGGVorbis; @@ -77,7 +77,7 @@ class AudioStreamOGGVorbis : public AudioStream { GDCLASS(AudioStreamOGGVorbis, AudioStream) OBJ_SAVE_TYPE(AudioStream) //children are all saved as AudioStream, so they can be exchanged - RES_BASE_EXTENSION("asogg"); + RES_BASE_EXTENSION("oggstr"); friend class AudioStreamPlaybackOGGVorbis; diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp index 9a3d5c2651..f0a7ee1ec6 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -48,7 +48,7 @@ void ResourceImporterOGGVorbis::get_recognized_extensions(List<String> *p_extens } String ResourceImporterOGGVorbis::get_save_extension() const { - return "asogg"; + return "oggstr"; } String ResourceImporterOGGVorbis::get_resource_type() const { @@ -99,7 +99,7 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin ogg_stream->set_data(data); ogg_stream->set_loop(loop); - return ResourceSaver::save(p_save_path + ".asogg", ogg_stream); + return ResourceSaver::save(p_save_path + ".oggstr", ogg_stream); } ResourceImporterOGGVorbis::ResourceImporterOGGVorbis() { diff --git a/modules/tga/SCsub b/modules/tga/SCsub new file mode 100644 index 0000000000..7e405f405c --- /dev/null +++ b/modules/tga/SCsub @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_tga = env_modules.Clone() + +# Godot's own source files +env_tga.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/tga/config.py b/modules/tga/config.py new file mode 100644 index 0000000000..fb920482f5 --- /dev/null +++ b/modules/tga/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp new file mode 100644 index 0000000000..5b8610b975 --- /dev/null +++ b/modules/tga/image_loader_tga.cpp @@ -0,0 +1,314 @@ +/*************************************************************************/ +/* image_loader_jpegd.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "image_loader_tga.h" + +#include "os/os.h" +#include "print_string.h" + +Error ImageLoaderTGA::decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size) { + Error error; + + PoolVector<uint8_t> pixels; + error = pixels.resize(p_pixel_size); + if (error != OK) + return error; + + PoolVector<uint8_t>::Write pixels_w = pixels.write(); + + size_t compressed_pos = 0; + size_t output_pos = 0; + size_t c = 0; + size_t count = 0; + + while (output_pos < p_output_size) { + c = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + count = (c & 0x7f) + 1; + + if (c & 0x80) { + for (int i = 0; i < p_pixel_size; i++) { + pixels_w.ptr()[i] = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + } + for (int i = 0; i < count; i++) { + for (int j = 0; j < p_pixel_size; j++) { + p_uncompressed_buffer[output_pos + j] = pixels_w.ptr()[j]; + } + output_pos += p_pixel_size; + } + } else { + count *= p_pixel_size; + for (int i = 0; i < count; i++) { + p_uncompressed_buffer[output_pos] = p_compressed_buffer[compressed_pos]; + compressed_pos += 1; + output_pos += 1; + } + } + } + return OK; +} + +Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome) { + +#define TGA_PUT_PIXEL(r, g, b, a) \ + int image_data_ofs = ((y * width) + x); \ + image_data_w[image_data_ofs * 4 + 0] = r; \ + image_data_w[image_data_ofs * 4 + 1] = g; \ + image_data_w[image_data_ofs * 4 + 2] = b; \ + image_data_w[image_data_ofs * 4 + 3] = a; + + uint32_t width = p_header.image_width; + uint32_t height = p_header.image_height; + tga_origin_e origin = static_cast<tga_origin_e>((p_header.image_descriptor & TGA_ORIGIN_MASK) >> TGA_ORIGIN_SHIFT); + + uint32_t x_start; + int32_t x_step; + uint32_t x_end; + uint32_t y_start; + int32_t y_step; + uint32_t y_end; + + if (origin == TGA_ORIGIN_TOP_LEFT || origin == TGA_ORIGIN_TOP_RIGHT) { + y_start = 0; + y_step = 1; + y_end = height; + } else { + y_start = height - 1; + y_step = -1; + y_end = -1; + } + + if (origin == TGA_ORIGIN_TOP_LEFT || origin == TGA_ORIGIN_BOTTOM_LEFT) { + x_start = 0; + x_step = 1; + x_end = width; + } else { + x_start = width - 1; + x_step = -1; + x_end = -1; + } + + PoolVector<uint8_t> image_data; + image_data.resize(width * height * sizeof(uint32_t)); + PoolVector<uint8_t>::Write image_data_w = image_data.write(); + + size_t i = 0; + uint32_t x = x_start; + uint32_t y = y_start; + + if (p_header.pixel_depth == 8) { + if (p_is_monochrome) { + while (y != y_end) { + while (x != x_end) { + uint8_t shade = p_buffer[i]; + + TGA_PUT_PIXEL(shade, shade, shade, 0xff) + + x += x_step; + i += 1; + } + x = x_start; + y += y_step; + } + } else { + while (y != y_end) { + while (x != x_end) { + uint8_t index = p_buffer[i]; + uint8_t r = 0x00; + uint8_t g = 0x00; + uint8_t b = 0x00; + uint8_t a = 0xff; + + if (p_header.color_map_depth == 24) { + r = (p_palette[(index * 3) + 0]); + g = (p_palette[(index * 3) + 1]); + b = (p_palette[(index * 3) + 2]); + } else { + return ERR_INVALID_DATA; + } + + TGA_PUT_PIXEL(r, g, b, a) + + x += x_step; + i += 1; + } + x = x_start; + y += y_step; + } + } + } else if (p_header.pixel_depth == 24) { + while (y != y_end) { + while (x != x_end) { + uint8_t r = p_buffer[i + 2]; + uint8_t g = p_buffer[i + 1]; + uint8_t b = p_buffer[i + 0]; + + TGA_PUT_PIXEL(r, g, b, 0xff) + + x += x_step; + i += 3; + } + x = x_start; + y += y_step; + } + } else if (p_header.pixel_depth == 32) { + while (y != y_end) { + while (x != x_end) { + uint8_t a = p_buffer[i + 3]; + uint8_t r = p_buffer[i + 2]; + uint8_t g = p_buffer[i + 1]; + uint8_t b = p_buffer[i + 0]; + + TGA_PUT_PIXEL(r, g, b, a) + + x += x_step; + i += 4; + } + x = x_start; + y += y_step; + } + } + + image_data_w = PoolVector<uint8_t>::Write(); + + p_image->create(width, height, 0, Image::FORMAT_RGBA8, image_data); + + return OK; +} + +Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + PoolVector<uint8_t> src_image; + int src_image_len = f->get_len(); + ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); + ERR_FAIL_COND_V(src_image_len < sizeof(tga_header_s), ERR_FILE_CORRUPT); + src_image.resize(src_image_len); + + Error err = OK; + + tga_header_s tga_header; + tga_header.id_length = f->get_8(); + tga_header.color_map_type = f->get_8(); + tga_header.image_type = static_cast<tga_type_e>(f->get_8()); + + tga_header.first_color_entry = f->get_16(); + tga_header.color_map_length = f->get_16(); + tga_header.color_map_depth = f->get_8(); + + tga_header.x_origin = f->get_16(); + tga_header.y_origin = f->get_16(); + tga_header.image_width = f->get_16(); + tga_header.image_height = f->get_16(); + tga_header.pixel_depth = f->get_8(); + tga_header.image_descriptor = f->get_8(); + + bool is_encoded = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_RLE_RGB || tga_header.image_type == TGA_TYPE_RLE_MONOCHROME); + bool has_color_map = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_INDEXED); + bool is_monochrome = (tga_header.image_type == TGA_TYPE_RLE_MONOCHROME || tga_header.image_type == TGA_TYPE_MONOCHROME); + + if (tga_header.image_type == TGA_TYPE_NO_DATA) + err = FAILED; + + if (has_color_map) { + if (tga_header.color_map_length > 256 || (tga_header.color_map_depth != 24) || tga_header.color_map_type != 1) { + err = FAILED; + } + } else { + if (tga_header.color_map_type) { + err = FAILED; + } + } + + if (tga_header.image_width <= 0 || tga_header.image_height <= 0) + err = FAILED; + + if (tga_header.pixel_depth != 8 && tga_header.pixel_depth != 24 && tga_header.pixel_depth != 32) + err = FAILED; + + if (err == OK) { + f->seek(f->get_pos() + tga_header.id_length); + + PoolVector<uint8_t> palette; + + if (has_color_map) { + size_t color_map_size = tga_header.color_map_length * (tga_header.color_map_depth >> 3); + err = palette.resize(color_map_size); + if (err == OK) { + PoolVector<uint8_t>::Write palette_w = palette.write(); + f->get_buffer(&palette_w[0], color_map_size); + } else { + return OK; + } + } + + PoolVector<uint8_t>::Write src_image_w = src_image.write(); + f->get_buffer(&src_image_w[0], src_image_len - f->get_pos()); + + PoolVector<uint8_t>::Read src_image_r = src_image.read(); + + const size_t pixel_size = tga_header.pixel_depth >> 3; + const size_t buffer_size = (tga_header.image_width * tga_header.image_height) * pixel_size; + + PoolVector<uint8_t> uncompressed_buffer; + uncompressed_buffer.resize(buffer_size); + PoolVector<uint8_t>::Write uncompressed_buffer_w = uncompressed_buffer.write(); + PoolVector<uint8_t>::Read uncompressed_buffer_r; + + const uint8_t *buffer = NULL; + + if (is_encoded) { + + err = decode_tga_rle(src_image_r.ptr(), pixel_size, uncompressed_buffer_w.ptr(), buffer_size); + + if (err == OK) { + uncompressed_buffer_r = uncompressed_buffer.read(); + buffer = uncompressed_buffer_r.ptr(); + } + } else { + buffer = src_image_r.ptr(); + }; + + if (err == OK) { + PoolVector<uint8_t>::Read palette_r = palette.read(); + err = convert_to_image(p_image, buffer, tga_header, palette_r.ptr(), is_monochrome); + } + } + + f->close(); + return err; +} + +void ImageLoaderTGA::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("tga"); +} + +ImageLoaderTGA::ImageLoaderTGA() { +} diff --git a/modules/tga/image_loader_tga.h b/modules/tga/image_loader_tga.h new file mode 100644 index 0000000000..11329ec68a --- /dev/null +++ b/modules/tga/image_loader_tga.h @@ -0,0 +1,83 @@ +/*************************************************************************/ +/* image_loader_jpegd.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef IMAGE_LOADER_TGA_H +#define IMAGE_LOADER_TGA_H + +#include "io/image_loader.h" + +/** + @author SaracenOne +*/ +class ImageLoaderTGA : public ImageFormatLoader { + enum tga_type_e { + TGA_TYPE_NO_DATA = 0, + TGA_TYPE_INDEXED = 1, + TGA_TYPE_RGB = 2, + TGA_TYPE_MONOCHROME = 3, + TGA_TYPE_RLE_INDEXED = 9, + TGA_TYPE_RLE_RGB = 10, + TGA_TYPE_RLE_MONOCHROME = 11 + }; + + enum tga_origin_e { + TGA_ORIGIN_BOTTOM_LEFT = 0x00, + TGA_ORIGIN_BOTTOM_RIGHT = 0x01, + TGA_ORIGIN_TOP_LEFT = 0x02, + TGA_ORIGIN_TOP_RIGHT = 0x03, + TGA_ORIGIN_SHIFT = 0x04, + TGA_ORIGIN_MASK = 0x30 + }; + + struct tga_header_s { + uint8_t id_length; + uint8_t color_map_type; + tga_type_e image_type; + + uint16_t first_color_entry; + uint16_t color_map_length; + uint8_t color_map_depth; + + uint16_t x_origin; + uint16_t y_origin; + uint16_t image_width; + uint16_t image_height; + uint8_t pixel_depth; + uint8_t image_descriptor; + }; + static Error decode_tga_rle(const uint8_t *p_compressed_buffer, size_t p_pixel_size, uint8_t *p_uncompressed_buffer, size_t p_output_size); + static Error convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome); + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderTGA(); +}; + +#endif diff --git a/modules/tga/register_types.cpp b/modules/tga/register_types.cpp new file mode 100644 index 0000000000..6e120fa3bf --- /dev/null +++ b/modules/tga/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "register_types.h" + +#include "image_loader_tga.h" + +static ImageLoaderTGA *image_loader_tga = NULL; + +void register_tga_types() { + + image_loader_tga = memnew(ImageLoaderTGA); + ImageLoader::add_image_format_loader(image_loader_tga); +} + +void unregister_tga_types() { + + memdelete(image_loader_tga); +} diff --git a/modules/tga/register_types.h b/modules/tga/register_types.h new file mode 100644 index 0000000000..079b7bf291 --- /dev/null +++ b/modules/tga/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +void register_tga_types(); +void unregister_tga_types(); diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 28463e2cba..d895f60280 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -31,7 +31,8 @@ #include "global_config.h" #include "os/os.h" -#include "yuv2rgb.h" + +#include "thirdparty/misc/yuv2rgb.h" int VideoStreamPlaybackTheora::buffer_data() { @@ -137,7 +138,7 @@ void VideoStreamPlaybackTheora::video_write(void) { format = Image::FORMAT_RGBA8; } - Image img(size.x, size.y, 0, Image::FORMAT_RGBA8, frame_data); //zero copy image creation + Ref<Image> img = memnew(Image(size.x, size.y, 0, Image::FORMAT_RGBA8, frame_data)); //zero copy image creation texture->set_data(img); //zero copy send to visual server diff --git a/modules/theora/yuv2rgb.h b/modules/theora/yuv2rgb.h deleted file mode 100644 index a9bef76da8..0000000000 --- a/modules/theora/yuv2rgb.h +++ /dev/null @@ -1,1123 +0,0 @@ -/* Thirdparty code presumably from http://wss.co.uk/pinknoise/yuv2rgb/ */ -/* FIXME: Move to thirdparty dir */ - -#ifndef YUV2RGB_H -#define YUV2RGB_H - -#include "typedefs.h" - -static const uint32_t tables[256*3] = { - /* y_table */ - 0x7FFFFFEDU, - 0x7FFFFFEFU, - 0x7FFFFFF0U, - 0x7FFFFFF1U, - 0x7FFFFFF2U, - 0x7FFFFFF3U, - 0x7FFFFFF4U, - 0x7FFFFFF6U, - 0x7FFFFFF7U, - 0x7FFFFFF8U, - 0x7FFFFFF9U, - 0x7FFFFFFAU, - 0x7FFFFFFBU, - 0x7FFFFFFDU, - 0x7FFFFFFEU, - 0x7FFFFFFFU, - 0x80000000U, - 0x80400801U, - 0x80A01002U, - 0x80E01803U, - 0x81202805U, - 0x81803006U, - 0x81C03807U, - 0x82004008U, - 0x82604809U, - 0x82A0500AU, - 0x82E0600CU, - 0x8340680DU, - 0x8380700EU, - 0x83C0780FU, - 0x84208010U, - 0x84608811U, - 0x84A09813U, - 0x8500A014U, - 0x8540A815U, - 0x8580B016U, - 0x85E0B817U, - 0x8620C018U, - 0x8660D01AU, - 0x86C0D81BU, - 0x8700E01CU, - 0x8740E81DU, - 0x87A0F01EU, - 0x87E0F81FU, - 0x88210821U, - 0x88811022U, - 0x88C11823U, - 0x89012024U, - 0x89412825U, - 0x89A13026U, - 0x89E14028U, - 0x8A214829U, - 0x8A81502AU, - 0x8AC1582BU, - 0x8B01602CU, - 0x8B61682DU, - 0x8BA1782FU, - 0x8BE18030U, - 0x8C418831U, - 0x8C819032U, - 0x8CC19833U, - 0x8D21A034U, - 0x8D61B036U, - 0x8DA1B837U, - 0x8E01C038U, - 0x8E41C839U, - 0x8E81D03AU, - 0x8EE1D83BU, - 0x8F21E83DU, - 0x8F61F03EU, - 0x8FC1F83FU, - 0x90020040U, - 0x90420841U, - 0x90A21042U, - 0x90E22044U, - 0x91222845U, - 0x91823046U, - 0x91C23847U, - 0x92024048U, - 0x92624849U, - 0x92A2504AU, - 0x92E2604CU, - 0x9342684DU, - 0x9382704EU, - 0x93C2784FU, - 0x94228050U, - 0x94628851U, - 0x94A29853U, - 0x9502A054U, - 0x9542A855U, - 0x9582B056U, - 0x95E2B857U, - 0x9622C058U, - 0x9662D05AU, - 0x96C2D85BU, - 0x9702E05CU, - 0x9742E85DU, - 0x97A2F05EU, - 0x97E2F85FU, - 0x98230861U, - 0x98831062U, - 0x98C31863U, - 0x99032064U, - 0x99632865U, - 0x99A33066U, - 0x99E34068U, - 0x9A434869U, - 0x9A83506AU, - 0x9AC3586BU, - 0x9B23606CU, - 0x9B63686DU, - 0x9BA3786FU, - 0x9BE38070U, - 0x9C438871U, - 0x9C839072U, - 0x9CC39873U, - 0x9D23A074U, - 0x9D63B076U, - 0x9DA3B877U, - 0x9E03C078U, - 0x9E43C879U, - 0x9E83D07AU, - 0x9EE3D87BU, - 0x9F23E87DU, - 0x9F63F07EU, - 0x9FC3F87FU, - 0xA0040080U, - 0xA0440881U, - 0xA0A41082U, - 0xA0E42084U, - 0xA1242885U, - 0xA1843086U, - 0xA1C43887U, - 0xA2044088U, - 0xA2644889U, - 0xA2A4588BU, - 0xA2E4608CU, - 0xA344688DU, - 0xA384708EU, - 0xA3C4788FU, - 0xA4248090U, - 0xA4649092U, - 0xA4A49893U, - 0xA504A094U, - 0xA544A895U, - 0xA584B096U, - 0xA5E4B897U, - 0xA624C098U, - 0xA664D09AU, - 0xA6C4D89BU, - 0xA704E09CU, - 0xA744E89DU, - 0xA7A4F09EU, - 0xA7E4F89FU, - 0xA82508A1U, - 0xA88510A2U, - 0xA8C518A3U, - 0xA90520A4U, - 0xA96528A5U, - 0xA9A530A6U, - 0xA9E540A8U, - 0xAA4548A9U, - 0xAA8550AAU, - 0xAAC558ABU, - 0xAB2560ACU, - 0xAB6568ADU, - 0xABA578AFU, - 0xAC0580B0U, - 0xAC4588B1U, - 0xAC8590B2U, - 0xACE598B3U, - 0xAD25A0B4U, - 0xAD65B0B6U, - 0xADA5B8B7U, - 0xAE05C0B8U, - 0xAE45C8B9U, - 0xAE85D0BAU, - 0xAEE5D8BBU, - 0xAF25E8BDU, - 0xAF65F0BEU, - 0xAFC5F8BFU, - 0xB00600C0U, - 0xB04608C1U, - 0xB0A610C2U, - 0xB0E620C4U, - 0xB12628C5U, - 0xB18630C6U, - 0xB1C638C7U, - 0xB20640C8U, - 0xB26648C9U, - 0xB2A658CBU, - 0xB2E660CCU, - 0xB34668CDU, - 0xB38670CEU, - 0xB3C678CFU, - 0xB42680D0U, - 0xB46690D2U, - 0xB4A698D3U, - 0xB506A0D4U, - 0xB546A8D5U, - 0xB586B0D6U, - 0xB5E6B8D7U, - 0xB626C8D9U, - 0xB666D0DAU, - 0xB6C6D8DBU, - 0xB706E0DCU, - 0xB746E8DDU, - 0xB7A6F0DEU, - 0xB7E6F8DFU, - 0xB82708E1U, - 0xB88710E2U, - 0xB8C718E3U, - 0xB90720E4U, - 0xB96728E5U, - 0xB9A730E6U, - 0xB9E740E8U, - 0xBA4748E9U, - 0xBA8750EAU, - 0xBAC758EBU, - 0xBB2760ECU, - 0xBB6768EDU, - 0xBBA778EFU, - 0xBC0780F0U, - 0xBC4788F1U, - 0xBC8790F2U, - 0xBCE798F3U, - 0xBD27A0F4U, - 0xBD67B0F6U, - 0xBDC7B8F7U, - 0xBE07C0F8U, - 0xBE47C8F9U, - 0xBEA7D0FAU, - 0xBEE7D8FBU, - 0xBF27E8FDU, - 0xBF87F0FEU, - 0xBFC7F8FFU, - 0xC0080100U, - 0xC0480901U, - 0xC0A81102U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - 0xC0E82104U, - /* u_table */ - 0x0C400103U, - 0x0C200105U, - 0x0C200107U, - 0x0C000109U, - 0x0BE0010BU, - 0x0BC0010DU, - 0x0BA0010FU, - 0x0BA00111U, - 0x0B800113U, - 0x0B600115U, - 0x0B400117U, - 0x0B400119U, - 0x0B20011BU, - 0x0B00011DU, - 0x0AE0011FU, - 0x0AE00121U, - 0x0AC00123U, - 0x0AA00125U, - 0x0A800127U, - 0x0A600129U, - 0x0A60012BU, - 0x0A40012DU, - 0x0A20012FU, - 0x0A000131U, - 0x0A000132U, - 0x09E00134U, - 0x09C00136U, - 0x09A00138U, - 0x09A0013AU, - 0x0980013CU, - 0x0960013EU, - 0x09400140U, - 0x09400142U, - 0x09200144U, - 0x09000146U, - 0x08E00148U, - 0x08C0014AU, - 0x08C0014CU, - 0x08A0014EU, - 0x08800150U, - 0x08600152U, - 0x08600154U, - 0x08400156U, - 0x08200158U, - 0x0800015AU, - 0x0800015CU, - 0x07E0015EU, - 0x07C00160U, - 0x07A00162U, - 0x07A00164U, - 0x07800166U, - 0x07600168U, - 0x0740016AU, - 0x0720016CU, - 0x0720016EU, - 0x07000170U, - 0x06E00172U, - 0x06C00174U, - 0x06C00176U, - 0x06A00178U, - 0x0680017AU, - 0x0660017CU, - 0x0660017EU, - 0x06400180U, - 0x06200182U, - 0x06000184U, - 0x05E00185U, - 0x05E00187U, - 0x05C00189U, - 0x05A0018BU, - 0x0580018DU, - 0x0580018FU, - 0x05600191U, - 0x05400193U, - 0x05200195U, - 0x05200197U, - 0x05000199U, - 0x04E0019BU, - 0x04C0019DU, - 0x04C0019FU, - 0x04A001A1U, - 0x048001A3U, - 0x046001A5U, - 0x044001A7U, - 0x044001A9U, - 0x042001ABU, - 0x040001ADU, - 0x03E001AFU, - 0x03E001B1U, - 0x03C001B3U, - 0x03A001B5U, - 0x038001B7U, - 0x038001B9U, - 0x036001BBU, - 0x034001BDU, - 0x032001BFU, - 0x032001C1U, - 0x030001C3U, - 0x02E001C5U, - 0x02C001C7U, - 0x02A001C9U, - 0x02A001CBU, - 0x028001CDU, - 0x026001CFU, - 0x024001D1U, - 0x024001D3U, - 0x022001D5U, - 0x020001D7U, - 0x01E001D8U, - 0x01E001DAU, - 0x01C001DCU, - 0x01A001DEU, - 0x018001E0U, - 0x016001E2U, - 0x016001E4U, - 0x014001E6U, - 0x012001E8U, - 0x010001EAU, - 0x010001ECU, - 0x00E001EEU, - 0x00C001F0U, - 0x00A001F2U, - 0x00A001F4U, - 0x008001F6U, - 0x006001F8U, - 0x004001FAU, - 0x004001FCU, - 0x002001FEU, - 0x00000200U, - 0xFFE00202U, - 0xFFC00204U, - 0xFFC00206U, - 0xFFA00208U, - 0xFF80020AU, - 0xFF60020CU, - 0xFF60020EU, - 0xFF400210U, - 0xFF200212U, - 0xFF000214U, - 0xFF000216U, - 0xFEE00218U, - 0xFEC0021AU, - 0xFEA0021CU, - 0xFEA0021EU, - 0xFE800220U, - 0xFE600222U, - 0xFE400224U, - 0xFE200226U, - 0xFE200228U, - 0xFE000229U, - 0xFDE0022BU, - 0xFDC0022DU, - 0xFDC0022FU, - 0xFDA00231U, - 0xFD800233U, - 0xFD600235U, - 0xFD600237U, - 0xFD400239U, - 0xFD20023BU, - 0xFD00023DU, - 0xFCE0023FU, - 0xFCE00241U, - 0xFCC00243U, - 0xFCA00245U, - 0xFC800247U, - 0xFC800249U, - 0xFC60024BU, - 0xFC40024DU, - 0xFC20024FU, - 0xFC200251U, - 0xFC000253U, - 0xFBE00255U, - 0xFBC00257U, - 0xFBC00259U, - 0xFBA0025BU, - 0xFB80025DU, - 0xFB60025FU, - 0xFB400261U, - 0xFB400263U, - 0xFB200265U, - 0xFB000267U, - 0xFAE00269U, - 0xFAE0026BU, - 0xFAC0026DU, - 0xFAA0026FU, - 0xFA800271U, - 0xFA800273U, - 0xFA600275U, - 0xFA400277U, - 0xFA200279U, - 0xFA20027BU, - 0xFA00027CU, - 0xF9E0027EU, - 0xF9C00280U, - 0xF9A00282U, - 0xF9A00284U, - 0xF9800286U, - 0xF9600288U, - 0xF940028AU, - 0xF940028CU, - 0xF920028EU, - 0xF9000290U, - 0xF8E00292U, - 0xF8E00294U, - 0xF8C00296U, - 0xF8A00298U, - 0xF880029AU, - 0xF860029CU, - 0xF860029EU, - 0xF84002A0U, - 0xF82002A2U, - 0xF80002A4U, - 0xF80002A6U, - 0xF7E002A8U, - 0xF7C002AAU, - 0xF7A002ACU, - 0xF7A002AEU, - 0xF78002B0U, - 0xF76002B2U, - 0xF74002B4U, - 0xF74002B6U, - 0xF72002B8U, - 0xF70002BAU, - 0xF6E002BCU, - 0xF6C002BEU, - 0xF6C002C0U, - 0xF6A002C2U, - 0xF68002C4U, - 0xF66002C6U, - 0xF66002C8U, - 0xF64002CAU, - 0xF62002CCU, - 0xF60002CEU, - 0xF60002CFU, - 0xF5E002D1U, - 0xF5C002D3U, - 0xF5A002D5U, - 0xF5A002D7U, - 0xF58002D9U, - 0xF56002DBU, - 0xF54002DDU, - 0xF52002DFU, - 0xF52002E1U, - 0xF50002E3U, - 0xF4E002E5U, - 0xF4C002E7U, - 0xF4C002E9U, - 0xF4A002EBU, - 0xF48002EDU, - 0xF46002EFU, - 0xF46002F1U, - 0xF44002F3U, - 0xF42002F5U, - 0xF40002F7U, - 0xF3E002F9U, - 0xF3E002FBU, - /* v_table */ - 0x1A09A000U, - 0x19E9A800U, - 0x19A9B800U, - 0x1969C800U, - 0x1949D000U, - 0x1909E000U, - 0x18C9E800U, - 0x18A9F800U, - 0x186A0000U, - 0x182A1000U, - 0x180A2000U, - 0x17CA2800U, - 0x17AA3800U, - 0x176A4000U, - 0x172A5000U, - 0x170A6000U, - 0x16CA6800U, - 0x168A7800U, - 0x166A8000U, - 0x162A9000U, - 0x160AA000U, - 0x15CAA800U, - 0x158AB800U, - 0x156AC000U, - 0x152AD000U, - 0x14EAE000U, - 0x14CAE800U, - 0x148AF800U, - 0x146B0000U, - 0x142B1000U, - 0x13EB2000U, - 0x13CB2800U, - 0x138B3800U, - 0x134B4000U, - 0x132B5000U, - 0x12EB6000U, - 0x12CB6800U, - 0x128B7800U, - 0x124B8000U, - 0x122B9000U, - 0x11EBA000U, - 0x11ABA800U, - 0x118BB800U, - 0x114BC000U, - 0x112BD000U, - 0x10EBE000U, - 0x10ABE800U, - 0x108BF800U, - 0x104C0000U, - 0x100C1000U, - 0x0FEC2000U, - 0x0FAC2800U, - 0x0F8C3800U, - 0x0F4C4000U, - 0x0F0C5000U, - 0x0EEC5800U, - 0x0EAC6800U, - 0x0E6C7800U, - 0x0E4C8000U, - 0x0E0C9000U, - 0x0DEC9800U, - 0x0DACA800U, - 0x0D6CB800U, - 0x0D4CC000U, - 0x0D0CD000U, - 0x0CCCD800U, - 0x0CACE800U, - 0x0C6CF800U, - 0x0C4D0000U, - 0x0C0D1000U, - 0x0BCD1800U, - 0x0BAD2800U, - 0x0B6D3800U, - 0x0B2D4000U, - 0x0B0D5000U, - 0x0ACD5800U, - 0x0AAD6800U, - 0x0A6D7800U, - 0x0A2D8000U, - 0x0A0D9000U, - 0x09CD9800U, - 0x098DA800U, - 0x096DB800U, - 0x092DC000U, - 0x090DD000U, - 0x08CDD800U, - 0x088DE800U, - 0x086DF800U, - 0x082E0000U, - 0x07EE1000U, - 0x07CE1800U, - 0x078E2800U, - 0x076E3800U, - 0x072E4000U, - 0x06EE5000U, - 0x06CE5800U, - 0x068E6800U, - 0x064E7800U, - 0x062E8000U, - 0x05EE9000U, - 0x05CE9800U, - 0x058EA800U, - 0x054EB800U, - 0x052EC000U, - 0x04EED000U, - 0x04AED800U, - 0x048EE800U, - 0x044EF000U, - 0x042F0000U, - 0x03EF1000U, - 0x03AF1800U, - 0x038F2800U, - 0x034F3000U, - 0x030F4000U, - 0x02EF5000U, - 0x02AF5800U, - 0x028F6800U, - 0x024F7000U, - 0x020F8000U, - 0x01EF9000U, - 0x01AF9800U, - 0x016FA800U, - 0x014FB000U, - 0x010FC000U, - 0x00EFD000U, - 0x00AFD800U, - 0x006FE800U, - 0x004FF000U, - 0x00100000U, - 0xFFD01000U, - 0xFFB01800U, - 0xFF702800U, - 0xFF303000U, - 0xFF104000U, - 0xFED05000U, - 0xFEB05800U, - 0xFE706800U, - 0xFE307000U, - 0xFE108000U, - 0xFDD09000U, - 0xFD909800U, - 0xFD70A800U, - 0xFD30B000U, - 0xFD10C000U, - 0xFCD0D000U, - 0xFC90D800U, - 0xFC70E800U, - 0xFC30F000U, - 0xFBF10000U, - 0xFBD11000U, - 0xFB911800U, - 0xFB712800U, - 0xFB313000U, - 0xFAF14000U, - 0xFAD14800U, - 0xFA915800U, - 0xFA516800U, - 0xFA317000U, - 0xF9F18000U, - 0xF9D18800U, - 0xF9919800U, - 0xF951A800U, - 0xF931B000U, - 0xF8F1C000U, - 0xF8B1C800U, - 0xF891D800U, - 0xF851E800U, - 0xF831F000U, - 0xF7F20000U, - 0xF7B20800U, - 0xF7921800U, - 0xF7522800U, - 0xF7123000U, - 0xF6F24000U, - 0xF6B24800U, - 0xF6925800U, - 0xF6526800U, - 0xF6127000U, - 0xF5F28000U, - 0xF5B28800U, - 0xF5729800U, - 0xF552A800U, - 0xF512B000U, - 0xF4F2C000U, - 0xF4B2C800U, - 0xF472D800U, - 0xF452E800U, - 0xF412F000U, - 0xF3D30000U, - 0xF3B30800U, - 0xF3731800U, - 0xF3532800U, - 0xF3133000U, - 0xF2D34000U, - 0xF2B34800U, - 0xF2735800U, - 0xF2336800U, - 0xF2137000U, - 0xF1D38000U, - 0xF1B38800U, - 0xF1739800U, - 0xF133A800U, - 0xF113B000U, - 0xF0D3C000U, - 0xF093C800U, - 0xF073D800U, - 0xF033E000U, - 0xF013F000U, - 0xEFD40000U, - 0xEF940800U, - 0xEF741800U, - 0xEF342000U, - 0xEEF43000U, - 0xEED44000U, - 0xEE944800U, - 0xEE745800U, - 0xEE346000U, - 0xEDF47000U, - 0xEDD48000U, - 0xED948800U, - 0xED549800U, - 0xED34A000U, - 0xECF4B000U, - 0xECD4C000U, - 0xEC94C800U, - 0xEC54D800U, - 0xEC34E000U, - 0xEBF4F000U, - 0xEBB50000U, - 0xEB950800U, - 0xEB551800U, - 0xEB352000U, - 0xEAF53000U, - 0xEAB54000U, - 0xEA954800U, - 0xEA555800U, - 0xEA156000U, - 0xE9F57000U, - 0xE9B58000U, - 0xE9958800U, - 0xE9559800U, - 0xE915A000U, - 0xE8F5B000U, - 0xE8B5C000U, - 0xE875C800U, - 0xE855D800U, - 0xE815E000U, - 0xE7F5F000U, - 0xE7B60000U, - 0xE7760800U, - 0xE7561800U, - 0xE7162000U, - 0xE6D63000U, - 0xE6B64000U, - 0xE6764800U, - 0xE6365800U -}; - -#define FLAGS 0x40080100 -#define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)]) -#define READY(Y) tables[Y] -#define FIXUP(Y) \ -do { \ - int tmp = (Y) & FLAGS; \ - if (tmp != 0) \ - { \ - tmp -= tmp>>8; \ - (Y) |= tmp; \ - tmp = FLAGS & ~(Y>>1); \ - (Y) += tmp>>8; \ - } \ -} while (0 == 1) - -#define STORE(Y,DSTPTR) \ -do { \ - *(DSTPTR)++ = (Y); \ - *(DSTPTR)++ = (Y)>>22; \ - *(DSTPTR)++ = (Y)>>11; \ - *(DSTPTR)++ = 255; \ -} while (0 == 1) - -static void yuv422_2_rgb8888(uint8_t *dst_ptr, - const uint8_t *y_ptr, - const uint8_t *u_ptr, - const uint8_t *v_ptr, - int32_t width, - int32_t height, - int32_t y_span, - int32_t uv_span, - int32_t dst_span, - int32_t dither) -{ - height -= 1; - while (height > 0) - { - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do top row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - y1 = uv + READY(*y_ptr++); - FIXUP(y0); - FIXUP(y1); - STORE(y0, dst_ptr); - STORE(y1, dst_ptr); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing top row pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr,*v_ptr); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - } - dst_ptr += dst_span-width*4; - y_ptr += y_span-width; - u_ptr += uv_span-(width>>1); - v_ptr += uv_span-(width>>1); - height = (height<<16)>>16; - height -= 1; - if (height == 0) - break; - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do second row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - y1 = uv + READY(*y_ptr++); - FIXUP(y0); - FIXUP(y1); - STORE(y0, dst_ptr); - STORE(y1, dst_ptr); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing bottom row pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr,*v_ptr); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - } - dst_ptr += dst_span-width*4; - y_ptr += y_span-width; - u_ptr += uv_span-(width>>1); - v_ptr += uv_span-(width>>1); - height = (height<<16)>>16; - height -= 1; - } -} - - -#undef FLAGS -#undef READUV -#undef READY -#undef FIXUP -#undef STORE - - -#define FLAGS 0x40080100 -#define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)]) -#define READY(Y) tables[Y] -#define FIXUP(Y) \ -do { \ - int tmp = (Y) & FLAGS; \ - if (tmp != 0) \ - { \ - tmp -= tmp>>8; \ - (Y) |= tmp; \ - tmp = FLAGS & ~(Y>>1); \ - (Y) += tmp>>8; \ - } \ -} while (0 == 1) - -#define STORE(Y,DSTPTR) \ -do { \ - (DSTPTR) = 0xFF000000 | (Y & 0xFF) | (0xFF00 & (Y>>14)) | (0xFF0000 & (Y<<5));\ -} while (0 == 1) - -static void yuv420_2_rgb8888(uint8_t *dst_ptr_, - const uint8_t *y_ptr, - const uint8_t *u_ptr, - const uint8_t *v_ptr, - int32_t width, - int32_t height, - int32_t y_span, - int32_t uv_span, - int32_t dst_span, - int32_t dither) -{ - uint32_t *dst_ptr = (uint32_t *)(void *)dst_ptr_; - dst_span >>= 2; - - height -= 1; - while (height > 0) - { - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do 2 column pairs */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y1 = uv + READY(y_ptr[y_span]); - y0 = uv + READY(*y_ptr++); - FIXUP(y1); - FIXUP(y0); - STORE(y1, dst_ptr[dst_span]); - STORE(y0, *dst_ptr++); - y1 = uv + READY(y_ptr[y_span]); - y0 = uv + READY(*y_ptr++); - FIXUP(y1); - FIXUP(y0); - STORE(y1, dst_ptr[dst_span]); - STORE(y0, *dst_ptr++); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing column pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr,*v_ptr); - y1 = uv + READY(y_ptr[y_span]); - y0 = uv + READY(*y_ptr++); - FIXUP(y1); - FIXUP(y0); - STORE(y0, dst_ptr[dst_span]); - STORE(y1, *dst_ptr++); - } - dst_ptr += dst_span*2-width; - y_ptr += y_span*2-width; - u_ptr += uv_span-(width>>1); - v_ptr += uv_span-(width>>1); - height = (height<<16)>>16; - height -= 2; - } - if (height == 0) - { - /* Trail row */ - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do a row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y1 = uv + READY(*y_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y1); - FIXUP(y0); - STORE(y1, *dst_ptr++); - STORE(y0, *dst_ptr++); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, *dst_ptr++); - } - } -} - - - -#undef FLAGS -#undef READUV -#undef READY -#undef FIXUP -#undef STORE - -#define FLAGS 0x40080100 -#define READUV(U,V) (tables[256 + (U)] + tables[512 + (V)]) -#define READY(Y) tables[Y] -#define FIXUP(Y) \ -do { \ - int tmp = (Y) & FLAGS; \ - if (tmp != 0) \ - { \ - tmp -= tmp>>8; \ - (Y) |= tmp; \ - tmp = FLAGS & ~(Y>>1); \ - (Y) += tmp>>8; \ - } \ -} while (0 == 1) - -#define STORE(Y,DSTPTR) \ -do { \ - *(DSTPTR)++ = (Y); \ - *(DSTPTR)++ = (Y)>>22; \ - *(DSTPTR)++ = (Y)>>11; \ - *(DSTPTR)++ = 255; \ -} while (0 == 1) - -static void yuv444_2_rgb8888(uint8_t *dst_ptr, - const uint8_t *y_ptr, - const uint8_t *u_ptr, - const uint8_t *v_ptr, - int32_t width, - int32_t height, - int32_t y_span, - int32_t uv_span, - int32_t dst_span, - int32_t dither) -{ - height -= 1; - while (height > 0) - { - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do top row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - uv = READUV(*u_ptr++,*v_ptr++); - y1 = uv + READY(*y_ptr++); - FIXUP(y1); - STORE(y1, dst_ptr); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing top row pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - } - dst_ptr += dst_span-width*4; - y_ptr += y_span-width; - u_ptr += uv_span-width; - v_ptr += uv_span-width; - height = (height<<16)>>16; - height -= 1; - if (height == 0) - break; - height -= width<<16; - height += 1<<16; - while (height < 0) - { - /* Do second row pair */ - uint32_t uv, y0, y1; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - uv = READUV(*u_ptr++,*v_ptr++); - y1 = uv + READY(*y_ptr++); - FIXUP(y1); - STORE(y1, dst_ptr); - height += (2<<16); - } - if ((height>>16) == 0) - { - /* Trailing bottom row pix */ - uint32_t uv, y0; - - uv = READUV(*u_ptr++,*v_ptr++); - y0 = uv + READY(*y_ptr++); - FIXUP(y0); - STORE(y0, dst_ptr); - } - dst_ptr += dst_span-width*4; - y_ptr += y_span-width; - u_ptr += uv_span-width; - v_ptr += uv_span-width; - height = (height<<16)>>16; - height -= 1; - } -} -#endif // YUV2RGB_H diff --git a/modules/tinyexr/SCsub b/modules/tinyexr/SCsub new file mode 100644 index 0000000000..38fd00cc65 --- /dev/null +++ b/modules/tinyexr/SCsub @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_tinyexr = env_modules.Clone() + +# Thirdparty source files +# Not unbundled for now as they are not commonly available as shared library +thirdparty_dir = "#thirdparty/tinyexr/" +thirdparty_sources = [ + "tinyexr.cc", +] +thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + +env_tinyexr.add_source_files(env.modules_sources, thirdparty_sources) +env_tinyexr.Append(CPPPATH=[thirdparty_dir]) + +# Godot's own source files +env_tinyexr.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/tinyexr/config.py b/modules/tinyexr/config.py new file mode 100644 index 0000000000..fb920482f5 --- /dev/null +++ b/modules/tinyexr/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/tinyexr/image_loader_tinyexr.cpp b/modules/tinyexr/image_loader_tinyexr.cpp new file mode 100644 index 0000000000..4eb91da10b --- /dev/null +++ b/modules/tinyexr/image_loader_tinyexr.cpp @@ -0,0 +1,168 @@ +/*************************************************************************/ +/* image_loader_jpegd.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "image_loader_tinyexr.h" + +#include "os/os.h" +#include "print_string.h" + +#include "thirdparty/tinyexr/tinyexr.h" + +Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { + + PoolVector<uint8_t> src_image; + int src_image_len = f->get_len(); + ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); + src_image.resize(src_image_len); + + PoolVector<uint8_t>::Write w = src_image.write(); + + f->get_buffer(&w[0], src_image_len); + + f->close(); + + EXRVersion exr_version; + EXRImage exr_image; + EXRHeader exr_header; + const char *err = NULL; + + InitEXRHeader(&exr_header); + + int ret = ParseEXRVersionFromMemory(&exr_version, w.ptr(), src_image_len); + if (ret != TINYEXR_SUCCESS) { + + return ERR_FILE_CORRUPT; + } + + ret = ParseEXRHeaderFromMemory(&exr_header, &exr_version, w.ptr(), src_image_len, &err); + if (ret != TINYEXR_SUCCESS) { + if (err) { + ERR_PRINTS(String(err)); + } + return ERR_FILE_CORRUPT; + } + + InitEXRImage(&exr_image); + ret = LoadEXRImageFromMemory(&exr_image, &exr_header, w.ptr(), src_image_len, &err); + if (ret != TINYEXR_SUCCESS) { + if (err) { + ERR_PRINTS(String(err)); + } + return ERR_FILE_CORRUPT; + } + + // RGBA + int idxR = -1; + int idxG = -1; + int idxB = -1; + int idxA = -1; + for (int c = 0; c < exr_header.num_channels; c++) { + if (strcmp(exr_header.channels[c].name, "R") == 0) { + idxR = c; + } else if (strcmp(exr_header.channels[c].name, "G") == 0) { + idxG = c; + } else if (strcmp(exr_header.channels[c].name, "B") == 0) { + idxB = c; + } else if (strcmp(exr_header.channels[c].name, "A") == 0) { + idxA = c; + } + } + + if (idxR == -1) { + ERR_PRINT("R channel not found"); + // @todo { free exr_image } + return ERR_FILE_CORRUPT; + } + + if (idxG == -1) { + ERR_PRINT("G channel not found\n") + // @todo { free exr_image } + return ERR_FILE_CORRUPT; + } + + if (idxB == -1) { + ERR_PRINT("B channel not found\n") + // @todo { free exr_image } + return ERR_FILE_CORRUPT; + } + + PoolVector<uint8_t> imgdata; + Image::Format format; + + if (idxA > 0) { + + imgdata.resize(exr_image.width * exr_image.height * 8); //RGBA16 + format = Image::FORMAT_RGBAH; + } else { + + imgdata.resize(exr_image.width * exr_image.height * 6); //RGB16 + format = Image::FORMAT_RGBH; + } + + { + + PoolVector<uint8_t>::Write wd = imgdata.write(); + uint16_t *iw = (uint16_t *)wd.ptr(); + + // Assume `out_rgba` have enough memory allocated. + for (int i = 0; i < exr_image.width * exr_image.height; i++) { + + Color color( + reinterpret_cast<float **>(exr_image.images)[idxR][i], + reinterpret_cast<float **>(exr_image.images)[idxG][i], + reinterpret_cast<float **>(exr_image.images)[idxB][i]); + + if (p_force_linear) + color = color.to_linear(); + + *iw++ = Math::make_half_float(color.r); + *iw++ = Math::make_half_float(color.g); + *iw++ = Math::make_half_float(color.b); + + if (idxA > 0) { + *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxA][i]); + } + } + } + + print_line("EXR w: " + itos(exr_image.width) + " h:" + itos(exr_image.height) + " format " + Image::get_format_name(format)); + p_image->create(exr_image.width, exr_image.height, false, format, imgdata); + + w = PoolVector<uint8_t>::Write(); + + return OK; +} + +void ImageLoaderTinyEXR::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("exr"); +} + +ImageLoaderTinyEXR::ImageLoaderTinyEXR() { +} diff --git a/modules/tinyexr/image_loader_tinyexr.h b/modules/tinyexr/image_loader_tinyexr.h new file mode 100644 index 0000000000..a52894b12b --- /dev/null +++ b/modules/tinyexr/image_loader_tinyexr.h @@ -0,0 +1,46 @@ +/*************************************************************************/ +/* image_loader_jpegd.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef IMAGE_LOADER_TINYEXR_H +#define IMAGE_LOADER_TINYEXR_H + +#include "io/image_loader.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class ImageLoaderTinyEXR : public ImageFormatLoader { + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderTinyEXR(); +}; + +#endif diff --git a/modules/tinyexr/register_types.cpp b/modules/tinyexr/register_types.cpp new file mode 100644 index 0000000000..73f3131276 --- /dev/null +++ b/modules/tinyexr/register_types.cpp @@ -0,0 +1,45 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "register_types.h" + +#include "image_loader_tinyexr.h" + +static ImageLoaderTinyEXR *image_loader_tinyexr = NULL; + +void register_tinyexr_types() { + + image_loader_tinyexr = memnew(ImageLoaderTinyEXR); + ImageLoader::add_image_format_loader(image_loader_tinyexr); +} + +void unregister_tinyexr_types() { + + memdelete(image_loader_tinyexr); +} diff --git a/modules/tinyexr/register_types.h b/modules/tinyexr/register_types.h new file mode 100644 index 0000000000..f3c7372359 --- /dev/null +++ b/modules/tinyexr/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +void register_tinyexr_types(); +void unregister_tinyexr_types(); diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 4006ad3428..c0467a901b 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -88,7 +88,7 @@ void register_visual_script_types() { ClassDB::register_class<VisualScriptWhile>(); ClassDB::register_class<VisualScriptIterator>(); ClassDB::register_class<VisualScriptSequence>(); - ClassDB::register_class<VisualScriptInputFilter>(); + //ClassDB::register_class<VisualScriptInputFilter>(); ClassDB::register_class<VisualScriptSwitch>(); ClassDB::register_class<VisualScriptYield>(); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 53521c55a7..bb8111ce99 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -1073,6 +1073,18 @@ void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const { } } +int VisualScript::get_member_line(const StringName &p_member) const { +#ifdef TOOLS_ENABLED + if (has_function(p_member)) { + for (Map<int, Function::NodeData>::Element *E = functions[p_member].nodes.front(); E; E = E->next()) { + if (E->get().node->cast_to<VisualScriptFunction>()) + return E->key(); + } + } +#endif + return -1; +} + #ifdef TOOLS_ENABLED bool VisualScript::are_subnodes_edited() const { @@ -2357,6 +2369,17 @@ Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const script->set_instance_base_type(p_base_class_name); return script; } + +bool VisualScriptLanguage::is_using_templates() { + + return true; +} + +void VisualScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) { + Ref<VisualScript> script = p_script; + script->set_instance_base_type(p_base_class_name); +} + bool VisualScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const { return false; diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index ee8ed2c965..1ccc358342 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -89,13 +89,11 @@ public: struct TypeGuess { Variant::Type type; - InputEvent::Type ev_type; StringName GDCLASS; Ref<Script> script; TypeGuess() { type = Variant::NIL; - ev_type = InputEvent::NONE; } }; @@ -356,6 +354,8 @@ public: virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + virtual int get_member_line(const StringName &p_member) const; + #ifdef TOOLS_ENABLED virtual bool are_subnodes_edited() const; #endif @@ -564,6 +564,8 @@ public: virtual void get_comment_delimiters(List<String> *p_delimiters) const; virtual void get_string_delimiters(List<String> *p_delimiters) const; virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const; + virtual bool is_using_templates(); + virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script); virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL) const; virtual Script *create_script() const; virtual bool has_named_classes() const; diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 7247636920..941668d474 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -346,11 +346,9 @@ static Color _color_from_type(Variant::Type p_type) { case Variant::TRANSFORM: color = Color::html("f6a86e"); break; case Variant::COLOR: color = Color::html("9dff70"); break; - case Variant::IMAGE: color = Color::html("93f1b9"); break; case Variant::NODE_PATH: color = Color::html("6993ec"); break; case Variant::_RID: color = Color::html("69ec9a"); break; case Variant::OBJECT: color = Color::html("79f3e8"); break; - case Variant::INPUT_EVENT: color = Color::html("adf18f"); break; case Variant::DICTIONARY: color = Color::html("77edb1"); break; case Variant::ARRAY: color = Color::html("e0e0e0"); break; @@ -451,11 +449,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { Control::get_icon("MiniBasis", "EditorIcons"), Control::get_icon("MiniTransform", "EditorIcons"), Control::get_icon("MiniColor", "EditorIcons"), - Control::get_icon("MiniImage", "EditorIcons"), Control::get_icon("MiniPath", "EditorIcons"), Control::get_icon("MiniRid", "EditorIcons"), Control::get_icon("MiniObject", "EditorIcons"), - Control::get_icon("MiniInput", "EditorIcons"), Control::get_icon("MiniDictionary", "EditorIcons"), Control::get_icon("MiniArray", "EditorIcons"), Control::get_icon("MiniRawArray", "EditorIcons"), @@ -735,11 +731,9 @@ void VisualScriptEditor::_update_members() { Control::get_icon("MiniMatrix3", "EditorIcons"), Control::get_icon("MiniTransform", "EditorIcons"), Control::get_icon("MiniColor", "EditorIcons"), - Control::get_icon("MiniImage", "EditorIcons"), Control::get_icon("MiniPath", "EditorIcons"), Control::get_icon("MiniRid", "EditorIcons"), Control::get_icon("MiniObject", "EditorIcons"), - Control::get_icon("MiniInput", "EditorIcons"), Control::get_icon("MiniDictionary", "EditorIcons"), Control::get_icon("MiniArray", "EditorIcons"), Control::get_icon("MiniRawArray", "EditorIcons"), @@ -1017,7 +1011,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } Rect2 pos = members->get_item_rect(ti); - new_function_menu->set_position(members->get_global_position() + pos.pos + Vector2(0, pos.size.y)); + new_function_menu->set_position(members->get_global_position() + pos.position + Vector2(0, pos.size.y)); new_function_menu->popup(); return; } else if (p_button == 0) { @@ -1422,9 +1416,11 @@ void VisualScriptEditor::_on_nodes_duplicate() { } } -void VisualScriptEditor::_input(const InputEvent &p_event) { +void VisualScriptEditor::_input(const Ref<InputEvent> &p_event) { - if (p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) { + Ref<InputEventMouseButton> mb = p_event; + + if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { revert_on_drag = String(); //so we can still drag functions } } @@ -2153,7 +2149,7 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { _update_graph(); _update_members(); - call_deferred("_center_on_node", p_line); //editor might be just created and size might not exist yet + call_deferred("call_deferred", "_center_on_node", p_line); //editor might be just created and size might not exist yet return; } @@ -2163,6 +2159,12 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { void VisualScriptEditor::trim_trailing_whitespace() { } +void VisualScriptEditor::convert_indent_to_spaces() { +} + +void VisualScriptEditor::convert_indent_to_tabs() { +} + void VisualScriptEditor::ensure_focus() { graph->grab_focus(); @@ -2192,18 +2194,6 @@ void VisualScriptEditor::get_breakpoints(List<int> *p_breakpoints) { } } -bool VisualScriptEditor::goto_method(const String &p_method) { - - if (!script->has_function(p_method)) - return false; - - edited_func = p_method; - selected = edited_func; - _update_members(); - _update_graph(); - return true; -} - void VisualScriptEditor::add_callback(const String &p_function, PoolStringArray p_args) { if (script->has_function(p_function)) { @@ -2250,6 +2240,10 @@ void VisualScriptEditor::add_callback(const String &p_function, PoolStringArray //undo_redo->clear_history(); } +bool VisualScriptEditor::show_members_overview() { + return false; +} + void VisualScriptEditor::update_settings() { _update_graph(); @@ -2649,7 +2643,7 @@ void VisualScriptEditor::_port_action_menu(int p_option) { } else { n->set_call_mode(VisualScriptPropertySet::CALL_MODE_BASIC_TYPE); n->set_basic_type(tg.type); - new_connect_node_select->select_property_from_basic_type(tg.type, tg.ev_type); + new_connect_node_select->select_property_from_basic_type(tg.type); } } break; case CREATE_GET: { @@ -2679,7 +2673,7 @@ void VisualScriptEditor::_port_action_menu(int p_option) { } else { n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_BASIC_TYPE); n->set_basic_type(tg.type); - new_connect_node_select->select_property_from_basic_type(tg.type, tg.ev_type); + new_connect_node_select->select_property_from_basic_type(tg.type); } } break; diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 7322da5cfb..92f31f20da 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -196,7 +196,7 @@ class VisualScriptEditor : public ScriptEditorBase { String revert_on_drag; - void _input(const InputEvent &p_event); + void _input(const Ref<InputEvent> &p_event); void _on_nodes_delete(); void _on_nodes_duplicate(); @@ -240,13 +240,15 @@ public: virtual void set_edit_state(const Variant &p_state); virtual void goto_line(int p_line, bool p_with_error = false); virtual void trim_trailing_whitespace(); + virtual void convert_indent_to_spaces(); + virtual void convert_indent_to_tabs(); virtual void ensure_focus(); virtual void tag_saved_version(); virtual void reload(bool p_soft); virtual void get_breakpoints(List<int> *p_breakpoints); - virtual bool goto_method(const String &p_method); virtual void add_callback(const String &p_function, PoolStringArray p_args); virtual void update_settings(); + virtual bool show_members_overview(); virtual void set_debugger_active(bool p_active); virtual void set_tooltip_request_func(String p_method, Object *p_obj); virtual Control *get_edit_menu(); diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 2deb6064d3..07d69db207 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -734,6 +734,7 @@ VisualScriptSwitch::VisualScriptSwitch() { ////////////////EVENT ACTION FILTER/////////// ////////////////////////////////////////// +#if 0 int VisualScriptInputFilter::get_output_sequence_port_count() const { return filters.size(); @@ -758,86 +759,86 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const String text; switch (filters[p_port].type) { - case InputEvent::NONE: { + case Ref<InputEvent>::NONE: { text = "None"; } break; - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { InputEventKey k = filters[p_port].key; - if (k.scancode == 0 && k.unicode == 0) { + if (k->get_scancode() == 0 && k.unicode == 0) { text = "No Key"; } else { - if (k.scancode != 0) { - text = "KeyCode: " + keycode_get_string(k.scancode); + if (k->get_scancode() != 0) { + text = "KeyCode: " + keycode_get_string(k->get_scancode()); } else if (k.unicode != 0) { text = "Uniode: " + String::chr(k.unicode); } - if (k.pressed) + if (k->is_pressed()) text += ", Pressed"; else text += ", Released"; if (k.echo) text += ", Echo"; - if (k.mod.alt) + if (k->get_alt()) text = "Alt+" + text; - if (k.mod.shift) + if (k->get_shift()) text = "Shift+" + text; - if (k.mod.control) + if (k->get_control()) text = "Ctrl+" + text; - if (k.mod.meta) + if (k->get_metakey()) text = "Meta+" + text; } } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { InputEventMouseMotion mm = filters[p_port].mouse_motion; text = "Mouse Motion"; String b = "Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight"; for (int i = 0; i < 7; i++) { - if (mm.button_mask & (1 << i)) { + if (mm->get_button_mask() & (1 << i)) { text = b.get_slice(",", i) + "+" + text; } } - if (mm.mod.alt) + if (mm->get_alt()) text = "Alt+" + text; - if (mm.mod.shift) + if (mm->get_shift()) text = "Shift+" + text; - if (mm.mod.control) + if (mm->get_control()) text = "Ctrl+" + text; - if (mm.mod.meta) + if (mm->get_metakey()) text = "Meta+" + text; } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { InputEventMouseButton mb = filters[p_port].mouse_button; String b = "Any,Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight"; - text = b.get_slice(",", mb.button_index) + " Mouse Button"; + text = b.get_slice(",", mb->get_button_index()) + " Mouse Button"; - if (mb.pressed) + if (mb->is_pressed()) text += ", Pressed"; else text += ", Released"; if (mb.doubleclick) text += ", DblClick"; - if (mb.mod.alt) + if (mb->get_alt()) text = "Alt+" + text; - if (mb.mod.shift) + if (mb->get_shift()) text = "Shift+" + text; - if (mb.mod.control) + if (mb->get_control()) text = "Ctrl+" + text; - if (mb.mod.meta) + if (mb->get_metakey()) text = "Meta+" + text; } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { InputEventJoypadMotion jm = filters[p_port].joy_motion; @@ -848,29 +849,29 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const text += " < " + rtos(-jm.axis_value); } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { InputEventJoypadButton jb = filters[p_port].joy_button; - text = "JoyButton " + itos(jb.button_index); - if (jb.pressed) + text = "JoyButton " + itos(jb->get_button_index()); + if (jb->is_pressed()) text += ", Pressed"; else text += ", Released"; } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { InputEventScreenTouch sd = filters[p_port].screen_touch; text = "Touch Finger " + itos(sd.index); - if (sd.pressed) + if (sd->is_pressed()) text += ", Pressed"; else text += ", Released"; } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { InputEventScreenDrag sd = filters[p_port].screen_drag; text = "Drag Finger " + itos(sd.index); } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { List<PropertyInfo> pinfo; GlobalConfig::get_singleton()->get_property_list(&pinfo); @@ -890,7 +891,7 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const index++; } - if (filters[p_port].action.pressed) + if (filters[p_port].action->is_pressed()) text += ", Pressed"; else text += ", Released"; @@ -939,20 +940,20 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va String what = String(p_name).get_slice("/", 1); if (what == "type") { - filters[idx] = InputEvent(); - filters[idx].type = InputEvent::Type(int(p_value)); - if (filters[idx].type == InputEvent::JOYPAD_MOTION) { + filters[idx] = Ref<InputEvent>(); + filters[idx].type = Ref<InputEvent>::Type(int(p_value)); + if (filters[idx].type == Ref<InputEvent>::JOYPAD_MOTION) { filters[idx].joy_motion.axis_value = 0.5; //for treshold - } else if (filters[idx].type == InputEvent::KEY) { - filters[idx].key.pressed = true; //put these as true to make it more user friendly - } else if (filters[idx].type == InputEvent::MOUSE_BUTTON) { - filters[idx].mouse_button.pressed = true; - } else if (filters[idx].type == InputEvent::JOYPAD_BUTTON) { - filters[idx].joy_button.pressed = true; - } else if (filters[idx].type == InputEvent::SCREEN_TOUCH) { - filters[idx].screen_touch.pressed = true; - } else if (filters[idx].type == InputEvent::ACTION) { - filters[idx].action.pressed = true; + } else if (filters[idx].type == Ref<InputEvent>::KEY) { + filters[idx]->is_pressed() = true; //put these as true to make it more user friendly + } else if (filters[idx].type == Ref<InputEvent>::MOUSE_BUTTON) { + filters[idx]->is_pressed() = true; + } else if (filters[idx].type == Ref<InputEvent>::JOYPAD_BUTTON) { + filters[idx].joy_button->is_pressed() = true; + } else if (filters[idx].type == Ref<InputEvent>::SCREEN_TOUCH) { + filters[idx].screen_touch->is_pressed() = true; + } else if (filters[idx].type == Ref<InputEvent>::ACTION) { + filters[idx].action->is_pressed() = true; } _change_notify(); ports_changed_notify(); @@ -967,14 +968,14 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va switch (filters[idx].type) { - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { if (what == "scancode") { String sc = p_value; if (sc == String()) { - filters[idx].key.scancode = 0; + filters[idx]->get_scancode() = 0; } else { - filters[idx].key.scancode = find_keycode(p_value); + filters[idx]->get_scancode() = find_keycode(p_value); } } else if (what == "unicode") { @@ -989,22 +990,22 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va } else if (what == "pressed") { - filters[idx].key.pressed = p_value; + filters[idx]->is_pressed() = p_value; } else if (what == "echo") { - filters[idx].key.echo = p_value; + filters[idx]->is_echo() = p_value; } else if (what == "mod_alt") { - filters[idx].key.mod.alt = p_value; + filters[idx]->get_alt() = p_value; } else if (what == "mod_shift") { - filters[idx].key.mod.shift = p_value; + filters[idx]->get_shift() = p_value; } else if (what == "mod_ctrl") { - filters[idx].key.mod.control = p_value; + filters[idx]->get_control() = p_value; } else if (what == "mod_meta") { - filters[idx].key.mod.meta = p_value; + filters[idx]->get_metakey() = p_value; } else { return false; } @@ -1012,22 +1013,22 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { if (what == "button_mask") { - filters[idx].mouse_motion.button_mask = p_value; + filters[idx]->get_button_mask() = p_value; } else if (what == "mod_alt") { - filters[idx].mouse_motion.mod.alt = p_value; + filters[idx].mouse_motion->get_alt() = p_value; } else if (what == "mod_shift") { - filters[idx].mouse_motion.mod.shift = p_value; + filters[idx].mouse_motion->get_shift() = p_value; } else if (what == "mod_ctrl") { - filters[idx].mouse_motion.mod.control = p_value; + filters[idx].mouse_motion->get_control() = p_value; } else if (what == "mod_meta") { - filters[idx].mouse_motion.mod.meta = p_value; + filters[idx].mouse_motion->get_metakey() = p_value; } else { return false; } @@ -1036,26 +1037,26 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { if (what == "button_index") { - filters[idx].mouse_button.button_index = p_value; + filters[idx]->get_button_index() = p_value; } else if (what == "pressed") { - filters[idx].mouse_button.pressed = p_value; + filters[idx]->is_pressed() = p_value; } else if (what == "doubleclicked") { filters[idx].mouse_button.doubleclick = p_value; } else if (what == "mod_alt") { - filters[idx].mouse_button.mod.alt = p_value; + filters[idx].mouse_button->get_alt() = p_value; } else if (what == "mod_shift") { - filters[idx].mouse_button.mod.shift = p_value; + filters[idx].mouse_button->get_shift() = p_value; } else if (what == "mod_ctrl") { - filters[idx].mouse_button.mod.control = p_value; + filters[idx].mouse_button->get_control() = p_value; } else if (what == "mod_meta") { - filters[idx].mouse_button.mod.meta = p_value; + filters[idx].mouse_button->get_metakey() = p_value; } else { return false; } @@ -1063,7 +1064,7 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { if (what == "axis") { filters[idx].joy_motion.axis = int(p_value) << 1 | filters[idx].joy_motion.axis; @@ -1078,12 +1079,12 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { if (what == "button_index") { - filters[idx].joy_button.button_index = p_value; + filters[idx].joy_button->get_button_index() = p_value; } else if (what == "pressed") { - filters[idx].joy_button.pressed = p_value; + filters[idx].joy_button->is_pressed() = p_value; } else { return false; } @@ -1091,19 +1092,19 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va return true; } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { if (what == "finger_index") { filters[idx].screen_touch.index = p_value; } else if (what == "pressed") { - filters[idx].screen_touch.pressed = p_value; + filters[idx].screen_touch->is_pressed() = p_value; } else { return false; } ports_changed_notify(); return true; } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { if (what == "finger_index") { filters[idx].screen_drag.index = p_value; } else { @@ -1112,7 +1113,7 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va ports_changed_notify(); return true; } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { if (what == "action_name") { @@ -1144,7 +1145,7 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va } else if (what == "pressed") { - filters[idx].action.pressed = p_value; + filters[idx].action->is_pressed() = p_value; ports_changed_notify(); return true; } @@ -1181,14 +1182,14 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con switch (filters[idx].type) { - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { if (what == "scancode") { - if (filters[idx].key.scancode == 0) + if (filters[idx]->get_scancode() == 0) r_ret = String(); else { - r_ret = keycode_get_string(filters[idx].key.scancode); + r_ret = keycode_get_string(filters[idx]->get_scancode()); } } else if (what == "unicode") { @@ -1202,44 +1203,44 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con } else if (what == "pressed") { - r_ret = filters[idx].key.pressed; + r_ret = filters[idx]->is_pressed(); } else if (what == "echo") { - r_ret = filters[idx].key.echo; + r_ret = filters[idx]->is_echo(); } else if (what == "mod_alt") { - r_ret = filters[idx].key.mod.alt; + r_ret = filters[idx]->get_alt(); } else if (what == "mod_shift") { - r_ret = filters[idx].key.mod.shift; + r_ret = filters[idx]->get_shift(); } else if (what == "mod_ctrl") { - r_ret = filters[idx].key.mod.control; + r_ret = filters[idx]->get_control(); } else if (what == "mod_meta") { - r_ret = filters[idx].key.mod.meta; + r_ret = filters[idx]->get_metakey(); } else { return false; } return true; } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { if (what == "button_mask") { - r_ret = filters[idx].mouse_motion.button_mask; + r_ret = filters[idx]->get_button_mask(); } else if (what == "mod_alt") { - r_ret = filters[idx].mouse_motion.mod.alt; + r_ret = filters[idx].mouse_motion->get_alt(); } else if (what == "mod_shift") { - r_ret = filters[idx].mouse_motion.mod.shift; + r_ret = filters[idx].mouse_motion->get_shift(); } else if (what == "mod_ctrl") { - r_ret = filters[idx].mouse_motion.mod.control; + r_ret = filters[idx].mouse_motion->get_control(); } else if (what == "mod_meta") { - r_ret = filters[idx].mouse_motion.mod.meta; + r_ret = filters[idx].mouse_motion->get_metakey(); } else { return false; } @@ -1247,33 +1248,33 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con return true; } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { if (what == "button_index") { - r_ret = filters[idx].mouse_button.button_index; + r_ret = filters[idx]->get_button_index(); } else if (what == "pressed") { - r_ret = filters[idx].mouse_button.pressed; + r_ret = filters[idx]->is_pressed(); } else if (what == "doubleclicked") { r_ret = filters[idx].mouse_button.doubleclick; } else if (what == "mod_alt") { - r_ret = filters[idx].mouse_button.mod.alt; + r_ret = filters[idx].mouse_button->get_alt(); } else if (what == "mod_shift") { - r_ret = filters[idx].mouse_button.mod.shift; + r_ret = filters[idx].mouse_button->get_shift(); } else if (what == "mod_ctrl") { - r_ret = filters[idx].mouse_button.mod.control; + r_ret = filters[idx].mouse_button->get_control(); } else if (what == "mod_meta") { - r_ret = filters[idx].mouse_button.mod.meta; + r_ret = filters[idx].mouse_button->get_metakey(); } else { return false; } return true; } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { if (what == "axis_index") { r_ret = filters[idx].joy_motion.axis >> 1; @@ -1287,30 +1288,30 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con return true; } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { if (what == "button_index") { - r_ret = filters[idx].joy_button.button_index; + r_ret = filters[idx].joy_button->get_button_index(); } else if (what == "pressed") { - r_ret = filters[idx].joy_button.pressed; + r_ret = filters[idx].joy_button->is_pressed(); } else { return false; } return true; } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { if (what == "finger_index") { r_ret = filters[idx].screen_touch.index; } else if (what == "pressed") { - r_ret = filters[idx].screen_touch.pressed; + r_ret = filters[idx].screen_touch->is_pressed(); } else { return false; } return true; } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { if (what == "finger_index") { r_ret = filters[idx].screen_drag.index; } else { @@ -1318,7 +1319,7 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con } return true; } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { if (what == "action_name") { @@ -1344,7 +1345,7 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con } else if (what == "pressed") { - r_ret = filters[idx].action.pressed; + r_ret = filters[idx].action->is_pressed(); return true; } @@ -1354,7 +1355,7 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con return false; } -static const char *event_type_names[InputEvent::TYPE_MAX] = { +static const char *event_type_names[Ref<InputEvent>::TYPE_MAX] = { "None", "Key", "MouseMotion", @@ -1371,7 +1372,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::INT, "filter_count", PROPERTY_HINT_RANGE, "0,64")); String et; - for (int i = 0; i < InputEvent::TYPE_MAX; i++) { + for (int i = 0; i < Ref<InputEvent>::TYPE_MAX; i++) { if (i > 0) et += ","; @@ -1388,10 +1389,10 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::INT, base + "device")); switch (filters[i].type) { - case InputEvent::NONE: { + case Ref<InputEvent>::NONE: { } break; - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { if (kc == String()) { int kcc = keycode_get_count(); kc = "None"; @@ -1410,7 +1411,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta")); } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { p_list->push_back(PropertyInfo(Variant::INT, base + "button_mask", PROPERTY_HINT_FLAGS, "Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_alt")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_shift")); @@ -1418,7 +1419,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta")); } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { p_list->push_back(PropertyInfo(Variant::INT, base + "button_index", PROPERTY_HINT_ENUM, "Any,Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "doubleclicked")); @@ -1428,26 +1429,26 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta")); } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { p_list->push_back(PropertyInfo(Variant::INT, base + "axis_index")); p_list->push_back(PropertyInfo(Variant::INT, base + "mode", PROPERTY_HINT_ENUM, "Min,Max")); p_list->push_back(PropertyInfo(Variant::REAL, base + "treshold", PROPERTY_HINT_RANGE, "0,1,0.01")); } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { p_list->push_back(PropertyInfo(Variant::INT, base + "button_index")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed")); } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { p_list->push_back(PropertyInfo(Variant::INT, base + "finger_index")); p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed")); } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { p_list->push_back(PropertyInfo(Variant::INT, base + "finger_index")); } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { if (actions == String()) { @@ -1485,7 +1486,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con class VisualScriptNodeInstanceInputFilter : public VisualScriptNodeInstance { public: VisualScriptInstance *instance; - Vector<InputEvent> filters; + Vector<Ref<InputEvent>> filters; //virtual int get_working_memory_size() const { return 0; } //virtual bool is_output_port_unsequenced(int p_idx) const { return false; } @@ -1499,11 +1500,11 @@ public: return 0; } - InputEvent event = *p_inputs[0]; + Ref<InputEvent> event = *p_inputs[0]; for (int i = 0; i < filters.size(); i++) { - const InputEvent &ie = filters[i]; + const Ref<InputEvent> &ie = filters[i]; if (ie.type != event.type) continue; @@ -1511,25 +1512,25 @@ public: switch (ie.type) { - case InputEvent::NONE: { + case Ref<InputEvent>::NONE: { match = true; } break; - case InputEvent::KEY: { + case Ref<InputEvent>::KEY: { InputEventKey k = ie.key; InputEventKey k2 = event.key; - if (k.scancode == 0 && k.unicode == 0 && k2.scancode == 0 && k2.unicode == 0) { + if (k->get_scancode() == 0 && k.unicode == 0 && k2->get_scancode() == 0 && k2.unicode == 0) { match = true; } else { - if ((k.scancode != 0 && k.scancode == k2.scancode) || (k.unicode != 0 && k.unicode == k2.unicode)) { + if ((k->get_scancode() != 0 && k->get_scancode() == k2->get_scancode()) || (k.unicode != 0 && k.unicode == k2.unicode)) { //key valid if ( - k.pressed == k2.pressed && + k->is_pressed() == k2->is_pressed() && k.echo == k2.echo && k.mod == k2.mod) { match = true; @@ -1538,30 +1539,30 @@ public: } } break; - case InputEvent::MOUSE_MOTION: { + case Ref<InputEvent>::MOUSE_MOTION: { InputEventMouseMotion mm = ie.mouse_motion; InputEventMouseMotion mm2 = event.mouse_motion; - if (mm.button_mask == mm2.button_mask && + if (mm->get_button_mask() == mm2->get_button_mask() && mm.mod == mm2.mod) { match = true; } } break; - case InputEvent::MOUSE_BUTTON: { + case Ref<InputEvent>::MOUSE_BUTTON: { InputEventMouseButton mb = ie.mouse_button; InputEventMouseButton mb2 = event.mouse_button; - if (mb.button_index == mb2.button_index && - mb.pressed == mb2.pressed && + if (mb->get_button_index() == mb2->get_button_index() && + mb->is_pressed() == mb2->is_pressed() && mb.doubleclick == mb2.doubleclick && mb.mod == mb2.mod) { match = true; } } break; - case InputEvent::JOYPAD_MOTION: { + case Ref<InputEvent>::JOYPAD_MOTION: { InputEventJoypadMotion jm = ie.joy_motion; InputEventJoypadMotion jm2 = event.joy_motion; @@ -1584,26 +1585,26 @@ public: } } break; - case InputEvent::JOYPAD_BUTTON: { + case Ref<InputEvent>::JOYPAD_BUTTON: { InputEventJoypadButton jb = ie.joy_button; InputEventJoypadButton jb2 = event.joy_button; - if (jb.button_index == jb2.button_index && - jb.pressed == jb2.pressed) { + if (jb->get_button_index() == jb2->get_button_index() && + jb->is_pressed() == jb2->is_pressed()) { match = true; } } break; - case InputEvent::SCREEN_TOUCH: { + case Ref<InputEvent>::SCREEN_TOUCH: { InputEventScreenTouch st = ie.screen_touch; InputEventScreenTouch st2 = event.screen_touch; if (st.index == st2.index && - st.pressed == st2.pressed) { + st->is_pressed() == st2->is_pressed()) { match = true; } } break; - case InputEvent::SCREEN_DRAG: { + case Ref<InputEvent>::SCREEN_DRAG: { InputEventScreenDrag sd = ie.screen_drag; InputEventScreenDrag sd2 = event.screen_drag; @@ -1611,13 +1612,13 @@ public: match = true; } } break; - case InputEvent::ACTION: { + case Ref<InputEvent>::ACTION: { InputEventAction ia = ie.action; InputEventAction ia2 = event.action; if (ia.action == ia2.action && - ia.pressed == ia2.pressed) { + ia->is_pressed() == ia2->is_pressed()) { match = true; } } break; @@ -1643,7 +1644,7 @@ VisualScriptNodeInstance *VisualScriptInputFilter::instance(VisualScriptInstance VisualScriptInputFilter::VisualScriptInputFilter() { } - +#endif ////////////////////////////////////////// ////////////////TYPE CAST/////////// ////////////////////////////////////////// @@ -1832,6 +1833,6 @@ void register_visual_script_flow_control_nodes() { VisualScriptLanguage::singleton->add_register_func("flow_control/iterator", create_node_generic<VisualScriptIterator>); VisualScriptLanguage::singleton->add_register_func("flow_control/sequence", create_node_generic<VisualScriptSequence>); VisualScriptLanguage::singleton->add_register_func("flow_control/switch", create_node_generic<VisualScriptSwitch>); - VisualScriptLanguage::singleton->add_register_func("flow_control/input_filter", create_node_generic<VisualScriptInputFilter>); + //VisualScriptLanguage::singleton->add_register_func("flow_control/input_filter", create_node_generic<VisualScriptInputFilter>); VisualScriptLanguage::singleton->add_register_func("flow_control/type_cast", create_node_generic<VisualScriptTypeCast>); } diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index e3936da9e5..314804602e 100644 --- a/modules/visual_script/visual_script_flow_control.h +++ b/modules/visual_script/visual_script_flow_control.h @@ -228,11 +228,12 @@ public: VisualScriptSwitch(); }; +#if 0 class VisualScriptInputFilter : public VisualScriptNode { GDCLASS(VisualScriptInputFilter, VisualScriptNode) - Vector<InputEvent> filters; + Vector<Ref<InputEvent>> filters; protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -259,7 +260,7 @@ public: VisualScriptInputFilter(); }; - +#endif class VisualScriptTypeCast : public VisualScriptNode { GDCLASS(VisualScriptTypeCast, VisualScriptNode) diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 84224dfcbe..b466e64aec 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -943,18 +943,6 @@ static Ref<VisualScriptNode> create_function_call_node(const String &p_name) { ////////////////SET////////////////////// ////////////////////////////////////////// -static const char *event_type_names[InputEvent::TYPE_MAX] = { - "None", - "Key", - "MouseMotion", - "MouseButton", - "JoypadMotion", - "JoypadButton", - "ScreenTouch", - "ScreenDrag", - "Action" -}; - int VisualScriptPropertySet::get_output_sequence_port_count() const { return call_mode != CALL_MODE_BASIC_TYPE ? 1 : 0; @@ -1119,24 +1107,6 @@ Variant::Type VisualScriptPropertySet::get_basic_type() const { return basic_type; } -void VisualScriptPropertySet::set_event_type(InputEvent::Type p_type) { - - if (event_type == p_type) - return; - event_type = p_type; - if (call_mode == CALL_MODE_BASIC_TYPE) { - _update_cache(); - } - _change_notify(); - _update_base_type(); - ports_changed_notify(); -} - -InputEvent::Type VisualScriptPropertySet::get_event_type() const { - - return event_type; -} - void VisualScriptPropertySet::set_base_type(const StringName &p_type) { if (base_type == p_type) @@ -1182,14 +1152,8 @@ void VisualScriptPropertySet::_update_cache() { //not super efficient.. Variant v; - if (basic_type == Variant::INPUT_EVENT) { - InputEvent ev; - ev.type = event_type; - v = ev; - } else { - Variant::CallError ce; - v = Variant::construct(basic_type, NULL, 0, ce); - } + Variant::CallError ce; + v = Variant::construct(basic_type, NULL, 0, ce); List<PropertyInfo> pinfo; v.get_property_list(&pinfo); @@ -1341,12 +1305,6 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { } } - if (property.name == "property/event_type") { - if (call_mode != CALL_MODE_BASIC_TYPE || basic_type != Variant::INPUT_EVENT) { - property.usage = 0; - } - } - if (property.name == "property/node_path") { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; @@ -1418,9 +1376,6 @@ void VisualScriptPropertySet::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_type_cache", "type_cache"), &VisualScriptPropertySet::_set_type_cache); ClassDB::bind_method(D_METHOD("_get_type_cache"), &VisualScriptPropertySet::_get_type_cache); - ClassDB::bind_method(D_METHOD("set_event_type", "event_type"), &VisualScriptPropertySet::set_event_type); - ClassDB::bind_method(D_METHOD("get_event_type"), &VisualScriptPropertySet::get_event_type); - ClassDB::bind_method(D_METHOD("set_property", "property"), &VisualScriptPropertySet::set_property); ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertySet::get_property); @@ -1438,14 +1393,6 @@ void VisualScriptPropertySet::_bind_methods() { bt += Variant::get_type_name(Variant::Type(i)); } - String et; - for (int i = 0; i < InputEvent::TYPE_MAX; i++) { - if (i > 0) - et += ","; - - et += event_type_names[i]; - } - List<String> script_extensions; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions); @@ -1463,7 +1410,6 @@ void VisualScriptPropertySet::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); ADD_PROPERTY(PropertyInfo(Variant::INT, "property/type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache"); ADD_PROPERTY(PropertyInfo(Variant::INT, "property/basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/event_type", PROPERTY_HINT_ENUM, et), "set_event_type", "get_event_type"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "property/node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/property"), "set_property", "get_property"); @@ -1574,7 +1520,6 @@ VisualScriptPropertySet::VisualScriptPropertySet() { call_mode = CALL_MODE_SELF; base_type = "Object"; basic_type = Variant::NIL; - event_type = InputEvent::NONE; } template <VisualScriptPropertySet::CallMode cmode> @@ -1764,14 +1709,8 @@ void VisualScriptPropertyGet::_update_cache() { //not super efficient.. Variant v; - if (basic_type == Variant::INPUT_EVENT) { - InputEvent ev; - ev.type = event_type; - v = ev; - } else { - Variant::CallError ce; - v = Variant::construct(basic_type, NULL, 0, ce); - } + Variant::CallError ce; + v = Variant::construct(basic_type, NULL, 0, ce); List<PropertyInfo> pinfo; v.get_property_list(&pinfo); @@ -1919,24 +1858,6 @@ Variant::Type VisualScriptPropertyGet::get_basic_type() const { return basic_type; } -void VisualScriptPropertyGet::set_event_type(InputEvent::Type p_type) { - - if (event_type == p_type) - return; - event_type = p_type; - if (call_mode == CALL_MODE_BASIC_TYPE) { - _update_cache(); - } - _change_notify(); - _update_base_type(); - ports_changed_notify(); -} - -InputEvent::Type VisualScriptPropertyGet::get_event_type() const { - - return event_type; -} - void VisualScriptPropertyGet::_set_type_cache(Variant::Type p_type) { type_cache = p_type; } @@ -1965,11 +1886,6 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { property.usage = 0; } } - if (property.name == "property/event_type") { - if (call_mode != CALL_MODE_BASIC_TYPE || basic_type != Variant::INPUT_EVENT) { - property.usage = 0; - } - } if (property.name == "property/node_path") { if (call_mode != CALL_MODE_NODE_PATH) { @@ -2041,9 +1957,6 @@ void VisualScriptPropertyGet::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_type_cache", "type_cache"), &VisualScriptPropertyGet::_set_type_cache); ClassDB::bind_method(D_METHOD("_get_type_cache"), &VisualScriptPropertyGet::_get_type_cache); - ClassDB::bind_method(D_METHOD("set_event_type", "event_type"), &VisualScriptPropertyGet::set_event_type); - ClassDB::bind_method(D_METHOD("get_event_type"), &VisualScriptPropertyGet::get_event_type); - ClassDB::bind_method(D_METHOD("set_property", "property"), &VisualScriptPropertyGet::set_property); ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertyGet::get_property); @@ -2061,14 +1974,6 @@ void VisualScriptPropertyGet::_bind_methods() { bt += Variant::get_type_name(Variant::Type(i)); } - String et; - for (int i = 0; i < InputEvent::TYPE_MAX; i++) { - if (i > 0) - et += ","; - - et += event_type_names[i]; - } - List<String> script_extensions; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions); @@ -2086,7 +1991,6 @@ void VisualScriptPropertyGet::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script"); ADD_PROPERTY(PropertyInfo(Variant::INT, "property/type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache"); ADD_PROPERTY(PropertyInfo(Variant::INT, "property/basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "property/event_type", PROPERTY_HINT_ENUM, et), "set_event_type", "get_event_type"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "property/node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/property"), "set_property", "get_property"); @@ -2184,7 +2088,6 @@ VisualScriptPropertyGet::VisualScriptPropertyGet() { call_mode = CALL_MODE_SELF; base_type = "Object"; basic_type = Variant::NIL; - event_type = InputEvent::NONE; type_cache = Variant::NIL; } diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index b56a3c2bcc..3b284952c5 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -155,7 +155,6 @@ private: String base_script; NodePath base_path; StringName property; - InputEvent::Type event_type; Node *_get_base_node() const; StringName _get_base_type() const; @@ -197,9 +196,6 @@ public: void set_basic_type(Variant::Type p_type); Variant::Type get_basic_type() const; - void set_event_type(InputEvent::Type p_type); - InputEvent::Type get_event_type() const; - void set_property(const StringName &p_type); StringName get_property() const; @@ -238,7 +234,6 @@ private: String base_script; NodePath base_path; StringName property; - InputEvent::Type event_type; void _update_base_type(); Node *_get_base_node() const; @@ -279,9 +274,6 @@ public: void set_basic_type(Variant::Type p_type); Variant::Type get_basic_type() const; - void set_event_type(InputEvent::Type p_type); - InputEvent::Type get_event_type() const; - void set_property(const StringName &p_type); StringName get_property() const; diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 08f4191d3d..8ea3b8098d 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -3460,14 +3460,8 @@ void VisualScriptDeconstruct::_update_elements() { elements.clear(); Variant v; - if (type == Variant::INPUT_EVENT) { - InputEvent ie; - ie.type = input_type; - v = ie; - } else { - Variant::CallError ce; - v = Variant::construct(type, NULL, 0, ce); - } + Variant::CallError ce; + v = Variant::construct(type, NULL, 0, ce); List<PropertyInfo> pinfo; v.get_property_list(&pinfo); @@ -3497,21 +3491,6 @@ Variant::Type VisualScriptDeconstruct::get_deconstruct_type() const { return type; } -void VisualScriptDeconstruct::set_deconstruct_input_type(InputEvent::Type p_input_type) { - - if (input_type == p_input_type) - return; - - input_type = p_input_type; - _update_elements(); - ports_changed_notify(); -} - -InputEvent::Type VisualScriptDeconstruct::get_deconstruct_input_type() const { - - return input_type; -} - void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) { ERR_FAIL_COND(p_elements.size() % 2 == 1); @@ -3570,12 +3549,6 @@ VisualScriptNodeInstance *VisualScriptDeconstruct::instance(VisualScriptInstance } void VisualScriptDeconstruct::_validate_property(PropertyInfo &property) const { - - if (property.name == "input_type") { - if (type != Variant::INPUT_EVENT) { - property.usage = 0; - } - } } void VisualScriptDeconstruct::_bind_methods() { @@ -3583,9 +3556,6 @@ void VisualScriptDeconstruct::_bind_methods() { ClassDB::bind_method(D_METHOD("set_deconstruct_type", "type"), &VisualScriptDeconstruct::set_deconstruct_type); ClassDB::bind_method(D_METHOD("get_deconstruct_type"), &VisualScriptDeconstruct::get_deconstruct_type); - ClassDB::bind_method(D_METHOD("set_deconstruct_input_type", "input_type"), &VisualScriptDeconstruct::set_deconstruct_input_type); - ClassDB::bind_method(D_METHOD("get_deconstruct_input_type"), &VisualScriptDeconstruct::get_deconstruct_input_type); - ClassDB::bind_method(D_METHOD("_set_elem_cache", "_cache"), &VisualScriptDeconstruct::_set_elem_cache); ClassDB::bind_method(D_METHOD("_get_elem_cache"), &VisualScriptDeconstruct::_get_elem_cache); @@ -3594,17 +3564,13 @@ void VisualScriptDeconstruct::_bind_methods() { argt += "," + Variant::get_type_name(Variant::Type(i)); } - String iet = "None,Key,MouseMotion,MouseButton,JoypadMotion,JoypadButton,ScreenTouch,ScreenDrag,Action"; - ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_deconstruct_type", "get_deconstruct_type"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "input_type", PROPERTY_HINT_ENUM, iet), "set_deconstruct_input_type", "get_deconstruct_input_type"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "elem_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_elem_cache", "_get_elem_cache"); } VisualScriptDeconstruct::VisualScriptDeconstruct() { type = Variant::NIL; - input_type = InputEvent::NONE; } void register_visual_script_nodes() { diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index c0933d1a78..402093fa80 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -923,7 +923,6 @@ class VisualScriptDeconstruct : public VisualScriptNode { void _update_elements(); Variant::Type type; - InputEvent::Type input_type; void _set_elem_cache(const Array &p_elements); Array _get_elem_cache() const; @@ -952,9 +951,6 @@ public: void set_deconstruct_type(Variant::Type p_type); Variant::Type get_deconstruct_type() const; - void set_deconstruct_input_type(InputEvent::Type p_input_type); - InputEvent::Type get_deconstruct_input_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); VisualScriptDeconstruct(); diff --git a/modules/webm/libvpx/SCsub b/modules/webm/libvpx/SCsub index 241d6e30cd..0ee2ed45b8 100644 --- a/modules/webm/libvpx/SCsub +++ b/modules/webm/libvpx/SCsub @@ -273,7 +273,7 @@ else: webm_cpu_x86 = True else: webm_cpu_x86 = not is_x11_or_server_arm and (cpu_bits == '32' or cpu_bits == '64') and (env["platform"] == 'windows' or env["platform"] == 'x11' or env["platform"] == 'osx' or env["platform"] == 'haiku' or is_android_x86 or is_ios_x86) - webm_cpu_arm = is_x11_or_server_arm or (not is_ios_x86 and env["platform"] == 'iphone') or env["platform"] == 'bb10' or (not is_android_x86 and env["platform"] == 'android') + webm_cpu_arm = is_x11_or_server_arm or (not is_ios_x86 and env["platform"] == 'iphone') or (not is_android_x86 and env["platform"] == 'android') if webm_cpu_x86: import subprocess diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index 9d8062d283..eaf4215302 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -32,12 +32,13 @@ #include "OpusVorbisDecoder.hpp" #include "VPXDecoder.hpp" -#include "../theora/yuv2rgb.h" #include "mkvparser/mkvparser.h" #include "global_config.h" #include "os/file_access.h" +#include "thirdparty/misc/yuv2rgb.h" + #include <string.h> class MkvReader : public mkvparser::IMkvReader { diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp index 39c8f812ac..87c2e811b3 100644 --- a/modules/webp/image_loader_webp.cpp +++ b/modules/webp/image_loader_webp.cpp @@ -37,23 +37,23 @@ #include <webp/decode.h> #include <webp/encode.h> -static PoolVector<uint8_t> _webp_lossy_pack(const Image &p_image, float p_quality) { +static PoolVector<uint8_t> _webp_lossy_pack(const Ref<Image> &p_image, float p_quality) { - ERR_FAIL_COND_V(p_image.empty(), PoolVector<uint8_t>()); + ERR_FAIL_COND_V(p_image.is_null() || p_image->empty(), PoolVector<uint8_t>()); - Image img = p_image; - if (img.detect_alpha()) - img.convert(Image::FORMAT_RGBA8); + Ref<Image> img = p_image->duplicate(); + if (img->detect_alpha()) + img->convert(Image::FORMAT_RGBA8); else - img.convert(Image::FORMAT_RGB8); + img->convert(Image::FORMAT_RGB8); - Size2 s(img.get_width(), img.get_height()); - PoolVector<uint8_t> data = img.get_data(); + Size2 s(img->get_width(), img->get_height()); + PoolVector<uint8_t> data = img->get_data(); PoolVector<uint8_t>::Read r = data.read(); uint8_t *dst_buff = NULL; size_t dst_size = 0; - if (img.get_format() == Image::FORMAT_RGB8) { + if (img->get_format() == Image::FORMAT_RGB8) { dst_size = WebPEncodeRGB(r.ptr(), s.width, s.height, 3 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff); } else { @@ -74,22 +74,24 @@ static PoolVector<uint8_t> _webp_lossy_pack(const Image &p_image, float p_qualit return dst; } -static Image _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { +static Ref<Image> _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { int size = p_buffer.size() - 4; - ERR_FAIL_COND_V(size <= 0, Image()); + ERR_FAIL_COND_V(size <= 0, Ref<Image>()); PoolVector<uint8_t>::Read r = p_buffer.read(); - ERR_FAIL_COND_V(r[0] != 'W' || r[1] != 'E' || r[2] != 'B' || r[3] != 'P', Image()); + ERR_FAIL_COND_V(r[0] != 'W' || r[1] != 'E' || r[2] != 'B' || r[3] != 'P', Ref<Image>()); WebPBitstreamFeatures features; if (WebPGetFeatures(&r[4], size, &features) != VP8_STATUS_OK) { ERR_EXPLAIN("Error unpacking WEBP image:"); - ERR_FAIL_V(Image()); + ERR_FAIL_V(Ref<Image>()); } - //print_line("width: "+itos(features.width)); - //print_line("height: "+itos(features.height)); - //print_line("alpha: "+itos(features.has_alpha)); + /* + print_line("width: "+itos(features.width)); + print_line("height: "+itos(features.height)); + print_line("alpha: "+itos(features.has_alpha)); + */ PoolVector<uint8_t> dst_image; int datasize = features.width * features.height * (features.has_alpha ? 4 : 3); @@ -105,14 +107,15 @@ static Image _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { } //ERR_EXPLAIN("Error decoding webp! - "+p_file); - ERR_FAIL_COND_V(errdec, Image()); + ERR_FAIL_COND_V(errdec, Ref<Image>()); dst_w = PoolVector<uint8_t>::Write(); - return Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image); + Ref<Image> img = memnew(Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image)); + return img; } -Error ImageLoaderWEBP::load_image(Image *p_image, FileAccess *f) { +Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { uint32_t size = f->get_len(); PoolVector<uint8_t> src_image; @@ -130,9 +133,11 @@ Error ImageLoaderWEBP::load_image(Image *p_image, FileAccess *f) { ERR_FAIL_V(ERR_FILE_CORRUPT); } + /* print_line("width: " + itos(features.width)); print_line("height: " + itos(features.height)); print_line("alpha: " + itos(features.has_alpha)); + */ src_w = PoolVector<uint8_t>::Write(); @@ -156,7 +161,7 @@ Error ImageLoaderWEBP::load_image(Image *p_image, FileAccess *f) { src_r = PoolVector<uint8_t>::Read(); dst_w = PoolVector<uint8_t>::Write(); - *p_image = Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image); + p_image->create(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image); return OK; } diff --git a/modules/webp/image_loader_webp.h b/modules/webp/image_loader_webp.h index 2d0ac796d3..1ac2196a71 100644 --- a/modules/webp/image_loader_webp.h +++ b/modules/webp/image_loader_webp.h @@ -38,7 +38,7 @@ class ImageLoaderWEBP : public ImageFormatLoader { public: - virtual Error load_image(Image *p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderWEBP(); }; |