diff options
Diffstat (limited to 'core/io')
43 files changed, 200 insertions, 309 deletions
diff --git a/core/io/SCsub b/core/io/SCsub index 1c5f954470..19a6549225 100644 --- a/core/io/SCsub +++ b/core/io/SCsub @@ -1,5 +1,5 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.core_sources, "*.cpp") diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 531467ecd6..73230e3a3c 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -107,7 +107,7 @@ bool ConfigFile::has_section_key(const String &p_section, const String &p_key) c void ConfigFile::get_sections(List<String> *r_sections) const { - for (OrderedHashMap<String, OrderedHashMap<String, Variant> >::ConstElement E = values.front(); E; E = E.next()) { + for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::ConstElement E = values.front(); E; E = E.next()) { r_sections->push_back(E.key()); } } @@ -187,7 +187,7 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass Error ConfigFile::_internal_save(FileAccess *file) { - for (OrderedHashMap<String, OrderedHashMap<String, Variant> >::Element E = values.front(); E; E = E.next()) { + for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::Element E = values.front(); E; E = E.next()) { if (E != values.front()) file->store_string("\n"); @@ -290,7 +290,7 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) next_tag.fields.clear(); next_tag.name = String(); - Error err = VariantParser::parse_tag_assign_eof(p_stream, lines, error_text, next_tag, assign, value, NULL, true); + Error err = VariantParser::parse_tag_assign_eof(p_stream, lines, error_text, next_tag, assign, value, nullptr, true); if (err == ERR_FILE_EOF) { return OK; } else if (err != OK) { diff --git a/core/io/config_file.h b/core/io/config_file.h index 7efcb5a04c..39fc2ab412 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -40,7 +40,7 @@ class ConfigFile : public Reference { GDCLASS(ConfigFile, Reference); - OrderedHashMap<String, OrderedHashMap<String, Variant> > values; + OrderedHashMap<String, OrderedHashMap<String, Variant>> values; PackedStringArray _get_sections() const; PackedStringArray _get_section_keys(const String &p_section) const; diff --git a/core/io/dtls_server.cpp b/core/io/dtls_server.cpp index 07e6abb1c9..5bda06e5b9 100644 --- a/core/io/dtls_server.cpp +++ b/core/io/dtls_server.cpp @@ -32,7 +32,7 @@ #include "core/os/file_access.h" #include "core/project_settings.h" -DTLSServer *(*DTLSServer::_create)() = NULL; +DTLSServer *(*DTLSServer::_create)() = nullptr; bool DTLSServer::available = false; DTLSServer *DTLSServer::create() { diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 17cc6ce58f..c76142d22d 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -64,7 +64,7 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { cmode = (Compression::Mode)f->get_32(); block_size = f->get_32(); if (block_size == 0) { - f = NULL; // Let the caller to handle the FileAccess object if failed to open as compressed file. + f = nullptr; // Let the caller to handle the FileAccess object if failed to open as compressed file. ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Can't open compressed file '" + p_base->get_path() + "' with block size 0, it is corrupted."); } read_total = f->get_32(); @@ -109,7 +109,7 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { if (err != OK) { //not openable - f = NULL; + f = nullptr; return err; } @@ -131,7 +131,7 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { rmagic[4] = 0; if (magic != rmagic || open_after_magic(f) != OK) { memdelete(f); - f = NULL; + f = nullptr; return ERR_FILE_UNRECOGNIZED; } } @@ -187,12 +187,12 @@ void FileAccessCompressed::close() { } memdelete(f); - f = NULL; + f = nullptr; } bool FileAccessCompressed::is_open() const { - return f != NULL; + return f != nullptr; } void FileAccessCompressed::seek(size_t p_position) { @@ -392,20 +392,20 @@ Error FileAccessCompressed::_set_unix_permissions(const String &p_file, uint32_t FileAccessCompressed::FileAccessCompressed() : cmode(Compression::MODE_ZSTD), writing(false), - write_ptr(0), + write_ptr(nullptr), write_buffer_size(0), write_max(0), block_size(0), read_eof(false), at_end(false), - read_ptr(NULL), + read_ptr(nullptr), read_block(0), read_block_count(0), read_block_size(0), read_pos(0), read_total(0), magic("GCMP"), - f(NULL) { + f(nullptr) { } FileAccessCompressed::~FileAccessCompressed() { diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 20b6fc81dc..a5b3807789 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -41,7 +41,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8_t> &p_key, Mode p_mode) { - ERR_FAIL_COND_V_MSG(file != NULL, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open."); + ERR_FAIL_COND_V_MSG(file != nullptr, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open."); ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER); pos = 0; @@ -159,7 +159,7 @@ void FileAccessEncrypted::close() { file->store_buffer(compressed.ptr(), compressed.size()); file->close(); memdelete(file); - file = NULL; + file = nullptr; data.clear(); } else { @@ -167,13 +167,13 @@ void FileAccessEncrypted::close() { file->close(); memdelete(file); data.clear(); - file = NULL; + file = nullptr; } } bool FileAccessEncrypted::is_open() const { - return file != NULL; + return file != nullptr; } String FileAccessEncrypted::get_path() const { @@ -319,7 +319,7 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t FileAccessEncrypted::FileAccessEncrypted() { - file = NULL; + file = nullptr; pos = 0; eofed = false; mode = MODE_MAX; diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index fc318b3dd2..a2379ce88f 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -35,12 +35,12 @@ #include "core/os/dir_access.h" #include "core/project_settings.h" -static Map<String, Vector<uint8_t> > *files = NULL; +static Map<String, Vector<uint8_t>> *files = nullptr; void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { if (!files) { - files = memnew((Map<String, Vector<uint8_t> >)); + files = memnew((Map<String, Vector<uint8_t>>)); } String name; @@ -71,7 +71,7 @@ bool FileAccessMemory::file_exists(const String &p_name) { String name = fix_path(p_name); //name = DirAccess::normalize_path(name); - return files && (files->find(name) != NULL); + return files && (files->find(name) != nullptr); } Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) { @@ -89,7 +89,7 @@ Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) { String name = fix_path(p_path); //name = DirAccess::normalize_path(name); - Map<String, Vector<uint8_t> >::Element *E = files->find(name); + Map<String, Vector<uint8_t>>::Element *E = files->find(name); ERR_FAIL_COND_V_MSG(!E, ERR_FILE_NOT_FOUND, "Can't find file '" + p_path + "'."); data = E->get().ptrw(); @@ -101,12 +101,12 @@ Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) { void FileAccessMemory::close() { - data = NULL; + data = nullptr; } bool FileAccessMemory::is_open() const { - return data != NULL; + return data != nullptr; } void FileAccessMemory::seek(size_t p_position) { @@ -196,5 +196,5 @@ void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) { FileAccessMemory::FileAccessMemory() { - data = NULL; + data = nullptr; } diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 370dd8f982..a3f307393f 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -114,7 +114,7 @@ void FileAccessNetworkClient::_thread_func() { int response = get_32(); DEBUG_PRINT("GET RESPONSE: " + itos(response)); - FileAccessNetwork *fa = NULL; + FileAccessNetwork *fa = nullptr; if (response != FileAccessNetwork::RESPONSE_DATA) { if (!accesses.has(id)) { @@ -219,11 +219,11 @@ Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const S return OK; } -FileAccessNetworkClient *FileAccessNetworkClient::singleton = NULL; +FileAccessNetworkClient *FileAccessNetworkClient::singleton = nullptr; FileAccessNetworkClient::FileAccessNetworkClient() { - thread = NULL; + thread = nullptr; quit = false; singleton = this; last_id = 0; @@ -295,7 +295,7 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { pos = 0; eof_flag = false; last_page = -1; - last_page_buff = NULL; + last_page_buff = nullptr; //buffers.clear(); nc->unlock_mutex(); diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 055ce816ad..0a7dee9444 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -98,18 +98,18 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o void PackedData::add_pack_source(PackSource *p_source) { - if (p_source != NULL) { + if (p_source != nullptr) { sources.push_back(p_source); } }; -PackedData *PackedData::singleton = NULL; +PackedData *PackedData::singleton = nullptr; PackedData::PackedData() { singleton = this; root = memnew(PackedDir); - root->parent = NULL; + root->parent = nullptr; disabled = false; add_pack_source(memnew(PackedSourcePCK)); diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index e1f35aabdd..8df6826ac9 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -185,9 +185,9 @@ FileAccess *PackedData::try_open_path(const String &p_path) { PathMD5 pmd5(p_path.md5_buffer()); Map<PathMD5, PackedFile>::Element *E = files.find(pmd5); if (!E) - return NULL; //not found + return nullptr; //not found if (E->get().offset == 0) - return NULL; //was erased + return nullptr; //was erased return E->get().src->get_file(p_path, &E->get()); } diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 680450ba43..57de66afaf 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -35,20 +35,20 @@ #include "core/os/copymem.h" #include "core/os/file_access.h" -ZipArchive *ZipArchive::instance = NULL; +ZipArchive *ZipArchive::instance = nullptr; extern "C" { static void *godot_open(void *data, const char *p_fname, int mode) { if (mode & ZLIB_FILEFUNC_MODE_WRITE) { - return NULL; + return nullptr; } FileAccess *f = (FileAccess *)data; f->open(p_fname, FileAccess::READ); - return f->is_open() ? data : NULL; + return f->is_open() ? data : nullptr; } static uLong godot_read(void *data, void *fdata, void *buf, uLong size) { @@ -126,11 +126,11 @@ void ZipArchive::close_handle(unzFile p_file) const { unzFile ZipArchive::get_file_handle(String p_file) const { - ERR_FAIL_COND_V_MSG(!file_exists(p_file), NULL, "File '" + p_file + " doesn't exist."); + ERR_FAIL_COND_V_MSG(!file_exists(p_file), nullptr, "File '" + p_file + " doesn't exist."); File file = files[p_file]; FileAccess *f = FileAccess::open(packages[file.package].filename, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!f, NULL, "Cannot open file '" + packages[file.package].filename + "'."); + ERR_FAIL_COND_V_MSG(!f, nullptr, "Cannot open file '" + packages[file.package].filename + "'."); zlib_filefunc_def io; zeromem(&io, sizeof(io)); @@ -149,12 +149,12 @@ unzFile ZipArchive::get_file_handle(String p_file) const { io.free_mem = godot_free; unzFile pkg = unzOpen2(packages[file.package].filename.utf8().get_data(), &io); - ERR_FAIL_COND_V(!pkg, NULL); + ERR_FAIL_COND_V(!pkg, nullptr); int unz_err = unzGoToFilePos(pkg, &file.file_pos); if (unz_err != UNZ_OK || unzOpenCurrentFile(pkg) != UNZ_OK) { unzClose(pkg); - ERR_FAIL_V(NULL); + ERR_FAIL_V(nullptr); } return pkg; @@ -199,7 +199,7 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) { char filename_inzip[256]; unz_file_info64 file_info; - err = unzGetCurrentFileInfo64(zfile, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); + err = unzGetCurrentFileInfo64(zfile, &file_info, filename_inzip, sizeof(filename_inzip), nullptr, 0, nullptr, 0); ERR_CONTINUE(err != UNZ_OK); File f; @@ -233,7 +233,7 @@ FileAccess *ZipArchive::get_file(const String &p_path, PackedData::PackedFile *p ZipArchive *ZipArchive::get_singleton() { - if (instance == NULL) { + if (instance == nullptr) { instance = memnew(ZipArchive); } @@ -268,7 +268,7 @@ Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { zfile = arch->get_file_handle(p_path); ERR_FAIL_COND_V(!zfile, FAILED); - int err = unzGetCurrentFileInfo64(zfile, &file_info, NULL, 0, NULL, 0, NULL, 0); + int err = unzGetCurrentFileInfo64(zfile, &file_info, nullptr, 0, nullptr, 0, nullptr, 0); ERR_FAIL_COND_V(err != UNZ_OK, FAILED); return OK; @@ -282,12 +282,12 @@ void FileAccessZip::close() { ZipArchive *arch = ZipArchive::get_singleton(); ERR_FAIL_COND(!arch); arch->close_handle(zfile); - zfile = NULL; + zfile = nullptr; } bool FileAccessZip::is_open() const { - return zfile != NULL; + return zfile != nullptr; } void FileAccessZip::seek(size_t p_position) { @@ -370,7 +370,7 @@ bool FileAccessZip::file_exists(const String &p_name) { } FileAccessZip::FileAccessZip(const String &p_path, const PackedData::PackedFile &p_file) : - zfile(NULL) { + zfile(nullptr) { _open(p_path, FileAccess::READ); } diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index ce7025de35..56f8f1ff91 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -350,7 +350,7 @@ Error HTTPClient::poll() { handshaking = true; } else { // We are already handshaking, which means we can use your already active SSL connection - ssl = static_cast<Ref<StreamPeerSSL> >(connection); + ssl = static_cast<Ref<StreamPeerSSL>>(connection); if (ssl.is_null()) { close(); status = STATUS_SSL_HANDSHAKE_ERROR; diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 99ac5bcdd9..2770adbd36 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -100,7 +100,7 @@ ImageFormatLoader *ImageLoader::recognize(const String &p_extension) { return loader[i]; } - return NULL; + return nullptr; } Vector<ImageFormatLoader *> ImageLoader::loader; diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 3ba028b99c..18b4df98f7 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -59,7 +59,7 @@ class ImageLoader { protected: public: - static Error load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom = NULL, bool p_force_linear = false, float p_scale = 1.0); + static Error load_image(String p_file, Ref<Image> p_image, FileAccess *p_custom = nullptr, bool p_force_linear = false, float p_scale = 1.0); static void get_recognized_extensions(List<String> *p_extensions); static ImageFormatLoader *recognize(const String &p_extension); @@ -73,10 +73,10 @@ public: class ResourceFormatLoaderImage : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; }; -#endif +#endif // IMAGE_LOADER_H diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 2143b84d15..5de7fb7186 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -280,19 +280,19 @@ void IP::_bind_methods() { BIND_ENUM_CONSTANT(TYPE_ANY); } -IP *IP::singleton = NULL; +IP *IP::singleton = nullptr; IP *IP::get_singleton() { return singleton; } -IP *(*IP::_create)() = NULL; +IP *(*IP::_create)() = nullptr; IP *IP::create() { - ERR_FAIL_COND_V_MSG(singleton, NULL, "IP singleton already exist."); - ERR_FAIL_COND_V(!_create, NULL); + ERR_FAIL_COND_V_MSG(singleton, nullptr, "IP singleton already exist."); + ERR_FAIL_COND_V(!_create, nullptr); return _create(); } @@ -307,7 +307,7 @@ IP::IP() { resolver->thread = Thread::create(_IP_ResolverPrivate::_thread_function, resolver); #else - resolver->thread = NULL; + resolver->thread = nullptr; #endif } diff --git a/core/io/logger.cpp b/core/io/logger.cpp index 4d732332d5..48aebeda3d 100644 --- a/core/io/logger.cpp +++ b/core/io/logger.cpp @@ -108,7 +108,7 @@ Logger::~Logger() {} void RotatedFileLogger::close_file() { if (file) { memdelete(file); - file = NULL; + file = nullptr; } } @@ -182,7 +182,7 @@ void RotatedFileLogger::rotate_file() { RotatedFileLogger::RotatedFileLogger(const String &p_base_path, int p_max_files) : base_path(p_base_path.simplify_path()), max_files(p_max_files > 0 ? p_max_files : 1), - file(NULL) { + file(nullptr) { rotate_file(); } diff --git a/core/io/logger.h b/core/io/logger.h index ab2f9d8bc7..7028551185 100644 --- a/core/io/logger.h +++ b/core/io/logger.h @@ -107,4 +107,4 @@ public: virtual ~CompositeLogger(); }; -#endif +#endif // LOGGER_H diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index fbcaa582b7..81bc45b2f7 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -439,7 +439,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*r_len) += 8; if (val.is_null()) { - r_variant = (Object *)NULL; + r_variant = (Object *)nullptr; } else { Ref<EncodedObjectAsID> obj_as_id; obj_as_id.instance(); @@ -457,7 +457,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int return err; if (str == String()) { - r_variant = (Object *)NULL; + r_variant = (Object *)nullptr; } else { Object *obj = ClassDB::instance(str); @@ -917,7 +917,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo // Test for potential wrong values sent by the debugger when it breaks. Object *obj = p_variant.get_validated_object(); if (!obj) { - // Object is invalid, send a NULL instead. + // Object is invalid, send a nullptr instead. if (buf) { encode_uint32(Variant::NIL, buf); } diff --git a/core/io/marshalls.h b/core/io/marshalls.h index 484f0755de..d029ed238c 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -199,7 +199,7 @@ public: EncodedObjectAsID(); }; -Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = NULL, bool p_allow_objects = false); +Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = nullptr, bool p_allow_objects = false); Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false); -#endif +#endif // MARSHALLS_H diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index d7c82fddd9..3bec52416e 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) { @@ -184,15 +207,11 @@ int get_packet_len(uint32_t p_node_target, int p_packet_len) { void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_FAIL_COND_MSG(root_node == NULL, "Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it."); + ERR_FAIL_COND_MSG(root_node == nullptr, "Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it."); 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: @@ -266,7 +285,7 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ } Node *node = _process_get_node(p_from, p_packet, node_target, p_packet_len); - ERR_FAIL_COND_MSG(node == NULL, "Invalid packet received. Requested node was not found."); + ERR_FAIL_COND_MSG(node == nullptr, "Invalid packet received. Requested node was not found."); uint16_t name_id = 0; switch (name_id_compression) { @@ -302,14 +321,14 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len) { - Node *node = NULL; + Node *node = nullptr; if (p_node_target & 0x80000000) { // Use full path (not cached yet). int ofs = p_node_target & 0x7FFFFFFF; - ERR_FAIL_COND_V_MSG(ofs >= p_packet_len, NULL, "Invalid packet received. Size smaller than declared."); + ERR_FAIL_COND_V_MSG(ofs >= p_packet_len, nullptr, "Invalid packet received. Size smaller than declared."); String paths; paths.parse_utf8((const char *)&p_packet[ofs], p_packet_len - ofs); @@ -325,10 +344,10 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin int id = p_node_target; Map<int, PathGetCache>::Element *E = path_get_cache.find(p_from); - ERR_FAIL_COND_V_MSG(!E, NULL, "Invalid packet received. Requests invalid peer cache."); + ERR_FAIL_COND_V_MSG(!E, nullptr, "Invalid packet received. Requests invalid peer cache."); Map<int, PathGetCache::NodeInfo>::Element *F = E->get().nodes.find(id); - ERR_FAIL_COND_V_MSG(!F, NULL, "Invalid packet received. Unabled to find requested cached node."); + ERR_FAIL_COND_V_MSG(!F, nullptr, "Invalid packet received. Unabled to find requested cached node."); PathGetCache::NodeInfo *ni = &F->get(); // Do proper caching later. @@ -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,15 +452,11 @@ 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; - Error err = _decode_and_decompress_variant(value, &p_packet[p_offset], p_packet_len - p_offset, NULL); + Error err = _decode_and_decompress_variant(value, &p_packet[p_offset], p_packet_len - p_offset, nullptr); ERR_FAIL_COND_MSG(err != OK, "Invalid packet received. Unable to decode RSET value."); @@ -480,7 +491,7 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, } Node *node = root_node->get_node(path); - ERR_FAIL_COND(node == NULL); + ERR_FAIL_COND(node == nullptr); const bool valid_rpc_checksum = node->get_rpc_md5() == methods_md5; if (valid_rpc_checksum == false) { ERR_PRINT("The rpc node checksum failed. Make sure to have the same methods on both nodes. Node path: " + path); @@ -493,7 +504,7 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, // Encode path to send ack. CharString pname = String(path).utf8(); - int len = encode_cstring(pname.get_data(), NULL); + int len = encode_cstring(pname.get_data(), nullptr); Vector<uint8_t> packet; @@ -561,7 +572,7 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC // Encode function name. const CharString path = String(p_path).utf8(); - const int path_len = encode_cstring(path.get_data(), NULL); + const int path_len = encode_cstring(path.get_data(), nullptr); // Extract MD5 from rpc methods list. const String methods_md5 = p_node->get_rpc_md5(); @@ -851,7 +862,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p // Set argument. int len(0); - Error err = _encode_and_compress_variant(*p_arg[0], NULL, len); + Error err = _encode_and_compress_variant(*p_arg[0], nullptr, len); ERR_FAIL_COND_MSG(err != OK, "Unable to encode RSET value. THIS IS LIKELY A BUG IN THE ENGINE!"); MAKE_ROOM(ofs + len); _encode_and_compress_variant(*p_arg[0], &(packet_cache.write[ofs]), len); @@ -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 @@ -895,7 +907,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p ofs += 1; for (int i = 0; i < p_argcount; i++) { int len(0); - Error err = _encode_and_compress_variant(*p_arg[i], NULL, len); + Error err = _encode_and_compress_variant(*p_arg[i], nullptr, len); ERR_FAIL_COND_MSG(err != OK, "Unable to encode RPC argument. THIS IS LIKELY A BUG IN THE ENGINE!"); MAKE_ROOM(ofs + len); _encode_and_compress_variant(*p_arg[i], &(packet_cache.write[ofs]), len); @@ -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. @@ -935,7 +943,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p // Append path at the end, since we will need it for some packets. CharString pname = String(from_path).utf8(); - int path_len = encode_cstring(pname.get_data(), NULL); + int path_len = encode_cstring(pname.get_data(), nullptr); MAKE_ROOM(ofs + path_len); encode_cstring(pname.get_data(), &(packet_cache.write[ofs])); @@ -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)); @@ -1351,10 +1262,7 @@ void MultiplayerAPI::_bind_methods() { MultiplayerAPI::MultiplayerAPI() : allow_object_decoding(false) { rpc_sender_id = 0; - root_node = NULL; -#ifdef DEBUG_ENABLED - profiling = false; -#endif + root_node = nullptr; clear(); } diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index a706a0e450..4eb4a53e99 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef MULTIPLAYER_PROTOCOL_H -#define MULTIPLAYER_PROTOCOL_H +#ifndef MULTIPLAYER_API_H +#define MULTIPLAYER_API_H #include "core/io/networked_multiplayer_peer.h" #include "core/reference.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,17 +142,10 @@ 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(); }; VARIANT_ENUM_CAST(MultiplayerAPI::RPCMode); -#endif // MULTIPLAYER_PROTOCOL_H +#endif // MULTIPLAYER_API_H diff --git a/core/io/net_socket.cpp b/core/io/net_socket.cpp index 23edbc7d64..838c674cec 100644 --- a/core/io/net_socket.cpp +++ b/core/io/net_socket.cpp @@ -30,7 +30,7 @@ #include "net_socket.h" -NetSocket *(*NetSocket::_create)() = NULL; +NetSocket *(*NetSocket::_create)() = nullptr; NetSocket *NetSocket::create() { @@ -38,5 +38,5 @@ NetSocket *NetSocket::create() { return _create(); ERR_PRINT("Unable to create network socket, platform not supported"); - return NULL; + return nullptr; } diff --git a/core/io/networked_multiplayer_peer.h b/core/io/networked_multiplayer_peer.h index bffd544589..c1f1924051 100644 --- a/core/io/networked_multiplayer_peer.h +++ b/core/io/networked_multiplayer_peer.h @@ -80,4 +80,4 @@ public: VARIANT_ENUM_CAST(NetworkedMultiplayerPeer::TransferMode) VARIANT_ENUM_CAST(NetworkedMultiplayerPeer::ConnectionStatus) -#endif // NetworkedMultiplayerPeer_H +#endif // NETWORKED_MULTIPLAYER_PEER_H diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 2f5c493c2c..38abb5c0d6 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -90,13 +90,13 @@ Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) { if (err) return err; - return decode_variant(r_variant, buffer, buffer_size, NULL, p_allow_objects); + return decode_variant(r_variant, buffer, buffer_size, nullptr, p_allow_objects); } Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) { int len; - Error err = encode_variant(p_packet, NULL, len, p_full_objects); // compute len first + Error err = encode_variant(p_packet, nullptr, len, p_full_objects); // compute len first if (err) return err; diff --git a/core/io/packet_peer_dtls.cpp b/core/io/packet_peer_dtls.cpp index 01218a6881..6da115eed2 100644 --- a/core/io/packet_peer_dtls.cpp +++ b/core/io/packet_peer_dtls.cpp @@ -32,7 +32,7 @@ #include "core/os/file_access.h" #include "core/project_settings.h" -PacketPeerDTLS *(*PacketPeerDTLS::_create)() = NULL; +PacketPeerDTLS *(*PacketPeerDTLS::_create)() = nullptr; bool PacketPeerDTLS::available = false; PacketPeerDTLS *PacketPeerDTLS::create() { diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index fb83f0ac90..5c4b3379ee 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -63,7 +63,7 @@ void PCKPacker::_bind_methods() { Error PCKPacker::pck_start(const String &p_file, int p_alignment) { - if (file != NULL) { + if (file != nullptr) { memdelete(file); } @@ -163,7 +163,7 @@ Error PCKPacker::flush(bool p_verbose) { src->close(); memdelete(src); count += 1; - if (p_verbose) { + if (p_verbose && files.size() > 0) { if (count % 100 == 0) { printf("%i/%i (%.2f)\r", count, files.size(), float(count) / files.size() * 100); fflush(stdout); @@ -182,12 +182,12 @@ Error PCKPacker::flush(bool p_verbose) { PCKPacker::PCKPacker() { - file = NULL; + file = nullptr; }; PCKPacker::~PCKPacker() { - if (file != NULL) { + if (file != nullptr) { memdelete(file); }; - file = NULL; + file = nullptr; }; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index efd452191a..a640565ecf 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1009,7 +1009,7 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) { ResourceLoaderBinary::ResourceLoaderBinary() : translation_remapped(false), ver_format(0), - f(NULL), + f(nullptr), importmd_ofs(0), error(OK) { @@ -1107,7 +1107,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons FileAccess *f = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file '" + p_path + "'."); - FileAccess *fw = NULL; //=FileAccess::open(p_path+".depren"); + FileAccess *fw = nullptr; //=FileAccess::open(p_path+".depren"); String local_path = p_path.get_base_dir(); @@ -2095,7 +2095,7 @@ void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, p_extensions->push_back("res"); } -ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = NULL; +ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = nullptr; ResourceFormatSaverBinary::ResourceFormatSaverBinary() { diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 0ffa2c3626..da67e1e648 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -101,7 +101,7 @@ public: class ResourceFormatLoaderBinary : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index efaf958949..ceb73cab77 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -69,7 +69,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy next_tag.fields.clear(); next_tag.name = String(); - err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true); if (err == ERR_FILE_EOF) { memdelete(f); return OK; @@ -274,7 +274,7 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat next_tag.fields.clear(); next_tag.name = String(); - err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true); if (err == ERR_FILE_EOF) { memdelete(f); return; @@ -362,7 +362,7 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String return Ref<ResourceImporter>(); } -void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers) { +void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter>> *r_importers) { for (int i = 0; i < importers.size(); i++) { List<String> local_exts; @@ -423,7 +423,7 @@ bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) con String ResourceFormatImporter::get_import_settings_hash() const { - Vector<Ref<ResourceImporter> > sorted_importers = importers; + Vector<Ref<ResourceImporter>> sorted_importers = importers; sorted_importers.sort_custom<SortImporterByName>(); @@ -434,7 +434,7 @@ String ResourceFormatImporter::get_import_settings_hash() const { return hash.md5_text(); } -ResourceFormatImporter *ResourceFormatImporter::singleton = NULL; +ResourceFormatImporter *ResourceFormatImporter::singleton = nullptr; ResourceFormatImporter::ResourceFormatImporter() { singleton = this; diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index 65c148f2ac..dbac80599a 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -45,7 +45,7 @@ class ResourceFormatImporter : public ResourceFormatLoader { Variant metadata; }; - Error _get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid = NULL) const; + Error _get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid = nullptr) const; static ResourceFormatImporter *singleton; @@ -54,11 +54,11 @@ class ResourceFormatImporter : public ResourceFormatLoader { bool operator()(const Ref<ResourceImporter> &p_a, const Ref<ResourceImporter> &p_b) const; }; - Vector<Ref<ResourceImporter> > importers; + Vector<Ref<ResourceImporter>> importers; public: static ResourceFormatImporter *get_singleton() { return singleton; } - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual bool recognize_path(const String &p_path, const String &p_for_type = String()) const; @@ -83,7 +83,7 @@ public: void remove_importer(const Ref<ResourceImporter> &p_importer) { importers.erase(p_importer); } Ref<ResourceImporter> get_importer_by_name(const String &p_name) const; Ref<ResourceImporter> get_importer_by_extension(const String &p_extension) const; - void get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter> > *r_importers); + void get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter>> *r_importers); bool are_import_settings_valid(const String &p_path) const; String get_import_settings_hash() const; @@ -123,9 +123,9 @@ public: virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const = 0; virtual String get_option_group_file() const { return String(); } - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL) = 0; + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) = 0; - virtual Error import_group_file(const String &p_group_file, const Map<String, Map<StringName, Variant> > &p_source_file_options, const Map<String, String> &p_base_paths) { return ERR_UNAVAILABLE; } + virtual Error import_group_file(const String &p_group_file, const Map<String, Map<StringName, Variant>> &p_source_file_options, const Map<String, String> &p_base_paths) { return ERR_UNAVAILABLE; } virtual bool are_import_settings_valid(const String &p_path) const { return true; } virtual String get_import_settings_string() const { return String(); } }; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 5dca8b3b89..05a41013c2 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -936,7 +936,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem next_tag.fields.clear(); next_tag.name = String(); - err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true); + err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, nullptr, true); if (err == ERR_FILE_EOF) { break; } else if (err != OK) { @@ -1048,7 +1048,7 @@ void ResourceLoader::set_load_callback(ResourceLoadedCallback p_callback) { _loaded_callback = p_callback; } -ResourceLoadedCallback ResourceLoader::_loaded_callback = NULL; +ResourceLoadedCallback ResourceLoader::_loaded_callback = nullptr; Ref<ResourceFormatLoader> ResourceLoader::_find_custom_resource_format_loader(String path) { for (int i = 0; i < loader_count; ++i) { @@ -1075,7 +1075,7 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { Object *obj = ClassDB::instance(ibt); - ERR_FAIL_COND_V_MSG(obj == NULL, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + "."); + ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + "."); ResourceFormatLoader *crl = Object::cast_to<ResourceFormatLoader>(obj); crl->set_script(s); @@ -1113,7 +1113,7 @@ void ResourceLoader::add_custom_loaders() { void ResourceLoader::remove_custom_loaders() { - Vector<Ref<ResourceFormatLoader> > custom_loaders; + Vector<Ref<ResourceFormatLoader>> custom_loaders; for (int i = 0; i < loader_count; ++i) { if (loader[i]->get_script_instance()) { custom_loaders.push_back(loader[i]); @@ -1140,11 +1140,11 @@ void ResourceLoader::finalize() { memdelete(thread_load_semaphore); } -ResourceLoadErrorNotify ResourceLoader::err_notify = NULL; -void *ResourceLoader::err_notify_ud = NULL; +ResourceLoadErrorNotify ResourceLoader::err_notify = nullptr; +void *ResourceLoader::err_notify_ud = nullptr; -DependencyErrorNotify ResourceLoader::dep_err_notify = NULL; -void *ResourceLoader::dep_err_notify_ud = NULL; +DependencyErrorNotify ResourceLoader::dep_err_notify = nullptr; +void *ResourceLoader::dep_err_notify_ud = nullptr; bool ResourceLoader::abort_on_missing_resource = true; bool ResourceLoader::timestamp_on_load = false; @@ -1159,7 +1159,7 @@ int ResourceLoader::thread_suspended_count = 0; int ResourceLoader::thread_load_max = 0; SelfList<Resource>::List ResourceLoader::remapped_list; -HashMap<String, Vector<String> > ResourceLoader::translation_remaps; +HashMap<String, Vector<String>> ResourceLoader::translation_remaps; HashMap<String, String> ResourceLoader::path_remaps; -ResourceLoaderImport ResourceLoader::import = NULL; +ResourceLoaderImport ResourceLoader::import = nullptr; diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index ea89917a5f..be4adf9091 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -43,7 +43,7 @@ protected: static void _bind_methods(); public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr); virtual bool exists(const String &p_path) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; @@ -90,10 +90,10 @@ private: static void *dep_err_notify_ud; static DependencyErrorNotify dep_err_notify; static bool abort_on_missing_resource; - static HashMap<String, Vector<String> > translation_remaps; + static HashMap<String, Vector<String>> translation_remaps; static HashMap<String, String> path_remaps; - static String _path_remap(const String &p_path, bool *r_translation_remapped = NULL); + static String _path_remap(const String &p_path, bool *r_translation_remapped = nullptr); friend class Resource; static SelfList<Resource>::List remapped_list; @@ -140,9 +140,9 @@ private: public: static Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false, const String &p_source_resource = String()); static ThreadLoadStatus load_threaded_get_status(const String &p_path, float *r_progress = nullptr); - static RES load_threaded_get(const String &p_path, Error *r_error = NULL); + static RES load_threaded_get(const String &p_path, Error *r_error = nullptr); - static RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = NULL); + static RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = nullptr); static bool exists(const String &p_path, const String &p_type_hint = ""); static void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions); @@ -200,4 +200,4 @@ public: static void finalize(); }; -#endif +#endif // RESOURCE_LOADER_H diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 740aaf5cfa..09128adb50 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -38,7 +38,7 @@ Ref<ResourceFormatSaver> ResourceSaver::saver[MAX_SAVERS]; int ResourceSaver::saver_count = 0; bool ResourceSaver::timestamp_on_save = false; -ResourceSavedCallback ResourceSaver::save_callback = 0; +ResourceSavedCallback ResourceSaver::save_callback = nullptr; Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { @@ -218,7 +218,7 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) { Object *obj = ClassDB::instance(ibt); - ERR_FAIL_COND_V_MSG(obj == NULL, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + "."); + ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + "."); ResourceFormatSaver *crl = Object::cast_to<ResourceFormatSaver>(obj); crl->set_script(s); @@ -256,7 +256,7 @@ void ResourceSaver::add_custom_savers() { void ResourceSaver::remove_custom_savers() { - Vector<Ref<ResourceFormatSaver> > custom_savers; + Vector<Ref<ResourceFormatSaver>> custom_savers; for (int i = 0; i < saver_count; ++i) { if (saver[i]->get_script_instance()) { custom_savers.push_back(saver[i]); diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index e749f54cfa..2ddebf0581 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -90,4 +90,4 @@ public: static void remove_custom_savers(); }; -#endif +#endif // RESOURCE_SAVER_H diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 3c695c18fc..b28b17aa95 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -224,7 +224,7 @@ void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) { int len = 0; Vector<uint8_t> buf; - encode_variant(p_variant, NULL, len, p_full_objects); + encode_variant(p_variant, nullptr, len, p_full_objects); buf.resize(len); put_32(len); encode_variant(p_variant, buf.ptrw(), len, p_full_objects); @@ -368,7 +368,7 @@ Variant StreamPeer::get_var(bool p_allow_objects) { ERR_FAIL_COND_V(err != OK, Variant()); Variant ret; - err = decode_variant(ret, var.ptr(), len, NULL, p_allow_objects); + err = decode_variant(ret, var.ptr(), len, nullptr, p_allow_objects); ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant."); return ret; diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 03ca726619..d98935f77c 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -32,13 +32,13 @@ #include "core/engine.h" -StreamPeerSSL *(*StreamPeerSSL::_create)() = NULL; +StreamPeerSSL *(*StreamPeerSSL::_create)() = nullptr; StreamPeerSSL *StreamPeerSSL::create() { if (_create) return _create(); - return NULL; + return nullptr; } bool StreamPeerSSL::available = false; 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..86df9ab8cf 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); @@ -90,4 +93,4 @@ public: VARIANT_ENUM_CAST(StreamPeerTCP::Status); -#endif +#endif // STREAM_PEER_TCP_H diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 4051bf2947..5da236d029 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -33,7 +33,7 @@ #include "core/os/file_access.h" #include "core/translation.h" -RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const String &p_path) { +RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { enum Status { @@ -67,7 +67,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S if (status == STATUS_READING_ID) { memdelete(f); - ERR_FAIL_V_MSG(RES(), p_path + ":" + itos(line) + " Unexpected EOF while reading 'msgid' at file: "); + ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected EOF while reading 'msgid' at file: "); } else { break; } @@ -78,7 +78,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S if (status == STATUS_READING_ID) { memdelete(f); - ERR_FAIL_V_MSG(RES(), p_path + ":" + itos(line) + " Unexpected 'msgid', was expecting 'msgstr' while parsing: "); + ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected 'msgid', was expecting 'msgstr' while parsing: "); } if (msg_id != "") { @@ -100,7 +100,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S if (status != STATUS_READING_ID) { memdelete(f); - ERR_FAIL_V_MSG(RES(), p_path + ":" + itos(line) + " Unexpected 'msgstr', was expecting 'msgid' while parsing: "); + ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected 'msgstr', was expecting 'msgid' while parsing: "); } l = l.substr(6, l.length()).strip_edges(); @@ -115,20 +115,29 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S continue; //nothing to read or comment } - ERR_FAIL_COND_V_MSG(!l.begins_with("\"") || status == STATUS_NONE, RES(), p_path + ":" + itos(line) + " Invalid line '" + l + "' while parsing: "); + ERR_FAIL_COND_V_MSG(!l.begins_with("\"") || status == STATUS_NONE, RES(), f->get_path() + ":" + itos(line) + " Invalid line '" + l + "' while parsing: "); l = l.substr(1, l.length()); - //find final quote + // Find final quote, ignoring escaped ones (\"). + // The escape_next logic is necessary to properly parse things like \\" + // where the blackslash is the one being escaped, not the quote. int end_pos = -1; + bool escape_next = false; for (int i = 0; i < l.length(); i++) { + if (l[i] == '\\' && !escape_next) { + escape_next = true; + continue; + } - if (l[i] == '"' && (i == 0 || l[i - 1] != '\\')) { + if (l[i] == '"' && !escape_next) { end_pos = i; break; } + + escape_next = false; } - ERR_FAIL_COND_V_MSG(end_pos == -1, RES(), p_path + ":" + itos(line) + " Expected '\"' at end of message while parsing file: "); + ERR_FAIL_COND_V_MSG(end_pos == -1, RES(), f->get_path() + ":" + itos(line) + ": Expected '\"' at end of message while parsing file."); l = l.substr(0, end_pos); l = l.c_unescape(); @@ -153,7 +162,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S config = msg_str; } - ERR_FAIL_COND_V_MSG(config == "", RES(), "No config found in file: " + p_path + "."); + ERR_FAIL_COND_V_MSG(config == "", RES(), "No config found in file: " + f->get_path() + "."); Vector<String> configs = config.split("\n"); for (int i = 0; i < configs.size(); i++) { diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h index fe3a75e5eb..9d3117b630 100644 --- a/core/io/translation_loader_po.h +++ b/core/io/translation_loader_po.h @@ -37,8 +37,8 @@ class TranslationLoaderPO : public ResourceFormatLoader { public: - static RES load_translation(FileAccess *f, Error *r_error, const String &p_path = String()); - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr); + static RES load_translation(FileAccess *f, Error *r_error = nullptr); + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index bd450dd84f..9613ad3f10 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -165,7 +165,7 @@ bool XMLParser::_parse_cdata() { return true; char *cDataBegin = P; - char *cDataEnd = 0; + char *cDataEnd = nullptr; // find end of CDATA while (*P && !cDataEnd) { @@ -529,9 +529,9 @@ void XMLParser::close() { if (data) memdelete_arr(data); - data = NULL; + data = nullptr; length = 0; - P = NULL; + P = nullptr; node_empty = false; node_type = NODE_NONE; node_offset = 0; @@ -544,7 +544,7 @@ int XMLParser::get_current_line() const { XMLParser::XMLParser() { - data = NULL; + data = nullptr; close(); special_characters.push_back("&"); special_characters.push_back("<lt;"); diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h index 47e276da28..26c3e6802f 100644 --- a/core/io/xml_parser.h +++ b/core/io/xml_parser.h @@ -121,4 +121,4 @@ public: ~XMLParser(); }; -#endif +#endif // XML_PARSER_H diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index 40e902d874..3a2a207d22 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -47,7 +47,7 @@ void *zipio_open(void *data, const char *p_fname, int mode) { } if (!f) - return NULL; + return nullptr; return data; } @@ -98,7 +98,7 @@ int zipio_close(voidpf opaque, voidpf stream) { if (f) { f->close(); memdelete(f); - f = NULL; + f = nullptr; } return 0; } |