diff options
230 files changed, 5117 insertions, 5169 deletions
@@ -24,7 +24,9 @@ Chris Bradfield <chris@kidscancode.org> <cb@scribe.net> Clay John <claynjohn@gmail.com> Clay John <claynjohn@gmail.com> <clayjohn@shaw.ca> Dana Olson <dana@shineuponthee.com> <adolson@gmail.com> +dankan1890 <mewuidev2@gmail.com> Daniel J. Ramirez <djrmuv@gmail.com> +Emmanuel Barroga <emmanuelbarroga@gmail.com> Erik Selecký <35656626+rxlecky@users.noreply.github.com> Erik Selecký <35656626+rxlecky@users.noreply.github.com> <35656626+SeleckyErik@users.noreply.github.com> Fabian <supagu@gmail.com> diff --git a/.travis.yml b/.travis.yml index 80191423c1..25b7795e13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -117,6 +117,16 @@ matrix: packages: - *linux_deps + - name: Javascript export template (release, emscripten latest) + stage: build + env: PLATFORM=javascript TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-emcc-latest EXTRA_ARGS="use_closure_compiler=yes" + os: linux + compiler: clang + addons: + apt: + packages: + - *linux_deps + before_install: - eval "${MATRIX_EVAL}" - if [ "$STATIC_CHECKS" = "yes" ]; then @@ -135,6 +145,11 @@ install: java -version; misc/travis/android-tools-linux.sh; fi + - if [ "$PLATFORM" = "javascript" ]; then + git clone --depth 1 "https://github.com/emscripten-core/emsdk.git"; + ./emsdk/emsdk install latest; + ./emsdk/emsdk activate latest; + fi before_script: - if [ "$PLATFORM" = "android" ]; then diff --git a/AUTHORS.md b/AUTHORS.md index 8be2d05455..a3269a73f7 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -124,6 +124,7 @@ name is available. Michael Alexsander (YeldhamDev) MichiRecRoom (LikeLakers2) mrezai + muiroc Nathan Warden (NathanWarden) Nils André-Chang (NilsIrl) Nuno Donato (nunodonato) @@ -28,8 +28,11 @@ generous deed immortalized in the next stable release of Godot Engine. Andres Hernandez Andrew Dunai Brandon Lamb + Christian Baune Christopher Montesano Darkhan Baimyrza + Darrin Massena + Dov Zimring Edward Flick Gamechuck GameDev.net @@ -42,13 +45,12 @@ generous deed immortalized in the next stable release of Godot Engine. Justin Arnold Justo Delgado Baudí Kyle Szklenski - Leonard Meagher - Mariano Suligoy Matthieu Huvé Maxim Karsten Mike King Nathan Warden Neal Gompa (Conan Kudo) + Péter Magyar Slobodan Milnovic Stephan Lanfermann Steve @@ -77,32 +79,31 @@ generous deed immortalized in the next stable release of Godot Engine. Austen McRae Bernhard Werner beVR - Brian van der Stel Carlo Cabanilla Daniel James David Giardi Default Name + eggs + Felix Bohmann Florian Breisch Gamejunkey Javier Roman Jay Horton - Joel Höglund Jon Woodward - Jose Fernando Alexandre Karl Werf + Keinan Powers Klavdij Voncina Lex Steers Luke Maciej Pendolski Matthew Hillier Mohamed Ikbel Boulabiar - Mored1984 - Péter Magyar + Mored4u Rob Messick Ryan Badour + Sandro Jenny Scott Wadden Sergey - Shawn Yu thechris Tom Langwaldt tukon @@ -115,6 +116,7 @@ generous deed immortalized in the next stable release of Godot Engine. Conrad Curry Craig Smith Darrian Little + Horváth Péter Ivan Trombley Jakub Dering Joan Fons @@ -128,6 +130,7 @@ generous deed immortalized in the next stable release of Godot Engine. Rob Robert Willes Ronnie Ashlock + SKison Thomas Bjarnelöf Unseen Domains Valryia @@ -135,49 +138,59 @@ generous deed immortalized in the next stable release of Godot Engine. Wojciech Chojnacki Xavier PATRICELLI + Adam Nakonieczny Adam Neumann Alexander J Maynard Alexey Dyadchenko + Alex Z Andreas Funke André Frélicot - Andrew Bowen aoshiwik + Ben Powell Carlos de Sousa Marques + Charlie Whitfield Chase Taranto Chris Petrich Christian Leth Jeppesen Christoph Schröder Cody Parker + Coldragon Craig Ostrin D Daniel Eichler David White + Denis Janßen + Easypete Eric Monson + ethan ball Eugenio Hugo Salgüero Jáñez Fain flesk + Gary Hulst gavlig GGGames.org + Green Fox Guilherme Felipe de C. G. da Silva + Halom Vered Heath Hayes - Hysteria Idzard Kwadijk + Isaac Clausman Jared White Jeff Nyte Jeremy Sims Jerry Ling Joe Flood + John G Gentzel + Jon Hermansen Jose Malheiro Joshua Lesperance Juan Velandia Juraj Móza - Kasper Jeppesen kinfox Marcelo Dornbusch Lopes Markus Fehr Markus Wiesner Martin Eigel - Marvin Matt Eunson Max Bulai MuffinManKen @@ -190,19 +203,23 @@ generous deed immortalized in the next stable release of Godot Engine. pl Ranoller Robert Larnach - Robin Arys Rocknight Studios Romildo Franco - Ryan Samuel Judd Scott Pilet + Sean Morgan + SleepCircle spilldata + Steve Hyatt Stoned Xander TheLevelOfDetail . Thomas Krampl Thomas Kurz Tobias Bocanegra + Tricky Fat Cat Urho + William Foster + Zhou Tuizhi Zie Weaver 蕭惟允 @@ -214,7 +231,7 @@ generous deed immortalized in the next stable release of Godot Engine. Adam Brunnmeier Adam Carr Adam Long - Adam Nakonieczny + Adam McCurdy Adam N Webber Adam Smeltzer Adam Szymański @@ -223,21 +240,23 @@ generous deed immortalized in the next stable release of Godot Engine. Agustinus Arya Aidan O'Flannagain Aki Mimoto + Alan Mervitz + Alan Stice Albin Jonasson Svärdsby Alder Stefano Alessandro Senese + Alexander Erlemann alex clavelle - Alex Davies-Moore + Allan Davis Allen Schade Andreas Evers Andreas Krampitz André Simões Andrew Thomas - Andrzej Skalski - Angelos Arnaoutis Anthony Staunton AP Condomines Arda Erol + Armin Preiml Arseniy M Arthur S. Muszynski Asger @@ -253,28 +272,29 @@ generous deed immortalized in the next stable release of Godot Engine. Black Block Blair Allen Bobby CC Wong - Bryan Stevenson + brian + bugcaptor + Burney Waring + Cameron Meyer Carl van der Geest Carwyn Edwards - Casey M. + Cassidy James Chris Brown Chris Chapin - Christian Baune Christian Winter Christoffer Sundbom + Christoph Brodmann Christopher Schmitt Christoph Woinke Clay Heaton - Collin Shooltz + Curt King + Dancin Liao Daniel Johnson Daniel Kimblad - DanielMaximiano Daniel Pontillo - Daniel Reed David May - David Rapisarda David Woodard - Dennis Idzikowsky + DiCola Jamn Dominic Cooney Dominik Wetzel Donn Eddy @@ -286,51 +306,61 @@ generous deed immortalized in the next stable release of Godot Engine. Dylan Todd Eduardo Teixeira Edward Herbert + Edward Moulsdale + Edward Swartz Egon Elbre + Elias Nykrem Elmeri '- Duy Kevin Nguyen + Ephemeral Eric Ellingson + Eric Rogers Eric Williams Erkki Seppälä Evan Rose Fancy Ants Studios Fekinox Felix Kollmann - fengjiongmax Flaredown Forty Doubleu FuDiggity - G3Dev sàrl Gadzhi Kharkharov gamedev by Celio - Gary Hulst + Gary Thomas George Marques GiulianoB + Gordian Arragon Greg Olson GREGORY C FEIN Greg P Greyson Richey + Grid Guldoman Hal A Heribert Hirth + Hudson Thorpe-Doubble Hunter Jones Hylpher + Ichiro Dohi Iiari + iKlem IndustrialRobot - Isaac Morton Jaiden Gerig Jaime Ruiz-Borau Vizárraga Jako Danar James A F Manley + Janders Jannik Gröger - Jax + JARKKO PARVIAINEN + Jarrod Davis Jeff Hungerford Jennifer Graves Jeremy Kahn Jesse Dubay - Joe Alden Joel Fivat + Joel Höglund Joel Setterberg Johannes Wuensch + John Gabriel Jomei Jackson Jonas Rudlang Jonas Yamazaki @@ -338,6 +368,7 @@ generous deed immortalized in the next stable release of Godot Engine. Jonathon Jon Bonazza Jon Sully + Jorge Caballero Jose Aleman Jose C. Rubio Joseph Catrambone @@ -346,9 +377,8 @@ generous deed immortalized in the next stable release of Godot Engine. Julian Murgia JungleRobba Justin Spedding - Kaiser Bald0 + KaDokta Kauzig - KC Chan Keedong Park Keith Bradner Kevin McPhillips @@ -356,40 +386,44 @@ generous deed immortalized in the next stable release of Godot Engine. Kiyohiro Kawamura (kyorohiro) Kjetil Haugland Klagsam - Klassix KR McGinley KsyTek Games Kuan Cheang kycho + Kyle Appelgate + Laurent Tréguier Leonardo Dimano Levi Lindsey Linus Lind Lundgren Lionel Gaillard + Luigi Renna LunaticInAHat Lurkars Major Haul Malcolm Malik Ahmed Malik Nejer - Marcus Richter Markus Michael Egger Martin Holas Martin Liška + Marvin + Mathieu Rimelen + Matt Edwards Matthew Little Matti Pohjanvirta Maxime Blade Maxwell medecau + Megasploot Melissa Mears - M H + mewin mhilbrunner - Michael Dürwald - Michael Gringauz Michael Haney Michael Labbe Mikael Olsson Mikayla Mike Birkhead + Mike Cunningham Mitchell J. Wagner MoM Nathan Fish @@ -399,8 +433,8 @@ generous deed immortalized in the next stable release of Godot Engine. Neil Wang Nerdforge Nicholas + Nicholas Girga Nick Macholl - Niclas Eriksen Nicolás Montaña Nicolas SAN AGUSTIN Nima Farid @@ -418,10 +452,7 @@ generous deed immortalized in the next stable release of Godot Engine. Penguin Petrus Prinsloo Philip Cohoe - Pierre-Igor Berthet - Pitsanu Tongprasin Point08 - Poryg Rad Cat Rafa Laguna rainerLinux @@ -431,13 +462,13 @@ generous deed immortalized in the next stable release of Godot Engine. Ricardo Alcantara Richard Diss Richard Ivánek - Richard Patching Robert Farr (Larington) Robert Hernandez - Rodrigo Loli + Roberto Sánchez Roger Smith Roland Rząsa Roman Tinkov + Ronald Ho Hip (CrimsonZA) Ronan Ryan Groom Ryan Hentz @@ -446,27 +477,29 @@ generous deed immortalized in the next stable release of Godot Engine. Samuele Zolfanelli Sasori Olkof Scott D. Yelich + Scott Longley Sebastian Michailidis + Sergio Mello-Grand sgnsajgon Shane Shane Sicienski Shane Spoor + Siim Raidma Simon Wenner SK smbe19 - Stonepyre + smo1704 Svenne Krap + Terry tezuvholovdr thomas Thomas Bechtold + Thomas Detoy Thomas Kelly - tiansheng li Tim Drumheller Timothy B. MacDonald - tinyBigGames LLC Tobbun - Tom Fulp - Tom Glenn + Torgeir Lilleskog Torsten Crass Travis O'Brien Trent Skinner @@ -476,7 +509,6 @@ generous deed immortalized in the next stable release of Godot Engine. Tyler Compton Tyler Stafos UltyX - Vaiktorg Vaughan Ling Victor Vigilant Watch @@ -487,7 +519,6 @@ generous deed immortalized in the next stable release of Godot Engine. Wiley Thompson Will William Hogben - Wout Standaert Wyatt Goodin Yegor Yuri Sizov diff --git a/core/SCsub b/core/SCsub index 755c5c65c6..b4974196bd 100644 --- a/core/SCsub +++ b/core/SCsub @@ -165,6 +165,7 @@ SConscript('os/SCsub') SConscript('math/SCsub') SConscript('crypto/SCsub') SConscript('io/SCsub') +SConscript('debugger/SCsub') SConscript('bind/SCsub') diff --git a/core/cowdata.h b/core/cowdata.h index 4fdcaf3cea..fba3f64899 100644 --- a/core/cowdata.h +++ b/core/cowdata.h @@ -82,24 +82,25 @@ private: } _FORCE_INLINE_ size_t _get_alloc_size(size_t p_elements) const { - //return nearest_power_of_2_templated(p_elements*sizeof(T)+sizeof(SafeRefCount)+sizeof(int)); return next_power_of_2(p_elements * sizeof(T)); } _FORCE_INLINE_ bool _get_alloc_size_checked(size_t p_elements, size_t *out) const { -#if defined(_add_overflow) && defined(_mul_overflow) +#if defined(__GNUC__) size_t o; size_t p; - if (_mul_overflow(p_elements, sizeof(T), &o)) { + if (__builtin_mul_overflow(p_elements, sizeof(T), &o)) { *out = 0; return false; } *out = next_power_of_2(o); - if (_add_overflow(o, static_cast<size_t>(32), &p)) return false; //no longer allocated here + if (__builtin_add_overflow(o, static_cast<size_t>(32), &p)) { + return false; // No longer allocated here. + } return true; #else // Speed is more important than correctness here, do the operations unchecked - // and hope the best + // and hope for the best. *out = _get_alloc_size(p_elements); return true; #endif diff --git a/core/debugger/SCsub b/core/debugger/SCsub new file mode 100644 index 0000000000..1c5f954470 --- /dev/null +++ b/core/debugger/SCsub @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +Import('env') + +env.add_source_files(env.core_sources, "*.cpp") diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp new file mode 100644 index 0000000000..eb3a19506a --- /dev/null +++ b/core/debugger/debugger_marshalls.cpp @@ -0,0 +1,329 @@ +/*************************************************************************/ +/* debugger_marshalls.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "debugger_marshalls.h" + +#include "core/io/marshalls.h" + +#define CHECK_SIZE(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() < (uint32_t)(expected), false, String("Malformed ") + what + " message from script debugger, message too short. Expected size: " + itos(expected) + ", actual size: " + itos(arr.size())) +#define CHECK_END(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() > (uint32_t)expected, false, String("Malformed ") + what + " message from script debugger, message too long. Expected size: " + itos(expected) + ", actual size: " + itos(arr.size())) + +Array DebuggerMarshalls::ResourceUsage::serialize() { + infos.sort(); + + Array arr; + arr.push_back(infos.size() * 4); + for (List<ResourceInfo>::Element *E = infos.front(); E; E = E->next()) { + arr.push_back(E->get().path); + arr.push_back(E->get().format); + arr.push_back(E->get().type); + arr.push_back(E->get().vram); + } + return arr; +} + +bool DebuggerMarshalls::ResourceUsage::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 1, "ResourceUsage"); + uint32_t size = p_arr[0]; + CHECK_SIZE(p_arr, size, "ResourceUsage"); + int idx = 1; + for (uint32_t i = 0; i < size / 4; i++) { + ResourceInfo info; + info.path = p_arr[idx]; + info.format = p_arr[idx + 1]; + info.type = p_arr[idx + 2]; + info.vram = p_arr[idx + 3]; + infos.push_back(info); + } + CHECK_END(p_arr, idx, "ResourceUsage"); + return true; +} + +Array DebuggerMarshalls::ScriptFunctionSignature::serialize() { + Array arr; + arr.push_back(name); + arr.push_back(id); + return arr; +} + +bool DebuggerMarshalls::ScriptFunctionSignature::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 2, "ScriptFunctionSignature"); + name = p_arr[0]; + id = p_arr[1]; + CHECK_END(p_arr, 2, "ScriptFunctionSignature"); + return true; +} + +Array DebuggerMarshalls::NetworkProfilerFrame::serialize() { + Array arr; + arr.push_back(infos.size() * 6); + for (int i = 0; i < infos.size(); ++i) { + arr.push_back(uint64_t(infos[i].node)); + arr.push_back(infos[i].node_path); + arr.push_back(infos[i].incoming_rpc); + arr.push_back(infos[i].incoming_rset); + arr.push_back(infos[i].outgoing_rpc); + arr.push_back(infos[i].outgoing_rset); + } + return arr; +} + +bool DebuggerMarshalls::NetworkProfilerFrame::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 1, "NetworkProfilerFrame"); + uint32_t size = p_arr[0]; + CHECK_SIZE(p_arr, size, "NetworkProfilerFrame"); + infos.resize(size); + int idx = 1; + for (uint32_t i = 0; i < size / 6; ++i) { + infos.write[i].node = uint64_t(p_arr[idx]); + infos.write[i].node_path = p_arr[idx + 1]; + infos.write[i].incoming_rpc = p_arr[idx + 2]; + infos.write[i].incoming_rset = p_arr[idx + 3]; + infos.write[i].outgoing_rpc = p_arr[idx + 4]; + infos.write[i].outgoing_rset = p_arr[idx + 5]; + } + CHECK_END(p_arr, idx, "NetworkProfilerFrame"); + return true; +} + +Array DebuggerMarshalls::ServersProfilerFrame::serialize() { + Array arr; + arr.push_back(frame_number); + arr.push_back(frame_time); + arr.push_back(idle_time); + arr.push_back(physics_time); + arr.push_back(physics_frame_time); + arr.push_back(script_time); + + arr.push_back(servers.size()); + for (int i = 0; i < servers.size(); i++) { + ServerInfo &s = servers[i]; + arr.push_back(s.name); + arr.push_back(s.functions.size() * 2); + for (int j = 0; j < s.functions.size(); j++) { + ServerFunctionInfo &f = s.functions[j]; + arr.push_back(f.name); + arr.push_back(f.time); + } + } + + arr.push_back(script_functions.size() * 4); + for (int i = 0; i < script_functions.size(); i++) { + arr.push_back(script_functions[i].sig_id); + arr.push_back(script_functions[i].call_count); + arr.push_back(script_functions[i].self_time); + arr.push_back(script_functions[i].total_time); + } + return arr; +} + +bool DebuggerMarshalls::ServersProfilerFrame::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 7, "ServersProfilerFrame"); + frame_number = p_arr[0]; + frame_time = p_arr[1]; + idle_time = p_arr[2]; + physics_time = p_arr[3]; + physics_frame_time = p_arr[4]; + script_time = p_arr[5]; + int servers_size = p_arr[6]; + int idx = 7; + while (servers_size) { + CHECK_SIZE(p_arr, idx + 2, "ServersProfilerFrame"); + servers_size--; + ServerInfo si; + si.name = p_arr[idx]; + int sub_data_size = p_arr[idx + 1]; + idx += 2; + CHECK_SIZE(p_arr, idx + sub_data_size, "ServersProfilerFrame"); + for (int j = 0; j < sub_data_size / 2; j++) { + ServerFunctionInfo sf; + sf.name = p_arr[idx]; + sf.time = p_arr[idx + 1]; + idx += 2; + si.functions.push_back(sf); + } + servers.push_back(si); + } + CHECK_SIZE(p_arr, idx + 3, "ServersProfilerFrame"); + int func_size = p_arr[idx]; + idx += 1; + CHECK_SIZE(p_arr, idx + func_size, "ServersProfilerFrame"); + for (int i = 0; i < func_size / 4; i++) { + ScriptFunctionInfo fi; + fi.sig_id = p_arr[idx]; + fi.call_count = p_arr[idx + 1]; + fi.self_time = p_arr[idx + 2]; + fi.total_time = p_arr[idx + 3]; + script_functions.push_back(fi); + idx += 4; + } + CHECK_END(p_arr, idx, "ServersProfilerFrame"); + return true; +} + +Array DebuggerMarshalls::ScriptStackDump::serialize() { + Array arr; + arr.push_back(frames.size() * 3); + for (int i = 0; i < frames.size(); i++) { + arr.push_back(frames[i].file); + arr.push_back(frames[i].line); + arr.push_back(frames[i].func); + } + return arr; +} + +bool DebuggerMarshalls::ScriptStackDump::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 1, "ScriptStackDump"); + uint32_t size = p_arr[0]; + CHECK_SIZE(p_arr, size, "ScriptStackDump"); + int idx = 1; + for (uint32_t i = 0; i < size / 3; i++) { + ScriptLanguage::StackInfo sf; + sf.file = p_arr[idx]; + sf.line = p_arr[idx + 1]; + sf.func = p_arr[idx + 2]; + frames.push_back(sf); + idx += 3; + } + CHECK_END(p_arr, idx, "ScriptStackDump"); + return true; +} + +Array DebuggerMarshalls::ScriptStackVariable::serialize(int max_size) { + Array arr; + arr.push_back(name); + arr.push_back(type); + + Variant var = value; + if (value.get_type() == Variant::OBJECT && value.get_validated_object() == nullptr) { + var = Variant(); + } + + int len = 0; + Error err = encode_variant(var, NULL, len, true); + if (err != OK) + ERR_PRINT("Failed to encode variant."); + + if (len > max_size) { + arr.push_back(Variant()); + } else { + arr.push_back(var); + } + return arr; +} + +bool DebuggerMarshalls::ScriptStackVariable::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 3, "ScriptStackVariable"); + name = p_arr[0]; + type = p_arr[1]; + value = p_arr[2]; + CHECK_END(p_arr, 3, "ScriptStackVariable"); + return true; +} + +Array DebuggerMarshalls::OutputError::serialize() { + Array arr; + arr.push_back(hr); + arr.push_back(min); + arr.push_back(sec); + arr.push_back(msec); + arr.push_back(source_file); + arr.push_back(source_func); + arr.push_back(source_line); + arr.push_back(error); + arr.push_back(error_descr); + arr.push_back(warning); + unsigned int size = callstack.size(); + const ScriptLanguage::StackInfo *r = callstack.ptr(); + arr.push_back(size * 3); + for (int i = 0; i < callstack.size(); i++) { + arr.push_back(r[i].file); + arr.push_back(r[i].func); + arr.push_back(r[i].line); + } + return arr; +} + +bool DebuggerMarshalls::OutputError::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 11, "OutputError"); + hr = p_arr[0]; + min = p_arr[1]; + sec = p_arr[2]; + msec = p_arr[3]; + source_file = p_arr[4]; + source_func = p_arr[5]; + source_line = p_arr[6]; + error = p_arr[7]; + error_descr = p_arr[8]; + warning = p_arr[9]; + unsigned int stack_size = p_arr[10]; + CHECK_SIZE(p_arr, stack_size, "OutputError"); + int idx = 11; + callstack.resize(stack_size / 3); + ScriptLanguage::StackInfo *w = callstack.ptrw(); + for (unsigned int i = 0; i < stack_size / 3; i++) { + w[i].file = p_arr[idx]; + w[i].func = p_arr[idx + 1]; + w[i].line = p_arr[idx + 2]; + idx += 3; + } + CHECK_END(p_arr, idx, "OutputError"); + return true; +} + +Array DebuggerMarshalls::VisualProfilerFrame::serialize() { + Array arr; + arr.push_back(frame_number); + arr.push_back(areas.size() * 3); + for (int i = 0; i < areas.size(); i++) { + arr.push_back(areas[i].name); + arr.push_back(areas[i].cpu_msec); + arr.push_back(areas[i].gpu_msec); + } + return arr; +} + +bool DebuggerMarshalls::VisualProfilerFrame::deserialize(const Array &p_arr) { + CHECK_SIZE(p_arr, 2, "VisualProfilerFrame"); + frame_number = p_arr[0]; + int size = p_arr[1]; + CHECK_SIZE(p_arr, size, "VisualProfilerFrame"); + int idx = 2; + areas.resize(size / 3); + VS::FrameProfileArea *w = areas.ptrw(); + for (int i = 0; i < size / 3; i++) { + w[i].name = p_arr[idx]; + w[i].cpu_msec = p_arr[idx + 1]; + w[i].gpu_msec = p_arr[idx + 2]; + idx += 3; + } + CHECK_END(p_arr, idx, "VisualProfilerFrame"); + return true; +} diff --git a/core/debugger/debugger_marshalls.h b/core/debugger/debugger_marshalls.h new file mode 100644 index 0000000000..4c15adc555 --- /dev/null +++ b/core/debugger/debugger_marshalls.h @@ -0,0 +1,175 @@ +/*************************************************************************/ +/* debugger_marshalls.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef DEBUGGER_MARSHARLLS_H +#define DEBUGGER_MARSHARLLS_H + +#include "core/script_language.h" +#include "servers/visual_server.h" + +struct DebuggerMarshalls { + + // Memory usage + struct ResourceInfo { + String path; + String format; + String type; + RID id; + int vram; + bool operator<(const ResourceInfo &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; } + ResourceInfo() { + vram = 0; + } + }; + + struct ResourceUsage { + List<ResourceInfo> infos; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + + // Network profiler + struct MultiplayerNodeInfo { + ObjectID node; + String node_path; + int incoming_rpc = 0; + int incoming_rset = 0; + int outgoing_rpc = 0; + int outgoing_rset = 0; + }; + + struct NetworkProfilerFrame { + Vector<MultiplayerNodeInfo> infos; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + + // Script Profiler + class ScriptFunctionSignature { + public: + StringName name; + int id = -1; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + + struct ScriptFunctionInfo { + StringName name; + int sig_id = -1; + int call_count = 0; + float self_time = 0; + float total_time = 0; + }; + + // Servers profiler + struct ServerFunctionInfo { + StringName name; + float time = 0; + }; + + struct ServerInfo { + StringName name; + List<ServerFunctionInfo> functions; + }; + + struct ServersProfilerFrame { + int frame_number = 0; + float frame_time = 0; + float idle_time = 0; + float physics_time = 0; + float physics_frame_time = 0; + float script_time = 0; + List<ServerInfo> servers; + Vector<ScriptFunctionInfo> script_functions; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + + struct ScriptStackVariable { + String name; + Variant value; + int type; + ScriptStackVariable() { + type = -1; + } + + Array serialize(int max_size = 1 << 20); // 1 MiB default. + bool deserialize(const Array &p_arr); + }; + + struct ScriptStackDump { + List<ScriptLanguage::StackInfo> frames; + ScriptStackDump() {} + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + + struct OutputError { + int hr; + int min; + int sec; + int msec; + String source_file; + String source_func; + int source_line; + String error; + String error_descr; + bool warning; + Vector<ScriptLanguage::StackInfo> callstack; + + OutputError() { + hr = -1; + min = -1; + sec = -1; + msec = -1; + source_line = -1; + warning = false; + } + + Array serialize(); + bool deserialize(const Array &p_arr); + }; + + // Visual Profiler + struct VisualProfilerFrame { + uint64_t frame_number; + Vector<VS::FrameProfileArea> areas; + + Array serialize(); + bool deserialize(const Array &p_arr); + }; +}; + +#endif // DEBUGGER_MARSHARLLS_H diff --git a/core/debugger/engine_debugger.cpp b/core/debugger/engine_debugger.cpp new file mode 100644 index 0000000000..c64d886800 --- /dev/null +++ b/core/debugger/engine_debugger.cpp @@ -0,0 +1,186 @@ +/*************************************************************************/ +/* engine_debugger.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "engine_debugger.h" + +#include "core/debugger/local_debugger.h" +#include "core/debugger/remote_debugger.h" +#include "core/debugger/script_debugger.h" +#include "core/os/os.h" + +EngineDebugger *EngineDebugger::singleton = NULL; +ScriptDebugger *EngineDebugger::script_debugger = NULL; + +Map<StringName, EngineDebugger::Profiler> EngineDebugger::profilers; +Map<StringName, EngineDebugger::Capture> EngineDebugger::captures; + +void EngineDebugger::register_profiler(const StringName &p_name, const Profiler &p_func) { + ERR_FAIL_COND_MSG(profilers.has(p_name), "Profiler already registered: " + p_name); + profilers.insert(p_name, p_func); +} + +void EngineDebugger::unregister_profiler(const StringName &p_name) { + ERR_FAIL_COND_MSG(!profilers.has(p_name), "Profiler not registered: " + p_name); + Profiler &p = profilers[p_name]; + if (p.active && p.toggle) { + p.toggle(p.data, false, Array()); + p.active = false; + } + profilers.erase(p_name); +} + +void EngineDebugger::register_message_capture(const StringName &p_name, Capture p_func) { + ERR_FAIL_COND_MSG(captures.has(p_name), "Capture already registered: " + p_name); + captures.insert(p_name, p_func); +} + +void EngineDebugger::unregister_message_capture(const StringName &p_name) { + ERR_FAIL_COND_MSG(!captures.has(p_name), "Capture not registered: " + p_name); + captures.erase(p_name); +} + +void EngineDebugger::profiler_enable(const StringName &p_name, bool p_enabled, const Array &p_opts) { + ERR_FAIL_COND_MSG(!profilers.has(p_name), "Can't change profiler state, no profiler: " + p_name); + Profiler &p = profilers[p_name]; + if (p.toggle) { + p.toggle(p.data, p_enabled, p_opts); + } + p.active = p_enabled; +} + +void EngineDebugger::profiler_add_frame_data(const StringName &p_name, const Array &p_data) { + ERR_FAIL_COND_MSG(!profilers.has(p_name), "Can't add frame data, no profiler: " + p_name); + Profiler &p = profilers[p_name]; + if (p.add) { + p.add(p.data, p_data); + } +} + +bool EngineDebugger::is_profiling(const StringName &p_name) { + return profilers.has(p_name) && profilers[p_name].active; +} + +bool EngineDebugger::has_profiler(const StringName &p_name) { + return profilers.has(p_name); +} + +bool EngineDebugger::has_capture(const StringName &p_name) { + return captures.has(p_name); +} + +Error EngineDebugger::capture_parse(const StringName &p_name, const String &p_msg, const Array &p_args, bool &r_captured) { + r_captured = false; + ERR_FAIL_COND_V_MSG(!captures.has(p_name), ERR_UNCONFIGURED, "Capture not registered: " + p_name); + const Capture &cap = captures[p_name]; + return cap.capture(cap.data, p_msg, p_args, r_captured); +} + +void EngineDebugger::line_poll() { + // The purpose of this is just processing events every now and then when the script might get too busy otherwise bugs like infinite loops can't be caught + if (poll_every % 2048 == 0) + poll_events(false); + poll_every++; +} + +void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, uint64_t p_physics_ticks, float p_physics_frame_time) { + frame_time = USEC_TO_SEC(p_frame_ticks); + idle_time = USEC_TO_SEC(p_idle_ticks); + physics_time = USEC_TO_SEC(p_physics_ticks); + physics_frame_time = p_physics_frame_time; + // Notify tick to running profilers + for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) { + Profiler &p = E->get(); + if (!p.active || !p.tick) + continue; + p.tick(p.data, frame_time, idle_time, physics_time, physics_frame_time); + } + singleton->poll_events(true); +} + +void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Vector<String> p_breakpoints) { + if (p_uri.empty()) + return; + if (p_uri == "local://") { + singleton = memnew(LocalDebugger); + script_debugger = memnew(ScriptDebugger); + // Tell the OS that we want to handle termination signals. + OS::get_singleton()->initialize_debugging(); + } else { + singleton = RemoteDebugger::create_for_uri(p_uri); + if (!singleton) + return; + script_debugger = memnew(ScriptDebugger); + // Notify editor of our pid (to allow focus stealing). + Array msg; + msg.push_back(OS::get_singleton()->get_process_id()); + singleton->send_message("set_pid", msg); + } + if (!singleton) + return; + + // There is a debugger, parse breakpoints. + ScriptDebugger *singleton_script_debugger = singleton->get_script_debugger(); + singleton_script_debugger->set_skip_breakpoints(p_skip_breakpoints); + + for (int i = 0; i < p_breakpoints.size(); i++) { + + String bp = p_breakpoints[i]; + int sp = bp.find_last(":"); + ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format."); + + singleton_script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp)); + } +} + +void EngineDebugger::deinitialize() { + if (!singleton) + return; + + // Stop all profilers + for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) { + if (E->get().active) + singleton->profiler_enable(E->key(), false); + } + + // Flush any remaining message + singleton->poll_events(false); + + memdelete(singleton); + singleton = NULL; + profilers.clear(); + captures.clear(); +} + +EngineDebugger::~EngineDebugger() { + if (script_debugger) + memdelete(script_debugger); + script_debugger = NULL; + singleton = NULL; +} diff --git a/core/debugger/engine_debugger.h b/core/debugger/engine_debugger.h new file mode 100644 index 0000000000..9e01aeba18 --- /dev/null +++ b/core/debugger/engine_debugger.h @@ -0,0 +1,130 @@ +/*************************************************************************/ +/* engine_debugger.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef ENGINE_DEBUGGER_H +#define ENGINE_DEBUGGER_H + +#include "core/array.h" +#include "core/map.h" +#include "core/string_name.h" +#include "core/ustring.h" +#include "core/variant.h" +#include "core/vector.h" + +class ScriptDebugger; + +class EngineDebugger { +public: + typedef void (*ProfilingToggle)(void *p_user, bool p_enable, const Array &p_opts); + typedef void (*ProfilingTick)(void *p_user, float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time); + typedef void (*ProfilingAdd)(void *p_user, const Array &p_arr); + typedef Error (*CaptureFunc)(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured); + + class Profiler { + friend class EngineDebugger; + + ProfilingToggle toggle = NULL; + ProfilingAdd add = NULL; + ProfilingTick tick = NULL; + void *data = NULL; + bool active = false; + + public: + Profiler() {} + Profiler(void *p_data, ProfilingToggle p_toggle, ProfilingAdd p_add, ProfilingTick p_tick) { + data = p_data; + toggle = p_toggle; + add = p_add; + tick = p_tick; + } + }; + + class Capture { + friend class EngineDebugger; + + CaptureFunc capture = NULL; + void *data = NULL; + + public: + Capture() {} + Capture(void *p_data, CaptureFunc p_capture) { + data = p_data; + capture = p_capture; + } + }; + +private: + float frame_time = 0.0; + float idle_time = 0.0; + float physics_time = 0.0; + float physics_frame_time = 0.0; + + uint32_t poll_every = 0; + +protected: + static EngineDebugger *singleton; + static ScriptDebugger *script_debugger; + + static Map<StringName, Profiler> profilers; + static Map<StringName, Capture> captures; + +public: + _FORCE_INLINE_ static EngineDebugger *get_singleton() { return singleton; } + _FORCE_INLINE_ static bool is_active() { return singleton != NULL && script_debugger != NULL; } + + _FORCE_INLINE_ static ScriptDebugger *get_script_debugger() { return script_debugger; }; + + static void initialize(const String &p_uri, bool p_skip_breakpoints, Vector<String> p_breakpoints); + static void deinitialize(); + static void register_profiler(const StringName &p_name, const Profiler &p_profiler); + static void unregister_profiler(const StringName &p_name); + static bool is_profiling(const StringName &p_name); + static bool has_profiler(const StringName &p_name); + static void profiler_add_frame_data(const StringName &p_name, const Array &p_data); + + static void register_message_capture(const StringName &p_name, Capture p_func); + static void unregister_message_capture(const StringName &p_name); + static bool has_capture(const StringName &p_name); + + void iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, uint64_t p_physics_ticks, float p_physics_frame_time); + void profiler_enable(const StringName &p_name, bool p_enabled, const Array &p_opts = Array()); + Error capture_parse(const StringName &p_name, const String &p_msg, const Array &p_args, bool &r_captured); + + void line_poll(); + + virtual void poll_events(bool p_is_idle) {} + virtual void send_message(const String &p_msg, const Array &p_data) = 0; + virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type) = 0; + virtual void debug(bool p_can_continue = true, bool p_is_error_breakpoint = false) = 0; + + virtual ~EngineDebugger(); +}; + +#endif // ENGINE_DEBUGGER_H diff --git a/core/script_debugger_local.cpp b/core/debugger/local_debugger.cpp index c64638e7ce..913d3fc031 100644 --- a/core/script_debugger_local.cpp +++ b/core/debugger/local_debugger.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* script_debugger_local.cpp */ +/* local_debugger.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,28 +28,112 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "script_debugger_local.h" +#include "local_debugger.h" +#include "core/debugger/script_debugger.h" #include "core/os/os.h" #include "scene/main/scene_tree.h" -void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint) { +struct LocalDebugger::ScriptsProfiler { + struct ProfileInfoSort { + + bool operator()(const ScriptLanguage::ProfilingInfo &A, const ScriptLanguage::ProfilingInfo &B) const { + return A.total_time > B.total_time; + } + }; + + float frame_time = 0; + uint64_t idle_accum = 0; + Vector<ScriptLanguage::ProfilingInfo> pinfo; + + void toggle(bool p_enable, const Array &p_opts) { + if (p_enable) { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->profiling_start(); + } + + print_line("BEGIN PROFILING"); + pinfo.resize(32768); + } else { + _print_frame_data(true); + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->profiling_stop(); + } + } + } + + void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { + frame_time = p_frame_time; + _print_frame_data(false); + } + + void _print_frame_data(bool p_accumulated) { + uint64_t diff = OS::get_singleton()->get_ticks_usec() - idle_accum; + + if (!p_accumulated && diff < 1000000) //show every one second + return; + + idle_accum = OS::get_singleton()->get_ticks_usec(); + + int ofs = 0; + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + if (p_accumulated) + ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&pinfo.write[ofs], pinfo.size() - ofs); + else + ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&pinfo.write[ofs], pinfo.size() - ofs); + } + + SortArray<ScriptLanguage::ProfilingInfo, ProfileInfoSort> sort; + sort.sort(pinfo.ptrw(), ofs); + + // compute total script frame time + uint64_t script_time_us = 0; + for (int i = 0; i < ofs; i++) { + + script_time_us += pinfo[i].self_time; + } + float script_time = USEC_TO_SEC(script_time_us); + float total_time = p_accumulated ? script_time : frame_time; + + if (!p_accumulated) { + print_line("FRAME: total: " + rtos(total_time) + " script: " + rtos(script_time) + "/" + itos(script_time * 100 / total_time) + " %"); + } else { + print_line("ACCUMULATED: total: " + rtos(total_time)); + } + + for (int i = 0; i < ofs; i++) { + + print_line(itos(i) + ":" + pinfo[i].signature); + float tt = USEC_TO_SEC(pinfo[i].total_time); + float st = USEC_TO_SEC(pinfo[i].self_time); + print_line("\ttotal: " + rtos(tt) + "/" + itos(tt * 100 / total_time) + " % \tself: " + rtos(st) + "/" + itos(st * 100 / total_time) + " % tcalls: " + itos(pinfo[i].call_count)); + } + } + + ScriptsProfiler() { + idle_accum = OS::get_singleton()->get_ticks_usec(); + } +}; + +void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { + + ScriptLanguage *script_lang = script_debugger->get_break_language(); if (!target_function.empty()) { - String current_function = p_script->debug_get_stack_level_function(0); + String current_function = script_lang->debug_get_stack_level_function(0); if (current_function != target_function) { - set_depth(0); - set_lines_left(1); + script_debugger->set_depth(0); + script_debugger->set_lines_left(1); return; } target_function = ""; } - print_line("\nDebugger Break, Reason: '" + p_script->debug_get_error() + "'"); - print_line("*Frame " + itos(0) + " - " + p_script->debug_get_stack_level_source(0) + ":" + itos(p_script->debug_get_stack_level_line(0)) + " in function '" + p_script->debug_get_stack_level_function(0) + "'"); + print_line("\nDebugger Break, Reason: '" + script_lang->debug_get_error() + "'"); + print_line("*Frame " + itos(0) + " - " + script_lang->debug_get_stack_level_source(0) + ":" + itos(script_lang->debug_get_stack_level_line(0)) + " in function '" + script_lang->debug_get_stack_level_function(0) + "'"); print_line("Enter \"help\" for assistance."); int current_frame = 0; - int total_frames = p_script->debug_get_stack_level_count(); + int total_frames = script_lang->debug_get_stack_level_count(); while (true) { OS::get_singleton()->print("debug> "); @@ -59,8 +143,8 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b String variable_prefix = options["variable_prefix"]; if (line == "") { - print_line("\nDebugger Break, Reason: '" + p_script->debug_get_error() + "'"); - print_line("*Frame " + itos(current_frame) + " - " + p_script->debug_get_stack_level_source(current_frame) + ":" + itos(p_script->debug_get_stack_level_line(current_frame)) + " in function '" + p_script->debug_get_stack_level_function(current_frame) + "'"); + print_line("\nDebugger Break, Reason: '" + script_lang->debug_get_error() + "'"); + print_line("*Frame " + itos(current_frame) + " - " + script_lang->debug_get_stack_level_source(current_frame) + ":" + itos(script_lang->debug_get_stack_level_line(current_frame)) + " in function '" + script_lang->debug_get_stack_level_function(current_frame) + "'"); print_line("Enter \"help\" for assistance."); } else if (line == "c" || line == "continue") break; @@ -69,20 +153,20 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b for (int i = 0; i < total_frames; i++) { String cfi = (current_frame == i) ? "*" : " "; //current frame indicator - print_line(cfi + "Frame " + itos(i) + " - " + p_script->debug_get_stack_level_source(i) + ":" + itos(p_script->debug_get_stack_level_line(i)) + " in function '" + p_script->debug_get_stack_level_function(i) + "'"); + print_line(cfi + "Frame " + itos(i) + " - " + script_lang->debug_get_stack_level_source(i) + ":" + itos(script_lang->debug_get_stack_level_line(i)) + " in function '" + script_lang->debug_get_stack_level_function(i) + "'"); } } else if (line.begins_with("fr") || line.begins_with("frame")) { if (line.get_slice_count(" ") == 1) { - print_line("*Frame " + itos(current_frame) + " - " + p_script->debug_get_stack_level_source(current_frame) + ":" + itos(p_script->debug_get_stack_level_line(current_frame)) + " in function '" + p_script->debug_get_stack_level_function(current_frame) + "'"); + print_line("*Frame " + itos(current_frame) + " - " + script_lang->debug_get_stack_level_source(current_frame) + ":" + itos(script_lang->debug_get_stack_level_line(current_frame)) + " in function '" + script_lang->debug_get_stack_level_function(current_frame) + "'"); } else { int frame = line.get_slicec(' ', 1).to_int(); if (frame < 0 || frame >= total_frames) { print_line("Error: Invalid frame."); } else { current_frame = frame; - print_line("*Frame " + itos(frame) + " - " + p_script->debug_get_stack_level_source(frame) + ":" + itos(p_script->debug_get_stack_level_line(frame)) + " in function '" + p_script->debug_get_stack_level_function(frame) + "'"); + print_line("*Frame " + itos(frame) + " - " + script_lang->debug_get_stack_level_source(frame) + ":" + itos(script_lang->debug_get_stack_level_line(frame)) + " in function '" + script_lang->debug_get_stack_level_function(frame) + "'"); } } @@ -120,21 +204,21 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b List<String> locals; List<Variant> values; - p_script->debug_get_stack_level_locals(current_frame, &locals, &values); + script_lang->debug_get_stack_level_locals(current_frame, &locals, &values); print_variables(locals, values, variable_prefix); } else if (line == "gv" || line == "globals") { List<String> globals; List<Variant> values; - p_script->debug_get_globals(&globals, &values); + script_lang->debug_get_globals(&globals, &values); print_variables(globals, values, variable_prefix); } else if (line == "mv" || line == "members") { List<String> members; List<Variant> values; - p_script->debug_get_stack_level_members(current_frame, &members, &values); + script_lang->debug_get_stack_level_members(current_frame, &members, &values); print_variables(members, values, variable_prefix); } else if (line.begins_with("p") || line.begins_with("print")) { @@ -144,29 +228,29 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b } else { String expr = line.get_slicec(' ', 2); - String res = p_script->debug_parse_stack_level_expression(current_frame, expr); + String res = script_lang->debug_parse_stack_level_expression(current_frame, expr); print_line(res); } } else if (line == "s" || line == "step") { - set_depth(-1); - set_lines_left(1); + script_debugger->set_depth(-1); + script_debugger->set_lines_left(1); break; } else if (line == "n" || line == "next") { - set_depth(0); - set_lines_left(1); + script_debugger->set_depth(0); + script_debugger->set_lines_left(1); break; } else if (line == "fin" || line == "finish") { - String current_function = p_script->debug_get_stack_level_function(0); + String current_function = script_lang->debug_get_stack_level_function(0); for (int i = 0; i < total_frames; i++) { - target_function = p_script->debug_get_stack_level_function(i); + target_function = script_lang->debug_get_stack_level_function(i); if (target_function != current_function) { - set_depth(0); - set_lines_left(1); + script_debugger->set_depth(0); + script_debugger->set_lines_left(1); return; } } @@ -178,7 +262,7 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b if (line.get_slice_count(" ") <= 1) { - const Map<int, Set<StringName> > &breakpoints = get_breakpoints(); + const Map<int, Set<StringName> > &breakpoints = script_debugger->get_breakpoints(); if (breakpoints.size() == 0) { print_line("No Breakpoints."); continue; @@ -199,7 +283,7 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b if (source.empty()) continue; - insert_breakpoint(linenr, source); + script_debugger->insert_breakpoint(linenr, source); print_line("Added breakpoint at " + source + ":" + itos(linenr)); } @@ -207,16 +291,16 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b } else if (line == "q" || line == "quit") { // Do not stop again on quit - clear_breakpoints(); - ScriptDebugger::get_singleton()->set_depth(-1); - ScriptDebugger::get_singleton()->set_lines_left(-1); + script_debugger->clear_breakpoints(); + script_debugger->set_depth(-1); + script_debugger->set_lines_left(-1); SceneTree::get_singleton()->quit(); break; } else if (line.begins_with("delete")) { if (line.get_slice_count(" ") <= 1) { - clear_breakpoints(); + script_debugger->clear_breakpoints(); } else { Pair<String, int> breakpoint = to_breakpoint(line); @@ -227,7 +311,7 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b if (source.empty()) continue; - remove_breakpoint(linenr, source); + script_debugger->remove_breakpoint(linenr, source); print_line("Removed breakpoint at " + source + ":" + itos(linenr)); } @@ -255,7 +339,7 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue, b } } -void ScriptDebuggerLocal::print_variables(const List<String> &names, const List<Variant> &values, const String &variable_prefix) { +void LocalDebugger::print_variables(const List<String> &names, const List<Variant> &values, const String &variable_prefix) { String value; Vector<String> value_lines; @@ -279,7 +363,7 @@ void ScriptDebuggerLocal::print_variables(const List<String> &names, const List< } } -Pair<String, int> ScriptDebuggerLocal::to_breakpoint(const String &p_line) { +Pair<String, int> LocalDebugger::to_breakpoint(const String &p_line) { String breakpoint_part = p_line.get_slicec(' ', 1); Pair<String, int> breakpoint; @@ -290,135 +374,43 @@ Pair<String, int> ScriptDebuggerLocal::to_breakpoint(const String &p_line) { return breakpoint; } - breakpoint.first = breakpoint_find_source(breakpoint_part.left(last_colon).strip_edges()); + breakpoint.first = script_debugger->breakpoint_find_source(breakpoint_part.left(last_colon).strip_edges()); breakpoint.second = breakpoint_part.right(last_colon).strip_edges().to_int(); return breakpoint; } -struct _ScriptDebuggerLocalProfileInfoSort { - - bool operator()(const ScriptLanguage::ProfilingInfo &A, const ScriptLanguage::ProfilingInfo &B) const { - return A.total_time > B.total_time; - } -}; - -void ScriptDebuggerLocal::profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { - - frame_time = p_frame_time; - idle_time = p_idle_time; - physics_time = p_physics_time; - physics_frame_time = p_physics_frame_time; -} - -void ScriptDebuggerLocal::idle_poll() { - - if (!profiling) - return; - - uint64_t diff = OS::get_singleton()->get_ticks_usec() - idle_accum; - - if (diff < 1000000) //show every one second - return; - - idle_accum = OS::get_singleton()->get_ticks_usec(); - - int ofs = 0; - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&pinfo.write[ofs], pinfo.size() - ofs); - } - - SortArray<ScriptLanguage::ProfilingInfo, _ScriptDebuggerLocalProfileInfoSort> sort; - sort.sort(pinfo.ptrw(), ofs); - - //falta el frame time - - uint64_t script_time_us = 0; - - for (int i = 0; i < ofs; i++) { - - script_time_us += pinfo[i].self_time; - } - - float script_time = USEC_TO_SEC(script_time_us); - - float total_time = frame_time; - - //print script total - - print_line("FRAME: total: " + rtos(frame_time) + " script: " + rtos(script_time) + "/" + itos(script_time * 100 / total_time) + " %"); - - for (int i = 0; i < ofs; i++) { - - print_line(itos(i) + ":" + pinfo[i].signature); - float tt = USEC_TO_SEC(pinfo[i].total_time); - float st = USEC_TO_SEC(pinfo[i].self_time); - print_line("\ttotal: " + rtos(tt) + "/" + itos(tt * 100 / total_time) + " % \tself: " + rtos(st) + "/" + itos(st * 100 / total_time) + " % tcalls: " + itos(pinfo[i].call_count)); - } -} - -void ScriptDebuggerLocal::profiling_start() { - - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->profiling_start(); - } - - print_line("BEGIN PROFILING"); - profiling = true; - pinfo.resize(32768); - frame_time = 0; - physics_time = 0; - idle_time = 0; - physics_frame_time = 0; -} - -void ScriptDebuggerLocal::profiling_end() { - - int ofs = 0; - - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&pinfo.write[ofs], pinfo.size() - ofs); - } - - SortArray<ScriptLanguage::ProfilingInfo, _ScriptDebuggerLocalProfileInfoSort> sort; - sort.sort(pinfo.ptrw(), ofs); - - uint64_t total_us = 0; - for (int i = 0; i < ofs; i++) { - total_us += pinfo[i].self_time; - } - - float total_time = total_us / 1000000.0; - - for (int i = 0; i < ofs; i++) { - - print_line(itos(i) + ":" + pinfo[i].signature); - float tt = USEC_TO_SEC(pinfo[i].total_time); - float st = USEC_TO_SEC(pinfo[i].self_time); - print_line("\ttotal_ms: " + rtos(tt) + "\tself_ms: " + rtos(st) + "total%: " + itos(tt * 100 / total_time) + "\tself%: " + itos(st * 100 / total_time) + "\tcalls: " + itos(pinfo[i].call_count)); - } - - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->profiling_stop(); - } - - profiling = false; -} - -void ScriptDebuggerLocal::send_message(const String &p_message, const Array &p_args) { +void LocalDebugger::send_message(const String &p_message, const Array &p_args) { // This needs to be cleaned up entirely. // print_line("MESSAGE: '" + p_message + "' - " + String(Variant(p_args))); } -void ScriptDebuggerLocal::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info) { +void LocalDebugger::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type) { print_line("ERROR: '" + (p_descr.empty() ? p_err : p_descr) + "'"); } -ScriptDebuggerLocal::ScriptDebuggerLocal() { +LocalDebugger::LocalDebugger() { - profiling = false; - idle_accum = OS::get_singleton()->get_ticks_usec(); options["variable_prefix"] = ""; + + // Bind scripts profiler. + scripts_profiler = memnew(ScriptsProfiler); + Profiler scr_prof( + scripts_profiler, + [](void *p_user, bool p_enable, const Array &p_opts) { + ((ScriptsProfiler *)p_user)->toggle(p_enable, p_opts); + }, + NULL, + [](void *p_user, float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { + ((ScriptsProfiler *)p_user)->tick(p_frame_time, p_idle_time, p_physics_time, p_physics_frame_time); + }); + register_profiler("scripts", scr_prof); +} + +LocalDebugger::~LocalDebugger() { + unregister_profiler("scripts"); + if (scripts_profiler) + memdelete(scripts_profiler); } diff --git a/core/script_debugger_local.h b/core/debugger/local_debugger.h index 7a64400191..e299df0546 100644 --- a/core/script_debugger_local.h +++ b/core/debugger/local_debugger.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* script_debugger_local.h */ +/* local_debugger.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,40 +28,33 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SCRIPT_DEBUGGER_LOCAL_H -#define SCRIPT_DEBUGGER_LOCAL_H +#ifndef LOCAL_DEBUGGER_H +#define LOCAL_DEBUGGER_H +#include "core/debugger/engine_debugger.h" #include "core/list.h" #include "core/script_language.h" -class ScriptDebuggerLocal : public ScriptDebugger { +class LocalDebugger : public EngineDebugger { + +private: + struct ScriptsProfiler; + + ScriptsProfiler *scripts_profiler = NULL; - bool profiling; - float frame_time, idle_time, physics_time, physics_frame_time; - uint64_t idle_accum; String target_function; Map<String, String> options; - Vector<ScriptLanguage::ProfilingInfo> pinfo; - Pair<String, int> to_breakpoint(const String &p_line); void print_variables(const List<String> &names, const List<Variant> &values, const String &variable_prefix); public: - void debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint); - virtual void send_message(const String &p_message, const Array &p_args); - virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info); - - virtual bool is_profiling() const { return profiling; } - virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data) {} - - virtual void idle_poll(); - - virtual void profiling_start(); - virtual void profiling_end(); - virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time); + void debug(bool p_can_continue, bool p_is_error_breakpoint); + void send_message(const String &p_message, const Array &p_args); + void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type); - ScriptDebuggerLocal(); + LocalDebugger(); + ~LocalDebugger(); }; -#endif // SCRIPT_DEBUGGER_LOCAL_H +#endif // LOCAL_DEBUGGER_H diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp new file mode 100644 index 0000000000..5f7ffb115c --- /dev/null +++ b/core/debugger/remote_debugger.cpp @@ -0,0 +1,935 @@ +/*************************************************************************/ +/* remote_debugger.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "remote_debugger.h" + +#include "core/debugger/debugger_marshalls.h" +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" +#include "core/os/input.h" +#include "core/os/os.h" +#include "core/project_settings.h" +#include "core/script_language.h" +#include "scene/main/node.h" + +template <typename T> +void RemoteDebugger::_bind_profiler(const String &p_name, T *p_prof) { + EngineDebugger::Profiler prof( + p_prof, + [](void *p_user, bool p_enable, const Array &p_opts) { + ((T *)p_user)->toggle(p_enable, p_opts); + }, + [](void *p_user, const Array &p_data) { + ((T *)p_user)->add(p_data); + }, + [](void *p_user, float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { + ((T *)p_user)->tick(p_frame_time, p_idle_time, p_physics_time, p_physics_frame_time); + }); + EngineDebugger::register_profiler(p_name, prof); +} + +struct RemoteDebugger::NetworkProfiler { + +public: + typedef DebuggerMarshalls::MultiplayerNodeInfo NodeInfo; + struct BandwidthFrame { + uint32_t timestamp; + int packet_size; + }; + + int bandwidth_in_ptr = 0; + Vector<BandwidthFrame> bandwidth_in; + int bandwidth_out_ptr = 0; + Vector<BandwidthFrame> bandwidth_out; + uint64_t last_bandwidth_time = 0; + + Map<ObjectID, NodeInfo> multiplayer_node_data; + uint64_t last_profile_time = 0; + + NetworkProfiler() {} + + int bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer) { + int total_bandwidth = 0; + + uint32_t timestamp = OS::get_singleton()->get_ticks_msec(); + uint32_t final_timestamp = timestamp - 1000; + + int i = (p_pointer + p_buffer.size() - 1) % p_buffer.size(); + + while (i != p_pointer && p_buffer[i].packet_size > 0) { + if (p_buffer[i].timestamp < final_timestamp) { + return total_bandwidth; + } + total_bandwidth += p_buffer[i].packet_size; + i = (i + p_buffer.size() - 1) % p_buffer.size(); + } + + ERR_FAIL_COND_V_MSG(i == p_pointer, total_bandwidth, "Reached the end of the bandwidth profiler buffer, values might be inaccurate."); + return total_bandwidth; + } + + void init_node(const ObjectID p_node) { + if (multiplayer_node_data.has(p_node)) + return; + multiplayer_node_data.insert(p_node, DebuggerMarshalls::MultiplayerNodeInfo()); + multiplayer_node_data[p_node].node = p_node; + multiplayer_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path(); + multiplayer_node_data[p_node].incoming_rpc = 0; + multiplayer_node_data[p_node].incoming_rset = 0; + multiplayer_node_data[p_node].outgoing_rpc = 0; + multiplayer_node_data[p_node].outgoing_rset = 0; + } + + void toggle(bool p_enable, const Array &p_opts) { + multiplayer_node_data.clear(); + + if (!p_enable) { + bandwidth_in.clear(); + bandwidth_out.clear(); + } else { + bandwidth_in_ptr = 0; + bandwidth_in.resize(16384); // ~128kB + for (int i = 0; i < bandwidth_in.size(); ++i) { + bandwidth_in.write[i].packet_size = -1; + } + bandwidth_out_ptr = 0; + bandwidth_out.resize(16384); // ~128kB + for (int i = 0; i < bandwidth_out.size(); ++i) { + bandwidth_out.write[i].packet_size = -1; + } + } + } + + void add(const Array &p_data) { + ERR_FAIL_COND(p_data.size() < 1); + const String type = p_data[0]; + if (type == "node") { + ERR_FAIL_COND(p_data.size() < 3); + const ObjectID id = p_data[1]; + const String what = p_data[2]; + init_node(id); + NodeInfo &info = multiplayer_node_data[id]; + if (what == "rpc_in") { + info.incoming_rpc++; + } else if (what == "rpc_out") { + info.outgoing_rpc++; + } else if (what == "rset_in") { + info.incoming_rset = 0; + } else if (what == "rset_out") { + info.outgoing_rset++; + } + } else if (type == "bandwidth") { + ERR_FAIL_COND(p_data.size() < 4); + const String inout = p_data[1]; + int time = p_data[2]; + int size = p_data[3]; + if (inout == "in") { + bandwidth_in.write[bandwidth_in_ptr].timestamp = time; + bandwidth_in.write[bandwidth_in_ptr].packet_size = size; + bandwidth_in_ptr = (bandwidth_in_ptr + 1) % bandwidth_in.size(); + } else if (inout == "out") { + bandwidth_out.write[bandwidth_out_ptr].timestamp = time; + bandwidth_out.write[bandwidth_out_ptr].packet_size = size; + bandwidth_out_ptr = (bandwidth_out_ptr + 1) % bandwidth_out.size(); + } + } + } + + void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { + uint64_t pt = OS::get_singleton()->get_ticks_msec(); + if (pt - last_bandwidth_time > 200) { + last_bandwidth_time = pt; + int incoming_bandwidth = bandwidth_usage(bandwidth_in, bandwidth_in_ptr); + int outgoing_bandwidth = bandwidth_usage(bandwidth_out, bandwidth_out_ptr); + + Array arr; + arr.push_back(incoming_bandwidth); + arr.push_back(outgoing_bandwidth); + EngineDebugger::get_singleton()->send_message("network:bandwidth", arr); + } + if (pt - last_profile_time > 100) { + last_profile_time = pt; + DebuggerMarshalls::NetworkProfilerFrame frame; + for (Map<ObjectID, NodeInfo>::Element *E = multiplayer_node_data.front(); E; E = E->next()) { + frame.infos.push_back(E->get()); + } + multiplayer_node_data.clear(); + EngineDebugger::get_singleton()->send_message("network:profile_frame", frame.serialize()); + } + } +}; + +struct RemoteDebugger::ScriptsProfiler { + typedef DebuggerMarshalls::ScriptFunctionSignature FunctionSignature; + typedef DebuggerMarshalls::ScriptFunctionInfo FunctionInfo; + struct ProfileInfoSort { + + bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const { + return A->total_time < B->total_time; + } + }; + Vector<ScriptLanguage::ProfilingInfo> info; + Vector<ScriptLanguage::ProfilingInfo *> ptrs; + Map<StringName, int> sig_map; + int max_frame_functions = 16; + + void toggle(bool p_enable, const Array &p_opts) { + if (p_enable) { + sig_map.clear(); + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->profiling_start(); + } + if (p_opts.size() == 1 && p_opts[0].get_type() == Variant::INT) { + max_frame_functions = MAX(0, int(p_opts[0])); + } + } else { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->profiling_stop(); + } + } + } + + void write_frame_data(Vector<FunctionInfo> &r_funcs, uint64_t &r_total, bool p_accumulated) { + int ofs = 0; + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + if (p_accumulated) + ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&info.write[ofs], info.size() - ofs); + else + ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&info.write[ofs], info.size() - ofs); + } + + for (int i = 0; i < ofs; i++) { + ptrs.write[i] = &info.write[i]; + } + + SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa; + sa.sort(ptrs.ptrw(), ofs); + + int to_send = MIN(ofs, max_frame_functions); + + // Check signatures first, and compute total time. + r_total = 0; + for (int i = 0; i < to_send; i++) { + if (!sig_map.has(ptrs[i]->signature)) { + int idx = sig_map.size(); + FunctionSignature sig; + sig.name = ptrs[i]->signature; + sig.id = idx; + EngineDebugger::get_singleton()->send_message("servers:function_signature", sig.serialize()); + sig_map[ptrs[i]->signature] = idx; + } + r_total += ptrs[i]->self_time; + } + + // Send frame, script time, functions information then + r_funcs.resize(to_send); + + FunctionInfo *w = r_funcs.ptrw(); + for (int i = 0; i < to_send; i++) { + if (sig_map.has(ptrs[i]->signature)) { + w[i].sig_id = sig_map[ptrs[i]->signature]; + } + w[i].call_count = ptrs[i]->call_count; + w[i].total_time = ptrs[i]->total_time / 1000000.0; + w[i].self_time = ptrs[i]->self_time / 1000000.0; + } + } + + ScriptsProfiler() { + info.resize(GLOBAL_GET("debug/settings/profiler/max_functions")); + ptrs.resize(info.size()); + } +}; + +struct RemoteDebugger::ServersProfiler { + + bool skip_profile_frame = false; + typedef DebuggerMarshalls::ServerInfo ServerInfo; + typedef DebuggerMarshalls::ServerFunctionInfo ServerFunctionInfo; + + Map<StringName, ServerInfo> server_data; + ScriptsProfiler scripts_profiler; + + float frame_time = 0; + float idle_time = 0; + float physics_time = 0; + float physics_frame_time = 0; + + void toggle(bool p_enable, const Array &p_opts) { + skip_profile_frame = false; + if (p_enable) { + server_data.clear(); // Clear old profiling data. + } else { + _send_frame_data(true); // Send final frame. + } + scripts_profiler.toggle(p_enable, p_opts); + } + + void add(const Array &p_data) { + String name = p_data[0]; + if (!server_data.has(name)) { + ServerInfo info; + info.name = name; + server_data[name] = info; + } + ServerInfo &srv = server_data[name]; + + ServerFunctionInfo fi; + fi.name = p_data[1]; + fi.time = p_data[2]; + srv.functions.push_back(fi); + } + + void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { + frame_time = p_frame_time; + idle_time = p_idle_time; + physics_time = p_physics_time; + physics_frame_time = p_physics_frame_time; + _send_frame_data(false); + } + + void _send_frame_data(bool p_final) { + DebuggerMarshalls::ServersProfilerFrame frame; + frame.frame_number = Engine::get_singleton()->get_frames_drawn(); + frame.frame_time = frame_time; + frame.idle_time = idle_time; + frame.physics_time = physics_time; + frame.physics_frame_time = physics_frame_time; + Map<StringName, ServerInfo>::Element *E = server_data.front(); + while (E) { + if (!p_final) { + frame.servers.push_back(E->get()); + } + E->get().functions.clear(); + E = E->next(); + } + uint64_t time = 0; + scripts_profiler.write_frame_data(frame.script_functions, time, p_final); + frame.script_time = USEC_TO_SEC(time); + if (skip_profile_frame) { + skip_profile_frame = false; + return; + } + if (p_final) { + EngineDebugger::get_singleton()->send_message("servers:profile_total", frame.serialize()); + } else { + EngineDebugger::get_singleton()->send_message("servers:profile_frame", frame.serialize()); + } + } +}; + +struct RemoteDebugger::VisualProfiler { + + typedef DebuggerMarshalls::ServerInfo ServerInfo; + typedef DebuggerMarshalls::ServerFunctionInfo ServerFunctionInfo; + + Map<StringName, ServerInfo> server_data; + + void toggle(bool p_enable, const Array &p_opts) { + VS::get_singleton()->set_frame_profiling_enabled(p_enable); + } + + void add(const Array &p_data) {} + + void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { + Vector<VS::FrameProfileArea> profile_areas = VS::get_singleton()->get_frame_profile(); + DebuggerMarshalls::VisualProfilerFrame frame; + if (!profile_areas.size()) + return; + + frame.frame_number = VS::get_singleton()->get_frame_profile_frame(); + frame.areas.append_array(profile_areas); + EngineDebugger::get_singleton()->send_message("visual:profile_frame", frame.serialize()); + } +}; + +struct RemoteDebugger::PerformanceProfiler { + + Object *performance = NULL; + int last_perf_time = 0; + + void toggle(bool p_enable, const Array &p_opts) {} + void add(const Array &p_data) {} + void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { + if (!performance) + return; + + uint64_t pt = OS::get_singleton()->get_ticks_msec(); + if (pt - last_perf_time < 1000) + return; + last_perf_time = pt; + int max = performance->get("MONITOR_MAX"); + Array arr; + arr.resize(max); + for (int i = 0; i < max; i++) { + arr[i] = performance->call("get_monitor", i); + } + EngineDebugger::get_singleton()->send_message("performance:profile_frame", arr); + } + + PerformanceProfiler(Object *p_performance) { + performance = p_performance; + } +}; + +void RemoteDebugger::_send_resource_usage() { + + DebuggerMarshalls::ResourceUsage usage; + + List<VS::TextureInfo> tinfo; + VS::get_singleton()->texture_debug_usage(&tinfo); + + for (List<VS::TextureInfo>::Element *E = tinfo.front(); E; E = E->next()) { + + DebuggerMarshalls::ResourceInfo info; + info.path = E->get().path; + info.vram = E->get().bytes; + info.id = E->get().texture; + info.type = "Texture"; + if (E->get().depth == 0) { + info.format = itos(E->get().width) + "x" + itos(E->get().height) + " " + Image::get_format_name(E->get().format); + } else { + info.format = itos(E->get().width) + "x" + itos(E->get().height) + "x" + itos(E->get().depth) + " " + Image::get_format_name(E->get().format); + } + usage.infos.push_back(info); + } + + EngineDebugger::get_singleton()->send_message("memory:usage", usage.serialize()); +} + +Error RemoteDebugger::_put_msg(String p_message, Array p_data) { + Array msg; + msg.push_back(p_message); + msg.push_back(p_data); + Error err = peer->put_message(msg); + if (err != OK) + n_messages_dropped++; + return err; +} + +void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) { + + if (p_type == ERR_HANDLER_SCRIPT) + return; //ignore script errors, those go through debugger + + RemoteDebugger *rd = (RemoteDebugger *)p_this; + if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive errors during flush. + return; + + Vector<ScriptLanguage::StackInfo> si; + + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + si = ScriptServer::get_language(i)->debug_get_current_stack_info(); + if (si.size()) + break; + } + + // send_error will lock internally. + rd->script_debugger->send_error(p_func, p_file, p_line, p_err, p_descr, p_type, si); +} + +void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p_error) { + + RemoteDebugger *rd = (RemoteDebugger *)p_this; + + if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive prints during flush. + return; + + String s = p_string; + int allowed_chars = MIN(MAX(rd->max_chars_per_second - rd->char_count, 0), s.length()); + + if (allowed_chars == 0) + return; + + if (allowed_chars < s.length()) { + s = s.substr(0, allowed_chars); + } + + MutexLock lock(rd->mutex); + + rd->char_count += allowed_chars; + bool overflowed = rd->char_count >= rd->max_chars_per_second; + if (rd->is_peer_connected()) { + if (overflowed) + s += "[...]"; + rd->output_strings.push_back(s); + + if (overflowed) { + rd->output_strings.push_back("[output overflow, print less text!]"); + } + } +} + +RemoteDebugger::ErrorMessage RemoteDebugger::_create_overflow_error(const String &p_what, const String &p_descr) { + ErrorMessage oe; + oe.error = p_what; + oe.error_descr = p_descr; + oe.warning = false; + uint64_t time = OS::get_singleton()->get_ticks_msec(); + oe.hr = time / 3600000; + oe.min = (time / 60000) % 60; + oe.sec = (time / 1000) % 60; + oe.msec = time % 1000; + return oe; +} + +void RemoteDebugger::flush_output() { + flush_thread = Thread::get_caller_id(); + flushing = true; + MutexLock lock(mutex); + if (!is_peer_connected()) + return; + + if (n_messages_dropped > 0) { + ErrorMessage err_msg = _create_overflow_error("TOO_MANY_MESSAGES", "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped. Profiling might misbheave, try raising 'network/limits/debugger/max_queued_messages' in project setting."); + if (_put_msg("error", err_msg.serialize()) == OK) + n_messages_dropped = 0; + } + + if (output_strings.size()) { + + // Join output strings so we generate less messages. + Vector<String> strings; + strings.resize(output_strings.size()); + String *w = strings.ptrw(); + for (int i = 0; i < output_strings.size(); i++) { + w[i] = output_strings[i]; + } + + Array arr; + arr.push_back(strings); + _put_msg("output", arr); + output_strings.clear(); + } + + while (errors.size()) { + ErrorMessage oe = errors.front()->get(); + _put_msg("error", oe.serialize()); + errors.pop_front(); + } + + // Update limits + uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000; + + if (ticks - last_reset > 1000) { + last_reset = ticks; + char_count = 0; + err_count = 0; + n_errors_dropped = 0; + warn_count = 0; + n_warnings_dropped = 0; + } + flushing = false; +} + +void RemoteDebugger::send_message(const String &p_message, const Array &p_args) { + + MutexLock lock(mutex); + if (is_peer_connected()) { + _put_msg(p_message, p_args); + } +} + +void RemoteDebugger::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type) { + + ErrorMessage oe; + oe.error = p_err; + oe.error_descr = p_descr; + oe.source_file = p_file; + oe.source_line = p_line; + oe.source_func = p_func; + oe.warning = p_type == ERR_HANDLER_WARNING; + uint64_t time = OS::get_singleton()->get_ticks_msec(); + oe.hr = time / 3600000; + oe.min = (time / 60000) % 60; + oe.sec = (time / 1000) % 60; + oe.msec = time % 1000; + oe.callstack.append_array(script_debugger->get_error_stack_info()); + + if (flushing && Thread::get_caller_id() == flush_thread) // Can't handle recursive errors during flush. + return; + + MutexLock lock(mutex); + + if (oe.warning) { + warn_count++; + } else { + err_count++; + } + + if (is_peer_connected()) { + + if (oe.warning) { + if (warn_count > max_warnings_per_second) { + n_warnings_dropped++; + if (n_warnings_dropped == 1) { + // Only print one message about dropping per second + ErrorMessage overflow = _create_overflow_error("TOO_MANY_WARNINGS", "Too many warnings! Ignoring warnings for up to 1 second."); + errors.push_back(overflow); + } + } else { + errors.push_back(oe); + } + } else { + if (err_count > max_errors_per_second) { + n_errors_dropped++; + if (n_errors_dropped == 1) { + // Only print one message about dropping per second + ErrorMessage overflow = _create_overflow_error("TOO_MANY_ERRORS", "Too many errors! Ignoring errors for up to 1 second."); + errors.push_back(overflow); + } + } else { + errors.push_back(oe); + } + } + } +} + +void RemoteDebugger::_send_stack_vars(List<String> &p_names, List<Variant> &p_vals, int p_type) { + DebuggerMarshalls::ScriptStackVariable stvar; + List<String>::Element *E = p_names.front(); + List<Variant>::Element *F = p_vals.front(); + while (E) { + stvar.name = E->get(); + stvar.value = F->get(); + stvar.type = p_type; + send_message("stack_frame_var", stvar.serialize()); + E = E->next(); + F = F->next(); + } +} + +Error RemoteDebugger::_try_capture(const String &p_msg, const Array &p_data, bool &r_captured) { + const int idx = p_msg.find(":"); + r_captured = false; + if (idx < 0) { // No prefix, unknown message. + return OK; + } + const String cap = p_msg.substr(0, idx); + if (!has_capture(cap)) + return ERR_UNAVAILABLE; // Unknown message... + const String msg = p_msg.substr(idx + 1); + return capture_parse(cap, msg, p_data, r_captured); +} + +void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { + + //this function is called when there is a debugger break (bug on script) + //or when execution is paused from editor + + if (script_debugger->is_skipping_breakpoints() && !p_is_error_breakpoint) + return; + + ERR_FAIL_COND_MSG(!is_peer_connected(), "Script Debugger failed to connect, but being used anyway."); + + ScriptLanguage *script_lang = script_debugger->get_break_language(); + const String error_str = script_lang ? script_lang->debug_get_error() : ""; + Array msg; + msg.push_back(p_can_continue); + msg.push_back(error_str); + send_message("debug_enter", msg); + + servers_profiler->skip_profile_frame = true; // Avoid frame time spike in debug. + + Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode(); + if (mouse_mode != Input::MOUSE_MODE_VISIBLE) + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + + uint64_t loop_begin_usec = 0; + uint64_t loop_time_sec = 0; + while (is_peer_connected()) { + loop_begin_usec = OS::get_singleton()->get_ticks_usec(); + + flush_output(); + peer->poll(); + + if (peer->has_message()) { + + Array cmd = peer->get_message(); + + ERR_CONTINUE(cmd.size() != 2); + ERR_CONTINUE(cmd[0].get_type() != Variant::STRING); + ERR_CONTINUE(cmd[1].get_type() != Variant::ARRAY); + + String command = cmd[0]; + Array data = cmd[1]; + + if (command == "step") { + script_debugger->set_depth(-1); + script_debugger->set_lines_left(1); + break; + + } else if (command == "next") { + script_debugger->set_depth(0); + script_debugger->set_lines_left(1); + break; + + } else if (command == "continue") { + script_debugger->set_depth(-1); + script_debugger->set_lines_left(-1); + OS::get_singleton()->move_window_to_foreground(); + break; + + } else if (command == "break") { + ERR_PRINT("Got break when already broke!"); + break; + + } else if (command == "get_stack_dump") { + ERR_FAIL_COND(!script_lang); + DebuggerMarshalls::ScriptStackDump dump; + int slc = script_lang->debug_get_stack_level_count(); + for (int i = 0; i < slc; i++) { + ScriptLanguage::StackInfo frame; + frame.file = script_lang->debug_get_stack_level_source(i); + frame.line = script_lang->debug_get_stack_level_line(i); + frame.func = script_lang->debug_get_stack_level_function(i); + dump.frames.push_back(frame); + } + send_message("stack_dump", dump.serialize()); + + } else if (command == "get_stack_frame_vars") { + ERR_FAIL_COND(data.size() != 1); + ERR_FAIL_COND(!script_lang); + int lv = data[0]; + + List<String> members; + List<Variant> member_vals; + if (ScriptInstance *inst = script_lang->debug_get_stack_level_instance(lv)) { + members.push_back("self"); + member_vals.push_back(inst->get_owner()); + } + script_lang->debug_get_stack_level_members(lv, &members, &member_vals); + ERR_FAIL_COND(members.size() != member_vals.size()); + + List<String> locals; + List<Variant> local_vals; + script_lang->debug_get_stack_level_locals(lv, &locals, &local_vals); + ERR_FAIL_COND(locals.size() != local_vals.size()); + + List<String> globals; + List<Variant> globals_vals; + script_lang->debug_get_globals(&globals, &globals_vals); + ERR_FAIL_COND(globals.size() != globals_vals.size()); + + send_message("stack_frame_vars", Array()); + _send_stack_vars(locals, local_vals, 0); + _send_stack_vars(members, member_vals, 1); + _send_stack_vars(globals, globals_vals, 2); + + } else if (command == "reload_scripts") { + reload_all_scripts = true; + + } else if (command == "breakpoint") { + ERR_FAIL_COND(data.size() < 3); + bool set = data[2]; + if (set) + script_debugger->insert_breakpoint(data[1], data[0]); + else + script_debugger->remove_breakpoint(data[1], data[0]); + + } else if (command == "set_skip_breakpoints") { + ERR_FAIL_COND(data.size() < 1); + script_debugger->set_skip_breakpoints(data[0]); + } else { + bool captured = false; + ERR_CONTINUE(_try_capture(command, data, captured) != OK); + if (!captured) + WARN_PRINT("Unknown message received from debugger: " + command); + } + } else { + OS::get_singleton()->delay_usec(10000); + OS::get_singleton()->process_and_drop_events(); + } + + // This is for the camera override to stay live even when the game is paused from the editor + loop_time_sec = (OS::get_singleton()->get_ticks_usec() - loop_begin_usec) / 1000000.0f; + VisualServer::get_singleton()->sync(); + if (VisualServer::get_singleton()->has_changed()) { + VisualServer::get_singleton()->draw(true, loop_time_sec * Engine::get_singleton()->get_time_scale()); + } + } + + send_message("debug_exit", Array()); + + if (mouse_mode != Input::MOUSE_MODE_VISIBLE) + Input::get_singleton()->set_mouse_mode(mouse_mode); +} + +void RemoteDebugger::poll_events(bool p_is_idle) { + if (peer.is_null()) + return; + + flush_output(); + peer->poll(); + while (peer->has_message()) { + + Array arr = peer->get_message(); + + ERR_CONTINUE(arr.size() != 2); + ERR_CONTINUE(arr[0].get_type() != Variant::STRING); + ERR_CONTINUE(arr[1].get_type() != Variant::ARRAY); + + const String cmd = arr[0]; + const int idx = cmd.find(":"); + bool parsed = false; + if (idx < 0) { // Not prefix, use scripts capture. + capture_parse("core", cmd, arr[1], parsed); + continue; + } + + const String cap = cmd.substr(0, idx); + if (!has_capture(cap)) + continue; // Unknown message... + + const String msg = cmd.substr(idx + 1); + capture_parse(cap, msg, arr[1], parsed); + } + + // Reload scripts during idle poll only. + if (p_is_idle && reload_all_scripts) { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->reload_all_scripts(); + } + reload_all_scripts = false; + } +} + +Error RemoteDebugger::_core_capture(const String &p_cmd, const Array &p_data, bool &r_captured) { + r_captured = true; + if (p_cmd == "reload_scripts") { + reload_all_scripts = true; + + } else if (p_cmd == "breakpoint") { + ERR_FAIL_COND_V(p_data.size() < 3, ERR_INVALID_DATA); + bool set = p_data[2]; + if (set) + script_debugger->insert_breakpoint(p_data[1], p_data[0]); + else + script_debugger->remove_breakpoint(p_data[1], p_data[0]); + + } else if (p_cmd == "set_skip_breakpoints") { + ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA); + script_debugger->set_skip_breakpoints(p_data[0]); + } else if (p_cmd == "memory") { + _send_resource_usage(); + } else if (p_cmd == "break") { + script_debugger->debug(script_debugger->get_break_language()); + } else { + r_captured = false; + } + return OK; +} + +Error RemoteDebugger::_profiler_capture(const String &p_cmd, const Array &p_data, bool &r_captured) { + r_captured = false; + ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_data[0].get_type() != Variant::BOOL, ERR_INVALID_DATA); + ERR_FAIL_COND_V(!has_profiler(p_cmd), ERR_UNAVAILABLE); + Array opts; + if (p_data.size() > 1) { // Optional profiler parameters. + ERR_FAIL_COND_V(p_data[1].get_type() != Variant::ARRAY, ERR_INVALID_DATA); + opts = p_data[1]; + } + r_captured = true; + profiler_enable(p_cmd, p_data[0], opts); + return OK; +} + +RemoteDebugger *RemoteDebugger::create_for_uri(const String &p_uri) { + Ref<RemoteDebuggerPeer> peer = RemoteDebuggerPeer::create_from_uri(p_uri); + if (peer.is_valid()) + return memnew(RemoteDebugger(peer)); + return NULL; +} + +RemoteDebugger::RemoteDebugger(Ref<RemoteDebuggerPeer> p_peer) { + peer = p_peer; + max_chars_per_second = GLOBAL_GET("network/limits/debugger/max_chars_per_second"); + max_errors_per_second = GLOBAL_GET("network/limits/debugger/max_errors_per_second"); + max_warnings_per_second = GLOBAL_GET("network/limits/debugger/max_warnings_per_second"); + + // Network Profiler + network_profiler = memnew(NetworkProfiler); + _bind_profiler("network", network_profiler); + + // Servers Profiler (audio/physics/...) + servers_profiler = memnew(ServersProfiler); + _bind_profiler("servers", servers_profiler); + + // Visual Profiler (cpu/gpu times) + visual_profiler = memnew(VisualProfiler); + _bind_profiler("visual", visual_profiler); + + // Performance Profiler + Object *perf = Engine::get_singleton()->get_singleton_object("Performance"); + if (perf) { + performance_profiler = memnew(PerformanceProfiler(perf)); + _bind_profiler("performance", performance_profiler); + profiler_enable("performance", true); + } + + // Core and profiler captures. + Capture core_cap(this, + [](void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) { + return ((RemoteDebugger *)p_user)->_core_capture(p_cmd, p_data, r_captured); + }); + register_message_capture("core", core_cap); + Capture profiler_cap(this, + [](void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) { + return ((RemoteDebugger *)p_user)->_profiler_capture(p_cmd, p_data, r_captured); + }); + register_message_capture("profiler", profiler_cap); + + // Error handlers + phl.printfunc = _print_handler; + phl.userdata = this; + add_print_handler(&phl); + + eh.errfunc = _err_handler; + eh.userdata = this; + add_error_handler(&eh); +} + +RemoteDebugger::~RemoteDebugger() { + remove_print_handler(&phl); + remove_error_handler(&eh); + + EngineDebugger::get_singleton()->unregister_profiler("servers"); + EngineDebugger::get_singleton()->unregister_profiler("network"); + EngineDebugger::get_singleton()->unregister_profiler("visual"); + if (EngineDebugger::has_profiler("performance")) { + EngineDebugger::get_singleton()->unregister_profiler("performance"); + } + memdelete(servers_profiler); + memdelete(network_profiler); + memdelete(visual_profiler); + if (performance_profiler) + memdelete(performance_profiler); +} diff --git a/core/debugger/remote_debugger.h b/core/debugger/remote_debugger.h new file mode 100644 index 0000000000..83789c67f9 --- /dev/null +++ b/core/debugger/remote_debugger.h @@ -0,0 +1,114 @@ +/*************************************************************************/ +/* remote_debugger.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef REMOTE_DEBUGGER_H +#define REMOTE_DEBUGGER_H + +#include "core/array.h" +#include "core/debugger/debugger_marshalls.h" +#include "core/debugger/engine_debugger.h" +#include "core/debugger/remote_debugger_peer.h" +#include "core/object.h" +#include "core/string_name.h" +#include "core/ustring.h" + +class RemoteDebugger : public EngineDebugger { + +private: + typedef DebuggerMarshalls::OutputError ErrorMessage; + + struct NetworkProfiler; + struct ServersProfiler; + struct ScriptsProfiler; + struct VisualProfiler; + struct PerformanceProfiler; + + NetworkProfiler *network_profiler = NULL; + ServersProfiler *servers_profiler = NULL; + VisualProfiler *visual_profiler = NULL; + PerformanceProfiler *performance_profiler = NULL; + + Ref<RemoteDebuggerPeer> peer; + + List<String> output_strings; + List<ErrorMessage> errors; + + int n_messages_dropped = 0; + int max_errors_per_second = 0; + int max_chars_per_second = 0; + int max_warnings_per_second = 0; + int n_errors_dropped = 0; + int n_warnings_dropped = 0; + int char_count = 0; + int err_count = 0; + int warn_count = 0; + int last_reset = 0; + bool reload_all_scripts = false; + + // Make handlers and send_message thread safe. + Mutex mutex; + bool flushing = false; + Thread::ID flush_thread = 0; + + PrintHandlerList phl; + static void _print_handler(void *p_this, const String &p_string, bool p_error); + ErrorHandlerList eh; + static void _err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type); + + ErrorMessage _create_overflow_error(const String &p_what, const String &p_descr); + Error _put_msg(String p_message, Array p_data); + + bool is_peer_connected() { return peer->is_peer_connected(); } + void flush_output(); + + void _send_resource_usage(); + void _send_stack_vars(List<String> &p_names, List<Variant> &p_vals, int p_type); + + Error _profiler_capture(const String &p_cmd, const Array &p_data, bool &r_captured); + Error _core_capture(const String &p_cmd, const Array &p_data, bool &r_captured); + + template <typename T> + void _bind_profiler(const String &p_name, T *p_prof); + Error _try_capture(const String &p_name, const Array &p_data, bool &r_captured); + +public: + static RemoteDebugger *create_for_uri(const String &p_uri); + + // Overrides + void poll_events(bool p_is_idle); + void send_message(const String &p_message, const Array &p_args); + void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type); + void debug(bool p_can_continue = true, bool p_is_error_breakpoint = false); + + RemoteDebugger(Ref<RemoteDebuggerPeer> p_peer); + ~RemoteDebugger(); +}; + +#endif // REMOTE_DEBUGGER_H diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp new file mode 100644 index 0000000000..42c2c8e309 --- /dev/null +++ b/core/debugger/remote_debugger_peer.cpp @@ -0,0 +1,242 @@ +/*************************************************************************/ +/* remote_debugger_peer.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "remote_debugger_peer.h" + +#include "core/io/marshalls.h" +#include "core/os/os.h" +#include "core/project_settings.h" + +bool RemoteDebuggerPeerTCP::is_peer_connected() { + return connected; +} + +bool RemoteDebuggerPeerTCP::has_message() { + return in_queue.size() > 0; +} + +Array RemoteDebuggerPeerTCP::get_message() { + MutexLock lock(mutex); + ERR_FAIL_COND_V(!has_message(), Array()); + Array out = in_queue[0]; + in_queue.pop_front(); + return out; +} + +Error RemoteDebuggerPeerTCP::put_message(const Array &p_arr) { + MutexLock lock(mutex); + if (out_queue.size() >= max_queued_messages) + return ERR_OUT_OF_MEMORY; + + out_queue.push_back(p_arr); + return OK; +} + +int RemoteDebuggerPeerTCP::get_max_message_size() const { + return 8 << 20; // 8 MiB +} + +void RemoteDebuggerPeerTCP::close() { + if (thread) { + running = false; + Thread::wait_to_finish(thread); + memdelete(thread); + thread = NULL; + } + tcp_client->disconnect_from_host(); + out_buf.resize(0); + in_buf.resize(0); +} + +RemoteDebuggerPeerTCP::RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_tcp) { + // This means remote debugger takes 16 MiB just because it exists... + in_buf.resize((8 << 20) + 4); // 8 MiB should be way more than enough (need 4 extra bytes for encoding packet size). + out_buf.resize(8 << 20); // 8 MiB should be way more than enough + tcp_client = p_tcp; + if (tcp_client.is_valid()) { // Attaching to an already connected stream. + connected = true; +#ifndef NO_THREADS + running = true; + thread = Thread::create(_thread_func, this); +#endif + } else { + tcp_client.instance(); + } +} + +RemoteDebuggerPeerTCP::~RemoteDebuggerPeerTCP() { + close(); +} + +void RemoteDebuggerPeerTCP::_write_out() { + while (tcp_client->poll(NetSocket::POLL_TYPE_OUT) == OK) { + uint8_t *buf = out_buf.ptrw(); + if (out_left <= 0) { + if (out_queue.size() == 0) + break; // Nothing left to send + mutex.lock(); + Variant var = out_queue[0]; + out_queue.pop_front(); + mutex.unlock(); + int size = 0; + Error err = encode_variant(var, NULL, size); + ERR_CONTINUE(err != OK || size > out_buf.size() - 4); // 4 bytes separator. + encode_uint32(size, buf); + encode_variant(var, buf + 4, size); + out_left = size + 4; + out_pos = 0; + } + int sent = 0; + tcp_client->put_partial_data(buf + out_pos, out_left, sent); + out_left -= sent; + out_pos += sent; + } +} + +void RemoteDebuggerPeerTCP::_read_in() { + while (tcp_client->poll(NetSocket::POLL_TYPE_IN) == OK) { + uint8_t *buf = in_buf.ptrw(); + if (in_left <= 0) { + if (in_queue.size() > max_queued_messages) { + break; // Too many messages already in queue. + } + if (tcp_client->get_available_bytes() < 4) { + break; // Need 4 more bytes. + } + uint32_t size = 0; + int read = 0; + Error err = tcp_client->get_partial_data((uint8_t *)&size, 4, read); + ERR_CONTINUE(read != 4 || err != OK || size > (uint32_t)in_buf.size()); + in_left = size; + in_pos = 0; + } + int read = 0; + tcp_client->get_partial_data(buf + in_pos, in_left, read); + in_left -= read; + in_pos += read; + if (in_left == 0) { + Variant var; + Error err = decode_variant(var, buf, in_pos, &read); + ERR_CONTINUE(read != in_pos || err != OK); + ERR_CONTINUE_MSG(var.get_type() != Variant::ARRAY, "Malformed packet received, not an Array."); + mutex.lock(); + in_queue.push_back(var); + mutex.unlock(); + } + } +} + +Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_port) { + + IP_Address ip; + if (p_host.is_valid_ip_address()) + ip = p_host; + else + ip = IP::get_singleton()->resolve_hostname(p_host); + + int port = p_port; + + const int tries = 6; + int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 }; + + tcp_client->connect_to_host(ip, port); + + for (int i = 0; i < tries; i++) { + + if (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED) { + print_verbose("Remote Debugger: Connected!"); + break; + } else { + + const int ms = waits[i]; + OS::get_singleton()->delay_usec(ms * 1000); + print_verbose("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec."); + }; + }; + + if (tcp_client->get_status() != StreamPeerTCP::STATUS_CONNECTED) { + + ERR_PRINT("Remote Debugger: Unable to connect. Status: " + String::num(tcp_client->get_status()) + "."); + return FAILED; + }; + connected = true; +#ifndef NO_THREADS + running = true; + thread = Thread::create(_thread_func, this); +#endif + return OK; +} + +void RemoteDebuggerPeerTCP::_thread_func(void *p_ud) { + RemoteDebuggerPeerTCP *peer = (RemoteDebuggerPeerTCP *)p_ud; + while (peer->running && peer->is_peer_connected()) { + peer->_poll(); + if (!peer->is_peer_connected()) + break; + peer->tcp_client->poll(NetSocket::POLL_TYPE_IN_OUT, 1); + } +} + +void RemoteDebuggerPeerTCP::poll() { +#ifdef NO_THREADS + _poll(); +#endif +} + +void RemoteDebuggerPeerTCP::_poll() { + if (connected) { + _write_out(); + _read_in(); + connected = tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED; + } +} + +Ref<RemoteDebuggerPeer> RemoteDebuggerPeer::create_from_uri(const String p_uri) { + if (!p_uri.begins_with("tcp://")) + return Ref<RemoteDebuggerPeer>(); // Only TCP supported for now, more to come. + + String debug_host = p_uri.replace("tcp://", ""); + uint16_t debug_port = 6007; + + if (debug_host.find(":") != -1) { + int sep_pos = debug_host.find_last(":"); + debug_port = debug_host.substr(sep_pos + 1).to_int(); + debug_host = debug_host.substr(0, sep_pos); + } + Ref<RemoteDebuggerPeerTCP> peer = Ref<RemoteDebuggerPeer>(memnew(RemoteDebuggerPeerTCP)); + Error err = peer->connect_to_host(debug_host, debug_port); + if (err != OK) + return Ref<RemoteDebuggerPeer>(); + return peer; +} + +RemoteDebuggerPeer::RemoteDebuggerPeer() { + max_queued_messages = (int)GLOBAL_GET("network/limits/debugger/max_queued_messages"); +} diff --git a/core/debugger/remote_debugger_peer.h b/core/debugger/remote_debugger_peer.h new file mode 100644 index 0000000000..6fc3214a51 --- /dev/null +++ b/core/debugger/remote_debugger_peer.h @@ -0,0 +1,94 @@ +/*************************************************************************/ +/* remote_debugger_peer.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef REMOTE_DEBUGGER_PEER_H +#define REMOTE_DEBUGGER_PEER_H + +#include "core/io/stream_peer_tcp.h" +#include "core/os/mutex.h" +#include "core/os/thread.h" +#include "core/reference.h" +#include "core/ustring.h" + +class RemoteDebuggerPeer : public Reference { +protected: + int max_queued_messages = 4096; + +public: + static Ref<RemoteDebuggerPeer> create_from_uri(const String p_uri); + virtual bool is_peer_connected() = 0; + virtual bool has_message() = 0; + virtual Error put_message(const Array &p_arr) = 0; + virtual Array get_message() = 0; + virtual void close() = 0; + virtual void poll() = 0; + virtual int get_max_message_size() const = 0; + + RemoteDebuggerPeer(); +}; + +class RemoteDebuggerPeerTCP : public RemoteDebuggerPeer { +private: + Ref<StreamPeerTCP> tcp_client; + Mutex mutex; + Thread *thread = NULL; + List<Array> in_queue; + List<Array> out_queue; + int out_left = 0; + int out_pos = 0; + Vector<uint8_t> out_buf; + int in_left = 0; + int in_pos = 0; + Vector<uint8_t> in_buf; + bool connected = false; + bool running = false; + + static void _thread_func(void *p_ud); + + void _poll(); + void _write_out(); + void _read_in(); + +public: + Error connect_to_host(const String &p_host, uint16_t p_port); + + void poll(); + bool is_peer_connected(); + bool has_message(); + Array get_message(); + Error put_message(const Array &p_arr); + int get_max_message_size() const; + void close(); + + RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_stream = Ref<StreamPeerTCP>()); + ~RemoteDebuggerPeerTCP(); +}; + +#endif // REMOTE_DEBUGGER_PEER_H diff --git a/core/debugger/script_debugger.cpp b/core/debugger/script_debugger.cpp new file mode 100644 index 0000000000..935ad01d80 --- /dev/null +++ b/core/debugger/script_debugger.cpp @@ -0,0 +1,123 @@ +/*************************************************************************/ +/* script_debugger.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "script_debugger.h" + +#include "core/debugger/engine_debugger.h" + +void ScriptDebugger::set_lines_left(int p_left) { + + lines_left = p_left; +} + +int ScriptDebugger::get_lines_left() const { + + return lines_left; +} + +void ScriptDebugger::set_depth(int p_depth) { + + depth = p_depth; +} + +int ScriptDebugger::get_depth() const { + + return depth; +} + +void ScriptDebugger::insert_breakpoint(int p_line, const StringName &p_source) { + + if (!breakpoints.has(p_line)) + breakpoints[p_line] = Set<StringName>(); + breakpoints[p_line].insert(p_source); +} + +void ScriptDebugger::remove_breakpoint(int p_line, const StringName &p_source) { + + if (!breakpoints.has(p_line)) + return; + + breakpoints[p_line].erase(p_source); + if (breakpoints[p_line].size() == 0) + breakpoints.erase(p_line); +} +bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const { + + if (!breakpoints.has(p_line)) + return false; + return breakpoints[p_line].has(p_source); +} +bool ScriptDebugger::is_breakpoint_line(int p_line) const { + + return breakpoints.has(p_line); +} + +String ScriptDebugger::breakpoint_find_source(const String &p_source) const { + + return p_source; +} + +void ScriptDebugger::clear_breakpoints() { + + breakpoints.clear(); +} + +void ScriptDebugger::set_skip_breakpoints(bool p_skip_breakpoints) { + + skip_breakpoints = p_skip_breakpoints; +} + +bool ScriptDebugger::is_skipping_breakpoints() { + + return skip_breakpoints; +} + +void ScriptDebugger::debug(ScriptLanguage *p_lang, bool p_can_continue, bool p_is_error_breakpoint) { + ScriptLanguage *prev = break_lang; + break_lang = p_lang; + EngineDebugger::get_singleton()->debug(p_can_continue, p_is_error_breakpoint); + break_lang = prev; +} + +void ScriptDebugger::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<StackInfo> &p_stack_info) { + // Store stack info, this is ugly, but allows us to separate EngineDebugger and ScriptDebugger. There might be a better way. + error_stack_info.append_array(p_stack_info); + EngineDebugger::get_singleton()->send_error(p_func, p_file, p_line, p_err, p_descr, p_type); + error_stack_info.resize(0); +} + +Vector<ScriptLanguage::StackInfo> ScriptDebugger::get_error_stack_info() const { + return error_stack_info; +} + +ScriptLanguage *ScriptDebugger::get_break_language() const { + + return break_lang; +} diff --git a/core/debugger/script_debugger.h b/core/debugger/script_debugger.h new file mode 100644 index 0000000000..d8ddf353bf --- /dev/null +++ b/core/debugger/script_debugger.h @@ -0,0 +1,80 @@ +/*************************************************************************/ +/* script_debugger.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef SCRIPT_DEBUGGER_H +#define SCRIPT_DEBUGGER_H + +#include "core/map.h" +#include "core/script_language.h" +#include "core/set.h" +#include "core/string_name.h" +#include "core/vector.h" + +class ScriptDebugger { + + typedef ScriptLanguage::StackInfo StackInfo; + + int lines_left = -1; + int depth = -1; + bool skip_breakpoints = false; + + Map<int, Set<StringName> > breakpoints; + + ScriptLanguage *break_lang = NULL; + Vector<StackInfo> error_stack_info; + +public: + void set_lines_left(int p_left); + int get_lines_left() const; + + void set_depth(int p_depth); + int get_depth() const; + + String breakpoint_find_source(const String &p_source) const; + void set_break_language(ScriptLanguage *p_lang) { break_lang = p_lang; } + ScriptLanguage *get_break_language() { return break_lang; } + void set_skip_breakpoints(bool p_skip_breakpoints); + bool is_skipping_breakpoints(); + void insert_breakpoint(int p_line, const StringName &p_source); + void remove_breakpoint(int p_line, const StringName &p_source); + bool is_breakpoint(int p_line, const StringName &p_source) const; + bool is_breakpoint_line(int p_line) const; + void clear_breakpoints(); + const Map<int, Set<StringName> > &get_breakpoints() const { return breakpoints; } + + void debug(ScriptLanguage *p_lang, bool p_can_continue = true, bool p_is_error_breakpoint = false); + ScriptLanguage *get_break_language() const; + + void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<StackInfo> &p_stack_info); + Vector<StackInfo> get_error_stack_info() const; + ScriptDebugger() {} +}; + +#endif diff --git a/core/error_macros.h b/core/error_macros.h index e4d7609e04..8818dcbe77 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -502,11 +502,11 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li * * The current function returns `m_retval`. */ -#define ERR_FAIL_V(m_retval) \ - if (1) { \ - _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_retval)); \ - return m_retval; \ - } else \ +#define ERR_FAIL_V(m_retval) \ + if (1) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " _STR(m_retval)); \ + return m_retval; \ + } else \ ((void)0) /** @@ -515,11 +515,11 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li * * Prints `m_msg`, and the current function returns `m_retval`. */ -#define ERR_FAIL_V_MSG(m_retval, m_msg) \ - if (1) { \ - _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_retval), DEBUG_STR(m_msg)); \ - return m_retval; \ - } else \ +#define ERR_FAIL_V_MSG(m_retval, m_msg) \ + if (1) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " _STR(m_retval), DEBUG_STR(m_msg)); \ + return m_retval; \ + } else \ ((void)0) /** diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index d7c82fddd9..c29df07624 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -30,6 +30,7 @@ #include "multiplayer_api.h" +#include "core/debugger/engine_debugger.h" #include "core/io/marshalls.h" #include "scene/main/node.h" #include <stdint.h> @@ -172,6 +173,28 @@ Ref<NetworkedMultiplayerPeer> MultiplayerAPI::get_network_peer() const { return network_peer; } +#ifdef DEBUG_ENABLED +void _profile_node_data(const String &p_what, ObjectID p_id) { + if (EngineDebugger::is_profiling("multiplayer")) { + Array values; + values.push_back("node"); + values.push_back(p_id); + values.push_back(p_what); + EngineDebugger::profiler_add_frame_data("multiplayer", values); + } +} +void _profile_bandwidth_data(const String &p_inout, int p_size) { + if (EngineDebugger::is_profiling("multiplayer")) { + Array values; + values.push_back("bandwidth"); + values.push_back(p_inout); + values.push_back(OS::get_singleton()->get_ticks_msec()); + values.push_back(p_size); + EngineDebugger::profiler_add_frame_data("multiplayer", values); + } +} +#endif + // Returns the packet size stripping the node path added when the node is not yet cached. int get_packet_len(uint32_t p_node_target, int p_packet_len) { if (p_node_target & 0x80000000) { @@ -188,11 +211,7 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ ERR_FAIL_COND_MSG(p_packet_len < 1, "Invalid packet received. Size too small."); #ifdef DEBUG_ENABLED - if (profiling) { - bandwidth_incoming_data.write[bandwidth_incoming_pointer].timestamp = OS::get_singleton()->get_ticks_msec(); - bandwidth_incoming_data.write[bandwidth_incoming_pointer].packet_size = p_packet_len; - bandwidth_incoming_pointer = (bandwidth_incoming_pointer + 1) % bandwidth_incoming_data.size(); - } + _profile_bandwidth_data("in", p_packet_len); #endif // Extract the `packet_type` from the LSB three bits: @@ -381,11 +400,7 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id, argp.resize(argc); #ifdef DEBUG_ENABLED - if (profiling) { - ObjectID id = p_node->get_instance_id(); - _init_node_profile(id); - profiler_frame_data[id].incoming_rpc += 1; - } + _profile_node_data("in_rpc", p_node->get_instance_id()); #endif if (byte_only) { @@ -437,11 +452,7 @@ void MultiplayerAPI::_process_rset(Node *p_node, const uint16_t p_rpc_property_i ERR_FAIL_COND_MSG(!can_call, "RSET '" + String(name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + "."); #ifdef DEBUG_ENABLED - if (profiling) { - ObjectID id = p_node->get_instance_id(); - _init_node_profile(id); - profiler_frame_data[id].incoming_rset += 1; - } + _profile_node_data("in_rset", p_node->get_instance_id()); #endif Variant value; @@ -863,7 +874,8 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p if (method_id == UINT16_MAX && p_from->get_script_instance()) { method_id = p_from->get_script_instance()->get_rpc_method_id(p_name); } - ERR_FAIL_COND_MSG(method_id == UINT16_MAX, "Unable to take the `method_id` for the function:" + p_name + ". this can happen only if this method is not marked as `remote`."); + ERR_FAIL_COND_MSG(method_id == UINT16_MAX, + vformat("Unable to take the `method_id` for the function \"%s\" at path: \"%s\". This happens when the method is not marked as `remote`.", p_name, p_from->get_path())); if (method_id <= UINT8_MAX) { // The ID fits in 1 byte @@ -912,11 +924,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p packet_cache.write[0] = command_type + (node_id_compression << NODE_ID_COMPRESSION_SHIFT) + (name_id_compression << NAME_ID_COMPRESSION_SHIFT) + ((byte_only_or_no_args ? 1 : 0) << BYTE_ONLY_OR_NO_ARGS_SHIFT); #ifdef DEBUG_ENABLED - if (profiling) { - bandwidth_outgoing_data.write[bandwidth_outgoing_pointer].timestamp = OS::get_singleton()->get_ticks_msec(); - bandwidth_outgoing_data.write[bandwidth_outgoing_pointer].packet_size = ofs; - bandwidth_outgoing_pointer = (bandwidth_outgoing_pointer + 1) % bandwidth_outgoing_data.size(); - } + _profile_bandwidth_data("out", ofs); #endif // Take chance and set transfer mode, since all send methods will use it. @@ -1031,11 +1039,7 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const if (!skip_rpc) { #ifdef DEBUG_ENABLED - if (profiling) { - ObjectID id = p_node->get_instance_id(); - _init_node_profile(id); - profiler_frame_data[id].outgoing_rpc += 1; - } + _profile_node_data("out_rpc", p_node->get_instance_id()); #endif _send_rpc(p_node, p_peer_id, p_unreliable, false, p_method, p_arg, p_argcount); @@ -1130,11 +1134,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const } #ifdef DEBUG_ENABLED - if (profiling) { - ObjectID id = p_node->get_instance_id(); - _init_node_profile(id); - profiler_frame_data[id].outgoing_rset += 1; - } + _profile_node_data("out_rset", p_node->get_instance_id()); #endif const Variant *vptr = &p_value; @@ -1220,95 +1220,6 @@ bool MultiplayerAPI::is_object_decoding_allowed() const { return allow_object_decoding; } -void MultiplayerAPI::profiling_start() { -#ifdef DEBUG_ENABLED - profiling = true; - profiler_frame_data.clear(); - - bandwidth_incoming_pointer = 0; - bandwidth_incoming_data.resize(16384); // ~128kB - for (int i = 0; i < bandwidth_incoming_data.size(); ++i) { - bandwidth_incoming_data.write[i].packet_size = -1; - } - - bandwidth_outgoing_pointer = 0; - bandwidth_outgoing_data.resize(16384); // ~128kB - for (int i = 0; i < bandwidth_outgoing_data.size(); ++i) { - bandwidth_outgoing_data.write[i].packet_size = -1; - } -#endif -} - -void MultiplayerAPI::profiling_end() { -#ifdef DEBUG_ENABLED - profiling = false; - bandwidth_incoming_data.clear(); - bandwidth_outgoing_data.clear(); -#endif -} - -int MultiplayerAPI::get_profiling_frame(ProfilingInfo *r_info) { - int i = 0; -#ifdef DEBUG_ENABLED - for (Map<ObjectID, ProfilingInfo>::Element *E = profiler_frame_data.front(); E; E = E->next()) { - r_info[i] = E->get(); - ++i; - } - profiler_frame_data.clear(); -#endif - return i; -} - -int MultiplayerAPI::get_incoming_bandwidth_usage() { -#ifdef DEBUG_ENABLED - return _get_bandwidth_usage(bandwidth_incoming_data, bandwidth_incoming_pointer); -#else - return 0; -#endif -} - -int MultiplayerAPI::get_outgoing_bandwidth_usage() { -#ifdef DEBUG_ENABLED - return _get_bandwidth_usage(bandwidth_outgoing_data, bandwidth_outgoing_pointer); -#else - return 0; -#endif -} - -#ifdef DEBUG_ENABLED -int MultiplayerAPI::_get_bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer) { - int total_bandwidth = 0; - - uint32_t timestamp = OS::get_singleton()->get_ticks_msec(); - uint32_t final_timestamp = timestamp - 1000; - - int i = (p_pointer + p_buffer.size() - 1) % p_buffer.size(); - - while (i != p_pointer && p_buffer[i].packet_size > 0) { - if (p_buffer[i].timestamp < final_timestamp) { - return total_bandwidth; - } - total_bandwidth += p_buffer[i].packet_size; - i = (i + p_buffer.size() - 1) % p_buffer.size(); - } - - ERR_FAIL_COND_V_MSG(i == p_pointer, total_bandwidth, "Reached the end of the bandwidth profiler buffer, values might be inaccurate."); - return total_bandwidth; -} - -void MultiplayerAPI::_init_node_profile(ObjectID p_node) { - if (profiler_frame_data.has(p_node)) - return; - profiler_frame_data.insert(p_node, ProfilingInfo()); - profiler_frame_data[p_node].node = p_node; - profiler_frame_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path(); - profiler_frame_data[p_node].incoming_rpc = 0; - profiler_frame_data[p_node].incoming_rset = 0; - profiler_frame_data[p_node].outgoing_rpc = 0; - profiler_frame_data[p_node].outgoing_rset = 0; -} -#endif - void MultiplayerAPI::_bind_methods() { ClassDB::bind_method(D_METHOD("set_root_node", "node"), &MultiplayerAPI::set_root_node); ClassDB::bind_method(D_METHOD("send_bytes", "bytes", "id", "mode"), &MultiplayerAPI::send_bytes, DEFVAL(NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST), DEFVAL(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE)); @@ -1352,9 +1263,6 @@ MultiplayerAPI::MultiplayerAPI() : allow_object_decoding(false) { rpc_sender_id = 0; root_node = NULL; -#ifdef DEBUG_ENABLED - profiling = false; -#endif clear(); } diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index a706a0e450..52f918aefa 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -38,16 +38,6 @@ class MultiplayerAPI : public Reference { GDCLASS(MultiplayerAPI, Reference); -public: - struct ProfilingInfo { - ObjectID node; - String node_path; - int incoming_rpc; - int incoming_rset; - int outgoing_rpc; - int outgoing_rset; - }; - private: //path sent caches struct PathSentCache { @@ -65,23 +55,6 @@ private: Map<int, NodeInfo> nodes; }; -#ifdef DEBUG_ENABLED - struct BandwidthFrame { - uint32_t timestamp; - int packet_size; - }; - - int bandwidth_incoming_pointer; - Vector<BandwidthFrame> bandwidth_incoming_data; - int bandwidth_outgoing_pointer; - Vector<BandwidthFrame> bandwidth_outgoing_data; - Map<ObjectID, ProfilingInfo> profiler_frame_data; - bool profiling; - - void _init_node_profile(ObjectID p_node); - int _get_bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer); -#endif - Ref<NetworkedMultiplayerPeer> network_peer; int rpc_sender_id; Set<int> connected_peers; @@ -169,13 +142,6 @@ public: void set_allow_object_decoding(bool p_enable); bool is_object_decoding_allowed() const; - void profiling_start(); - void profiling_end(); - - int get_profiling_frame(ProfilingInfo *r_info); - int get_incoming_bandwidth_usage(); - int get_outgoing_bandwidth_usage(); - MultiplayerAPI(); ~MultiplayerAPI(); }; diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 044431743a..f0c5816d73 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -288,6 +288,11 @@ void StreamPeerTCP::disconnect_from_host() { peer_port = 0; } +Error StreamPeerTCP::poll(NetSocket::PollType p_type, int timeout) { + ERR_FAIL_COND_V(_sock.is_null() || !_sock->is_open(), ERR_UNAVAILABLE); + return _sock->poll(p_type, timeout); +} + Error StreamPeerTCP::put_data(const uint8_t *p_data, int p_bytes) { int total; diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index f16d4a2bd4..327aa3cc3b 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -78,6 +78,9 @@ public: void set_no_delay(bool p_enabled); + // Poll functions (wait or check for writable, readable) + Error poll(NetSocket::PollType p_type, int timeout = 0); + // Read/Write from StreamPeer Error put_data(const uint8_t *p_data, int p_bytes); Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent); diff --git a/core/math/expression.cpp b/core/math/expression.cpp index 058673b681..04fda9d09a 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -1839,7 +1839,7 @@ Expression::ENode *Expression::_parse_expression() { } } - //consecutively do unary opeators + //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { OperatorNode *op = alloc_node<OperatorNode>(); diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index ac65ce3509..8fd5a056fa 100644 --- a/core/math/random_pcg.h +++ b/core/math/random_pcg.h @@ -37,10 +37,10 @@ #include "thirdparty/misc/pcg.h" -#if defined(__GNUC__) || (_llvm_has_builtin(__builtin_clz)) +#if defined(__GNUC__) #define CLZ32(x) __builtin_clz(x) #elif defined(_MSC_VER) -#include "intrin.h" +#include <intrin.h> static int __bsr_clz32(uint32_t x) { unsigned long index; _BitScanReverse(&index, x); @@ -50,11 +50,11 @@ static int __bsr_clz32(uint32_t x) { #else #endif -#if defined(__GNUC__) || (_llvm_has_builtin(__builtin_ldexp) && _llvm_has_builtin(__builtin_ldexpf)) +#if defined(__GNUC__) #define LDEXP(s, e) __builtin_ldexp(s, e) #define LDEXPF(s, e) __builtin_ldexpf(s, e) #else -#include "math.h" +#include <math.h> #define LDEXP(s, e) ldexp(s, e) #define LDEXPF(s, e) ldexp(s, e) #endif diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp index 74c308f646..97297dca28 100644 --- a/core/os/mutex.cpp +++ b/core/os/mutex.cpp @@ -40,7 +40,11 @@ void _global_unlock() { _global_mutex.unlock(); } +#ifndef NO_THREADS + template class MutexImpl<std::recursive_mutex>; template class MutexImpl<std::mutex>; template class MutexLock<MutexImpl<std::recursive_mutex> >; template class MutexLock<MutexImpl<std::mutex> >; + +#endif diff --git a/core/os/mutex.h b/core/os/mutex.h index 8d7b378d60..9033f0cb06 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -71,9 +71,22 @@ public: } }; +using Mutex = MutexImpl<std::recursive_mutex>; // Recursive, for general use +using BinaryMutex = MutexImpl<std::mutex>; // Non-recursive, handle with care + +extern template class MutexImpl<std::recursive_mutex>; +extern template class MutexImpl<std::mutex>; +extern template class MutexLock<MutexImpl<std::recursive_mutex> >; +extern template class MutexLock<MutexImpl<std::mutex> >; + #else -template <class StdMutexType> +class FakeMutex { + + FakeMutex(){}; +}; + +template <class MutexT> class MutexImpl { public: _ALWAYS_INLINE_ void lock() const {} @@ -87,14 +100,9 @@ public: explicit MutexLock(const MutexT &p_mutex) {} }; -#endif // !NO_THREADS - -using Mutex = MutexImpl<std::recursive_mutex>; // Recursive, for general use -using BinaryMutex = MutexImpl<std::mutex>; // Non-recursive, handle with care +using Mutex = MutexImpl<FakeMutex>; +using BinaryMutex = MutexImpl<FakeMutex>; // Non-recursive, handle with care -extern template class MutexImpl<std::recursive_mutex>; -extern template class MutexImpl<std::mutex>; -extern template class MutexLock<MutexImpl<std::recursive_mutex> >; -extern template class MutexLock<MutexImpl<std::mutex> >; +#endif // !NO_THREADS #endif diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp deleted file mode 100644 index 67375da6e2..0000000000 --- a/core/script_debugger_remote.cpp +++ /dev/null @@ -1,1143 +0,0 @@ -/*************************************************************************/ -/* script_debugger_remote.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "script_debugger_remote.h" - -#include "core/engine.h" -#include "core/io/ip.h" -#include "core/io/marshalls.h" -#include "core/os/input.h" -#include "core/os/os.h" -#include "core/project_settings.h" -#include "servers/visual_server.h" - -#define CHECK_SIZE(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() < (uint32_t)(expected), false, String("Malformed ") + what + " message from script debugger, message too short. Exptected size: " + itos(expected) + ", actual size: " + itos(arr.size())) -#define CHECK_END(arr, expected, what) ERR_FAIL_COND_V_MSG((uint32_t)arr.size() > (uint32_t)expected, false, String("Malformed ") + what + " message from script debugger, message too short. Exptected size: " + itos(expected) + ", actual size: " + itos(arr.size())) - -Array ScriptDebuggerRemote::ScriptStackDump::serialize() { - Array arr; - arr.push_back(frames.size() * 3); - for (int i = 0; i < frames.size(); i++) { - arr.push_back(frames[i].file); - arr.push_back(frames[i].line); - arr.push_back(frames[i].func); - } - return arr; -} - -bool ScriptDebuggerRemote::ScriptStackDump::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 1, "ScriptStackDump"); - uint32_t size = p_arr[0]; - CHECK_SIZE(p_arr, size, "ScriptStackDump"); - int idx = 1; - for (uint32_t i = 0; i < size / 3; i++) { - ScriptLanguage::StackInfo sf; - sf.file = p_arr[idx]; - sf.line = p_arr[idx + 1]; - sf.func = p_arr[idx + 2]; - frames.push_back(sf); - idx += 3; - } - CHECK_END(p_arr, idx, "ScriptStackDump"); - return true; -} - -Array ScriptDebuggerRemote::ScriptStackVariable::serialize(int max_size) { - Array arr; - arr.push_back(name); - arr.push_back(type); - - Variant var = value; - if (value.get_type() == Variant::OBJECT && value.get_validated_object() == nullptr) { - var = Variant(); - } - - int len = 0; - Error err = encode_variant(var, NULL, len, true); - if (err != OK) - ERR_PRINT("Failed to encode variant."); - - if (len > max_size) { - arr.push_back(Variant()); - } else { - arr.push_back(var); - } - return arr; -} - -bool ScriptDebuggerRemote::ScriptStackVariable::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 3, "ScriptStackVariable"); - name = p_arr[0]; - type = p_arr[1]; - value = p_arr[2]; - CHECK_END(p_arr, 3, "ScriptStackVariable"); - return true; -} - -Array ScriptDebuggerRemote::OutputError::serialize() { - Array arr; - arr.push_back(hr); - arr.push_back(min); - arr.push_back(sec); - arr.push_back(msec); - arr.push_back(source_file); - arr.push_back(source_func); - arr.push_back(source_line); - arr.push_back(error); - arr.push_back(error_descr); - arr.push_back(warning); - unsigned int size = callstack.size(); - const ScriptLanguage::StackInfo *r = callstack.ptr(); - arr.push_back(size * 3); - for (int i = 0; i < callstack.size(); i++) { - arr.push_back(r[i].file); - arr.push_back(r[i].func); - arr.push_back(r[i].line); - } - return arr; -} - -bool ScriptDebuggerRemote::OutputError::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 11, "OutputError"); - hr = p_arr[0]; - min = p_arr[1]; - sec = p_arr[2]; - msec = p_arr[3]; - source_file = p_arr[4]; - source_func = p_arr[5]; - source_line = p_arr[6]; - error = p_arr[7]; - error_descr = p_arr[8]; - warning = p_arr[9]; - unsigned int stack_size = p_arr[10]; - CHECK_SIZE(p_arr, stack_size, "OutputError"); - int idx = 11; - callstack.resize(stack_size / 3); - ScriptLanguage::StackInfo *w = callstack.ptrw(); - for (unsigned int i = 0; i < stack_size / 3; i++) { - w[i].file = p_arr[idx]; - w[i].func = p_arr[idx + 1]; - w[i].line = p_arr[idx + 2]; - idx += 3; - } - CHECK_END(p_arr, idx, "OutputError"); - return true; -} - -Array ScriptDebuggerRemote::ResourceUsage::serialize() { - infos.sort(); - - Array arr; - arr.push_back(infos.size() * 4); - for (List<ResourceInfo>::Element *E = infos.front(); E; E = E->next()) { - arr.push_back(E->get().path); - arr.push_back(E->get().format); - arr.push_back(E->get().type); - arr.push_back(E->get().vram); - } - return arr; -} - -bool ScriptDebuggerRemote::ResourceUsage::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 1, "ResourceUsage"); - uint32_t size = p_arr[0]; - CHECK_SIZE(p_arr, size, "ResourceUsage"); - int idx = 1; - for (uint32_t i = 0; i < size / 4; i++) { - ResourceInfo info; - info.path = p_arr[idx]; - info.format = p_arr[idx + 1]; - info.type = p_arr[idx + 2]; - info.vram = p_arr[idx + 3]; - infos.push_back(info); - } - CHECK_END(p_arr, idx, "ResourceUsage"); - return true; -} - -Array ScriptDebuggerRemote::ProfilerSignature::serialize() { - Array arr; - arr.push_back(name); - arr.push_back(id); - return arr; -} - -bool ScriptDebuggerRemote::ProfilerSignature::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 2, "ProfilerSignature"); - name = p_arr[0]; - id = p_arr[1]; - CHECK_END(p_arr, 2, "ProfilerSignature"); - return true; -} - -Array ScriptDebuggerRemote::ProfilerFrame::serialize() { - Array arr; - arr.push_back(frame_number); - arr.push_back(frame_time); - arr.push_back(idle_time); - arr.push_back(physics_time); - arr.push_back(physics_frame_time); - arr.push_back(USEC_TO_SEC(script_time)); - - arr.push_back(frames_data.size()); - arr.push_back(frame_functions.size() * 4); - - // Servers profiling info. - for (int i = 0; i < frames_data.size(); i++) { - arr.push_back(frames_data[i].name); // Type (physics/process/audio/...) - arr.push_back(frames_data[i].data.size()); - for (int j = 0; j < frames_data[i].data.size() / 2; j++) { - arr.push_back(frames_data[i].data[2 * j]); // NAME - arr.push_back(frames_data[i].data[2 * j + 1]); // TIME - } - } - for (int i = 0; i < frame_functions.size(); i++) { - arr.push_back(frame_functions[i].sig_id); - arr.push_back(frame_functions[i].call_count); - arr.push_back(frame_functions[i].self_time); - arr.push_back(frame_functions[i].total_time); - } - return arr; -} - -bool ScriptDebuggerRemote::ProfilerFrame::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 8, "ProfilerFrame"); - frame_number = p_arr[0]; - frame_time = p_arr[1]; - idle_time = p_arr[2]; - physics_time = p_arr[3]; - physics_frame_time = p_arr[4]; - script_time = p_arr[5]; - uint32_t frame_data_size = p_arr[6]; - int frame_func_size = p_arr[7]; - int idx = 8; - while (frame_data_size) { - CHECK_SIZE(p_arr, idx + 2, "ProfilerFrame"); - frame_data_size--; - FrameData fd; - fd.name = p_arr[idx]; - int sub_data_size = p_arr[idx + 1]; - idx += 2; - CHECK_SIZE(p_arr, idx + sub_data_size, "ProfilerFrame"); - for (int j = 0; j < sub_data_size / 2; j++) { - fd.data.push_back(p_arr[idx]); // NAME - fd.data.push_back(p_arr[idx + 1]); // TIME - idx += 2; - } - frames_data.push_back(fd); - } - CHECK_SIZE(p_arr, idx + frame_func_size, "ProfilerFrame"); - for (int i = 0; i < frame_func_size / 4; i++) { - FrameFunction ff; - ff.sig_id = p_arr[idx]; - ff.call_count = p_arr[idx + 1]; - ff.self_time = p_arr[idx + 2]; - ff.total_time = p_arr[idx + 3]; - frame_functions.push_back(ff); - idx += 4; - } - CHECK_END(p_arr, idx, "ProfilerFrame"); - return true; -} - -Array ScriptDebuggerRemote::NetworkProfilerFrame::serialize() { - Array arr; - arr.push_back(infos.size() * 6); - for (int i = 0; i < infos.size(); ++i) { - arr.push_back(uint64_t(infos[i].node)); - arr.push_back(infos[i].node_path); - arr.push_back(infos[i].incoming_rpc); - arr.push_back(infos[i].incoming_rset); - arr.push_back(infos[i].outgoing_rpc); - arr.push_back(infos[i].outgoing_rset); - } - return arr; -} - -bool ScriptDebuggerRemote::NetworkProfilerFrame::deserialize(const Array &p_arr) { - CHECK_SIZE(p_arr, 1, "NetworkProfilerFrame"); - uint32_t size = p_arr[0]; - CHECK_SIZE(p_arr, size, "NetworkProfilerFrame"); - infos.resize(size); - int idx = 1; - for (uint32_t i = 0; i < size / 6; ++i) { - infos.write[i].node = uint64_t(p_arr[idx]); - infos.write[i].node_path = p_arr[idx + 1]; - infos.write[i].incoming_rpc = p_arr[idx + 2]; - infos.write[i].incoming_rset = p_arr[idx + 3]; - infos.write[i].outgoing_rpc = p_arr[idx + 4]; - infos.write[i].outgoing_rset = p_arr[idx + 5]; - } - CHECK_END(p_arr, idx, "NetworkProfilerFrame"); - return true; -} - -void ScriptDebuggerRemote::_put_msg(String p_message, Array p_data) { - Array msg; - msg.push_back(p_message); - msg.push_back(p_data); - packet_peer_stream->put_var(msg); -} - -bool ScriptDebuggerRemote::is_peer_connected() { - return tcp_client->is_connected_to_host() && tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED; -} - -void ScriptDebuggerRemote::_send_video_memory() { - - ResourceUsage usage; - if (resource_usage_func) - resource_usage_func(&usage); - - _put_msg("message:video_mem", usage.serialize()); -} - -Error ScriptDebuggerRemote::connect_to_host(const String &p_host, uint16_t p_port) { - - IP_Address ip; - if (p_host.is_valid_ip_address()) - ip = p_host; - else - ip = IP::get_singleton()->resolve_hostname(p_host); - - int port = p_port; - - const int tries = 6; - int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 }; - - tcp_client->connect_to_host(ip, port); - - for (int i = 0; i < tries; i++) { - - if (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED) { - print_verbose("Remote Debugger: Connected!"); - break; - } else { - - const int ms = waits[i]; - OS::get_singleton()->delay_usec(ms * 1000); - print_verbose("Remote Debugger: Connection failed with status: '" + String::num(tcp_client->get_status()) + "', retrying in " + String::num(ms) + " msec."); - }; - }; - - if (tcp_client->get_status() != StreamPeerTCP::STATUS_CONNECTED) { - - ERR_PRINT("Remote Debugger: Unable to connect. Status: " + String::num(tcp_client->get_status()) + "."); - return FAILED; - }; - - packet_peer_stream->set_stream_peer(tcp_client); - Array msg; - msg.push_back(OS::get_singleton()->get_process_id()); - send_message("set_pid", msg); - - return OK; -} - -void ScriptDebuggerRemote::_parse_message(const String p_command, const Array &p_data, ScriptLanguage *p_script) { - - if (p_command == "request_video_mem") { - _send_video_memory(); - - } else if (p_command == "start_profiling") { - ERR_FAIL_COND(p_data.size() < 1); - - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->profiling_start(); - } - - max_frame_functions = p_data[0]; - profiler_function_signature_map.clear(); - profiling = true; - frame_time = 0; - idle_time = 0; - physics_time = 0; - physics_frame_time = 0; - print_line("PROFILING ALRIGHT!"); - - } else if (p_command == "stop_profiling") { - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->profiling_stop(); - } - profiling = false; - _send_profiling_data(false); - print_line("PROFILING END!"); - - } else if (p_command == "start_visual_profiling") { - - visual_profiling = true; - VS::get_singleton()->set_frame_profiling_enabled(true); - } else if (p_command == "stop_visual_profiling") { - - visual_profiling = false; - VS::get_singleton()->set_frame_profiling_enabled(false); - - } else if (p_command == "start_network_profiling") { - - network_profiling = true; - multiplayer->profiling_start(); - - } else if (p_command == "stop_network_profiling") { - - network_profiling = false; - multiplayer->profiling_end(); - - } else if (p_command == "reload_scripts") { - reload_all_scripts = true; - - } else if (p_command == "breakpoint") { - ERR_FAIL_COND(p_data.size() < 3); - bool set = p_data[2]; - if (set) - insert_breakpoint(p_data[1], p_data[0]); - else - remove_breakpoint(p_data[1], p_data[0]); - - } else if (p_command == "set_skip_breakpoints") { - ERR_FAIL_COND(p_data.size() < 1); - skip_breakpoints = p_data[0]; - - } else if (p_command == "get_stack_dump") { - ERR_FAIL_COND(!p_script); - ScriptStackDump dump; - int slc = p_script->debug_get_stack_level_count(); - for (int i = 0; i < slc; i++) { - ScriptLanguage::StackInfo frame; - frame.file = p_script->debug_get_stack_level_source(i); - frame.line = p_script->debug_get_stack_level_line(i); - frame.func = p_script->debug_get_stack_level_function(i); - dump.frames.push_back(frame); - } - _put_msg("stack_dump", dump.serialize()); - - } else if (p_command == "get_stack_frame_vars") { - ERR_FAIL_COND(p_data.size() != 1); - ERR_FAIL_COND(!p_script); - int lv = p_data[0]; - - List<String> members; - List<Variant> member_vals; - if (ScriptInstance *inst = p_script->debug_get_stack_level_instance(lv)) { - members.push_back("self"); - member_vals.push_back(inst->get_owner()); - } - p_script->debug_get_stack_level_members(lv, &members, &member_vals); - ERR_FAIL_COND(members.size() != member_vals.size()); - - List<String> locals; - List<Variant> local_vals; - p_script->debug_get_stack_level_locals(lv, &locals, &local_vals); - ERR_FAIL_COND(locals.size() != local_vals.size()); - - List<String> globals; - List<Variant> globals_vals; - p_script->debug_get_globals(&globals, &globals_vals); - ERR_FAIL_COND(globals.size() != globals_vals.size()); - - _put_msg("stack_frame_vars", Array()); - - ScriptStackVariable stvar; - { //locals - List<String>::Element *E = locals.front(); - List<Variant>::Element *F = local_vals.front(); - while (E) { - stvar.name = E->get(); - stvar.value = F->get(); - stvar.type = 0; - _put_msg("stack_frame_var", stvar.serialize()); - - E = E->next(); - F = F->next(); - } - } - - { //members - List<String>::Element *E = members.front(); - List<Variant>::Element *F = member_vals.front(); - while (E) { - stvar.name = E->get(); - stvar.value = F->get(); - stvar.type = 1; - _put_msg("stack_frame_var", stvar.serialize()); - - E = E->next(); - F = F->next(); - } - } - - { //globals - List<String>::Element *E = globals.front(); - List<Variant>::Element *F = globals_vals.front(); - while (E) { - stvar.name = E->get(); - stvar.value = F->get(); - stvar.type = 2; - _put_msg("stack_frame_var", stvar.serialize()); - - E = E->next(); - F = F->next(); - } - } - - } else { - if (scene_tree_parse_func) { - scene_tree_parse_func(p_command, p_data); - } - // Unknown message... - } -} - -void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue, bool p_is_error_breakpoint) { - - //this function is called when there is a debugger break (bug on script) - //or when execution is paused from editor - - if (skip_breakpoints && !p_is_error_breakpoint) - return; - - ERR_FAIL_COND_MSG(!is_peer_connected(), "Script Debugger failed to connect, but being used anyway."); - - Array msg; - msg.push_back(p_can_continue); - msg.push_back(p_script->debug_get_error()); - _put_msg("debug_enter", msg); - - skip_profile_frame = true; // to avoid super long frame time for the frame - - Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode(); - if (mouse_mode != Input::MOUSE_MODE_VISIBLE) - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); - - uint64_t loop_begin_usec = 0; - uint64_t loop_time_sec = 0; - while (true) { - loop_begin_usec = OS::get_singleton()->get_ticks_usec(); - - _get_output(); - - if (packet_peer_stream->get_available_packet_count() > 0) { - - Variant var; - Error err = packet_peer_stream->get_var(var); - - ERR_CONTINUE(err != OK); - ERR_CONTINUE(var.get_type() != Variant::ARRAY); - - Array cmd = var; - - ERR_CONTINUE(cmd.size() != 2); - ERR_CONTINUE(cmd[0].get_type() != Variant::STRING); - ERR_CONTINUE(cmd[1].get_type() != Variant::ARRAY); - - String command = cmd[0]; - Array data = cmd[1]; - if (command == "step") { - - set_depth(-1); - set_lines_left(1); - break; - } else if (command == "next") { - - set_depth(0); - set_lines_left(1); - break; - - } else if (command == "continue") { - set_depth(-1); - set_lines_left(-1); - OS::get_singleton()->move_window_to_foreground(); - break; - } else if (command == "break") { - ERR_PRINT("Got break when already broke!"); - break; - } - - _parse_message(command, data, p_script); - } else { - OS::get_singleton()->delay_usec(10000); - OS::get_singleton()->process_and_drop_events(); - } - - // This is for the camera override to stay live even when the game is paused from the editor - loop_time_sec = (OS::get_singleton()->get_ticks_usec() - loop_begin_usec) / 1000000.0f; - VisualServer::get_singleton()->sync(); - if (VisualServer::get_singleton()->has_changed()) { - VisualServer::get_singleton()->draw(true, loop_time_sec * Engine::get_singleton()->get_time_scale()); - } - } - - _put_msg("debug_exit", Array()); - - if (mouse_mode != Input::MOUSE_MODE_VISIBLE) - Input::get_singleton()->set_mouse_mode(mouse_mode); -} - -void ScriptDebuggerRemote::_get_output() { - - MutexLock lock(mutex); - - if (output_strings.size()) { - - locking = true; - - while (output_strings.size()) { - - Array arr; - arr.push_back(output_strings.front()->get()); - _put_msg("output", arr); - output_strings.pop_front(); - } - locking = false; - } - - if (n_messages_dropped > 0) { - Message msg; - msg.message = "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped."; - messages.push_back(msg); - n_messages_dropped = 0; - } - - while (messages.size()) { - locking = true; - Message msg = messages.front()->get(); - _put_msg("message:" + msg.message, msg.data); - messages.pop_front(); - locking = false; - } - - if (n_errors_dropped == 1) { - // Only print one message about dropping per second - OutputError oe; - oe.error = "TOO_MANY_ERRORS"; - oe.error_descr = "Too many errors! Ignoring errors for up to 1 second."; - oe.warning = false; - uint64_t time = OS::get_singleton()->get_ticks_msec(); - oe.hr = time / 3600000; - oe.min = (time / 60000) % 60; - oe.sec = (time / 1000) % 60; - oe.msec = time % 1000; - errors.push_back(oe); - } - - if (n_warnings_dropped == 1) { - // Only print one message about dropping per second - OutputError oe; - oe.error = "TOO_MANY_WARNINGS"; - oe.error_descr = "Too many warnings! Ignoring warnings for up to 1 second."; - oe.warning = true; - uint64_t time = OS::get_singleton()->get_ticks_msec(); - oe.hr = time / 3600000; - oe.min = (time / 60000) % 60; - oe.sec = (time / 1000) % 60; - oe.msec = time % 1000; - errors.push_back(oe); - } - - while (errors.size()) { - locking = true; - OutputError oe = errors.front()->get(); - _put_msg("error", oe.serialize()); - errors.pop_front(); - locking = false; - } -} - -void ScriptDebuggerRemote::line_poll() { - - //the purpose of this is just processing events every now and then when the script might get too busy - //otherwise bugs like infinite loops can't be caught - if (poll_every % 2048 == 0) - _poll_events(); - poll_every++; -} - -void ScriptDebuggerRemote::_err_handler(void *ud, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) { - - if (p_type == ERR_HANDLER_SCRIPT) - return; //ignore script errors, those go through debugger - - Vector<ScriptLanguage::StackInfo> si; - - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - si = ScriptServer::get_language(i)->debug_get_current_stack_info(); - if (si.size()) - break; - } - - ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)ud; - sdr->send_error(p_func, p_file, p_line, p_err, p_descr, p_type, si); -} - -void ScriptDebuggerRemote::_poll_events() { - - //this si called from ::idle_poll, happens only when running the game, - //does not get called while on debug break - - while (packet_peer_stream->get_available_packet_count() > 0) { - - _get_output(); - - //send over output_strings - - Variant var; - Error err = packet_peer_stream->get_var(var); - - ERR_CONTINUE(err != OK); - ERR_CONTINUE(var.get_type() != Variant::ARRAY); - - Array cmd = var; - - ERR_CONTINUE(cmd.size() < 2); - ERR_CONTINUE(cmd[0].get_type() != Variant::STRING); - ERR_CONTINUE(cmd[1].get_type() != Variant::ARRAY); - - String command = cmd[0]; - Array data = cmd[1]; - - if (command == "break") { - - if (get_break_language()) - debug(get_break_language()); - } else { - _parse_message(command, data); - } - } -} - -void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) { - - int ofs = 0; - - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - if (p_for_frame) - ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&profile_info.write[ofs], profile_info.size() - ofs); - else - ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&profile_info.write[ofs], profile_info.size() - ofs); - } - - for (int i = 0; i < ofs; i++) { - profile_info_ptrs.write[i] = &profile_info.write[i]; - } - - SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa; - sa.sort(profile_info_ptrs.ptrw(), ofs); - - int to_send = MIN(ofs, max_frame_functions); - - //check signatures first - uint64_t total_script_time = 0; - - for (int i = 0; i < to_send; i++) { - - if (!profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) { - - int idx = profiler_function_signature_map.size(); - ProfilerSignature sig; - sig.name = profile_info_ptrs[i]->signature; - sig.id = idx; - _put_msg("profile_sig", sig.serialize()); - profiler_function_signature_map[profile_info_ptrs[i]->signature] = idx; - } - - total_script_time += profile_info_ptrs[i]->self_time; - } - - //send frames then - ProfilerFrame metric; - metric.frame_number = Engine::get_singleton()->get_frames_drawn(); - metric.frame_time = frame_time; - metric.idle_time = idle_time; - metric.physics_time = physics_time; - metric.physics_frame_time = physics_frame_time; - metric.script_time = total_script_time; - - // Add script functions information. - metric.frame_functions.resize(to_send); - FrameFunction *w = metric.frame_functions.ptrw(); - for (int i = 0; i < to_send; i++) { - - if (profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) { - w[i].sig_id = profiler_function_signature_map[profile_info_ptrs[i]->signature]; - } - - w[i].call_count = profile_info_ptrs[i]->call_count; - w[i].total_time = profile_info_ptrs[i]->total_time / 1000000.0; - w[i].self_time = profile_info_ptrs[i]->self_time / 1000000.0; - } - if (p_for_frame) { - // Add profile frame data information. - metric.frames_data.append_array(profile_frame_data); - _put_msg("profile_frame", metric.serialize()); - profile_frame_data.clear(); - } else { - _put_msg("profile_total", metric.serialize()); - } -} - -void ScriptDebuggerRemote::idle_poll() { - - // this function is called every frame, except when there is a debugger break (::debug() in this class) - // execution stops and remains in the ::debug function - - _get_output(); - - if (requested_quit) { - - _put_msg("kill_me", Array()); - requested_quit = false; - } - - if (performance) { - - uint64_t pt = OS::get_singleton()->get_ticks_msec(); - if (pt - last_perf_time > 1000) { - - last_perf_time = pt; - int max = performance->get("MONITOR_MAX"); - Array arr; - arr.resize(max); - for (int i = 0; i < max; i++) { - arr[i] = performance->call("get_monitor", i); - } - _put_msg("performance", arr); - } - } - - if (visual_profiling) { - Vector<VS::FrameProfileArea> profile_areas = VS::get_singleton()->get_frame_profile(); - if (profile_areas.size()) { - Vector<String> area_names; - Vector<real_t> area_times; - area_names.resize(profile_areas.size()); - area_times.resize(profile_areas.size() * 2); - { - String *area_namesw = area_names.ptrw(); - real_t *area_timesw = area_times.ptrw(); - - for (int i = 0; i < profile_areas.size(); i++) { - area_namesw[i] = profile_areas[i].name; - area_timesw[i * 2 + 0] = profile_areas[i].cpu_msec; - area_timesw[i * 2 + 1] = profile_areas[i].gpu_msec; - } - } - Array msg; - msg.push_back(VS::get_singleton()->get_frame_profile_frame()); - msg.push_back(area_names); - msg.push_back(area_times); - _put_msg("visual_profile", msg); - } - } - - if (profiling) { - - if (skip_profile_frame) { - skip_profile_frame = false; - } else { - //send profiling info normally - _send_profiling_data(true); - } - } - - if (network_profiling) { - uint64_t pt = OS::get_singleton()->get_ticks_msec(); - if (pt - last_net_bandwidth_time > 200) { - last_net_bandwidth_time = pt; - _send_network_bandwidth_usage(); - } - if (pt - last_net_prof_time > 100) { - last_net_prof_time = pt; - _send_network_profiling_data(); - } - } - - if (reload_all_scripts) { - - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->reload_all_scripts(); - } - reload_all_scripts = false; - } - - _poll_events(); -} - -void ScriptDebuggerRemote::_send_network_profiling_data() { - ERR_FAIL_COND(multiplayer.is_null()); - - int n_nodes = multiplayer->get_profiling_frame(&network_profile_info.write[0]); - - NetworkProfilerFrame frame; - for (int i = 0; i < n_nodes; i++) { - frame.infos.push_back(network_profile_info[i]); - } - _put_msg("network_profile", frame.serialize()); -} - -void ScriptDebuggerRemote::_send_network_bandwidth_usage() { - ERR_FAIL_COND(multiplayer.is_null()); - - int incoming_bandwidth = multiplayer->get_incoming_bandwidth_usage(); - int outgoing_bandwidth = multiplayer->get_outgoing_bandwidth_usage(); - - Array arr; - arr.push_back(incoming_bandwidth); - arr.push_back(outgoing_bandwidth); - _put_msg("network_bandwidth", arr); -} - -void ScriptDebuggerRemote::send_message(const String &p_message, const Array &p_args) { - - MutexLock lock(mutex); - - if (!locking && is_peer_connected()) { - - if (messages.size() >= max_messages_per_frame) { - n_messages_dropped++; - } else { - Message msg; - msg.message = p_message; - msg.data = p_args; - messages.push_back(msg); - } - } -} - -void ScriptDebuggerRemote::send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info) { - - OutputError oe; - oe.error = p_err; - oe.error_descr = p_descr; - oe.source_file = p_file; - oe.source_line = p_line; - oe.source_func = p_func; - oe.warning = p_type == ERR_HANDLER_WARNING; - uint64_t time = OS::get_singleton()->get_ticks_msec(); - oe.hr = time / 3600000; - oe.min = (time / 60000) % 60; - oe.sec = (time / 1000) % 60; - oe.msec = time % 1000; - Array cstack; - - uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000; - msec_count += ticks - last_msec; - last_msec = ticks; - - if (msec_count > 1000) { - msec_count = 0; - - err_count = 0; - n_errors_dropped = 0; - warn_count = 0; - n_warnings_dropped = 0; - } - - cstack.resize(p_stack_info.size() * 3); - for (int i = 0; i < p_stack_info.size(); i++) { - cstack[i * 3 + 0] = p_stack_info[i].file; - cstack[i * 3 + 1] = p_stack_info[i].func; - cstack[i * 3 + 2] = p_stack_info[i].line; - } - - //oe.callstack = cstack; - if (oe.warning) { - warn_count++; - } else { - err_count++; - } - - MutexLock lock(mutex); - - if (!locking && is_peer_connected()) { - - if (oe.warning) { - if (warn_count > max_warnings_per_second) { - n_warnings_dropped++; - } else { - errors.push_back(oe); - } - } else { - if (err_count > max_errors_per_second) { - n_errors_dropped++; - } else { - errors.push_back(oe); - } - } - } -} - -void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, bool p_error) { - - ScriptDebuggerRemote *sdr = (ScriptDebuggerRemote *)p_this; - - uint64_t ticks = OS::get_singleton()->get_ticks_usec() / 1000; - sdr->msec_count += ticks - sdr->last_msec; - sdr->last_msec = ticks; - - if (sdr->msec_count > 1000) { - sdr->char_count = 0; - sdr->msec_count = 0; - } - - String s = p_string; - int allowed_chars = MIN(MAX(sdr->max_cps - sdr->char_count, 0), s.length()); - - if (allowed_chars == 0) - return; - - if (allowed_chars < s.length()) { - s = s.substr(0, allowed_chars); - } - - sdr->char_count += allowed_chars; - bool overflowed = sdr->char_count >= sdr->max_cps; - - { - MutexLock lock(sdr->mutex); - - if (!sdr->locking && sdr->is_peer_connected()) { - - if (overflowed) - s += "[...]"; - - sdr->output_strings.push_back(s); - - if (overflowed) { - sdr->output_strings.push_back("[output overflow, print less text!]"); - } - } - } -} - -void ScriptDebuggerRemote::request_quit() { - - requested_quit = true; -} - -void ScriptDebuggerRemote::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) { - multiplayer = p_multiplayer; -} - -bool ScriptDebuggerRemote::is_profiling() const { - - return profiling; -} -void ScriptDebuggerRemote::add_profiling_frame_data(const StringName &p_name, const Array &p_data) { - - int idx = -1; - for (int i = 0; i < profile_frame_data.size(); i++) { - if (profile_frame_data[i].name == p_name) { - idx = i; - break; - } - } - - FrameData fd; - fd.name = p_name; - fd.data = p_data; - - if (idx == -1) { - profile_frame_data.push_back(fd); - } else { - profile_frame_data.write[idx] = fd; - } -} - -void ScriptDebuggerRemote::profiling_start() { - //ignores this, uses it via connection -} - -void ScriptDebuggerRemote::profiling_end() { - //ignores this, uses it via connection -} - -void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) { - - frame_time = p_frame_time; - idle_time = p_idle_time; - physics_time = p_physics_time; - physics_frame_time = p_physics_frame_time; -} - -void ScriptDebuggerRemote::set_skip_breakpoints(bool p_skip_breakpoints) { - skip_breakpoints = p_skip_breakpoints; -} - -ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = NULL; -ScriptDebuggerRemote::ParseMessageFunc ScriptDebuggerRemote::scene_tree_parse_func = NULL; - -ScriptDebuggerRemote::ScriptDebuggerRemote() : - profiling(false), - visual_profiling(false), - network_profiling(false), - max_frame_functions(16), - skip_profile_frame(false), - reload_all_scripts(false), - tcp_client(Ref<StreamPeerTCP>(memnew(StreamPeerTCP))), - packet_peer_stream(Ref<PacketPeerStream>(memnew(PacketPeerStream))), - last_perf_time(0), - last_net_prof_time(0), - last_net_bandwidth_time(0), - performance(Engine::get_singleton()->get_singleton_object("Performance")), - requested_quit(false), - max_messages_per_frame(GLOBAL_GET("network/limits/debugger_stdout/max_messages_per_frame")), - n_messages_dropped(0), - max_errors_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_errors_per_second")), - max_warnings_per_second(GLOBAL_GET("network/limits/debugger_stdout/max_warnings_per_second")), - n_errors_dropped(0), - max_cps(GLOBAL_GET("network/limits/debugger_stdout/max_chars_per_second")), - char_count(0), - err_count(0), - warn_count(0), - last_msec(0), - msec_count(0), - locking(false), - poll_every(0) { - - packet_peer_stream->set_stream_peer(tcp_client); - packet_peer_stream->set_output_buffer_max_size((1024 * 1024 * 8) - 4); // 8 MiB should be way more than enough, minus 4 bytes for separator. - - phl.printfunc = _print_handler; - phl.userdata = this; - add_print_handler(&phl); - - eh.errfunc = _err_handler; - eh.userdata = this; - add_error_handler(&eh); - - profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions")); - network_profile_info.resize(GLOBAL_GET("debug/settings/profiler/max_functions")); - profile_info_ptrs.resize(profile_info.size()); -} - -ScriptDebuggerRemote::~ScriptDebuggerRemote() { - - remove_print_handler(&phl); - remove_error_handler(&eh); -} diff --git a/core/script_debugger_remote.h b/core/script_debugger_remote.h deleted file mode 100644 index b7a309b2f9..0000000000 --- a/core/script_debugger_remote.h +++ /dev/null @@ -1,316 +0,0 @@ -/*************************************************************************/ -/* script_debugger_remote.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef SCRIPT_DEBUGGER_REMOTE_H -#define SCRIPT_DEBUGGER_REMOTE_H - -#include "core/io/packet_peer.h" -#include "core/io/stream_peer_tcp.h" -#include "core/list.h" -#include "core/os/os.h" -#include "core/script_language.h" - -class ScriptDebuggerRemote : public ScriptDebugger { - -public: - class ResourceInfo { - public: - String path; - String format; - String type; - RID id; - int vram; - bool operator<(const ResourceInfo &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; } - ResourceInfo() { - vram = 0; - } - }; - - class ResourceUsage { - public: - List<ResourceInfo> infos; - - Array serialize(); - bool deserialize(const Array &p_arr); - }; - - class FrameInfo { - public: - StringName name; - float self_time; - float total_time; - - FrameInfo() { - self_time = 0; - total_time = 0; - } - }; - - class FrameFunction { - public: - int sig_id; - int call_count; - StringName name; - float self_time; - float total_time; - - FrameFunction() { - sig_id = -1; - call_count = 0; - self_time = 0; - total_time = 0; - } - }; - - class ScriptStackVariable { - public: - String name; - Variant value; - int type; - ScriptStackVariable() { - type = -1; - } - - Array serialize(int max_size = 1 << 20); // 1 MiB default. - bool deserialize(const Array &p_arr); - }; - - class ScriptStackDump { - public: - List<ScriptLanguage::StackInfo> frames; - ScriptStackDump() {} - - Array serialize(); - bool deserialize(const Array &p_arr); - }; - - class Message { - - public: - String message; - Array data; - - Message() {} - }; - - class OutputError { - public: - int hr; - int min; - int sec; - int msec; - String source_file; - String source_func; - int source_line; - String error; - String error_descr; - bool warning; - Vector<ScriptLanguage::StackInfo> callstack; - - OutputError() { - hr = -1; - min = -1; - sec = -1; - msec = -1; - source_line = -1; - warning = false; - } - - Array serialize(); - bool deserialize(const Array &p_arr); - }; - - struct FrameData { - - StringName name; - Array data; - }; - - class ProfilerSignature { - public: - StringName name; - int id; - - Array serialize(); - bool deserialize(const Array &p_arr); - - ProfilerSignature() { - id = -1; - }; - }; - - class ProfilerFrame { - public: - int frame_number; - float frame_time; - float idle_time; - float physics_time; - float physics_frame_time; - float script_time; - - Vector<FrameData> frames_data; - Vector<FrameFunction> frame_functions; - - ProfilerFrame() { - frame_number = 0; - frame_time = 0; - idle_time = 0; - physics_time = 0; - physics_frame_time = 0; - } - - Array serialize(); - bool deserialize(const Array &p_arr); - }; - - class NetworkProfilerFrame { - public: - Vector<MultiplayerAPI::ProfilingInfo> infos; - - Array serialize(); - bool deserialize(const Array &p_arr); - - NetworkProfilerFrame(){}; - }; - -protected: - struct ProfileInfoSort { - - bool operator()(ScriptLanguage::ProfilingInfo *A, ScriptLanguage::ProfilingInfo *B) const { - return A->total_time < B->total_time; - } - }; - - Vector<ScriptLanguage::ProfilingInfo> profile_info; - Vector<ScriptLanguage::ProfilingInfo *> profile_info_ptrs; - Vector<MultiplayerAPI::ProfilingInfo> network_profile_info; - - Map<StringName, int> profiler_function_signature_map; - float frame_time, idle_time, physics_time, physics_frame_time; - - bool profiling; - bool visual_profiling; - bool network_profiling; - int max_frame_functions; - bool skip_profile_frame; - bool reload_all_scripts; - - Ref<StreamPeerTCP> tcp_client; - Ref<PacketPeerStream> packet_peer_stream; - - uint64_t last_perf_time; - uint64_t last_net_prof_time; - uint64_t last_net_bandwidth_time; - Object *performance; - bool requested_quit; - Mutex mutex; - - List<String> output_strings; - List<Message> messages; - int max_messages_per_frame; - int n_messages_dropped; - List<OutputError> errors; - int max_errors_per_second; - int max_warnings_per_second; - int n_errors_dropped; - int n_warnings_dropped; - - int max_cps; - int char_count; - int err_count; - int warn_count; - uint64_t last_msec; - uint64_t msec_count; - - bool locking; //hack to avoid a deadloop - static void _print_handler(void *p_this, const String &p_string, bool p_error); - - PrintHandlerList phl; - - void _get_output(); - void _poll_events(); - uint32_t poll_every; - - void _parse_message(const String p_command, const Array &p_data, ScriptLanguage *p_script = NULL); - - void _set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value); - - void _send_object_id(ObjectID p_id); - void _send_video_memory(); - - Ref<MultiplayerAPI> multiplayer; - - ErrorHandlerList eh; - static void _err_handler(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type); - - void _put_msg(String p_message, Array p_data); - void _send_profiling_data(bool p_for_frame); - void _send_network_profiling_data(); - void _send_network_bandwidth_usage(); - - Vector<FrameData> profile_frame_data; - - bool skip_breakpoints; - -public: - typedef void (*ResourceUsageFunc)(ResourceUsage *); - typedef Error (*ParseMessageFunc)(const String &p_name, const Array &p_msg); // Returns true if something was found (stopping propagation). - - static ResourceUsageFunc resource_usage_func; - static ParseMessageFunc scene_tree_parse_func; // Could be made into list, extensible... - - Error connect_to_host(const String &p_host, uint16_t p_port); - bool is_peer_connected(); - virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true, bool p_is_error_breakpoint = false); - virtual void idle_poll(); - virtual void line_poll(); - - virtual bool is_remote() const { return true; } - virtual void request_quit(); - - virtual void send_message(const String &p_message, const Array &p_args); - virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info); - - virtual void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer); - - virtual bool is_profiling() const; - virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data); - - virtual void profiling_start(); - virtual void profiling_end(); - virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time); - - virtual void set_skip_breakpoints(bool p_skip_breakpoints); - - ScriptDebuggerRemote(); - ~ScriptDebuggerRemote(); -}; - -#endif // SCRIPT_DEBUGGER_REMOTE_H diff --git a/core/script_language.cpp b/core/script_language.cpp index 0b00247502..428f363b17 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -31,6 +31,8 @@ #include "script_language.h" #include "core/core_string_names.h" +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" #include "core/project_settings.h" #include <stdint.h> @@ -46,8 +48,8 @@ void Script::_notification(int p_what) { if (p_what == NOTIFICATION_POSTINITIALIZE) { - if (ScriptDebugger::get_singleton()) - ScriptDebugger::get_singleton()->set_break_language(get_language()); + if (EngineDebugger::is_active()) + EngineDebugger::get_script_debugger()->set_break_language(get_language()); } } @@ -356,89 +358,6 @@ ScriptCodeCompletionCache::ScriptCodeCompletionCache() { void ScriptLanguage::frame() { } -ScriptDebugger *ScriptDebugger::singleton = NULL; - -void ScriptDebugger::set_lines_left(int p_left) { - - lines_left = p_left; -} - -int ScriptDebugger::get_lines_left() const { - - return lines_left; -} - -void ScriptDebugger::set_depth(int p_depth) { - - depth = p_depth; -} - -int ScriptDebugger::get_depth() const { - - return depth; -} - -void ScriptDebugger::insert_breakpoint(int p_line, const StringName &p_source) { - - if (!breakpoints.has(p_line)) - breakpoints[p_line] = Set<StringName>(); - breakpoints[p_line].insert(p_source); -} - -void ScriptDebugger::remove_breakpoint(int p_line, const StringName &p_source) { - - if (!breakpoints.has(p_line)) - return; - - breakpoints[p_line].erase(p_source); - if (breakpoints[p_line].size() == 0) - breakpoints.erase(p_line); -} -bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const { - - if (!breakpoints.has(p_line)) - return false; - return breakpoints[p_line].has(p_source); -} -bool ScriptDebugger::is_breakpoint_line(int p_line) const { - - return breakpoints.has(p_line); -} - -String ScriptDebugger::breakpoint_find_source(const String &p_source) const { - - return p_source; -} - -void ScriptDebugger::clear_breakpoints() { - - breakpoints.clear(); -} - -void ScriptDebugger::idle_poll() { -} - -void ScriptDebugger::line_poll() { -} - -void ScriptDebugger::set_break_language(ScriptLanguage *p_lang) { - - break_lang = p_lang; -} - -ScriptLanguage *ScriptDebugger::get_break_language() const { - - return break_lang; -} - -ScriptDebugger::ScriptDebugger() { - - singleton = this; - lines_left = -1; - depth = -1; - break_lang = NULL; -} - bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) { if (script->is_placeholder_fallback_enabled()) diff --git a/core/script_language.h b/core/script_language.h index 48570ae546..f1b809425b 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -350,6 +350,11 @@ public: virtual void thread_exit() {} /* DEBUGGER FUNCTIONS */ + struct StackInfo { + String file; + String func; + int line; + }; virtual String debug_get_error() const = 0; virtual int debug_get_stack_level_count() const = 0; @@ -362,12 +367,6 @@ public: virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) = 0; virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1) = 0; - struct StackInfo { - String file; - String func; - int line; - }; - virtual Vector<StackInfo> debug_get_current_stack_info() { return Vector<StackInfo>(); } virtual void reload_all_scripts() = 0; @@ -460,56 +459,4 @@ public: PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner); ~PlaceHolderScriptInstance(); }; - -class ScriptDebugger { - - int lines_left; - int depth; - - static ScriptDebugger *singleton; - Map<int, Set<StringName> > breakpoints; - - ScriptLanguage *break_lang; - -public: - _FORCE_INLINE_ static ScriptDebugger *get_singleton() { return singleton; } - void set_lines_left(int p_left); - int get_lines_left() const; - - void set_depth(int p_depth); - int get_depth() const; - - String breakpoint_find_source(const String &p_source) const; - void insert_breakpoint(int p_line, const StringName &p_source); - void remove_breakpoint(int p_line, const StringName &p_source); - bool is_breakpoint(int p_line, const StringName &p_source) const; - bool is_breakpoint_line(int p_line) const; - void clear_breakpoints(); - const Map<int, Set<StringName> > &get_breakpoints() const { return breakpoints; } - - virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true, bool p_is_error_breakpoint = false) = 0; - virtual void idle_poll(); - virtual void line_poll(); - - void set_break_language(ScriptLanguage *p_lang); - ScriptLanguage *get_break_language() const; - - virtual void send_message(const String &p_message, const Array &p_args) = 0; - virtual void send_error(const String &p_func, const String &p_file, int p_line, const String &p_err, const String &p_descr, ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> &p_stack_info) = 0; - - virtual bool is_remote() const { return false; } - virtual void request_quit() {} - - virtual void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {} - - virtual bool is_profiling() const = 0; - virtual void add_profiling_frame_data(const StringName &p_name, const Array &p_data) = 0; - virtual void profiling_start() = 0; - virtual void profiling_end() = 0; - virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) = 0; - - ScriptDebugger(); - virtual ~ScriptDebugger() { singleton = NULL; } -}; - #endif diff --git a/core/typedefs.h b/core/typedefs.h index 5376b0718a..bafbffcded 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -37,60 +37,41 @@ * Basic definitions and simple functions to be used everywhere. */ +// Include first in case the platform needs to pre-define/include some things. #include "platform_config.h" +// Should be available everywhere. +#include "core/error_list.h" +#include "core/int_types.h" + +// Turn argument to string constant: +// https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html#Stringizing #ifndef _STR #define _STR(m_x) #m_x #define _MKSTR(m_x) _STR(m_x) #endif -//should always inline no matter what +// Should always inline no matter what. #ifndef _ALWAYS_INLINE_ - -#if defined(__GNUC__) && (__GNUC__ >= 4) -#define _ALWAYS_INLINE_ __attribute__((always_inline)) inline -#elif defined(__llvm__) +#if defined(__GNUC__) #define _ALWAYS_INLINE_ __attribute__((always_inline)) inline #elif defined(_MSC_VER) #define _ALWAYS_INLINE_ __forceinline #else #define _ALWAYS_INLINE_ inline #endif - #endif -//should always inline, except in some cases because it makes debugging harder +// Should always inline, except in debug builds because it makes debugging harder. #ifndef _FORCE_INLINE_ - #ifdef DISABLE_FORCED_INLINE #define _FORCE_INLINE_ inline #else #define _FORCE_INLINE_ _ALWAYS_INLINE_ #endif - #endif -//custom, gcc-safe offsetof, because gcc complains a lot. -template <class T> -T *_nullptr() { - T *t = NULL; - return t; -} - -#define OFFSET_OF(st, m) \ - ((size_t)((char *)&(_nullptr<st>()->m) - (char *)0)) -/** - * Some platforms (devices) don't define NULL - */ - -#ifndef NULL -#define NULL 0 -#endif - -/** - * Windows badly defines a lot of stuff we'll never use. Undefine it. - */ - +// Windows badly defines a lot of stuff we'll never use. Undefine it. #ifdef _WIN32 #undef min // override standard definition #undef max // override standard definition @@ -105,18 +86,11 @@ T *_nullptr() { #undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enum #endif -#include "core/int_types.h" - -#include "core/error_list.h" - -/** Generic ABS function, for math uses please use Math::abs */ - +// Generic ABS function, for math uses please use Math::abs. #ifndef ABS #define ABS(m_v) (((m_v) < 0) ? (-(m_v)) : (m_v)) #endif -#define ABSDIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y))) - #ifndef SGN #define SGN(m_v) (((m_v) < 0) ? (-1.0) : (+1.0)) #endif @@ -133,49 +107,24 @@ T *_nullptr() { #define CLAMP(m_a, m_min, m_max) (((m_a) < (m_min)) ? (m_min) : (((m_a) > (m_max)) ? m_max : m_a)) #endif -/** Generic swap template */ +// Generic swap template. #ifndef SWAP - #define SWAP(m_x, m_y) __swap_tmpl((m_x), (m_y)) template <class T> inline void __swap_tmpl(T &x, T &y) { - T aux = x; x = y; y = aux; } +#endif // SWAP -#endif //swap - -/* clang-format off */ -#define HEX2CHR(m_hex) \ - ((m_hex >= '0' && m_hex <= '9') ? (m_hex - '0') : \ - ((m_hex >= 'A' && m_hex <= 'F') ? (10 + m_hex - 'A') : \ - ((m_hex >= 'a' && m_hex <= 'f') ? (10 + m_hex - 'a') : 0))) -/* clang-format on */ - -// Macro to check whether we are compiled by clang -// and we have a specific builtin -#if defined(__llvm__) && defined(__has_builtin) -#define _llvm_has_builtin(x) __has_builtin(x) -#else -#define _llvm_has_builtin(x) 0 -#endif - -#if (defined(__GNUC__) && (__GNUC__ >= 5)) || _llvm_has_builtin(__builtin_mul_overflow) -#define _mul_overflow __builtin_mul_overflow -#endif - -#if (defined(__GNUC__) && (__GNUC__ >= 5)) || _llvm_has_builtin(__builtin_add_overflow) -#define _add_overflow __builtin_add_overflow -#endif - -/** Function to find the next power of 2 to an integer */ +/* Functions to handle powers of 2 and shifting. */ +// Function to find the next power of 2 to an integer. static _FORCE_INLINE_ unsigned int next_power_of_2(unsigned int x) { - - if (x == 0) + if (x == 0) { return 0; + } --x; x |= x >> 1; @@ -187,8 +136,8 @@ static _FORCE_INLINE_ unsigned int next_power_of_2(unsigned int x) { return ++x; } +// Function to find the previous power of 2 to an integer. static _FORCE_INLINE_ unsigned int previous_power_of_2(unsigned int x) { - x |= x >> 1; x |= x >> 2; x |= x >> 4; @@ -197,40 +146,45 @@ static _FORCE_INLINE_ unsigned int previous_power_of_2(unsigned int x) { return x - (x >> 1); } +// Function to find the closest power of 2 to an integer. static _FORCE_INLINE_ unsigned int closest_power_of_2(unsigned int x) { - unsigned int nx = next_power_of_2(x); unsigned int px = previous_power_of_2(x); return (nx - x) > (x - px) ? px : nx; } -// We need this definition inside the function below. -static inline int get_shift_from_power_of_2(unsigned int p_pixel); +// Get a shift value from a power of 2. +static inline int get_shift_from_power_of_2(unsigned int p_bits) { + for (unsigned int i = 0; i < 32; i++) { + if (p_bits == (unsigned int)(1 << i)) { + return i; + } + } + + return -1; +} template <class T> static _FORCE_INLINE_ T nearest_power_of_2_templated(T x) { - --x; // The number of operations on x is the base two logarithm - // of the p_number of bits in the type. Add three to account + // of the number of bits in the type. Add three to account // for sizeof(T) being in bytes. size_t num = get_shift_from_power_of_2(sizeof(T)) + 3; - // If the compiler is smart, it unrolls this loop - // If its dumb, this is a bit slow. - for (size_t i = 0; i < num; i++) + // If the compiler is smart, it unrolls this loop. + // If it's dumb, this is a bit slow. + for (size_t i = 0; i < num; i++) { x |= x >> (1 << i); + } return ++x; } -/** Function to find the nearest (bigger) power of 2 to an integer */ - +// Function to find the nearest (bigger) power of 2 to an integer. static inline unsigned int nearest_shift(unsigned int p_number) { - for (int i = 30; i >= 0; i--) { - if (p_number & (1 << i)) return i + 1; } @@ -238,41 +192,20 @@ static inline unsigned int nearest_shift(unsigned int p_number) { return 0; } -/** get a shift value from a power of 2 */ -static inline int get_shift_from_power_of_2(unsigned int p_pixel) { - // return a GL_TEXTURE_SIZE_ENUM - - for (unsigned int i = 0; i < 32; i++) { - - if (p_pixel == (unsigned int)(1 << i)) - return i; - } - - return -1; -} - -/** Swap 16 bits value for endianness */ -#if defined(__GNUC__) || _llvm_has_builtin(__builtin_bswap16) +// Swap 16, 32 and 64 bits value for endianness. +#if defined(__GNUC__) #define BSWAP16(x) __builtin_bswap16(x) +#define BSWAP32(x) __builtin_bswap32(x) +#define BSWAP64(x) __builtin_bswap64(x) #else static inline uint16_t BSWAP16(uint16_t x) { return (x >> 8) | (x << 8); } -#endif -/** Swap 32 bits value for endianness */ -#if defined(__GNUC__) || _llvm_has_builtin(__builtin_bswap32) -#define BSWAP32(x) __builtin_bswap32(x) -#else static inline uint32_t BSWAP32(uint32_t x) { return ((x << 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x >> 24)); } -#endif -/** Swap 64 bits value for endianness */ -#if defined(__GNUC__) || _llvm_has_builtin(__builtin_bswap64) -#define BSWAP64(x) __builtin_bswap64(x) -#else static inline uint64_t BSWAP64(uint64_t x) { x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32; x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16; @@ -281,40 +214,24 @@ static inline uint64_t BSWAP64(uint64_t x) { } #endif -/** When compiling with RTTI, we can add an "extra" - * layer of safeness in many operations, so dynamic_cast - * is used besides casting by enum. - */ - +// Generic comparator used in Map, List, etc. template <class T> struct Comparator { - _ALWAYS_INLINE_ bool operator()(const T &p_a, const T &p_b) const { return (p_a < p_b); } }; +// Global lock macro, relies on the static Mutex::_global_mutex. void _global_lock(); void _global_unlock(); struct _GlobalLock { - _GlobalLock() { _global_lock(); } ~_GlobalLock() { _global_unlock(); } }; #define GLOBAL_LOCK_FUNCTION _GlobalLock _global_lock_; -#ifdef NO_SAFE_CAST -#define SAFE_CAST static_cast -#else -#define SAFE_CAST dynamic_cast -#endif - -#define MT_SAFE - -#define __STRX(m_index) #m_index -#define __STR(m_index) __STRX(m_index) - -#ifdef __GNUC__ +#if defined(__GNUC__) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else @@ -330,14 +247,12 @@ struct _GlobalLock { #define _PRINTF_FORMAT_ATTRIBUTE_2_3 #endif -/** This is needed due to a strange OpenGL API that expects a pointer - * type for an argument that is actually an offset. - */ +// This is needed due to a strange OpenGL API that expects a pointer +// type for an argument that is actually an offset. #define CAST_INT_TO_UCHAR_PTR(ptr) ((uint8_t *)(uintptr_t)(ptr)) // Home-made index sequence trick, so it can be used everywhere without the costly include of std::tuple. // https://stackoverflow.com/questions/15014096/c-index-of-type-during-variadic-template-expansion - template <size_t... Is> struct IndexSequence {}; diff --git a/core/ustring.cpp b/core/ustring.cpp index 1d4d9c2dfd..da089dce40 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -1402,7 +1402,7 @@ String String::utf8(const char *p_utf8, int p_len) { bool String::parse_utf8(const char *p_utf8, int p_len) { -#define _UNICERROR(m_err) print_line("Unicode error: " + String(m_err)); +#define _UNICERROR(m_err) print_line("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-8?"); if (!p_utf8) return true; diff --git a/core/variant.cpp b/core/variant.cpp index 550974363b..b82602a5a4 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -31,6 +31,7 @@ #include "variant.h" #include "core/core_string_names.h" +#include "core/debugger/engine_debugger.h" #include "core/io/marshalls.h" #include "core/math/math_funcs.h" #include "core/print_string.h" @@ -2221,7 +2222,7 @@ Variant::operator RID() const { return RID(); } else if (type == OBJECT && _get_obj().obj) { #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { ERR_FAIL_COND_V_MSG(ObjectDB::get_instance(_get_obj().id) == nullptr, RID(), "Invalid pointer (object was freed)."); }; #endif diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 95c11be5cf..db7244a221 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -33,10 +33,10 @@ #include "core/color_names.inc" #include "core/core_string_names.h" #include "core/crypto/crypto_core.h" +#include "core/debugger/engine_debugger.h" #include "core/io/compression.h" #include "core/object.h" #include "core/os/os.h" -#include "core/script_language.h" typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args); typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args); @@ -1213,7 +1213,7 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p return; } #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; return; } diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 36d1278929..88f6ce19a2 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -31,8 +31,8 @@ #include "variant.h" #include "core/core_string_names.h" +#include "core/debugger/engine_debugger.h" #include "core/object.h" -#include "core/script_language.h" #define CASE_TYPE_ALL(PREFIX, OP) \ CASE_TYPE(PREFIX, OP, INT) \ @@ -1739,7 +1739,7 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool #ifdef DEBUG_ENABLED if (!_get_obj().obj) { break; - } else if (ScriptDebugger::get_singleton() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + } else if (EngineDebugger::is_active() && ObjectDB::get_instance(_get_obj().id) == nullptr) { break; } @@ -1941,7 +1941,7 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { return "Instance base is null."; } else { - if (ScriptDebugger::get_singleton() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { if (r_valid) *r_valid = false; return "Attempted use of stray pointer object."; @@ -2556,7 +2556,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) if (obj) { #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { WARN_PRINT("Attempted use of previously freed pointer object."); valid = false; @@ -3011,7 +3011,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { valid = false; return "Attempted get on previously freed instance."; } @@ -3076,7 +3076,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { bool valid = false; #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { if (r_valid) { *r_valid = false; } @@ -3405,7 +3405,7 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { if (obj) { #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { WARN_PRINT("Attempted get_property list on previously freed instance."); return; } @@ -3490,7 +3490,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { valid = false; return false; } @@ -3676,7 +3676,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { valid = false; return false; } @@ -3855,7 +3855,7 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { return Variant(); } #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { + if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) { r_valid = false; return Variant(); } diff --git a/doc/classes/AnimatedSprite.xml b/doc/classes/AnimatedSprite.xml index 03c23b6fdd..b5c1d38ff9 100644 --- a/doc/classes/AnimatedSprite.xml +++ b/doc/classes/AnimatedSprite.xml @@ -61,8 +61,10 @@ If [code]true[/code], the [member animation] is currently playing. </member> <member name="shininess" type="float" setter="set_shininess" getter="get_shininess" default="1.0"> + Strength of the specular light effect of this [AnimatedSprite]. </member> <member name="specular_color" type="Color" setter="set_specular_color" getter="get_specular_color" default="Color( 1, 1, 1, 1 )"> + The color of the specular light effect. </member> <member name="speed_scale" type="float" setter="set_speed_scale" getter="get_speed_scale" default="1.0"> The animation speed is multiplied by this value. diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml index 0926ef9855..09811d5617 100644 --- a/doc/classes/Animation.xml +++ b/doc/classes/Animation.xml @@ -14,7 +14,7 @@ animation.track_insert_key(track_index, 0.0, 0) animation.track_insert_key(track_index, 0.5, 100) [/codeblock] - Animations are just data containers, and must be added to nodes such as an [AnimationPlayer] to be played back. + Animations are just data containers, and must be added to nodes such as an [AnimationPlayer] to be played back. Animation tracks have different types, each with its own set of dedicated methods. Check [enum TrackType] to see available types. </description> <tutorials> <link>https://docs.godotengine.org/en/latest/tutorials/animation/index.html</link> @@ -39,6 +39,7 @@ <argument index="1" name="key_idx" type="int"> </argument> <description> + Returns the animation name at the key identified by [code]key_idx[/code]. The [code]track_idx[/code] must be the index of an Animation Track. </description> </method> <method name="animation_track_insert_key"> @@ -51,6 +52,7 @@ <argument index="2" name="animation" type="StringName"> </argument> <description> + Inserts a key with value [code]animation[/code] at the given [code]time[/code] (in seconds). The [code]track_idx[/code] must be the index of an Animation Track. </description> </method> <method name="animation_track_set_key_animation"> @@ -63,6 +65,7 @@ <argument index="2" name="animation" type="StringName"> </argument> <description> + Sets the key identified by [code]key_idx[/code] to value [code]animation[/code]. The [code]track_idx[/code] must be the index of an Animation Track. </description> </method> <method name="audio_track_get_key_end_offset" qualifiers="const"> @@ -73,6 +76,8 @@ <argument index="1" name="key_idx" type="int"> </argument> <description> + Returns the end offset of the key identified by [code]key_idx[/code]. The [code]track_idx[/code] must be the index of an Audio Track. + End offset is the number of seconds cut off at the ending of the audio stream. </description> </method> <method name="audio_track_get_key_start_offset" qualifiers="const"> @@ -83,6 +88,8 @@ <argument index="1" name="key_idx" type="int"> </argument> <description> + Returns the start offset of the key identified by [code]key_idx[/code]. The [code]track_idx[/code] must be the index of an Audio Track. + Start offset is the number of seconds cut off at the beginning of the audio stream. </description> </method> <method name="audio_track_get_key_stream" qualifiers="const"> @@ -93,6 +100,7 @@ <argument index="1" name="key_idx" type="int"> </argument> <description> + Returns the audio stream of the key identified by [code]key_idx[/code]. The [code]track_idx[/code] must be the index of an Audio Track. </description> </method> <method name="audio_track_insert_key"> @@ -109,6 +117,8 @@ <argument index="4" name="end_offset" type="float" default="0"> </argument> <description> + Inserts an Audio Track key at the given [code]time[/code] in seconds. The [code]track_idx[/code] must be the index of an Audio Track. + [code]stream[/code] is the [AudioStream] resource to play. [code]start_offset[/code] is the number of seconds cut off at the beginning of the audio stream, while [code]end_offset[/code] is at the ending. </description> </method> <method name="audio_track_set_key_end_offset"> @@ -121,6 +131,7 @@ <argument index="2" name="offset" type="float"> </argument> <description> + Sets the end offset of the key identified by [code]key_idx[/code] to value [code]offset[/code]. The [code]track_idx[/code] must be the index of an Audio Track. </description> </method> <method name="audio_track_set_key_start_offset"> @@ -133,6 +144,7 @@ <argument index="2" name="offset" type="float"> </argument> <description> + Sets the start offset of the key identified by [code]key_idx[/code] to value [code]offset[/code]. The [code]track_idx[/code] must be the index of an Audio Track. </description> </method> <method name="audio_track_set_key_stream"> @@ -145,6 +157,7 @@ <argument index="2" name="stream" type="Resource"> </argument> <description> + Sets the stream of the key identified by [code]key_idx[/code] to value [code]offset[/code]. The [code]track_idx[/code] must be the index of an Audio Track. </description> </method> <method name="bezier_track_get_key_in_handle" qualifiers="const"> @@ -155,6 +168,7 @@ <argument index="1" name="key_idx" type="int"> </argument> <description> + Returns the in handle of the key identified by [code]key_idx[/code]. The [code]track_idx[/code] must be the index of a Bezier Track. </description> </method> <method name="bezier_track_get_key_out_handle" qualifiers="const"> @@ -165,6 +179,7 @@ <argument index="1" name="key_idx" type="int"> </argument> <description> + Returns the out handle of the key identified by [code]key_idx[/code]. The [code]track_idx[/code] must be the index of a Bezier Track. </description> </method> <method name="bezier_track_get_key_value" qualifiers="const"> @@ -175,6 +190,7 @@ <argument index="1" name="key_idx" type="int"> </argument> <description> + Returns the value of the key identified by [code]key_idx[/code]. The [code]track_idx[/code] must be the index of a Bezier Track. </description> </method> <method name="bezier_track_insert_key"> @@ -191,6 +207,8 @@ <argument index="4" name="out_handle" type="Vector2" default="Vector2( 0, 0 )"> </argument> <description> + Inserts a Bezier Track key at the given [code]time[/code] in seconds. The [code]track_idx[/code] must be the index of a Bezier Track. + [code]in_handle[/code] is the left-side weight of the added Bezier curve point, [code]out_handle[/code] is the right-side one, while [code]value[/code] is the actual value at this point. </description> </method> <method name="bezier_track_interpolate" qualifiers="const"> @@ -201,6 +219,7 @@ <argument index="1" name="time" type="float"> </argument> <description> + Returns the interpolated value at the given [code]time[/code] (in seconds). The [code]track_idx[/code] must be the index of a Bezier Track. </description> </method> <method name="bezier_track_set_key_in_handle"> @@ -213,6 +232,7 @@ <argument index="2" name="in_handle" type="Vector2"> </argument> <description> + Sets the in handle of the key identified by [code]key_idx[/code] to value [code]in_handle[/code]. The [code]track_idx[/code] must be the index of a Bezier Track. </description> </method> <method name="bezier_track_set_key_out_handle"> @@ -225,6 +245,7 @@ <argument index="2" name="out_handle" type="Vector2"> </argument> <description> + Sets the out handle of the key identified by [code]key_idx[/code] to value [code]out_handle[/code]. The [code]track_idx[/code] must be the index of a Bezier Track. </description> </method> <method name="bezier_track_set_key_value"> @@ -237,6 +258,7 @@ <argument index="2" name="value" type="float"> </argument> <description> + Sets the value of the key identified by [code]key_idx[/code] to the given value. The [code]track_idx[/code] must be the index of a Bezier Track. </description> </method> <method name="clear"> @@ -675,6 +697,7 @@ <signals> <signal name="tracks_changed"> <description> + Emitted when there's a change in the list of tracks, e.g. tracks are added, moved or have changed paths. </description> </signal> </signals> @@ -689,10 +712,13 @@ Method tracks call functions with given arguments per key. </constant> <constant name="TYPE_BEZIER" value="3" enum="TrackType"> + Bezier tracks are used to interpolate a value using custom curves. They can also be used to animate sub-properties of vectors and colors (e.g. alpha value of a [Color]). </constant> <constant name="TYPE_AUDIO" value="4" enum="TrackType"> + Audio tracks are used to play an audio stream with either type of [AudioStreamPlayer]. The stream can be trimmed and previewed in the animation. </constant> <constant name="TYPE_ANIMATION" value="5" enum="TrackType"> + Animation tracks play animations in other [AnimationPlayer] nodes. </constant> <constant name="INTERPOLATION_NEAREST" value="0" enum="InterpolationType"> No interpolation (nearest value). @@ -713,6 +739,7 @@ Update at the keyframes. </constant> <constant name="UPDATE_CAPTURE" value="3" enum="UpdateMode"> + Same as linear interpolation, but also interpolates from the current value (i.e. dynamically at runtime) if the first key isn't at 0 seconds. </constant> </constants> </class> diff --git a/doc/classes/AnimationNodeBlendTree.xml b/doc/classes/AnimationNodeBlendTree.xml index 0befb79577..4a34d75ff9 100644 --- a/doc/classes/AnimationNodeBlendTree.xml +++ b/doc/classes/AnimationNodeBlendTree.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AnimationNodeBlendTree" inherits="AnimationRootNode" version="4.0"> <brief_description> + [AnimationTree] node resource that contains many blend type nodes. </brief_description> <description> + This node may contain a sub-tree of any other blend type nodes, such as mix, blend2, blend3, one shot, etc. This is one of the most commonly used roots. </description> <tutorials> <link>https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link> @@ -18,6 +20,7 @@ <argument index="2" name="position" type="Vector2" default="Vector2( 0, 0 )"> </argument> <description> + Adds an [AnimationNode] at the given [code]position[/code]. The [code]name[/code] is used to identify the created sub-node later. </description> </method> <method name="connect_node"> @@ -30,6 +33,7 @@ <argument index="2" name="output_node" type="StringName"> </argument> <description> + Connects the output of an [AnimationNode] as input for another [AnimationNode], at the input port specified by [code]input_index[/code]. </description> </method> <method name="disconnect_node"> @@ -40,6 +44,7 @@ <argument index="1" name="input_index" type="int"> </argument> <description> + Disconnects the node connected to the specified input. </description> </method> <method name="get_node" qualifiers="const"> @@ -48,6 +53,7 @@ <argument index="0" name="name" type="StringName"> </argument> <description> + Returns the sub-node with the specified [code]name[/code]. </description> </method> <method name="get_node_position" qualifiers="const"> @@ -56,6 +62,7 @@ <argument index="0" name="name" type="StringName"> </argument> <description> + Returns the position of the sub-node with the specified [code]name[/code]. </description> </method> <method name="has_node" qualifiers="const"> @@ -64,6 +71,7 @@ <argument index="0" name="name" type="StringName"> </argument> <description> + Returns [code]true[/code] if a sub-node with specified [code]name[/code] exists. </description> </method> <method name="remove_node"> @@ -72,6 +80,7 @@ <argument index="0" name="name" type="StringName"> </argument> <description> + Removes a sub-node. </description> </method> <method name="rename_node"> @@ -82,6 +91,7 @@ <argument index="1" name="new_name" type="StringName"> </argument> <description> + Changes the name of a sub-node. </description> </method> <method name="set_node_position"> @@ -92,25 +102,33 @@ <argument index="1" name="position" type="Vector2"> </argument> <description> + Modifies the position of a sub-node. </description> </method> </methods> <members> <member name="graph_offset" type="Vector2" setter="set_graph_offset" getter="get_graph_offset" default="Vector2( 0, 0 )"> + The global offset of all sub-nodes. </member> </members> <constants> <constant name="CONNECTION_OK" value="0"> + The connection was successful. </constant> <constant name="CONNECTION_ERROR_NO_INPUT" value="1"> + The input node is [code]null[/code]. </constant> <constant name="CONNECTION_ERROR_NO_INPUT_INDEX" value="2"> + The specified input port is out of range. </constant> <constant name="CONNECTION_ERROR_NO_OUTPUT" value="3"> + The output node is [code]null[/code]. </constant> <constant name="CONNECTION_ERROR_SAME_NODE" value="4"> + Input and output nodes are the same. </constant> <constant name="CONNECTION_ERROR_CONNECTION_EXISTS" value="5"> + The specified connection already exists. </constant> </constants> </class> diff --git a/doc/classes/AnimationNodeOneShot.xml b/doc/classes/AnimationNodeOneShot.xml index b6e4ed9c98..4ba0b82df6 100644 --- a/doc/classes/AnimationNodeOneShot.xml +++ b/doc/classes/AnimationNodeOneShot.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AnimationNodeOneShot" inherits="AnimationNode" version="4.0"> <brief_description> + Plays an animation once in [AnimationNodeBlendTree]. </brief_description> <description> + A resource to add to an [AnimationNodeBlendTree]. This node will execute a sub-animation and return once it finishes. Blend times for fading in and out can be customized, as well as filters. </description> <tutorials> <link>https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link> @@ -25,10 +27,13 @@ </methods> <members> <member name="autorestart" type="bool" setter="set_autorestart" getter="has_autorestart" default="false"> + If [code]true[/code], the sub-animation will restart automatically after finishing. </member> <member name="autorestart_delay" type="float" setter="set_autorestart_delay" getter="get_autorestart_delay" default="1.0"> + The delay after which the automatic restart is triggered, in seconds. </member> <member name="autorestart_random_delay" type="float" setter="set_autorestart_random_delay" getter="get_autorestart_random_delay" default="0.0"> + If [member autorestart] is [code]true[/code], a random additional delay (in seconds) between 0 and this value will be added to [member autorestart_delay]. </member> <member name="fadein_time" type="float" setter="set_fadein_time" getter="get_fadein_time" default="0.1"> </member> diff --git a/doc/classes/AnimationNodeOutput.xml b/doc/classes/AnimationNodeOutput.xml index f4bded2cd1..38b05eb650 100644 --- a/doc/classes/AnimationNodeOutput.xml +++ b/doc/classes/AnimationNodeOutput.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AnimationNodeOutput" inherits="AnimationNode" version="4.0"> <brief_description> + Generic output node to be added to [AnimationNodeBlendTree]. </brief_description> <description> </description> diff --git a/doc/classes/AnimationNodeStateMachine.xml b/doc/classes/AnimationNodeStateMachine.xml index b647ff70b8..4ff39b7500 100644 --- a/doc/classes/AnimationNodeStateMachine.xml +++ b/doc/classes/AnimationNodeStateMachine.xml @@ -28,6 +28,17 @@ Adds a new node to the graph. The [code]position[/code] is used for display in the editor. </description> </method> + <method name="replace_node"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="node" type="AnimationNode"> + </argument> + <description> + Replaces the node and keeps its transitions unchanged. + </description> + </method> <method name="add_transition"> <return type="void"> </return> diff --git a/doc/classes/AnimationNodeTimeScale.xml b/doc/classes/AnimationNodeTimeScale.xml index 229f9bbba2..5c2e6cb692 100644 --- a/doc/classes/AnimationNodeTimeScale.xml +++ b/doc/classes/AnimationNodeTimeScale.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AnimationNodeTimeScale" inherits="AnimationNode" version="4.0"> <brief_description> + A time-scaling animation node to be used with [AnimationTree]. </brief_description> <description> + Allows scaling the speed of the animation (or reversing it) in any children nodes. Setting it to 0 will pause the animation. </description> <tutorials> <link>https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link> diff --git a/doc/classes/AnimationNodeTimeSeek.xml b/doc/classes/AnimationNodeTimeSeek.xml index 5a9cbe4861..0fef106da5 100644 --- a/doc/classes/AnimationNodeTimeSeek.xml +++ b/doc/classes/AnimationNodeTimeSeek.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AnimationNodeTimeSeek" inherits="AnimationNode" version="4.0"> <brief_description> + A time-seeking animation node to be used with [AnimationTree]. </brief_description> <description> + This node can be used to cause a seek command to happen to any sub-children of the graph. After setting the time, this value returns to -1. </description> <tutorials> <link>https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link> diff --git a/doc/classes/AnimationNodeTransition.xml b/doc/classes/AnimationNodeTransition.xml index bf94fe0466..11250c5b17 100644 --- a/doc/classes/AnimationNodeTransition.xml +++ b/doc/classes/AnimationNodeTransition.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AnimationNodeTransition" inherits="AnimationNode" version="4.0"> <brief_description> + A generic animation transition node for [AnimationTree]. </brief_description> <description> + Simple state machine for cases which don't require a more advanced [AnimationNodeStateMachine]. Animations can be connected to the inputs and transition times can be specified. </description> <tutorials> <link>https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html</link> @@ -47,8 +49,10 @@ </methods> <members> <member name="input_count" type="int" setter="set_enabled_inputs" getter="get_enabled_inputs" default="0"> + The number of available input ports for this node. </member> <member name="xfade_time" type="float" setter="set_cross_fade_time" getter="get_cross_fade_time" default="0.0"> + Cross-fading time (in seconds) between each animation connected to the inputs. </member> </members> <constants> diff --git a/doc/classes/AnimationTree.xml b/doc/classes/AnimationTree.xml index 2a7db37eea..9642dd1c70 100644 --- a/doc/classes/AnimationTree.xml +++ b/doc/classes/AnimationTree.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AnimationTree" inherits="Node" version="4.0"> <brief_description> + A node to be used for advanced animation transitions in an [AnimationPlayer]. </brief_description> <description> </description> @@ -15,6 +16,7 @@ <argument index="0" name="delta" type="float"> </argument> <description> + Manually advance the animations by the specified time (in seconds). </description> </method> <method name="get_root_motion_transform" qualifiers="const"> @@ -36,22 +38,29 @@ </methods> <members> <member name="active" type="bool" setter="set_active" getter="is_active" default="false"> + If [code]true[/code], the [AnimationTree] will be processing. </member> <member name="anim_player" type="NodePath" setter="set_animation_player" getter="get_animation_player" default="NodePath("")"> + The path to the [AnimationPlayer] used for animating. </member> <member name="process_mode" type="int" setter="set_process_mode" getter="get_process_mode" enum="AnimationTree.AnimationProcessMode" default="1"> + The process mode of this [AnimationTree]. See [enum AnimationProcessMode] for available modes. </member> <member name="root_motion_track" type="NodePath" setter="set_root_motion_track" getter="get_root_motion_track" default="NodePath("")"> </member> <member name="tree_root" type="AnimationNode" setter="set_tree_root" getter="get_tree_root"> + The root animation node of this [AnimationTree]. See [AnimationNode]. </member> </members> <constants> <constant name="ANIMATION_PROCESS_PHYSICS" value="0" enum="AnimationProcessMode"> + The animations will progress during the physics frame (i.e. [method Node._physics_process]). </constant> <constant name="ANIMATION_PROCESS_IDLE" value="1" enum="AnimationProcessMode"> + The animations will progress during the idle frame (i.e. [method Node._process]). </constant> <constant name="ANIMATION_PROCESS_MANUAL" value="2" enum="AnimationProcessMode"> + The animations will only progress manually (see [method advance]). </constant> </constants> </class> diff --git a/doc/classes/ArrayMesh.xml b/doc/classes/ArrayMesh.xml index 33b62054df..47abd2e996 100644 --- a/doc/classes/ArrayMesh.xml +++ b/doc/classes/ArrayMesh.xml @@ -70,6 +70,7 @@ <return type="void"> </return> <description> + Removes all surfaces from this [ArrayMesh]. </description> </method> <method name="get_blend_shape_count" qualifiers="const"> diff --git a/doc/classes/AudioEffectRecord.xml b/doc/classes/AudioEffectRecord.xml index 189e3c7059..4dac81322f 100644 --- a/doc/classes/AudioEffectRecord.xml +++ b/doc/classes/AudioEffectRecord.xml @@ -1,22 +1,26 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="AudioEffectRecord" inherits="AudioEffect" version="4.0"> <brief_description> + Audio effect used for recording sound from a microphone. </brief_description> <description> </description> <tutorials> + <link>https://docs.godotengine.org/en/latest/tutorials/audio/recording_with_microphone.html</link> </tutorials> <methods> <method name="get_recording" qualifiers="const"> <return type="AudioStreamSample"> </return> <description> + Returns the recorded sample. </description> </method> <method name="is_recording_active" qualifiers="const"> <return type="bool"> </return> <description> + Returns whether the recording is active or not. </description> </method> <method name="set_recording_active"> @@ -25,11 +29,13 @@ <argument index="0" name="record" type="bool"> </argument> <description> + If [code]true[/code], the sound will be recorded. Note that restarting the recording will remove the previously recorded sample. </description> </method> </methods> <members> <member name="format" type="int" setter="set_format" getter="get_format" enum="AudioStreamSample.Format" default="1"> + Specifies the format in which the sample will be recorded. See [enum AudioStreamSample.Format] for available formats. </member> </members> <constants> diff --git a/doc/classes/BaseMaterial3D.xml b/doc/classes/BaseMaterial3D.xml index 2e4ca9677d..380e739f46 100644 --- a/doc/classes/BaseMaterial3D.xml +++ b/doc/classes/BaseMaterial3D.xml @@ -67,6 +67,7 @@ <argument index="1" name="texture" type="Texture2D"> </argument> <description> + Sets the texture for the slot specified by [code]param[/code]. See [enum TextureParam] for available slots. </description> </method> </methods> @@ -425,8 +426,10 @@ Represents the size of the [enum TextureParam] enum. </constant> <constant name="TEXTURE_FILTER_NEAREST" value="0" enum="TextureFilter"> + The texture filter reads from the nearest pixel only. The simplest and fastest method of filtering, but the texture will look pixelized. </constant> <constant name="TEXTURE_FILTER_LINEAR" value="1" enum="TextureFilter"> + The texture filter blends between the nearest four pixels. Use this for most cases where you want to avoid a pixelated style. </constant> <constant name="TEXTURE_FILTER_NEAREST_WITH_MIPMAPS" value="2" enum="TextureFilter"> </constant> @@ -437,6 +440,7 @@ <constant name="TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC" value="5" enum="TextureFilter"> </constant> <constant name="TEXTURE_FILTER_MAX" value="6" enum="TextureFilter"> + Represents the size of the [enum TextureFilter] enum. </constant> <constant name="DETAIL_UV_1" value="0" enum="DetailUV"> Use [code]UV[/code] with the detail texture. @@ -445,22 +449,29 @@ Use [code]UV2[/code] with the detail texture. </constant> <constant name="TRANSPARENCY_DISABLED" value="0" enum="Transparency"> + The material will not use transparency. </constant> <constant name="TRANSPARENCY_ALPHA" value="1" enum="Transparency"> + The material will use the texture's alpha values for transparency. </constant> <constant name="TRANSPARENCY_ALPHA_SCISSOR" value="2" enum="Transparency"> </constant> <constant name="TRANSPARENCY_ALPHA_DEPTH_PRE_PASS" value="3" enum="Transparency"> </constant> <constant name="TRANSPARENCY_MAX" value="4" enum="Transparency"> + Represents the size of the [enum Transparency] enum. </constant> <constant name="SHADING_MODE_UNSHADED" value="0" enum="ShadingMode"> + The object will not receive shadows. </constant> <constant name="SHADING_MODE_PER_PIXEL" value="1" enum="ShadingMode"> + The object will be shaded per pixel. Useful for realistic shading effect. </constant> <constant name="SHADING_MODE_PER_VERTEX" value="2" enum="ShadingMode"> + The object will be shaded per vertex. Useful when you want cheaper shaders and do not care about visual quality. </constant> <constant name="SHADING_MODE_MAX" value="3" enum="ShadingMode"> + Represents the size of the [enum ShadingMode] enum. </constant> <constant name="FEATURE_EMISSION" value="0" enum="Feature"> Constant for setting [member emission_enabled]. diff --git a/doc/classes/Callable.xml b/doc/classes/Callable.xml index ec38128c1e..3cc74beb58 100644 --- a/doc/classes/Callable.xml +++ b/doc/classes/Callable.xml @@ -1,8 +1,20 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="Callable" version="4.0"> <brief_description> + An object representing a method in a certain object that can be called. </brief_description> <description> + [Callable] is a first class object which can be held in variables and passed to functions. It represents a given method in an [Object], and is typically used for signal callbacks. + [b]Example:[/b] + [codeblock] + var callable = Callable(self, "print_args") + func print_args(arg1, arg2, arg3 = ""): + prints(arg1, arg2, arg3) + func test(): + callable.call("hello", "world") # Prints "hello world". + callable.call(Vector2.UP, 42, callable) # Prints "(0, -1) 42 Node(Node.gd)::print_args". + callable.call("invalid") # Invalid call, should have at least 2 arguments. + [/codeblock] </description> <tutorials> </tutorials> @@ -15,36 +27,42 @@ <argument index="1" name="method_name" type="StringName"> </argument> <description> + Creates a new [Callable] for the method called [code]method_name[/code] in the specified [code]object[/code]. </description> </method> <method name="call" qualifiers="vararg"> <return type="Variant"> </return> <description> + Calls the method represented by this [Callable]. Arguments can be passed and should match the method's signature. </description> </method> <method name="call_deferred" qualifiers="vararg"> <return type="void"> </return> <description> + Calls the method represented by this [Callable] in deferred mode, i.e. during the idle frame. Arguments can be passed and should match the method's signature. </description> </method> <method name="get_method"> <return type="StringName"> </return> <description> + Returns the name of the method represented by this [Callable]. </description> </method> <method name="get_object"> <return type="Object"> </return> <description> + Returns the object on which this [Callable] is called. </description> </method> <method name="get_object_id"> <return type="int"> </return> <description> + Returns the ID of this [Callable]'s object (see [method Object.get_instance_id]). </description> </method> <method name="hash"> diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml index dec7c907a4..73ba8b392f 100644 --- a/doc/classes/CanvasItem.xml +++ b/doc/classes/CanvasItem.xml @@ -656,10 +656,13 @@ The [CanvasItem] has exited the canvas. </constant> <constant name="TEXTURE_FILTER_PARENT_NODE" value="0" enum="TextureFilter"> + The [CanvasItem] will inherit the filter from its parent. </constant> <constant name="TEXTURE_FILTER_NEAREST" value="1" enum="TextureFilter"> + The texture filter reads from the nearest pixel only. The simplest and fastest method of filtering. Useful for pixel art. </constant> <constant name="TEXTURE_FILTER_LINEAR" value="2" enum="TextureFilter"> + The texture filter blends between the nearest four pixels. Use this for most cases where you want to avoid a pixelated style. </constant> <constant name="TEXTURE_FILTER_NEAREST_WITH_MIPMAPS" value="3" enum="TextureFilter"> </constant> @@ -670,16 +673,22 @@ <constant name="TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC" value="6" enum="TextureFilter"> </constant> <constant name="TEXTURE_FILTER_MAX" value="7" enum="TextureFilter"> + Represents the size of the [enum TextureFilter] enum. </constant> <constant name="TEXTURE_REPEAT_PARENT_NODE" value="0" enum="TextureRepeat"> + The [CanvasItem] will inherit the filter from its parent. </constant> <constant name="TEXTURE_REPEAT_DISABLED" value="1" enum="TextureRepeat"> + Texture will not repeat. </constant> <constant name="TEXTURE_REPEAT_ENABLED" value="2" enum="TextureRepeat"> + Texture will repeat normally. </constant> <constant name="TEXTURE_REPEAT_MIRROR" value="3" enum="TextureRepeat"> + Texture will repeat in a 2x2 tiled mode, where elements at even positions are mirrored. </constant> <constant name="TEXTURE_REPEAT_MAX" value="4" enum="TextureRepeat"> + Represents the size of the [enum TextureRepeat] enum. </constant> </constants> </class> diff --git a/doc/classes/CheckBox.xml b/doc/classes/CheckBox.xml index c29f089bce..9c42091eb8 100644 --- a/doc/classes/CheckBox.xml +++ b/doc/classes/CheckBox.xml @@ -4,7 +4,7 @@ Binary choice user interface widget. See also [CheckButton]. </brief_description> <description> - A checkbox allows the user to make a binary choice (choosing only one of two possible options). It's similar to [CheckButton] in functionality, but it has a different apperance. To follow established UX patterns, it's recommended to use CheckBox when toggling it has [b]no[/b] immediate effect on something. For instance, it should be used when toggling it will only do something once a confirmation button is pressed. + A checkbox allows the user to make a binary choice (choosing only one of two possible options). It's similar to [CheckButton] in functionality, but it has a different appearance. To follow established UX patterns, it's recommended to use CheckBox when toggling it has [b]no[/b] immediate effect on something. For instance, it should be used when toggling it will only do something once a confirmation button is pressed. </description> <tutorials> </tutorials> diff --git a/doc/classes/CheckButton.xml b/doc/classes/CheckButton.xml index 616940a494..514ff9a691 100644 --- a/doc/classes/CheckButton.xml +++ b/doc/classes/CheckButton.xml @@ -4,7 +4,7 @@ Checkable button. See also [CheckBox]. </brief_description> <description> - CheckButton is a toggle button displayed as a check field. It's similar to [CheckBox] in functionality, but it has a different apperance. To follow established UX patterns, it's recommended to use CheckButton when toggling it has an [b]immediate[/b] effect on something. For instance, it should be used if toggling it enables/disables a setting without requiring the user to press a confirmation button. + CheckButton is a toggle button displayed as a check field. It's similar to [CheckBox] in functionality, but it has a different appearance. To follow established UX patterns, it's recommended to use CheckButton when toggling it has an [b]immediate[/b] effect on something. For instance, it should be used if toggling it enables/disables a setting without requiring the user to press a confirmation button. </description> <tutorials> </tutorials> diff --git a/doc/classes/CollisionPolygon2D.xml b/doc/classes/CollisionPolygon2D.xml index e3135a4d0f..242cdb8c80 100644 --- a/doc/classes/CollisionPolygon2D.xml +++ b/doc/classes/CollisionPolygon2D.xml @@ -21,6 +21,7 @@ If [code]true[/code], only edges that face up, relative to [CollisionPolygon2D]'s rotation, will collide with other objects. </member> <member name="one_way_collision_margin" type="float" setter="set_one_way_collision_margin" getter="get_one_way_collision_margin" default="1.0"> + The margin used for one-way collision (in pixels). Higher values will make the shape thicker, and work better for colliders that enter the polygon at a high velocity. </member> <member name="polygon" type="PackedVector2Array" setter="set_polygon" getter="get_polygon" default="PackedVector2Array( )"> The polygon's list of vertices. The final point will be connected to the first. The returned value is a clone of the [PackedVector2Array], not a reference. diff --git a/doc/classes/CollisionShape2D.xml b/doc/classes/CollisionShape2D.xml index 4903f0d3a5..e32ce9c9f9 100644 --- a/doc/classes/CollisionShape2D.xml +++ b/doc/classes/CollisionShape2D.xml @@ -19,7 +19,7 @@ Sets whether this collision shape should only detect collision on one side (top or bottom). </member> <member name="one_way_collision_margin" type="float" setter="set_one_way_collision_margin" getter="get_one_way_collision_margin" default="1.0"> - The margin used for one-way collision (in pixels). + The margin used for one-way collision (in pixels). Higher values will make the shape thicker, and work better for colliders that enter the shape at a high velocity. </member> <member name="shape" type="Shape2D" setter="set_shape" getter="get_shape"> The actual shape owned by this collision shape. diff --git a/doc/classes/ColorPicker.xml b/doc/classes/ColorPicker.xml index 5ab929d911..d8b4a8f76c 100644 --- a/doc/classes/ColorPicker.xml +++ b/doc/classes/ColorPicker.xml @@ -88,26 +88,34 @@ </constants> <theme_items> <theme_item name="add_preset" type="Texture2D"> + The icon for the "Add Preset" button. </theme_item> <theme_item name="color_hue" type="Texture2D"> + Custom texture for the hue selection slider on the right. </theme_item> <theme_item name="color_sample" type="Texture2D"> </theme_item> <theme_item name="h_width" type="int" default="30"> + The width of the hue selection slider. </theme_item> <theme_item name="label_width" type="int" default="10"> </theme_item> <theme_item name="margin" type="int" default="4"> + The margin around the [ColorPicker]. </theme_item> <theme_item name="overbright_indicator" type="Texture2D"> + The indicator used to signalize that the color value is outside the 0-1 range. </theme_item> <theme_item name="preset_bg" type="Texture2D"> </theme_item> <theme_item name="screen_picker" type="Texture2D"> + The icon for the screen color picker button. </theme_item> <theme_item name="sv_height" type="int" default="256"> + The height of the saturation-value selection box. </theme_item> <theme_item name="sv_width" type="int" default="256"> + The width of the saturation-value selection box. </theme_item> </theme_items> </class> diff --git a/doc/classes/EditorExportPlugin.xml b/doc/classes/EditorExportPlugin.xml index da3840384e..8fac3e950d 100644 --- a/doc/classes/EditorExportPlugin.xml +++ b/doc/classes/EditorExportPlugin.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="EditorExportPlugin" inherits="Reference" version="4.0"> <brief_description> + A script that is executed when exporting projects. </brief_description> <description> </description> @@ -19,12 +20,14 @@ <argument index="3" name="flags" type="int"> </argument> <description> + Virtual method to be overridden by the user. It is called when the export starts and provides all information about the export. </description> </method> <method name="_export_end" qualifiers="virtual"> <return type="void"> </return> <description> + Virtual method to be overridden by the user. Called when the export is finished. </description> </method> <method name="_export_file" qualifiers="virtual"> diff --git a/doc/classes/EditorFileDialog.xml b/doc/classes/EditorFileDialog.xml index 2afdfde064..3e6bbd682d 100644 --- a/doc/classes/EditorFileDialog.xml +++ b/doc/classes/EditorFileDialog.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="EditorFileDialog" inherits="ConfirmationDialog" version="4.0"> <brief_description> + A modified version of [FileDialog] used by the editor. </brief_description> <description> </description> diff --git a/doc/classes/EditorFileSystem.xml b/doc/classes/EditorFileSystem.xml index a79c57e90f..30e1de1f5e 100644 --- a/doc/classes/EditorFileSystem.xml +++ b/doc/classes/EditorFileSystem.xml @@ -75,6 +75,7 @@ <return type="void"> </return> <description> + Scans the script files and updates the list of custom class names. </description> </method> </methods> diff --git a/doc/classes/Environment.xml b/doc/classes/Environment.xml index 3dad948629..f5c04b3947 100644 --- a/doc/classes/Environment.xml +++ b/doc/classes/Environment.xml @@ -191,6 +191,7 @@ <member name="reflected_light_source" type="int" setter="set_reflection_source" getter="get_reflection_source" enum="Environment.ReflectionSource" default="0"> </member> <member name="sky" type="Sky" setter="set_sky" getter="get_sky"> + The [Sky] resource used for this [Environment]. </member> <member name="sky_custom_fov" type="float" setter="set_sky_custom_fov" getter="get_sky_custom_fov" default="0.0"> </member> diff --git a/doc/classes/FileDialog.xml b/doc/classes/FileDialog.xml index f2c65a8610..78fcec33ea 100644 --- a/doc/classes/FileDialog.xml +++ b/doc/classes/FileDialog.xml @@ -133,16 +133,22 @@ </constants> <theme_items> <theme_item name="files_disabled" type="Color" default="Color( 0, 0, 0, 0.7 )"> + The color tint for disabled files (when the [FileDialog] is used in open folder mode). </theme_item> <theme_item name="folder" type="Texture2D"> + Custom icon for folders. </theme_item> <theme_item name="folder_icon_modulate" type="Color" default="Color( 1, 1, 1, 1 )"> + The color modulation applied to the folder icon. </theme_item> <theme_item name="parent_folder" type="Texture2D"> + Custom icon for the parent folder arrow. </theme_item> <theme_item name="reload" type="Texture2D"> + Custom icon for the reload button. </theme_item> <theme_item name="toggle_hidden" type="Texture2D"> + Custom icon for the toggle hidden button. </theme_item> </theme_items> </class> diff --git a/doc/classes/Font.xml b/doc/classes/Font.xml index 6543a3ecf1..882f819e37 100644 --- a/doc/classes/Font.xml +++ b/doc/classes/Font.xml @@ -85,6 +85,7 @@ <argument index="1" name="width" type="float"> </argument> <description> + Returns the size that the string would have with word wrapping enabled with a fixed [code]width[/code]. </description> </method> <method name="has_outline" qualifiers="const"> diff --git a/doc/classes/Geometry.xml b/doc/classes/Geometry.xml index b2d77f6f92..4d6f7b60a3 100644 --- a/doc/classes/Geometry.xml +++ b/doc/classes/Geometry.xml @@ -70,7 +70,7 @@ </argument> <description> Clips [code]polygon_a[/code] against [code]polygon_b[/code] and returns an array of clipped polygons. This performs [constant OPERATION_DIFFERENCE] between polygons. Returns an empty array if [code]polygon_b[/code] completely overlaps [code]polygon_a[/code]. - If [code]polygon_b[/code] is enclosed by [code]polygon_a[/code], returns an outer polygon (boundary) and inner polygon (hole) which could be distiguished by calling [method is_polygon_clockwise]. + If [code]polygon_b[/code] is enclosed by [code]polygon_a[/code], returns an outer polygon (boundary) and inner polygon (hole) which could be distinguished by calling [method is_polygon_clockwise]. </description> </method> <method name="clip_polyline_with_polygon_2d"> @@ -102,7 +102,7 @@ </argument> <description> Mutually excludes common area defined by intersection of [code]polygon_a[/code] and [code]polygon_b[/code] (see [method intersect_polygons_2d]) and returns an array of excluded polygons. This performs [constant OPERATION_XOR] between polygons. In other words, returns all but common area between polygons. - The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distiguished by calling [method is_polygon_clockwise]. + The operation may result in an outer polygon (boundary) and inner polygon (hole) produced which could be distinguished by calling [method is_polygon_clockwise]. </description> </method> <method name="get_closest_point_to_segment"> diff --git a/doc/classes/GraphEdit.xml b/doc/classes/GraphEdit.xml index 543afb01ee..c41ffd4bff 100644 --- a/doc/classes/GraphEdit.xml +++ b/doc/classes/GraphEdit.xml @@ -303,26 +303,37 @@ <theme_item name="bezier_len_pos" type="int" default="80"> </theme_item> <theme_item name="bg" type="StyleBox"> + The background drawn under the grid. </theme_item> <theme_item name="grid_major" type="Color" default="Color( 1, 1, 1, 0.2 )"> + Color of major grid lines. </theme_item> <theme_item name="grid_minor" type="Color" default="Color( 1, 1, 1, 0.05 )"> + Color of minor grid lines. </theme_item> <theme_item name="minus" type="Texture2D"> + The icon for the zoom out button. </theme_item> <theme_item name="more" type="Texture2D"> + The icon for the zoom in button. </theme_item> <theme_item name="port_grab_distance_horizontal" type="int" default="48"> + The horizontal range within which a port can be grabbed (on both sides). </theme_item> <theme_item name="port_grab_distance_vertical" type="int" default="6"> + The vertical range within which a port can be grabbed (on both sides). </theme_item> <theme_item name="reset" type="Texture2D"> + The icon for the zoom reset button. </theme_item> <theme_item name="selection_fill" type="Color" default="Color( 1, 1, 1, 0.3 )"> + The fill color of the selection rectangle. </theme_item> <theme_item name="selection_stroke" type="Color" default="Color( 1, 1, 1, 0.8 )"> + The outline color of the selection rectangle. </theme_item> <theme_item name="snap" type="Texture2D"> + The icon for the snap toggle button. </theme_item> </theme_items> </class> diff --git a/doc/classes/GraphNode.xml b/doc/classes/GraphNode.xml index a9f1b15443..33074536da 100644 --- a/doc/classes/GraphNode.xml +++ b/doc/classes/GraphNode.xml @@ -253,42 +253,59 @@ </constants> <theme_items> <theme_item name="breakpoint" type="StyleBox"> + The background used when [member overlay] is set to [constant OVERLAY_BREAKPOINT]. </theme_item> <theme_item name="close" type="Texture2D"> + The icon for the close button, visible when [member show_close] is enabled. </theme_item> <theme_item name="close_color" type="Color" default="Color( 0, 0, 0, 1 )"> + The color modulation applied to the close button icon. </theme_item> <theme_item name="close_offset" type="int" default="18"> + The vertical offset of the close button. </theme_item> <theme_item name="comment" type="StyleBox"> + The [StyleBox] used when [member comment] is enabled. </theme_item> <theme_item name="commentfocus" type="StyleBox"> + The [StyleBox] used when [member comment] is enabled and the [GraphNode] is focused. </theme_item> <theme_item name="defaultfocus" type="StyleBox"> </theme_item> <theme_item name="defaultframe" type="StyleBox"> </theme_item> <theme_item name="frame" type="StyleBox"> + The default background for [GraphNode]. </theme_item> <theme_item name="port" type="Texture2D"> + The icon used for representing ports. </theme_item> <theme_item name="port_offset" type="int" default="3"> + Horizontal offset for the ports. </theme_item> <theme_item name="position" type="StyleBox"> + The background used when [member overlay] is set to [constant OVERLAY_POSITION]. </theme_item> <theme_item name="resizer" type="Texture2D"> + The icon used for resizer, visible when [member resizable] is enabled. </theme_item> <theme_item name="resizer_color" type="Color" default="Color( 0, 0, 0, 1 )"> + The color modulation applied to the resizer icon. </theme_item> <theme_item name="selectedframe" type="StyleBox"> + The background used when the [GraphNode] is selected. </theme_item> <theme_item name="separation" type="int" default="1"> + The vertical distance between ports. </theme_item> <theme_item name="title_color" type="Color" default="Color( 0, 0, 0, 1 )"> + Color of the title text. </theme_item> <theme_item name="title_font" type="Font"> + Font used for the title text. </theme_item> <theme_item name="title_offset" type="int" default="20"> + Vertical offset of the title text. </theme_item> </theme_items> </class> diff --git a/doc/classes/GridContainer.xml b/doc/classes/GridContainer.xml index 4493ee8dc1..e13dc43104 100644 --- a/doc/classes/GridContainer.xml +++ b/doc/classes/GridContainer.xml @@ -20,8 +20,10 @@ </constants> <theme_items> <theme_item name="hseparation" type="int" default="4"> + The horizontal separation of children nodes. </theme_item> <theme_item name="vseparation" type="int" default="4"> + The vertical separation of children nodes. </theme_item> </theme_items> </class> diff --git a/doc/classes/HSeparator.xml b/doc/classes/HSeparator.xml index aa83b67934..5b418d6428 100644 --- a/doc/classes/HSeparator.xml +++ b/doc/classes/HSeparator.xml @@ -14,8 +14,10 @@ </constants> <theme_items> <theme_item name="separation" type="int" default="4"> + The height of the area covered by the separator. Effectively works like a minimum height. </theme_item> <theme_item name="separator" type="StyleBox"> + The style for the separator line. Works best with [StyleBoxLine]. </theme_item> </theme_items> </class> diff --git a/doc/classes/HSlider.xml b/doc/classes/HSlider.xml index be3c94e495..2738958058 100644 --- a/doc/classes/HSlider.xml +++ b/doc/classes/HSlider.xml @@ -14,16 +14,22 @@ </constants> <theme_items> <theme_item name="grabber" type="Texture2D"> + The texture for the grabber (the draggable element). </theme_item> <theme_item name="grabber_area" type="StyleBox"> + The background of the area to the left of the grabber. </theme_item> <theme_item name="grabber_disabled" type="Texture2D"> + The texture for the grabber when it's disabled. </theme_item> <theme_item name="grabber_highlight" type="Texture2D"> + The texture for the grabber when it's focused. </theme_item> <theme_item name="slider" type="StyleBox"> + The background for the whole slider. Determines the height of the [code]grabber_area[/code]. </theme_item> <theme_item name="tick" type="Texture2D"> + The texture for the ticks, visible when [member Slider.tick_count] is greater than 0. </theme_item> </theme_items> </class> diff --git a/doc/classes/HSplitContainer.xml b/doc/classes/HSplitContainer.xml index 0dd1f96602..f6e9f33c20 100644 --- a/doc/classes/HSplitContainer.xml +++ b/doc/classes/HSplitContainer.xml @@ -14,12 +14,15 @@ </constants> <theme_items> <theme_item name="autohide" type="int" default="1"> + Boolean value. If 1 ([code]true[/code]), the grabber will hide automatically when it isn't under the cursor. If 0 ([code]false[/code]), it's always visible. </theme_item> <theme_item name="bg" type="StyleBox"> </theme_item> <theme_item name="grabber" type="Texture2D"> + The icon used for the grabber drawn in the middle area. </theme_item> <theme_item name="separation" type="int" default="12"> + The space between sides of the container. </theme_item> </theme_items> </class> diff --git a/doc/classes/HingeJoint.xml b/doc/classes/HingeJoint.xml index 53fa74cace..0d1b6ff0e0 100644 --- a/doc/classes/HingeJoint.xml +++ b/doc/classes/HingeJoint.xml @@ -15,6 +15,7 @@ <argument index="0" name="flag" type="int" enum="HingeJoint.Flag"> </argument> <description> + Returns the value of the specified flag. </description> </method> <method name="get_param" qualifiers="const"> @@ -23,6 +24,7 @@ <argument index="0" name="param" type="int" enum="HingeJoint.Param"> </argument> <description> + Returns the value of the specified parameter. </description> </method> <method name="set_flag"> @@ -33,6 +35,7 @@ <argument index="1" name="enabled" type="bool"> </argument> <description> + If [code]true[/code], enables the specified flag. </description> </method> <method name="set_param"> @@ -43,6 +46,7 @@ <argument index="1" name="value" type="float"> </argument> <description> + Sets the value of the specified parameter. </description> </method> </methods> diff --git a/doc/classes/ImageTexture.xml b/doc/classes/ImageTexture.xml index 98eb42831b..1578783b8b 100644 --- a/doc/classes/ImageTexture.xml +++ b/doc/classes/ImageTexture.xml @@ -42,6 +42,7 @@ <argument index="1" name="immediate" type="bool" default="false"> </argument> <description> + Replaces the texture's data with a new [code]image[/code]. If [code]immediate[/code] is [code]true[/code], it will take effect immediately after the call. </description> </method> </methods> diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml index 557a63b1cc..0f212e7498 100644 --- a/doc/classes/Input.xml +++ b/doc/classes/Input.xml @@ -349,7 +349,8 @@ <argument index="0" name="enable" type="bool"> </argument> <description> - Whether to accumulate similar input events sent by the operating system. Enabled by default. + Enables or disables the accumulation of similar input events sent by the operating system. When input accumulation is enabled, all input events generated during a frame will be merged and emitted when the frame is done rendering. Therefore, this limits the number of input method calls per second to the rendering FPS. + Input accumulation is enabled by default. It can be disabled to get slightly more precise/reactive input at the cost of increased CPU usage. In applications where drawing freehand lines is required, input accumulation should generally be disabled while the user is drawing the line to get results that closely follow the actual input. </description> </method> <method name="start_joy_vibration"> diff --git a/doc/classes/InputEventGesture.xml b/doc/classes/InputEventGesture.xml index 9cacd3e6fd..861ec026cd 100644 --- a/doc/classes/InputEventGesture.xml +++ b/doc/classes/InputEventGesture.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="InputEventGesture" inherits="InputEventWithModifiers" version="4.0"> <brief_description> + Base class for touch control gestures. </brief_description> <description> </description> @@ -10,6 +11,7 @@ </methods> <members> <member name="position" type="Vector2" setter="set_position" getter="get_position" default="Vector2( 0, 0 )"> + The local gesture position relative to the [Viewport]. If used in [method Control._gui_input], the position is relative to the current [Control] that received this gesture. </member> </members> <constants> diff --git a/doc/classes/MultiMesh.xml b/doc/classes/MultiMesh.xml index 24b87f8e28..2a1d270990 100644 --- a/doc/classes/MultiMesh.xml +++ b/doc/classes/MultiMesh.xml @@ -125,8 +125,10 @@ Format of transform used to transform mesh, either 2D or 3D. </member> <member name="use_colors" type="bool" setter="set_use_colors" getter="is_using_colors" default="false"> + If [code]true[/code], the [MultiMesh] will use color data (see [member color_array]). </member> <member name="use_custom_data" type="bool" setter="set_use_custom_data" getter="is_using_custom_data" default="false"> + If [code]true[/code], the [MultiMesh] will use custom data (see [member custom_data_array]). </member> <member name="visible_instance_count" type="int" setter="set_visible_instance_count" getter="get_visible_instance_count" default="-1"> Limits the number of instances drawn, -1 draws all instances. Changing this does not change the sizes of the buffers. diff --git a/doc/classes/NavigationAgent.xml b/doc/classes/NavigationAgent.xml index f896bf6d15..c6c9abec13 100644 --- a/doc/classes/NavigationAgent.xml +++ b/doc/classes/NavigationAgent.xml @@ -124,7 +124,7 @@ The distance to search for other agents. </member> <member name="path_max_distance" type="float" setter="set_path_max_distance" getter="get_path_max_distance" default="3.0"> - The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceded, it recalculates the ideal path. + The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceeded, it recalculates the ideal path. </member> <member name="radius" type="float" setter="set_radius" getter="get_radius" default="1.0"> The radius of the agent. diff --git a/doc/classes/NavigationAgent2D.xml b/doc/classes/NavigationAgent2D.xml index 116db76cc5..5a9c31ef67 100644 --- a/doc/classes/NavigationAgent2D.xml +++ b/doc/classes/NavigationAgent2D.xml @@ -118,7 +118,7 @@ The distance to search for other agents. </member> <member name="path_max_distance" type="float" setter="set_path_max_distance" getter="get_path_max_distance" default="3.0"> - The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceded, it recalculates the ideal path. + The maximum distance the agent is allowed away from the ideal path to the final location. This can happen due to trying to avoid collisions. When the maximum distance is exceeded, it recalculates the ideal path. </member> <member name="radius" type="float" setter="set_radius" getter="get_radius" default="10.0"> The radius of the agent. diff --git a/doc/classes/NavigationRegion.xml b/doc/classes/NavigationRegion.xml index 41fac70654..a32ded2878 100644 --- a/doc/classes/NavigationRegion.xml +++ b/doc/classes/NavigationRegion.xml @@ -13,7 +13,7 @@ <return type="void"> </return> <description> - Bakes the [NavigationMesh]. The baking is done in a seperate thread because navigation baking is not a cheap operation. This can be done at runtime. When it is completed, it automatically sets the new [NavigationMesh]. + Bakes the [NavigationMesh]. The baking is done in a separate thread because navigation baking is not a cheap operation. This can be done at runtime. When it is completed, it automatically sets the new [NavigationMesh]. </description> </method> </methods> diff --git a/doc/classes/PackedDataContainerRef.xml b/doc/classes/PackedDataContainerRef.xml index 9e7ed59054..f0f59675de 100644 --- a/doc/classes/PackedDataContainerRef.xml +++ b/doc/classes/PackedDataContainerRef.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="PackedDataContainerRef" inherits="Reference" version="4.0"> <brief_description> + Reference version of [PackedDataContainer]. </brief_description> <description> </description> diff --git a/doc/classes/PacketPeerUDP.xml b/doc/classes/PacketPeerUDP.xml index aa5599a3fb..668655b725 100644 --- a/doc/classes/PacketPeerUDP.xml +++ b/doc/classes/PacketPeerUDP.xml @@ -25,7 +25,7 @@ </argument> <description> Calling this method connects this UDP peer to the given [code]host[/code]/[code]port[/code] pair. UDP is in reality connectionless, so this option only means that incoming packets from different addresses are automatically discarded, and that outgoing packets are always sent to the connected address (future calls to [method set_dest_address] are not allowed). This method does not send any data to the remote peer, to do that, use [method PacketPeer.put_var] or [method PacketPeer.put_packet] as usual. See also [UDPServer]. - Note: Connecting to the remote peer does not help to protect from malicious attacks like IP spoofing, etc. Think about using an encryption technique like SSL or DTLS if you feel like your application is transfering sensitive information. + Note: Connecting to the remote peer does not help to protect from malicious attacks like IP spoofing, etc. Think about using an encryption technique like SSL or DTLS if you feel like your application is transferring sensitive information. </description> </method> <method name="get_packet_ip" qualifiers="const"> diff --git a/doc/classes/Panel.xml b/doc/classes/Panel.xml index a96871ba28..a3f6a0be8f 100644 --- a/doc/classes/Panel.xml +++ b/doc/classes/Panel.xml @@ -14,6 +14,7 @@ </constants> <theme_items> <theme_item name="panel" type="StyleBox"> + The style of this [Panel]. </theme_item> </theme_items> </class> diff --git a/doc/classes/PanelContainer.xml b/doc/classes/PanelContainer.xml index 9803a8dc51..d39122c395 100644 --- a/doc/classes/PanelContainer.xml +++ b/doc/classes/PanelContainer.xml @@ -17,6 +17,7 @@ </constants> <theme_items> <theme_item name="panel" type="StyleBox"> + The style of [PanelContainer]'s background. </theme_item> </theme_items> </class> diff --git a/doc/classes/PhysicsServer.xml b/doc/classes/PhysicsServer.xml index c9f4accee2..1b9ce80a1b 100644 --- a/doc/classes/PhysicsServer.xml +++ b/doc/classes/PhysicsServer.xml @@ -1388,7 +1388,7 @@ </constant> <constant name="CONE_TWIST_JOINT_SWING_SPAN" value="0" enum="ConeTwistJointParam"> Swing is rotation from side to side, around the axis perpendicular to the twist axis. - The swing span defines, how much rotation will not get corrected allong the swing axis. + The swing span defines, how much rotation will not get corrected along the swing axis. Could be defined as looseness in the [ConeTwistJoint]. If below 0.05, this behavior is locked. </constant> diff --git a/doc/classes/PinJoint.xml b/doc/classes/PinJoint.xml index de4cb9d98a..78cab4805e 100644 --- a/doc/classes/PinJoint.xml +++ b/doc/classes/PinJoint.xml @@ -15,6 +15,7 @@ <argument index="0" name="param" type="int" enum="PinJoint.Param"> </argument> <description> + Returns the value of the specified parameter. </description> </method> <method name="set_param"> @@ -25,6 +26,7 @@ <argument index="1" name="value" type="float"> </argument> <description> + Sets the value of the specified parameter. </description> </method> </methods> diff --git a/doc/classes/Polygon2D.xml b/doc/classes/Polygon2D.xml index f777545733..13332ca4f0 100644 --- a/doc/classes/Polygon2D.xml +++ b/doc/classes/Polygon2D.xml @@ -17,12 +17,14 @@ <argument index="1" name="weights" type="PackedFloat32Array"> </argument> <description> + Adds a bone with the specified [code]path[/code] and [code]weights[/code]. </description> </method> <method name="clear_bones"> <return type="void"> </return> <description> + Removes all bones from this [Polygon2D]. </description> </method> <method name="erase_bone"> @@ -31,12 +33,14 @@ <argument index="0" name="index" type="int"> </argument> <description> + Removes the specified bone from this [Polygon2D]. </description> </method> <method name="get_bone_count" qualifiers="const"> <return type="int"> </return> <description> + Returns the number of bones in this [Polygon2D]. </description> </method> <method name="get_bone_path" qualifiers="const"> @@ -45,6 +49,7 @@ <argument index="0" name="index" type="int"> </argument> <description> + Returns the path to the node associated with the specified bone. </description> </method> <method name="get_bone_weights" qualifiers="const"> @@ -53,6 +58,7 @@ <argument index="0" name="index" type="int"> </argument> <description> + Returns the height values of the specified bone. </description> </method> <method name="set_bone_path"> @@ -63,6 +69,7 @@ <argument index="1" name="path" type="NodePath"> </argument> <description> + Sets the path to the node associated with the specified bone. </description> </method> <method name="set_bone_weights"> @@ -73,6 +80,7 @@ <argument index="1" name="weights" type="PackedFloat32Array"> </argument> <description> + Sets the weight values for the specified bone. </description> </method> </methods> diff --git a/doc/classes/PopupPanel.xml b/doc/classes/PopupPanel.xml index a3dd722f81..2e62d09f8f 100644 --- a/doc/classes/PopupPanel.xml +++ b/doc/classes/PopupPanel.xml @@ -14,6 +14,7 @@ </constants> <theme_items> <theme_item name="panel" type="StyleBox"> + The background panel style of this [PopupPanel]. </theme_item> </theme_items> </class> diff --git a/doc/classes/ProgressBar.xml b/doc/classes/ProgressBar.xml index e94299a5b8..c957d6f182 100644 --- a/doc/classes/ProgressBar.xml +++ b/doc/classes/ProgressBar.xml @@ -21,14 +21,19 @@ </constants> <theme_items> <theme_item name="bg" type="StyleBox"> + The style of the background. </theme_item> <theme_item name="fg" type="StyleBox"> + The style of the progress (i.e. the part that fills the bar). </theme_item> <theme_item name="font" type="Font"> + Font used to draw the fill percentage if [member percent_visible] is [code]true[/code]. </theme_item> <theme_item name="font_color" type="Color" default="Color( 0.94, 0.94, 0.94, 1 )"> + The color of the text. </theme_item> <theme_item name="font_color_shadow" type="Color" default="Color( 0, 0, 0, 1 )"> + The color of the text's shadow. </theme_item> </theme_items> </class> diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 8347283785..76674dcef8 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -824,17 +824,17 @@ </member> <member name="mono/unhandled_exception_policy" type="int" setter="" getter="" default="0"> </member> - <member name="network/limits/debugger_stdout/max_chars_per_second" type="int" setter="" getter="" default="2048"> + <member name="network/limits/debugger/max_chars_per_second" type="int" setter="" getter="" default="32768"> Maximum amount of characters allowed to send as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection. </member> - <member name="network/limits/debugger_stdout/max_errors_per_second" type="int" setter="" getter="" default="100"> - Maximum number of errors allowed to be sent as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection. + <member name="network/limits/debugger/max_errors_per_second" type="int" setter="" getter="" default="400"> + Maximum number of errors allowed to be sent from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection. </member> - <member name="network/limits/debugger_stdout/max_messages_per_frame" type="int" setter="" getter="" default="10"> - Maximum amount of messages allowed to send as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection. + <member name="network/limits/debugger/max_queued_messages" type="int" setter="" getter="" default="2048"> + Maximum amount of messages in the debugger queue. Over this value, content is dropped. This helps to limit the debugger memory usage. </member> - <member name="network/limits/debugger_stdout/max_warnings_per_second" type="int" setter="" getter="" default="100"> - Maximum number of warnings allowed to be sent as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection. + <member name="network/limits/debugger/max_warnings_per_second" type="int" setter="" getter="" default="400"> + Maximum number of warnings allowed to be sent from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection. </member> <member name="network/limits/packet_peer_stream/max_buffer_po2" type="int" setter="" getter="" default="16"> Default size of packet peer stream for deserializing Godot data. Over this size, data is dropped. diff --git a/doc/classes/ResourceLoader.xml b/doc/classes/ResourceLoader.xml index 533bc9ec28..1cf775f389 100644 --- a/doc/classes/ResourceLoader.xml +++ b/doc/classes/ResourceLoader.xml @@ -74,6 +74,8 @@ <argument index="0" name="path" type="String"> </argument> <description> + Returns the resource loaded by [method load_threaded_request]. + If this is called before the loading thread is done (i.e. [method load_threaded_get_status] is not [constant THREAD_LOAD_LOADED]), the calling thread will be blocked until the resource has finished loading. </description> </method> <method name="load_threaded_get_status"> @@ -84,6 +86,8 @@ <argument index="1" name="progress" type="Array" default="[ ]"> </argument> <description> + Returns the status of a threaded loading operation started with [method load_threaded_request] for the resource at [code]path[/code]. See [enum ThreadLoadStatus] for possible return values. + An array variable can optionally be passed via [code]progress[/code], and will return a one-element array containing the percentage of completion of the threaded loading. </description> </method> <method name="load_threaded_request"> @@ -96,6 +100,7 @@ <argument index="2" name="use_sub_threads" type="bool" default="false"> </argument> <description> + Loads the resource using threads. If [code]use_sub_threads[/code] is [code]true[/code], multiple threads will be used to load the resource, which makes loading faster, but may affect the main thread (and thus cause game slowdowns). </description> </method> <method name="set_abort_on_missing_resources"> @@ -110,12 +115,16 @@ </methods> <constants> <constant name="THREAD_LOAD_INVALID_RESOURCE" value="0" enum="ThreadLoadStatus"> + The resource is invalid, or has not been loaded with [method load_threaded_request]. </constant> <constant name="THREAD_LOAD_IN_PROGRESS" value="1" enum="ThreadLoadStatus"> + The resource is still being loaded. </constant> <constant name="THREAD_LOAD_FAILED" value="2" enum="ThreadLoadStatus"> + Some error occurred during loading and it failed. </constant> <constant name="THREAD_LOAD_LOADED" value="3" enum="ThreadLoadStatus"> + The resource was loaded successfully and can be accessed via [method load_threaded_get]. </constant> </constants> </class> diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml index 5f07133a27..efc0c9d600 100644 --- a/doc/classes/RichTextLabel.xml +++ b/doc/classes/RichTextLabel.xml @@ -409,38 +409,55 @@ </constants> <theme_items> <theme_item name="bold_font" type="Font"> + The font used for bold text. </theme_item> <theme_item name="bold_italics_font" type="Font"> + The font used for bold italics text. </theme_item> <theme_item name="default_color" type="Color" default="Color( 1, 1, 1, 1 )"> + The default text color. </theme_item> <theme_item name="focus" type="StyleBox"> + The background The background used when the [RichTextLabel] is focused. </theme_item> <theme_item name="font_color_selected" type="Color" default="Color( 0.49, 0.49, 0.49, 1 )"> + The color of selected text, used when [member selection_enabled] is [code]true[/code]. </theme_item> <theme_item name="font_color_shadow" type="Color" default="Color( 0, 0, 0, 0 )"> + The color of the font's shadow. </theme_item> <theme_item name="italics_font" type="Font"> + The font used for italics text. </theme_item> <theme_item name="line_separation" type="int" default="1"> + The vertical space between lines. </theme_item> <theme_item name="mono_font" type="Font"> + The font used for monospace text. </theme_item> <theme_item name="normal" type="StyleBox"> + The normal background for the [RichTextLabel]. </theme_item> <theme_item name="normal_font" type="Font"> + The default text font. </theme_item> <theme_item name="selection_color" type="Color" default="Color( 0.1, 0.1, 1, 0.8 )"> + The color of the selection box. </theme_item> <theme_item name="shadow_as_outline" type="int" default="0"> + Boolean value. If 1 ([code]true[/code]), the shadow will be displayed around the whole text as an outline. </theme_item> <theme_item name="shadow_offset_x" type="int" default="1"> + The horizontal offset of the font's shadow. </theme_item> <theme_item name="shadow_offset_y" type="int" default="1"> + The vertical offset of the font's shadow. </theme_item> <theme_item name="table_hseparation" type="int" default="3"> + The horizontal separation of elements in a table. </theme_item> <theme_item name="table_vseparation" type="int" default="3"> + The vertical separation of elements in a table. </theme_item> </theme_items> </class> diff --git a/doc/classes/Script.xml b/doc/classes/Script.xml index f671315620..0d94453e52 100644 --- a/doc/classes/Script.xml +++ b/doc/classes/Script.xml @@ -38,30 +38,35 @@ <argument index="0" name="property" type="StringName"> </argument> <description> + Returns the default value of the specified property. </description> </method> <method name="get_script_constant_map"> <return type="Dictionary"> </return> <description> + Returns a dictionary containing constant names and their values. </description> </method> <method name="get_script_method_list"> <return type="Array"> </return> <description> + Returns the list of methods in this [Script]. </description> </method> <method name="get_script_property_list"> <return type="Array"> </return> <description> + Returns the list of properties in this [Script]. </description> </method> <method name="get_script_signal_list"> <return type="Array"> </return> <description> + Returns the list of user signals defined in this [Script]. </description> </method> <method name="has_script_signal" qualifiers="const"> diff --git a/doc/classes/ScriptEditor.xml b/doc/classes/ScriptEditor.xml index ed401d6853..10d6e5f578 100644 --- a/doc/classes/ScriptEditor.xml +++ b/doc/classes/ScriptEditor.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="ScriptEditor" inherits="PanelContainer" version="4.0"> <brief_description> + Godot editor's script editor. </brief_description> <description> </description> diff --git a/doc/classes/Signal.xml b/doc/classes/Signal.xml index 350ab40c0e..51490caf6f 100644 --- a/doc/classes/Signal.xml +++ b/doc/classes/Signal.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="Signal" version="4.0"> <brief_description> + Class representing a signal defined in an object. </brief_description> <description> </description> @@ -15,6 +16,7 @@ <argument index="1" name="signal_name" type="StringName"> </argument> <description> + Creates a new signal named [code]signal_name[/code] in the given object. </description> </method> <method name="connect"> @@ -27,6 +29,7 @@ <argument index="2" name="flags" type="int" default="0"> </argument> <description> + Connects this signal to the specified [Callable], optionally providing binds and connection flags. </description> </method> <method name="disconnect"> @@ -35,36 +38,42 @@ <argument index="0" name="callable" type="Callable"> </argument> <description> + Disconnects this signal from the specified [Callable]. </description> </method> <method name="emit" qualifiers="vararg"> <return type="void"> </return> <description> + Emits this signal to all connected objects. </description> </method> <method name="get_connections"> <return type="Array"> </return> <description> + Returns the list of [Callable]s connected to this signal. </description> </method> <method name="get_name"> <return type="StringName"> </return> <description> + Returns the name of this signal. </description> </method> <method name="get_object"> <return type="Object"> </return> <description> + Returns the object emitting this signal. </description> </method> <method name="get_object_id"> <return type="int"> </return> <description> + Returns the ID of the object emitting this signal (see [method Object.get_instance_id]). </description> </method> <method name="is_connected"> @@ -73,6 +82,7 @@ <argument index="0" name="callable" type="Callable"> </argument> <description> + Returns [code]true[/code] if the specified [Callable] is connected to this signal. </description> </method> <method name="is_null"> diff --git a/doc/classes/Sprite.xml b/doc/classes/Sprite.xml index 89cdae1dff..6c21881535 100644 --- a/doc/classes/Sprite.xml +++ b/doc/classes/Sprite.xml @@ -68,10 +68,13 @@ The region of the atlas texture to display. [member region_enabled] must be [code]true[/code]. </member> <member name="shininess" type="float" setter="set_shininess" getter="get_shininess" default="1.0"> + Strength of the specular light effect of this [Sprite]. </member> <member name="specular_color" type="Color" setter="set_specular_color" getter="get_specular_color" default="Color( 1, 1, 1, 1 )"> + The color of the specular light effect. </member> <member name="specular_map" type="Texture2D" setter="set_specular_map" getter="get_specular_map"> + The specular map is used for more control on the shininess effect. </member> <member name="texture" type="Texture2D" setter="set_texture" getter="get_texture"> [Texture2D] object to draw. diff --git a/doc/classes/SpriteBase3D.xml b/doc/classes/SpriteBase3D.xml index aaea4178fb..563a17e8f6 100644 --- a/doc/classes/SpriteBase3D.xml +++ b/doc/classes/SpriteBase3D.xml @@ -21,12 +21,14 @@ <argument index="0" name="flag" type="int" enum="SpriteBase3D.DrawFlags"> </argument> <description> + Returns the value of the specified flag. </description> </method> <method name="get_item_rect" qualifiers="const"> <return type="Rect2"> </return> <description> + Returns the rectangle representing this sprite. </description> </method> <method name="set_draw_flag"> @@ -37,6 +39,7 @@ <argument index="1" name="enabled" type="bool"> </argument> <description> + If [code]true[/code], the specified flag will be enabled. </description> </method> </methods> diff --git a/doc/classes/StreamPeerSSL.xml b/doc/classes/StreamPeerSSL.xml index 738d623d02..69e8f67a5e 100644 --- a/doc/classes/StreamPeerSSL.xml +++ b/doc/classes/StreamPeerSSL.xml @@ -72,11 +72,13 @@ A status representing a [StreamPeerSSL] that is disconnected. </constant> <constant name="STATUS_HANDSHAKING" value="1" enum="Status"> + A status representing a [StreamPeerSSL] during handshaking. </constant> <constant name="STATUS_CONNECTED" value="2" enum="Status"> A status representing a [StreamPeerSSL] that is connected to a host. </constant> <constant name="STATUS_ERROR" value="3" enum="Status"> + A status representing a [StreamPeerSSL] in error state. </constant> <constant name="STATUS_ERROR_HOSTNAME_MISMATCH" value="4" enum="Status"> An error status that shows a mismatch in the SSL certificate domain presented by the host and the domain requested for validation. diff --git a/doc/classes/StreamTexture.xml b/doc/classes/StreamTexture.xml index a2d26d3d14..03afcb5b0d 100644 --- a/doc/classes/StreamTexture.xml +++ b/doc/classes/StreamTexture.xml @@ -15,6 +15,7 @@ <argument index="0" name="path" type="String"> </argument> <description> + Loads the texture from the given path. </description> </method> </methods> diff --git a/doc/classes/StringName.xml b/doc/classes/StringName.xml index f323a4bb6a..5d8ac6fdcc 100644 --- a/doc/classes/StringName.xml +++ b/doc/classes/StringName.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="StringName" version="4.0"> <brief_description> + An optimized string type for unique names. </brief_description> <description> + [StringName]s are immutable strings designed for general-purpose represention of unique names. [StringName] ensures that only one instance of a given name exists (so two [StringName]s with the same value are the same object). Comparing them is much faster than with regular [String]s, because only the pointers are compared, not the whole strings. </description> <tutorials> </tutorials> @@ -13,6 +15,7 @@ <argument index="0" name="from" type="String"> </argument> <description> + Creates a new [StringName] from the given [String]. </description> </method> </methods> diff --git a/doc/classes/TabContainer.xml b/doc/classes/TabContainer.xml index 3c4fd4c41a..f7e94ad236 100644 --- a/doc/classes/TabContainer.xml +++ b/doc/classes/TabContainer.xml @@ -187,36 +187,52 @@ </constants> <theme_items> <theme_item name="decrement" type="Texture2D"> + Icon for the left arrow button that appears when there are too many tabs to fit in the container width. When the button is disabled (i.e. the first tab is visible), it appears semi-transparent. </theme_item> <theme_item name="decrement_highlight" type="Texture2D"> + Icon for the left arrow button that appears when there are too many tabs to fit in the container width. Used when the button is being hovered with the cursor. </theme_item> <theme_item name="font" type="Font"> + The font used to draw tab names. </theme_item> <theme_item name="font_color_bg" type="Color" default="Color( 0.69, 0.69, 0.69, 1 )"> + Font color of inactive tabs. </theme_item> <theme_item name="font_color_disabled" type="Color" default="Color( 0.9, 0.9, 0.9, 0.2 )"> + Font color of disabled tabs. </theme_item> <theme_item name="font_color_fg" type="Color" default="Color( 0.94, 0.94, 0.94, 1 )"> + Font color of the currently selected tab. </theme_item> <theme_item name="hseparation" type="int" default="4"> + Horizontal separation between tabs. </theme_item> <theme_item name="increment" type="Texture2D"> + Icon for the right arrow button that appears when there are too many tabs to fit in the container width. When the button is disabled (i.e. the last tab is visible) it appears semi-transparent. </theme_item> <theme_item name="increment_highlight" type="Texture2D"> + Icon for the right arrow button that appears when there are too many tabs to fit in the container width. Used when the button is being hovered with the cursor. </theme_item> <theme_item name="menu" type="Texture2D"> + The icon for the menu button (see [method set_popup]). </theme_item> <theme_item name="menu_highlight" type="Texture2D"> + The icon for the menu button (see [method set_popup]) when it's being hovered with the cursor. </theme_item> <theme_item name="panel" type="StyleBox"> + The style for the background fill. </theme_item> <theme_item name="side_margin" type="int" default="8"> + The space at the left and right edges of the tab bar. </theme_item> <theme_item name="tab_bg" type="StyleBox"> + The style of inactive tabs. </theme_item> <theme_item name="tab_disabled" type="StyleBox"> + The style of disabled tabs. </theme_item> <theme_item name="tab_fg" type="StyleBox"> + The style of the currently selected tab. </theme_item> </theme_items> </class> diff --git a/doc/classes/Tabs.xml b/doc/classes/Tabs.xml index 8f31b24131..3fc1db9dc6 100644 --- a/doc/classes/Tabs.xml +++ b/doc/classes/Tabs.xml @@ -262,36 +262,51 @@ </constants> <theme_items> <theme_item name="button" type="StyleBox"> + Background of the close button when it's being hovered with the cursor. </theme_item> <theme_item name="button_pressed" type="StyleBox"> + Background of the close button when it's being pressed. </theme_item> <theme_item name="close" type="Texture2D"> + The icon for the close button (see [member tab_close_display_policy]). </theme_item> <theme_item name="decrement" type="Texture2D"> + Icon for the left arrow button that appears when there are too many tabs to fit in the container width. When the button is disabled (i.e. the first tab is visible), it appears semi-transparent. </theme_item> <theme_item name="decrement_highlight" type="Texture2D"> + Icon for the left arrow button that appears when there are too many tabs to fit in the container width. Used when the button is being hovered with the cursor. </theme_item> <theme_item name="font" type="Font"> + The font used to draw tab names. </theme_item> <theme_item name="font_color_bg" type="Color" default="Color( 0.69, 0.69, 0.69, 1 )"> + Font color of inactive tabs. </theme_item> <theme_item name="font_color_disabled" type="Color" default="Color( 0.9, 0.9, 0.9, 0.2 )"> + Font color of disabled tabs. </theme_item> <theme_item name="font_color_fg" type="Color" default="Color( 0.94, 0.94, 0.94, 1 )"> + Font color of the currently selected tab. </theme_item> <theme_item name="hseparation" type="int" default="4"> + The horizontal separation between the tabs. </theme_item> <theme_item name="increment" type="Texture2D"> + Icon for the right arrow button that appears when there are too many tabs to fit in the container width. When the button is disabled (i.e. the last tab is visible) it appears semi-transparent. </theme_item> <theme_item name="increment_highlight" type="Texture2D"> + Icon for the right arrow button that appears when there are too many tabs to fit in the container width. Used when the button is being hovered with the cursor. </theme_item> <theme_item name="panel" type="StyleBox"> </theme_item> <theme_item name="tab_bg" type="StyleBox"> + The style of an inactive tab. </theme_item> <theme_item name="tab_disabled" type="StyleBox"> + The style of a disabled tab </theme_item> <theme_item name="tab_fg" type="StyleBox"> + The style of the currently selected tab. </theme_item> </theme_items> </class> diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index d4eeb574eb..b515b27b31 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -502,6 +502,12 @@ <description> </description> </signal> + <signal name="symbol_validate"> + <argument index="0" name="symbol" type="String"> + </argument> + <description> + </description> + </signal> <signal name="text_changed"> <description> Emitted when the text changes. diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml index 5fa24100ae..b01ba3850f 100644 --- a/doc/classes/Tree.xml +++ b/doc/classes/Tree.xml @@ -313,6 +313,7 @@ </signal> <signal name="item_custom_button_pressed"> <description> + Emitted when a custom button is pressed (i.e. in a [constant TreeItem.CELL_MODE_CUSTOM] mode cell). </description> </signal> <signal name="item_double_clicked"> diff --git a/doc/classes/VSeparator.xml b/doc/classes/VSeparator.xml index 19e995b9bc..52f31b1da7 100644 --- a/doc/classes/VSeparator.xml +++ b/doc/classes/VSeparator.xml @@ -14,8 +14,10 @@ </constants> <theme_items> <theme_item name="separation" type="int" default="4"> + The width of the area covered by the separator. Effectively works like a minimum width. </theme_item> <theme_item name="separator" type="StyleBox"> + The style for the separator line. Works best with [StyleBoxLine] (remember to enable [member StyleBoxLine.vertical]). </theme_item> </theme_items> </class> diff --git a/doc/classes/VSlider.xml b/doc/classes/VSlider.xml index cbc4ac1a13..3faafdfe80 100644 --- a/doc/classes/VSlider.xml +++ b/doc/classes/VSlider.xml @@ -18,16 +18,22 @@ </constants> <theme_items> <theme_item name="grabber" type="Texture2D"> + The texture for the grabber (the draggable element). </theme_item> <theme_item name="grabber_area" type="StyleBox"> + The background of the area below the grabber. </theme_item> <theme_item name="grabber_disabled" type="Texture2D"> + The texture for the grabber when it's disabled. </theme_item> <theme_item name="grabber_highlight" type="Texture2D"> + The texture for the grabber when it's focused. </theme_item> <theme_item name="slider" type="StyleBox"> + The background for the whole slider. Determines the width of the [code]grabber_area[/code]. </theme_item> <theme_item name="tick" type="Texture2D"> + The texture for the ticks, visible when [member Slider.tick_count] is greater than 0. </theme_item> </theme_items> </class> diff --git a/doc/classes/VSplitContainer.xml b/doc/classes/VSplitContainer.xml index 0e659408d7..18b515e7ce 100644 --- a/doc/classes/VSplitContainer.xml +++ b/doc/classes/VSplitContainer.xml @@ -14,12 +14,15 @@ </constants> <theme_items> <theme_item name="autohide" type="int" default="1"> + Boolean value. If 1 ([code]true[/code]), the grabber will hide automatically when it isn't under the cursor. If 0 ([code]false[/code]), it's always visible. </theme_item> <theme_item name="bg" type="StyleBox"> </theme_item> <theme_item name="grabber" type="Texture2D"> + The icon used for the grabber drawn in the middle area. </theme_item> <theme_item name="separation" type="int" default="12"> + The space between sides of the container. </theme_item> </theme_items> </class> diff --git a/doc/classes/VisualShader.xml b/doc/classes/VisualShader.xml index 0dd8ec0064..40b0f52469 100644 --- a/doc/classes/VisualShader.xml +++ b/doc/classes/VisualShader.xml @@ -22,6 +22,7 @@ <argument index="3" name="id" type="int"> </argument> <description> + Adds the specified node to the shader. </description> </method> <method name="can_connect_nodes" qualifiers="const"> @@ -38,6 +39,7 @@ <argument index="4" name="to_port" type="int"> </argument> <description> + Returns [code]true[/code] if the specified nodes and ports can be connected together. </description> </method> <method name="connect_nodes"> @@ -54,6 +56,7 @@ <argument index="4" name="to_port" type="int"> </argument> <description> + Connects the specified nodes and ports. </description> </method> <method name="connect_nodes_forced"> @@ -70,6 +73,7 @@ <argument index="4" name="to_port" type="int"> </argument> <description> + Connects the specified nodes and ports, even if they can't be connected. Such connection is invalid and will not function properly. </description> </method> <method name="disconnect_nodes"> @@ -86,6 +90,7 @@ <argument index="4" name="to_port" type="int"> </argument> <description> + Connects the specified nodes and ports. </description> </method> <method name="get_node" qualifiers="const"> @@ -96,6 +101,7 @@ <argument index="1" name="id" type="int"> </argument> <description> + Returns the shader node instance with specified [code]type[/code] and [code]id[/code]. </description> </method> <method name="get_node_connections" qualifiers="const"> @@ -104,6 +110,7 @@ <argument index="0" name="type" type="int" enum="VisualShader.Type"> </argument> <description> + Returns the list of connected nodes with the specified type. </description> </method> <method name="get_node_list" qualifiers="const"> @@ -112,6 +119,7 @@ <argument index="0" name="type" type="int" enum="VisualShader.Type"> </argument> <description> + Returns the list of all nodes in the shader with the specified type. </description> </method> <method name="get_node_position" qualifiers="const"> @@ -122,6 +130,7 @@ <argument index="1" name="id" type="int"> </argument> <description> + Returns the position of the specified node within the shader graph. </description> </method> <method name="get_valid_node_id" qualifiers="const"> @@ -146,6 +155,7 @@ <argument index="4" name="to_port" type="int"> </argument> <description> + Returns [code]true[/code] if the specified node and port connection exist. </description> </method> <method name="remove_node"> @@ -156,6 +166,7 @@ <argument index="1" name="id" type="int"> </argument> <description> + Removes the specified node from the shader. </description> </method> <method name="set_mode"> @@ -164,6 +175,7 @@ <argument index="0" name="mode" type="int" enum="Shader.Mode"> </argument> <description> + Sets the mode of this shader. </description> </method> <method name="set_node_position"> @@ -176,22 +188,27 @@ <argument index="2" name="position" type="Vector2"> </argument> <description> + Sets the position of the specified node. </description> </method> </methods> <members> <member name="code" type="String" setter="set_code" getter="get_code" override="true" default=""shader_type spatial;void vertex() {// Output:0}void fragment() {// Output:0}void light() {// Output:0}"" /> <member name="graph_offset" type="Vector2" setter="set_graph_offset" getter="get_graph_offset" default="Vector2( 0, 0 )"> + The offset vector of the whole graph. </member> <member name="version" type="String" setter="set_version" getter="get_version" default=""""> </member> </members> <constants> <constant name="TYPE_VERTEX" value="0" enum="Type"> + A vertex shader, operating on vertices. </constant> <constant name="TYPE_FRAGMENT" value="1" enum="Type"> + A fragment shader, operating on fragments (pixels). </constant> <constant name="TYPE_LIGHT" value="2" enum="Type"> + A shader for light calculations. </constant> <constant name="TYPE_MAX" value="3" enum="Type"> Represents the size of the [enum Type] enum. diff --git a/doc/classes/VisualShaderNode.xml b/doc/classes/VisualShaderNode.xml index 72ce743656..28d13a7d32 100644 --- a/doc/classes/VisualShaderNode.xml +++ b/doc/classes/VisualShaderNode.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="VisualShaderNode" inherits="Resource" version="4.0"> <brief_description> + Base class for nodes in a visual shader graph. </brief_description> <description> </description> diff --git a/doc/classes/VisualShaderNodeIf.xml b/doc/classes/VisualShaderNodeIf.xml index 1ebd945d42..ad0b21a370 100644 --- a/doc/classes/VisualShaderNodeIf.xml +++ b/doc/classes/VisualShaderNodeIf.xml @@ -4,7 +4,7 @@ Compares two floating-point numbers in order to return a required vector within the visual shader graph. </brief_description> <description> - First two ports are scalar floatin-point numbers to compare, third is tolerance comparsion amount and last three ports represents a vectors returned if [code]a == b[/code], [code]a > b[/code] and [code]a < b[/code] respectivly. + First two ports are scalar floatin-point numbers to compare, third is tolerance comparison amount and last three ports represents a vectors returned if [code]a == b[/code], [code]a > b[/code] and [code]a < b[/code] respectively. </description> <tutorials> </tutorials> diff --git a/doc/classes/WindowDialog.xml b/doc/classes/WindowDialog.xml index 16b8085df3..8b6bf00508 100644 --- a/doc/classes/WindowDialog.xml +++ b/doc/classes/WindowDialog.xml @@ -29,22 +29,31 @@ </constants> <theme_items> <theme_item name="close" type="Texture2D"> + The icon for the close button. </theme_item> <theme_item name="close_h_ofs" type="int" default="18"> + The horizontal offset of the close button. </theme_item> <theme_item name="close_highlight" type="Texture2D"> + The icon used for the close button when it's hovered with the mouse cursor. </theme_item> <theme_item name="close_v_ofs" type="int" default="18"> + The vertical offset of the close button. </theme_item> <theme_item name="panel" type="StyleBox"> + The style for both the content background of the [WindowDialog] and the title bar. </theme_item> <theme_item name="scaleborder_size" type="int" default="4"> + The thickness of the border that can be dragged when scaling the window (if [member resizable] is enabled). </theme_item> <theme_item name="title_color" type="Color" default="Color( 0, 0, 0, 1 )"> + The color of the title text. </theme_item> <theme_item name="title_font" type="Font"> + The font used to draw the title. </theme_item> <theme_item name="title_height" type="int" default="20"> + The vertical offset of the title text. </theme_item> </theme_items> </class> diff --git a/drivers/SCsub b/drivers/SCsub index 932014b540..41c20d81ad 100644 --- a/drivers/SCsub +++ b/drivers/SCsub @@ -23,7 +23,7 @@ SConscript('coremidi/SCsub') SConscript('winmidi/SCsub') # Graphics drivers -if (env["platform"] != "server"): +if (env["platform"] != "server" and env["platform"] != "javascript"): # SConscript('gles2/SCsub') SConscript('vulkan/SCsub') SConscript('gl_context/SCsub') diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h index fb23370863..4df28e3ea4 100644 --- a/drivers/dummy/rasterizer_dummy.h +++ b/drivers/dummy/rasterizer_dummy.h @@ -47,9 +47,18 @@ public: void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) {} bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) { return false; } + void directional_shadow_atlas_set_size(int p_size) {} int get_directional_light_shadow_size(RID p_light_intance) { return 0; } void set_directional_shadow_count(int p_count) {} + /* SKY API */ + + RID sky_create() { return RID(); } + void sky_set_radiance_size(RID p_sky, int p_radiance_size) {} + void sky_set_mode(RID p_sky, VS::SkyMode p_samples) {} + void sky_set_texture(RID p_sky, RID p_panorama) {} + void sky_set_texture(RID p_sky, RID p_cube_map, int p_radiance_size) {} + /* ENVIRONMENT API */ RID environment_create() { return RID(); } @@ -61,17 +70,19 @@ public: void environment_set_bg_color(RID p_env, const Color &p_color) {} void environment_set_bg_energy(RID p_env, float p_energy) {} void environment_set_canvas_max_layer(RID p_env, int p_max_layer) {} - void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0) {} - void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id){}; + void environment_set_ambient_light(RID p_env, const Color &p_color, VS::EnvironmentAmbientSource p_ambient = VS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, VS::EnvironmentReflectionSource p_reflection_source = VS::ENV_REFLECTION_SOURCE_BG, const Color &p_ao_color = Color()) {} +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 + void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id) {} +#endif - void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) {} - void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) {} - void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) {} + void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, bool p_bicubic_upscale) {} void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) {} void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance, bool p_roughness) {} - void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {} + virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_bias, float p_light_affect, float p_ao_channel_affect, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {} + virtual void environment_set_ssao_quality(VS::EnvironmentSSAOQuality p_quality, bool p_half_size) {} void environment_set_tonemap(RID p_env, VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) {} @@ -81,9 +92,17 @@ public: void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve) {} void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve) {} - bool is_environment(RID p_env) { return false; } - VS::EnvironmentBG environment_get_background(RID p_env) { return VS::ENV_BG_KEEP; } - int environment_get_canvas_max_layer(RID p_env) { return 0; } + bool is_environment(RID p_env) const { return false; } + VS::EnvironmentBG environment_get_background(RID p_env) const { return VS::ENV_BG_KEEP; } + int environment_get_canvas_max_layer(RID p_env) const { return 0; } + + virtual RID camera_effects_create() { return RID(); } + + virtual void camera_effects_set_dof_blur_quality(VS::DOFBlurQuality p_quality, bool p_use_jitter) {} + virtual void camera_effects_set_dof_blur_bokeh_shape(VS::DOFBokehShape p_shape) {} + + virtual void camera_effects_set_dof_blur(RID p_camera_effects, bool p_far_enable, float p_far_distance, float p_far_transition, bool p_near_enable, float p_near_distance, float p_near_transition, float p_amount) {} + virtual void camera_effects_set_custom_exposure(RID p_camera_effects, bool p_enable, float p_exposure) {} RID light_instance_create(RID p_light) { return RID(); } void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) {} @@ -91,8 +110,7 @@ public: void light_instance_mark_visible(RID p_light_instance) {} RID reflection_atlas_create() { return RID(); } - void reflection_atlas_set_size(RID p_ref_atlas, int p_size) {} - void reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv) {} + virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) {} RID reflection_probe_instance_create(RID p_probe) { return RID(); } void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform) {} @@ -102,18 +120,28 @@ public: bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) { return false; } bool reflection_probe_instance_postprocess_step(RID p_instance) { return true; } - RID gi_probe_instance_create() { return RID(); } + virtual RID gi_probe_instance_create(RID p_gi_probe) { return RID(); } void gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data) {} void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform) {} - void gi_probe_instance_set_bounds(RID p_probe, const Vector3 &p_bounds) {} + virtual bool gi_probe_needs_update(RID p_probe) const { return false; } + virtual void gi_probe_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, int p_dynamic_object_count, InstanceBase **p_dynamic_objects) {} - void render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {} + virtual void render_scene(RID p_render_buffers, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID *p_gi_probe_cull_result, int p_gi_probe_cull_count, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {} void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) {} + virtual void render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region) {} void set_scene_pass(uint64_t p_pass) {} + virtual void set_time(double p_time, double p_step) {} void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw) {} + virtual RID render_buffers_create() { return RID(); } + virtual void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, VS::ViewportMSAA p_msaa) {} + + virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_curve) {} + virtual bool screen_space_roughness_limiter_is_active() const { return false; } + bool free(RID p_rid) { return true; } + virtual void update() {} RasterizerSceneDummy() {} ~RasterizerSceneDummy() {} @@ -152,6 +180,43 @@ public: mutable RID_PtrOwner<DummyTexture> texture_owner; mutable RID_PtrOwner<DummyMesh> mesh_owner; + virtual RID texture_2d_create(const Ref<Image> &p_image) { return RID(); } + virtual RID texture_2d_layered_create(const Vector<Ref<Image> > &p_layers, VS::TextureLayeredType p_layered_type) { return RID(); } + virtual RID texture_3d_create(const Vector<Ref<Image> > &p_slices) { return RID(); } + virtual RID texture_proxy_create(RID p_base) { return RID(); } + + virtual void texture_2d_update_immediate(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) {} + virtual void texture_2d_update(RID p_texture, const Ref<Image> &p_image, int p_layer = 0) {} + virtual void texture_3d_update(RID p_texture, const Ref<Image> &p_image, int p_depth, int p_mipmap) {} + virtual void texture_proxy_update(RID p_proxy, RID p_base) {} + + virtual RID texture_2d_placeholder_create() { return RID(); } + virtual RID texture_2d_layered_placeholder_create() { return RID(); } + virtual RID texture_3d_placeholder_create() { return RID(); } + + virtual Ref<Image> texture_2d_get(RID p_texture) const { return Ref<Image>(); } + virtual Ref<Image> texture_2d_layer_get(RID p_texture, int p_layer) const { return Ref<Image>(); } + virtual Ref<Image> texture_3d_slice_get(RID p_texture, int p_depth, int p_mipmap) const { return Ref<Image>(); } + + virtual void texture_replace(RID p_texture, RID p_by_texture) {} + virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) {} +// FIXME: Disabled during Vulkan refactoring, should be ported. +#if 0 + virtual void texture_bind(RID p_texture, uint32_t p_texture_no) = 0; +#endif + + virtual void texture_set_path(RID p_texture, const String &p_path) {} + virtual String texture_get_path(RID p_texture) const { return String(); } + + virtual void texture_set_detect_3d_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) {} + virtual void texture_set_detect_normal_callback(RID p_texture, VS::TextureDetectCallback p_callback, void *p_userdata) {} + virtual void texture_set_detect_roughness_callback(RID p_texture, VS::TextureDetectRoughnessCallback p_callback, void *p_userdata) {} + + virtual void texture_debug_usage(List<VS::TextureInfo> *r_info) {} + virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) {} + virtual Size2 texture_size_with_proxy(RID p_proxy) { return Size2(); } + +#if 0 RID texture_create() { DummyTexture *texture = memnew(DummyTexture); @@ -246,11 +311,7 @@ public: void texture_set_proxy(RID p_proxy, RID p_base) {} virtual Size2 texture_size_with_proxy(RID p_texture) const { return Size2(); } void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) {} - - /* SKY API */ - - RID sky_create() { return RID(); } - void sky_set_texture(RID p_sky, RID p_cube_map, int p_radiance_size) {} +#endif /* SHADER API */ @@ -262,6 +323,7 @@ public: void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {} RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const { return RID(); } + virtual Variant shader_get_param_default(RID p_material, const StringName &p_param) const { return Variant(); } /* COMMON MATERIAL API */ @@ -269,21 +331,15 @@ public: void material_set_render_priority(RID p_material, int priority) {} void material_set_shader(RID p_shader_material, RID p_shader) {} - RID material_get_shader(RID p_shader_material) const { return RID(); } void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) {} Variant material_get_param(RID p_material, const StringName &p_param) const { return Variant(); } - Variant material_get_param_default(RID p_material, const StringName &p_param) const { return Variant(); } - - void material_set_line_width(RID p_material, float p_width) {} void material_set_next_pass(RID p_material, RID p_next_material) {} bool material_is_animated(RID p_material) { return false; } bool material_casts_shadows(RID p_material) { return false; } - - void material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {} - void material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) {} + void material_update_dependency(RID p_material, RasterizerScene::InstanceBase *p_instance) {} /* MESH API */ @@ -295,6 +351,9 @@ public: return mesh_owner.make_rid(mesh); } + void mesh_add_surface(RID p_mesh, const VS::SurfaceData &p_surface) {} + +#if 0 void mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t> > &p_blend_shapes = Vector<Vector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()) { DummyMesh *m = mesh_owner.getornull(p_mesh); ERR_FAIL_COND(!m); @@ -317,6 +376,8 @@ public: ERR_FAIL_COND(!m); m->blend_shape_count = p_amount; } +#endif + int mesh_get_blend_shape_count(RID p_mesh) const { DummyMesh *m = mesh_owner.getornull(p_mesh); ERR_FAIL_COND_V(!m, 0); @@ -339,6 +400,7 @@ public: void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) {} RID mesh_surface_get_material(RID p_mesh, int p_surface) const { return RID(); } +#if 0 int mesh_surface_get_array_len(RID p_mesh, int p_surface) const { DummyMesh *m = mesh_owner.getornull(p_mesh); ERR_FAIL_COND_V(!m, 0); @@ -404,6 +466,9 @@ public: m->surfaces.remove(p_index); } +#endif + + VS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const { return VS::SurfaceData(); } int mesh_get_surface_count(RID p_mesh) const { DummyMesh *m = mesh_owner.getornull(p_mesh); ERR_FAIL_COND_V(!m, 0); @@ -413,14 +478,14 @@ public: void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) {} AABB mesh_get_custom_aabb(RID p_mesh) const { return AABB(); } - AABB mesh_get_aabb(RID p_mesh, RID p_skeleton) const { return AABB(); } + AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) { return AABB(); } void mesh_clear(RID p_mesh) {} /* MULTIMESH API */ virtual RID multimesh_create() { return RID(); } - void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data = VS::MULTIMESH_CUSTOM_DATA_NONE) {} + virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false) {} int multimesh_get_instance_count(RID p_multimesh) const { return 0; } void multimesh_set_mesh(RID p_multimesh, RID p_mesh) {} @@ -430,19 +495,18 @@ public: void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) {} RID multimesh_get_mesh(RID p_multimesh) const { return RID(); } + AABB multimesh_get_aabb(RID p_multimesh) const { return AABB(); } Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const { return Transform(); } Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const { return Transform2D(); } Color multimesh_instance_get_color(RID p_multimesh, int p_index) const { return Color(); } Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const { return Color(); } - - void multimesh_set_as_bulk_array(RID p_multimesh, const Vector<float> &p_array) {} + virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) {} + virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const { return Vector<float>(); } void multimesh_set_visible_instances(RID p_multimesh, int p_visible) {} int multimesh_get_visible_instances(RID p_multimesh) const { return 0; } - AABB multimesh_get_aabb(RID p_multimesh) const { return AABB(); } - /* IMMEDIATE API */ RID immediate_create() { return RID(); } @@ -490,7 +554,6 @@ public: void light_set_use_gi(RID p_light, bool p_enabled) {} void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) {} - void light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail) {} void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) {} void light_directional_set_blend_splits(RID p_light, bool p_enable) {} @@ -536,57 +599,55 @@ public: float reflection_probe_get_origin_max_distance(RID p_probe) const { return 0.0; } bool reflection_probe_renders_shadows(RID p_probe) const { return false; } - void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) {} - void instance_remove_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) {} - - void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {} - void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {} + virtual void base_update_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {} + virtual void skeleton_update_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) {} /* GI PROBE API */ RID gi_probe_create() { return RID(); } - void gi_probe_set_bounds(RID p_probe, const AABB &p_bounds) {} - AABB gi_probe_get_bounds(RID p_probe) const { return AABB(); } + virtual void gi_probe_allocate(RID p_gi_probe, const Transform &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) {} - void gi_probe_set_cell_size(RID p_probe, float p_range) {} - float gi_probe_get_cell_size(RID p_probe) const { return 0.0; } + virtual AABB gi_probe_get_bounds(RID p_gi_probe) const { return AABB(); } + virtual Vector3i gi_probe_get_octree_size(RID p_gi_probe) const { return Vector3i(); } + virtual Vector<uint8_t> gi_probe_get_octree_cells(RID p_gi_probe) const { return Vector<uint8_t>(); } + virtual Vector<uint8_t> gi_probe_get_data_cells(RID p_gi_probe) const { return Vector<uint8_t>(); } + virtual Vector<uint8_t> gi_probe_get_distance_field(RID p_gi_probe) const { return Vector<uint8_t>(); } - void gi_probe_set_to_cell_xform(RID p_probe, const Transform &p_xform) {} - Transform gi_probe_get_to_cell_xform(RID p_probe) const { return Transform(); } + virtual Vector<int> gi_probe_get_level_counts(RID p_gi_probe) const { return Vector<int>(); } + virtual Transform gi_probe_get_to_cell_xform(RID p_gi_probe) const { return Transform(); } - void gi_probe_set_dynamic_data(RID p_probe, const Vector<int> &p_data) {} - Vector<int> gi_probe_get_dynamic_data(RID p_probe) const { - Vector<int> p; - return p; - } + virtual void gi_probe_set_dynamic_range(RID p_gi_probe, float p_range) {} + virtual float gi_probe_get_dynamic_range(RID p_gi_probe) const { return 0; } + + virtual void gi_probe_set_propagation(RID p_gi_probe, float p_range) {} + virtual float gi_probe_get_propagation(RID p_gi_probe) const { return 0; } - void gi_probe_set_dynamic_range(RID p_probe, int p_range) {} - int gi_probe_get_dynamic_range(RID p_probe) const { return 0; } + void gi_probe_set_energy(RID p_gi_probe, float p_range) {} + float gi_probe_get_energy(RID p_gi_probe) const { return 0.0; } - void gi_probe_set_energy(RID p_probe, float p_range) {} - float gi_probe_get_energy(RID p_probe) const { return 0.0; } + virtual void gi_probe_set_ao(RID p_gi_probe, float p_ao) {} + virtual float gi_probe_get_ao(RID p_gi_probe) const { return 0; } - void gi_probe_set_bias(RID p_probe, float p_range) {} - float gi_probe_get_bias(RID p_probe) const { return 0.0; } + virtual void gi_probe_set_ao_size(RID p_gi_probe, float p_strength) {} + virtual float gi_probe_get_ao_size(RID p_gi_probe) const { return 0; } - void gi_probe_set_normal_bias(RID p_probe, float p_range) {} - float gi_probe_get_normal_bias(RID p_probe) const { return 0.0; } + void gi_probe_set_bias(RID p_gi_probe, float p_range) {} + float gi_probe_get_bias(RID p_gi_probe) const { return 0.0; } - void gi_probe_set_propagation(RID p_probe, float p_range) {} - float gi_probe_get_propagation(RID p_probe) const { return 0.0; } + void gi_probe_set_normal_bias(RID p_gi_probe, float p_range) {} + float gi_probe_get_normal_bias(RID p_gi_probe) const { return 0.0; } - void gi_probe_set_interior(RID p_probe, bool p_enable) {} - bool gi_probe_is_interior(RID p_probe) const { return false; } + void gi_probe_set_interior(RID p_gi_probe, bool p_enable) {} + bool gi_probe_is_interior(RID p_gi_probe) const { return false; } - void gi_probe_set_compress(RID p_probe, bool p_enable) {} - bool gi_probe_is_compressed(RID p_probe) const { return false; } + virtual void gi_probe_set_use_two_bounces(RID p_gi_probe, bool p_enable) {} + virtual bool gi_probe_is_using_two_bounces(RID p_gi_probe) const { return false; } - uint32_t gi_probe_get_version(RID p_probe) { return 0; } + virtual void gi_probe_set_anisotropy_strength(RID p_gi_probe, float p_strength) {} + virtual float gi_probe_get_anisotropy_strength(RID p_gi_probe) const { return 0; } - GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const { return GI_PROBE_UNCOMPRESSED; } - RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression) { return RID(); } - void gi_probe_dynamic_data_update(RID p_gi_probe_data, int p_depth_slice, int p_slice_count, int p_mipmap, const void *p_data) {} + uint32_t gi_probe_get_version(RID p_gi_probe) { return 0; } /* LIGHTMAP CAPTURE */ struct Instantiable { @@ -598,7 +659,7 @@ public: SelfList<RasterizerScene::InstanceBase> *instances = instance_list.first(); while (instances) { - instances->self()->base_changed(p_aabb, p_materials); + //instances->self()->base_changed(p_aabb, p_materials); instances = instances->next(); } } @@ -608,7 +669,7 @@ public: while (instances) { SelfList<RasterizerScene::InstanceBase> *next = instances->next(); - instances->self()->base_removed(); + //instances->self()->base_removed(); instances = next; } } @@ -697,21 +758,17 @@ public: RID render_target_create() { return RID(); } void render_target_set_position(RID p_render_target, int p_x, int p_y) {} void render_target_set_size(RID p_render_target, int p_width, int p_height) {} - RID render_target_get_texture(RID p_render_target) const { return RID(); } + RID render_target_get_texture(RID p_render_target) { return RID(); } void render_target_set_external_texture(RID p_render_target, unsigned int p_texture_id) {} void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) {} bool render_target_was_used(RID p_render_target) { return false; } void render_target_set_as_unused(RID p_render_target) {} - void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa) {} - - /* CANVAS SHADOW */ - - RID canvas_light_shadow_buffer_create(int p_width) { return RID(); } - /* LIGHT SHADOW MAPPING */ - - RID canvas_light_occluder_create() { return RID(); } - void canvas_light_occluder_set_polylines(RID p_occluder, const Vector<Vector2> &p_lines) {} + virtual void render_target_request_clear(RID p_render_target, const Color &p_clear_color) {} + virtual bool render_target_is_clear_requested(RID p_render_target) { return false; } + virtual Color render_target_get_clear_request_color(RID p_render_target) { return Color(); } + virtual void render_target_disable_clear_request(RID p_render_target) {} + virtual void render_target_do_clear_request(RID p_render_target) {} VS::InstanceType get_base_type(RID p_rid) const { if (mesh_owner.owns(p_rid)) { @@ -748,28 +805,43 @@ public: static RasterizerStorage *base_singleton; - RasterizerStorageDummy(){}; + virtual void capture_timestamps_begin() {} + virtual void capture_timestamp(const String &p_name) {} + virtual uint32_t get_captured_timestamps_count() const { return 0; } + virtual uint64_t get_captured_timestamps_frame() const { return 0; } + virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const { return 0; } + virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const { return 0; } + virtual String get_captured_timestamp_name(uint32_t p_index) const { return String(); } + + RasterizerStorageDummy() {} ~RasterizerStorageDummy() {} }; class RasterizerCanvasDummy : public RasterizerCanvas { public: - RID light_internal_create() { return RID(); } - void light_internal_update(RID p_rid, Light *p_light) {} - void light_internal_free(RID p_rid) {} + virtual TextureBindingID request_texture_binding(RID p_texture, RID p_normalmap, RID p_specular, VS::CanvasItemTextureFilter p_filter, VS::CanvasItemTextureRepeat p_repeat, RID p_multimesh) { return 0; } + virtual void free_texture_binding(TextureBindingID p_binding) {} - void canvas_begin(){}; - void canvas_end(){}; + virtual PolygonID request_polygon(const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), const Vector<int> &p_bones = Vector<int>(), const Vector<float> &p_weights = Vector<float>()) { return 0; } + virtual void free_polygon(PolygonID p_polygon) {} - void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_transform){}; - void canvas_debug_viewport_shadows(Light *p_lights_with_shadow){}; + virtual void canvas_render_items(RID p_to_render_target, Item *p_item_list, const Color &p_modulate, Light *p_light_list, const Transform2D &p_canvas_transform) {} + virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow) {} - void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {} + virtual RID light_create() { return RID(); } + virtual void light_set_texture(RID p_rid, RID p_texture) {} + virtual void light_set_use_shadow(RID p_rid, bool p_enable, int p_resolution) {} + virtual void light_update_shadow(RID p_rid, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders) {} - void reset_canvas() {} + virtual RID occluder_polygon_create() { return RID(); } + virtual void occluder_polygon_set_shape_as_lines(RID p_occluder, const Vector<Vector2> &p_lines) {} + virtual void occluder_polygon_set_cull_mode(RID p_occluder, VS::CanvasOccluderPolygonCullMode p_mode) {} void draw_window_margins(int *p_margins, RID *p_margin_textures) {} + virtual bool free(RID p_rid) { return true; } + virtual void update() {} + RasterizerCanvasDummy() {} ~RasterizerCanvasDummy() {} }; @@ -789,11 +861,10 @@ public: void initialize() {} void begin_frame(double frame_step) {} - void set_current_render_target(RID p_render_target) {} - void restore_render_target(bool p_3d_was_drawn) {} - void clear_render_target(const Color &p_color) {} - void blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen = 0) {} - void output_lens_distorted_to_screen(RID p_render_target, const Rect2 &p_screen_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample) {} + + virtual void prepare_for_blitting_render_targets() {} + virtual void blit_render_targets_to_screen(int p_screen, const BlitToScreen *p_render_targets, int p_amount) {} + void end_frame(bool p_swap_buffers) { OS::get_singleton()->swap_buffers(); } void finalize() {} diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index d21b095037..458488f3e9 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -32,6 +32,8 @@ #ifdef UNIX_ENABLED +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" #include "core/os/thread_dummy.h" #include "core/project_settings.h" #include "drivers/unix/dir_access_unix.h" @@ -94,16 +96,16 @@ void OS_Unix::debug_break() { }; static void handle_interrupt(int sig) { - if (ScriptDebugger::get_singleton() == NULL) + if (!EngineDebugger::is_active()) return; - ScriptDebugger::get_singleton()->set_depth(-1); - ScriptDebugger::get_singleton()->set_lines_left(1); + EngineDebugger::get_script_debugger()->set_depth(-1); + EngineDebugger::get_script_debugger()->set_lines_left(1); } void OS_Unix::initialize_debugging() { - if (ScriptDebugger::get_singleton() != NULL) { + if (EngineDebugger::is_active()) { struct sigaction action; memset(&action, 0, sizeof(action)); action.sa_handler = handle_interrupt; diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp index 038cae7f96..c8ff342713 100644 --- a/drivers/vulkan/vulkan_context.cpp +++ b/drivers/vulkan/vulkan_context.cpp @@ -356,39 +356,8 @@ Error VulkanContext::_create_physical_device() { free(physical_devices); ERR_FAIL_V(ERR_CANT_CREATE); } - - /*Find the first discrete GPU with the most VRAM.*/ - { - print_line("Selecting primary GPU."); - VkPhysicalDeviceProperties device_properties; - VkPhysicalDeviceMemoryProperties memory_properties; - gpu = physical_devices[0]; - uint32_t largest_vram_size = 0; - VkPhysicalDeviceType gpu_type = VK_PHYSICAL_DEVICE_TYPE_OTHER; - for (uint32_t i = 0; i < gpu_count; i++) { - vkGetPhysicalDeviceProperties(physical_devices[i], &device_properties); - - /*Skip virtual and CPU devices for now.*/ - if (device_properties.deviceType > VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) { - continue; - } - - vkGetPhysicalDeviceMemoryProperties(physical_devices[i], &memory_properties); - - /*Total all heaps in case of 3GB+1GB configurations and similar.*/ - uint32_t memory_size = 0; - for (uint32_t j = 0; j < memory_properties.memoryHeapCount; j++) { - memory_size += memory_properties.memoryHeaps[j].size; - } - - if ((device_properties.deviceType >= gpu_type) || (device_properties.deviceType == gpu_type && memory_size > largest_vram_size)) { - gpu = physical_devices[i]; - gpu_type = device_properties.deviceType; - largest_vram_size = memory_size; - print_line(device_properties.deviceName); - } - } - } + /* for now, just grab the first physical device */ + gpu = physical_devices[0]; free(physical_devices); /* Look for device extensions */ @@ -1514,6 +1483,7 @@ VkPhysicalDeviceLimits VulkanContext::get_device_limits() const { } VulkanContext::VulkanContext() { + queue_props = NULL; command_buffer_count = 0; instance_validation_layers = NULL; use_validation_layers = true; diff --git a/editor/collada/collada.cpp b/editor/collada/collada.cpp index 231173e459..cf39abdc53 100644 --- a/editor/collada/collada.cpp +++ b/editor/collada/collada.cpp @@ -2194,7 +2194,11 @@ void Collada::_merge_skeletons(VisualScene *p_vscene, Node *p_node) { ERR_CONTINUE(!state.scene_map.has(nodeid)); //weird, it should have it... - NodeJoint *nj = SAFE_CAST<NodeJoint *>(state.scene_map[nodeid]); +#ifdef NO_SAFE_CAST + NodeJoint *nj = static_cast<NodeJoint *>(state.scene_map[nodeid]); +#else + NodeJoint *nj = dynamic_cast<NodeJoint *>(state.scene_map[nodeid]); +#endif ERR_CONTINUE(!nj); //broken collada ERR_CONTINUE(!nj->owner); //weird, node should have a skeleton owner @@ -2366,7 +2370,11 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L String nodeid = ng->skeletons[0]; ERR_FAIL_COND_V(!state.scene_map.has(nodeid), false); //weird, it should have it... - NodeJoint *nj = SAFE_CAST<NodeJoint *>(state.scene_map[nodeid]); +#ifdef NO_SAFE_CAST + NodeJoint *nj = static_cast<NodeJoint *>(state.scene_map[nodeid]); +#else + NodeJoint *nj = dynamic_cast<NodeJoint *>(state.scene_map[nodeid]); +#endif ERR_FAIL_COND_V(!nj, false); ERR_FAIL_COND_V(!nj->owner, false); //weird, node should have a skeleton owner diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp index 1506d64b63..9587daf93e 100644 --- a/editor/debugger/editor_debugger_inspector.cpp +++ b/editor/debugger/editor_debugger_inspector.cpp @@ -30,8 +30,8 @@ #include "editor_debugger_inspector.h" +#include "core/debugger/debugger_marshalls.h" #include "core/io/marshalls.h" -#include "core/script_debugger_remote.h" #include "editor/editor_node.h" #include "scene/debugger/scene_debugger.h" @@ -226,7 +226,7 @@ Object *EditorDebuggerInspector::get_object(ObjectID p_id) { void EditorDebuggerInspector::add_stack_variable(const Array &p_array) { - ScriptDebuggerRemote::ScriptStackVariable var; + DebuggerMarshalls::ScriptStackVariable var; var.deserialize(p_array); String n = var.name; Variant v = var.value; diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index fba86f2954..f4a8102b79 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -31,9 +31,12 @@ #include "editor_debugger_node.h" #include "editor/debugger/editor_debugger_tree.h" +#include "editor/debugger/script_editor_debugger.h" #include "editor/editor_log.h" #include "editor/editor_node.h" #include "editor/plugins/script_editor_plugin.h" +#include "scene/gui/menu_button.h" +#include "scene/gui/tab_container.h" template <typename Func> void _for_all(TabContainer *p_node, const Func &p_func) { @@ -49,7 +52,6 @@ EditorDebuggerNode *EditorDebuggerNode::singleton = NULL; EditorDebuggerNode::EditorDebuggerNode() { if (!singleton) singleton = this; - server.instance(); add_constant_override("margin_left", -EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT)); add_constant_override("margin_right", -EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT)); @@ -179,10 +181,9 @@ Error EditorDebuggerNode::start() { EditorNode::get_singleton()->make_bottom_panel_item_visible(this); } - int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); - const Error err = server->listen(remote_port); + server = Ref<EditorDebuggerServer>(EditorDebuggerServer::create_default()); + const Error err = server->start(); if (err != OK) { - EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), EditorLog::MSG_TYPE_ERROR); return err; } set_process(true); @@ -191,9 +192,10 @@ Error EditorDebuggerNode::start() { } void EditorDebuggerNode::stop() { - if (server->is_listening()) { + if (server.is_valid()) { server->stop(); EditorNode::get_log()->add_message("--- Debugging process stopped ---", EditorLog::MSG_TYPE_EDITOR); + server.unref(); } // Also close all debugging sessions. _for_all(tabs, [&](ScriptEditorDebugger *dbg) { @@ -231,9 +233,15 @@ void EditorDebuggerNode::_notification(int p_what) { break; } - if (p_what != NOTIFICATION_PROCESS || !server->is_listening()) + if (p_what != NOTIFICATION_PROCESS || !server.is_valid()) return; + if (!server.is_valid() || !server->is_active()) { + stop(); + return; + } + server->poll(); + // Errors and warnings int error_count = 0; int warning_count = 0; @@ -293,9 +301,8 @@ void EditorDebuggerNode::_notification(int p_what) { if (tabs->get_tab_count() <= 4) { // Max 4 debugging sessions active. debugger = _add_debugger(); } else { - // We already have too many sessions, disconnecting new clients to prevent it from hanging. - // (Not keeping a reference to the connection will disconnect it) - server->take_connection(); + // We already have too many sessions, disconnecting new clients to prevent them from hanging. + server->take_connection()->close(); return; // Can't add, stop here. } } @@ -462,6 +469,26 @@ void EditorDebuggerNode::reload_scripts() { }); } +void EditorDebuggerNode::debug_next() { + get_default_debugger()->debug_next(); +} + +void EditorDebuggerNode::debug_step() { + get_default_debugger()->debug_step(); +} + +void EditorDebuggerNode::debug_break() { + get_default_debugger()->debug_break(); +} + +void EditorDebuggerNode::debug_continue() { + get_default_debugger()->debug_continue(); +} + +String EditorDebuggerNode::get_var_value(const String &p_var) const { + return get_default_debugger()->get_var_value(p_var); +} + // LiveEdit/Inspector void EditorDebuggerNode::request_remote_tree() { get_current_debugger()->request_remote_tree(); diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h index 13a1d6dcb3..6181ccdb5f 100644 --- a/editor/debugger/editor_debugger_node.h +++ b/editor/debugger/editor_debugger_node.h @@ -31,17 +31,30 @@ #ifndef EDITOR_DEBUGGER_NODE_H #define EDITOR_DEBUGGER_NODE_H -#include "core/io/tcp_server.h" -#include "editor/debugger/script_editor_debugger.h" -#include "scene/gui/button.h" -#include "scene/gui/tab_container.h" +#include "editor/debugger/editor_debugger_server.h" +#include "scene/gui/margin_container.h" +class Button; class EditorDebuggerTree; +class EditorDebuggerRemoteObject; +class MenuButton; +class ScriptEditorDebugger; +class TabContainer; class EditorDebuggerNode : public MarginContainer { GDCLASS(EditorDebuggerNode, MarginContainer); +public: + enum CameraOverride { + OVERRIDE_NONE, + OVERRIDE_2D, + OVERRIDE_3D_1, // 3D Viewport 1 + OVERRIDE_3D_2, // 3D Viewport 2 + OVERRIDE_3D_3, // 3D Viewport 3 + OVERRIDE_3D_4 // 3D Viewport 4 + }; + private: enum Options { DEBUG_NEXT, @@ -71,7 +84,7 @@ private: } }; - Ref<TCP_Server> server = NULL; + Ref<EditorDebuggerServer> server; TabContainer *tabs = NULL; Button *debugger_button = NULL; MenuButton *script_menu = NULL; @@ -87,7 +100,7 @@ private: bool auto_switch_remote_scene_tree = false; bool debug_with_external_editor = false; bool hide_on_stop = true; - ScriptEditorDebugger::CameraOverride camera_override = ScriptEditorDebugger::OVERRIDE_NONE; + CameraOverride camera_override = OVERRIDE_NONE; Map<Breakpoint, bool> breakpoints; ScriptEditorDebugger *_add_debugger(); @@ -130,10 +143,10 @@ public: ScriptEditorDebugger *get_default_debugger() const; ScriptEditorDebugger *get_debugger(int p_debugger) const; - void debug_next() { get_default_debugger()->debug_next(); } - void debug_step() { get_default_debugger()->debug_step(); } - void debug_break() { get_default_debugger()->debug_break(); } - void debug_continue() { get_default_debugger()->debug_continue(); } + void debug_next(); + void debug_step(); + void debug_break(); + void debug_continue(); void set_script_debug_button(MenuButton *p_button); @@ -141,7 +154,7 @@ public: debugger_button = p_button; } - String get_var_value(const String &p_var) const { return get_default_debugger()->get_var_value(p_var); } + String get_var_value(const String &p_var) const; Ref<Script> get_dump_stack_script() const { return stack_script; } // Why do we need this? bool get_debug_with_external_editor() { return debug_with_external_editor; } @@ -167,8 +180,8 @@ public: void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos); // Camera - void set_camera_override(ScriptEditorDebugger::CameraOverride p_override) { camera_override = p_override; } - ScriptEditorDebugger::CameraOverride get_camera_override() { return camera_override; } + void set_camera_override(CameraOverride p_override) { camera_override = p_override; } + CameraOverride get_camera_override() { return camera_override; } Error start(); diff --git a/editor/debugger/editor_debugger_server.cpp b/editor/debugger/editor_debugger_server.cpp new file mode 100644 index 0000000000..c80988a662 --- /dev/null +++ b/editor/debugger/editor_debugger_server.cpp @@ -0,0 +1,90 @@ +/*************************************************************************/ +/* editor_debugger_server.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "editor_debugger_server.h" + +#include "core/io/marshalls.h" +#include "core/io/tcp_server.h" +#include "core/os/mutex.h" +#include "core/os/thread.h" +#include "editor/editor_log.h" +#include "editor/editor_node.h" +#include "editor/editor_settings.h" + +class EditorDebuggerServerTCP : public EditorDebuggerServer { + +private: + Ref<TCP_Server> server; + +public: + virtual void poll() {} + virtual Error start(); + virtual void stop(); + virtual bool is_active() const; + virtual bool is_connection_available() const; + virtual Ref<RemoteDebuggerPeer> take_connection(); + + EditorDebuggerServerTCP(); +}; + +EditorDebuggerServerTCP::EditorDebuggerServerTCP() { + server.instance(); +} + +Error EditorDebuggerServerTCP::start() { + int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port"); + const Error err = server->listen(remote_port); + if (err != OK) { + EditorNode::get_log()->add_message(String("Error listening on port ") + itos(remote_port), EditorLog::MSG_TYPE_ERROR); + return err; + } + return err; +} + +void EditorDebuggerServerTCP::stop() { + server->stop(); +} + +bool EditorDebuggerServerTCP::is_active() const { + return server->is_listening(); +} + +bool EditorDebuggerServerTCP::is_connection_available() const { + return server->is_listening() && server->is_connection_available(); +} + +Ref<RemoteDebuggerPeer> EditorDebuggerServerTCP::take_connection() { + ERR_FAIL_COND_V(!is_connection_available(), Ref<RemoteDebuggerPeer>()); + return memnew(RemoteDebuggerPeerTCP(server->take_connection())); +} + +EditorDebuggerServer *EditorDebuggerServer::create_default() { + return memnew(EditorDebuggerServerTCP); +} diff --git a/editor/debugger/editor_debugger_server.h b/editor/debugger/editor_debugger_server.h new file mode 100644 index 0000000000..e9798c90b3 --- /dev/null +++ b/editor/debugger/editor_debugger_server.h @@ -0,0 +1,49 @@ +/*************************************************************************/ +/* editor_debugger_server.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef EDITOR_DEBUGGER_CONNECTION_H +#define EDITOR_DEBUGGER_CONNECTION_H + +#include "core/debugger/remote_debugger_peer.h" +#include "core/reference.h" + +class EditorDebuggerServer : public Reference { + +public: + static EditorDebuggerServer *create_default(); + virtual void poll() = 0; + virtual Error start() = 0; + virtual void stop() = 0; + virtual bool is_active() const = 0; + virtual bool is_connection_available() const = 0; + virtual Ref<RemoteDebuggerPeer> take_connection() = 0; +}; + +#endif // EDITOR_DEBUGGER_CONNECTION_H diff --git a/editor/editor_network_profiler.cpp b/editor/debugger/editor_network_profiler.cpp index a9ef21bb87..21ef66d1aa 100644 --- a/editor/editor_network_profiler.cpp +++ b/editor/debugger/editor_network_profiler.cpp @@ -31,8 +31,8 @@ #include "editor_network_profiler.h" #include "core/os/os.h" -#include "editor_scale.h" -#include "editor_settings.h" +#include "editor/editor_scale.h" +#include "editor/editor_settings.h" void EditorNetworkProfiler::_bind_methods() { ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable"))); @@ -58,7 +58,7 @@ void EditorNetworkProfiler::_update_frame() { TreeItem *root = counters_display->create_item(); - for (Map<ObjectID, MultiplayerAPI::ProfilingInfo>::Element *E = nodes_data.front(); E; E = E->next()) { + for (Map<ObjectID, DebuggerMarshalls::MultiplayerNodeInfo>::Element *E = nodes_data.front(); E; E = E->next()) { TreeItem *node = counters_display->create_item(root); @@ -95,7 +95,7 @@ void EditorNetworkProfiler::_clear_pressed() { } } -void EditorNetworkProfiler::add_node_frame_data(const MultiplayerAPI::ProfilingInfo p_frame) { +void EditorNetworkProfiler::add_node_frame_data(const DebuggerMarshalls::MultiplayerNodeInfo p_frame) { if (!nodes_data.has(p_frame.node)) { nodes_data.insert(p_frame.node, p_frame); diff --git a/editor/editor_network_profiler.h b/editor/debugger/editor_network_profiler.h index 680131c288..f532dc5dd0 100644 --- a/editor/editor_network_profiler.h +++ b/editor/debugger/editor_network_profiler.h @@ -31,6 +31,7 @@ #ifndef EDITORNETWORKPROFILER_H #define EDITORNETWORKPROFILER_H +#include "core/debugger/debugger_marshalls.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/label.h" @@ -50,7 +51,7 @@ private: Timer *frame_delay; - Map<ObjectID, MultiplayerAPI::ProfilingInfo> nodes_data; + Map<ObjectID, DebuggerMarshalls::MultiplayerNodeInfo> nodes_data; void _update_frame(); @@ -62,7 +63,7 @@ protected: static void _bind_methods(); public: - void add_node_frame_data(const MultiplayerAPI::ProfilingInfo p_frame); + void add_node_frame_data(const DebuggerMarshalls::MultiplayerNodeInfo p_frame); void set_bandwidth(int p_incoming, int p_outgoing); bool is_profiling(); diff --git a/editor/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index 64b633e656..2f3ad210b2 100644 --- a/editor/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -31,8 +31,8 @@ #include "editor_profiler.h" #include "core/os/os.h" -#include "editor_scale.h" -#include "editor_settings.h" +#include "editor/editor_scale.h" +#include "editor/editor_settings.h" void EditorProfiler::_make_metric_ptrs(Metric &m) { diff --git a/editor/editor_profiler.h b/editor/debugger/editor_profiler.h index 0a442ddd5c..0a442ddd5c 100644 --- a/editor/editor_profiler.h +++ b/editor/debugger/editor_profiler.h diff --git a/editor/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index e9638148e2..52aa418922 100644 --- a/editor/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -31,8 +31,8 @@ #include "editor_visual_profiler.h" #include "core/os/os.h" -#include "editor_scale.h" -#include "editor_settings.h" +#include "editor/editor_scale.h" +#include "editor/editor_settings.h" void EditorVisualProfiler::add_frame_metric(const Metric &p_metric) { diff --git a/editor/editor_visual_profiler.h b/editor/debugger/editor_visual_profiler.h index 5194c08b96..5194c08b96 100644 --- a/editor/editor_visual_profiler.h +++ b/editor/debugger/editor_visual_profiler.h diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 169ff61e71..3d567ed2b3 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -30,21 +30,22 @@ #include "script_editor_debugger.h" +#include "core/debugger/debugger_marshalls.h" #include "core/io/marshalls.h" #include "core/project_settings.h" -#include "core/script_debugger_remote.h" #include "core/ustring.h" +#include "editor/debugger/editor_network_profiler.h" +#include "editor/debugger/editor_profiler.h" +#include "editor/debugger/editor_visual_profiler.h" #include "editor/editor_log.h" -#include "editor/editor_network_profiler.h" #include "editor/editor_node.h" -#include "editor/editor_profiler.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" -#include "editor/editor_visual_profiler.h" #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/spatial_editor_plugin.h" #include "editor/property_editor.h" #include "main/performance.h" +#include "scene/3d/camera.h" #include "scene/debugger/scene_debugger.h" #include "scene/gui/dialogs.h" #include "scene/gui/label.h" @@ -58,12 +59,14 @@ #include "scene/gui/tree.h" #include "scene/resources/packed_scene.h" +using CameraOverride = EditorDebuggerNode::CameraOverride; + void ScriptEditorDebugger::_put_msg(String p_message, Array p_data) { if (is_session_active()) { Array msg; msg.push_back(p_message); msg.push_back(p_data); - ppeer->put_var(msg); + peer->put_message(msg); } } @@ -141,7 +144,7 @@ void ScriptEditorDebugger::save_node(ObjectID p_id, const String &p_file) { Array msg; msg.push_back(p_id); msg.push_back(p_file); - _put_msg("save_node", msg); + _put_msg("scene:save_node", msg); } void ScriptEditorDebugger::_file_selected(const String &p_file) { @@ -183,7 +186,7 @@ void ScriptEditorDebugger::_file_selected(const String &p_file) { void ScriptEditorDebugger::request_remote_tree() { - _put_msg("request_scene_tree", Array()); + _put_msg("scene:request_scene_tree", Array()); } const SceneDebuggerTree *ScriptEditorDebugger::get_remote_tree() { @@ -196,7 +199,7 @@ void ScriptEditorDebugger::update_remote_object(ObjectID p_obj_id, const String msg.push_back(p_obj_id); msg.push_back(p_prop); msg.push_back(p_value); - _put_msg("set_object_property", msg); + _put_msg("scene:set_object_property", msg); } void ScriptEditorDebugger::request_remote_object(ObjectID p_obj_id) { @@ -204,7 +207,7 @@ void ScriptEditorDebugger::request_remote_object(ObjectID p_obj_id) { ERR_FAIL_COND(p_obj_id.is_null()); Array msg; msg.push_back(p_obj_id); - _put_msg("inspect_object", msg); + _put_msg("scene:inspect_object", msg); } Object *ScriptEditorDebugger::get_remote_object(ObjectID p_id) { @@ -226,7 +229,7 @@ void ScriptEditorDebugger::_remote_object_property_updated(ObjectID p_id, const void ScriptEditorDebugger::_video_mem_request() { - _put_msg("request_video_mem", Array()); + _put_msg("core:memory", Array()); } Size2 ScriptEditorDebugger::get_minimum_size() const { @@ -267,36 +270,36 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da emit_signal("breaked", false, false); profiler->set_enabled(true); profiler->disable_seeking(); - } else if (p_msg == "message:set_pid") { + } else if (p_msg == "set_pid") { ERR_FAIL_COND(p_data.size() < 1); remote_pid = p_data[0]; - } else if (p_msg == "message:click_ctrl") { + } else if (p_msg == "scene:click_ctrl") { ERR_FAIL_COND(p_data.size() < 2); clicked_ctrl->set_text(p_data[0]); clicked_ctrl_type->set_text(p_data[1]); - } else if (p_msg == "message:scene_tree") { + } else if (p_msg == "scene:scene_tree") { scene_tree->nodes.clear(); scene_tree->deserialize(p_data); emit_signal("remote_tree_updated"); _update_buttons_state(); - } else if (p_msg == "message:inspect_object") { + } else if (p_msg == "scene:inspect_object") { ObjectID id = inspector->add_object(p_data); if (id.is_valid()) emit_signal("remote_object_updated", id); - } else if (p_msg == "message:video_mem") { + } else if (p_msg == "memory:usage") { vmem_tree->clear(); TreeItem *root = vmem_tree->create_item(); - ScriptDebuggerRemote::ResourceUsage usage; + DebuggerMarshalls::ResourceUsage usage; usage.deserialize(p_data); int total = 0; - for (List<ScriptDebuggerRemote::ResourceInfo>::Element *E = usage.infos.front(); E; E = E->next()) { + for (List<DebuggerMarshalls::ResourceInfo>::Element *E = usage.infos.front(); E; E = E->next()) { TreeItem *it = vmem_tree->create_item(root); String type = E->get().type; @@ -316,7 +319,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da } else if (p_msg == "stack_dump") { - ScriptDebuggerRemote::ScriptStackDump stack; + DebuggerMarshalls::ScriptStackDump stack; stack.deserialize(p_data); stack_dump->clear(); @@ -349,10 +352,10 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da } else if (p_msg == "output") { ERR_FAIL_COND(p_data.size() < 1); - String t = p_data[0]; - EditorNode::get_log()->add_message(t); - - } else if (p_msg == "performance") { + ERR_FAIL_COND(p_data[0].get_type() != Variant::PACKED_STRING_ARRAY); + Vector<String> strings = p_data[0]; + EditorNode::get_log()->add_message(String("\n").join(strings)); + } else if (p_msg == "performance:profile_frame") { Vector<float> p; p.resize(p_data.size()); for (int i = 0; i < p_data.size(); i++) { @@ -385,36 +388,28 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da perf_history.push_front(p); perf_draw->update(); - } else if (p_msg == "visual_profile") { - // TODO check me. - uint64_t frame = p_data[0]; - Vector<String> names = p_data[1]; - Vector<real_t> values = p_data[2]; + } else if (p_msg == "visual:profile_frame") { + DebuggerMarshalls::VisualProfilerFrame frame; + frame.deserialize(p_data); EditorVisualProfiler::Metric metric; - metric.areas.resize(names.size()); - metric.frame_number = frame; + metric.areas.resize(frame.areas.size()); + metric.frame_number = frame.frame_number; metric.valid = true; { EditorVisualProfiler::Metric::Area *areas_ptr = metric.areas.ptrw(); - int metric_count = names.size(); - - const String *rs = names.ptr(); - const real_t *rr = values.ptr(); - - for (int i = 0; i < metric_count; i++) { - - areas_ptr[i].name = rs[i]; - areas_ptr[i].cpu_time = rr[i * 2 + 0]; - areas_ptr[i].gpu_time = rr[i * 2 + 1]; + for (int i = 0; i < frame.areas.size(); i++) { + areas_ptr[i].name = frame.areas[i].name; + areas_ptr[i].cpu_time = frame.areas[i].cpu_msec; + areas_ptr[i].gpu_time = frame.areas[i].gpu_msec; } } visual_profiler->add_frame_metric(metric); } else if (p_msg == "error") { - ScriptDebuggerRemote::OutputError oe; + DebuggerMarshalls::OutputError oe; ERR_FAIL_COND_MSG(oe.deserialize(p_data) == false, "Failed to deserialize error message"); // Format time. @@ -520,15 +515,15 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da else error_count++; - } else if (p_msg == "profile_sig") { + } else if (p_msg == "servers:function_signature") { // Cache a profiler signature. - ScriptDebuggerRemote::ProfilerSignature sig; + DebuggerMarshalls::ScriptFunctionSignature sig; sig.deserialize(p_data); profiler_signature[sig.id] = sig.name; - } else if (p_msg == "profile_frame" || p_msg == "profile_total") { + } else if (p_msg == "servers:profile_frame" || p_msg == "servers:profile_total") { EditorProfiler::Metric metric; - ScriptDebuggerRemote::ProfilerFrame frame; + DebuggerMarshalls::ServersProfilerFrame frame; frame.deserialize(p_data); metric.valid = true; metric.frame_number = frame.frame_number; @@ -536,10 +531,8 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da metric.idle_time = frame.idle_time; metric.physics_time = frame.physics_time; metric.physics_frame_time = frame.physics_frame_time; - int frame_data_amount = frame.frames_data.size(); - int frame_function_amount = frame.frame_functions.size(); - if (frame_data_amount) { + if (frame.servers.size()) { EditorProfiler::Metric::Category frame_time; frame_time.signature = "category_frame_time"; frame_time.name = "Frame Time"; @@ -573,42 +566,42 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da metric.categories.push_back(frame_time); } - for (int i = 0; i < frame_data_amount; i++) { + for (int i = 0; i < frame.servers.size(); i++) { + const DebuggerMarshalls::ServerInfo &srv = frame.servers[i]; EditorProfiler::Metric::Category c; - String name = frame.frames_data[i].name; - Array values = frame.frames_data[i].data; + const String name = srv.name; c.name = name.capitalize(); - c.items.resize(values.size() / 2); + c.items.resize(srv.functions.size()); c.total_time = 0; c.signature = "categ::" + name; - for (int j = 0; j < values.size(); j += 2) { + for (int j = 0; j < srv.functions.size(); j++) { EditorProfiler::Metric::Category::Item item; item.calls = 1; item.line = 0; - item.name = values[j]; - item.self = values[j + 1]; + item.name = srv.functions[j].name; + item.self = srv.functions[j].time; item.total = item.self; item.signature = "categ::" + name + "::" + item.name; item.name = item.name.capitalize(); c.total_time += item.total; - c.items.write[j / 2] = item; + c.items.write[j] = item; } metric.categories.push_back(c); } EditorProfiler::Metric::Category funcs; funcs.total_time = frame.script_time; - funcs.items.resize(frame_function_amount); + funcs.items.resize(frame.script_functions.size()); funcs.name = "Script Functions"; funcs.signature = "script_functions"; - for (int i = 0; i < frame_function_amount; i++) { + for (int i = 0; i < frame.script_functions.size(); i++) { - int signature = frame.frame_functions[i].sig_id; - int calls = frame.frame_functions[i].call_count; - float total = frame.frame_functions[i].total_time; - float self = frame.frame_functions[i].self_time; + int signature = frame.script_functions[i].sig_id; + int calls = frame.script_functions[i].call_count; + float total = frame.script_functions[i].total_time; + float self = frame.script_functions[i].self_time; EditorProfiler::Metric::Category::Item item; if (profiler_signature.has(signature)) { @@ -639,24 +632,28 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da metric.categories.push_back(funcs); - if (p_msg == "profile_frame") + if (p_msg == "servers:profile_frame") profiler->add_frame_metric(metric, false); else profiler->add_frame_metric(metric, true); - } else if (p_msg == "network_profile") { - ScriptDebuggerRemote::NetworkProfilerFrame frame; + } else if (p_msg == "network:profile_frame") { + DebuggerMarshalls::NetworkProfilerFrame frame; frame.deserialize(p_data); for (int i = 0; i < frame.infos.size(); i++) { network_profiler->add_node_frame_data(frame.infos[i]); } - } else if (p_msg == "network_bandwidth") { + + } else if (p_msg == "network:bandwidth") { ERR_FAIL_COND(p_data.size() < 2); network_profiler->set_bandwidth(p_data[0], p_data[1]); - } else if (p_msg == "kill_me") { + } else if (p_msg == "request_quit") { emit_signal("stop_requested"); _stop_and_notify(); + + } else { + WARN_PRINT("unknown message " + p_msg); } } @@ -776,7 +773,7 @@ void ScriptEditorDebugger::_notification(int p_what) { if (is_session_active()) { - if (camera_override == OVERRIDE_2D) { + if (camera_override == CameraOverride::OVERRIDE_2D) { CanvasItemEditor *editor = CanvasItemEditor::get_singleton(); Dictionary state = editor->get_state(); @@ -789,10 +786,10 @@ void ScriptEditorDebugger::_notification(int p_what) { Array msg; msg.push_back(transform); - _put_msg("override_camera_2D:transform", msg); + _put_msg("scene:override_camera_2D:transform", msg); - } else if (camera_override >= OVERRIDE_3D_1) { - int viewport_idx = camera_override - OVERRIDE_3D_1; + } else if (camera_override >= CameraOverride::OVERRIDE_3D_1) { + int viewport_idx = camera_override - CameraOverride::OVERRIDE_3D_1; SpatialEditorViewport *viewport = SpatialEditor::get_singleton()->get_editor_viewport(viewport_idx); Camera *const cam = viewport->get_camera(); @@ -807,34 +804,15 @@ void ScriptEditorDebugger::_notification(int p_what) { } msg.push_back(cam->get_znear()); msg.push_back(cam->get_zfar()); - _put_msg("override_camera_3D:transform", msg); + _put_msg("scene:override_camera_3D:transform", msg); } } - if (!is_session_active()) { - _stop_and_notify(); - break; - }; - - if (ppeer->get_available_packet_count() <= 0) { - break; - }; - const uint64_t until = OS::get_singleton()->get_ticks_msec() + 20; - while (ppeer->get_available_packet_count() > 0) { + while (peer->has_message()) { - Variant cmd; - Error ret = ppeer->get_var(cmd); - if (ret != OK) { - _stop_and_notify(); - ERR_FAIL_MSG("Error decoding variant from peer"); - } - if (cmd.get_type() != Variant::ARRAY) { - _stop_and_notify(); - ERR_FAIL_MSG("Invalid message format received from peer"); - } - Array arr = cmd; + Array arr = peer->get_message(); if (arr.size() != 2 || arr[0].get_type() != Variant::STRING || arr[1].get_type() != Variant::ARRAY) { _stop_and_notify(); ERR_FAIL_MSG("Invalid message format received from peer"); @@ -844,6 +822,10 @@ void ScriptEditorDebugger::_notification(int p_what) { if (OS::get_singleton()->get_ticks_msec() > until) break; } + if (!is_session_active()) { + _stop_and_notify(); + break; + }; } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { @@ -875,14 +857,14 @@ void ScriptEditorDebugger::_clear_execution() { inspector->clear_stack_variables(); } -void ScriptEditorDebugger::start(Ref<StreamPeerTCP> p_connection) { +void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) { error_count = 0; warning_count = 0; stop(); - connection = p_connection; - ppeer->set_stream_peer(connection); + peer = p_peer; + ERR_FAIL_COND(p_peer.is_null()); perf_history.clear(); for (int i = 0; i < Performance::MONITOR_MAX; i++) { @@ -893,19 +875,11 @@ void ScriptEditorDebugger::start(Ref<StreamPeerTCP> p_connection) { set_process(true); breaked = false; can_debug = true; - camera_override = OVERRIDE_NONE; + camera_override = CameraOverride::OVERRIDE_NONE; tabs->set_current_tab(0); _set_reason_text(TTR("Debug session started."), MESSAGE_SUCCESS); _update_buttons_state(); - - if (profiler->is_profiling()) { - _profiler_activate(true); - } - - if (network_profiler->is_profiling()) { - _network_profiler_activate(true); - } } void ScriptEditorDebugger::_update_buttons_state() { @@ -936,10 +910,10 @@ void ScriptEditorDebugger::stop() { _clear_execution(); inspector->clear_cache(); - ppeer->set_stream_peer(Ref<StreamPeer>()); - if (connection.is_valid()) { - connection.unref(); + if (peer.is_valid()) { + peer->close(); + peer.unref(); reason->set_text(""); reason->set_tooltip(""); } @@ -952,49 +926,31 @@ void ScriptEditorDebugger::stop() { _update_buttons_state(); } -void ScriptEditorDebugger::_profiler_activate(bool p_enable) { - - if (p_enable) { - profiler_signature.clear(); - Array msg; - int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions"); - max_funcs = CLAMP(max_funcs, 16, 512); - msg.push_back(max_funcs); - _put_msg("start_profiling", msg); - print_verbose("Starting profiling."); - - } else { - _put_msg("stop_profiling", Array()); - print_verbose("Ending profiling."); - } -} - -void ScriptEditorDebugger::_visual_profiler_activate(bool p_enable) { +void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) { - if (!connection.is_valid()) - return; - - if (p_enable) { - profiler_signature.clear(); - _put_msg("start_visual_profiling", Array()); - print_verbose("Starting visual profiling."); - - } else { - _put_msg("stop_visual_profiling", Array()); - print_verbose("Ending visual profiling."); - } -} - -void ScriptEditorDebugger::_network_profiler_activate(bool p_enable) { - - if (p_enable) { - profiler_signature.clear(); - _put_msg("start_network_profiling", Array()); - print_verbose("Starting network profiling."); - - } else { - _put_msg("stop_network_profiling", Array()); - print_verbose("Ending network profiling."); + Array data; + data.push_back(p_enable); + switch (p_type) { + case PROFILER_NETWORK: + _put_msg("profiler:network", data); + break; + case PROFILER_VISUAL: + _put_msg("profiler:visual", data); + break; + case PROFILER_SCRIPTS_SERVERS: + if (p_enable) { + // Clear old script signatures. (should we move all this into the profiler?) + profiler_signature.clear(); + // Add max funcs options to request. + Array opts; + int max_funcs = EditorSettings::get_singleton()->get("debugger/profiler_frame_max_functions"); + opts.push_back(CLAMP(max_funcs, 16, 512)); + data.push_back(opts); + } + _put_msg("profiler:servers", data); + break; + default: + ERR_FAIL_MSG("Invalid profiler type"); } } @@ -1045,7 +1001,7 @@ int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) { Array msg; msg.push_back(p_path); msg.push_back(last_path_id); - _put_msg("live_node_path", msg); + _put_msg("scene:live_node_path", msg); return last_path_id; } @@ -1063,7 +1019,7 @@ int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) { Array msg; msg.push_back(p_path); msg.push_back(last_path_id); - _put_msg("live_res_path", msg); + _put_msg("scene:live_res_path", msg); return last_path_id; } @@ -1095,7 +1051,7 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n //no pointers, sorry msg.push_back(*argptr[i]); } - _put_msg("live_node_call", msg); + _put_msg("scene:live_node_call", msg); return; } @@ -1114,7 +1070,7 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n //no pointers, sorry msg.push_back(*argptr[i]); } - _put_msg("live_res_call", msg); + _put_msg("scene:live_res_call", msg); return; } @@ -1140,7 +1096,7 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p msg.push_back(pathid); msg.push_back(p_property); msg.push_back(res->get_path()); - _put_msg("live_node_prop_res", msg); + _put_msg("scene:live_node_prop_res", msg); } } else { @@ -1148,7 +1104,7 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p msg.push_back(pathid); msg.push_back(p_property); msg.push_back(p_value); - _put_msg("live_node_prop", msg); + _put_msg("scene:live_node_prop", msg); } return; @@ -1169,7 +1125,7 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p msg.push_back(pathid); msg.push_back(p_property); msg.push_back(res2->get_path()); - _put_msg("live_res_prop_res", msg); + _put_msg("scene:live_res_prop_res", msg); } } else { @@ -1177,7 +1133,7 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p msg.push_back(pathid); msg.push_back(p_property); msg.push_back(p_value); - _put_msg("live_res_prop", msg); + _put_msg("scene:live_res_prop", msg); } return; @@ -1255,7 +1211,7 @@ void ScriptEditorDebugger::update_live_edit_root() { msg.push_back(editor->get_edited_scene()->get_filename()); else msg.push_back(""); - _put_msg("live_set_root", msg); + _put_msg("scene:live_set_root", msg); live_edit_root->set_text(np); } @@ -1266,7 +1222,7 @@ void ScriptEditorDebugger::live_debug_create_node(const NodePath &p_parent, cons msg.push_back(p_parent); msg.push_back(p_type); msg.push_back(p_name); - _put_msg("live_create_node", msg); + _put_msg("scene:live_create_node", msg); } } @@ -1277,7 +1233,7 @@ void ScriptEditorDebugger::live_debug_instance_node(const NodePath &p_parent, co msg.push_back(p_parent); msg.push_back(p_path); msg.push_back(p_name); - _put_msg("live_instance_node", msg); + _put_msg("scene:live_instance_node", msg); } } void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) { @@ -1285,7 +1241,7 @@ void ScriptEditorDebugger::live_debug_remove_node(const NodePath &p_at) { if (live_debug) { Array msg; msg.push_back(p_at); - _put_msg("live_remove_node", msg); + _put_msg("scene:live_remove_node", msg); } } void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, ObjectID p_keep_id) { @@ -1294,7 +1250,7 @@ void ScriptEditorDebugger::live_debug_remove_and_keep_node(const NodePath &p_at, Array msg; msg.push_back(p_at); msg.push_back(p_keep_id); - _put_msg("live_remove_and_keep_node", msg); + _put_msg("scene:live_remove_and_keep_node", msg); } } void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath &p_at, int p_at_pos) { @@ -1304,7 +1260,7 @@ void ScriptEditorDebugger::live_debug_restore_node(ObjectID p_id, const NodePath msg.push_back(p_id); msg.push_back(p_at); msg.push_back(p_at_pos); - _put_msg("live_restore_node", msg); + _put_msg("scene:live_restore_node", msg); } } void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name) { @@ -1313,7 +1269,7 @@ void ScriptEditorDebugger::live_debug_duplicate_node(const NodePath &p_at, const Array msg; msg.push_back(p_at); msg.push_back(p_new_name); - _put_msg("live_duplicate_node", msg); + _put_msg("scene:live_duplicate_node", msg); } } void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) { @@ -1324,32 +1280,32 @@ void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const msg.push_back(p_new_place); msg.push_back(p_new_name); msg.push_back(p_at_pos); - _put_msg("live_reparent_node", msg); + _put_msg("scene:live_reparent_node", msg); } } -ScriptEditorDebugger::CameraOverride ScriptEditorDebugger::get_camera_override() const { +CameraOverride ScriptEditorDebugger::get_camera_override() const { return camera_override; } void ScriptEditorDebugger::set_camera_override(CameraOverride p_override) { - if (p_override == OVERRIDE_2D && camera_override != OVERRIDE_2D) { + if (p_override == CameraOverride::OVERRIDE_2D && camera_override != CameraOverride::OVERRIDE_2D) { Array msg; msg.push_back(true); - _put_msg("override_camera_2D:set", msg); - } else if (p_override != OVERRIDE_2D && camera_override == OVERRIDE_2D) { + _put_msg("scene:override_camera_2D:set", msg); + } else if (p_override != CameraOverride::OVERRIDE_2D && camera_override == CameraOverride::OVERRIDE_2D) { Array msg; msg.push_back(false); - _put_msg("override_camera_2D:set", msg); - } else if (p_override >= OVERRIDE_3D_1 && camera_override < OVERRIDE_3D_1) { + _put_msg("scene:override_camera_2D:set", msg); + } else if (p_override >= CameraOverride::OVERRIDE_3D_1 && camera_override < CameraOverride::OVERRIDE_3D_1) { Array msg; msg.push_back(true); - _put_msg("override_camera_3D:set", msg); - } else if (p_override < OVERRIDE_3D_1 && camera_override >= OVERRIDE_3D_1) { + _put_msg("scene:override_camera_3D:set", msg); + } else if (p_override < CameraOverride::OVERRIDE_3D_1 && camera_override >= CameraOverride::OVERRIDE_3D_1) { Array msg; msg.push_back(false); - _put_msg("override_camera_3D:set", msg); + _put_msg("scene:override_camera_3D:set", msg); } camera_override = p_override; @@ -1423,7 +1379,6 @@ void ScriptEditorDebugger::_clear_errors_list() { error_tree->clear(); error_count = 0; warning_count = 0; - update_tabs(); } // Right click on specific file(s) or folder(s). @@ -1470,7 +1425,7 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) { void ScriptEditorDebugger::_tab_changed(int p_tab) { if (tabs->get_tab_title(p_tab) == TTR("Video RAM")) { - // "Video RAM" tab was clicked, refresh the data it's dislaying when entering the tab. + // "Video RAM" tab was clicked, refresh the data it's displaying when entering the tab. _video_mem_request(); } } @@ -1502,8 +1457,6 @@ void ScriptEditorDebugger::_bind_methods() { ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { - ppeer = Ref<PacketPeerStream>(memnew(PacketPeerStream)); - ppeer->set_input_buffer_max_size((1024 * 1024 * 8) - 4); // 8 MiB should be enough, minus 4 bytes for separator. editor = p_editor; tabs = memnew(TabContainer); @@ -1655,7 +1608,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { profiler = memnew(EditorProfiler); profiler->set_name(TTR("Profiler")); tabs->add_child(profiler); - profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate)); + profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_SCRIPTS_SERVERS)); profiler->connect("break_request", callable_mp(this, &ScriptEditorDebugger::_profiler_seeked)); } @@ -1663,14 +1616,14 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { visual_profiler = memnew(EditorVisualProfiler); visual_profiler->set_name(TTR("Visual Profiler")); tabs->add_child(visual_profiler); - visual_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_visual_profiler_activate)); + visual_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_VISUAL)); } { //network profiler network_profiler = memnew(EditorNetworkProfiler); network_profiler->set_name(TTR("Network Profiler")); tabs->add_child(network_profiler); - network_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_network_profiler_activate)); + network_profiler->connect("enable_profiling", callable_mp(this, &ScriptEditorDebugger::_profiler_activate), varray(PROFILER_NETWORK)); } { //monitors @@ -1824,7 +1777,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { add_child(msgdialog); live_debug = true; - camera_override = OVERRIDE_NONE; + camera_override = CameraOverride::OVERRIDE_NONE; last_path_id = false; error_count = 0; warning_count = 0; @@ -1833,6 +1786,9 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { ScriptEditorDebugger::~ScriptEditorDebugger() { - ppeer->set_stream_peer(Ref<StreamPeer>()); + if (peer.is_valid()) { + peer->close(); + peer.unref(); + } memdelete(scene_tree); } diff --git a/editor/debugger/script_editor_debugger.h b/editor/debugger/script_editor_debugger.h index fd034ba983..e7ce917543 100644 --- a/editor/debugger/script_editor_debugger.h +++ b/editor/debugger/script_editor_debugger.h @@ -31,14 +31,13 @@ #ifndef SCRIPT_EDITOR_DEBUGGER_H #define SCRIPT_EDITOR_DEBUGGER_H -#include "core/io/packet_peer.h" -#include "core/io/stream_peer_tcp.h" +#include "core/os/os.h" #include "editor/debugger/editor_debugger_inspector.h" -#include "editor/editor_inspector.h" -#include "editor/property_editor.h" -#include "scene/3d/camera.h" -#include "scene/gui/box_container.h" +#include "editor/debugger/editor_debugger_node.h" +#include "editor/debugger/editor_debugger_server.h" +#include "editor/editor_file_dialog.h" #include "scene/gui/button.h" +#include "scene/gui/margin_container.h" class Tree; class EditorNode; @@ -61,16 +60,6 @@ class ScriptEditorDebugger : public MarginContainer { friend class EditorDebuggerNode; -public: - enum CameraOverride { - OVERRIDE_NONE, - OVERRIDE_2D, - OVERRIDE_3D_1, // 3D Viewport 1 - OVERRIDE_3D_2, // 3D Viewport 2 - OVERRIDE_3D_3, // 3D Viewport 3 - OVERRIDE_3D_4 // 3D Viewport 4 - }; - private: enum MessageType { MESSAGE_ERROR, @@ -78,6 +67,12 @@ private: MESSAGE_SUCCESS, }; + enum ProfilerType { + PROFILER_NETWORK, + PROFILER_VISUAL, + PROFILER_SCRIPTS_SERVERS + }; + AcceptDialog *msgdialog; LineEdit *clicked_ctrl; @@ -132,8 +127,7 @@ private: EditorDebuggerInspector *inspector; SceneDebuggerTree *scene_tree; - Ref<StreamPeerTCP> connection; - Ref<PacketPeerStream> ppeer; + Ref<RemoteDebuggerPeer> peer; HashMap<NodePath, int> node_path_cache; int last_path_id; @@ -151,7 +145,7 @@ private: bool live_debug; - CameraOverride camera_override; + EditorDebuggerNode::CameraOverride camera_override; void _performance_draw(); void _performance_select(); @@ -183,12 +177,9 @@ private: void _expand_errors_list(); void _collapse_errors_list(); - void _visual_profiler_activate(bool p_enable); - void _profiler_activate(bool p_enable); + void _profiler_activate(bool p_enable, int p_profiler); void _profiler_seeked(); - void _network_profiler_activate(bool p_enable); - void _clear_errors_list(); void _error_tree_item_rmb_selected(const Vector2 &p_pos); @@ -216,7 +207,7 @@ public: void request_remote_tree(); const SceneDebuggerTree *get_remote_tree(); - void start(Ref<StreamPeerTCP> p_connection); + void start(Ref<RemoteDebuggerPeer> p_peer); void stop(); void debug_skip_breakpoints(); @@ -228,7 +219,7 @@ public: void debug_continue(); bool is_breaked() const { return breaked; } bool is_debuggable() const { return can_debug; } - bool is_session_active() { return connection.is_valid() && connection->is_connected_to_host(); }; + bool is_session_active() { return peer.is_valid() && peer->is_peer_connected(); }; int get_remote_pid() const { return remote_pid; } int get_error_count() const { return error_count; } @@ -252,8 +243,8 @@ public: void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name); void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos); - CameraOverride get_camera_override() const; - void set_camera_override(CameraOverride p_override); + EditorDebuggerNode::CameraOverride get_camera_override() const; + void set_camera_override(EditorDebuggerNode::CameraOverride p_override); void set_breakpoint(const String &p_path, int p_line, bool p_enabled); diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp index 76dbadf67e..33877f86c2 100644 --- a/editor/editor_plugin_settings.cpp +++ b/editor/editor_plugin_settings.cpp @@ -137,19 +137,12 @@ void EditorPluginSettings::update_plugins() { item->set_metadata(1, script); item->set_text(2, author); item->set_metadata(2, description); - item->set_cell_mode(3, TreeItem::CELL_MODE_RANGE); - item->set_range_config(3, 0, 1, 1); - item->set_text(3, "Inactive,Active"); + item->set_cell_mode(3, TreeItem::CELL_MODE_CHECK); + item->set_text(3, TTR("Enable")); + bool is_active = EditorNode::get_singleton()->is_addon_plugin_enabled(d2); + item->set_checked(3, is_active); item->set_editable(3, true); item->add_button(4, get_icon("Edit", "EditorIcons"), BUTTON_PLUGIN_EDIT, false, TTR("Edit Plugin")); - - if (EditorNode::get_singleton()->is_addon_plugin_enabled(d2)) { - item->set_custom_color(3, get_color("success_color", "Editor")); - item->set_range(3, 1); - } else { - item->set_custom_color(3, get_color("disabled_font_color", "Editor")); - item->set_range(3, 0); - } } } } @@ -164,7 +157,7 @@ void EditorPluginSettings::_plugin_activity_changed() { TreeItem *ti = plugin_list->get_edited(); ERR_FAIL_COND(!ti); - bool active = ti->get_range(3); + bool active = ti->is_checked(3); String name = ti->get_metadata(0); EditorNode::get_singleton()->set_addon_plugin_enabled(name, active, true); @@ -173,14 +166,9 @@ void EditorPluginSettings::_plugin_activity_changed() { if (is_active != active) { updating = true; - ti->set_range(3, is_active ? 1 : 0); + ti->set_checked(3, is_active); updating = false; } - - if (is_active) - ti->set_custom_color(3, get_color("success_color", "Editor")); - else - ti->set_custom_color(3, get_color("disabled_font_color", "Editor")); } void EditorPluginSettings::_create_clicked() { diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 3c401a6fc7..98bc544478 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -109,9 +109,10 @@ void EditorResourcePreview::_thread_func(void *ud) { void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Texture2D> &p_texture, const Ref<Texture2D> &p_small_texture, ObjectID id, const StringName &p_func, const Variant &p_ud) { - MutexLock lock(preview_mutex); String path = p_str; { + MutexLock lock(preview_mutex); + uint32_t hash = 0; uint64_t modified_time = 0; @@ -364,7 +365,6 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p cache[path_id].order = order++; p_receiver->call(p_receiver_func, path_id, cache[path_id].preview, cache[path_id].small_preview, p_userdata); - preview_mutex.unlock(); return; } @@ -391,7 +391,6 @@ void EditorResourcePreview::queue_resource_preview(const String &p_path, Object if (cache.has(p_path)) { cache[p_path].order = order++; p_receiver->call(p_receiver_func, p_path, cache[p_path].preview, cache[p_path].small_preview, p_userdata); - preview_mutex.unlock(); return; } @@ -436,9 +435,10 @@ void EditorResourcePreview::_bind_methods() { void EditorResourcePreview::check_for_invalidation(const String &p_path) { - MutexLock lock(preview_mutex); bool call_invalidated = false; { + MutexLock lock(preview_mutex); + if (cache.has(p_path)) { uint64_t modified_time = FileAccess::get_modified_time(p_path); diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index 92ecda8508..0090d30b9c 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -350,7 +350,7 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String f->store_32(flags); f->store_32(p_limit_mipmap); - //reserverd for future use + //reserved for future use f->store_32(0); f->store_32(0); f->store_32(0); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index af7f8cf5d6..5629e3854d 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -462,7 +462,15 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig } float CanvasItemEditor::snap_angle(float p_target, float p_start) const { - return (((smart_snap_active || snap_rotation) ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL)) && snap_rotation_step != 0) ? Math::stepify(p_target - snap_rotation_offset, snap_rotation_step) + snap_rotation_offset : p_target; + if (((smart_snap_active || snap_rotation) ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL)) && snap_rotation_step != 0) { + if (snap_relative) { + return Math::stepify(p_target - snap_rotation_offset, snap_rotation_step) + snap_rotation_offset + (p_start - (int)(p_start / snap_rotation_step) * snap_rotation_step); + } else { + return Math::stepify(p_target - snap_rotation_offset, snap_rotation_step) + snap_rotation_offset; + } + } else { + return p_target; + } } void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { @@ -3992,7 +4000,7 @@ void CanvasItemEditor::_notification(int p_what) { if (!is_visible() && override_camera_button->is_pressed()) { EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton(); - debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_NONE); + debugger->set_camera_override(EditorDebuggerNode::OVERRIDE_NONE); override_camera_button->set_pressed(false); } } @@ -4348,9 +4356,9 @@ void CanvasItemEditor::_button_override_camera(bool p_pressed) { EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton(); if (p_pressed) { - debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_2D); + debugger->set_camera_override(EditorDebuggerNode::OVERRIDE_2D); } else { - debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_NONE); + debugger->set_camera_override(EditorDebuggerNode::OVERRIDE_NONE); } } diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp index b195609fb0..c4069ac2ab 100644 --- a/editor/plugins/debugger_editor_plugin.cpp +++ b/editor/plugins/debugger_editor_plugin.cpp @@ -122,6 +122,7 @@ void DebuggerEditorPlugin::_menu_option(int p_option) { debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_FILE_SERVER), !ischecked); EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_file_server", !ischecked); + } break; case RUN_LIVE_DEBUG: { @@ -136,6 +137,7 @@ void DebuggerEditorPlugin::_menu_option(int p_option) { bool ischecked = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG)); debug_menu->get_popup()->set_item_checked(debug_menu->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG), !ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_deploy_remote_debug", !ischecked); } break; case RUN_DEBUG_COLLISONS: { diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 60bed10351..bb03cad285 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -37,7 +37,6 @@ #include "core/os/os.h" #include "core/project_settings.h" #include "editor/debugger/editor_debugger_node.h" -#include "editor/debugger/script_editor_debugger.h" #include "editor/editor_node.h" #include "editor/editor_run_script.h" #include "editor/editor_scale.h" diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 02168a4c97..1489ea1e27 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -980,6 +980,23 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c } } +void ScriptTextEditor::_validate_symbol(const String &p_symbol) { + + TextEdit *text_edit = code_editor->get_text_edit(); + + Node *base = get_tree()->get_edited_scene_root(); + if (base) { + base = _find_node_for_script(base, base, script); + } + + ScriptLanguage::LookupResult result; + if (ScriptServer::is_global_class(p_symbol) || p_symbol.is_resource_file() || script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), p_symbol, script->get_path(), base, result) == OK) { + text_edit->set_highlighted_word(p_symbol); + } else { + text_edit->set_highlighted_word(String()); + } +} + void ScriptTextEditor::update_toggle_scripts_button() { if (code_editor != NULL) { code_editor->update_toggle_scripts_button(); @@ -1769,6 +1786,7 @@ ScriptTextEditor::ScriptTextEditor() { code_editor->set_code_complete_func(_code_complete_scripts, this); code_editor->get_text_edit()->connect("breakpoint_toggled", callable_mp(this, &ScriptTextEditor::_breakpoint_toggled)); code_editor->get_text_edit()->connect("symbol_lookup", callable_mp(this, &ScriptTextEditor::_lookup_symbol)); + code_editor->get_text_edit()->connect("symbol_validate", callable_mp(this, &ScriptTextEditor::_validate_symbol)); code_editor->get_text_edit()->connect("info_clicked", callable_mp(this, &ScriptTextEditor::_lookup_connections)); code_editor->set_v_size_flags(SIZE_EXPAND_FILL); code_editor->show_toggle_scripts_button(); diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index e23160d029..d2f0b310e6 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -178,6 +178,7 @@ protected: void _goto_line(int p_line) { goto_line(p_line); } void _lookup_symbol(const String &p_symbol, int p_row, int p_column); + void _validate_symbol(const String &p_symbol); void _lookup_connections(int p_row, String p_method); diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 4b0cbdb4e7..652e9c7a7d 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2416,11 +2416,18 @@ void SpatialEditorViewport::_notification(int p_what) { if (!se) continue; + Transform t = sp->get_global_gizmo_transform(); + + exist = true; + if (se->last_xform == t) + continue; + changed = true; + se->last_xform = t; + VisualInstance *vi = Object::cast_to<VisualInstance>(sp); se->aabb = vi ? vi->get_aabb() : _calculate_spatial_bounds(sp); - Transform t = sp->get_global_gizmo_transform(); t.translate(se->aabb.position); // apply AABB scaling before item's global transform @@ -2428,11 +2435,6 @@ void SpatialEditorViewport::_notification(int p_what) { aabb_s.scale(se->aabb.size); t.basis = t.basis * aabb_s; - exist = true; - if (se->last_xform == t) - continue; - changed = true; - se->last_xform = t; VisualServer::get_singleton()->instance_set_transform(se->sbox_instance, t); } @@ -4773,12 +4775,12 @@ void SpatialEditor::_menu_item_toggled(bool pressed, int p_option) { case MENU_TOOL_OVERRIDE_CAMERA: { EditorDebuggerNode *const debugger = EditorDebuggerNode::get_singleton(); + using Override = EditorDebuggerNode::CameraOverride; if (pressed) { - using Override = ScriptEditorDebugger::CameraOverride; debugger->set_camera_override((Override)(Override::OVERRIDE_3D_1 + camera_override_viewport_id)); } else { - debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_NONE); + debugger->set_camera_override(Override::OVERRIDE_NONE); } } break; @@ -4831,8 +4833,8 @@ void SpatialEditor::_update_camera_override_viewport(Object *p_viewport) { EditorDebuggerNode *const debugger = EditorDebuggerNode::get_singleton(); camera_override_viewport_id = current_viewport->index; - if (debugger->get_camera_override() >= ScriptEditorDebugger::OVERRIDE_3D_1) { - using Override = ScriptEditorDebugger::CameraOverride; + if (debugger->get_camera_override() >= EditorDebuggerNode::OVERRIDE_3D_1) { + using Override = EditorDebuggerNode::CameraOverride; debugger->set_camera_override((Override)(Override::OVERRIDE_3D_1 + camera_override_viewport_id)); } @@ -5789,7 +5791,7 @@ void SpatialEditor::_notification(int p_what) { if (!is_visible() && tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->is_pressed()) { EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton(); - debugger->set_camera_override(ScriptEditorDebugger::OVERRIDE_NONE); + debugger->set_camera_override(EditorDebuggerNode::OVERRIDE_NONE); tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->set_pressed(false); } } @@ -6241,6 +6243,10 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { settings_zfar->set_value(EDITOR_DEF("editors/3d/default_z_far", 1500)); settings_vbc->add_margin_child(TTR("View Z-Far:"), settings_zfar); + for (uint32_t i = 0; i < VIEWPORTS_COUNT; ++i) { + settings_dialog->connect("confirmed", callable_mp(viewports[i], &SpatialEditorViewport::_update_camera), varray(0.0)); + } + /* XFORM DIALOG */ xform_dialog = memnew(ConfirmationDialog); diff --git a/editor/translations/ca.po b/editor/translations/ca.po index 15d4265ef4..304fa8905b 100644 --- a/editor/translations/ca.po +++ b/editor/translations/ca.po @@ -11,12 +11,13 @@ # Adolfo Jayme Barrientos <fitojb@ubuntu.com>, 2020. # Xavier Gomez <hiulit@gmail.com>, 2020. # Aina <ainasoga@gmail.com>, 2020. +# Alex Mancha <codingstain@gmail.com>, 2020. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-02-07 10:32+0000\n" -"Last-Translator: Roger Blanco Ribera <roger.blancoribera@gmail.com>\n" +"PO-Revision-Date: 2020-03-11 12:20+0000\n" +"Last-Translator: Alex Mancha <codingstain@gmail.com>\n" "Language-Team: Catalan <https://hosted.weblate.org/projects/godot-engine/" "godot/ca/>\n" "Language: ca\n" @@ -24,7 +25,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 3.11-dev\n" +"X-Generator: Weblate 4.0-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -694,9 +695,8 @@ msgid "Line Number:" msgstr "Línia:" #: editor/code_editor.cpp -#, fuzzy msgid "%d replaced." -msgstr "Substitueix..." +msgstr "%d reemplaçat." #: editor/code_editor.cpp editor/editor_help.cpp msgid "%d match." @@ -2756,7 +2756,6 @@ msgid "Set Up Version Control" msgstr "Configurar Control de Versions" #: editor/editor_node.cpp -#, fuzzy msgid "Shut Down Version Control" msgstr "Desactivar el control de versions" @@ -5974,7 +5973,7 @@ msgstr "" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "Couldn't create a single convex collision shape." -msgstr "" +msgstr "No s'ha pogut crear una capa de col·lisió convexa." #: editor/plugins/mesh_instance_editor_plugin.cpp #, fuzzy diff --git a/editor/translations/cs.po b/editor/translations/cs.po index f3ae992410..595db1837f 100644 --- a/editor/translations/cs.po +++ b/editor/translations/cs.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-03-01 05:50+0000\n" +"PO-Revision-Date: 2020-03-12 23:33+0000\n" "Last-Translator: Vojtěch Šamla <auzkok@seznam.cz>\n" "Language-Team: Czech <https://hosted.weblate.org/projects/godot-engine/godot/" "cs/>\n" @@ -1117,7 +1117,7 @@ msgstr "Děkujeme za komunitu Godotu!" #: editor/editor_about.cpp msgid "Godot Engine contributors" -msgstr "Přispívající do Godot Enginu" +msgstr "Přispěvatelé do Godot Enginu" #: editor/editor_about.cpp msgid "Project Founders" @@ -9907,7 +9907,6 @@ msgid "Can't run project" msgstr "Nelze spustit projekt" #: editor/project_manager.cpp -#, fuzzy msgid "" "You currently don't have any projects.\n" "Would you like to explore official example projects in the Asset Library?" diff --git a/editor/translations/de.po b/editor/translations/de.po index 14d9926ecb..1520c3aa2a 100644 --- a/editor/translations/de.po +++ b/editor/translations/de.po @@ -53,8 +53,8 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-03-08 22:32+0000\n" -"Last-Translator: PagDev <pag.develop@gmail.com>\n" +"PO-Revision-Date: 2020-03-14 15:05+0000\n" +"Last-Translator: So Wieso <sowieso@dukun.de>\n" "Language-Team: German <https://hosted.weblate.org/projects/godot-engine/" "godot/de/>\n" "Language: de\n" @@ -6029,9 +6029,8 @@ msgstr "" "Dies ist die präziseste (aber langsamste) Methode für Kollisionsberechnungen." #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Create Single Convex Collision Sibling" -msgstr "Ein einzelnes konvexes Kollisionsunterelement erzeugen" +msgstr "Ein einzelnes konvexes Kollisionsnachbarelement erzeugen" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "" @@ -12483,7 +12482,7 @@ msgstr "" #: scene/3d/collision_shape.cpp msgid "" "ConcavePolygonShape doesn't support RigidBody in another mode than static." -msgstr "" +msgstr "ConcavePolygonShape unterstützt RigidBody nur im Modus Statisch." #: scene/3d/cpu_particles.cpp msgid "Nothing is visible because no mesh has been assigned." diff --git a/editor/translations/es.po b/editor/translations/es.po index ed82e80658..3bbe96bcb3 100644 --- a/editor/translations/es.po +++ b/editor/translations/es.po @@ -47,7 +47,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-02-27 07:01+0000\n" +"PO-Revision-Date: 2020-03-11 12:20+0000\n" "Last-Translator: Javier Ocampos <xavier.ocampos@gmail.com>\n" "Language-Team: Spanish <https://hosted.weblate.org/projects/godot-engine/" "godot/es/>\n" @@ -6027,9 +6027,8 @@ msgstr "" "Es la opción más precisa (pero la más lenta) para la detección de colisiones." #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Create Single Convex Collision Sibling" -msgstr "Crear una Única Colisión Convexa Hermana" +msgstr "Crear Colisión Convexa Única Hermana" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "" @@ -12481,6 +12480,7 @@ msgstr "" msgid "" "ConcavePolygonShape doesn't support RigidBody in another mode than static." msgstr "" +"ConcavePolygonShape no soporta RigidBody de otro modo que no sea estático." #: scene/3d/cpu_particles.cpp msgid "Nothing is visible because no mesh has been assigned." diff --git a/editor/translations/es_AR.po b/editor/translations/es_AR.po index dce0d89b7e..7781d59f34 100644 --- a/editor/translations/es_AR.po +++ b/editor/translations/es_AR.po @@ -18,7 +18,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-02-27 07:01+0000\n" +"PO-Revision-Date: 2020-03-11 12:20+0000\n" "Last-Translator: Javier Ocampos <xavier.ocampos@gmail.com>\n" "Language-Team: Spanish (Argentina) <https://hosted.weblate.org/projects/" "godot-engine/godot/es_AR/>\n" @@ -5991,9 +5991,8 @@ msgstr "" "Esta es la opción mas exacta (pero más lenta) de detección de colisiones." #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Create Single Convex Collision Sibling" -msgstr "Crear Colisión Convexa Unica como Nodo Hermano" +msgstr "Crear Colisión Convexa Única Hermana" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "" @@ -12435,6 +12434,7 @@ msgstr "" msgid "" "ConcavePolygonShape doesn't support RigidBody in another mode than static." msgstr "" +"ConcavePolygonShape no soporta RigidBody de otro modo que no sea estático." #: scene/3d/cpu_particles.cpp msgid "Nothing is visible because no mesh has been assigned." diff --git a/editor/translations/fi.po b/editor/translations/fi.po index d590546571..2798d56d28 100644 --- a/editor/translations/fi.po +++ b/editor/translations/fi.po @@ -14,7 +14,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-02-21 23:33+0000\n" +"PO-Revision-Date: 2020-03-14 15:05+0000\n" "Last-Translator: Tapani Niemi <tapani.niemi@kapsi.fi>\n" "Language-Team: Finnish <https://hosted.weblate.org/projects/godot-engine/" "godot/fi/>\n" @@ -23,7 +23,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 3.11.1\n" +"X-Generator: Weblate 4.0-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -5945,9 +5945,8 @@ msgstr "" "Tämä on tarkin (mutta hitain) vaihtoehto törmäystunnistukselle." #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Create Single Convex Collision Sibling" -msgstr "Luo yksittäisen konveksin törmäysmuodon sisaret" +msgstr "Luo yksittäisen konveksin törmäyksen sisar" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "" @@ -12362,6 +12361,7 @@ msgstr "" msgid "" "ConcavePolygonShape doesn't support RigidBody in another mode than static." msgstr "" +"ConcavePolygonShape ei tue RigidBody solmua muussa kuin staattisessa tilassa." #: scene/3d/cpu_particles.cpp msgid "Nothing is visible because no mesh has been assigned." diff --git a/editor/translations/ja.po b/editor/translations/ja.po index 3c14b17b53..0bb76f1261 100644 --- a/editor/translations/ja.po +++ b/editor/translations/ja.po @@ -35,7 +35,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-03-05 08:33+0000\n" +"PO-Revision-Date: 2020-03-16 09:43+0000\n" "Last-Translator: Akihiro Ogoshi <technical@palsystem-game.com>\n" "Language-Team: Japanese <https://hosted.weblate.org/projects/godot-engine/" "godot/ja/>\n" @@ -908,7 +908,7 @@ msgstr "切断" #: editor/connections_dialog.cpp msgid "Connect a Signal to a Method" -msgstr "メソッドにシグナルを接続する" +msgstr "メソッドにシグナルを接続" #: editor/connections_dialog.cpp msgid "Edit Connection:" @@ -5834,7 +5834,7 @@ msgstr "グラデーション編集" #: editor/plugins/item_list_editor_plugin.cpp msgid "Item %d" -msgstr "アイテム%d" +msgstr "アイテム %d" #: editor/plugins/item_list_editor_plugin.cpp msgid "Items" @@ -5854,7 +5854,7 @@ msgstr "メッシュがありません!" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "Couldn't create a Trimesh collision shape." -msgstr "トライメッシュコリジョンシェイプを作成できませんでした。" +msgstr "三角形メッシュ コリジョンシェイプを作成できませんでした。" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "Create Static Trimesh Body" @@ -5954,7 +5954,7 @@ msgstr "" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "Create Trimesh Collision Sibling" -msgstr "三角形メッシュ兄弟コリジョンを生成" +msgstr "三角形メッシュ コリジョンの兄弟を作成" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "" @@ -5965,7 +5965,6 @@ msgstr "" "これは、衝突検出の最も正確な(ただし最も遅い)オプションです。" #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Create Single Convex Collision Sibling" msgstr "単一の凸型コリジョンの兄弟を作成" @@ -5979,7 +5978,7 @@ msgstr "" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "Create Multiple Convex Collision Siblings" -msgstr "複数の凸型コリジョンの兄弟を作成する" +msgstr "複数の凸型コリジョンの兄弟を作成" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "" @@ -7654,7 +7653,7 @@ msgstr "ジオメトリが無効です。衝突ポリゴンを作成できませ #: editor/plugins/sprite_editor_plugin.cpp msgid "Create CollisionPolygon2D Sibling" -msgstr "CollisionPolygon2Dの兄弟を作成する" +msgstr "CollisionPolygon2Dの兄弟を作成" #: editor/plugins/sprite_editor_plugin.cpp msgid "Invalid geometry, can't create light occluder." @@ -7662,7 +7661,7 @@ msgstr "ジオメトリが無効です。ライトオクールダーを作成で #: editor/plugins/sprite_editor_plugin.cpp msgid "Create LightOccluder2D Sibling" -msgstr "LightOccluder2Dの兄弟を作成する" +msgstr "LightOccluder2Dの兄弟を作成" #: editor/plugins/sprite_editor_plugin.cpp msgid "Sprite" @@ -11936,9 +11935,9 @@ msgid "" " Godot Version: %s\n" "Please reinstall Android build template from 'Project' menu." msgstr "" -"Androidビルドバージョンの不一致:\n" -"インストールされたテンプレート:%s\n" -"ゴドーバージョン:%s\n" +"Androidビルド バージョンの不一致:\n" +" インストールされたテンプレート: %s\n" +" Godot バージョン: %s\n" "「プロジェクト 」メニューからAndroidビルドテンプレートを再インストールしてく" "ださい。" @@ -11952,7 +11951,7 @@ msgid "" "Alternatively visit docs.godotengine.org for Android build documentation." msgstr "" "Androidプロジェクトのビルドに失敗しました。エラーの出力を確認してください。\n" -"あるいは、Androidビルドドキュメントについてはdocs.godotengine.orgをご覧くださ" +"また、Androidビルドについてのドキュメントは docs.godotengine.org をご覧くださ" "い。" #: platform/android/export/export.cpp @@ -12372,6 +12371,8 @@ msgstr "" msgid "" "ConcavePolygonShape doesn't support RigidBody in another mode than static." msgstr "" +"ConcavePolygonShape は、Static 以外のモードの RigidBody をサポートしていませ" +"ん。" #: scene/3d/cpu_particles.cpp msgid "Nothing is visible because no mesh has been assigned." diff --git a/editor/translations/ko.po b/editor/translations/ko.po index 37c950097b..ec33599440 100644 --- a/editor/translations/ko.po +++ b/editor/translations/ko.po @@ -19,7 +19,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-03-05 08:33+0000\n" +"PO-Revision-Date: 2020-03-14 00:33+0000\n" "Last-Translator: Ch. <ccwpc@hanmail.net>\n" "Language-Team: Korean <https://hosted.weblate.org/projects/godot-engine/" "godot/ko/>\n" @@ -12271,6 +12271,8 @@ msgstr "" msgid "" "ConcavePolygonShape doesn't support RigidBody in another mode than static." msgstr "" +"ConcavePolygonShape는 static 외의 모드가 설정된 RigidBody를 지원하지 않습니" +"다." #: scene/3d/cpu_particles.cpp msgid "Nothing is visible because no mesh has been assigned." diff --git a/editor/translations/lv.po b/editor/translations/lv.po index dc0a5aa151..14dfdff801 100644 --- a/editor/translations/lv.po +++ b/editor/translations/lv.po @@ -4,12 +4,13 @@ # This file is distributed under the same license as the Godot source code. # Gustavs Porietis (pg829-) <porietisgustavs@gmail.com>, 2018. # Martch Zagorski <martchzagorski@gmail.com>, 2018. +# Jānis Ondzuls <janisond@inbox.lv>, 2020. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2018-12-13 14:41+0100\n" -"Last-Translator: Martch Zagorski <martchzagorski@gmail.com>\n" +"PO-Revision-Date: 2020-03-11 12:20+0000\n" +"Last-Translator: Jānis Ondzuls <janisond@inbox.lv>\n" "Language-Team: Latvian <https://hosted.weblate.org/projects/godot-engine/" "godot/lv/>\n" "Language: lv\n" @@ -18,7 +19,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n % 10 == 0 || n % 100 >= 11 && n % 100 <= " "19) ? 0 : ((n % 10 == 1 && n % 100 != 11) ? 1 : 2);\n" -"X-Generator: Poedit 2.2\n" +"X-Generator: Weblate 4.0-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -65,31 +66,31 @@ msgstr "" #: core/ustring.cpp msgid "B" -msgstr "" +msgstr "B" #: core/ustring.cpp msgid "KiB" -msgstr "" +msgstr "KiB" #: core/ustring.cpp msgid "MiB" -msgstr "" +msgstr "MiB" #: core/ustring.cpp msgid "GiB" -msgstr "" +msgstr "GiB" #: core/ustring.cpp msgid "TiB" -msgstr "" +msgstr "TiB" #: core/ustring.cpp msgid "PiB" -msgstr "" +msgstr "PiB" #: core/ustring.cpp msgid "EiB" -msgstr "" +msgstr "EiB" #: editor/animation_bezier_editor.cpp msgid "Free" @@ -101,29 +102,27 @@ msgstr "Balancēts" #: editor/animation_bezier_editor.cpp msgid "Mirror" -msgstr "" +msgstr "Spogulis" #: editor/animation_bezier_editor.cpp editor/editor_profiler.cpp msgid "Time:" -msgstr "" +msgstr "Laiks:" #: editor/animation_bezier_editor.cpp msgid "Value:" -msgstr "" +msgstr "Vērtība:" #: editor/animation_bezier_editor.cpp msgid "Insert Key Here" -msgstr "" +msgstr "Ievadiet vērtību šeit" #: editor/animation_bezier_editor.cpp -#, fuzzy msgid "Duplicate Selected Key(s)" -msgstr "Dublikāta Izvēle" +msgstr "Dublikāta Vērtības" #: editor/animation_bezier_editor.cpp -#, fuzzy msgid "Delete Selected Key(s)" -msgstr "Izdzēst izvēlētos failus?" +msgstr "Izdzēst izvēlēto(ās) vērtību(as)?" #: editor/animation_bezier_editor.cpp msgid "Add Bezier Point" @@ -682,7 +681,7 @@ msgstr "" #: editor/array_property_edit.cpp msgid "Change Array Value" -msgstr "" +msgstr "Izmainīt masīva vērtību" #: editor/code_editor.cpp msgid "Go to Line" @@ -690,20 +689,19 @@ msgstr "Doties uz Rindu" #: editor/code_editor.cpp msgid "Line Number:" -msgstr "" +msgstr "Rindas Numurs:" #: editor/code_editor.cpp -#, fuzzy msgid "%d replaced." -msgstr "Aizvietot" +msgstr "%d aizvietots." #: editor/code_editor.cpp editor/editor_help.cpp msgid "%d match." -msgstr "" +msgstr "%d sakritība." #: editor/code_editor.cpp editor/editor_help.cpp msgid "%d matches." -msgstr "" +msgstr "%d sakritības." #: editor/code_editor.cpp editor/find_in_files.cpp msgid "Match Case" @@ -719,16 +717,16 @@ msgstr "Aizvietot" #: editor/code_editor.cpp msgid "Replace All" -msgstr "" +msgstr "Aizvietot visu" #: editor/code_editor.cpp msgid "Selection Only" -msgstr "" +msgstr "Tikai izvēlētais" #: editor/code_editor.cpp editor/plugins/script_text_editor.cpp #: editor/plugins/text_editor.cpp msgid "Standard" -msgstr "" +msgstr "Standarts" #: editor/code_editor.cpp editor/plugins/script_editor_plugin.cpp msgid "Toggle Scripts Panel" diff --git a/editor/translations/nl.po b/editor/translations/nl.po index 458ff0b5b8..a729ea6119 100644 --- a/editor/translations/nl.po +++ b/editor/translations/nl.po @@ -44,7 +44,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-03-08 22:33+0000\n" +"PO-Revision-Date: 2020-03-16 09:43+0000\n" "Last-Translator: Stijn Hinlopen <f.a.hinlopen@gmail.com>\n" "Language-Team: Dutch <https://hosted.weblate.org/projects/godot-engine/godot/" "nl/>\n" @@ -12434,7 +12434,7 @@ msgstr "" #: scene/3d/collision_shape.cpp msgid "" "ConcavePolygonShape doesn't support RigidBody in another mode than static." -msgstr "" +msgstr "ConcavePolygonShape ondersteunt RigidBody alleen in statische modus." #: scene/3d/cpu_particles.cpp msgid "Nothing is visible because no mesh has been assigned." diff --git a/editor/translations/pl.po b/editor/translations/pl.po index 14bbb799aa..de1d6d5375 100644 --- a/editor/translations/pl.po +++ b/editor/translations/pl.po @@ -42,7 +42,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-03-08 22:33+0000\n" +"PO-Revision-Date: 2020-03-16 09:43+0000\n" "Last-Translator: Tomek <kobewi4e@gmail.com>\n" "Language-Team: Polish <https://hosted.weblate.org/projects/godot-engine/" "godot/pl/>\n" @@ -5981,7 +5981,6 @@ msgstr "" "To jest najdokładniejsza (ale najwolniejsza) opcja do detekcji kolizji." #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Create Single Convex Collision Sibling" msgstr "Utwórz pojedynczego wypukłego sąsiada kolizji" @@ -12400,6 +12399,8 @@ msgstr "" msgid "" "ConcavePolygonShape doesn't support RigidBody in another mode than static." msgstr "" +"ConcavePolygonShape nie obsługuje węzła RigidBody w innym trybie niż " +"statyczny." #: scene/3d/cpu_particles.cpp msgid "Nothing is visible because no mesh has been assigned." diff --git a/editor/translations/pt_PT.po b/editor/translations/pt_PT.po index 60009b3171..d7532e38d4 100644 --- a/editor/translations/pt_PT.po +++ b/editor/translations/pt_PT.po @@ -19,7 +19,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-02-18 15:09+0000\n" +"PO-Revision-Date: 2020-03-16 09:43+0000\n" "Last-Translator: João Lopes <linux-man@hotmail.com>\n" "Language-Team: Portuguese (Portugal) <https://hosted.weblate.org/projects/" "godot-engine/godot/pt_PT/>\n" @@ -28,7 +28,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 3.11\n" +"X-Generator: Weblate 4.0-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -5958,7 +5958,6 @@ msgstr "" "Esta é a mais precisa (mas mais lenta) opção para deteção de colisão." #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Create Single Convex Collision Sibling" msgstr "Criar Irmãos Únicos de Colisão Convexa" @@ -12362,7 +12361,7 @@ msgstr "" #: scene/3d/collision_shape.cpp msgid "" "ConcavePolygonShape doesn't support RigidBody in another mode than static." -msgstr "" +msgstr "ConcavePolygonShape apenas suporta RigidBody no modo estático." #: scene/3d/cpu_particles.cpp msgid "Nothing is visible because no mesh has been assigned." diff --git a/editor/translations/ru.po b/editor/translations/ru.po index b05077637a..d3402fd63e 100644 --- a/editor/translations/ru.po +++ b/editor/translations/ru.po @@ -66,12 +66,13 @@ # Artur Tretiak <stikyt@protonmail.com>, 2020. # Smadjavul <o1985af@gmail.com>, 2020. # anonymous <noreply@weblate.org>, 2020. +# Vinsent Insaider_red <vinsent.in7aider@gmail.com>, 2020. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-03-07 21:18+0000\n" -"Last-Translator: Smadjavul <o1985af@gmail.com>\n" +"PO-Revision-Date: 2020-03-11 12:20+0000\n" +"Last-Translator: Vinsent Insaider_red <vinsent.in7aider@gmail.com>\n" "Language-Team: Russian <https://hosted.weblate.org/projects/godot-engine/" "godot/ru/>\n" "Language: ru\n" @@ -98,9 +99,8 @@ msgid "Not enough bytes for decoding bytes, or invalid format." msgstr "Недостаточно байтов для декодирования байтов или неверный формат." #: core/math/expression.cpp -#, fuzzy msgid "Invalid input %i (not passed) in expression" -msgstr "Некорректный ввод %i (не был передан) в выражении" +msgstr "Некорректный ввод %i (не подходит) в выражении" #: core/math/expression.cpp msgid "self can't be used because instance is null (not passed)" diff --git a/editor/translations/tr.po b/editor/translations/tr.po index c73724c7b7..83eb878d8c 100644 --- a/editor/translations/tr.po +++ b/editor/translations/tr.po @@ -42,12 +42,13 @@ # Muhammet Mustafa Tozlu <m.mustafatozlu@gmail.com>, 2019. # HALİL ATAŞ <halillatass@gmail.com>, 2019. # Zsosu Ktosu <zktosu@gmail.com>, 2020. +# Mesut Aslan <kontinyu@gmail.com>, 2020. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-01-30 03:56+0000\n" -"Last-Translator: Zsosu Ktosu <zktosu@gmail.com>\n" +"PO-Revision-Date: 2020-03-11 12:20+0000\n" +"Last-Translator: Mesut Aslan <kontinyu@gmail.com>\n" "Language-Team: Turkish <https://hosted.weblate.org/projects/godot-engine/" "godot/tr/>\n" "Language: tr\n" @@ -55,7 +56,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 3.11-dev\n" +"X-Generator: Weblate 4.0-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -726,9 +727,8 @@ msgid "Line Number:" msgstr "Satır Numarası:" #: editor/code_editor.cpp -#, fuzzy msgid "%d replaced." -msgstr "Değiştir..." +msgstr "%d değiştirildi." #: editor/code_editor.cpp editor/editor_help.cpp msgid "%d match." @@ -3989,9 +3989,8 @@ msgid "Saving..." msgstr "Kaydediliyor..." #: editor/import_dock.cpp -#, fuzzy msgid "%d Files" -msgstr " Dosyalar" +msgstr "%d Dosya" #: editor/import_dock.cpp msgid "Set as Default for '%s'" @@ -5870,9 +5869,8 @@ msgid "Mesh is empty!" msgstr "Örüntü boş!" #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Couldn't create a Trimesh collision shape." -msgstr "Üçlü Örüntü Çarpışma Kardeşi Oluştur" +msgstr "Trimesh çarpışma şekli oluşturulamadı." #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "Create Static Trimesh Body" @@ -5888,25 +5886,23 @@ msgstr "Üçlü Örüntü Yüzeyi Oluştur" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "Can't create a single convex collision shape for the scene root." -msgstr "" +msgstr "Sahne kökü için tek bir dışbükey çarpışma şekli oluşturulamaz." #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "Couldn't create a single convex collision shape." -msgstr "" +msgstr "Tek dışbükey çarpışma şekli oluşturulamadı." #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Create Single Convex Shape" -msgstr "Dışbükey Şekil[ler] Oluştur" +msgstr "Tekil Dışbükey Şekil Oluştur" #: editor/plugins/mesh_instance_editor_plugin.cpp msgid "Can't create multiple convex collision shapes for the scene root." msgstr "" #: editor/plugins/mesh_instance_editor_plugin.cpp -#, fuzzy msgid "Couldn't create any collision shapes." -msgstr "Klasör oluşturulamadı." +msgstr "Herhangi bir çarpışma şekli oluşturulamadı." #: editor/plugins/mesh_instance_editor_plugin.cpp #, fuzzy @@ -5977,6 +5973,8 @@ msgid "" "Creates a polygon-based collision shape.\n" "This is the most accurate (but slowest) option for collision detection." msgstr "" +"Poligon bazlı bir çarpışma şekli oluştur.\n" +"Bu en hassas (fakat en yavaş) çarpışma algılama seçeneğidir." #: editor/plugins/mesh_instance_editor_plugin.cpp #, fuzzy diff --git a/main/main.cpp b/main/main.cpp index d8a9cc87a7..887d423d52 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -31,6 +31,7 @@ #include "main.h" #include "core/crypto/crypto.h" +#include "core/debugger/engine_debugger.h" #include "core/input_map.h" #include "core/io/file_access_network.h" #include "core/io/file_access_pack.h" @@ -43,9 +44,6 @@ #include "core/os/os.h" #include "core/project_settings.h" #include "core/register_core_types.h" -#include "core/script_debugger_local.h" -#include "core/script_debugger_remote.h" -#include "core/script_language.h" #include "core/translation.h" #include "core/version.h" #include "core/version_hash.gen.h" @@ -96,7 +94,6 @@ static PackedData *packed_data = NULL; static ZipArchive *zip_packed_data = NULL; #endif static FileAccessNetworkClient *file_access_network_client = NULL; -static ScriptDebugger *script_debugger = NULL; static MessageQueue *message_queue = NULL; // Initialized in setup2() @@ -410,8 +407,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph String audio_driver = ""; String project_path = "."; bool upwards = false; - String debug_mode; - String debug_host; + String debug_uri = ""; bool skip_breakpoints = false; String main_pack; bool quiet_stdout = false; @@ -784,7 +780,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph }; } else if (I->get() == "-d" || I->get() == "--debug") { - debug_mode = "local"; + debug_uri = "local://"; #if defined(DEBUG_ENABLED) && !defined(SERVER_ENABLED) } else if (I->get() == "--debug-collisions") { debug_collisions = true; @@ -794,12 +790,12 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (I->get() == "--remote-debug") { if (I->next()) { - debug_mode = "remote"; - debug_host = I->next()->get(); - if (debug_host.find(":") == -1) { // wrong address + debug_uri = I->next()->get(); + if (debug_uri.find(":") == -1) { // wrong address OS::get_singleton()->print("Invalid debug host address, it should be of the form <host/IP>:<port>.\n"); goto error; } + debug_uri = "tcp://" + debug_uri; // will support multiple protocols eventually. N = I->next()->next(); } else { OS::get_singleton()->print("Missing remote debug host address, aborting.\n"); @@ -886,50 +882,16 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph GLOBAL_DEF("memory/limits/multithreaded_server/rid_pool_prealloc", 60); ProjectSettings::get_singleton()->set_custom_property_info("memory/limits/multithreaded_server/rid_pool_prealloc", PropertyInfo(Variant::INT, "memory/limits/multithreaded_server/rid_pool_prealloc", PROPERTY_HINT_RANGE, "0,500,1")); // No negative and limit to 500 due to crashes - GLOBAL_DEF("network/limits/debugger_stdout/max_chars_per_second", 2048); - ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_chars_per_second", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_chars_per_second", PROPERTY_HINT_RANGE, "0, 4096, 1, or_greater")); - GLOBAL_DEF("network/limits/debugger_stdout/max_messages_per_frame", 10); - ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_messages_per_frame", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_messages_per_frame", PROPERTY_HINT_RANGE, "0, 20, 1, or_greater")); - GLOBAL_DEF("network/limits/debugger_stdout/max_errors_per_second", 100); - ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_errors_per_second", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_errors_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater")); - GLOBAL_DEF("network/limits/debugger_stdout/max_warnings_per_second", 100); - ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger_stdout/max_warnings_per_second", PropertyInfo(Variant::INT, "network/limits/debugger_stdout/max_warnings_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater")); - - if (debug_mode == "remote") { - - ScriptDebuggerRemote *sdr = memnew(ScriptDebuggerRemote); - uint16_t debug_port = 6007; - if (debug_host.find(":") != -1) { - int sep_pos = debug_host.find_last(":"); - debug_port = debug_host.substr(sep_pos + 1, debug_host.length()).to_int(); - debug_host = debug_host.substr(0, sep_pos); - } - Error derr = sdr->connect_to_host(debug_host, debug_port); - - sdr->set_skip_breakpoints(skip_breakpoints); - - if (derr != OK) { - memdelete(sdr); - } else { - script_debugger = sdr; - } - } else if (debug_mode == "local") { + GLOBAL_DEF("network/limits/debugger/max_chars_per_second", 32768); + ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger/max_chars_per_second", PropertyInfo(Variant::INT, "network/limits/debugger/max_chars_per_second", PROPERTY_HINT_RANGE, "0, 4096, 1, or_greater")); + GLOBAL_DEF("network/limits/debugger/max_queued_messages", 2048); + ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger/max_queued_messages", PropertyInfo(Variant::INT, "network/limits/debugger/max_queued_messages", PROPERTY_HINT_RANGE, "0, 8192, 1, or_greater")); + GLOBAL_DEF("network/limits/debugger/max_errors_per_second", 400); + ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger/max_errors_per_second", PropertyInfo(Variant::INT, "network/limits/debugger/max_errors_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater")); + GLOBAL_DEF("network/limits/debugger/max_warnings_per_second", 400); + ProjectSettings::get_singleton()->set_custom_property_info("network/limits/debugger/max_warnings_per_second", PropertyInfo(Variant::INT, "network/limits/debugger/max_warnings_per_second", PROPERTY_HINT_RANGE, "0, 200, 1, or_greater")); - script_debugger = memnew(ScriptDebuggerLocal); - OS::get_singleton()->initialize_debugging(); - } - if (script_debugger) { - //there is a debugger, parse breakpoints - - for (int i = 0; i < breakpoints.size(); i++) { - - String bp = breakpoints[i]; - int sp = bp.find_last(":"); - ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format."); - - script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp)); - } - } + EngineDebugger::initialize(debug_uri, skip_breakpoints, breakpoints); #ifdef TOOLS_ENABLED if (editor) { @@ -1179,6 +1141,8 @@ error: if (show_help) print_help(execpath); + EngineDebugger::deinitialize(); + if (performance) memdelete(performance); if (input_map) @@ -1189,8 +1153,6 @@ error: memdelete(globals); if (engine) memdelete(engine); - if (script_debugger) - memdelete(script_debugger); if (packed_data) memdelete(packed_data); if (file_access_network_client) @@ -1401,8 +1363,10 @@ Error Main::setup2(Thread::ID p_main_tid_override) { audio_server->load_default_bus_layout(); - if (use_debug_profiler && script_debugger) { - script_debugger->profiling_start(); + if (use_debug_profiler && EngineDebugger::is_active()) { + // Start the "scripts" profiler, used in local debugging. + // We could add more, and make the CLI arg require a comma-separated list of profilers. + EngineDebugger::get_singleton()->profiler_enable("scripts", true); } _start_success = true; locale = String(); @@ -2090,12 +2054,8 @@ bool Main::iteration() { AudioServer::get_singleton()->update(); - if (script_debugger) { - if (script_debugger->is_profiling()) { - script_debugger->profiling_set_frame_times(USEC_TO_SEC(frame_time), USEC_TO_SEC(idle_process_ticks), USEC_TO_SEC(physics_process_ticks), frame_slice); - } - script_debugger->idle_poll(); - } + if (EngineDebugger::is_active()) + EngineDebugger::get_singleton()->iteration(frame_time, idle_process_ticks, physics_process_ticks, frame_slice); frames++; Engine::get_singleton()->_idle_frames++; @@ -2173,10 +2133,7 @@ void Main::cleanup() { ERR_FAIL_COND(!_start_success); - if (script_debugger) { - // Flush any remaining messages - script_debugger->idle_poll(); - } + EngineDebugger::deinitialize(); ResourceLoader::remove_custom_loaders(); ResourceSaver::remove_custom_savers(); @@ -2184,14 +2141,6 @@ void Main::cleanup() { message_queue->flush(); memdelete(message_queue); - if (script_debugger) { - if (use_debug_profiler) { - script_debugger->profiling_end(); - } - - memdelete(script_debugger); - } - OS::get_singleton()->delete_main_loop(); OS::get_singleton()->_cmdline.clear(); diff --git a/modules/basis_universal/SCsub b/modules/basis_universal/SCsub index d7342358d7..63324e920b 100644 --- a/modules/basis_universal/SCsub +++ b/modules/basis_universal/SCsub @@ -22,7 +22,6 @@ tool_sources = [ "basisu_resample_filters.cpp", "basisu_resampler.cpp", "basisu_ssim.cpp", - "basisu_tool.cpp", "lodepng.cpp", ] tool_sources = [thirdparty_dir + file for file in tool_sources] diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp index e9ca1d3e5b..4e39cce4a5 100644 --- a/modules/csg/csg.cpp +++ b/modules/csg/csg.cpp @@ -88,7 +88,7 @@ static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3 Vector3 edge2 = p_vertices[2] - p_vertices[0]; Vector3 h = p_dir.cross(edge2); real_t a = edge1.dot(h); - // Check if ray is parrallel to triangle. + // Check if ray is parallel to triangle. if (Math::is_zero_approx(a)) return false; real_t f = 1.0 / a; @@ -818,7 +818,7 @@ void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vert int axis = 0; if (Math::abs(new_point.x - first_point.x) < Math::abs(new_point.y - first_point.y)) axis = 1; - // Add it to the beginnig or the end appropriately. + // Add it to the beginning or the end appropriately. if (new_point[axis] < first_point[axis]) r_vertex_indices.insert(0, p_new_vertex_index); else @@ -868,7 +868,7 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ inner_idx = p_segment_indices[segments + segments / 2 - sorted_idx]; } - // Find the mergable faces. + // Find the mergeable faces. Vector<int> merge_faces_idx; Vector<Face2D> merge_faces; Vector<int> merge_faces_inner_vertex_idx; diff --git a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml index 456bf649d2..860da32a22 100644 --- a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml +++ b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml @@ -134,7 +134,7 @@ The compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all. </member> <member name="dtls_verify" type="bool" setter="set_dtls_verify_enabled" getter="is_dtls_verify_enabled" default="true"> - Enable or disable certiticate verification when [member use_dtls] [code]true[/code]. + Enable or disable certificate verification when [member use_dtls] [code]true[/code]. </member> <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> <member name="server_relay" type="bool" setter="set_server_relay_enabled" getter="is_server_relay_enabled" default="true"> diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index fe1f63f6da..b7cbedc51a 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -194,7 +194,7 @@ ScriptInstance *PluginScript::instance_create(Object *p_this) { if (!ClassDB::is_parent_class(p_this->get_class_name(), base_type)) { String msg = "Script inherits from native type '" + String(base_type) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"; // TODO: implement PluginscriptLanguage::debug_break_parse - // if (ScriptDebugger::get_singleton()) { + // if (EngineDebugger::is_active()) { // _language->debug_break_parse(get_path(), 0, msg); // } ERR_FAIL_V_MSG(NULL, msg); diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp index 4db10cda78..a1f6ddfedc 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/gdnavigation/gd_navigation_server.cpp @@ -41,7 +41,7 @@ */ /// Creates a struct for each function and a function that once called creates -/// an instance of that struct with the submited parameters. +/// an instance of that struct with the submitted parameters. /// Then, that struct is stored in an array; the `sync` function consume that array. #define COMMAND_1(F_NAME, T_0, D_0) \ diff --git a/modules/gdnavigation/nav_map.cpp b/modules/gdnavigation/nav_map.cpp index 00a1901c48..338e49eb9f 100644 --- a/modules/gdnavigation/nav_map.cpp +++ b/modules/gdnavigation/nav_map.cpp @@ -691,7 +691,7 @@ void NavMap::sync() { const float ecm_squared(edge_connection_margin * edge_connection_margin); #define LEN_TOLLERANCE 0.1 #define DIR_TOLLERANCE 0.9 - // In front of tollerance + // In front of tolerance #define IFO_TOLLERANCE 0.5 // Find the compatible near edges. @@ -715,7 +715,7 @@ void NavMap::sync() { Vector3 rel_centers = other_edge.edge_center - edge.edge_center; if (ecm_squared > rel_centers.length_squared() // Are enough closer? && ABS(edge.edge_len_squared - other_edge.edge_len_squared) < LEN_TOLLERANCE // Are the same length? - && ABS(edge.edge_dir.dot(other_edge.edge_dir)) > DIR_TOLLERANCE // Are alligned? + && ABS(edge.edge_dir.dot(other_edge.edge_dir)) > DIR_TOLLERANCE // Are aligned? && ABS(rel_centers.normalized().dot(edge.edge_dir)) < IFO_TOLLERANCE // Are one in front the other? ) { // The edges can be connected diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index c641ce37c5..2882567b0a 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -315,7 +315,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) { if (top->native.is_valid()) { if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) { - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); } ERR_FAIL_V_MSG(NULL, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type '" + p_this->get_class() + "'" + "."); @@ -556,7 +556,7 @@ Error GDScript::reload(bool p_keep_state) { GDScriptParser parser; Error err = parser.parse(source, basedir, false, path); if (err) { - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), parser.get_error_line(), "Parser Error: " + parser.get_error()); } _err_print_error("GDScript::reload", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), parser.get_error_line(), ("Parse Error: " + parser.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT); @@ -571,7 +571,7 @@ Error GDScript::reload(bool p_keep_state) { if (err) { if (can_run) { - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), compiler.get_error_line(), "Parser Error: " + compiler.get_error()); } _err_print_error("GDScript::reload", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), compiler.get_error_line(), ("Compile Error: " + compiler.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT); @@ -583,9 +583,9 @@ Error GDScript::reload(bool p_keep_state) { #ifdef DEBUG_ENABLED for (const List<GDScriptWarning>::Element *E = parser.get_warnings().front(); E; E = E->next()) { const GDScriptWarning &warning = E->get(); - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { Vector<ScriptLanguage::StackInfo> si; - ScriptDebugger::get_singleton()->send_error("", get_path(), warning.line, warning.get_name(), warning.get_message(), ERR_HANDLER_WARNING, si); + EngineDebugger::get_script_debugger()->send_error("", get_path(), warning.line, warning.get_name(), warning.get_message(), ERR_HANDLER_WARNING, si); } } #endif @@ -597,52 +597,7 @@ Error GDScript::reload(bool p_keep_state) { _set_subclass_path(E->get(), path); } - // Copy the base rpc methods so we don't mask their IDs. - rpc_functions.clear(); - rpc_variables.clear(); - if (base.is_valid()) { - rpc_functions = base->rpc_functions; - rpc_variables = base->rpc_variables; - } - - GDScript *cscript = this; - Map<StringName, Ref<GDScript> >::Element *sub_E = subclasses.front(); - while (cscript) { - // RPC Methods - for (Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.front(); E; E = E->next()) { - if (E->get()->get_rpc_mode() != MultiplayerAPI::RPC_MODE_DISABLED) { - ScriptNetData nd; - nd.name = E->key(); - nd.mode = E->get()->get_rpc_mode(); - if (-1 == rpc_functions.find(nd)) { - rpc_functions.push_back(nd); - } - } - } - // RSet - for (Map<StringName, MemberInfo>::Element *E = cscript->member_indices.front(); E; E = E->next()) { - if (E->get().rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) { - ScriptNetData nd; - nd.name = E->key(); - nd.mode = E->get().rpc_mode; - if (-1 == rpc_variables.find(nd)) { - rpc_variables.push_back(nd); - } - } - } - - if (cscript != this) - sub_E = sub_E->next(); - - if (sub_E) - cscript = sub_E->get().ptr(); - else - cscript = NULL; - } - - // Sort so we are 100% that they are always the same. - rpc_functions.sort_custom<SortNetData>(); - rpc_variables.sort_custom<SortNetData>(); + _init_rpc_methods_properties(); return OK; } @@ -715,8 +670,8 @@ StringName GDScript::get_rset_property(const uint16_t p_rset_member_id) const { } MultiplayerAPI::RPCMode GDScript::get_rset_mode_by_id(const uint16_t p_rset_member_id) const { - ERR_FAIL_COND_V(p_rset_member_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED); - return rpc_functions[p_rset_member_id].mode; + ERR_FAIL_COND_V(p_rset_member_id >= rpc_variables.size(), MultiplayerAPI::RPC_MODE_DISABLED); + return rpc_variables[p_rset_member_id].mode; } MultiplayerAPI::RPCMode GDScript::get_rset_mode(const StringName &p_variable) const { @@ -881,6 +836,8 @@ Error GDScript::load_byte_code(const String &p_path) { _set_subclass_path(E->get(), path); } + _init_rpc_methods_properties(); + return OK; } @@ -1030,6 +987,55 @@ void GDScript::_save_orphaned_subclasses() { } } +void GDScript::_init_rpc_methods_properties() { + // Copy the base rpc methods so we don't mask their IDs. + rpc_functions.clear(); + rpc_variables.clear(); + if (base.is_valid()) { + rpc_functions = base->rpc_functions; + rpc_variables = base->rpc_variables; + } + + GDScript *cscript = this; + Map<StringName, Ref<GDScript> >::Element *sub_E = subclasses.front(); + while (cscript) { + // RPC Methods + for (Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.front(); E; E = E->next()) { + if (E->get()->get_rpc_mode() != MultiplayerAPI::RPC_MODE_DISABLED) { + ScriptNetData nd; + nd.name = E->key(); + nd.mode = E->get()->get_rpc_mode(); + if (-1 == rpc_functions.find(nd)) { + rpc_functions.push_back(nd); + } + } + } + // RSet + for (Map<StringName, MemberInfo>::Element *E = cscript->member_indices.front(); E; E = E->next()) { + if (E->get().rpc_mode != MultiplayerAPI::RPC_MODE_DISABLED) { + ScriptNetData nd; + nd.name = E->key(); + nd.mode = E->get().rpc_mode; + if (-1 == rpc_variables.find(nd)) { + rpc_variables.push_back(nd); + } + } + } + + if (cscript != this) + sub_E = sub_E->next(); + + if (sub_E) + cscript = sub_E->get().ptr(); + else + cscript = NULL; + } + + // Sort so we are 100% that they are always the same. + rpc_functions.sort_custom<SortNetData>(); + rpc_variables.sort_custom<SortNetData>(); +} + GDScript::~GDScript() { for (Map<StringName, GDScriptFunction *>::Element *E = member_functions.front(); E; E = E->next()) { memdelete(E->get()); @@ -2201,7 +2207,7 @@ GDScriptLanguage::GDScriptLanguage() { int dmcs = GLOBAL_DEF("debug/settings/gdscript/max_call_stack", 1024); ProjectSettings::get_singleton()->set_custom_property_info("debug/settings/gdscript/max_call_stack", PropertyInfo(Variant::INT, "debug/settings/gdscript/max_call_stack", PROPERTY_HINT_RANGE, "1024,4096,1,or_greater")); //minimum is 1024 - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { //debugging enabled! _debug_max_call_stack = dmcs; diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 3a90f0fc20..2b8158fe55 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -31,6 +31,8 @@ #ifndef GDSCRIPT_H #define GDSCRIPT_H +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" #include "core/script_language.h" @@ -134,6 +136,7 @@ class GDScript : public Script { bool _update_exports(); void _save_orphaned_subclasses(); + void _init_rpc_methods_properties(); protected: bool _get(const StringName &p_name, Variant &r_ret) const; @@ -393,13 +396,13 @@ public: if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now - if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) - ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() + 1); + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() + 1); if (_debug_call_stack_pos >= _debug_max_call_stack) { //stack overflow _debug_error = "Stack Overflow (Stack Size: " + itos(_debug_max_call_stack) + ")"; - ScriptDebugger::get_singleton()->debug(this); + EngineDebugger::get_script_debugger()->debug(this); return; } @@ -416,13 +419,13 @@ public: if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now - if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) - ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() - 1); + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() - 1); if (_debug_call_stack_pos == 0) { _debug_error = "Stack Underflow (Engine Bug)"; - ScriptDebugger::get_singleton()->debug(this); + EngineDebugger::get_script_debugger()->debug(this); return; } diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 4bd425f999..42efdeffbb 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1579,7 +1579,7 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser codegen.stack_max = 0; codegen.current_line = 0; codegen.call_max = 0; - codegen.debug_stack = ScriptDebugger::get_singleton() != NULL; + codegen.debug_stack = EngineDebugger::is_active(); Vector<StringName> argnames; int stack_level = 0; @@ -1765,7 +1765,7 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser gdfunc->_call_size = codegen.call_max; gdfunc->name = func_name; #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { String signature; //path if (p_script->get_path() != String()) diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 1bc1aae0d2..966a3db840 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -221,12 +221,12 @@ Script *GDScriptLanguage::create_script() const { bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const String &p_error) { //break because of parse error - if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { + if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = p_line; _debug_parse_err_file = p_file; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, false, true); + EngineDebugger::get_script_debugger()->debug(this, false, true); return true; } else { return false; @@ -235,13 +235,13 @@ bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { + if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = -1; _debug_parse_err_file = ""; _debug_error = p_error; bool is_error_breakpoint = p_error != "Breakpoint"; - ScriptDebugger::get_singleton()->debug(this, p_allow_continue, is_error_breakpoint); + EngineDebugger::get_script_debugger()->debug(this, p_allow_continue, is_error_breakpoint); return true; } else { return false; diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 79c550c81c..3f73654a1e 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -391,7 +391,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) + if (EngineDebugger::is_active()) GDScriptLanguage::get_singleton()->enter_function(p_instance, this, stack, &ip, &line); #define GD_ERR_BREAK(m_cond) \ @@ -1522,7 +1522,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE(OPCODE_BREAKPOINT) { #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->debug_break("Breakpoint Statement", true); } #endif @@ -1536,26 +1536,26 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a line = _code_ptr[ip + 1]; ip += 2; - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { // line bool do_break = false; - if (ScriptDebugger::get_singleton()->get_lines_left() > 0) { + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) { - if (ScriptDebugger::get_singleton()->get_depth() <= 0) - ScriptDebugger::get_singleton()->set_lines_left(ScriptDebugger::get_singleton()->get_lines_left() - 1); - if (ScriptDebugger::get_singleton()->get_lines_left() <= 0) + if (EngineDebugger::get_script_debugger()->get_depth() <= 0) + EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1); + if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) do_break = true; } - if (ScriptDebugger::get_singleton()->is_breakpoint(line, source)) + if (EngineDebugger::get_script_debugger()->is_breakpoint(line, source)) do_break = true; if (do_break) { GDScriptLanguage::get_singleton()->debug_break("Breakpoint", true); } - ScriptDebugger::get_singleton()->line_poll(); + EngineDebugger::get_singleton()->line_poll(); } } DISPATCH_OPCODE; @@ -1622,7 +1622,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a // When it's the last resume it will postpone the exit from stack, // so the debugger knows which function triggered the resume of the next function (if any) if (!p_state || yielded) { - if (ScriptDebugger::get_singleton()) + if (EngineDebugger::is_active()) GDScriptLanguage::get_singleton()->exit_function(); #endif @@ -1884,7 +1884,7 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) { } #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) + if (EngineDebugger::is_active()) GDScriptLanguage::get_singleton()->exit_function(); if (state.stack_size) { //free stack diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 0382944efd..b42fcba7d3 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -1517,7 +1517,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } } - //consecutively do unary opeators + //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { OperatorNode *op = alloc_node<OperatorNode>(); @@ -3102,18 +3102,18 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { Vector<Node *> args; Vector<double> constants; - bool constant = false; + bool constant = true; for (int i = 1; i < op->arguments.size(); i++) { args.push_back(op->arguments[i]); - if (constant && op->arguments[i]->type == Node::TYPE_CONSTANT) { + if (op->arguments[i]->type == Node::TYPE_CONSTANT) { ConstantNode *c = static_cast<ConstantNode *>(op->arguments[i]); if (c->value.get_type() == Variant::FLOAT || c->value.get_type() == Variant::INT) { constants.push_back(c->value); - constant = true; } } else { constant = false; + break; } } @@ -3809,6 +3809,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } StringName argname = tokenizer->get_token_identifier(); + for (int i = 0; i < arguments.size(); i++) { + if (arguments[i] == argname) { + _set_error("The argument name \"" + String(argname) + "\" is defined multiple times."); + return; + } + } arguments.push_back(argname); #ifdef DEBUG_ENABLED arguments_usage.push_back(0); @@ -5227,6 +5233,10 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } } break; + case GDScriptTokenizer::TK_CF_PASS: { + tokenizer->advance(); + } break; + default: { _set_error(String() + "Unexpected token: " + tokenizer->get_token_name(tokenizer->get_token()) + ":" + tokenizer->get_token_identifier()); diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 6809cbdff9..02ff6bcf13 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -33,6 +33,8 @@ #include <mono/metadata/threads.h> #include <stdint.h> +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" #include "core/io/json.h" #include "core/os/file_access.h" #include "core/os/mutex.h" @@ -1134,11 +1136,11 @@ void CSharpLanguage::thread_exit() { bool CSharpLanguage::debug_break_parse(const String &p_file, int p_line, const String &p_error) { // Not a parser error in our case, but it's still used for other type of errors - if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { + if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = p_line; _debug_parse_err_file = p_file; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, false, true); + EngineDebugger::get_script_debugger()->debug(this, false, true); return true; } else { return false; @@ -1147,11 +1149,11 @@ bool CSharpLanguage::debug_break_parse(const String &p_file, int p_line, const S bool CSharpLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { + if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = -1; _debug_parse_err_file = ""; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, p_allow_continue); + EngineDebugger::get_script_debugger()->debug(this, p_allow_continue); return true; } else { return false; @@ -2998,7 +3000,7 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { if (native) { String native_name = NATIVE_GDMONOCLASS_NAME(native); if (!ClassDB::is_parent_class(p_this->get_class_name(), native_name)) { - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { CSharpLanguage::get_singleton()->debug_break_parse(get_path(), 0, "Script inherits from native type '" + native_name + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); } ERR_FAIL_V_MSG(NULL, "Script inherits from native type '" + native_name + diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs index 76cb249acf..9afd9adeb1 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs @@ -1,6 +1,8 @@ using GodotTools.Core; using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Text.RegularExpressions; namespace GodotTools.ProjectEditor { @@ -118,5 +120,40 @@ EndProject"; const string ProjectPlatformsConfig = @" {{{0}}}.{1}|Any CPU.ActiveCfg = {1}|Any CPU {{{0}}}.{1}|Any CPU.Build.0 = {1}|Any CPU"; + + public static void MigrateFromOldConfigNames(string slnPath) + { + if (!File.Exists(slnPath)) + return; + + var input = File.ReadAllText(slnPath); + + if (!Regex.IsMatch(input, Regex.Escape("Tools|Any CPU"))) + return; + + // This method renames old configurations in solutions to the new ones. + // + // This is the order configs appear in the solution and what we want to rename them to: + // Debug|Any CPU = Debug|Any CPU -> ExportDebug|Any CPU = ExportDebug|Any CPU + // Tools|Any CPU = Tools|Any CPU -> Debug|Any CPU = Debug|Any CPU + // + // But we want to move Tools (now Debug) to the top, so it's easier to rename like this: + // Debug|Any CPU = Debug|Any CPU -> Debug|Any CPU = Debug|Any CPU + // Release|Any CPU = Release|Any CPU -> ExportDebug|Any CPU = ExportDebug|Any CPU + // Tools|Any CPU = Tools|Any CPU -> ExportRelease|Any CPU = ExportRelease|Any CPU + + var dict = new Dictionary<string, string> + { + {"Debug|Any CPU", "Debug|Any CPU"}, + {"Release|Any CPU", "ExportDebug|Any CPU"}, + {"Tools|Any CPU", "ExportRelease|Any CPU"} + }; + + var regex = new Regex(string.Join("|",dict.Keys.Select(Regex.Escape))); + var result = regex.Replace(input,m => dict[m.Value]); + + if (result != input) + File.WriteAllText(slnPath, result); + } } } diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs index 28b7832f90..cbe3afaedd 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectGenerator.cs @@ -17,30 +17,30 @@ namespace GodotTools.ProjectEditor string path = Path.Combine(dir, name + ".csproj"); ProjectPropertyGroupElement mainGroup; - var root = CreateLibraryProject(name, "Tools", out mainGroup); + var root = CreateLibraryProject(name, "Debug", out mainGroup); mainGroup.SetProperty("OutputPath", Path.Combine(".mono", "temp", "bin", "$(Configuration)")); mainGroup.SetProperty("BaseIntermediateOutputPath", Path.Combine(".mono", "temp", "obj")); mainGroup.SetProperty("IntermediateOutputPath", Path.Combine("$(BaseIntermediateOutputPath)", "$(Configuration)")); - mainGroup.SetProperty("ApiConfiguration", "Debug").Condition = " '$(Configuration)' != 'Release' "; - mainGroup.SetProperty("ApiConfiguration", "Release").Condition = " '$(Configuration)' == 'Release' "; - - var toolsGroup = root.AddPropertyGroup(); - toolsGroup.Condition = " '$(Configuration)|$(Platform)' == 'Tools|AnyCPU' "; - toolsGroup.AddProperty("DebugSymbols", "true"); - toolsGroup.AddProperty("DebugType", "portable"); - toolsGroup.AddProperty("Optimize", "false"); - toolsGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;TOOLS;"); - toolsGroup.AddProperty("ErrorReport", "prompt"); - toolsGroup.AddProperty("WarningLevel", "4"); - toolsGroup.AddProperty("ConsolePause", "false"); + mainGroup.SetProperty("ApiConfiguration", "Debug").Condition = " '$(Configuration)' != 'ExportRelease' "; + mainGroup.SetProperty("ApiConfiguration", "Release").Condition = " '$(Configuration)' == 'ExportRelease' "; + + var debugGroup = root.AddPropertyGroup(); + debugGroup.Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "; + debugGroup.AddProperty("DebugSymbols", "true"); + debugGroup.AddProperty("DebugType", "portable"); + debugGroup.AddProperty("Optimize", "false"); + debugGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;TOOLS;"); + debugGroup.AddProperty("ErrorReport", "prompt"); + debugGroup.AddProperty("WarningLevel", "4"); + debugGroup.AddProperty("ConsolePause", "false"); var coreApiRef = root.AddItem("Reference", CoreApiProjectName); coreApiRef.AddMetadata("HintPath", Path.Combine("$(ProjectDir)", ".mono", "assemblies", "$(ApiConfiguration)", CoreApiProjectName + ".dll")); coreApiRef.AddMetadata("Private", "False"); var editorApiRef = root.AddItem("Reference", EditorApiProjectName); - editorApiRef.Condition = " '$(Configuration)' == 'Tools' "; + editorApiRef.Condition = " '$(Configuration)' == 'Debug' "; editorApiRef.AddMetadata("HintPath", Path.Combine("$(ProjectDir)", ".mono", "assemblies", "$(ApiConfiguration)", EditorApiProjectName + ".dll")); editorApiRef.AddMetadata("Private", "False"); @@ -103,24 +103,24 @@ namespace GodotTools.ProjectEditor mainGroup.AddProperty("TargetFrameworkVersion", "v4.7"); mainGroup.AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString()); - var debugGroup = root.AddPropertyGroup(); - debugGroup.Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "; - debugGroup.AddProperty("DebugSymbols", "true"); - debugGroup.AddProperty("DebugType", "portable"); - debugGroup.AddProperty("Optimize", "false"); - debugGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;"); - debugGroup.AddProperty("ErrorReport", "prompt"); - debugGroup.AddProperty("WarningLevel", "4"); - debugGroup.AddProperty("ConsolePause", "false"); - - var releaseGroup = root.AddPropertyGroup(); - releaseGroup.Condition = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "; - releaseGroup.AddProperty("DebugType", "portable"); - releaseGroup.AddProperty("Optimize", "true"); - releaseGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;"); - releaseGroup.AddProperty("ErrorReport", "prompt"); - releaseGroup.AddProperty("WarningLevel", "4"); - releaseGroup.AddProperty("ConsolePause", "false"); + var exportDebugGroup = root.AddPropertyGroup(); + exportDebugGroup.Condition = " '$(Configuration)|$(Platform)' == 'ExportDebug|AnyCPU' "; + exportDebugGroup.AddProperty("DebugSymbols", "true"); + exportDebugGroup.AddProperty("DebugType", "portable"); + exportDebugGroup.AddProperty("Optimize", "false"); + exportDebugGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;DEBUG;"); + exportDebugGroup.AddProperty("ErrorReport", "prompt"); + exportDebugGroup.AddProperty("WarningLevel", "4"); + exportDebugGroup.AddProperty("ConsolePause", "false"); + + var exportReleaseGroup = root.AddPropertyGroup(); + exportReleaseGroup.Condition = " '$(Configuration)|$(Platform)' == 'ExportRelease|AnyCPU' "; + exportReleaseGroup.AddProperty("DebugType", "portable"); + exportReleaseGroup.AddProperty("Optimize", "true"); + exportReleaseGroup.AddProperty("DefineConstants", "$(GodotDefineConstants);GODOT;"); + exportReleaseGroup.AddProperty("ErrorReport", "prompt"); + exportReleaseGroup.AddProperty("WarningLevel", "4"); + exportReleaseGroup.AddProperty("ConsolePause", "false"); // References var referenceGroup = root.AddItemGroup(); diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs index 233aab45b3..af36f125f5 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Reflection; using DotNet.Globbing; using Microsoft.Build.Construction; @@ -44,6 +45,7 @@ namespace GodotTools.ProjectEditor globOptions.Evaluation.CaseInsensitive = false; var root = ProjectRootElement.Open(projectPath); + Debug.Assert(root != null); foreach (var itemGroup in root.ItemGroups) { @@ -85,35 +87,35 @@ namespace GodotTools.ProjectEditor void AddPropertyIfNotPresent(string name, string condition, string value) { if (root.PropertyGroups - .Any(g => (g.Condition == string.Empty || g.Condition == condition) && + .Any(g => (g.Condition == string.Empty || g.Condition.Trim() == condition) && g.Properties .Any(p => p.Name == name && p.Value == value && - (p.Condition == condition || g.Condition == condition)))) + (p.Condition.Trim() == condition || g.Condition.Trim() == condition)))) { return; } - root.AddProperty(name, value).Condition = condition; + root.AddProperty(name, value).Condition = " " + condition + " "; dirty = true; } AddPropertyIfNotPresent(name: "ApiConfiguration", - condition: " '$(Configuration)' != 'Release' ", + condition: "'$(Configuration)' != 'ExportRelease'", value: "Debug"); AddPropertyIfNotPresent(name: "ApiConfiguration", - condition: " '$(Configuration)' == 'Release' ", + condition: "'$(Configuration)' == 'ExportRelease'", value: "Release"); void SetReferenceHintPath(string referenceName, string condition, string hintPath) { foreach (var itemGroup in root.ItemGroups.Where(g => - g.Condition == string.Empty || g.Condition == condition)) + g.Condition.Trim() == string.Empty || g.Condition.Trim() == condition)) { var references = itemGroup.Items.Where(item => item.ItemType == "Reference" && item.Include == referenceName && - (item.Condition == condition || itemGroup.Condition == condition)); + (item.Condition.Trim() == condition || itemGroup.Condition.Trim() == condition)); var referencesWithHintPath = references.Where(reference => reference.Metadata.Any(m => m.Name == "HintPath")); @@ -152,7 +154,7 @@ namespace GodotTools.ProjectEditor } // Found no Reference item at all. Add it. - root.AddItem("Reference", referenceName).Condition = condition; + root.AddItem("Reference", referenceName).Condition = " " + condition + " "; dirty = true; } @@ -160,7 +162,7 @@ namespace GodotTools.ProjectEditor const string editorProjectName = "GodotSharpEditor"; const string coreCondition = ""; - const string editorCondition = " '$(Configuration)' == 'Tools' "; + const string editorCondition = "'$(Configuration)' == 'Debug'"; var coreHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{coreProjectName}.dll"; var editorHintPath = $"$(ProjectDir)/.mono/assemblies/$(ApiConfiguration)/{editorProjectName}.dll"; @@ -171,5 +173,104 @@ namespace GodotTools.ProjectEditor if (dirty) root.Save(); } + + public static void MigrateFromOldConfigNames(string projectPath) + { + var root = ProjectRootElement.Open(projectPath); + Debug.Assert(root != null); + + bool dirty = false; + + bool hasGodotProjectGeneratorVersion = false; + bool foundOldConfiguration = false; + + foreach (var propertyGroup in root.PropertyGroups.Where(g => g.Condition == string.Empty)) + { + if (!hasGodotProjectGeneratorVersion && propertyGroup.Properties.Any(p => p.Name == "GodotProjectGeneratorVersion")) + hasGodotProjectGeneratorVersion = true; + + foreach (var configItem in propertyGroup.Properties + .Where(p => p.Condition.Trim() == "'$(Configuration)' == ''" && p.Value == "Tools")) + { + configItem.Value = "Debug"; + foundOldConfiguration = true; + dirty = true; + } + } + + if (!hasGodotProjectGeneratorVersion) + { + root.PropertyGroups.First(g => g.Condition == string.Empty)? + .AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString()); + dirty = true; + } + + if (!foundOldConfiguration) + { + var toolsConditions = new[] + { + "'$(Configuration)|$(Platform)' == 'Tools|AnyCPU'", + "'$(Configuration)|$(Platform)' != 'Tools|AnyCPU'", + "'$(Configuration)' == 'Tools'", + "'$(Configuration)' != 'Tools'" + }; + + foundOldConfiguration = root.PropertyGroups + .Any(g => toolsConditions.Any(c => c == g.Condition.Trim())); + } + + if (foundOldConfiguration) + { + void MigrateConfigurationConditions(string oldConfiguration, string newConfiguration) + { + void MigrateConditions(string oldCondition, string newCondition) + { + foreach (var propertyGroup in root.PropertyGroups.Where(g => g.Condition.Trim() == oldCondition)) + { + propertyGroup.Condition = " " + newCondition + " "; + dirty = true; + } + + foreach (var propertyGroup in root.PropertyGroups) + { + foreach (var prop in propertyGroup.Properties.Where(p => p.Condition.Trim() == oldCondition)) + { + prop.Condition = " " + newCondition + " "; + dirty = true; + } + } + + foreach (var itemGroup in root.ItemGroups.Where(g => g.Condition.Trim() == oldCondition)) + { + itemGroup.Condition = " " + newCondition + " "; + dirty = true; + } + + foreach (var itemGroup in root.ItemGroups) + { + foreach (var item in itemGroup.Items.Where(item => item.Condition.Trim() == oldCondition)) + { + item.Condition = " " + newCondition + " "; + dirty = true; + } + } + } + + foreach (var op in new[] {"==", "!="}) + { + MigrateConditions($"'$(Configuration)|$(Platform)' {op} '{oldConfiguration}|AnyCPU'", $"'$(Configuration)|$(Platform)' {op} '{newConfiguration}|AnyCPU'"); + MigrateConditions($"'$(Configuration)' {op} '{oldConfiguration}'", $"'$(Configuration)' {op} '{newConfiguration}'"); + } + } + + MigrateConfigurationConditions("Debug", "ExportDebug"); + MigrateConfigurationConditions("Release", "ExportRelease"); + MigrateConfigurationConditions("Tools", "Debug"); // Must be last + } + + + if (dirty) + root.Save(); + } } } diff --git a/modules/mono/editor/GodotTools/GodotTools/BottomPanel.cs b/modules/mono/editor/GodotTools/GodotTools/BottomPanel.cs index bd7eb59913..2971236482 100644 --- a/modules/mono/editor/GodotTools/GodotTools/BottomPanel.cs +++ b/modules/mono/editor/GodotTools/GodotTools/BottomPanel.cs @@ -166,7 +166,7 @@ namespace GodotTools Internal.GodotIs32Bits() ? "32" : "64" }; - bool buildSuccess = BuildManager.BuildProjectBlocking("Tools", godotDefines); + bool buildSuccess = BuildManager.BuildProjectBlocking("Debug", godotDefines); if (!buildSuccess) return; diff --git a/modules/mono/editor/GodotTools/GodotTools/BuildManager.cs b/modules/mono/editor/GodotTools/GodotTools/BuildManager.cs index 69a8c9cf4a..94214cbb8f 100644 --- a/modules/mono/editor/GodotTools/GodotTools/BuildManager.cs +++ b/modules/mono/editor/GodotTools/GodotTools/BuildManager.cs @@ -166,7 +166,7 @@ namespace GodotTools // Make sure the API assemblies are up to date before building the project. // We may not have had the chance to update the release API assemblies, and the debug ones // may have been deleted by the user at some point after they were loaded by the Godot editor. - string apiAssembliesUpdateError = Internal.UpdateApiAssembliesFromPrebuilt(config == "Release" ? "Release" : "Debug"); + string apiAssembliesUpdateError = Internal.UpdateApiAssembliesFromPrebuilt(config == "ExportRelease" ? "Release" : "Debug"); if (!string.IsNullOrEmpty(apiAssembliesUpdateError)) { @@ -242,7 +242,7 @@ namespace GodotTools Internal.GodotIs32Bits() ? "32" : "64" }; - return BuildProjectBlocking("Tools", godotDefines); + return BuildProjectBlocking("Debug", godotDefines); } public static void Initialize() @@ -256,7 +256,7 @@ namespace GodotTools : BuildTool.MsBuildVs; EditorDef("mono/builds/build_tool", msbuild); - + editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary { ["type"] = Godot.Variant.Type.Int, diff --git a/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs b/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs index 9abfda4538..421729cc11 100644 --- a/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs +++ b/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs @@ -32,18 +32,6 @@ namespace GodotTools ProjectUtils.AddItemToProjectChecked(projectPath, itemType, include); } - public static void FixApiHintPath(string projectPath) - { - try - { - ProjectUtils.FixApiHintPath(projectPath); - } - catch (Exception e) - { - GD.PushError(e.ToString()); - } - } - private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); private static ulong ConvertToTimestamp(this DateTime value) diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs index 3e2a8c22a9..05f84f547b 100644 --- a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs +++ b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs @@ -150,7 +150,7 @@ namespace GodotTools.Export string outputDir = new FileInfo(path).Directory?.FullName ?? throw new FileNotFoundException("Base directory not found"); - string buildConfig = isDebug ? "Debug" : "Release"; + string buildConfig = isDebug ? "ExportDebug" : "ExportRelease"; string scriptsMetadataPath = Path.Combine(GodotSharpDirs.ResMetadataDir, $"scripts_metadata.{(isDebug ? "debug" : "release")}"); CsProjOperations.GenerateScriptsMetadata(GodotSharpDirs.ProjectCsProjPath, scriptsMetadataPath); diff --git a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs index 147bc95bb8..796522b2f2 100644 --- a/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs +++ b/modules/mono/editor/GodotTools/GodotTools/GodotSharpEditor.cs @@ -61,7 +61,7 @@ namespace GodotTools { Guid = guid, PathRelativeToSolution = name + ".csproj", - Configs = new List<string> { "Debug", "Release", "Tools" } + Configs = new List<string> { "Debug", "ExportDebug", "ExportRelease" } }; solution.AddNewProject(name, projectInfo); @@ -401,8 +401,22 @@ namespace GodotTools if (File.Exists(GodotSharpDirs.ProjectSlnPath) && File.Exists(GodotSharpDirs.ProjectCsProjPath)) { - // Make sure the existing project has Api assembly references configured correctly - CsProjOperations.FixApiHintPath(GodotSharpDirs.ProjectCsProjPath); + try + { + // Migrate solution from old configuration names to: Debug, ExportDebug and ExportRelease + DotNetSolution.MigrateFromOldConfigNames(GodotSharpDirs.ProjectSlnPath); + // Migrate csproj from old configuration names to: Debug, ExportDebug and ExportRelease + ProjectUtils.MigrateFromOldConfigNames(GodotSharpDirs.ProjectCsProjPath); + + // Apply the other fixes after configurations are migrated + + // Make sure the existing project has Api assembly references configured correctly + ProjectUtils.FixApiHintPath(GodotSharpDirs.ProjectCsProjPath); + } + catch (Exception e) + { + GD.PushError(e.ToString()); + } } else { diff --git a/modules/mono/glue/GodotSharp/GodotSharp.sln b/modules/mono/glue/GodotSharp/GodotSharp.sln index a496e36da3..4896d0a07d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp.sln +++ b/modules/mono/glue/GodotSharp/GodotSharp.sln @@ -8,8 +8,6 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {AEBF0036-DA76-4341-B651-A3F2856AB2FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index 895393537f..eb4c263745 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -37,6 +37,7 @@ #include <mono/metadata/mono-gc.h> #include <mono/metadata/profiler.h> +#include "core/debugger/engine_debugger.h" #include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/os.h" @@ -1183,8 +1184,8 @@ void GDMono::unhandled_exception_hook(MonoObject *p_exc, void *) { #ifdef DEBUG_ENABLED GDMonoUtils::debug_send_unhandled_exception_error((MonoException *)p_exc); - if (ScriptDebugger::get_singleton()) - ScriptDebugger::get_singleton()->idle_poll(); + if (EngineDebugger::is_active()) + EngineDebugger::get_singleton()->poll_events(false); #endif exit(mono_environment_exitcode_get()); diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp index 74ffa90cb3..b179b484f3 100644 --- a/modules/mono/mono_gd/gd_mono_internals.cpp +++ b/modules/mono/mono_gd/gd_mono_internals.cpp @@ -38,6 +38,9 @@ #include "gd_mono_marshal.h" #include "gd_mono_utils.h" +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" + #include <mono/metadata/exception.h> namespace GDMonoInternals { @@ -120,8 +123,8 @@ void unhandled_exception(MonoException *p_exc) { } else { #ifdef DEBUG_ENABLED GDMonoUtils::debug_send_unhandled_exception_error((MonoException *)p_exc); - if (ScriptDebugger::get_singleton()) - ScriptDebugger::get_singleton()->idle_poll(); + if (EngineDebugger::is_active()) + EngineDebugger::get_singleton()->poll_events(false); #endif } } diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp index 41f49d8ac9..bc290f3a7f 100644 --- a/modules/mono/mono_gd/gd_mono_utils.cpp +++ b/modules/mono/mono_gd/gd_mono_utils.cpp @@ -32,6 +32,8 @@ #include <mono/metadata/exception.h> +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" #include "core/os/dir_access.h" #include "core/os/mutex.h" #include "core/os/os.h" @@ -39,7 +41,7 @@ #include "core/reference.h" #ifdef TOOLS_ENABLED -#include "editor/debugger/script_editor_debugger.h" +#include "editor/debugger/editor_debugger_node.h" #endif #include "../csharp_script.h" @@ -351,7 +353,7 @@ void debug_print_unhandled_exception(MonoException *p_exc) { void debug_send_unhandled_exception_error(MonoException *p_exc) { #ifdef DEBUG_ENABLED - if (!ScriptDebugger::get_singleton()) { + if (!EngineDebugger::is_active()) { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { ERR_PRINT(GDMonoUtils::get_exception_name_and_message(p_exc)); @@ -410,7 +412,7 @@ void debug_send_unhandled_exception_error(MonoException *p_exc) { int line = si.size() ? si[0].line : __LINE__; String error_msg = "Unhandled exception"; - ScriptDebugger::get_singleton()->send_error(func, file, line, error_msg, exc_msg, ERR_HANDLER_ERROR, si); + EngineDebugger::get_script_debugger()->send_error(func, file, line, error_msg, exc_msg, ERR_HANDLER_ERROR, si); #endif } diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 471f43cadd..1f3ba2f20b 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -1148,8 +1148,8 @@ StringName VisualScript::get_rset_property(const uint16_t p_rset_property_id) co } MultiplayerAPI::RPCMode VisualScript::get_rset_mode_by_id(const uint16_t p_rset_variable_id) const { - ERR_FAIL_COND_V(p_rset_variable_id >= rpc_functions.size(), MultiplayerAPI::RPC_MODE_DISABLED); - return rpc_functions[p_rset_variable_id].mode; + ERR_FAIL_COND_V(p_rset_variable_id >= rpc_variables.size(), MultiplayerAPI::RPC_MODE_DISABLED); + return rpc_variables[p_rset_variable_id].mode; } MultiplayerAPI::RPCMode VisualScript::get_rset_mode(const StringName &p_variable) const { @@ -1629,7 +1629,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p int flow_stack_pos = p_flow_stack_pos; #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { VisualScriptLanguage::singleton->enter_function(this, &p_method, variant_stack, &working_mem, ¤t_node_id); } #endif @@ -1766,7 +1766,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p #ifdef DEBUG_ENABLED //will re-enter later, so exiting - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { VisualScriptLanguage::singleton->exit_function(); } #endif @@ -1776,26 +1776,26 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { // line bool do_break = false; - if (ScriptDebugger::get_singleton()->get_lines_left() > 0) { + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) { - if (ScriptDebugger::get_singleton()->get_depth() <= 0) - ScriptDebugger::get_singleton()->set_lines_left(ScriptDebugger::get_singleton()->get_lines_left() - 1); - if (ScriptDebugger::get_singleton()->get_lines_left() <= 0) + if (EngineDebugger::get_script_debugger()->get_depth() <= 0) + EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1); + if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) do_break = true; } - if (ScriptDebugger::get_singleton()->is_breakpoint(current_node_id, source)) + if (EngineDebugger::get_script_debugger()->is_breakpoint(current_node_id, source)) do_break = true; if (do_break) { VisualScriptLanguage::singleton->debug_break("Breakpoint", true); } - ScriptDebugger::get_singleton()->line_poll(); + EngineDebugger::get_singleton()->line_poll(); } #endif int output = ret & VisualScriptNodeInstance::STEP_MASK; @@ -1983,7 +1983,7 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { VisualScriptLanguage::singleton->exit_function(); } #endif @@ -2593,12 +2593,12 @@ void VisualScriptLanguage::add_global_constant(const StringName &p_variable, con bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, const String &p_error) { //break because of parse error - if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { + if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_node = p_node; _debug_parse_err_file = p_file; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, false, true); + EngineDebugger::get_script_debugger()->debug(this, false, true); return true; } else { return false; @@ -2607,12 +2607,12 @@ bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, c bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { + if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_node = -1; _debug_parse_err_file = ""; _debug_error = p_error; - ScriptDebugger::get_singleton()->debug(this, p_allow_continue, true); + EngineDebugger::get_script_debugger()->debug(this, p_allow_continue, true); return true; } else { return false; @@ -2837,7 +2837,7 @@ VisualScriptLanguage::VisualScriptLanguage() { int dmcs = GLOBAL_DEF("debug/settings/visual_script/max_call_stack", 1024); ProjectSettings::get_singleton()->set_custom_property_info("debug/settings/visual_script/max_call_stack", PropertyInfo(Variant::INT, "debug/settings/visual_script/max_call_stack", PROPERTY_HINT_RANGE, "1024,4096,1,or_greater")); //minimum is 1024 - if (ScriptDebugger::get_singleton()) { + if (EngineDebugger::is_active()) { //debugging enabled! _debug_max_call_stack = dmcs; _call_stack = memnew_arr(CallLevel, _debug_max_call_stack + 1); diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index 0a6daba64f..d1005c025c 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -31,6 +31,8 @@ #ifndef VISUAL_SCRIPT_H #define VISUAL_SCRIPT_H +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" #include "core/os/thread.h" #include "core/script_language.h" @@ -540,13 +542,13 @@ public: if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now - if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) - ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() + 1); + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() + 1); if (_debug_call_stack_pos >= _debug_max_call_stack) { //stack overflow _debug_error = "Stack Overflow (Stack Size: " + itos(_debug_max_call_stack) + ")"; - ScriptDebugger::get_singleton()->debug(this); + EngineDebugger::get_script_debugger()->debug(this); return; } @@ -563,13 +565,13 @@ public: if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now - if (ScriptDebugger::get_singleton()->get_lines_left() > 0 && ScriptDebugger::get_singleton()->get_depth() >= 0) - ScriptDebugger::get_singleton()->set_depth(ScriptDebugger::get_singleton()->get_depth() - 1); + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() - 1); if (_debug_call_stack_pos == 0) { _debug_error = "Stack Underflow (Engine Bug)"; - ScriptDebugger::get_singleton()->debug(this); + EngineDebugger::get_script_debugger()->debug(this); return; } diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 23d1c8ccc0..c52315a477 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -1141,7 +1141,7 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } } - //consecutively do unary opeators + //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { OperatorNode *op = alloc_node<OperatorNode>(); diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp index f396a1c812..9472daa620 100644 --- a/modules/websocket/emws_peer.cpp +++ b/modules/websocket/emws_peer.cpp @@ -90,12 +90,11 @@ Error EMWSPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { if (_in_buffer.packets_left() == 0) return ERR_UNAVAILABLE; - uint8_t *rw = _packet_buffer.ptrw(); int read = 0; - Error err = _in_buffer.read_packet(rw.ptr(), _packet_buffer.size(), &_is_string, read); + Error err = _in_buffer.read_packet(_packet_buffer.ptrw(), _packet_buffer.size(), &_is_string, read); ERR_FAIL_COND_V(err != OK, err); - *r_buffer = rw.ptr(); + *r_buffer = _packet_buffer.ptr(); r_buffer_size = read; return OK; diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub index 85a633442e..d3cd8f76b7 100644 --- a/platform/javascript/SCsub +++ b/platform/javascript/SCsub @@ -10,8 +10,11 @@ javascript_files = [ 'os_javascript.cpp', ] -build = env.add_program(['#bin/godot${PROGSUFFIX}.js', '#bin/godot${PROGSUFFIX}.wasm'], javascript_files); -js, wasm = build +build_targets = ['#bin/godot${PROGSUFFIX}.js', '#bin/godot${PROGSUFFIX}.wasm'] +if env['threads_enabled']: + build_targets.append('#bin/godot${PROGSUFFIX}.worker.js') + +build = env.add_program(build_targets, javascript_files) js_libraries = [ 'http_request.js', @@ -27,18 +30,38 @@ for module in js_modules: env.Append(LINKFLAGS=['--pre-js', env.File(module).path]) env.Depends(build, js_modules) -wrapper_start = env.File('pre.js') -wrapper_end = env.File('engine.js') -js_wrapped = env.Textfile('#bin/godot', [wrapper_start, js, wrapper_end], TEXTFILESUFFIX='${PROGSUFFIX}.wrapped.js') +engine = [ + 'engine/preloader.js', + 'engine/loader.js', + 'engine/utils.js', + 'engine/engine.js', +] +externs = [ + env.File('#platform/javascript/engine/externs.js') +] +js_engine = env.CreateEngineFile('#bin/godot${PROGSUFFIX}.engine.js', engine, externs) +env.Depends(js_engine, externs) + +wrap_list = [ + build[0], + js_engine, +] +js_wrapped = env.Textfile('#bin/godot', [env.File(f) for f in wrap_list], TEXTFILESUFFIX='${PROGSUFFIX}.wrapped.js') zip_dir = env.Dir('#bin/.javascript_zip') -zip_files = env.InstallAs([ +out_files = [ zip_dir.File('godot.js'), zip_dir.File('godot.wasm'), zip_dir.File('godot.html') -], [ +] +in_files = [ js_wrapped, - wasm, + build[1], '#misc/dist/html/full-size.html' -]) +] +if env['threads_enabled']: + in_files.append(build[2]) + out_files.append(zip_dir.File('godot.worker.js')) + +zip_files = env.InstallAs(out_files, in_files) env.Zip('#bin/godot', zip_files, ZIPROOT=zip_dir, ZIPSUFFIX='${PROGSUFFIX}${ZIPSUFFIX}', ZIPCOMSTR='Archving $SOURCES as $TARGET') diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp index f1bc7c4382..d63c6a40a5 100644 --- a/platform/javascript/audio_driver_javascript.cpp +++ b/platform/javascript/audio_driver_javascript.cpp @@ -69,31 +69,37 @@ void AudioDriverJavaScript::process_capture(float sample) { Error AudioDriverJavaScript::init() { /* clang-format off */ - EM_ASM({ - _audioDriver_audioContext = new (window.AudioContext || window.webkitAudioContext); - _audioDriver_audioInput = null; - _audioDriver_inputStream = null; - _audioDriver_scriptNode = null; + _driver_id = EM_ASM_INT({ + return Module.IDHandler.add({ + 'context': new (window.AudioContext || window.webkitAudioContext), + 'input': null, + 'stream': null, + 'script': null + }); }); /* clang-format on */ int channel_count = get_total_channels_by_speaker_mode(get_speaker_mode()); /* clang-format off */ buffer_length = EM_ASM_INT({ - var CHANNEL_COUNT = $0; + var ref = Module.IDHandler.get($0); + var ctx = ref['context']; + var CHANNEL_COUNT = $1; - var channelCount = _audioDriver_audioContext.destination.channelCount; + var channelCount = ctx.destination.channelCount; + var script = null; try { // Try letting the browser recommend a buffer length. - _audioDriver_scriptNode = _audioDriver_audioContext.createScriptProcessor(0, 2, channelCount); + script = ctx.createScriptProcessor(0, 2, channelCount); } catch (e) { // ...otherwise, default to 4096. - _audioDriver_scriptNode = _audioDriver_audioContext.createScriptProcessor(4096, 2, channelCount); + script = ctx.createScriptProcessor(4096, 2, channelCount); } - _audioDriver_scriptNode.connect(_audioDriver_audioContext.destination); + script.connect(ctx.destination); + ref['script'] = script; - return _audioDriver_scriptNode.bufferSize; - }, channel_count); + return script.bufferSize; + }, _driver_id, channel_count); /* clang-format on */ if (!buffer_length) { return FAILED; @@ -112,11 +118,12 @@ void AudioDriverJavaScript::start() { /* clang-format off */ EM_ASM({ - var INTERNAL_BUFFER_PTR = $0; + const ref = Module.IDHandler.get($0); + var INTERNAL_BUFFER_PTR = $1; var audioDriverMixFunction = cwrap('audio_driver_js_mix'); var audioDriverProcessCapture = cwrap('audio_driver_process_capture', null, ['number']); - _audioDriver_scriptNode.onaudioprocess = function(audioProcessingEvent) { + ref['script'].onaudioprocess = function(audioProcessingEvent) { audioDriverMixFunction(); var input = audioProcessingEvent.inputBuffer; @@ -133,7 +140,7 @@ void AudioDriverJavaScript::start() { } } - if (_audioDriver_audioInput) { + if (ref['input']) { var inputDataL = input.getChannelData(0); var inputDataR = input.getChannelData(1); for (var i = 0; i < inputDataL.length; i++) { @@ -142,34 +149,37 @@ void AudioDriverJavaScript::start() { } } }; - }, internal_buffer); + }, _driver_id, internal_buffer); /* clang-format on */ } void AudioDriverJavaScript::resume() { /* clang-format off */ EM_ASM({ - if (_audioDriver_audioContext.resume) - _audioDriver_audioContext.resume(); - }); + const ref = Module.IDHandler.get($0); + if (ref && ref['context'] && ref['context'].resume) + ref['context'].resume(); + }, _driver_id); /* clang-format on */ } int AudioDriverJavaScript::get_mix_rate() const { /* clang-format off */ - return EM_ASM_INT_V({ - return _audioDriver_audioContext.sampleRate; - }); + return EM_ASM_INT({ + const ref = Module.IDHandler.get($0); + return ref && ref['context'] ? ref['context'].sampleRate : 0; + }, _driver_id); /* clang-format on */ } AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const { /* clang-format off */ - return get_speaker_mode_by_total_channels(EM_ASM_INT_V({ - return _audioDriver_audioContext.destination.channelCount; - })); + return get_speaker_mode_by_total_channels(EM_ASM_INT({ + const ref = Module.IDHandler.get($0); + return ref && ref['context'] ? ref['context'].destination.channelCount : 0; + }, _driver_id)); /* clang-format on */ } @@ -184,16 +194,15 @@ void AudioDriverJavaScript::finish() { /* clang-format off */ EM_ASM({ - _audioDriver_audioContext = null; - _audioDriver_audioInput = null; - _audioDriver_scriptNode = null; - }); + Module.IDHandler.remove($0); + }, _driver_id); /* clang-format on */ if (internal_buffer) { memdelete_arr(internal_buffer); internal_buffer = NULL; } + _driver_id = 0; } Error AudioDriverJavaScript::capture_start() { @@ -203,9 +212,10 @@ Error AudioDriverJavaScript::capture_start() { /* clang-format off */ EM_ASM({ function gotMediaInput(stream) { - _audioDriver_inputStream = stream; - _audioDriver_audioInput = _audioDriver_audioContext.createMediaStreamSource(stream); - _audioDriver_audioInput.connect(_audioDriver_scriptNode); + var ref = Module.IDHandler.get($0); + ref['stream'] = stream; + ref['input'] = ref['context'].createMediaStreamSource(stream); + ref['input'].connect(ref['script']); } function gotMediaInputError(e) { @@ -219,7 +229,7 @@ Error AudioDriverJavaScript::capture_start() { navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia; navigator.getUserMedia({"audio": true}, gotMediaInput, gotMediaInputError); } - }); + }, _driver_id); /* clang-format on */ return OK; @@ -229,20 +239,21 @@ Error AudioDriverJavaScript::capture_stop() { /* clang-format off */ EM_ASM({ - if (_audioDriver_inputStream) { - const tracks = _audioDriver_inputStream.getTracks(); + var ref = Module.IDHandler.get($0); + if (ref['stream']) { + const tracks = ref['stream'].getTracks(); for (var i = 0; i < tracks.length; i++) { tracks[i].stop(); } - _audioDriver_inputStream = null; + ref['stream'] = null; } - if (_audioDriver_audioInput) { - _audioDriver_audioInput.disconnect(); - _audioDriver_audioInput = null; + if (ref['input']) { + ref['input'].disconnect(); + ref['input'] = null; } - }); + }, _driver_id); /* clang-format on */ input_buffer.clear(); @@ -252,7 +263,9 @@ Error AudioDriverJavaScript::capture_stop() { AudioDriverJavaScript::AudioDriverJavaScript() { + _driver_id = 0; internal_buffer = NULL; + buffer_length = 0; singleton = this; } diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h index 2bb97ba192..f6f2dacd4e 100644 --- a/platform/javascript/audio_driver_javascript.h +++ b/platform/javascript/audio_driver_javascript.h @@ -37,6 +37,7 @@ class AudioDriverJavaScript : public AudioDriver { float *internal_buffer; + int _driver_id; int buffer_length; public: diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 1766833364..fb02752aa7 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -1,5 +1,6 @@ import os +from emscripten_helpers import parse_config, run_closure_compiler, create_engine_file def is_active(): return True @@ -18,6 +19,8 @@ def get_opts(): return [ # eval() can be a security concern, so it can be disabled. BoolVariable('javascript_eval', 'Enable JavaScript eval interface', True), + BoolVariable('threads_enabled', 'Enable WebAssembly Threads support (limited browser support)', False), + BoolVariable('use_closure_compiler', 'Use closure compiler to minimize Javascript code', False), ] @@ -37,7 +40,7 @@ def configure(env): ## Build type - if env['target'] != 'debug': + if env['target'] == 'release': # Use -Os to prioritize optimizing for reduced file size. This is # particularly valuable for the web platform because it directly # decreases download time. @@ -46,38 +49,55 @@ def configure(env): # run-time performance. env.Append(CCFLAGS=['-Os']) env.Append(LINKFLAGS=['-Os']) - if env['target'] == 'release_debug': - env.Append(CPPDEFINES=['DEBUG_ENABLED']) - # Retain function names for backtraces at the cost of file size. - env.Append(LINKFLAGS=['--profiling-funcs']) - else: + elif env['target'] == 'release_debug': + env.Append(CCFLAGS=['-Os']) + env.Append(LINKFLAGS=['-Os']) + env.Append(CPPDEFINES=['DEBUG_ENABLED']) + # Retain function names for backtraces at the cost of file size. + env.Append(LINKFLAGS=['--profiling-funcs']) + else: # 'debug' env.Append(CPPDEFINES=['DEBUG_ENABLED']) env.Append(CCFLAGS=['-O1', '-g']) env.Append(LINKFLAGS=['-O1', '-g']) env.Append(LINKFLAGS=['-s', 'ASSERTIONS=1']) - ## Compiler configuration + if env['tools']: + if not env['threads_enabled']: + raise RuntimeError("Threads must be enabled to build the editor. Please add the 'threads_enabled=yes' option") + # Tools need more memory. Initial stack memory in bytes. See `src/settings.js` in emscripten repository (will be renamed to INITIAL_MEMORY). + env.Append(LINKFLAGS=['-s', 'TOTAL_MEMORY=33554432']) + else: + # Disable exceptions and rtti on non-tools (template) builds + # These flags help keep the file size down. + env.Append(CCFLAGS=['-fno-exceptions', '-fno-rtti']) + # Don't use dynamic_cast, necessary with no-rtti. + env.Append(CPPDEFINES=['NO_SAFE_CAST']) + ## Copy env variables. env['ENV'] = os.environ - em_config_file = os.getenv('EM_CONFIG') or os.path.expanduser('~/.emscripten') - if not os.path.exists(em_config_file): - raise RuntimeError("Emscripten configuration file '%s' does not exist" % em_config_file) - with open(em_config_file) as f: - em_config = {} - try: - # Emscripten configuration file is a Python file with simple assignments. - exec(f.read(), em_config) - except StandardError as e: - raise RuntimeError("Emscripten configuration file '%s' is invalid:\n%s" % (em_config_file, e)) - if 'BINARYEN_ROOT' in em_config and os.path.isdir(os.path.join(em_config.get('BINARYEN_ROOT'), 'emscripten')): - # New style, emscripten path as a subfolder of BINARYEN_ROOT - env.PrependENVPath('PATH', os.path.join(em_config.get('BINARYEN_ROOT'), 'emscripten')) - elif 'EMSCRIPTEN_ROOT' in em_config: - # Old style (but can be there as a result from previous activation, so do last) - env.PrependENVPath('PATH', em_config.get('EMSCRIPTEN_ROOT')) - else: - raise RuntimeError("'BINARYEN_ROOT' or 'EMSCRIPTEN_ROOT' missing in Emscripten configuration file '%s'" % em_config_file) + # LTO + if env['use_lto']: + env.Append(CCFLAGS=['-s', 'WASM_OBJECT_FILES=0']) + env.Append(LINKFLAGS=['-s', 'WASM_OBJECT_FILES=0']) + env.Append(LINKFLAGS=['--llvm-lto', '1']) + + # Closure compiler + if env['use_closure_compiler']: + # For emscripten support code. + env.Append(LINKFLAGS=['--closure', '1']) + # Register builder for our Engine files + jscc = env.Builder(generator=run_closure_compiler, suffix='.cc.js', src_suffix='.js') + env.Append(BUILDERS = {'BuildJS' : jscc}) + + # Add method that joins/compiles our Engine files. + env.AddMethod(create_engine_file, "CreateEngineFile") + + # Closure compiler extern and support for ecmascript specs (const, let, etc). + env['ENV']['EMCC_CLOSURE_ARGS'] = '--language_in ECMASCRIPT6' + + em_config = parse_config() + env.PrependENVPath('PATH', em_config['EMCC_ROOT']) env['CC'] = 'emcc' env['CXX'] = 'em++' @@ -104,44 +124,31 @@ def configure(env): env['LIBPREFIXES'] = ['$LIBPREFIX'] env['LIBSUFFIXES'] = ['$LIBSUFFIX'] - ## Compile flags - env.Prepend(CPPPATH=['#platform/javascript']) env.Append(CPPDEFINES=['JAVASCRIPT_ENABLED', 'UNIX_ENABLED']) - # No multi-threading (SharedArrayBuffer) available yet, - # once feasible also consider memory buffer size issues. - env.Append(CPPDEFINES=['NO_THREADS']) - - # Disable exceptions and rtti on non-tools (template) builds - if not env['tools']: - # These flags help keep the file size down. - env.Append(CCFLAGS=['-fno-exceptions', '-fno-rtti']) - # Don't use dynamic_cast, necessary with no-rtti. - env.Append(CPPDEFINES=['NO_SAFE_CAST']) - if env['javascript_eval']: env.Append(CPPDEFINES=['JAVASCRIPT_EVAL_ENABLED']) - ## Link flags + # Thread support (via SharedArrayBuffer). + if env['threads_enabled']: + env.Append(CPPDEFINES=['PTHREAD_NO_RENAME']) + env.Append(CCFLAGS=['-s', 'USE_PTHREADS=1']) + env.Append(LINKFLAGS=['-s', 'USE_PTHREADS=1']) + env.Append(LINKFLAGS=['-s', 'PTHREAD_POOL_SIZE=4']) + env.Append(LINKFLAGS=['-s', 'WASM_MEM_MAX=2048MB']) + else: + env.Append(CPPDEFINES=['NO_THREADS']) + + # Reduce code size by generating less support code (e.g. skip NodeJS support). + env.Append(LINKFLAGS=['-s', 'ENVIRONMENT=web,worker']) # We use IDBFS in javascript_main.cpp. Since Emscripten 1.39.1 it needs to # be linked explicitly. env.Append(LIBS=['idbfs.js']) env.Append(LINKFLAGS=['-s', 'BINARYEN=1']) - - # Only include the JavaScript support code for the web environment - # (i.e. exclude Node.js and other unused environments). - # This makes the JavaScript support code about 4 KB smaller. - env.Append(LINKFLAGS=['-s', 'ENVIRONMENT=web']) - - # This needs to be defined for Emscripten using 'fastcomp' (default pre-1.39.0) - # and undefined if using 'upstream'. And to make things simple, earlier - # Emscripten versions didn't include 'fastcomp' in their path, so we check - # against the presence of 'upstream' to conditionally add the flag. - if not "upstream" in em_config['EMSCRIPTEN_ROOT']: - env.Append(LINKFLAGS=['-s', 'BINARYEN_TRAP_MODE=\'clamp\'']) + env.Append(LINKFLAGS=['-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME="Godot"']) # Allow increasing memory buffer size during runtime. This is efficient # when using WebAssembly (in comparison to asm.js) and works well for @@ -153,8 +160,5 @@ def configure(env): env.Append(LINKFLAGS=['-s', 'INVOKE_RUN=0']) - # TODO: Reevaluate usage of this setting now that engine.js manages engine runtime. - env.Append(LINKFLAGS=['-s', 'NO_EXIT_RUNTIME=1']) - - #adding flag due to issue with emscripten 1.38.41 callMain method https://github.com/emscripten-core/emscripten/blob/incoming/ChangeLog.md#v13841-08072019 - env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["callMain"]']) + # callMain for manual start, FS for preloading. + env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["callMain", "FS"]']) diff --git a/platform/javascript/emscripten_helpers.py b/platform/javascript/emscripten_helpers.py new file mode 100644 index 0000000000..bda5b40a74 --- /dev/null +++ b/platform/javascript/emscripten_helpers.py @@ -0,0 +1,37 @@ +import os + +def parse_config(): + em_config_file = os.getenv('EM_CONFIG') or os.path.expanduser('~/.emscripten') + if not os.path.exists(em_config_file): + raise RuntimeError("Emscripten configuration file '%s' does not exist" % em_config_file) + + normalized = {} + em_config = {} + with open(em_config_file) as f: + try: + # Emscripten configuration file is a Python file with simple assignments. + exec(f.read(), em_config) + except StandardError as e: + raise RuntimeError("Emscripten configuration file '%s' is invalid:\n%s" % (em_config_file, e)) + normalized['EMCC_ROOT'] = em_config.get('EMSCRIPTEN_ROOT') + normalized['NODE_JS'] = em_config.get('NODE_JS') + normalized['CLOSURE_BIN'] = os.path.join(normalized['EMCC_ROOT'], 'node_modules', '.bin', 'google-closure-compiler') + return normalized + + +def run_closure_compiler(target, source, env, for_signature): + cfg = parse_config() + cmd = [cfg['NODE_JS'], cfg['CLOSURE_BIN']] + cmd.extend(['--compilation_level', 'ADVANCED_OPTIMIZATIONS']) + for f in env['JSEXTERNS']: + cmd.extend(['--externs', f.get_abspath()]) + for f in source: + cmd.extend(['--js', f.get_abspath()]) + cmd.extend(['--js_output_file', target[0].get_abspath()]) + return ' '.join(cmd) + + +def create_engine_file(env, target, source, externs): + if env['use_closure_compiler']: + return env.BuildJS(target, source, JSEXTERNS=externs) + return env.Textfile(target, [env.File(s) for s in source]) diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js deleted file mode 100644 index 227accadb0..0000000000 --- a/platform/javascript/engine.js +++ /dev/null @@ -1,411 +0,0 @@ - // The following is concatenated with generated code, and acts as the end - // of a wrapper for said code. See pre.js for the other part of the - // wrapper. - exposedLibs['PATH'] = PATH; - exposedLibs['FS'] = FS; - return Module; - }, -}; - -(function() { - var engine = Engine; - - var DOWNLOAD_ATTEMPTS_MAX = 4; - - var basePath = null; - var wasmFilenameExtensionOverride = null; - var engineLoadPromise = null; - - var loadingFiles = {}; - - function getPathLeaf(path) { - - while (path.endsWith('/')) - path = path.slice(0, -1); - return path.slice(path.lastIndexOf('/') + 1); - } - - function getBasePath(path) { - - if (path.endsWith('/')) - path = path.slice(0, -1); - if (path.lastIndexOf('.') > path.lastIndexOf('/')) - path = path.slice(0, path.lastIndexOf('.')); - return path; - } - - function getBaseName(path) { - - return getPathLeaf(getBasePath(path)); - } - - Engine = function Engine() { - - this.rtenv = null; - - var LIBS = {}; - - var initPromise = null; - var unloadAfterInit = true; - - var preloadedFiles = []; - - var resizeCanvasOnStart = true; - var progressFunc = null; - var preloadProgressTracker = {}; - var lastProgress = { loaded: 0, total: 0 }; - - var canvas = null; - var executableName = null; - var locale = null; - var stdout = null; - var stderr = null; - - this.init = function(newBasePath) { - - if (!initPromise) { - initPromise = Engine.load(newBasePath).then( - instantiate.bind(this) - ); - requestAnimationFrame(animateProgress); - if (unloadAfterInit) - initPromise.then(Engine.unloadEngine); - } - return initPromise; - }; - - function instantiate(wasmBuf) { - - var rtenvProps = { - engine: this, - ENV: {}, - }; - if (typeof stdout === 'function') - rtenvProps.print = stdout; - if (typeof stderr === 'function') - rtenvProps.printErr = stderr; - rtenvProps.instantiateWasm = function(imports, onSuccess) { - WebAssembly.instantiate(wasmBuf, imports).then(function(result) { - onSuccess(result.instance); - }); - return {}; - }; - - return new Promise(function(resolve, reject) { - rtenvProps.onRuntimeInitialized = resolve; - rtenvProps.onAbort = reject; - rtenvProps.thisProgram = executableName; - rtenvProps.engine.rtenv = Engine.RuntimeEnvironment(rtenvProps, LIBS); - }); - } - - this.preloadFile = function(pathOrBuffer, destPath) { - - if (pathOrBuffer instanceof ArrayBuffer) { - pathOrBuffer = new Uint8Array(pathOrBuffer); - } else if (ArrayBuffer.isView(pathOrBuffer)) { - pathOrBuffer = new Uint8Array(pathOrBuffer.buffer); - } - if (pathOrBuffer instanceof Uint8Array) { - preloadedFiles.push({ - path: destPath, - buffer: pathOrBuffer - }); - return Promise.resolve(); - } else if (typeof pathOrBuffer === 'string') { - return loadPromise(pathOrBuffer, preloadProgressTracker).then(function(xhr) { - preloadedFiles.push({ - path: destPath || pathOrBuffer, - buffer: xhr.response - }); - }); - } else { - throw Promise.reject("Invalid object for preloading"); - } - }; - - this.start = function() { - - return this.init().then( - Function.prototype.apply.bind(synchronousStart, this, arguments) - ); - }; - - this.startGame = function(execName, mainPack) { - - executableName = execName; - var mainArgs = [ '--main-pack', getPathLeaf(mainPack) ]; - - return Promise.all([ - this.init(getBasePath(execName)), - this.preloadFile(mainPack, getPathLeaf(mainPack)) - ]).then( - Function.prototype.apply.bind(synchronousStart, this, mainArgs) - ); - }; - - function synchronousStart() { - - if (canvas instanceof HTMLCanvasElement) { - this.rtenv.canvas = canvas; - } else { - var firstCanvas = document.getElementsByTagName('canvas')[0]; - if (firstCanvas instanceof HTMLCanvasElement) { - this.rtenv.canvas = firstCanvas; - } else { - throw new Error("No canvas found"); - } - } - - var actualCanvas = this.rtenv.canvas; - // canvas can grab focus on click - if (actualCanvas.tabIndex < 0) { - actualCanvas.tabIndex = 0; - } - // necessary to calculate cursor coordinates correctly - actualCanvas.style.padding = 0; - actualCanvas.style.borderWidth = 0; - actualCanvas.style.borderStyle = 'none'; - // disable right-click context menu - actualCanvas.addEventListener('contextmenu', function(ev) { - ev.preventDefault(); - }, false); - // until context restoration is implemented - actualCanvas.addEventListener('webglcontextlost', function(ev) { - alert("WebGL context lost, please reload the page"); - ev.preventDefault(); - }, false); - - if (locale) { - this.rtenv.locale = locale; - } else { - this.rtenv.locale = navigator.languages ? navigator.languages[0] : navigator.language; - } - this.rtenv.locale = this.rtenv.locale.split('.')[0]; - this.rtenv.resizeCanvasOnStart = resizeCanvasOnStart; - - preloadedFiles.forEach(function(file) { - var dir = LIBS.PATH.dirname(file.path); - try { - LIBS.FS.stat(dir); - } catch (e) { - if (e.code !== 'ENOENT') { - throw e; - } - LIBS.FS.mkdirTree(dir); - } - // With memory growth, canOwn should be false. - LIBS.FS.createDataFile(file.path, null, new Uint8Array(file.buffer), true, true, false); - }, this); - - preloadedFiles = null; - initPromise = null; - this.rtenv.callMain(arguments); - } - - this.setProgressFunc = function(func) { - progressFunc = func; - }; - - this.setResizeCanvasOnStart = function(enabled) { - resizeCanvasOnStart = enabled; - }; - - function animateProgress() { - - var loaded = 0; - var total = 0; - var totalIsValid = true; - var progressIsFinal = true; - - [loadingFiles, preloadProgressTracker].forEach(function(tracker) { - Object.keys(tracker).forEach(function(file) { - if (!tracker[file].final) - progressIsFinal = false; - if (!totalIsValid || tracker[file].total === 0) { - totalIsValid = false; - total = 0; - } else { - total += tracker[file].total; - } - loaded += tracker[file].loaded; - }); - }); - if (loaded !== lastProgress.loaded || total !== lastProgress.total) { - lastProgress.loaded = loaded; - lastProgress.total = total; - if (typeof progressFunc === 'function') - progressFunc(loaded, total); - } - if (!progressIsFinal) - requestAnimationFrame(animateProgress); - } - - this.setCanvas = function(elem) { - canvas = elem; - }; - - this.setExecutableName = function(newName) { - - executableName = newName; - }; - - this.setLocale = function(newLocale) { - - locale = newLocale; - }; - - this.setUnloadAfterInit = function(enabled) { - - if (enabled && !unloadAfterInit && initPromise) { - initPromise.then(Engine.unloadEngine); - } - unloadAfterInit = enabled; - }; - - this.setStdoutFunc = function(func) { - - var print = function(text) { - if (arguments.length > 1) { - text = Array.prototype.slice.call(arguments).join(" "); - } - func(text); - }; - if (this.rtenv) - this.rtenv.print = print; - stdout = print; - }; - - this.setStderrFunc = function(func) { - - var printErr = function(text) { - if (arguments.length > 1) - text = Array.prototype.slice.call(arguments).join(" "); - func(text); - }; - if (this.rtenv) - this.rtenv.printErr = printErr; - stderr = printErr; - }; - - - }; // Engine() - - Engine.RuntimeEnvironment = engine.RuntimeEnvironment; - - Engine.isWebGLAvailable = function(majorVersion = 1) { - - var testContext = false; - try { - var testCanvas = document.createElement('canvas'); - if (majorVersion === 1) { - testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl'); - } else if (majorVersion === 2) { - testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2'); - } - } catch (e) {} - return !!testContext; - }; - - Engine.setWebAssemblyFilenameExtension = function(override) { - - if (String(override).length === 0) { - throw new Error('Invalid WebAssembly filename extension override'); - } - wasmFilenameExtensionOverride = String(override); - } - - Engine.load = function(newBasePath) { - - if (newBasePath !== undefined) basePath = getBasePath(newBasePath); - if (engineLoadPromise === null) { - if (typeof WebAssembly !== 'object') - return Promise.reject(new Error("Browser doesn't support WebAssembly")); - // TODO cache/retrieve module to/from idb - engineLoadPromise = loadPromise(basePath + '.' + (wasmFilenameExtensionOverride || 'wasm')).then(function(xhr) { - return xhr.response; - }); - engineLoadPromise = engineLoadPromise.catch(function(err) { - engineLoadPromise = null; - throw err; - }); - } - return engineLoadPromise; - }; - - Engine.unload = function() { - engineLoadPromise = null; - }; - - function loadPromise(file, tracker) { - if (tracker === undefined) - tracker = loadingFiles; - return new Promise(function(resolve, reject) { - loadXHR(resolve, reject, file, tracker); - }); - } - - function loadXHR(resolve, reject, file, tracker) { - - var xhr = new XMLHttpRequest; - xhr.open('GET', file); - if (!file.endsWith('.js')) { - xhr.responseType = 'arraybuffer'; - } - ['loadstart', 'progress', 'load', 'error', 'abort'].forEach(function(ev) { - xhr.addEventListener(ev, onXHREvent.bind(xhr, resolve, reject, file, tracker)); - }); - xhr.send(); - } - - function onXHREvent(resolve, reject, file, tracker, ev) { - - if (this.status >= 400) { - - if (this.status < 500 || ++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) { - reject(new Error("Failed loading file '" + file + "': " + this.statusText)); - this.abort(); - return; - } else { - setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000); - } - } - - switch (ev.type) { - case 'loadstart': - if (tracker[file] === undefined) { - tracker[file] = { - total: ev.total, - loaded: ev.loaded, - attempts: 0, - final: false, - }; - } - break; - - case 'progress': - tracker[file].loaded = ev.loaded; - tracker[file].total = ev.total; - break; - - case 'load': - tracker[file].final = true; - resolve(this); - break; - - case 'error': - if (++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) { - tracker[file].final = true; - reject(new Error("Failed loading file '" + file + "'")); - } else { - setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000); - } - break; - - case 'abort': - tracker[file].final = true; - reject(new Error("Loading file '" + file + "' was aborted.")); - break; - } - } -})(); diff --git a/platform/javascript/engine/engine.js b/platform/javascript/engine/engine.js new file mode 100644 index 0000000000..6d7509377f --- /dev/null +++ b/platform/javascript/engine/engine.js @@ -0,0 +1,184 @@ +Function('return this')()['Engine'] = (function() { + + var unloadAfterInit = true; + var canvas = null; + var resizeCanvasOnStart = false; + var customLocale = 'en_US'; + var wasmExt = '.wasm'; + + var preloader = new Preloader(); + var loader = new Loader(); + var rtenv = null; + + var executableName = ''; + var loadPath = ''; + var loadPromise = null; + var initPromise = null; + var stderr = null; + var stdout = null; + var progressFunc = null; + + function load(basePath) { + if (loadPromise == null) { + loadPath = basePath; + loadPromise = preloader.loadPromise(basePath + wasmExt); + preloader.setProgressFunc(progressFunc); + requestAnimationFrame(preloader.animateProgress); + } + return loadPromise; + }; + + function unload() { + loadPromise = null; + }; + + /** @constructor */ + function Engine() {}; + + Engine.prototype.init = /** @param {string=} basePath */ function(basePath) { + if (initPromise) { + return initPromise; + } + if (!loadPromise) { + if (!basePath) { + initPromise = Promise.reject(new Error("A base path must be provided when calling `init` and the engine is not loaded.")); + return initPromise; + } + load(basePath); + } + var config = {} + if (typeof stdout === 'function') + config.print = stdout; + if (typeof stderr === 'function') + config.printErr = stderr; + initPromise = loader.init(loadPromise, loadPath, config).then(function() { + return new Promise(function(resolve, reject) { + rtenv = loader.env; + if (unloadAfterInit) { + loadPromise = null; + } + resolve(); + }); + }); + return initPromise; + }; + + /** @type {function(string, string):Object} */ + Engine.prototype.preloadFile = function(file, path) { + return preloader.preload(file, path); + }; + + /** @type {function(...string):Object} */ + Engine.prototype.start = function() { + // Start from arguments. + var args = []; + for (var i = 0; i < arguments.length; i++) { + args.push(arguments[i]); + } + var me = this; + return new Promise(function(resolve, reject) { + return me.init().then(function() { + if (!(canvas instanceof HTMLCanvasElement)) { + canvas = Utils.findCanvas(); + } + rtenv['locale'] = customLocale; + rtenv['canvas'] = canvas; + rtenv['thisProgram'] = executableName; + rtenv['resizeCanvasOnStart'] = resizeCanvasOnStart; + loader.start(preloader.preloadedFiles, args).then(function() { + loader = null; + initPromise = null; + resolve(); + }); + }); + }); + }; + + Engine.prototype.startGame = function(execName, mainPack) { + // Start and init with execName as loadPath if not inited. + executableName = execName; + var me = this; + return Promise.all([ + this.init(execName), + this.preloadFile(mainPack, mainPack) + ]).then(function() { + return me.start('--main-pack', mainPack); + }); + }; + + Engine.prototype.setWebAssemblyFilenameExtension = function(override) { + if (String(override).length === 0) { + throw new Error('Invalid WebAssembly filename extension override'); + } + wasmExt = String(override); + }; + + Engine.prototype.setUnloadAfterInit = function(enabled) { + unloadAfterInit = enabled; + }; + + Engine.prototype.setCanvas = function(canvasElem) { + canvas = canvasElem; + }; + + Engine.prototype.setCanvasResizedOnStart = function(enabled) { + resizeCanvasOnStart = enabled; + }; + + Engine.prototype.setLocale = function(locale) { + customLocale = locale; + }; + + Engine.prototype.setExecutableName = function(newName) { + executableName = newName; + }; + + Engine.prototype.setProgressFunc = function(func) { + progressFunc = func; + } + + Engine.prototype.setStdoutFunc = function(func) { + + var print = function(text) { + if (arguments.length > 1) { + text = Array.prototype.slice.call(arguments).join(" "); + } + func(text); + }; + if (rtenv) + rtenv.print = print; + stdout = print; + }; + + Engine.prototype.setStderrFunc = function(func) { + + var printErr = function(text) { + if (arguments.length > 1) + text = Array.prototype.slice.call(arguments).join(" "); + func(text); + }; + if (rtenv) + rtenv.printErr = printErr; + stderr = printErr; + }; + + // Closure compiler exported engine methods. + /** @export */ + Engine['isWebGLAvailable'] = Utils.isWebGLAvailable; + Engine['load'] = load; + Engine['unload'] = unload; + Engine.prototype['init'] = Engine.prototype.init + Engine.prototype['preloadFile'] = Engine.prototype.preloadFile + Engine.prototype['start'] = Engine.prototype.start + Engine.prototype['startGame'] = Engine.prototype.startGame + Engine.prototype['setWebAssemblyFilenameExtension'] = Engine.prototype.setWebAssemblyFilenameExtension + Engine.prototype['setUnloadAfterInit'] = Engine.prototype.setUnloadAfterInit + Engine.prototype['setCanvas'] = Engine.prototype.setCanvas + Engine.prototype['setCanvasResizedOnStart'] = Engine.prototype.setCanvasResizedOnStart + Engine.prototype['setLocale'] = Engine.prototype.setLocale + Engine.prototype['setExecutableName'] = Engine.prototype.setExecutableName + Engine.prototype['setProgressFunc'] = Engine.prototype.setProgressFunc + Engine.prototype['setStdoutFunc'] = Engine.prototype.setStdoutFunc + Engine.prototype['setStderrFunc'] = Engine.prototype.setStderrFunc + return Engine; +})(); diff --git a/platform/javascript/engine/externs.js b/platform/javascript/engine/externs.js new file mode 100644 index 0000000000..1a94dd15ec --- /dev/null +++ b/platform/javascript/engine/externs.js @@ -0,0 +1,3 @@ +var Godot; +var WebAssembly = {}; +WebAssembly.instantiate = function(buffer, imports) {}; diff --git a/platform/javascript/engine/loader.js b/platform/javascript/engine/loader.js new file mode 100644 index 0000000000..d27fbf612e --- /dev/null +++ b/platform/javascript/engine/loader.js @@ -0,0 +1,33 @@ +var Loader = /** @constructor */ function() { + + this.env = null; + + this.init = function(loadPromise, basePath, config) { + var me = this; + return new Promise(function(resolve, reject) { + var cfg = config || {}; + cfg['locateFile'] = Utils.createLocateRewrite(basePath); + cfg['instantiateWasm'] = Utils.createInstantiatePromise(loadPromise); + loadPromise = null; + Godot(cfg).then(function(module) { + me.env = module; + resolve(); + }); + }); + } + + this.start = function(preloadedFiles, args) { + var me = this; + return new Promise(function(resolve, reject) { + if (!me.env) { + reject(new Error('The engine must be initialized before it can be started')); + } + preloadedFiles.forEach(function(file) { + Utils.copyToFS(me.env['FS'], file.path, file.buffer); + }); + preloadedFiles.length = 0; // Clear memory + me.env['callMain'](args); + resolve(); + }); + } +}; diff --git a/platform/javascript/engine/preloader.js b/platform/javascript/engine/preloader.js new file mode 100644 index 0000000000..17918eae38 --- /dev/null +++ b/platform/javascript/engine/preloader.js @@ -0,0 +1,139 @@ +var Preloader = /** @constructor */ function() { + + var DOWNLOAD_ATTEMPTS_MAX = 4; + var progressFunc = null; + var lastProgress = { loaded: 0, total: 0 }; + + var loadingFiles = {}; + this.preloadedFiles = []; + + function loadXHR(resolve, reject, file, tracker) { + var xhr = new XMLHttpRequest; + xhr.open('GET', file); + if (!file.endsWith('.js')) { + xhr.responseType = 'arraybuffer'; + } + ['loadstart', 'progress', 'load', 'error', 'abort'].forEach(function(ev) { + xhr.addEventListener(ev, onXHREvent.bind(xhr, resolve, reject, file, tracker)); + }); + xhr.send(); + } + + function onXHREvent(resolve, reject, file, tracker, ev) { + + if (this.status >= 400) { + + if (this.status < 500 || ++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) { + reject(new Error("Failed loading file '" + file + "': " + this.statusText)); + this.abort(); + return; + } else { + setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000); + } + } + + switch (ev.type) { + case 'loadstart': + if (tracker[file] === undefined) { + tracker[file] = { + total: ev.total, + loaded: ev.loaded, + attempts: 0, + final: false, + }; + } + break; + + case 'progress': + tracker[file].loaded = ev.loaded; + tracker[file].total = ev.total; + break; + + case 'load': + tracker[file].final = true; + resolve(this); + break; + + case 'error': + if (++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) { + tracker[file].final = true; + reject(new Error("Failed loading file '" + file + "'")); + } else { + setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000); + } + break; + + case 'abort': + tracker[file].final = true; + reject(new Error("Loading file '" + file + "' was aborted.")); + break; + } + } + + this.loadPromise = function(file) { + return new Promise(function(resolve, reject) { + loadXHR(resolve, reject, file, loadingFiles); + }); + } + + this.preload = function(pathOrBuffer, destPath) { + if (pathOrBuffer instanceof ArrayBuffer) { + pathOrBuffer = new Uint8Array(pathOrBuffer); + } else if (ArrayBuffer.isView(pathOrBuffer)) { + pathOrBuffer = new Uint8Array(pathOrBuffer.buffer); + } + if (pathOrBuffer instanceof Uint8Array) { + this.preloadedFiles.push({ + path: destPath, + buffer: pathOrBuffer + }); + return Promise.resolve(); + } else if (typeof pathOrBuffer === 'string') { + var me = this; + return this.loadPromise(pathOrBuffer).then(function(xhr) { + me.preloadedFiles.push({ + path: destPath || pathOrBuffer, + buffer: xhr.response + }); + return Promise.resolve(); + }); + } else { + throw Promise.reject("Invalid object for preloading"); + } + }; + + var animateProgress = function() { + + var loaded = 0; + var total = 0; + var totalIsValid = true; + var progressIsFinal = true; + + Object.keys(loadingFiles).forEach(function(file) { + const stat = loadingFiles[file]; + if (!stat.final) { + progressIsFinal = false; + } + if (!totalIsValid || stat.total === 0) { + totalIsValid = false; + total = 0; + } else { + total += stat.total; + } + loaded += stat.loaded; + }); + if (loaded !== lastProgress.loaded || total !== lastProgress.total) { + lastProgress.loaded = loaded; + lastProgress.total = total; + if (typeof progressFunc === 'function') + progressFunc(loaded, total); + } + if (!progressIsFinal) + requestAnimationFrame(animateProgress); + } + this.animateProgress = animateProgress; // Also exposed to start it. + + this.setProgressFunc = function(callback) { + progressFunc = callback; + } +}; diff --git a/platform/javascript/engine/utils.js b/platform/javascript/engine/utils.js new file mode 100644 index 0000000000..fdff90a923 --- /dev/null +++ b/platform/javascript/engine/utils.js @@ -0,0 +1,69 @@ +var Utils = { + + createLocateRewrite: function(execName) { + function rw(path) { + if (path.endsWith('.worker.js')) { + return execName + '.worker.js'; + } else if (path.endsWith('.js')) { + return execName + '.js'; + } else if (path.endsWith('.wasm')) { + return execName + '.wasm'; + } + } + return rw; + }, + + createInstantiatePromise: function(wasmLoader) { + function instantiateWasm(imports, onSuccess) { + wasmLoader.then(function(xhr) { + WebAssembly.instantiate(xhr.response, imports).then(function(result) { + onSuccess(result['instance'], result['module']); + }); + }); + wasmLoader = null; + return {}; + }; + + return instantiateWasm; + }, + + copyToFS: function(fs, path, buffer) { + var p = path.lastIndexOf("/"); + var dir = "/"; + if (p > 0) { + dir = path.slice(0, path.lastIndexOf("/")); + } + try { + fs.stat(dir); + } catch (e) { + if (e.errno !== 44) { // 'ENOENT', see https://github.com/emscripten-core/emscripten/blob/master/system/lib/libc/musl/arch/emscripten/bits/errno.h + throw e; + } + fs['mkdirTree'](dir); + } + // With memory growth, canOwn should be false. + fs['writeFile'](path, new Uint8Array(buffer), {'flags': 'wx+'}); + }, + + findCanvas: function() { + var nodes = document.getElementsByTagName('canvas'); + if (nodes.length && nodes[0] instanceof HTMLCanvasElement) { + return nodes[0]; + } + throw new Error("No canvas found"); + }, + + isWebGLAvailable: function(majorVersion = 1) { + + var testContext = false; + try { + var testCanvas = document.createElement('canvas'); + if (majorVersion === 1) { + testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl'); + } else if (majorVersion === 2) { + testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2'); + } + } catch (e) {} + return !!testContext; + } +}; diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index f0326d5027..da61425747 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -94,6 +94,9 @@ public: } else if (req[1] == basereq + ".js") { filepath += ".js"; ctype = "application/javascript"; + } else if (req[1] == basereq + ".worker.js") { + filepath += ".worker.js"; + ctype = "application/javascript"; } else if (req[1] == basereq + ".pck") { filepath += ".pck"; ctype = "application/octet-stream"; @@ -432,6 +435,10 @@ Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPrese } else if (file == "godot.js") { file = p_path.get_file().get_basename() + ".js"; + } else if (file == "godot.worker.js") { + + file = p_path.get_file().get_basename() + ".worker.js"; + } else if (file == "godot.wasm") { file = p_path.get_file().get_basename() + ".wasm"; @@ -563,6 +570,7 @@ Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_prese // Export generates several files, clean them up on failure. DirAccess::remove_file_or_error(basepath + ".html"); DirAccess::remove_file_or_error(basepath + ".js"); + DirAccess::remove_file_or_error(basepath + ".worker.js"); DirAccess::remove_file_or_error(basepath + ".pck"); DirAccess::remove_file_or_error(basepath + ".png"); DirAccess::remove_file_or_error(basepath + ".wasm"); diff --git a/platform/javascript/http_client.h.inc b/platform/javascript/http_client.h.inc index 03e2ce8b8a..ac275aadbc 100644 --- a/platform/javascript/http_client.h.inc +++ b/platform/javascript/http_client.h.inc @@ -45,7 +45,7 @@ String password; int polled_response_code; String polled_response_header; -PoolByteArray polled_response; +PackedByteArray polled_response; #ifdef DEBUG_ENABLED bool has_polled; diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp index d7796cc4f4..472384cf30 100644 --- a/platform/javascript/http_client_javascript.cpp +++ b/platform/javascript/http_client_javascript.cpp @@ -108,8 +108,7 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector Error err = prepare_request(p_method, p_url, p_headers); if (err != OK) return err; - const uint8_t *read = p_body.ptr(); - godot_xhr_send_data(xhr_id, read.ptr(), p_body.size()); + godot_xhr_send_data(xhr_id, p_body.ptr(), p_body.size()); return OK; } @@ -180,11 +179,7 @@ PackedByteArray HTTPClient::read_response_body_chunk() { int to_read = MIN(read_limit, polled_response.size() - response_read_offset); PackedByteArray chunk; chunk.resize(to_read); - uint8_t *write = chunk.ptrw(); - const uint8_t *read = polled_response.ptr(); - memcpy(write.ptr(), read.ptr() + response_read_offset, to_read); - write = uint8_t * (); - read = const uint8_t * (); + memcpy(chunk.ptrw(), polled_response.ptr() + response_read_offset, to_read); response_read_offset += to_read; if (response_read_offset == polled_response.size()) { @@ -267,19 +262,13 @@ Error HTTPClient::poll() { int len = godot_xhr_get_response_headers_length(xhr_id); bytes.resize(len + 1); - uint8_t *write = bytes.ptrw(); - godot_xhr_get_response_headers(xhr_id, reinterpret_cast<char *>(write.ptr()), len); - write[len] = 0; - write = uint8_t * (); + godot_xhr_get_response_headers(xhr_id, reinterpret_cast<char *>(bytes.ptrw()), len); + bytes.ptrw()[len] = 0; - const uint8_t *read = bytes.ptr(); - polled_response_header = String::utf8(reinterpret_cast<const char *>(read.ptr())); - read = const uint8_t * (); + polled_response_header = String::utf8(reinterpret_cast<const char *>(bytes.ptr())); polled_response.resize(godot_xhr_get_response_length(xhr_id)); - write = polled_response.ptrw(); - godot_xhr_get_response(xhr_id, write.ptr(), polled_response.size()); - write = uint8_t * (); + godot_xhr_get_response(xhr_id, polled_response.ptrw(), polled_response.size()); break; } diff --git a/platform/javascript/id_handler.js b/platform/javascript/id_handler.js index 3851123ed1..67d29075b8 100644 --- a/platform/javascript/id_handler.js +++ b/platform/javascript/id_handler.js @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -var IDHandler = function() { +var IDHandler = /** @constructor */ function() { var ids = {}; var size = 0; diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp index 44cce28d57..db8050b90e 100644 --- a/platform/javascript/javascript_eval.cpp +++ b/platform/javascript/javascript_eval.cpp @@ -33,11 +33,11 @@ #include "api/javascript_eval.h" #include "emscripten.h" -extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_PackedByteArray_and_open_write(PackedByteArray *p_arr, uint8_t **r_write, int p_len) { +extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_PackedByteArray_and_open_write(PackedByteArray *p_arr, VectorWriteProxy<uint8_t> *r_write, int p_len) { p_arr->resize(p_len); - *r_write = p_arr->write(); - return r_write->ptr(); + *r_write = p_arr->write; + return p_arr->ptrw(); } Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { @@ -49,7 +49,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { } js_data; PackedByteArray arr; - uint8_t *arr_write; + VectorWriteProxy<uint8_t> arr_write; /* clang-format off */ Variant::Type return_type = static_cast<Variant::Type>(EM_ASM_INT({ @@ -138,7 +138,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { return str; } case Variant::PACKED_BYTE_ARRAY: - arr_write = uint8_t * (); + arr_write = VectorWriteProxy<uint8_t>(); return arr; default: return Variant(); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 037f78c7af..1d7a16db80 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -31,7 +31,8 @@ #include "os_javascript.h" #include "core/io/file_access_buffered_fa.h" -#include "drivers/gles2/rasterizer_gles2.h" +//#include "drivers/gles2/rasterizer_gles2.h" +#include "drivers/dummy/rasterizer_dummy.h" #include "drivers/unix/dir_access_unix.h" #include "drivers/unix/file_access_unix.h" #include "main/main.h" @@ -539,15 +540,11 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s PackedByteArray png; size_t len; - const uint8_t *r = image->get_data().ptr(); - ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, r.ptr(), 0, NULL)); + PackedByteArray data = image->get_data(); + ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, NULL)); png.resize(len); - uint8_t *w = png.ptrw(); - ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, w.ptr(), &len, 0, r.ptr(), 0, NULL)); - w = uint8_t * (); - - r = png.ptr(); + ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, NULL)); char *object_url; /* clang-format off */ @@ -562,9 +559,8 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s var string_on_wasm_heap = _malloc(length_bytes); setValue(PTR, string_on_wasm_heap, '*'); stringToUTF8(url, string_on_wasm_heap, length_bytes); - }, r.ptr(), len, &object_url); + }, png.ptr(), len, &object_url); /* clang-format on */ - r = const uint8_t * (); String url = String::utf8(object_url) + "?" + itos(p_hotspot.x) + " " + itos(p_hotspot.y); @@ -896,6 +892,7 @@ void OS_JavaScript::initialize_core() { Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { +#if 0 EmscriptenWebGLContextAttributes attributes; emscripten_webgl_init_context_attributes(&attributes); attributes.alpha = GLOBAL_GET("display/window/per_pixel_transparency/allowed"); @@ -938,6 +935,7 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, if (p_desired.fullscreen) { /* clang-format off */ EM_ASM({ + const canvas = Module.canvas; (canvas.requestFullscreen || canvas.msRequestFullscreen || canvas.mozRequestFullScreen || canvas.mozRequestFullscreen || canvas.webkitRequestFullscreen @@ -952,6 +950,8 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, } else { set_window_size(get_window_size()); } +#endif + RasterizerDummy::make_current(); // TODO GLES2 in Godot 4.0... or webgpu? char locale_ptr[16]; /* clang-format off */ @@ -1181,15 +1181,12 @@ void OS_JavaScript::set_icon(const Ref<Image> &p_icon) { PackedByteArray png; size_t len; - const uint8_t *r = icon->get_data().ptr(); - ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, r.ptr(), 0, NULL)); + PackedByteArray data = icon->get_data(); + ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, NULL)); png.resize(len); - uint8_t *w = png.ptrw(); - ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, w.ptr(), &len, 0, r.ptr(), 0, NULL)); - w = uint8_t * (); + ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, NULL)); - r = png.ptr(); /* clang-format off */ EM_ASM_ARGS({ var PNG_PTR = $0; @@ -1205,7 +1202,7 @@ void OS_JavaScript::set_icon(const Ref<Image> &p_icon) { document.head.appendChild(link); } link.href = url; - }, r.ptr(), len); + }, png.ptr(), len); /* clang-format on */ } diff --git a/platform/javascript/pre.js b/platform/javascript/pre.js deleted file mode 100644 index a870e676ea..0000000000 --- a/platform/javascript/pre.js +++ /dev/null @@ -1,5 +0,0 @@ -var Engine = { - RuntimeEnvironment: function(Module, exposedLibs) { - // The above is concatenated with generated code, and acts as the start of - // a wrapper for said code. See engine.js for the other part of the - // wrapper. diff --git a/platform/osx/detect.py b/platform/osx/detect.py index b2f4032f66..12ca5c10dc 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -151,13 +151,13 @@ def configure(env): env.Prepend(CPPPATH=['#platform/osx']) env.Append(CPPDEFINES=['OSX_ENABLED', 'UNIX_ENABLED', 'APPLE_STYLE_KEYS', 'COREAUDIO_ENABLED', 'COREMIDI_ENABLED']) - env.AppendUnique(FRAMEWORKS=['Cocoa', 'Carbon', 'AudioUnit', 'CoreAudio', 'CoreMIDI', 'IOKit', 'ForceFeedback', 'CoreVideo', 'AVFoundation', 'CoreMedia']) + env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreMIDI', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'CoreVideo', '-framework', 'AVFoundation', '-framework', 'CoreMedia']) env.Append(LIBS=['pthread', 'z']) env.Append(CPPDEFINES=['VULKAN_ENABLED']) - env.AppendUnique(FRAMEWORKS=['Metal', 'QuartzCore', 'IOSurface']) + env.Append(LINKFLAGS=['-framework', 'Metal', '-framework', 'QuartzCore', '-framework', 'IOSurface']) if (env['use_static_mvk']): - env.AppendUnique(FRAMEWORKS=['MoltenVK']) + env.Append(LINKFLAGS=['-framework', 'MoltenVK']) env['builtin_vulkan'] = False elif not env['builtin_vulkan']: env.Append(LIBS=['vulkan']) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 63f0cd53a4..a112f26ac4 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -33,8 +33,9 @@ #include "os_windows.h" +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" #include "core/io/marshalls.h" -#include "core/script_language.h" #include "core/version_generated.gen.h" #if defined(OPENGL_ENABLED) @@ -194,13 +195,13 @@ void RedirectIOToConsole() { } BOOL WINAPI HandlerRoutine(_In_ DWORD dwCtrlType) { - if (ScriptDebugger::get_singleton() == NULL) + if (!EngineDebugger::is_active()) return FALSE; switch (dwCtrlType) { case CTRL_C_EVENT: - ScriptDebugger::get_singleton()->set_depth(-1); - ScriptDebugger::get_singleton()->set_lines_left(1); + EngineDebugger::get_script_debugger()->set_depth(-1); + EngineDebugger::get_script_debugger()->set_lines_left(1); return TRUE; default: return FALSE; diff --git a/platform/x11/detect_prime.cpp b/platform/x11/detect_prime.cpp index 98a51ff27c..a0e5f835c0 100644 --- a/platform/x11/detect_prime.cpp +++ b/platform/x11/detect_prime.cpp @@ -62,6 +62,7 @@ vendor vendormap[] = { { "NVIDIA Corporation", 30 }, { "X.Org", 30 }, { "Intel Open Source Technology Center", 20 }, + { "Intel", 20 }, { "nouveau", 10 }, { "Mesa Project", 0 }, { NULL, 0 } diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index c74981fd55..ddb5237d1b 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -2012,8 +2012,10 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { // is correct, but the xorg developers are // not very helpful today. - ::Time tresh = ABSDIFF(peek_event.xkey.time, xkeyevent->time); - if (peek_event.type == KeyPress && tresh < 5) { +#define ABSDIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y))) + ::Time threshold = ABSDIFF(peek_event.xkey.time, xkeyevent->time); +#undef ABSDIFF + if (peek_event.type == KeyPress && threshold < 5) { KeySym rk; XLookupString((XKeyEvent *)&peek_event, str, 256, &rk, NULL); if (rk == keysym_keycode) { diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index fbd9a2aa7d..ce1e75a61d 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -565,6 +565,27 @@ void AnimationNodeStateMachine::add_node(const StringName &p_name, Ref<Animation p_node->connect("tree_changed", callable_mp(this, &AnimationNodeStateMachine::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED); } +void AnimationNodeStateMachine::replace_node(const StringName &p_name, Ref<AnimationNode> p_node) { + + ERR_FAIL_COND(states.has(p_name) == false); + ERR_FAIL_COND(p_node.is_null()); + ERR_FAIL_COND(String(p_name).find("/") != -1); + + { + Ref<AnimationNode> node = states[p_name].node; + if (node.is_valid()) { + node->disconnect_compat("tree_changed", this, "_tree_changed"); + } + } + + states[p_name].node = p_node; + + emit_changed(); + emit_signal("tree_changed"); + + p_node->connect_compat("tree_changed", this, "_tree_changed", varray(), CONNECT_REFERENCE_COUNTED); +} + Ref<AnimationNode> AnimationNodeStateMachine::get_node(const StringName &p_name) const { ERR_FAIL_COND_V(!states.has(p_name), Ref<AnimationNode>()); @@ -949,6 +970,7 @@ void AnimationNodeStateMachine::_tree_changed() { void AnimationNodeStateMachine::_bind_methods() { ClassDB::bind_method(D_METHOD("add_node", "name", "node", "position"), &AnimationNodeStateMachine::add_node, DEFVAL(Vector2())); + ClassDB::bind_method(D_METHOD("replace_node", "name", "node"), &AnimationNodeStateMachine::replace_node); ClassDB::bind_method(D_METHOD("get_node", "name"), &AnimationNodeStateMachine::get_node); ClassDB::bind_method(D_METHOD("remove_node", "name"), &AnimationNodeStateMachine::remove_node); ClassDB::bind_method(D_METHOD("rename_node", "name", "new_name"), &AnimationNodeStateMachine::rename_node); diff --git a/scene/animation/animation_node_state_machine.h b/scene/animation/animation_node_state_machine.h index 55c9c3f00e..27a4451f08 100644 --- a/scene/animation/animation_node_state_machine.h +++ b/scene/animation/animation_node_state_machine.h @@ -178,6 +178,7 @@ public: virtual Variant get_parameter_default_value(const StringName &p_parameter) const; void add_node(const StringName &p_name, Ref<AnimationNode> p_node, const Vector2 &p_position = Vector2()); + void replace_node(const StringName &p_name, Ref<AnimationNode> p_node); Ref<AnimationNode> get_node(const StringName &p_name) const; void remove_node(const StringName &p_name); void rename_node(const StringName &p_name, const StringName &p_new_name); diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 22ff0611a7..2a98b4cf22 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -30,8 +30,9 @@ #include "scene_debugger.h" +#include "core/debugger/engine_debugger.h" #include "core/io/marshalls.h" -#include "core/script_debugger_remote.h" +#include "core/script_language.h" #include "scene/main/scene_tree.h" #include "scene/main/viewport.h" #include "scene/resources/packed_scene.h" @@ -39,13 +40,16 @@ void SceneDebugger::initialize() { #ifdef DEBUG_ENABLED LiveEditor::singleton = memnew(LiveEditor); - ScriptDebuggerRemote::scene_tree_parse_func = SceneDebugger::parse_message; + EngineDebugger::register_message_capture("scene", EngineDebugger::Capture(NULL, SceneDebugger::parse_message)); #endif } void SceneDebugger::deinitialize() { #ifdef DEBUG_ENABLED if (LiveEditor::singleton) { + // Should be removed automatically when deiniting debugger, but just in case + if (EngineDebugger::has_capture("scene")) + EngineDebugger::unregister_message_capture("scene"); memdelete(LiveEditor::singleton); LiveEditor::singleton = NULL; } @@ -53,13 +57,15 @@ void SceneDebugger::deinitialize() { } #ifdef DEBUG_ENABLED -Error SceneDebugger::parse_message(const String &p_msg, const Array &p_args) { +Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured) { SceneTree *scene_tree = SceneTree::get_singleton(); if (!scene_tree) return ERR_UNCONFIGURED; LiveEditor *live_editor = LiveEditor::get_singleton(); if (!live_editor) return ERR_UNCONFIGURED; + + r_captured = true; if (p_msg == "request_scene_tree") { // Scene tree live_editor->_send_tree(); @@ -171,7 +177,7 @@ Error SceneDebugger::parse_message(const String &p_msg, const Array &p_args) { ERR_FAIL_COND_V(p_args.size() < 4, ERR_INVALID_DATA); live_editor->_reparent_node_func(p_args[0], p_args[1], p_args[2], p_args[3]); } else { - return ERR_SKIP; + r_captured = false; } return OK; } @@ -180,7 +186,6 @@ void SceneDebugger::_save_node(ObjectID id, const String &p_path) { Node *node = Object::cast_to<Node>(ObjectDB::get_instance(id)); ERR_FAIL_COND(!node); - WARN_PRINT("SAVING " + itos(id) + " TO " + p_path); Ref<PackedScene> ps = memnew(PackedScene); ps->pack(node); ResourceSaver::save(p_path, ps); @@ -193,7 +198,7 @@ void SceneDebugger::_send_object_id(ObjectID p_id, int p_max_size) { Array arr; obj.serialize(arr); - ScriptDebugger::get_singleton()->send_message("inspect_object", arr); + EngineDebugger::get_singleton()->send_message("scene:inspect_object", arr); } void SceneDebugger::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) { @@ -216,7 +221,7 @@ void SceneDebugger::add_to_cache(const String &p_filename, Node *p_node) { if (!debugger) return; - if (ScriptDebugger::get_singleton() && p_filename != String()) { + if (EngineDebugger::get_script_debugger() && p_filename != String()) { debugger->live_scene_edit_cache[p_filename].insert(p_node); } } @@ -487,7 +492,7 @@ void LiveEditor::_send_tree() { // Encoded as a flat list depth fist. SceneDebuggerTree tree(scene_tree->root); tree.serialize(arr); - ScriptDebugger::get_singleton()->send_message("scene_tree", arr); + EngineDebugger::get_singleton()->send_message("scene:scene_tree", arr); } void LiveEditor::_node_path_func(const NodePath &p_path, int p_id) { diff --git a/scene/debugger/scene_debugger.h b/scene/debugger/scene_debugger.h index d22f8e8e18..afe58a5d01 100644 --- a/scene/debugger/scene_debugger.h +++ b/scene/debugger/scene_debugger.h @@ -34,9 +34,10 @@ #include "core/array.h" #include "core/object.h" #include "core/pair.h" -#include "core/script_language.h" #include "core/ustring.h" +class Script; + class SceneDebugger { public: @@ -50,7 +51,7 @@ private: static void _send_object_id(ObjectID p_id, int p_max_size = 1 << 20); public: - static Error parse_message(const String &p_msg, const Array &p_args); + static Error parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured); static void add_to_cache(const String &p_filename, Node *p_node); static void remove_from_cache(const String &p_filename, Node *p_node); #endif diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 5e925bf37f..06691d09be 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1856,6 +1856,7 @@ void TextEdit::_consume_pair_symbol(CharType ch) { bool in_single_quote = false; bool in_double_quote = false; + bool found_comment = false; int c = 0; while (c < line.length()) { @@ -1865,6 +1866,9 @@ void TextEdit::_consume_pair_symbol(CharType ch) { if (cursor.column == c) { break; } + } else if (!in_single_quote && !in_double_quote && line[c] == '#') { + found_comment = true; + break; } else { if (line[c] == '\'' && !in_double_quote) { in_single_quote = !in_single_quote; @@ -1880,7 +1884,15 @@ void TextEdit::_consume_pair_symbol(CharType ch) { } } - // Disallow inserting duplicated quotes while already in string + // Do not need to duplicate quotes while in comments + if (found_comment) { + insert_text_at_cursor(ch_single); + cursor_set_column(cursor_position_to_move); + + return; + } + + // Disallow inserting duplicated quotes while already in string if ((in_single_quote || in_double_quote) && (ch == '"' || ch == '\'')) { insert_text_at_cursor(ch_single); cursor_set_column(cursor_position_to_move); @@ -2517,13 +2529,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { String new_word = get_word_at_pos(mm->get_position()); if (new_word != highlighted_word) { - highlighted_word = new_word; - update(); + emit_signal("symbol_validate", new_word); } } else { if (highlighted_word != String()) { - highlighted_word = String(); - update(); + set_highlighted_word(String()); } } } @@ -2572,13 +2582,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (select_identifiers_enabled) { if (k->is_pressed() && !dragging_minimap && !dragging_selection) { - - highlighted_word = get_word_at_pos(get_local_mouse_position()); - update(); - + emit_signal("symbol_validate", get_word_at_pos(get_local_mouse_position())); } else { - highlighted_word = String(); - update(); + set_highlighted_word(String()); } } } @@ -6996,6 +7002,11 @@ void TextEdit::menu_option(int p_option) { } } +void TextEdit::set_highlighted_word(const String &new_word) { + highlighted_word = new_word; + update(); +} + void TextEdit::set_select_identifiers_on_hover(bool p_enable) { select_identifiers_enabled = p_enable; @@ -7213,6 +7224,7 @@ void TextEdit::_bind_methods() { ADD_SIGNAL(MethodInfo("breakpoint_toggled", PropertyInfo(Variant::INT, "row"))); ADD_SIGNAL(MethodInfo("symbol_lookup", PropertyInfo(Variant::STRING, "symbol"), PropertyInfo(Variant::INT, "row"), PropertyInfo(Variant::INT, "column"))); ADD_SIGNAL(MethodInfo("info_clicked", PropertyInfo(Variant::INT, "row"), PropertyInfo(Variant::STRING, "info"))); + ADD_SIGNAL(MethodInfo("symbol_validate", PropertyInfo(Variant::STRING, "symbol"))); BIND_ENUM_CONSTANT(MENU_CUT); BIND_ENUM_CONSTANT(MENU_COPY); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 6e267f5a47..3c9d1a5c85 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -585,6 +585,7 @@ public: bool is_insert_text_operation(); + void set_highlighted_word(const String &new_word); void set_text(String p_text); void insert_text_at_cursor(const String &p_text); void insert_at(const String &p_text, int at); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 370cf6a2a4..57bb3b6b5e 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -30,6 +30,7 @@ #include "scene_tree.h" +#include "core/debugger/engine_debugger.h" #include "core/io/marshalls.h" #include "core/io/resource_loader.h" #include "core/message_queue.h" @@ -38,7 +39,6 @@ #include "core/os/os.h" #include "core/print_string.h" #include "core/project_settings.h" -#include "core/script_debugger_remote.h" #include "main/input_default.h" #include "node.h" #include "scene/debugger/scene_debugger.h" @@ -432,11 +432,11 @@ void SceneTree::input_event(const Ref<InputEvent> &p_event) { call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_input", ev); //special one for GUI, as controls use their own process check - if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_remote()) { + if (EngineDebugger::is_active()) { //quit from game window using F8 Ref<InputEventKey> k = ev; if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == KEY_F8) { - ScriptDebugger::get_singleton()->request_quit(); + EngineDebugger::get_singleton()->send_message("request_quit", Array()); } } @@ -1737,10 +1737,6 @@ SceneTree::SceneTree() { last_screen_size = Size2(OS::get_singleton()->get_window_size().width, OS::get_singleton()->get_window_size().height); _update_root_rect(); - if (ScriptDebugger::get_singleton()) { - ScriptDebugger::get_singleton()->set_multiplayer(multiplayer); - } - root->set_physics_object_picking(GLOBAL_DEF("physics/common/enable_object_picking", true)); #ifdef TOOLS_ENABLED diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index e027ec9b4b..c11b11bc71 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -31,6 +31,7 @@ #include "viewport.h" #include "core/core_string_names.h" +#include "core/debugger/engine_debugger.h" #include "core/os/input.h" #include "core/os/os.h" #include "core/project_settings.h" @@ -1927,12 +1928,12 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { mb->set_position(pos); #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && gui.mouse_focus) { + if (EngineDebugger::get_singleton() && gui.mouse_focus) { Array arr; arr.push_back(gui.mouse_focus->get_path()); arr.push_back(gui.mouse_focus->get_class()); - ScriptDebugger::get_singleton()->send_message("click_ctrl", arr); + EngineDebugger::get_singleton()->send_message("scene:click_ctrl", arr); } #endif diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp index ed25729c40..a68b750b31 100644 --- a/scene/resources/audio_stream_sample.cpp +++ b/scene/resources/audio_stream_sample.cpp @@ -258,7 +258,7 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in float srate = base->mix_rate; srate *= p_rate_scale; float fincrement = srate / base_rate; - int32_t increment = int32_t(fincrement * MIX_FRAC_LEN); + int32_t increment = int32_t(MAX(fincrement * MIX_FRAC_LEN, 1)); increment *= sign; //looping diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index a063b7f74f..5e032c41bf 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -252,10 +252,12 @@ Ref<Shape> Mesh::create_trimesh_shape() const { Vector<Vector3> face_points; face_points.resize(faces.size() * 3); - for (int i = 0; i < face_points.size(); i++) { + for (int i = 0; i < face_points.size(); i += 3) { Face3 f = faces.get(i / 3); - face_points.set(i, f.vertex[i % 3]); + face_points.set(i, f.vertex[0]); + face_points.set(i + 1, f.vertex[1]); + face_points.set(i + 2, f.vertex[2]); } Ref<ConcavePolygonShape> shape = memnew(ConcavePolygonShape); @@ -543,15 +545,9 @@ Vector<Ref<Shape> > Mesh::convex_decompose() const { ERR_FAIL_COND_V(!convex_composition_function, Vector<Ref<Shape> >()); - Vector<Face3> faces = get_faces(); - Vector<Face3> f3; - f3.resize(faces.size()); - const Face3 *f = faces.ptr(); - for (int i = 0; i < f3.size(); i++) { - f3.write[i] = f[i]; - } + const Vector<Face3> faces = get_faces(); - Vector<Vector<Face3> > decomposed = convex_composition_function(f3); + Vector<Vector<Face3> > decomposed = convex_composition_function(faces); Vector<Ref<Shape> > ret; diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index 00fc016ca1..959ee214a2 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -150,7 +150,7 @@ Array PrimitiveMesh::surface_get_blend_shape_arrays(int p_surface) const { uint32_t PrimitiveMesh::surface_get_format(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, 1, 0); - return VS::ARRAY_COMPRESS_DEFAULT; + return VS::ARRAY_FORMAT_VERTEX | VS::ARRAY_FORMAT_NORMAL | VS::ARRAY_FORMAT_TANGENT | VS::ARRAY_FORMAT_TEX_UV | VS::ARRAY_FORMAT_INDEX | VS::ARRAY_COMPRESS_DEFAULT; } Mesh::PrimitiveType PrimitiveMesh::surface_get_primitive_type(int p_idx) const { diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index caee5f5db5..0e68c8a543 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -30,6 +30,7 @@ #include "audio_server.h" +#include "core/debugger/engine_debugger.h" #include "core/io/resource_loader.h" #include "core/os/file_access.h" #include "core/os/os.h" @@ -992,7 +993,7 @@ void AudioServer::init() { void AudioServer::update() { #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) { + if (EngineDebugger::is_profiling("servers")) { // Driver time includes server time + effects times // Server time includes effects times @@ -1030,7 +1031,8 @@ void AudioServer::update() { values.push_back("audio_driver"); values.push_back(USEC_TO_SEC(driver_time)); - ScriptDebugger::get_singleton()->add_profiling_frame_data("audio_thread", values); + values.push_front("audio_thread"); + EngineDebugger::profiler_add_frame_data("servers", values); } // Reset profiling times diff --git a/servers/navigation_2d_server.h b/servers/navigation_2d_server.h index 955b0c3726..7b0b9fbb01 100644 --- a/servers/navigation_2d_server.h +++ b/servers/navigation_2d_server.h @@ -49,7 +49,7 @@ protected: static void _bind_methods(); public: - /// Thread safe, can be used accross many threads. + /// Thread safe, can be used across many threads. static const Navigation2DServer *get_singleton() { return singleton; } /// MUST be used in single thread! diff --git a/servers/navigation_server.h b/servers/navigation_server.h index 7c9b6ba595..546e543db3 100644 --- a/servers/navigation_server.h +++ b/servers/navigation_server.h @@ -54,7 +54,7 @@ protected: static void _bind_methods(); public: - /// Thread safe, can be used accross many threads. + /// Thread safe, can be used across many threads. static const NavigationServer *get_singleton(); /// MUST be used in single thread! diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 6024e9ab7f..25b21a5394 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -32,8 +32,8 @@ #include "broad_phase_basic.h" #include "broad_phase_octree.h" +#include "core/debugger/engine_debugger.h" #include "core/os/os.h" -#include "core/script_language.h" #include "joints/cone_twist_joint_sw.h" #include "joints/generic_6dof_joint_sw.h" #include "joints/hinge_joint_sw.h" @@ -1467,7 +1467,7 @@ void PhysicsServerSW::flush_queries() { flushing_queries = false; - if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) { + if (EngineDebugger::is_profiling("servers")) { uint64_t total_time[SpaceSW::ELAPSED_TIME_MAX]; static const char *time_name[SpaceSW::ELAPSED_TIME_MAX] = { @@ -1498,7 +1498,8 @@ void PhysicsServerSW::flush_queries() { values.push_back("flush_queries"); values.push_back(USEC_TO_SEC(OS::get_singleton()->get_ticks_usec() - time_beg)); - ScriptDebugger::get_singleton()->add_profiling_frame_data("physics", values); + values.push_front("physics"); + EngineDebugger::profiler_add_frame_data("server", values); } #endif }; diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index aa374aa6bc..baeb3f76b0 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -32,9 +32,9 @@ #include "broad_phase_2d_basic.h" #include "broad_phase_2d_hash_grid.h" #include "collision_solver_2d_sw.h" +#include "core/debugger/engine_debugger.h" #include "core/os/os.h" #include "core/project_settings.h" -#include "core/script_language.h" #define FLUSH_QUERY_CHECK(m_object) \ ERR_FAIL_COND_MSG(m_object->get_space() && flushing_queries, "Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead."); @@ -1369,7 +1369,7 @@ void Physics2DServerSW::flush_queries() { flushing_queries = false; - if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) { + if (EngineDebugger::is_profiling("servers")) { uint64_t total_time[Space2DSW::ELAPSED_TIME_MAX]; static const char *time_name[Space2DSW::ELAPSED_TIME_MAX] = { @@ -1400,7 +1400,8 @@ void Physics2DServerSW::flush_queries() { values.push_back("flush_queries"); values.push_back(USEC_TO_SEC(OS::get_singleton()->get_ticks_usec() - time_beg)); - ScriptDebugger::get_singleton()->add_profiling_frame_data("physics_2d", values); + values.push_front("physics_2d"); + EngineDebugger::profiler_add_frame_data("servers", values); } } diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index c9f5277a4d..fd65f57380 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -56,7 +56,6 @@ #include "audio_server.h" #include "camera/camera_feed.h" #include "camera_server.h" -#include "core/script_debugger_remote.h" #include "navigation_2d_server.h" #include "navigation_server.h" #include "physics/physics_server_sw.h" @@ -67,27 +66,6 @@ #include "visual/shader_types.h" #include "visual_server.h" -static void _debugger_get_resource_usage(ScriptDebuggerRemote::ResourceUsage *r_usage) { - - List<VS::TextureInfo> tinfo; - VS::get_singleton()->texture_debug_usage(&tinfo); - - for (List<VS::TextureInfo>::Element *E = tinfo.front(); E; E = E->next()) { - - ScriptDebuggerRemote::ResourceInfo usage; - usage.path = E->get().path; - usage.vram = E->get().bytes; - usage.id = E->get().texture; - usage.type = "Texture"; - if (E->get().depth == 0) { - usage.format = itos(E->get().width) + "x" + itos(E->get().height) + " " + Image::get_format_name(E->get().format); - } else { - usage.format = itos(E->get().width) + "x" + itos(E->get().height) + "x" + itos(E->get().depth) + " " + Image::get_format_name(E->get().format); - } - r_usage->infos.push_back(usage); - } -} - ShaderTypes *shader_types = NULL; PhysicsServer *_createGodotPhysicsCallback() { @@ -189,8 +167,6 @@ void register_server_types() { ClassDB::register_virtual_class<PhysicsDirectSpaceState>(); ClassDB::register_virtual_class<PhysicsShapeQueryResult>(); - ScriptDebuggerRemote::resource_usage_func = _debugger_get_resource_usage; - // Physics 2D GLOBAL_DEF(Physics2DServerManager::setting_property_name, "DEFAULT"); ProjectSettings::get_singleton()->set_custom_property_info(Physics2DServerManager::setting_property_name, PropertyInfo(Variant::STRING, Physics2DServerManager::setting_property_name, PROPERTY_HINT_ENUM, "DEFAULT")); diff --git a/servers/visual/rasterizer_rd/rasterizer_canvas_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_canvas_rd.cpp index 78fff0c381..38b1e3b3a6 100644 --- a/servers/visual/rasterizer_rd/rasterizer_canvas_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_canvas_rd.cpp @@ -2242,14 +2242,14 @@ RasterizerCanvasRD::RasterizerCanvasRD(RasterizerStorageRD *p_storage) { //non light variants variants.push_back(""); //none by default is first variant variants.push_back("#define USE_NINEPATCH\n"); //ninepatch is the second variant - variants.push_back("#define USE_PRIMITIVE\n"); //primitve is the third + variants.push_back("#define USE_PRIMITIVE\n"); //primitive is the third variants.push_back("#define USE_PRIMITIVE\n#define USE_POINT_SIZE\n"); //points need point size variants.push_back("#define USE_ATTRIBUTES\n"); // attributes for vertex arrays variants.push_back("#define USE_ATTRIBUTES\n#define USE_POINT_SIZE\n"); //attributes with point size //light variants variants.push_back("#define USE_LIGHTING\n"); //none by default is first variant variants.push_back("#define USE_LIGHTING\n#define USE_NINEPATCH\n"); //ninepatch is the second variant - variants.push_back("#define USE_LIGHTING\n#define USE_PRIMITIVE\n"); //primitve is the third + variants.push_back("#define USE_LIGHTING\n#define USE_PRIMITIVE\n"); //primitive is the third variants.push_back("#define USE_LIGHTING\n#define USE_PRIMITIVE\n#define USE_POINT_SIZE\n"); //points need point size variants.push_back("#define USE_LIGHTING\n#define USE_ATTRIBUTES\n"); // attributes for vertex arrays variants.push_back("#define USE_LIGHTING\n#define USE_ATTRIBUTES\n#define USE_POINT_SIZE\n"); //attributes with point size diff --git a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp index 52cefa7511..850acbf554 100644 --- a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp @@ -3938,7 +3938,7 @@ void RasterizerStorageRD::_update_render_target(RenderTarget *rt) { if (rt->size.width == 0 || rt->size.height == 0) { return; } - //until we implement suport for HDR monitors (and render target is attached to screen), this is enough. + //until we implement support for HDR monitors (and render target is attached to screen), this is enough. rt->color_format = RD::DATA_FORMAT_R8G8B8A8_UNORM; rt->color_format_srgb = RD::DATA_FORMAT_R8G8B8A8_SRGB; rt->image_format = rt->flags[RENDER_TARGET_TRANSPARENT] ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8; diff --git a/servers/visual/rasterizer_rd/shaders/canvas.glsl b/servers/visual/rasterizer_rd/shaders/canvas.glsl index 57e9451e48..28135fce31 100644 --- a/servers/visual/rasterizer_rd/shaders/canvas.glsl +++ b/servers/visual/rasterizer_rd/shaders/canvas.glsl @@ -416,7 +416,7 @@ FRAGMENT_SHADER_CODE vec4 base_color = color; if (bool(draw_data.flags & FLAGS_USING_LIGHT_MASK)) { - color = vec4(0.0); //inivisible by default due to using light mask + color = vec4(0.0); //invisible by default due to using light mask } color *= canvas_data.canvas_modulation; diff --git a/servers/visual/rendering_device.h b/servers/visual/rendering_device.h index c3b937d5e2..1ff169f102 100644 --- a/servers/visual/rendering_device.h +++ b/servers/visual/rendering_device.h @@ -418,7 +418,7 @@ public: virtual RID texture_create_shared_from_slice(const TextureView &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, TextureSliceType p_slice_type = TEXTURE_SLICE_2D) = 0; - virtual Error texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, bool p_sync_with_draw = false) = 0; //this function can be used from any thread and it takes effect at the begining of the frame, unless sync with draw is used, which is used to mix updates with draw calls + virtual Error texture_update(RID p_texture, uint32_t p_layer, const Vector<uint8_t> &p_data, bool p_sync_with_draw = false) = 0; //this function can be used from any thread and it takes effect at the beginning of the frame, unless sync with draw is used, which is used to mix updates with draw calls virtual Vector<uint8_t> texture_get_data(RID p_texture, uint32_t p_layer) = 0; // CPU textures will return immediately, while GPU textures will most likely force a flush virtual bool texture_is_format_supported_for_usage(DataFormat p_format, uint32_t p_usage) const = 0; @@ -621,7 +621,7 @@ public: virtual RID uniform_set_create(const Vector<Uniform> &p_uniforms, RID p_shader, uint32_t p_shader_set) = 0; virtual bool uniform_set_is_valid(RID p_uniform_set) = 0; - virtual Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, bool p_sync_with_draw = false) = 0; //this function can be used from any thread and it takes effect at the begining of the frame, unless sync with draw is used, which is used to mix updates with draw calls + virtual Error buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const void *p_data, bool p_sync_with_draw = false) = 0; //this function can be used from any thread and it takes effect at the beginning of the frame, unless sync with draw is used, which is used to mix updates with draw calls virtual Vector<uint8_t> buffer_get_data(RID p_buffer) = 0; //this causes stall, only use to retrieve large buffers for saving /*************************/ @@ -643,7 +643,7 @@ public: RENDER_PRIMITIVE_MAX }; - //disable optimization, tesselate control points + //disable optimization, tessellate control points enum PolygonCullMode { POLYGON_CULL_DISABLED, @@ -907,7 +907,7 @@ public: enum InitialAction { INITIAL_ACTION_CLEAR, //start rendering and clear the framebuffer (supply params) INITIAL_ACTION_KEEP, //start rendering, but keep attached color texture contents (depth will be cleared) - INITIAL_ACTION_CONTINUE, //continue rendering (framebuffer must have been left in "continue" state as final action prevously) + INITIAL_ACTION_CONTINUE, //continue rendering (framebuffer must have been left in "continue" state as final action previously) INITIAL_ACTION_MAX }; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index ed3feccb43..e32e7c093a 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -2198,6 +2198,14 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p valid = true; break; } + if (b->parent_function) { + for (int i = 0; i < b->parent_function->arguments.size(); i++) { + if (b->parent_function->arguments[i].name == var_name) { + valid = true; + break; + } + } + } b = b->parent_block; } @@ -4346,7 +4354,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons } } - //consecutively do unary opeators + //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { OperatorNode *op = alloc_node<OperatorNode>(); diff --git a/thirdparty/README.md b/thirdparty/README.md index 0602d2a1d1..b52b68fe47 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -32,7 +32,7 @@ Files extracted from upstream source: Files extracted from upstream source: -- `.cpp` and `.h` files in root folder +- `.cpp` and `.h` files in root folder except for `basisu_tool.cpp` (contains `main` and can cause link error) - `.cpp`, `.h` and `.inc` files in `transcoder/`, keeping folder structure - `LICENSE` @@ -312,6 +312,9 @@ File extracted from upstream release tarball (`-apache.tgz` variant): - LICENSE and apache-2.0.txt files - Applied the patch in `thirdparty/mbedtls/patches/1453.diff` (PR 1453). Soon to be merged upstream. Check it out at next update. +- Applied the patch in `thirdparty/mbedtls/patches/padlock.diff`. This disables + VIA padlock support which defines a symbol `unsupported` which clashes with + a pre-defined symbol. - Added 2 files `godot_core_mbedtls_platform.{c,h}` providing configuration for light bundling with core. diff --git a/thirdparty/basis_universal/basisu_tool.cpp b/thirdparty/basis_universal/basisu_tool.cpp deleted file mode 100644 index 8172a8c5cc..0000000000 --- a/thirdparty/basis_universal/basisu_tool.cpp +++ /dev/null @@ -1,1548 +0,0 @@ -// basisu_tool.cpp -// Copyright (C) 2019 Binomial LLC. All Rights Reserved. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#include "transcoder/basisu.h" -#include "transcoder/basisu_transcoder_internal.h" -#include "basisu_enc.h" -#include "basisu_etc.h" -#include "basisu_gpu_texture.h" -#include "basisu_frontend.h" -#include "basisu_backend.h" -#include "transcoder/basisu_global_selector_palette.h" -#include "basisu_comp.h" -#include "transcoder/basisu_transcoder.h" -#include "basisu_ssim.h" - -#define BASISU_CATCH_EXCEPTIONS 1 - -using namespace basisu; - -#define BASISU_TOOL_VERSION "1.10.00" - -enum tool_mode -{ - cDefault, - cCompress, - cValidate, - cUnpack, - cCompare, - cVersion, -}; - -static void print_usage() -{ - printf("\nUsage: basisu filename [filename ...] <options>\n"); - - puts("\n" - "The default mode is compression of one or more PNG files to a .basis file. Alternate modes:\n" - " -unpack: Use transcoder to unpack .basis file to one or more .ktx/.png files\n" - " -validate: Validate and display information about a .basis file\n" - " -compare: Compare two PNG images specified with -file, output PSNR and SSIM statistics and RGB/A delta images\n" - " -version: Print basisu version and exit\n" - "Unless an explicit mode is specified, if one or more files have the .basis extension this tool defaults to unpack mode.\n" - "\n" - "Important: By default, the compressor assumes the input is in the sRGB colorspace (like photos/albedo textures).\n" - "If the input is NOT sRGB (like a normal map), be sure to specify -linear for less artifacts. Depending on the content type, some experimentation may be needed.\n" - "\n" - "Filenames prefixed with a @ symbol are read as filename listing files. Listing text files specify which actual filenames to process (one filename per line).\n" - "\n" - "Options:\n" - " -file filename.png: Input image filename, multiple images are OK, use -file X for each input filename (prefixing input filenames with -file is optional)\n" - " -alpha_file filename.png: Input alpha image filename, multiple images are OK, use -file X for each input filename (must be paired with -file), images converted to REC709 grayscale and used as input alpha\n" - " -multifile_printf: printf() format strint to use to compose multiple filenames\n" - " -multifile_first: The index of the first file to process, default is 0 (must specify -multifile_printf and -multifile_num)\n" - " -multifile_num: The total number of files to process.\n" - " -q X: Set quality level, 1-255, default is 128, lower=better compression/lower quality/faster, higher=less compression/higher quality/slower, default is 128. For even higher quality, use -max_endpoints/-max_selectors.\n" - " -linear: Use linear colorspace metrics (instead of the default sRGB), and by default linear (not sRGB) mipmap filtering.\n" - " -output_file filename: Output .basis/.ktx filename\n" - " -output_path: Output .basis/.ktx files to specified directory.\n" - " -debug: Enable codec debug print to stdout (slightly slower).\n" - " -debug_images: Enable codec debug images (much slower).\n" - " -stats: Compute and display image quality metrics (slightly slower).\n" - " -tex_type <2d, 2darray, 3d, video, cubemap>: Set Basis file header's texture type field. Cubemap arrays require multiples of 6 images, in X+, X-, Y+, Y-, Z+, Z- order, each image must be the same resolutions.\n" - " 2d=arbitrary 2D images, 2darray=2D array, 3D=volume texture slices, video=video frames, cubemap=array of faces. For 2darray/3d/cubemaps/video, each source image's dimensions and # of mipmap levels must be the same.\n" - " For video, the .basis file will be written with the first frame being an I-Frame, and subsequent frames being P-Frames (using conditional replenishment). Playback must always occur in order from first to last image.\n" - " -framerate X: Set framerate in header to X/frames sec.\n" - " -individual: Process input images individually and output multiple .basis files (not as a texture array)\n" - " -comp_level X: Set encoding speed vs. quality tradeoff. Range is 0-5, default is 1. Higher values=MUCH slower, but slightly higher quality. Mostly intended for videos. Use -q first!\n" - " -fuzz_testing: Use with -validate: Disables CRC16 validation of file contents before transcoding\n" - "\n" - "More options:\n" - " -max_endpoints X: Manually set the max number of color endpoint clusters from 1-16128, use instead of -q\n" - " -max_selectors X: Manually set the max number of color selector clusters from 1-16128, use instead of -q\n" - " -y_flip: Flip input images vertically before compression\n" - " -normal_map: Tunes codec parameters for better quality on normal maps (linear colorspace metrics, linear mipmap filtering, no selector RDO, no sRGB)\n" - " -no_alpha: Always output non-alpha basis files, even if one or more inputs has alpha\n" - " -force_alpha: Always output alpha basis files, even if no inputs has alpha\n" - " -separate_rg_to_color_alpha: Separate input R and G channels to RGB and A (for tangent space XY normal maps)\n" - " -no_multithreading: Disable multithreading\n" - " -no_ktx: Disable KTX writing when unpacking (faster)\n" - " -etc1_only: Only unpack to ETC1, skipping the other texture formats during -unpack\n" - " -disable_hierarchical_endpoint_codebooks: Disable hierarchical endpoint codebook usage, slower but higher quality on some compression levels\n" - " -compare_ssim: Compute and display SSIM of image comparison (slow)\n" - "\n" - "Mipmap generation options:\n" - " -mipmap: Generate mipmaps for each source image\n" - " -mip_srgb: Convert image to linear before filtering, then back to sRGB\n" - " -mip_linear: Keep image in linear light during mipmap filtering\n" - " -mip_scale X: Set mipmap filter kernel's scale, lower=sharper, higher=more blurry, default is 1.0\n" - " -mip_filter X: Set mipmap filter kernel, default is kaiser, filters: box, tent, bell, blackman, catmullrom, mitchell, etc.\n" - " -mip_renorm: Renormalize normal map to unit length vectors after filtering\n" - " -mip_clamp: Use clamp addressing on borders, instead of wrapping\n" - " -mip_smallest X: Set smallest pixel dimension for generated mipmaps, default is 1 pixel\n" - "By default, mipmap filtering will occur in sRGB space (for the RGB color channels) unless -linear is specified. You can override this behavior with -mip_srgb/-mip_linear.\n" - "\n" - "Backend endpoint/selector RDO codec options:\n" - " -no_selector_rdo: Disable backend's selector rate distortion optimizations (slightly faster, less noisy output, but lower quality per output bit)\n" - " -selector_rdo_thresh X: Set selector RDO quality threshold, default is 1.25, lower is higher quality but less quality per output bit (try 1.0-3.0)\n" - " -no_endpoint_rdo: Disable backend's endpoint rate distortion optimizations (slightly faster, less noisy output, but lower quality per output bit)\n" - " -endpoint_rdo_thresh X: Set endpoint RDO quality threshold, default is 1.5, lower is higher quality but less quality per output bit (try 1.0-3.0)\n" - "\n" - "Hierarchical virtual selector codebook options:\n" - " -global_sel_pal: Always use vitual selector palettes (instead of custom palettes), slightly smaller files, but lower quality, slower encoding\n" - " -auto_global_sel_pal: Automatically use virtual selector palettes on small images for slightly smaller files (defaults to off for faster encoding time)\n" - " -no_hybrid_sel_cb: Don't automatically use hybrid virtual selector codebooks (for higher quality, only active when -global_sel_pal is specified)\n" - " -global_pal_bits X: Set virtual selector codebook palette bits, range is [0,12], default is 8, higher is slower/better quality\n" - " -global_mod_bits X: Set virtual selector codebook modifier bits, range is [0,15], defualt is 8, higher is slower/better quality\n" - " -hybrid_sel_cb_quality_thresh X: Set hybrid selector codebook quality threshold, default is 2.0, try 1.5-3, higher is lower quality/smaller codebooks\n" - "\n" - "Set various fields in the Basis file header:\n" - " -userdata0 X: Set 32-bit userdata0 field in Basis file header to X (X is a signed 32-bit int)\n" - " -userdata1 X: Set 32-bit userdata1 field in Basis file header to X (X is a signed 32-bit int)\n" - "\n" - "Various command line examples:\n" - " basisu x.png : Compress sRGB image x.png to x.basis using default settings (multiple filenames OK)\n" - " basisu x.basis : Unpack x.basis to PNG/KTX files (multiple filenames OK)\n" - " basisu -file x.png -mipmap -y_flip : Compress a mipmapped x.basis file from an sRGB image named x.png, Y flip each source image\n" - " basisu -validate -file x.basis : Validate x.basis (check header, check file CRC's, attempt to transcode all slices)\n" - " basisu -unpack -file x.basis : Validates, transcodes and unpacks x.basis to mipmapped .KTX and RGB/A .PNG files (transcodes to all supported GPU texture formats)\n" - " basisu -q 255 -file x.png -mipmap -debug -stats : Compress sRGB x.png to x.basis at quality level 255 with compressor debug output/statistics\n" - " basisu -linear -max_endpoints 16128 -max_selectors 16128 -file x.png : Compress non-sRGB x.png to x.basis using the largest supported manually specified codebook sizes\n" - " basisu -linear -global_sel_pal -no_hybrid_sel_cb -file x.png : Compress a non-sRGB image, use virtual selector codebooks for improved compression (but slower encoding)\n" - " basisu -linear -global_sel_pal -file x.png: Compress a non-sRGB image, use hybrid selector codebooks for slightly improved compression (but slower encoding)\n" - " basisu -tex_type video -framerate 20 -multifile_printf \"x%02u.png\" -multifile_first 1 -multifile_count 20 : Compress a 20 sRGB source image video sequence (x01.png, x02.png, x03.png, etc.) to x01.basis\n" - "\n" - "Note: For video use, it's recommended you use a very powerful machine with many cores. Use -slower for better codebook generation, specify very large codebooks using -max_endpoints and -max_selectors, and reduce\n" - "the default endpoint RDO threshold (-endpoint_rdo_thresh) to around 1.25. Videos may have mipmaps and alpha channels. Videos must always be played back by the transcoder in first to last image order.\n" - "Video files currently use I-Frames on the first image, and P-Frames using conditional replenishment on subsequent frames.\n" - "Compression level details:\n" - " Level 0: Fastest, but has marginal quality and is a work in progress. Brittle on complex images. Avg. Y dB: 35.45\n" - " Level 1: Hierarchical codebook searching. 36.87 dB, ~1.4x slower vs. level 0. (This is the default setting.)\n" - " Level 2: Full codebook searching. 37.13 dB, ~1.8x slower vs. level 0. (Equivalent the the initial release's default settings.)\n" - " Level 3: Hierarchical codebook searching, codebook k-means iterations. 37.15 dB, ~4x slower vs. level 0\n" - " Level 4: Full codebook searching, codebook k-means iterations. 37.41 dB, ~5.5x slower vs. level 0. (Equivalent to the initial release's -slower setting.)\n" - " Level 5: Full codebook searching, twice as many codebook k-means iterations, best ETC1 endpoint opt. 37.43 dB, ~12x slower vs. level 0\n" - ); -} - -static bool load_listing_file(const std::string &f, std::vector<std::string> &filenames) -{ - std::string filename(f); - filename.erase(0, 1); - - FILE *pFile = nullptr; -#ifdef _WIN32 - fopen_s(&pFile, filename.c_str(), "r"); -#else - pFile = fopen(filename.c_str(), "r"); -#endif - - if (!pFile) - { - error_printf("Failed opening listing file: \"%s\"\n", filename.c_str()); - return false; - } - - uint32_t total_filenames = 0; - - for ( ; ; ) - { - char buf[3072]; - buf[0] = '\0'; - - char *p = fgets(buf, sizeof(buf), pFile); - if (!p) - { - if (ferror(pFile)) - { - error_printf("Failed reading from listing file: \"%s\"\n", filename.c_str()); - - fclose(pFile); - return false; - } - else - break; - } - - std::string read_filename(p); - while (read_filename.size()) - { - if (read_filename[0] == ' ') - read_filename.erase(0, 1); - else - break; - } - - while (read_filename.size()) - { - const char c = read_filename.back(); - if ((c == ' ') || (c == '\n') || (c == '\r')) - read_filename.erase(read_filename.size() - 1, 1); - else - break; - } - - if (read_filename.size()) - { - filenames.push_back(read_filename); - total_filenames++; - } - } - - fclose(pFile); - - printf("Successfully read %u filenames(s) from listing file \"%s\"\n", total_filenames, filename.c_str()); - - return true; -} - -class command_line_params -{ - BASISU_NO_EQUALS_OR_COPY_CONSTRUCT(command_line_params); - -public: - command_line_params() : - m_mode(cDefault), - m_multifile_first(0), - m_multifile_num(0), - m_individual(false), - m_no_ktx(false), - m_etc1_only(false), - m_fuzz_testing(false), - m_compare_ssim(false) - { - } - - bool parse(int arg_c, const char **arg_v) - { - int arg_index = 1; - while (arg_index < arg_c) - { - const char *pArg = arg_v[arg_index]; - const int num_remaining_args = arg_c - (arg_index + 1); - int arg_count = 1; - -#define REMAINING_ARGS_CHECK(n) if (num_remaining_args < (n)) { error_printf("Error: Expected %u values to follow %s!\n", n, pArg); return false; } - - if (strcasecmp(pArg, "-compress") == 0) - m_mode = cCompress; - else if (strcasecmp(pArg, "-compare") == 0) - m_mode = cCompare; - else if (strcasecmp(pArg, "-unpack") == 0) - m_mode = cUnpack; - else if (strcasecmp(pArg, "-validate") == 0) - m_mode = cValidate; - else if (strcasecmp(pArg, "-version") == 0) - m_mode = cVersion; - else if (strcasecmp(pArg, "-compare_ssim") == 0) - m_compare_ssim = true; - else if (strcasecmp(pArg, "-file") == 0) - { - REMAINING_ARGS_CHECK(1); - m_input_filenames.push_back(std::string(arg_v[arg_index + 1])); - arg_count++; - } - else if (strcasecmp(pArg, "-alpha_file") == 0) - { - REMAINING_ARGS_CHECK(1); - m_input_alpha_filenames.push_back(std::string(arg_v[arg_index + 1])); - arg_count++; - } - else if (strcasecmp(pArg, "-multifile_printf") == 0) - { - REMAINING_ARGS_CHECK(1); - m_multifile_printf = std::string(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-multifile_first") == 0) - { - REMAINING_ARGS_CHECK(1); - m_multifile_first = atoi(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-multifile_num") == 0) - { - REMAINING_ARGS_CHECK(1); - m_multifile_num = atoi(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-linear") == 0) - m_comp_params.m_perceptual = false; - else if (strcasecmp(pArg, "-srgb") == 0) - m_comp_params.m_perceptual = true; - else if (strcasecmp(pArg, "-q") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_quality_level = clamp<int>(atoi(arg_v[arg_index + 1]), BASISU_QUALITY_MIN, BASISU_QUALITY_MAX); - arg_count++; - } - else if (strcasecmp(pArg, "-output_file") == 0) - { - REMAINING_ARGS_CHECK(1); - m_output_filename = arg_v[arg_index + 1]; - arg_count++; - } - else if (strcasecmp(pArg, "-output_path") == 0) - { - REMAINING_ARGS_CHECK(1); - m_output_path = arg_v[arg_index + 1]; - arg_count++; - } - else if (strcasecmp(pArg, "-debug") == 0) - { - m_comp_params.m_debug = true; - enable_debug_printf(true); - } - else if (strcasecmp(pArg, "-debug_images") == 0) - m_comp_params.m_debug_images = true; - else if (strcasecmp(pArg, "-stats") == 0) - m_comp_params.m_compute_stats = true; - else if (strcasecmp(pArg, "-comp_level") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_compression_level = atoi(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-slower") == 0) - { - // This option is gone, but we'll do something reasonable with it anyway. Level 4 is equivalent to the original release's -slower, but let's just go to level 2. - m_comp_params.m_compression_level = 2; - } - else if (strcasecmp(pArg, "-max_endpoints") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_max_endpoint_clusters = clamp<int>(atoi(arg_v[arg_index + 1]), 1, BASISU_MAX_ENDPOINT_CLUSTERS); - arg_count++; - } - else if (strcasecmp(pArg, "-max_selectors") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_max_selector_clusters = clamp<int>(atoi(arg_v[arg_index + 1]), 1, BASISU_MAX_SELECTOR_CLUSTERS); - arg_count++; - } - else if (strcasecmp(pArg, "-y_flip") == 0) - m_comp_params.m_y_flip = true; - else if (strcasecmp(pArg, "-normal_map") == 0) - { - m_comp_params.m_perceptual = false; - m_comp_params.m_mip_srgb = false; - m_comp_params.m_no_selector_rdo = true; - m_comp_params.m_no_endpoint_rdo = true; - } - else if (strcasecmp(pArg, "-no_alpha") == 0) - m_comp_params.m_check_for_alpha = false; - else if (strcasecmp(pArg, "-force_alpha") == 0) - m_comp_params.m_force_alpha = true; - else if ((strcasecmp(pArg, "-separate_rg_to_color_alpha") == 0) || - (strcasecmp(pArg, "-seperate_rg_to_color_alpha") == 0)) // was mispelled for a while - whoops! - m_comp_params.m_seperate_rg_to_color_alpha = true; - else if (strcasecmp(pArg, "-no_multithreading") == 0) - { - m_comp_params.m_multithreading = false; - } - else if (strcasecmp(pArg, "-mipmap") == 0) - m_comp_params.m_mip_gen = true; - else if (strcasecmp(pArg, "-no_ktx") == 0) - m_no_ktx = true; - else if (strcasecmp(pArg, "-etc1_only") == 0) - m_etc1_only = true; - else if (strcasecmp(pArg, "-disable_hierarchical_endpoint_codebooks") == 0) - m_comp_params.m_disable_hierarchical_endpoint_codebooks = true; - else if (strcasecmp(pArg, "-mip_scale") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_mip_scale = (float)atof(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-mip_filter") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_mip_filter = arg_v[arg_index + 1]; - // TODO: Check filter - arg_count++; - } - else if (strcasecmp(pArg, "-mip_renorm") == 0) - m_comp_params.m_mip_renormalize = true; - else if (strcasecmp(pArg, "-mip_clamp") == 0) - m_comp_params.m_mip_wrapping = false; - else if (strcasecmp(pArg, "-mip_smallest") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_mip_smallest_dimension = atoi(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-mip_srgb") == 0) - m_comp_params.m_mip_srgb = true; - else if (strcasecmp(pArg, "-mip_linear") == 0) - m_comp_params.m_mip_srgb = false; - else if (strcasecmp(pArg, "-no_selector_rdo") == 0) - m_comp_params.m_no_selector_rdo = true; - else if (strcasecmp(pArg, "-selector_rdo_thresh") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_selector_rdo_thresh = (float)atof(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-no_endpoint_rdo") == 0) - m_comp_params.m_no_endpoint_rdo = true; - else if (strcasecmp(pArg, "-endpoint_rdo_thresh") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_endpoint_rdo_thresh = (float)atof(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-global_sel_pal") == 0) - m_comp_params.m_global_sel_pal = true; - else if (strcasecmp(pArg, "-no_auto_global_sel_pal") == 0) - m_comp_params.m_auto_global_sel_pal = false; - else if (strcasecmp(pArg, "-auto_global_sel_pal") == 0) - m_comp_params.m_auto_global_sel_pal = true; - else if (strcasecmp(pArg, "-global_pal_bits") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_global_pal_bits = atoi(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-global_mod_bits") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_global_mod_bits = atoi(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-no_hybrid_sel_cb") == 0) - m_comp_params.m_no_hybrid_sel_cb = true; - else if (strcasecmp(pArg, "-hybrid_sel_cb_quality_thresh") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_hybrid_sel_cb_quality_thresh = (float)atof(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-userdata0") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_userdata0 = atoi(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-userdata1") == 0) - { - REMAINING_ARGS_CHECK(1); - m_comp_params.m_userdata1 = atoi(arg_v[arg_index + 1]); - arg_count++; - } - else if (strcasecmp(pArg, "-framerate") == 0) - { - REMAINING_ARGS_CHECK(1); - double fps = atof(arg_v[arg_index + 1]); - double us_per_frame = 0; - if (fps > 0) - us_per_frame = 1000000.0f / fps; - - m_comp_params.m_us_per_frame = clamp<int>(static_cast<int>(us_per_frame + .5f), 0, basist::cBASISMaxUSPerFrame); - arg_count++; - } - else if (strcasecmp(pArg, "-tex_type") == 0) - { - REMAINING_ARGS_CHECK(1); - const char *pType = arg_v[arg_index + 1]; - if (strcasecmp(pType, "2d") == 0) - m_comp_params.m_tex_type = basist::cBASISTexType2D; - else if (strcasecmp(pType, "2darray") == 0) - m_comp_params.m_tex_type = basist::cBASISTexType2DArray; - else if (strcasecmp(pType, "3d") == 0) - m_comp_params.m_tex_type = basist::cBASISTexTypeVolume; - else if (strcasecmp(pType, "cubemap") == 0) - m_comp_params.m_tex_type = basist::cBASISTexTypeCubemapArray; - else if (strcasecmp(pType, "video") == 0) - m_comp_params.m_tex_type = basist::cBASISTexTypeVideoFrames; - else - { - error_printf("Invalid texture type: %s\n", pType); - return false; - } - arg_count++; - } - else if (strcasecmp(pArg, "-individual") == 0) - m_individual = true; - else if (strcasecmp(pArg, "-fuzz_testing") == 0) - m_fuzz_testing = true; - else if (strcasecmp(pArg, "-csv_file") == 0) - { - REMAINING_ARGS_CHECK(1); - m_csv_file = arg_v[arg_index + 1]; - m_comp_params.m_compute_stats = true; - - arg_count++; - } - else if (pArg[0] == '-') - { - error_printf("Unrecognized command line option: %s\n", pArg); - return false; - } - else - { - // Let's assume it's a source filename, so globbing works - //error_printf("Unrecognized command line option: %s\n", pArg); - m_input_filenames.push_back(pArg); - } - - arg_index += arg_count; - } - - if (m_comp_params.m_quality_level != -1) - { - m_comp_params.m_max_endpoint_clusters = 0; - m_comp_params.m_max_selector_clusters = 0; - } - else if ((!m_comp_params.m_max_endpoint_clusters) || (!m_comp_params.m_max_selector_clusters)) - { - m_comp_params.m_max_endpoint_clusters = 0; - m_comp_params.m_max_selector_clusters = 0; - - m_comp_params.m_quality_level = 128; - } - - if (!m_comp_params.m_mip_srgb.was_changed()) - { - // They didn't specify what colorspace to do mipmap filtering in, so choose sRGB if they've specified that the texture is sRGB. - if (m_comp_params.m_perceptual) - m_comp_params.m_mip_srgb = true; - else - m_comp_params.m_mip_srgb = false; - } - - return true; - } - - bool process_listing_files() - { - std::vector<std::string> new_input_filenames; - for (uint32_t i = 0; i < m_input_filenames.size(); i++) - { - if (m_input_filenames[i][0] == '@') - { - if (!load_listing_file(m_input_filenames[i], new_input_filenames)) - return false; - } - else - new_input_filenames.push_back(m_input_filenames[i]); - } - new_input_filenames.swap(m_input_filenames); - - std::vector<std::string> new_input_alpha_filenames; - for (uint32_t i = 0; i < m_input_alpha_filenames.size(); i++) - { - if (m_input_alpha_filenames[i][0] == '@') - { - if (!load_listing_file(m_input_alpha_filenames[i], new_input_alpha_filenames)) - return false; - } - else - new_input_alpha_filenames.push_back(m_input_alpha_filenames[i]); - } - new_input_alpha_filenames.swap(m_input_alpha_filenames); - - return true; - } - - basis_compressor_params m_comp_params; - - tool_mode m_mode; - - std::vector<std::string> m_input_filenames; - std::vector<std::string> m_input_alpha_filenames; - - std::string m_output_filename; - std::string m_output_path; - - std::string m_multifile_printf; - uint32_t m_multifile_first; - uint32_t m_multifile_num; - - std::string m_csv_file; - - bool m_individual; - bool m_no_ktx; - bool m_etc1_only; - bool m_fuzz_testing; - bool m_compare_ssim; -}; - -static bool expand_multifile(command_line_params &opts) -{ - if (!opts.m_multifile_printf.size()) - return true; - - if (!opts.m_multifile_num) - { - error_printf("-multifile_printf specified, but not -multifile_num\n"); - return false; - } - - std::string fmt(opts.m_multifile_printf); - size_t x = fmt.find_first_of('!'); - if (x != std::string::npos) - fmt[x] = '%'; - - if (string_find_right(fmt, '%') == -1) - { - error_printf("Must include C-style printf() format character '%%' in -multifile_printf string\n"); - return false; - } - - for (uint32_t i = opts.m_multifile_first; i < opts.m_multifile_first + opts.m_multifile_num; i++) - { - char buf[1024]; -#ifdef _WIN32 - sprintf_s(buf, sizeof(buf), fmt.c_str(), i); -#else - snprintf(buf, sizeof(buf), fmt.c_str(), i); -#endif - - if (buf[0]) - opts.m_input_filenames.push_back(buf); - } - - return true; -} - -static bool compress_mode(command_line_params &opts) -{ - basist::etc1_global_selector_codebook sel_codebook(basist::g_global_selector_cb_size, basist::g_global_selector_cb); - - uint32_t num_threads = 1; - - if (opts.m_comp_params.m_multithreading) - { - num_threads = std::thread::hardware_concurrency(); - if (num_threads < 1) - num_threads = 1; - } - - job_pool jpool(num_threads); - opts.m_comp_params.m_pJob_pool = &jpool; - - if (!expand_multifile(opts)) - { - error_printf("-multifile expansion failed!\n"); - return false; - } - - if (!opts.m_input_filenames.size()) - { - error_printf("No input files to process!\n"); - return false; - } - - basis_compressor_params ¶ms = opts.m_comp_params; - - params.m_read_source_images = true; - params.m_write_output_basis_files = true; - params.m_pSel_codebook = &sel_codebook; - - FILE *pCSV_file = nullptr; - if (opts.m_csv_file.size()) - { - pCSV_file = fopen_safe(opts.m_csv_file.c_str(), "a"); - if (!pCSV_file) - { - error_printf("Failed opening CVS file \"%s\"\n", opts.m_csv_file.c_str()); - return false; - } - } - - printf("Processing %u total files\n", (uint32_t)opts.m_input_filenames.size()); - - for (size_t file_index = 0; file_index < (opts.m_individual ? opts.m_input_filenames.size() : 1U); file_index++) - { - if (opts.m_individual) - { - params.m_source_filenames.resize(1); - params.m_source_filenames[0] = opts.m_input_filenames[file_index]; - - if (file_index < opts.m_input_alpha_filenames.size()) - { - params.m_source_alpha_filenames.resize(1); - params.m_source_alpha_filenames[0] = opts.m_input_alpha_filenames[file_index]; - - printf("Processing source file \"%s\", alpha file \"%s\"\n", params.m_source_filenames[0].c_str(), params.m_source_alpha_filenames[0].c_str()); - } - else - { - params.m_source_alpha_filenames.resize(0); - - printf("Processing source file \"%s\"\n", params.m_source_filenames[0].c_str()); - } - } - else - { - params.m_source_filenames = opts.m_input_filenames; - params.m_source_alpha_filenames = opts.m_input_alpha_filenames; - } - - if ((opts.m_output_filename.size()) && (!opts.m_individual)) - params.m_out_filename = opts.m_output_filename; - else - { - std::string filename; - - string_get_filename(opts.m_input_filenames[file_index].c_str(), filename); - string_remove_extension(filename); - filename += ".basis"; - - if (opts.m_output_path.size()) - string_combine_path(filename, opts.m_output_path.c_str(), filename.c_str()); - - params.m_out_filename = filename; - } - - basis_compressor c; - - if (!c.init(opts.m_comp_params)) - { - error_printf("basis_compressor::init() failed!\n"); - - if (pCSV_file) - { - fclose(pCSV_file); - pCSV_file = nullptr; - } - - return false; - } - - interval_timer tm; - tm.start(); - - basis_compressor::error_code ec = c.process(); - - tm.stop(); - - if (ec == basis_compressor::cECSuccess) - { - printf("Compression succeeded to file \"%s\" in %3.3f secs\n", params.m_out_filename.c_str(), tm.get_elapsed_secs()); - } - else - { - bool exit_flag = true; - - switch (ec) - { - case basis_compressor::cECFailedReadingSourceImages: - { - error_printf("Compressor failed reading a source image!\n"); - - if (opts.m_individual) - exit_flag = false; - - break; - } - case basis_compressor::cECFailedValidating: - error_printf("Compressor failed 2darray/cubemap/video validation checks!\n"); - break; - case basis_compressor::cECFailedFrontEnd: - error_printf("Compressor frontend stage failed!\n"); - break; - case basis_compressor::cECFailedFontendExtract: - error_printf("Compressor frontend data extraction failed!\n"); - break; - case basis_compressor::cECFailedBackend: - error_printf("Compressor backend stage failed!\n"); - break; - case basis_compressor::cECFailedCreateBasisFile: - error_printf("Compressor failed creating Basis file data!\n"); - break; - case basis_compressor::cECFailedWritingOutput: - error_printf("Compressor failed writing to output Basis file!\n"); - break; - default: - error_printf("basis_compress::process() failed!\n"); - break; - } - - if (exit_flag) - { - if (pCSV_file) - { - fclose(pCSV_file); - pCSV_file = nullptr; - } - - return false; - } - } - - if ((pCSV_file) && (c.get_stats().size())) - { - for (size_t slice_index = 0; slice_index < c.get_stats().size(); slice_index++) - { - fprintf(pCSV_file, "\"%s\", %u, %u, %u, %u, %u, %f, %f, %f, %f, %u, %u, %f\n", - params.m_out_filename.c_str(), - (uint32_t)slice_index, (uint32_t)c.get_stats().size(), - c.get_stats()[slice_index].m_width, c.get_stats()[slice_index].m_height, (uint32_t)c.get_any_source_image_has_alpha(), - c.get_basis_bits_per_texel(), - c.get_stats()[slice_index].m_best_luma_709_psnr, - c.get_stats()[slice_index].m_basis_etc1s_luma_709_psnr, - c.get_stats()[slice_index].m_basis_bc1_luma_709_psnr, - params.m_quality_level, (int)params.m_compression_level, tm.get_elapsed_secs()); - fflush(pCSV_file); - } - } - - if (opts.m_individual) - printf("\n"); - - } // file_index - - if (pCSV_file) - { - fclose(pCSV_file); - pCSV_file = nullptr; - } - - return true; -} - -static bool unpack_and_validate_mode(command_line_params &opts, bool validate_flag) -{ - basist::etc1_global_selector_codebook sel_codebook(basist::g_global_selector_cb_size, basist::g_global_selector_cb); - - if (!opts.m_input_filenames.size()) - { - error_printf("No input files to process!\n"); - return false; - } - - uint32_t total_unpack_warnings = 0; - uint32_t total_pvrtc_nonpow2_warnings = 0; - - for (uint32_t file_index = 0; file_index < opts.m_input_filenames.size(); file_index++) - { - const char* pInput_filename = opts.m_input_filenames[file_index].c_str(); - - std::string base_filename; - string_split_path(pInput_filename, nullptr, nullptr, &base_filename, nullptr); - - uint8_vec basis_data; - if (!basisu::read_file_to_vec(pInput_filename, basis_data)) - { - error_printf("Failed reading file \"%s\"\n", pInput_filename); - return false; - } - - printf("Input file \"%s\"\n", pInput_filename); - - if (!basis_data.size()) - { - error_printf("File is empty!\n"); - return false; - } - - if (basis_data.size() > UINT32_MAX) - { - error_printf("File is too large!\n"); - return false; - } - - basist::basisu_transcoder dec(&sel_codebook); - - if (!opts.m_fuzz_testing) - { - // Skip the full validation, which CRC16's the entire file. - - // Validate the file - note this isn't necessary for transcoding - if (!dec.validate_file_checksums(&basis_data[0], (uint32_t)basis_data.size(), true)) - { - error_printf("File version is unsupported, or file fail CRC checks!\n"); - return false; - } - } - - printf("File version and CRC checks succeeded\n"); - - basist::basisu_file_info fileinfo; - if (!dec.get_file_info(&basis_data[0], (uint32_t)basis_data.size(), fileinfo)) - { - error_printf("Failed retrieving Basis file information!\n"); - return false; - } - - assert(fileinfo.m_total_images == fileinfo.m_image_mipmap_levels.size()); - assert(fileinfo.m_total_images == dec.get_total_images(&basis_data[0], (uint32_t)basis_data.size())); - - printf("File info:\n"); - printf(" Version: %X\n", fileinfo.m_version); - printf(" Total header size: %u\n", fileinfo.m_total_header_size); - printf(" Total selectors: %u\n", fileinfo.m_total_selectors); - printf(" Selector codebook size: %u\n", fileinfo.m_selector_codebook_size); - printf(" Total endpoints: %u\n", fileinfo.m_total_endpoints); - printf(" Endpoint codebook size: %u\n", fileinfo.m_endpoint_codebook_size); - printf(" Tables size: %u\n", fileinfo.m_tables_size); - printf(" Slices size: %u\n", fileinfo.m_slices_size); - printf(" Texture type: %s\n", basist::basis_get_texture_type_name(fileinfo.m_tex_type)); - printf(" us per frame: %u (%f fps)\n", fileinfo.m_us_per_frame, fileinfo.m_us_per_frame ? (1.0f / ((float)fileinfo.m_us_per_frame / 1000000.0f)) : 0.0f); - printf(" Total slices: %u\n", (uint32_t)fileinfo.m_slice_info.size()); - printf(" Total images: %i\n", fileinfo.m_total_images); - printf(" Y Flipped: %u, Has alpha slices: %u\n", fileinfo.m_y_flipped, fileinfo.m_has_alpha_slices); - printf(" userdata0: 0x%X userdata1: 0x%X\n", fileinfo.m_userdata0, fileinfo.m_userdata1); - printf(" Per-image mipmap levels: "); - for (uint32_t i = 0; i < fileinfo.m_total_images; i++) - printf("%u ", fileinfo.m_image_mipmap_levels[i]); - printf("\n"); - - printf("\nImage info:\n"); - for (uint32_t i = 0; i < fileinfo.m_total_images; i++) - { - basist::basisu_image_info ii; - if (!dec.get_image_info(&basis_data[0], (uint32_t)basis_data.size(), ii, i)) - { - error_printf("get_image_info() failed!\n"); - return false; - } - - printf("Image %u: MipLevels: %u OrigDim: %ux%u, BlockDim: %ux%u, FirstSlice: %u, HasAlpha: %u\n", i, ii.m_total_levels, ii.m_orig_width, ii.m_orig_height, - ii.m_num_blocks_x, ii.m_num_blocks_y, ii.m_first_slice_index, (uint32_t)ii.m_alpha_flag); - } - - printf("\nSlice info:\n"); - for (uint32_t i = 0; i < fileinfo.m_slice_info.size(); i++) - { - const basist::basisu_slice_info& sliceinfo = fileinfo.m_slice_info[i]; - printf("%u: OrigWidthHeight: %ux%u, BlockDim: %ux%u, TotalBlocks: %u, Compressed size: %u, Image: %u, Level: %u, UnpackedCRC16: 0x%X, alpha: %u, iframe: %i\n", - i, - sliceinfo.m_orig_width, sliceinfo.m_orig_height, - sliceinfo.m_num_blocks_x, sliceinfo.m_num_blocks_y, - sliceinfo.m_total_blocks, - sliceinfo.m_compressed_size, - sliceinfo.m_image_index, sliceinfo.m_level_index, - sliceinfo.m_unpacked_slice_crc16, - (uint32_t)sliceinfo.m_alpha_flag, - (uint32_t)sliceinfo.m_iframe_flag); - } - printf("\n"); - - interval_timer tm; - tm.start(); - - if (!dec.start_transcoding(&basis_data[0], (uint32_t)basis_data.size())) - { - error_printf("start_transcoding() failed!\n"); - return false; - } - - printf("start_transcoding time: %3.3f ms\n", tm.get_elapsed_ms()); - - std::vector< gpu_image_vec > gpu_images[(int)basist::transcoder_texture_format::cTFTotalTextureFormats]; - - int first_format = 0; - int last_format = (int)basist::transcoder_texture_format::cTFTotalTextureFormats; - - if (opts.m_etc1_only) - { - first_format = (int)basist::transcoder_texture_format::cTFETC1_RGB; - last_format = first_format + 1; - } - - for (int format_iter = first_format; format_iter < last_format; format_iter++) - { - basist::transcoder_texture_format tex_fmt = static_cast<basist::transcoder_texture_format>(format_iter); - - if (basist::basis_transcoder_format_is_uncompressed(tex_fmt)) - continue; - - gpu_images[(int)tex_fmt].resize(fileinfo.m_total_images); - - for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++) - gpu_images[(int)tex_fmt][image_index].resize(fileinfo.m_image_mipmap_levels[image_index]); - } - - // Now transcode the file to all supported texture formats and save mipmapped KTX files - for (int format_iter = first_format; format_iter < last_format; format_iter++) - { - const basist::transcoder_texture_format transcoder_tex_fmt = static_cast<basist::transcoder_texture_format>(format_iter); - - if (basist::basis_transcoder_format_is_uncompressed(transcoder_tex_fmt)) - continue; - - for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++) - { - for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++) - { - basist::basisu_image_level_info level_info; - - if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index)) - { - error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index); - return false; - } - - if ((transcoder_tex_fmt == basist::transcoder_texture_format::cTFPVRTC1_4_RGB) || (transcoder_tex_fmt == basist::transcoder_texture_format::cTFPVRTC1_4_RGBA)) - { - if (!is_pow2(level_info.m_width) || !is_pow2(level_info.m_height)) - { - total_pvrtc_nonpow2_warnings++; - - printf("Warning: Will not transcode image %u level %u res %ux%u to PVRTC1 (one or more dimension is not a power of 2)\n", image_index, level_index, level_info.m_width, level_info.m_height); - - // Can't transcode this image level to PVRTC because it's not a pow2 (we're going to support transcoding non-pow2 to the next larger pow2 soon) - continue; - } - } - - basisu::texture_format tex_fmt = basis_get_basisu_texture_format(transcoder_tex_fmt); - - gpu_image& gi = gpu_images[(int)transcoder_tex_fmt][image_index][level_index]; - gi.init(tex_fmt, level_info.m_orig_width, level_info.m_orig_height); - - // Fill the buffer with psuedo-random bytes, to help more visibly detect cases where the transcoder fails to write to part of the output. - fill_buffer_with_random_bytes(gi.get_ptr(), gi.get_size_in_bytes()); - - uint32_t decode_flags = 0; - - tm.start(); - - if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, gi.get_ptr(), gi.get_total_blocks(), transcoder_tex_fmt, decode_flags)) - { - error_printf("Failed transcoding image level (%u %u %u)!\n", image_index, level_index, format_iter); - return false; - } - - double total_transcode_time = tm.get_elapsed_ms(); - - printf("Transcode of image %u level %u res %ux%u format %s succeeded in %3.3f ms\n", image_index, level_index, level_info.m_orig_width, level_info.m_orig_height, basist::basis_get_format_name(transcoder_tex_fmt), total_transcode_time); - - } // format_iter - - } // level_index - - } // image_info - - if (!validate_flag) - { - // Now write KTX files and unpack them to individual PNG's - - for (int format_iter = first_format; format_iter < last_format; format_iter++) - { - const basist::transcoder_texture_format transcoder_tex_fmt = static_cast<basist::transcoder_texture_format>(format_iter); - - if (basist::basis_transcoder_format_is_uncompressed(transcoder_tex_fmt)) - continue; - - if ((!opts.m_no_ktx) && (fileinfo.m_tex_type == basist::cBASISTexTypeCubemapArray)) - { - // No KTX tool that we know of supports cubemap arrays, so write individual cubemap files. - for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index += 6) - { - std::vector<gpu_image_vec> cubemap; - for (uint32_t i = 0; i < 6; i++) - cubemap.push_back(gpu_images[format_iter][image_index + i]); - - std::string ktx_filename(base_filename + string_format("_transcoded_cubemap_%s_%u.ktx", basist::basis_get_format_name(transcoder_tex_fmt), image_index / 6)); - if (!write_compressed_texture_file(ktx_filename.c_str(), cubemap, true)) - { - error_printf("Failed writing KTX file \"%s\"!\n", ktx_filename.c_str()); - return false; - } - printf("Wrote KTX file \"%s\"\n", ktx_filename.c_str()); - } - } - - for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++) - { - gpu_image_vec& gi = gpu_images[format_iter][image_index]; - - if (!gi.size()) - continue; - - uint32_t level; - for (level = 0; level < gi.size(); level++) - if (!gi[level].get_total_blocks()) - break; - - if (level < gi.size()) - continue; - - if ((!opts.m_no_ktx) && (fileinfo.m_tex_type != basist::cBASISTexTypeCubemapArray)) - { - std::string ktx_filename(base_filename + string_format("_transcoded_%s_%04u.ktx", basist::basis_get_format_name(transcoder_tex_fmt), image_index)); - if (!write_compressed_texture_file(ktx_filename.c_str(), gi)) - { - error_printf("Failed writing KTX file \"%s\"!\n", ktx_filename.c_str()); - return false; - } - printf("Wrote KTX file \"%s\"\n", ktx_filename.c_str()); - } - - for (uint32_t level_index = 0; level_index < gi.size(); level_index++) - { - basist::basisu_image_level_info level_info; - - if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index)) - { - error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index); - return false; - } - - image u; - if (!gi[level_index].unpack(u)) - { - printf("Warning: Failed unpacking GPU texture data (%u %u %u). Unpacking as much as possible.\n", format_iter, image_index, level_index); - total_unpack_warnings++; - } - //u.crop(level_info.m_orig_width, level_info.m_orig_height); - - std::string rgb_filename; - if (gi.size() > 1) - rgb_filename = base_filename + string_format("_unpacked_rgb_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index); - else - rgb_filename = base_filename + string_format("_unpacked_rgb_%s_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), image_index); - if (!save_png(rgb_filename, u, cImageSaveIgnoreAlpha)) - { - error_printf("Failed writing to PNG file \"%s\"\n", rgb_filename.c_str()); - return false; - } - printf("Wrote PNG file \"%s\"\n", rgb_filename.c_str()); - - if (transcoder_tex_fmt == basist::transcoder_texture_format::cTFFXT1_RGB) - { - std::string out_filename; - if (gi.size() > 1) - out_filename = base_filename + string_format("_unpacked_rgb_%s_%u_%04u.out", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index); - else - out_filename = base_filename + string_format("_unpacked_rgb_%s_%04u.out", basist::basis_get_format_name(transcoder_tex_fmt), image_index); - if (!write_3dfx_out_file(out_filename.c_str(), gi[level_index])) - { - error_printf("Failed writing to OUT file \"%s\"\n", out_filename.c_str()); - return false; - } - printf("Wrote .OUT file \"%s\"\n", out_filename.c_str()); - } - - if (basis_transcoder_format_has_alpha(transcoder_tex_fmt)) - { - std::string a_filename; - if (gi.size() > 1) - a_filename = base_filename + string_format("_unpacked_a_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index); - else - a_filename = base_filename + string_format("_unpacked_a_%s_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), image_index); - if (!save_png(a_filename, u, cImageSaveGrayscale, 3)) - { - error_printf("Failed writing to PNG file \"%s\"\n", a_filename.c_str()); - return false; - } - printf("Wrote PNG file \"%s\"\n", a_filename.c_str()); - } - - } // level_index - - } // image_index - - } // format_iter - - } // if (!validate_flag) - - // Now unpack to RGBA using the transcoder itself to do the unpacking to raster images - for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++) - { - for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++) - { - const basist::transcoder_texture_format transcoder_tex_fmt = basist::transcoder_texture_format::cTFRGBA32; - - basist::basisu_image_level_info level_info; - - if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index)) - { - error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index); - return false; - } - - image img(level_info.m_orig_width, level_info.m_orig_height); - - fill_buffer_with_random_bytes(&img(0, 0), img.get_total_pixels() * sizeof(uint32_t)); - - tm.start(); - - if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, &img(0, 0).r, img.get_total_pixels(), transcoder_tex_fmt, 0, img.get_pitch(), nullptr, img.get_height())) - { - error_printf("Failed transcoding image level (%u %u %u)!\n", image_index, level_index, transcoder_tex_fmt); - return false; - } - - double total_transcode_time = tm.get_elapsed_ms(); - - printf("Transcode of image %u level %u res %ux%u format %s succeeded in %3.3f ms\n", image_index, level_index, level_info.m_orig_width, level_info.m_orig_height, basist::basis_get_format_name(transcoder_tex_fmt), total_transcode_time); - - std::string rgb_filename(base_filename + string_format("_unpacked_rgb_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index)); - if (!save_png(rgb_filename, img, cImageSaveIgnoreAlpha)) - { - error_printf("Failed writing to PNG file \"%s\"\n", rgb_filename.c_str()); - return false; - } - printf("Wrote PNG file \"%s\"\n", rgb_filename.c_str()); - - std::string a_filename(base_filename + string_format("_unpacked_a_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index)); - if (!save_png(a_filename, img, cImageSaveGrayscale, 3)) - { - error_printf("Failed writing to PNG file \"%s\"\n", a_filename.c_str()); - return false; - } - printf("Wrote PNG file \"%s\"\n", a_filename.c_str()); - - } // level_index - } // image_index - - // Now unpack to RGB565 using the transcoder itself to do the unpacking to raster images - for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++) - { - for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++) - { - const basist::transcoder_texture_format transcoder_tex_fmt = basist::transcoder_texture_format::cTFRGB565; - - basist::basisu_image_level_info level_info; - - if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index)) - { - error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index); - return false; - } - - std::vector<uint16_t> packed_img(level_info.m_orig_width * level_info.m_orig_height); - - fill_buffer_with_random_bytes(&packed_img[0], packed_img.size() * sizeof(uint16_t)); - - tm.start(); - - if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, &packed_img[0], (uint32_t)packed_img.size(), transcoder_tex_fmt, 0, level_info.m_orig_width, nullptr, level_info.m_orig_height)) - { - error_printf("Failed transcoding image level (%u %u %u)!\n", image_index, level_index, transcoder_tex_fmt); - return false; - } - - double total_transcode_time = tm.get_elapsed_ms(); - - image img(level_info.m_orig_width, level_info.m_orig_height); - for (uint32_t y = 0; y < level_info.m_orig_height; y++) - { - for (uint32_t x = 0; x < level_info.m_orig_width; x++) - { - const uint16_t p = packed_img[x + y * level_info.m_orig_width]; - uint32_t r = p >> 11, g = (p >> 5) & 63, b = p & 31; - r = (r << 3) | (r >> 2); - g = (g << 2) | (g >> 4); - b = (b << 3) | (b >> 2); - img(x, y).set(r, g, b, 255); - } - } - - printf("Transcode of image %u level %u res %ux%u format %s succeeded in %3.3f ms\n", image_index, level_index, level_info.m_orig_width, level_info.m_orig_height, basist::basis_get_format_name(transcoder_tex_fmt), total_transcode_time); - - std::string rgb_filename(base_filename + string_format("_unpacked_rgb_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index)); - if (!save_png(rgb_filename, img, cImageSaveIgnoreAlpha)) - { - error_printf("Failed writing to PNG file \"%s\"\n", rgb_filename.c_str()); - return false; - } - printf("Wrote PNG file \"%s\"\n", rgb_filename.c_str()); - - } // level_index - } // image_index - - // Now unpack to RGBA4444 using the transcoder itself to do the unpacking to raster images - for (uint32_t image_index = 0; image_index < fileinfo.m_total_images; image_index++) - { - for (uint32_t level_index = 0; level_index < fileinfo.m_image_mipmap_levels[image_index]; level_index++) - { - const basist::transcoder_texture_format transcoder_tex_fmt = basist::transcoder_texture_format::cTFRGBA4444; - - basist::basisu_image_level_info level_info; - - if (!dec.get_image_level_info(&basis_data[0], (uint32_t)basis_data.size(), level_info, image_index, level_index)) - { - error_printf("Failed retrieving image level information (%u %u)!\n", image_index, level_index); - return false; - } - - std::vector<uint16_t> packed_img(level_info.m_orig_width * level_info.m_orig_height); - - fill_buffer_with_random_bytes(&packed_img[0], packed_img.size() * sizeof(uint16_t)); - - tm.start(); - - if (!dec.transcode_image_level(&basis_data[0], (uint32_t)basis_data.size(), image_index, level_index, &packed_img[0], (uint32_t)packed_img.size(), transcoder_tex_fmt, 0, level_info.m_orig_width, nullptr, level_info.m_orig_height)) - { - error_printf("Failed transcoding image level (%u %u %u)!\n", image_index, level_index, transcoder_tex_fmt); - return false; - } - - double total_transcode_time = tm.get_elapsed_ms(); - - image img(level_info.m_orig_width, level_info.m_orig_height); - for (uint32_t y = 0; y < level_info.m_orig_height; y++) - { - for (uint32_t x = 0; x < level_info.m_orig_width; x++) - { - const uint16_t p = packed_img[x + y * level_info.m_orig_width]; - uint32_t r = p >> 12, g = (p >> 8) & 15, b = (p >> 4) & 15, a = p & 15; - r = (r << 4) | r; - g = (g << 4) | g; - b = (b << 4) | b; - a = (a << 4) | a; - img(x, y).set(r, g, b, a); - } - } - - printf("Transcode of image %u level %u res %ux%u format %s succeeded in %3.3f ms\n", image_index, level_index, level_info.m_orig_width, level_info.m_orig_height, basist::basis_get_format_name(transcoder_tex_fmt), total_transcode_time); - - std::string rgb_filename(base_filename + string_format("_unpacked_rgb_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index)); - if (!save_png(rgb_filename, img, cImageSaveIgnoreAlpha)) - { - error_printf("Failed writing to PNG file \"%s\"\n", rgb_filename.c_str()); - return false; - } - printf("Wrote PNG file \"%s\"\n", rgb_filename.c_str()); - - std::string a_filename(base_filename + string_format("_unpacked_a_%s_%u_%04u.png", basist::basis_get_format_name(transcoder_tex_fmt), level_index, image_index)); - if (!save_png(a_filename, img, cImageSaveGrayscale, 3)) - { - error_printf("Failed writing to PNG file \"%s\"\n", a_filename.c_str()); - return false; - } - printf("Wrote PNG file \"%s\"\n", a_filename.c_str()); - - } // level_index - } // image_index - - } // file_index - - if (total_pvrtc_nonpow2_warnings) - printf("Warning: %u images could not be transcoded to PVRTC1 because one or both dimensions were not a power of 2\n", total_pvrtc_nonpow2_warnings); - - if (total_unpack_warnings) - printf("ATTENTION: %u total images had invalid GPU texture data!\n", total_unpack_warnings); - else - printf("Success\n"); - - return true; -} - -static bool compare_mode(command_line_params &opts) -{ - if (opts.m_input_filenames.size() != 2) - { - error_printf("Must specify two PNG filenames using -file\n"); - return false; - } - - image a, b; - if (!load_png(opts.m_input_filenames[0].c_str(), a)) - { - error_printf("Failed loading image from file \"%s\"!\n", opts.m_input_filenames[0].c_str()); - return false; - } - - printf("Loaded \"%s\", %ux%u, has alpha: %u\n", opts.m_input_filenames[0].c_str(), a.get_width(), a.get_height(), a.has_alpha()); - - if (!load_png(opts.m_input_filenames[1].c_str(), b)) - { - error_printf("Failed loading image from file \"%s\"!\n", opts.m_input_filenames[1].c_str()); - return false; - } - - printf("Loaded \"%s\", %ux%u, has alpha: %u\n", opts.m_input_filenames[1].c_str(), b.get_width(), b.get_height(), b.has_alpha()); - - if ((a.get_width() != b.get_width()) || (a.get_height() != b.get_height())) - { - printf("Images don't have the same dimensions - cropping input images to smallest common dimensions\n"); - - uint32_t w = minimum(a.get_width(), b.get_width()); - uint32_t h = minimum(a.get_height(), b.get_height()); - - a.crop(w, h); - b.crop(w, h); - } - - printf("Comparison image res: %ux%u\n", a.get_width(), a.get_height()); - - image_metrics im; - im.calc(a, b, 0, 3); - im.print("RGB "); - - im.calc(a, b, 0, 1); - im.print("R "); - - im.calc(a, b, 1, 1); - im.print("G "); - - im.calc(a, b, 2, 1); - im.print("B "); - - im.calc(a, b, 0, 0); - im.print("Y 709 " ); - - im.calc(a, b, 0, 0, true, true); - im.print("Y 601 " ); - - if (opts.m_compare_ssim) - { - vec4F s_rgb(compute_ssim(a, b, false, false)); - - printf("R SSIM: %f\n", s_rgb[0]); - printf("G SSIM: %f\n", s_rgb[1]); - printf("B SSIM: %f\n", s_rgb[2]); - printf("RGB Avg SSIM: %f\n", (s_rgb[0] + s_rgb[1] + s_rgb[2]) / 3.0f); - printf("A SSIM: %f\n", s_rgb[3]); - - vec4F s_y_709(compute_ssim(a, b, true, false)); - printf("Y 709 SSIM: %f\n", s_y_709[0]); - - vec4F s_y_601(compute_ssim(a, b, true, true)); - printf("Y 601 SSIM: %f\n", s_y_601[0]); - } - - image delta_img(a.get_width(), a.get_height()); - - const int X = 2; - - for (uint32_t y = 0; y < a.get_height(); y++) - { - for (uint32_t x = 0; x < a.get_width(); x++) - { - color_rgba &d = delta_img(x, y); - - for (int c = 0; c < 4; c++) - d[c] = (uint8_t)clamp<int>((a(x, y)[c] - b(x, y)[c]) * X + 128, 0, 255); - } // x - } // y - - save_png("a_rgb.png", a, cImageSaveIgnoreAlpha); - save_png("a_alpha.png", a, cImageSaveGrayscale, 3); - printf("Wrote a_rgb.png and a_alpha.png\n"); - - save_png("b_rgb.png", b, cImageSaveIgnoreAlpha); - save_png("b_alpha.png", b, cImageSaveGrayscale, 3); - printf("Wrote b_rgb.png and b_alpha.png\n"); - - save_png("delta_img_rgb.png", delta_img, cImageSaveIgnoreAlpha); - printf("Wrote delta_img_rgb.png\n"); - - save_png("delta_img_a.png", delta_img, cImageSaveGrayscale, 3); - printf("Wrote delta_img_a.png\n"); - - return true; -} - -static int main_internal(int argc, const char **argv) -{ - printf("Basis Universal GPU Texture Compressor Reference Encoder v" BASISU_TOOL_VERSION ", Copyright (C) 2019 Binomial LLC, All rights reserved\n"); - - //interval_timer tm; - //tm.start(); - - basisu_encoder_init(); - - //printf("Encoder and transcoder libraries initialized in %3.3f ms\n", tm.get_elapsed_ms()); - -#if defined(DEBUG) || defined(_DEBUG) - printf("DEBUG build\n"); -#endif - - if (argc == 1) - { - print_usage(); - return EXIT_FAILURE; - } - - command_line_params opts; - if (!opts.parse(argc, argv)) - { - print_usage(); - return EXIT_FAILURE; - } - - if (!opts.process_listing_files()) - return EXIT_FAILURE; - - if (opts.m_mode == cDefault) - { - for (size_t i = 0; i < opts.m_input_filenames.size(); i++) - { - std::string ext(string_get_extension(opts.m_input_filenames[i])); - if (strcasecmp(ext.c_str(), "basis") == 0) - { - // If they haven't specified any modes, and they give us a .basis file, then assume they want to unpack it. - opts.m_mode = cUnpack; - break; - } - } - } - - bool status = false; - - switch (opts.m_mode) - { - case cDefault: - case cCompress: - status = compress_mode(opts); - break; - case cValidate: - status = unpack_and_validate_mode(opts, true); - break; - case cUnpack: - status = unpack_and_validate_mode(opts, false); - break; - case cCompare: - status = compare_mode(opts); - break; - case cVersion: - status = true; // We printed the version at the beginning of main_internal - break; - default: - assert(0); - break; - } - - return status ? EXIT_SUCCESS : EXIT_FAILURE; -} - -int main(int argc, const char **argv) -{ - int status = EXIT_FAILURE; - -#if BASISU_CATCH_EXCEPTIONS - try - { - status = main_internal(argc, argv); - } - catch (const std::exception &exc) - { - fprintf(stderr, "Fatal error: Caught exception \"%s\"\n", exc.what()); - } - catch (...) - { - fprintf(stderr, "Fatal error: Uncaught exception!\n"); - } -#else - status = main_internal(argc, argv); -#endif - - return status; -} diff --git a/thirdparty/mbedtls/include/mbedtls/config.h b/thirdparty/mbedtls/include/mbedtls/config.h index 834cced87f..8d9c31a504 100644 --- a/thirdparty/mbedtls/include/mbedtls/config.h +++ b/thirdparty/mbedtls/include/mbedtls/config.h @@ -2542,7 +2542,9 @@ * * This modules adds support for the VIA PadLock on x86. */ -#define MBEDTLS_PADLOCK_C +// -- GODOT start -- +// #define MBEDTLS_PADLOCK_C +// -- GODOT end -- /** * \def MBEDTLS_PEM_PARSE_C diff --git a/thirdparty/mbedtls/library/entropy_poll.c b/thirdparty/mbedtls/library/entropy_poll.c index 4556f88a55..ba56b70f77 100644 --- a/thirdparty/mbedtls/library/entropy_poll.c +++ b/thirdparty/mbedtls/library/entropy_poll.c @@ -61,28 +61,43 @@ #define _WIN32_WINNT 0x0400 #endif #include <windows.h> -#include <wincrypt.h> +#include <bcrypt.h> +#if defined(_MSC_VER) && _MSC_VER <= 1600 +/* Visual Studio 2010 and earlier issue a warning when both <stdint.h> and + * <intsafe.h> are included, as they redefine a number of <TYPE>_MAX constants. + * These constants are guaranteed to be the same, though, so we suppress the + * warning when including intsafe.h. + */ +#pragma warning( push ) +#pragma warning( disable : 4005 ) +#endif +#include <intsafe.h> +#if defined(_MSC_VER) && _MSC_VER <= 1600 +#pragma warning( pop ) +#endif int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len, size_t *olen ) { - HCRYPTPROV provider; + ULONG len_as_ulong = 0; ((void) data); *olen = 0; - if( CryptAcquireContext( &provider, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE ) + /* + * BCryptGenRandom takes ULONG for size, which is smaller than size_t on + * 64-bit Windows platforms. Ensure len's value can be safely converted into + * a ULONG. + */ + if ( FAILED( SizeTToULong( len, &len_as_ulong ) ) ) { return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); } - if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE ) + if ( !BCRYPT_SUCCESS( BCryptGenRandom( NULL, output, len_as_ulong, BCRYPT_USE_SYSTEM_PREFERRED_RNG ) ) ) { - CryptReleaseContext( provider, 0 ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); } - CryptReleaseContext( provider, 0 ); *olen = len; return( 0 ); diff --git a/thirdparty/mbedtls/library/x509_crt.c b/thirdparty/mbedtls/library/x509_crt.c index 9c2e36547e..a3697f13f9 100644 --- a/thirdparty/mbedtls/library/x509_crt.c +++ b/thirdparty/mbedtls/library/x509_crt.c @@ -65,6 +65,19 @@ #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) #include <windows.h> +#if defined(_MSC_VER) && _MSC_VER <= 1600 +/* Visual Studio 2010 and earlier issue a warning when both <stdint.h> and + * <intsafe.h> are included, as they redefine a number of <TYPE>_MAX constants. + * These constants are guaranteed to be the same, though, so we suppress the + * warning when including intsafe.h. + */ +#pragma warning( push ) +#pragma warning( disable : 4005 ) +#endif +#include <intsafe.h> +#if defined(_MSC_VER) && _MSC_VER <= 1600 +#pragma warning( pop ) +#endif #else #include <time.h> #endif @@ -1277,6 +1290,7 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path ) char filename[MAX_PATH]; char *p; size_t len = strlen( path ); + int lengthAsInt = 0; WIN32_FIND_DATAW file_data; HANDLE hFind; @@ -1291,7 +1305,18 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path ) p = filename + len; filename[len++] = '*'; - w_ret = MultiByteToWideChar( CP_ACP, 0, filename, (int)len, szDir, + if ( FAILED ( SizeTToInt( len, &lengthAsInt ) ) ) + return( MBEDTLS_ERR_X509_FILE_IO_ERROR ); + + /* + * Note this function uses the code page CP_ACP, and assumes the incoming + * string is encoded in ANSI, before translating it into Unicode. If the + * incoming string were changed to be UTF-8, then the length check needs to + * change to check the number of characters, not the number of bytes, in the + * incoming string are less than MAX_PATH to avoid a buffer overrun with + * MultiByteToWideChar(). + */ + w_ret = MultiByteToWideChar( CP_ACP, 0, filename, lengthAsInt, szDir, MAX_PATH - 3 ); if( w_ret == 0 ) return( MBEDTLS_ERR_X509_BAD_INPUT_DATA ); @@ -1308,8 +1333,11 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path ) if( file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) continue; + if ( FAILED( SizeTToInt( wcslen( file_data.cFileName ), &lengthAsInt ) ) ) + return( MBEDTLS_ERR_X509_FILE_IO_ERROR ); + w_ret = WideCharToMultiByte( CP_ACP, 0, file_data.cFileName, - lstrlenW( file_data.cFileName ), + lengthAsInt, p, (int) len - 1, NULL, NULL ); if( w_ret == 0 ) diff --git a/thirdparty/mbedtls/patches/padlock.diff b/thirdparty/mbedtls/patches/padlock.diff new file mode 100644 index 0000000000..6ace48891c --- /dev/null +++ b/thirdparty/mbedtls/patches/padlock.diff @@ -0,0 +1,13 @@ +--- a/thirdparty/mbedtls/include/mbedtls/config.h ++++ b/thirdparty/mbedtls/include/mbedtls/config.h +@@ -2477,7 +2477,9 @@ + * + * This modules adds support for the VIA PadLock on x86. + */ +-#define MBEDTLS_PADLOCK_C ++// -- GODOT start -- ++// #define MBEDTLS_PADLOCK_C ++// -- GODOT end -- + + /** + * \def MBEDTLS_PEM_PARSE_C |