diff options
Diffstat (limited to 'core/io')
50 files changed, 431 insertions, 251 deletions
diff --git a/core/io/compression.cpp b/core/io/compression.cpp index ea2f5d2d9c..0bc006b41e 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/compression.h b/core/io/compression.h index 70742d42d6..106a3f0201 100644 --- a/core/io/compression.h +++ b/core/io/compression.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,28 +26,28 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef COMPRESSION_H
-#define COMPRESSION_H
-
-#include "typedefs.h"
-
-class Compression
-{
-public:
-
- enum Mode {
- MODE_FASTLZ,
- MODE_DEFLATE
- };
-
-
- static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,Mode p_mode=MODE_FASTLZ);
- static int get_max_compressed_buffer_size(int p_src_size,Mode p_mode=MODE_FASTLZ);
- static void decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size,Mode p_mode=MODE_FASTLZ);
-
- Compression();
-};
-
-
-
-#endif // COMPRESSION_H
+#ifndef COMPRESSION_H +#define COMPRESSION_H + +#include "typedefs.h" + +class Compression +{ +public: + + enum Mode { + MODE_FASTLZ, + MODE_DEFLATE + }; + + + static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,Mode p_mode=MODE_FASTLZ); + static int get_max_compressed_buffer_size(int p_src_size,Mode p_mode=MODE_FASTLZ); + static void decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size,Mode p_mode=MODE_FASTLZ); + + Compression(); +}; + + + +#endif // COMPRESSION_H diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 17ee72f2eb..75388f514a 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -357,6 +357,7 @@ if (res!=-1 && res < min_pos) {\ } break; case MIN_OPEN: { int level=1; + end++; while(end<close_pos) { if (str[end]=='[') @@ -373,6 +374,7 @@ if (res!=-1 && res < min_pos) {\ } break; case MIN_CURLY_OPEN: { int level=1; + end++; while(end<close_pos) { if (str[end]=='{') diff --git a/core/io/config_file.h b/core/io/config_file.h index e132e46fea..608f143fb1 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp index 6927b3772f..ab17cb8118 100644 --- a/core/io/file_access_buffered.cpp +++ b/core/io/file_access_buffered.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h index 533cc6c7dd..e6de203cda 100644 --- a/core/io/file_access_buffered.h +++ b/core/io/file_access_buffered.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_buffered_fa.h b/core/io/file_access_buffered_fa.h index 5de2f66ace..d36c4843e4 100644 --- a/core/io/file_access_buffered_fa.h +++ b/core/io/file_access_buffered_fa.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index b90a41df54..1d06dc8c4b 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h index 3039b5c8be..69a03fa14f 100644 --- a/core/io/file_access_compressed.h +++ b/core/io/file_access_compressed.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,76 +26,76 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef FILE_ACCESS_COMPRESSED_H
-#define FILE_ACCESS_COMPRESSED_H
-
-#include "io/compression.h"
-#include "os/file_access.h"
-
-class FileAccessCompressed : public FileAccess {
-
- Compression::Mode cmode;
- bool writing;
- int write_pos;
- uint8_t*write_ptr;
- int write_buffer_size;
- int write_max;
- int block_size;
- mutable bool read_eof;
- mutable bool at_end;
-
- struct ReadBlock {
- int csize;
- int offset;
- };
-
- mutable Vector<uint8_t> comp_buffer;
- uint8_t *read_ptr;
- mutable int read_block;
- int read_block_count;
- mutable int read_block_size;
- mutable int read_pos;
- Vector<ReadBlock> read_blocks;
- int read_total;
-
-
-
-
- String magic;
- mutable Vector<uint8_t> buffer;
- FileAccess *f;
-public:
-
- void configure(const String& p_magic, Compression::Mode p_mode=Compression::MODE_FASTLZ, int p_block_size=4096);
-
- Error open_after_magic(FileAccess *p_base);
-
- virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file
- virtual void close(); ///< close a file
- virtual bool is_open() const; ///< true when file is open
-
- virtual void seek(size_t p_position); ///< seek to a given position
- virtual void seek_end(int64_t p_position=0); ///< seek from the end of file
- virtual size_t get_pos() const; ///< get position in the file
- virtual size_t get_len() const; ///< get size of the file
-
- virtual bool eof_reached() const; ///< reading passed EOF
-
- virtual uint8_t get_8() const; ///< get a byte
- virtual int get_buffer(uint8_t *p_dst, int p_length) const;
-
- virtual Error get_error() const; ///< get last error
-
- virtual void store_8(uint8_t p_dest); ///< store a byte
-
- virtual bool file_exists(const String& p_name); ///< return true if a file exists
-
- virtual uint64_t _get_modified_time(const String& p_file);
-
-
- FileAccessCompressed();
- virtual ~FileAccessCompressed();
-
-};
-
-#endif // FILE_ACCESS_COMPRESSED_H
+#ifndef FILE_ACCESS_COMPRESSED_H +#define FILE_ACCESS_COMPRESSED_H + +#include "io/compression.h" +#include "os/file_access.h" + +class FileAccessCompressed : public FileAccess { + + Compression::Mode cmode; + bool writing; + int write_pos; + uint8_t*write_ptr; + int write_buffer_size; + int write_max; + int block_size; + mutable bool read_eof; + mutable bool at_end; + + struct ReadBlock { + int csize; + int offset; + }; + + mutable Vector<uint8_t> comp_buffer; + uint8_t *read_ptr; + mutable int read_block; + int read_block_count; + mutable int read_block_size; + mutable int read_pos; + Vector<ReadBlock> read_blocks; + int read_total; + + + + + String magic; + mutable Vector<uint8_t> buffer; + FileAccess *f; +public: + + void configure(const String& p_magic, Compression::Mode p_mode=Compression::MODE_FASTLZ, int p_block_size=4096); + + Error open_after_magic(FileAccess *p_base); + + virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file + virtual void close(); ///< close a file + virtual bool is_open() const; ///< true when file is open + + virtual void seek(size_t p_position); ///< seek to a given position + virtual void seek_end(int64_t p_position=0); ///< seek from the end of file + virtual size_t get_pos() const; ///< get position in the file + virtual size_t get_len() const; ///< get size of the file + + virtual bool eof_reached() const; ///< reading passed EOF + + virtual uint8_t get_8() const; ///< get a byte + virtual int get_buffer(uint8_t *p_dst, int p_length) const; + + virtual Error get_error() const; ///< get last error + + virtual void store_8(uint8_t p_dest); ///< store a byte + + virtual bool file_exists(const String& p_name); ///< return true if a file exists + + virtual uint64_t _get_modified_time(const String& p_file); + + + FileAccessCompressed(); + virtual ~FileAccessCompressed(); + +}; + +#endif // FILE_ACCESS_COMPRESSED_H diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 29f27dcbda..65b1ca5207 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -5,10 +5,12 @@ #include "print_string.h" #define COMP_MAGIC 0x43454447 +#include "core/variant.h" +#include <stdio.h> Error FileAccessEncrypted::open_and_parse(FileAccess *p_base,const Vector<uint8_t>& p_key,Mode p_mode) { - print_line("open and parse!"); + //print_line("open and parse!"); ERR_FAIL_COND_V(file!=NULL,ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(p_key.size()!=32,ERR_INVALID_PARAMETER); diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index a1dd2e48bb..83da55fc61 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -39,7 +39,7 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { if (!files) { files = memnew((Map<String, Vector<uint8_t> >)); - }; + } String name; if (Globals::get_singleton()) @@ -49,7 +49,7 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { name = DirAccess::normalize_path(name); (*files)[name] = p_data; -}; +} void FileAccessMemory::cleanup() { @@ -57,13 +57,13 @@ void FileAccessMemory::cleanup() { return; memdelete(files); -}; +} FileAccess* FileAccessMemory::create() { return memnew(FileAccessMemory); -}; +} bool FileAccessMemory::file_exists(const String& p_name) { @@ -71,8 +71,16 @@ bool FileAccessMemory::file_exists(const String& p_name) { name = DirAccess::normalize_path(name); return files && (files->find(name) != NULL); -}; +} + +Error FileAccessMemory::open_custom(const uint8_t* p_data, int p_len) { + + data=(uint8_t*)p_data; + length=p_len; + pos=0; + return OK; +} Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) { @@ -89,57 +97,57 @@ Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) { pos = 0; return OK; -}; +} void FileAccessMemory::close() { data = NULL; -}; +} bool FileAccessMemory::is_open() const { return data != NULL; -}; +} void FileAccessMemory::seek(size_t p_position) { ERR_FAIL_COND(!data); pos = p_position; -}; +} void FileAccessMemory::seek_end(int64_t p_position) { ERR_FAIL_COND(!data); pos = length + p_position; -}; +} size_t FileAccessMemory::get_pos() const { ERR_FAIL_COND_V(!data, 0); return pos; -}; +} size_t FileAccessMemory::get_len() const { ERR_FAIL_COND_V(!data, 0); return length; -}; +} bool FileAccessMemory::eof_reached() const { return pos >= length; -}; +} uint8_t FileAccessMemory::get_8() const { - uint8_t ret; + uint8_t ret = 0; if (pos < length) { ret = data[pos]; - }; + } ++pos; return ret; -}; +} int FileAccessMemory::get_buffer(uint8_t *p_dst,int p_length) const { @@ -156,19 +164,19 @@ int FileAccessMemory::get_buffer(uint8_t *p_dst,int p_length) const { pos += p_length; return read; -}; +} Error FileAccessMemory::get_error() const { return pos >= length ? ERR_FILE_EOF : OK; -}; +} void FileAccessMemory::store_8(uint8_t p_byte) { ERR_FAIL_COND(!data); ERR_FAIL_COND(pos >= length); data[pos++] = p_byte; -}; +} void FileAccessMemory::store_buffer(const uint8_t *p_src,int p_length) { @@ -176,11 +184,11 @@ void FileAccessMemory::store_buffer(const uint8_t *p_src,int p_length) { int write = MIN(p_length, left); if (write < p_length) { WARN_PRINT("Writing less data than requested"); - }; + } copymem(&data[pos], p_src, write); pos += p_length; -}; +} FileAccessMemory::FileAccessMemory() { diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h index a02a022a4f..8c58a8a8ce 100644 --- a/core/io/file_access_memory.h +++ b/core/io/file_access_memory.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -44,6 +44,7 @@ public: static void register_file(String p_name, Vector<uint8_t> p_data); static void cleanup(); + virtual Error open_custom(const uint8_t* p_data, int p_len); ///< open a file virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file virtual void close(); ///< close a file virtual bool is_open() const; ///< true when file is open diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 26194040b0..850e055129 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -254,6 +254,7 @@ FileAccessNetworkClient::~FileAccessNetworkClient() { quit=true; sem->post(); Thread::wait_to_finish(thread); + memdelete(thread); } memdelete(blockrequest_mutex); diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h index f338bea43f..2190cdb0ea 100644 --- a/core/io/file_access_network.h +++ b/core/io/file_access_network.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index afbd7e3d46..339a6d0528 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -92,7 +92,9 @@ void PackedData::add_path(const String& pkg_path, const String& path, uint64_t o void PackedData::add_pack_source(PackSource *p_source) { - sources.push_back(p_source); + if (p_source != NULL) { + sources.push_back(p_source); + } }; PackedData *PackedData::singleton=NULL; @@ -107,6 +109,21 @@ PackedData::PackedData() { add_pack_source(memnew(PackedSourcePCK)); } +void PackedData::_free_packed_dirs(PackedDir *p_dir) { + + for (Map<String,PackedDir*>::Element *E=p_dir->subdirs.front();E;E=E->next()) + _free_packed_dirs(E->get()); + memdelete(p_dir); +} + +PackedData::~PackedData() { + + for(int i=0;i<sources.size();i++) { + memdelete(sources[i]); + } + _free_packed_dirs(root); +} + ////////////////////////////////////////////////////////////////// diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index 2d0cf5b32e..5bf5ad012c 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -96,6 +96,8 @@ private: static PackedData *singleton; bool disabled; + void _free_packed_dirs(PackedDir *p_dir); + public: void add_pack_source(PackSource* p_source); @@ -111,6 +113,7 @@ public: _FORCE_INLINE_ bool has_path(const String& p_path); PackedData(); + ~PackedData(); }; class PackSource { @@ -119,6 +122,7 @@ public: virtual bool try_open_pack(const String& p_path)=0; virtual FileAccess* get_file(const String& p_path, PackedData::PackedFile* p_file)=0; + virtual ~PackSource() {} }; class PackedSourcePCK : public PackSource { diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 55c0dedad9..ab2eb3b3f2 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -31,6 +31,7 @@ #include "file_access_zip.h" #include "core/os/file_access.h" +#include "core/os/copymem.h" ZipArchive* ZipArchive::instance = NULL; @@ -103,9 +104,17 @@ static int godot_testerror(voidpf opaque, voidpf stream) { return f->get_error()!=OK?1:0; }; +static voidpf godot_alloc(voidpf opaque, uInt items, uInt size) { + return memalloc(items * size); }; +static void godot_free(voidpf opaque, voidpf address) { + + memfree(address); +}; + +}; // extern "C" void ZipArchive::close_handle(unzFile p_file) const { @@ -125,6 +134,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const { ERR_FAIL_COND_V(!f, NULL); zlib_filefunc_def io; + zeromem(&io, sizeof(io)); io.opaque = f; io.zopen_file = godot_open; @@ -136,9 +146,13 @@ unzFile ZipArchive::get_file_handle(String p_file) const { io.zclose_file = godot_close; io.zerror_file = godot_testerror; + io.alloc_mem = godot_alloc; + io.free_mem = godot_free; + unzFile pkg = unzOpen2(packages[file.package].filename.utf8().get_data(), &io); ERR_FAIL_COND_V(!pkg, NULL); - unzGoToFilePos(pkg, &file.file_pos); + int unz_err = unzGoToFilePos(pkg, &file.file_pos); + ERR_FAIL_COND_V(unz_err != UNZ_OK, NULL); if (unzOpenCurrentFile(pkg) != UNZ_OK) { unzClose(pkg); @@ -150,7 +164,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const { bool ZipArchive::try_open_pack(const String& p_name) { - printf("opening pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); + //printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); if (p_name.extension().nocasecmp_to("zip") != 0 && p_name.extension().nocasecmp_to("pcz") != 0) return false; @@ -198,7 +212,8 @@ bool ZipArchive::try_open_pack(const String& p_name) { files[fname] = f; uint8_t md5[16]={0,0,0,0,0,0,0,0 , 0,0,0,0,0,0,0,0}; - PackedData::get_singleton()->add_path(p_name, fname, 0, 0, md5, this); + PackedData::get_singleton()->add_path(p_name, fname, 1, 0, md5, this); + //printf("packed data add path %ls, %ls\n", p_name.c_str(), fname.c_str()); if ((i+1)<gi.number_entry) { unzGoToNextFile(zfile); diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index c7906018e9..24012660d2 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -325,7 +325,7 @@ Error HTTPClient::poll(){ if (i==0 && responses[i].begins_with("HTTP")) { - String num = responses[i].get_slice(" ",1); + String num = responses[i].get_slicec(' ',1); response_num=num.to_int(); } else { diff --git a/core/io/http_client.h b/core/io/http_client.h index d0ebaa4596..21281f38c5 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 180df8964b..d3390ae199 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 665cc0b460..ff972696ea 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 6ef6b31188..523f9f472b 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -183,7 +183,7 @@ void IP::erase_resolve_item(ResolverID p_id) { GLOBAL_LOCK_FUNCTION; - resolver->queue[p_id].status=IP::RESOLVER_STATUS_DONE; + resolver->queue[p_id].status=IP::RESOLVER_STATUS_NONE; } diff --git a/core/io/ip.h b/core/io/ip.h index 0181dc7d12..6f50a190e6 100644 --- a/core/io/ip.h +++ b/core/io/ip.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index a1400adbb6..ed5a45c9ef 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -47,7 +47,7 @@ IP_Address::IP_Address(const String& p_string) { } for(int i=0;i<4;i++) { - field[i]=p_string.get_slice(".",i).to_int(); + field[i]=p_string.get_slicec('.',i).to_int(); } } diff --git a/core/io/ip_address.h b/core/io/ip_address.h index 3cd8bb7733..e55f45a2d7 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/json.cpp b/core/io/json.cpp index 88a23eb4cd..14890abd26 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/json.h b/core/io/json.h index d113d0e4ef..78b6303451 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index c6c15af5e0..b0d24abfe3 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/marshalls.h b/core/io/marshalls.h index bb8d3b336a..df673debf5 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index b566ce4b7b..875cace368 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -36,7 +36,7 @@ PacketPeer::PacketPeer() { - + last_get_error=OK; } Error PacketPeer::get_packet_buffer(DVector<uint8_t> &r_buffer) const { @@ -108,10 +108,29 @@ Variant PacketPeer::_bnd_get_var() const { return var; }; +Error PacketPeer::_put_packet(const DVector<uint8_t> &p_buffer) { + return put_packet_buffer(p_buffer); +} +DVector<uint8_t> PacketPeer::_get_packet() const { + + DVector<uint8_t> raw; + last_get_error=get_packet_buffer(raw); + return raw; +} + +Error PacketPeer::_get_packet_error() const { + + return last_get_error; +} + + void PacketPeer::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_var"),&PacketPeer::_bnd_get_var); ObjectTypeDB::bind_method(_MD("put_var", "var:var"),&PacketPeer::put_var); + ObjectTypeDB::bind_method(_MD("get_packet"),&PacketPeer::_get_packet); + ObjectTypeDB::bind_method(_MD("put_packet:Error", "buffer"),&PacketPeer::_put_packet); + ObjectTypeDB::bind_method(_MD("get_packet_error:Error"),&PacketPeer::_get_packet_error); ObjectTypeDB::bind_method(_MD("get_available_packet_count"),&PacketPeer::get_available_packet_count); }; diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index e9d6be4fb9..76d1eb22b5 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -41,6 +41,14 @@ class PacketPeer : public Reference { static void _bind_methods(); + + Error _put_packet(const DVector<uint8_t> &p_buffer); + DVector<uint8_t> _get_packet() const; + Error _get_packet_error() const; + + + mutable Error last_get_error; + public: virtual int get_available_packet_count() const=0; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index ead6984650..c6cf631de6 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -390,7 +390,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) { if (path.find("://")==-1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(res_path.get_base_dir()+"/"+path); + path=Globals::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); } @@ -663,14 +663,18 @@ Error ResourceInteractiveLoaderBinary::poll(){ //maybe it is loaded already String path; + int subindex=0; if (!main) { path=internal_resources[s].path; - if (path.begins_with("local://")) - path=path.replace("local://",res_path+"::"); + if (path.begins_with("local://")) { + path=path.replace_first("local://",""); + subindex = path.to_int(); + path=res_path+"::"+path; + } @@ -709,6 +713,7 @@ Error ResourceInteractiveLoaderBinary::poll(){ RES res = RES( r ); r->set_path(path); + r->set_subindex(subindex); int pc = f->get_32(); @@ -861,7 +866,7 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { print_bl("minor: "+itos(ver_minor)); print_bl("format: "+itos(ver_format)); - if (ver_format<FORMAT_VERSION || ver_major>VERSION_MAJOR || (ver_major==VERSION_MAJOR && ver_minor>VERSION_MINOR)) { + if (ver_format<FORMAT_VERSION || ver_major>VERSION_MAJOR) { f->close(); ERR_EXPLAIN("File Format '"+itos(FORMAT_VERSION)+"."+itos(ver_major)+"."+itos(ver_minor)+"' is too new! Please upgrade to a a new engine version: "+local_path); @@ -968,7 +973,7 @@ String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) { uint32_t ver_minor=f->get_32(); uint32_t ver_format=f->get_32(); - if (ver_format<FORMAT_VERSION || ver_major>VERSION_MAJOR || (ver_major==VERSION_MAJOR && ver_minor>VERSION_MINOR)) { + if (ver_format<FORMAT_VERSION || ver_major>VERSION_MAJOR) { f->close(); return ""; @@ -1434,14 +1439,14 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant& p_property, save_unicode_string(path); } else { - if (!resource_map.has(res)) { + if (!resource_set.has(res)) { f->store_32(OBJECT_EMPTY); ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?"); ERR_FAIL(); } f->store_32(OBJECT_INTERNAL_RESOURCE); - f->store_32(resource_map[res]); + f->store_32(res->get_subindex()); //internal resource } @@ -1598,7 +1603,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant& p_variant } - if (resource_map.has(res)) + if (resource_set.has(res)) return; List<PropertyInfo> property_list; @@ -1613,7 +1618,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant& p_variant } } - resource_map[ res ] = saved_resources.size(); + resource_set.insert(res); saved_resources.push_back(res); } break; @@ -1814,7 +1819,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_ Property p; p.name_idx=get_string_index(F->get().name); p.value=E->get()->get(F->get().name); - if (F->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && p.value.is_zero()) + if ((F->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && p.value.is_zero())||(F->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && p.value.is_one()) ) continue; p.pi=F->get(); @@ -1846,11 +1851,42 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_ // save internal resource table f->store_32(saved_resources.size()); //amount of internal resources Vector<uint64_t> ofs_pos; + Set<int> used_indices; + + for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) { + + RES r = E->get(); + if (r->get_path()=="" || r->get_path().find("::")!=-1) { + + if (r->get_subindex()!=0) { + if (used_indices.has(r->get_subindex())) { + r->set_subindex(0); //repeated + } else { + used_indices.insert(r->get_subindex()); + } + } + } + + } + + for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) { + RES r = E->get(); if (r->get_path()=="" || r->get_path().find("::")!=-1) { - save_unicode_string("local://"+itos(ofs_pos.size())); + if (r->get_subindex()==0) { + int new_subindex=1; + if (used_indices.size()) { + new_subindex=used_indices.back()->get()+1; + } + + r->set_subindex(new_subindex); + used_indices.insert(new_subindex); + + } + + save_unicode_string("local://"+itos(r->get_subindex())); if (takeover_paths) { r->set_path(p_path+"::"+itos(ofs_pos.size()),true); } diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index cc26357bfb..da415d97a5 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -129,7 +129,7 @@ class ResourceFormatSaverBinaryInstance { int bin_meta_idx; FileAccess *f; String magic; - Map<RES,int> resource_map; + Set<RES> resource_set; Map<StringName,int> string_map; Vector<StringName> strings; diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp index 033b4d5e5a..b744cbf967 100644 --- a/core/io/resource_format_xml.cpp +++ b/core/io/resource_format_xml.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -309,6 +309,7 @@ Error ResourceInteractiveLoaderXML::_parse_array_element(Vector<char> &buff,bool buff_max++; buff.resize(buff_max); + buffptr=buff.ptr(); } @@ -458,7 +459,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) path=path.replace("local://",local_path+"::"); else if (path.find("://")==-1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(local_path.get_base_dir()+"/"+path); + path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); } @@ -1206,47 +1207,47 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) r_v=Vector3( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double() ); } else if (type=="vector2") { r_v=Vector2( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double() ); } else if (type=="plane") { r_v=Plane( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ); } else if (type=="quaternion") { r_v=Quat( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ); } else if (type=="rect2") { r_v=Rect2( Vector2( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double() ), Vector2( - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ) ); @@ -1255,14 +1256,14 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) r_v=AABB( Vector3( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double() ), Vector3( - data.get_slice(",",3).to_double(), - data.get_slice(",",4).to_double(), - data.get_slice(",",5).to_double() + data.get_slicec(',',3).to_double(), + data.get_slicec(',',4).to_double(), + data.get_slicec(',',5).to_double() ) ); @@ -1271,7 +1272,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) Matrix32 m3; for (int i=0;i<3;i++) { for (int j=0;j<2;j++) { - m3.elements[i][j]=data.get_slice(",",i*2+j).to_double(); + m3.elements[i][j]=data.get_slicec(',',i*2+j).to_double(); } } r_v=m3; @@ -1281,7 +1282,7 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) Matrix3 m3; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { - m3.elements[i][j]=data.get_slice(",",i*3+j).to_double(); + m3.elements[i][j]=data.get_slicec(',',i*3+j).to_double(); } } r_v=m3; @@ -1291,24 +1292,24 @@ Error ResourceInteractiveLoaderXML::parse_property(Variant& r_v, String &r_name) Transform tr; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { - tr.basis.elements[i][j]=data.get_slice(",",i*3+j).to_double(); + tr.basis.elements[i][j]=data.get_slicec(',',i*3+j).to_double(); } } tr.origin=Vector3( - data.get_slice(",",9).to_double(), - data.get_slice(",",10).to_double(), - data.get_slice(",",11).to_double() + data.get_slicec(',',9).to_double(), + data.get_slicec(',',10).to_double(), + data.get_slicec(',',11).to_double() ); r_v=tr; } else if (type=="color") { r_v=Color( - data.get_slice(",",0).to_double(), - data.get_slice(",",1).to_double(), - data.get_slice(",",2).to_double(), - data.get_slice(",",3).to_double() + data.get_slicec(',',0).to_double(), + data.get_slicec(',',1).to_double(), + data.get_slicec(',',2).to_double(), + data.get_slicec(',',3).to_double() ); } else if (type=="node_path") { @@ -1373,7 +1374,7 @@ Error ResourceInteractiveLoaderXML::poll() { if (res.is_null()) { if (ResourceLoader::get_abort_on_missing_resources()) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": editor exported unexisting resource at: "+path); + ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": editor exported nonexistent resource at: "+path); ERR_FAIL_V(error); } else { ResourceLoader::notify_load_error("Resource Not Found: "+path); @@ -1423,7 +1424,7 @@ Error ResourceInteractiveLoaderXML::poll() { if (path.find("://")==-1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(local_path.get_base_dir()+"/"+path); + path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); } @@ -1432,7 +1433,7 @@ Error ResourceInteractiveLoaderXML::poll() { if (res.is_null()) { if (ResourceLoader::get_abort_on_missing_resources()) { - ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> referenced unexisting resource at: "+path); + ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <ext_resource> referenced nonexistent resource at: "+path); ERR_FAIL_V(error); } else { ResourceLoader::notify_load_error("Resource Not Found: "+path); @@ -1465,6 +1466,7 @@ Error ResourceInteractiveLoaderXML::poll() { String type; String path; + int subres=0; if (!main) { //loading resource @@ -1475,11 +1477,15 @@ Error ResourceInteractiveLoaderXML::poll() { ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": <resource> missing 'type' field."); ERR_FAIL_COND_V(!tag->args.has("type"),ERR_FILE_CORRUPT); path=tag->args["path"]; + error=OK; if (path.begins_with("local://")) { //built-in resource (but really external) - path=path.replace("local://",local_path+"::"); + + path=path.replace("local://",""); + subres=path.to_int(); + path=local_path+"::"+path; } @@ -1518,6 +1524,7 @@ Error ResourceInteractiveLoaderXML::poll() { res = RES( r ); if (path!="") r->set_path(path); + r->set_subindex(subres); //load properties @@ -1601,7 +1608,7 @@ void ResourceInteractiveLoaderXML::get_dependencies(FileAccess *f,List<String> * if (path.find("://")==-1 && path.is_rel_path()) { // path is relative to file being loaded, so convert to a resource path - path=Globals::get_singleton()->localize_path(local_path.get_base_dir()+"/"+path); + path=Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path)); } if (path.ends_with("*")) { @@ -1667,10 +1674,10 @@ void ResourceInteractiveLoaderXML::open(FileAccess *p_f) { ERR_FAIL(); } - int major = version.get_slice(".",0).to_int(); - int minor = version.get_slice(".",1).to_int(); + int major = version.get_slicec('.',0).to_int(); + int minor = version.get_slicec('.',1).to_int(); - if (major>VERSION_MAJOR || (major==VERSION_MAJOR && minor>VERSION_MINOR)) { + if (major>VERSION_MAJOR) { error=ERR_FILE_UNRECOGNIZED; ResourceLoader::notify_load_error(local_path+": File Format '"+version+"' is too new. Please upgrade to a newer engine version."); @@ -1849,7 +1856,7 @@ void ResourceFormatSaverXMLInstance::escape(String& p_str) { p_str=p_str.replace(">","<"); p_str=p_str.replace("'","'"); p_str=p_str.replace("\"","""); - for (int i=1;i<32;i++) { + for (char i=1;i<32;i++) { char chr[2]={i,0}; const char hexn[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; @@ -2028,9 +2035,9 @@ void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const V //internal resource ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?"); - ERR_FAIL_COND(!resource_map.has(res)); + ERR_FAIL_COND(!resource_set.has(res)); - params+=" path=\"local://"+itos(resource_map[res])+"\""; + params+=" path=\"local://"+itos(res->get_subindex())+"\""; } } break; @@ -2243,12 +2250,12 @@ void ResourceFormatSaverXMLInstance::write_property(const String& p_name,const V List<Variant> keys; dict.get_key_list(&keys); + keys.sort(); for(List<Variant>::Element *E=keys.front();E;E=E->next()) { //if (!_check_type(dict[E->get()])) // continue; - bool ok; write_property("",E->get(),&ok); ERR_CONTINUE(!ok); @@ -2438,16 +2445,17 @@ void ResourceFormatSaverXMLInstance::_find_resources(const Variant& p_variant,bo return; if (!p_main && (!bundle_resources ) && res->get_path().length() && res->get_path().find("::") == -1 ) { - external_resources.insert(res); + external_resources.push_back(res); return; } - if (resource_map.has(res)) + if (resource_set.has(res)) return; List<PropertyInfo> property_list; res->get_property_list( &property_list ); + property_list.sort(); List<PropertyInfo>::Element *I=property_list.front(); @@ -2464,7 +2472,7 @@ void ResourceFormatSaverXMLInstance::_find_resources(const Variant& p_variant,bo I=I->next(); } - resource_map[ res ] = resource_map.size(); //saved after, so the childs it needs are available when loaded + resource_set.insert( res ); //saved after, so the childs it needs are available when loaded saved_resources.push_back(res); } break; @@ -2525,7 +2533,7 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res enter_tag("resource_file","type=\""+p_resource->get_type()+"\" subresource_count=\""+itos(saved_resources.size()+external_resources.size())+"\" version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\" version_name=\""+VERSION_FULL_NAME+"\""); write_string("\n",false); - for(Set<RES>::Element *E=external_resources.front();E;E=E->next()) { + for(List<RES>::Element *E=external_resources.front();E;E=E->next()) { write_tabs(); String p = E->get()->get_path(); @@ -2535,12 +2543,27 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res write_string("\n",false); } + Set<int> used_indices; + for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) { + + RES res = E->get(); + if (E->next() && (res->get_path()=="" || res->get_path().find("::") != -1 )) { + + if (res->get_subindex()!=0) { + if (used_indices.has(res->get_subindex())) { + res->set_subindex(0); //repeated + } else { + used_indices.insert(res->get_subindex()); + } + } + } + } for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) { RES res = E->get(); - ERR_CONTINUE(!resource_map.has(res)); + ERR_CONTINUE(!resource_set.has(res)); bool main = (E->next()==NULL); write_tabs(); @@ -2550,7 +2573,18 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res else if (res->get_path().length() && res->get_path().find("::") == -1 ) enter_tag("resource","type=\""+res->get_type()+"\" path=\""+res->get_path()+"\""); //bundled else { - int idx = resource_map[res]; + + if (res->get_subindex()==0) { + int new_subindex=1; + if (used_indices.size()) { + new_subindex=used_indices.back()->get()+1; + } + + res->set_subindex(new_subindex); + used_indices.insert(new_subindex); + } + + int idx = res->get_subindex(); enter_tag("resource","type=\""+res->get_type()+"\" path=\"local://"+itos(idx)+"\""); if (takeover_paths) { res->set_path(p_path+"::"+itos(idx),true); @@ -2562,6 +2596,7 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res List<PropertyInfo> property_list; res->get_property_list(&property_list); +// property_list.sort(); for(List<PropertyInfo>::Element *PE = property_list.front();PE;PE=PE->next()) { @@ -2572,9 +2607,12 @@ Error ResourceFormatSaverXMLInstance::save(const String &p_path,const RES& p_res String name = PE->get().name; Variant value = res->get(name); - if (PE->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero()) + + + if ((PE->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero())||(PE->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && value.is_one()) ) continue; + write_property(name,value); } diff --git a/core/io/resource_format_xml.h b/core/io/resource_format_xml.h index 40aaa01451..d5ba9eb800 100644 --- a/core/io/resource_format_xml.h +++ b/core/io/resource_format_xml.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -123,9 +123,9 @@ class ResourceFormatSaverXMLInstance { bool skip_editor; FileAccess *f; int depth; - Map<RES,int> resource_map; + Set<RES> resource_set; List<RES> saved_resources; - Set<RES> external_resources; + List<RES> external_resources; void enter_tag(const char* p_tag,const String& p_args=String()); void exit_tag(const char* p_tag); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index d2610d5d4f..22d89840ae 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -117,6 +117,7 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const Stri RES ResourceFormatLoader::load(const String &p_path,const String& p_original_path) { + String path=p_path; //or this must be implemented Ref<ResourceInteractiveLoader> ril = load_interactive(p_path); @@ -150,9 +151,13 @@ void ResourceFormatLoader::get_dependencies(const String& p_path,List<String> *p RES ResourceLoader::load(const String &p_path,const String& p_type_hint,bool p_no_cache) { - String local_path = Globals::get_singleton()->localize_path(p_path); + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); - local_path=find_complete_path(p_path,p_type_hint); + local_path=find_complete_path(local_path,p_type_hint); ERR_FAIL_COND_V(local_path=="",RES()); if (!p_no_cache && ResourceCache::has(local_path)) { @@ -209,7 +214,12 @@ RES ResourceLoader::load(const String &p_path,const String& p_type_hint,bool p_n Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p_path) { - String local_path = Globals::get_singleton()->localize_path(p_path); + + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); String extension=p_path.extension(); bool found=false; @@ -283,9 +293,13 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ - String local_path = Globals::get_singleton()->localize_path(p_path); + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); - local_path=find_complete_path(p_path,p_type_hint); + local_path=find_complete_path(local_path,p_type_hint); ERR_FAIL_COND_V(local_path=="",Ref<ResourceInteractiveLoader>()); @@ -340,7 +354,13 @@ void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_l void ResourceLoader::get_dependencies(const String& p_path,List<String> *p_dependencies) { - String local_path = Globals::get_singleton()->localize_path(p_path); + + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); + String remapped_path = PathRemap::get_singleton()->get_remap(local_path); String extension=remapped_path.extension(); @@ -359,7 +379,11 @@ void ResourceLoader::get_dependencies(const String& p_path,List<String> *p_depen String ResourceLoader::guess_full_filename(const String &p_path,const String& p_type) { - String local_path = Globals::get_singleton()->localize_path(p_path); + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); return find_complete_path(local_path,p_type); @@ -367,7 +391,12 @@ String ResourceLoader::guess_full_filename(const String &p_path,const String& p_ String ResourceLoader::get_resource_type(const String &p_path) { - String local_path = Globals::get_singleton()->localize_path(p_path); + String local_path; + if (p_path.is_rel_path()) + local_path="res://"+p_path; + else + local_path = Globals::get_singleton()->localize_path(p_path); + String remapped_path = PathRemap::get_singleton()->get_remap(local_path); String extension=remapped_path.extension(); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index ab23158785..d25727f19f 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 598f517d76..fdb9a53f0d 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index e307668721..05cbe7f98e 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 0eae660373..b00b462eb6 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h index 84552cfd3e..e83fc71b93 100644 --- a/core/io/stream_peer.h +++ b/core/io/stream_peer.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index f83c174084..c2343790ea 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index d447ded78b..0e37303516 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index bce9e19ae3..803df87086 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index fff00e5ce0..b59f3293d7 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 0d42cebb41..c32b25c407 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h index 7a0c4e10dc..9d8ad97a29 100644 --- a/core/io/translation_loader_po.h +++ b/core/io/translation_loader_po.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index 1d69f8e5e7..1ff458f325 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h index 9debbf9e2f..418a8efa70 100644 --- a/core/io/xml_parser.h +++ b/core/io/xml_parser.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/core/io/zip_io.h b/core/io/zip_io.h index 798265cc48..c4b4d6b34d 100644 --- a/core/io/zip_io.h +++ b/core/io/zip_io.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ |