diff options
Diffstat (limited to 'modules')
23 files changed, 308 insertions, 220 deletions
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 c04528d2a0..c04528d2a0 100644 --- a/modules/etc1/texture_loader_pkm.cpp +++ b/modules/etc/texture_loader_pkm.cpp 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 121f50684d..0000000000 --- a/modules/etc1/image_etc.cpp +++ /dev/null @@ -1,183 +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())); - bool needs_mipmaps = p_img->has_mipmaps(); - p_img->create(p_img->get_width(), p_img->get_height(), p_img->has_mipmaps(), Image::FORMAT_RGB8, dst); - if (needs_mipmaps) - p_img->generate_mipmaps(); -} - -static void _compress_etc(Image *p_img) { - - Ref<Image> img = p_img->duplicate(); - - 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->create(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 9c8625c1e0..706b81f7a3 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -516,9 +516,9 @@ static const char *_dl_platforms_info[] = { "unix|server|so|Server", "unix|android|so|Android", "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", diff --git a/modules/gdnative/godot.h b/modules/gdnative/godot.h index 726bde0b65..1d86998291 100644 --- a/modules/gdnative/godot.h +++ b/modules/gdnative/godot.h @@ -60,6 +60,13 @@ extern "C" { #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> #include <stdint.h> diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index eea5b15236..5e3ce31dd6 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -69,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; diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index dcc0e24098..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); diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 00ae136790..ebef4fed74 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -381,6 +381,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/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index 32772e0cd2..efce76c805 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -80,7 +80,7 @@ void image_decompress_squish(Image *p_image) { 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, bool p_srgb) { +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 @@ -97,11 +97,16 @@ void image_compress_squish(Image *p_image, bool p_srgb) { p_image->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert - if (p_srgb && (dc == Image::DETECTED_R || dc == Image::DETECTED_RG)) { + 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; } + if (p_source == Image::COMPRESS_SOURCE_NORMAL) { + //R and RG do not support SRGB + dc = Image::DETECTED_RG; + } + switch (dc) { case Image::DETECTED_L: { diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h index 8d859b8e0b..68aaeefc30 100644 --- a/modules/squish/image_compress_squish.h +++ b/modules/squish/image_compress_squish.h @@ -32,7 +32,7 @@ #include "image.h" -void image_compress_squish(Image *p_image, bool p_srgb); +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/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index 287aa4ca47..46cdfd3f2d 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -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/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index aec60391d3..bb8111ce99 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -2369,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 72843099c7..1ccc358342 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -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; |