Procházet zdrojové kódy

refactoring for demo

dmuratshin před 7 roky
rodič
revize
74b35bc902

binární
examples/Demo/data/ext/fonts.xml.ox/bmfc_font/big_0.png


binární
examples/Demo/data/ext/fonts.xml.ox/bmfc_font/main_0.png


+ 0 - 1
examples/Demo/data/ext/fonts.xml.ox/meta.xml

@@ -1 +0,0 @@
-<resources version="2"><set/><bmfc_font sf="1.0" size="16"/><bmfc_font sf="1.0" size="26"/></resources>

binární
examples/Demo/data/ext/res_ui.xml.ox/atlas/1_0.png


+ 0 - 1
examples/Demo/data/ext/res_ui.xml.ox/meta.xml

@@ -1 +0,0 @@
-<resources version="2"><set/><atlas><atlas file="1_0.png" format="r8g8b8a8" h="512" w="256"/><image fs="1,1,128,128,1.000000" ht="0,128,32,32">0,2,251,12,21,107,58;</image><image fs="1,1,150,107,1.000000" ht="128,208,37,26">0,2,140,0,0,150,107;</image><image fs="3,1,166,44,1.000000">0,2,48,1,1,164,42;0,2,2,1,1,165,42;0,2,94,2,2,164,42;</image><ht len="448">AAAAAAAAAAAAAAAAAAAAAAAAAAAAAB4AAMA/AAD8fwAA/v8BQP//A4D//wfAP/AD4A/AD+ADgB/gA4Af+AGAH/gBgD/4AQA/+AEAHsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPwAAAAAAAIB/AAAAAAAA4P8BAAAAAADg/wEAAAAAAOD/AQAAAAAA8P8DAAAAAADw8wMAAAAAAPj/AQAAAAAA/P///wcAAAD/////DwAAAP////8PAAAA/////w8AAAD/H///DwAAAP+///8PAAAA/3///w8AAAD8////DwAAAPz///8PAAAA/P///w8AAAD8/P//BwAAAPz8//8PAAAA/P///x8AAAD8////HwAAAPz///8fAAAA+P///x8AAADwv///DwAAAMAf+AMAAAAA</ht></atlas></resources>

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 3 - 0
examples/Demo/src/test.cpp


+ 2 - 0
oxygine/SDL/win32/oxygine.vcxproj

@@ -158,6 +158,7 @@
     <ClCompile Include="..\..\src\oxygine\core\UberShaderProgram.cpp" />
     <ClCompile Include="..\..\src\oxygine\core\VideoDriver.cpp" />
     <ClCompile Include="..\..\src\oxygine\core\ZipFileSystem.cpp" />
+    <ClCompile Include="..\..\src\oxygine\core\Zips.cpp" />
     <ClCompile Include="..\..\src\oxygine\dev_tools\DeveloperMenu.cpp" />
     <ClCompile Include="..\..\src\oxygine\dev_tools\TexturesInspector.cpp" />
     <ClCompile Include="..\..\src\oxygine\dev_tools\TreeInspector.cpp" />
@@ -268,6 +269,7 @@
     <ClInclude Include="..\..\src\oxygine\core\VertexDeclaration.h" />
     <ClInclude Include="..\..\src\oxygine\core\VideoDriver.h" />
     <ClInclude Include="..\..\src\oxygine\core\ZipFileSystem.h" />
+    <ClInclude Include="..\..\src\oxygine\core\Zips.h" />
     <ClInclude Include="..\..\src\oxygine\dev_tools\DeveloperMenu.h" />
     <ClInclude Include="..\..\src\oxygine\dev_tools\TexturesInspector.h" />
     <ClInclude Include="..\..\src\oxygine\dev_tools\TreeInspector.h" />

+ 6 - 0
oxygine/SDL/win32/oxygine.vcxproj.filters

@@ -357,6 +357,9 @@
     <ClCompile Include="..\..\src\oxygine\Material.cpp">
       <Filter>src</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\oxygine\core\Zips.cpp">
+      <Filter>src\core</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\oxygine\closure\closure.h">
@@ -761,6 +764,9 @@
     <ClInclude Include="..\..\src\oxygine\Material.h">
       <Filter>src</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\oxygine\core\Zips.h">
+      <Filter>src\core</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="ReadMe.txt" />

+ 1 - 0
oxygine/src/oxygine/PostProcess.cpp

@@ -8,6 +8,7 @@
 #include "core/gl/VertexDeclarationGL.h"
 #include "core/oxygine.h"
 #include "core/system_data.h"
+#include "core/Zips.h"
 
 namespace oxygine
 {

+ 1 - 1
oxygine/src/oxygine/STDRenderer.cpp

@@ -12,7 +12,7 @@
 #include "core/gl/VideoDriverGLES20.h"
 #include "core/system_data.h"
 #include "math/Rect.h"
-
+#include "core/Zips.h"
 //#define EXP_SORT
 
 namespace oxygine

+ 16 - 292
oxygine/src/oxygine/core/ZipFileSystem.cpp

@@ -5,294 +5,18 @@
 #include <algorithm>
 #include <map>
 #include <string.h>
+#include "Zips.h"
 
 namespace oxygine
 {
     namespace file
     {
-        bool sortFiles(const file_entry& ob1, const file_entry& ob2)
+       
+        ZipFileSystem::ZipFileSystem() : FileSystem(true) 
         {
-            return strcmp_cns(ob1.name, ob2.name) < 0;
+            _zips = new Zips();
         }
 
-        bool readEntry(const file_entry* entry, file::buffer& bf)
-        {
-            bf.data.clear();
-            int r = unzGoToFilePos(entry->zp, const_cast<unz_file_pos*>(&entry->pos));
-            OX_ASSERT(r == UNZ_OK);
-
-            unz_file_info file_info;
-            r = unzGetCurrentFileInfo(entry->zp, &file_info, 0, 0, 0, 0, 0, 0);
-            OX_ASSERT(r == UNZ_OK);
-
-            unzOpenCurrentFile(entry->zp);
-
-            bf.data.resize(file_info.uncompressed_size);
-            r = unzReadCurrentFile(entry->zp, &bf.data.front(), (int)bf.data.size());
-            OX_ASSERT(r == (int)file_info.uncompressed_size);
-
-            unzCloseCurrentFile(entry->zp);
-            return true;
-        }
-
-        Zips::Zips(): _lock(true)
-        {
-
-        }
-
-        Zips::~Zips()
-        {
-            reset();
-        }
-
-        void Zips::read(unzFile zp)
-        {
-            //MutexAutoLock al(_lock);
-
-            do
-            {
-                unz_file_pos pos;
-                unzGetFilePos(zp, &pos);
-
-                file_entry entry;
-                unzGetCurrentFileInfo(zp, 0, entry.name, sizeof(entry.name) - 1, 0, 0, 0, 0);
-                entry.refs = 0;
-                entry.pos = pos;
-                entry.zp = zp;
-
-                char* str = entry.name;
-                for (int i = 0; str[i]; i++)
-                    str[i] = tolower(str[i]);
-
-
-                OX_ASSERT(_files.find(entry.name) == _files.end());
-
-                _files[entry.name] = entry;
-
-            }
-            while (unzGoToNextFile(zp) != UNZ_END_OF_LIST_OF_FILE);
-
-        }
-
-        void Zips::add(const unsigned char* data, unsigned int size)
-        {
-            MutexAutoLock al(_lock);
-
-            zlib_filefunc_def ff;
-            fill_memory_filefunc(&ff);
-
-            zmemdata dta;
-            dta.data = (char*)data;
-            dta.size = size;
-
-            unzFile zp = unzOpen2((const char*)&dta, &ff);
-            OX_ASSERT(zp);
-            if (!zp)
-                return;
-
-
-            zpitem item;
-            item.handle = zp;
-            _zps.push_back(item);
-
-            read(zp);
-        }
-
-        void Zips::add(std::vector<char>& data)
-        {
-            MutexAutoLock al(_lock);
-
-            zlib_filefunc_def ff;
-            fill_memory_filefunc(&ff);
-
-            zmemdata dta;
-            dta.data = (char*)&data.front();
-            dta.size = data.size();
-
-            unzFile zp = unzOpen2((const char*)&dta, &ff);
-            OX_ASSERT(zp);
-            if (!zp)
-                return;
-
-            _zps.push_back(zpitem());
-            zpitem& item = _zps.back();
-            item.handle = zp;
-            std::swap(item.data, data);
-
-            read(zp);
-        }
-
-        voidpf ZCALLBACK ox_fopen(voidpf opaque, const char* filename, int mode)
-        {
-            return file::open(filename, "rb");
-        }
-
-        uLong ZCALLBACK ox_fread(voidpf opaque, voidpf stream, void* buf, uLong size)
-        {
-            return file::read((handle)stream, buf, (unsigned int)size);
-        }
-
-        /*
-        uLong ZCALLBACK ox_fwriteOF(voidpf opaque, voidpf stream, const void* buf, uLong size)
-        {
-
-        }
-        */
-
-        long ZCALLBACK ox_ftell(voidpf opaque, voidpf stream)
-        {
-            return file::tell((handle)stream);
-        }
-
-        long ZCALLBACK ox_fseek(voidpf opaque, voidpf stream, uLong offset, int origin)
-        {
-            file::seek((handle)stream, (unsigned int)offset, origin);
-            return 0;
-        }
-
-        int ZCALLBACK ox_fclose(voidpf opaque, voidpf stream)
-        {
-            file::close((handle)stream);
-            return 0;
-        }
-
-        int ZCALLBACK ox_ferror(voidpf opaque, voidpf stream)
-        {
-            return 0;
-        }
-
-        void Zips::remove(const char* name)
-        {
-            MutexAutoLock al(_lock);
-
-            for (size_t i = 0; i < _zps.size(); ++i)
-            {
-                zpitem& item = _zps[i];
-                if (!strcmp(item.name, name))
-                {
-                    for (files::iterator it = _files.begin(); it != _files.end();)
-                    {
-                        file_entry& entry = it->second;
-                        if (entry.zp == item.handle)
-                        {
-                            OX_ASSERT(entry.refs == 0);
-                            it = _files.erase(it);
-                        }
-                        else
-                            ++it;
-                    }
-
-                    unzClose(item.handle);
-
-                    _zps.erase(_zps.begin() + i);
-                    break;
-                }
-            }
-        }
-
-        void Zips::add(const char* name)
-        {
-            MutexAutoLock al(_lock);
-
-            zlib_filefunc_def zpfs;
-            memset(&zpfs, 0, sizeof(zpfs));
-
-            zpfs.zopen_file = ox_fopen;
-            zpfs.zread_file = ox_fread;
-            zpfs.zwrite_file = 0;
-            zpfs.ztell_file = ox_ftell;
-            zpfs.zseek_file = ox_fseek;
-            zpfs.zclose_file = ox_fclose;
-            zpfs.zerror_file = ox_ferror;
-            zpfs.opaque = (void*)_zps.size();
-            //zpfs.opaque = name;
-
-            unzFile zp = unzOpen2(name, &zpfs);//todo, optimize search in zip
-            OX_ASSERT(zp);
-            if (!zp)
-                return;
-
-            zpitem item;
-            item.handle = zp;
-            strcpy(item.name, name);
-            _zps.push_back(item);
-
-            read(zp);
-        }
-
-        bool Zips::isExists(const char* name)
-        {
-            MutexAutoLock al(_lock);
-            return getEntryByName(name) != 0;
-        }
-
-        bool Zips::read(const char* name, file::buffer& bf)
-        {
-            MutexAutoLock al(_lock);
-
-            const file_entry* entry = getEntryByName(name);
-            if (!entry)
-                return false;
-            return readEntry(entry, bf);
-        }
-
-        bool Zips::read(const file_entry* entry, file::buffer& bf)
-        {
-            MutexAutoLock al(_lock);
-            return readEntry(entry, bf);
-        }
-
-        void Zips::reset()
-        {
-            MutexAutoLock al(_lock);
-            for (zips::iterator i = _zps.begin(); i != _zps.end(); ++i)
-            {
-                zpitem& f = *i;
-                unzClose(f.handle);
-            }
-
-
-#ifdef OX_DEBUG
-            for (files::iterator i = _files.begin(); i != _files.end(); ++i)
-            {
-                OX_ASSERT(i->second.refs == 0);
-            }
-
-#endif
-            _zps.clear();
-            _files.clear();
-        }
-
-        file_entry* Zips::getEntryByName(const char* name)
-        {
-            char str[255];
-            char* p = str;
-            while (*name)
-            {
-                *p = tolower(*name);
-                name++;
-                ++p;
-            }
-            *p = 0;
-
-            files::iterator it = _files.find(str);
-            if (it != _files.end())
-                return &it->second;
-
-            return 0;
-        }
-
-        /*
-        const file_entry* Zips::getEntry(int index)
-        {
-            return &_files[index];
-        }
-
-        size_t Zips::getNumEntries() const
-        {
-            return _files.size();
-        }
-        */
 
 
         class fileHandleZip: public fileHandle
@@ -311,7 +35,7 @@ namespace oxygine
             void release()
             {
                 ZipFileSystem* zfs = static_cast<ZipFileSystem*>(_fs);
-                MutexAutoLock lock(zfs->_zips.getMutex());
+                MutexAutoLock lock(zfs->_zips->getMutex());
                 _entry->refs--;
 
                 int r = unzCloseCurrentFile(_entry->zp);
@@ -387,7 +111,7 @@ namespace oxygine
             ~fileHandleZipStreaming()
             {
                 ZipFileSystem* zfs = static_cast<ZipFileSystem*>(_fs);
-                MutexAutoLock lock(zfs->_zips.getMutex());
+                MutexAutoLock lock(zfs->_zips->getMutex());
                 _entry->refs--;
             }
 
@@ -450,33 +174,33 @@ namespace oxygine
         void ZipFileSystem::add(const char* zip)
         {
             logs::messageln("ZipFileSystem::add %s", zip);
-            _zips.add(zip);
+            _zips->add(zip);
         }
 
         void ZipFileSystem::add(const unsigned char* data, unsigned int size)
         {
-            _zips.add(data, size);
+            _zips->add(data, size);
         }
 
         void ZipFileSystem::add(std::vector<char>& data)
         {
-            _zips.add(data);
+            _zips->add(data);
         }
 
 
         void ZipFileSystem::remove(const char* zip)
         {
-            _zips.remove(zip);
+            _zips->remove(zip);
         }
 
         void ZipFileSystem::reset()
         {
-            _zips.reset();
+            _zips->reset();
         }
 
         FileSystem::status ZipFileSystem::_read(const char* file, file::buffer& bf, error_policy ep)
         {
-            if (_zips.read(file, bf))
+            if (_zips->read(file, bf))
                 return status_ok;
 
             return status_error;
@@ -484,13 +208,13 @@ namespace oxygine
 
         FileSystem::status ZipFileSystem::_open(const char* file, const char* mode, error_policy ep, file::fileHandle*& fh)
         {
-            MutexAutoLock lock(_zips._lock);
+            MutexAutoLock lock(_zips->_lock);
 
-            file_entry* entry = _zips.getEntryByName(file);
+            file_entry* entry = _zips->getEntryByName(file);
             if (entry)
             {
                 if (*mode == 's')
-                    fh = new fileHandleZipStreaming(this, entry, _zips);
+                    fh = new fileHandleZipStreaming(this, entry, *_zips);
                 else
                     fh = new fileHandleZip(this, entry);
                 return status_ok;
@@ -502,7 +226,7 @@ namespace oxygine
 
         bool ZipFileSystem::_isExists(const char* file)
         {
-            return _zips.isExists(file);
+            return _zips->isExists(file);
         }
 
         FileSystem::status ZipFileSystem::_deleteFile(const char* file)

+ 2 - 60
oxygine/src/oxygine/core/ZipFileSystem.h

@@ -1,73 +1,15 @@
 #pragma once
 #include "../oxygine-include.h"
 #include "FileSystem.h"
-#include "../core/Mutex.h"
-#include "../core/file.h"
-#include "../minizip/unzip.h"
-#include <unordered_map>
-#include <vector>
 
 namespace oxygine
 {
     namespace file
     {
-        struct file_entry
-        {
-            unzFile zp;
-            char name[128];
-            unz_file_pos pos;
-            int refs;
-        };
-
-        class Zips
-        {
-        public:
-            Zips();
-            ~Zips();
-
-            void reset();
-
-            void add(const char* name);
-            void add(const unsigned char* data, unsigned int size);
-            void add(std::vector<char>& data);
-            void remove(const char* name);
-
-            bool read(const char* name, file::buffer& bf);
-            bool read(const file_entry* entry, file::buffer& bf);
-            bool isExists(const char* name);
-
-            file_entry*         getEntryByName(const char* name);
-            const char*         getZipFileName(int i) const { return _zps[i].name; }
-            Mutex&              getMutex() { return _lock; }
-
-        private:
-            friend class ZipFileSystem;
-            void read(unzFile zp);
-
-            typedef std::unordered_map<std::string, file_entry> files;
-            files _files;
-
-            struct zpitem
-            {
-                unzFile handle;
-                std::vector<char> data;
-                char name[255];
-
-                zpitem() : handle(0) { name[0] = 0; }
-            };
-            typedef std::vector<zpitem> zips;
-            zips _zps;
-
-            Mutex _lock;
-        };
-
-        bool read(file_entry* entry, file::buffer& bf);
-
-
         class ZipFileSystem: public FileSystem
         {
         public:
-            ZipFileSystem(): FileSystem(true) {}
+            ZipFileSystem();
 
             /**add zip from file*/
             void add(const char* zip);
@@ -83,7 +25,7 @@ namespace oxygine
             friend class fileHandleZip;
             friend class fileHandleZipStreaming;
 
-            Zips _zips;
+            class Zips* _zips;
 
             status _read(const char* file, file::buffer&, error_policy ep);
             status _open(const char* file, const char* mode, error_policy ep, file::fileHandle*& fh);

+ 296 - 0
oxygine/src/oxygine/core/Zips.cpp

@@ -0,0 +1,296 @@
+#include "Zips.h"
+#include "../core/Object.h"
+#include "../minizip/ioapi_mem.h"
+#include "../utils/stringUtils.h"
+#include <algorithm>
+#include <map>
+#include <string.h>
+
+namespace oxygine
+{
+    namespace file
+    {
+    bool sortFiles(const file_entry& ob1, const file_entry& ob2)
+    {
+        return strcmp_cns(ob1.name, ob2.name) < 0;
+    }
+
+    bool readEntry(const file_entry* entry, file::buffer& bf)
+    {
+        bf.data.clear();
+        int r = unzGoToFilePos(entry->zp, const_cast<unz_file_pos*>(&entry->pos));
+        OX_ASSERT(r == UNZ_OK);
+
+        unz_file_info file_info;
+        r = unzGetCurrentFileInfo(entry->zp, &file_info, 0, 0, 0, 0, 0, 0);
+        OX_ASSERT(r == UNZ_OK);
+
+        unzOpenCurrentFile(entry->zp);
+
+        bf.data.resize(file_info.uncompressed_size);
+        r = unzReadCurrentFile(entry->zp, &bf.data.front(), (int)bf.data.size());
+        OX_ASSERT(r == (int)file_info.uncompressed_size);
+
+        unzCloseCurrentFile(entry->zp);
+        return true;
+    }
+
+    Zips::Zips() : _lock(true)
+    {
+
+    }
+
+    Zips::~Zips()
+    {
+        reset();
+    }
+
+    void Zips::read(unzFile zp)
+    {
+        //MutexAutoLock al(_lock);
+
+        do
+        {
+            unz_file_pos pos;
+            unzGetFilePos(zp, &pos);
+
+            file_entry entry;
+            unzGetCurrentFileInfo(zp, 0, entry.name, sizeof(entry.name) - 1, 0, 0, 0, 0);
+            entry.refs = 0;
+            entry.pos = pos;
+            entry.zp = zp;
+
+            char* str = entry.name;
+            for (int i = 0; str[i]; i++)
+                str[i] = tolower(str[i]);
+
+
+            OX_ASSERT(_files.find(entry.name) == _files.end());
+
+            _files[entry.name] = entry;
+
+        } while (unzGoToNextFile(zp) != UNZ_END_OF_LIST_OF_FILE);
+
+    }
+
+    void Zips::add(const unsigned char* data, unsigned int size)
+    {
+        MutexAutoLock al(_lock);
+
+        zlib_filefunc_def ff;
+        fill_memory_filefunc(&ff);
+
+        zmemdata dta;
+        dta.data = (char*)data;
+        dta.size = size;
+
+        unzFile zp = unzOpen2((const char*)&dta, &ff);
+        OX_ASSERT(zp);
+        if (!zp)
+            return;
+
+
+        zpitem item;
+        item.handle = zp;
+        _zps.push_back(item);
+
+        read(zp);
+    }
+
+    void Zips::add(std::vector<char>& data)
+    {
+        MutexAutoLock al(_lock);
+
+        zlib_filefunc_def ff;
+        fill_memory_filefunc(&ff);
+
+        zmemdata dta;
+        dta.data = (char*)&data.front();
+        dta.size = data.size();
+
+        unzFile zp = unzOpen2((const char*)&dta, &ff);
+        OX_ASSERT(zp);
+        if (!zp)
+            return;
+
+        _zps.push_back(zpitem());
+        zpitem& item = _zps.back();
+        item.handle = zp;
+        std::swap(item.data, data);
+
+        read(zp);
+    }
+
+    voidpf ZCALLBACK ox_fopen(voidpf opaque, const char* filename, int mode)
+    {
+        return file::open(filename, "rb");
+    }
+
+    uLong ZCALLBACK ox_fread(voidpf opaque, voidpf stream, void* buf, uLong size)
+    {
+        return file::read((handle)stream, buf, (unsigned int)size);
+    }
+
+    /*
+    uLong ZCALLBACK ox_fwriteOF(voidpf opaque, voidpf stream, const void* buf, uLong size)
+    {
+
+    }
+    */
+
+    long ZCALLBACK ox_ftell(voidpf opaque, voidpf stream)
+    {
+        return file::tell((handle)stream);
+    }
+
+    long ZCALLBACK ox_fseek(voidpf opaque, voidpf stream, uLong offset, int origin)
+    {
+        file::seek((handle)stream, (unsigned int)offset, origin);
+        return 0;
+    }
+
+    int ZCALLBACK ox_fclose(voidpf opaque, voidpf stream)
+    {
+        file::close((handle)stream);
+        return 0;
+    }
+
+    int ZCALLBACK ox_ferror(voidpf opaque, voidpf stream)
+    {
+        return 0;
+    }
+
+    void Zips::remove(const char* name)
+    {
+        MutexAutoLock al(_lock);
+
+        for (size_t i = 0; i < _zps.size(); ++i)
+        {
+            zpitem& item = _zps[i];
+            if (!strcmp(item.name, name))
+            {
+                for (files::iterator it = _files.begin(); it != _files.end();)
+                {
+                    file_entry& entry = it->second;
+                    if (entry.zp == item.handle)
+                    {
+                        OX_ASSERT(entry.refs == 0);
+                        it = _files.erase(it);
+                    }
+                    else
+                        ++it;
+                }
+
+                unzClose(item.handle);
+
+                _zps.erase(_zps.begin() + i);
+                break;
+            }
+        }
+    }
+
+    void Zips::add(const char* name)
+    {
+        MutexAutoLock al(_lock);
+
+        zlib_filefunc_def zpfs;
+        memset(&zpfs, 0, sizeof(zpfs));
+
+        zpfs.zopen_file = ox_fopen;
+        zpfs.zread_file = ox_fread;
+        zpfs.zwrite_file = 0;
+        zpfs.ztell_file = ox_ftell;
+        zpfs.zseek_file = ox_fseek;
+        zpfs.zclose_file = ox_fclose;
+        zpfs.zerror_file = ox_ferror;
+        zpfs.opaque = (void*)_zps.size();
+        //zpfs.opaque = name;
+
+        unzFile zp = unzOpen2(name, &zpfs);//todo, optimize search in zip
+        OX_ASSERT(zp);
+        if (!zp)
+            return;
+
+        zpitem item;
+        item.handle = zp;
+        strcpy(item.name, name);
+        _zps.push_back(item);
+
+        read(zp);
+    }
+
+    bool Zips::isExists(const char* name)
+    {
+        MutexAutoLock al(_lock);
+        return getEntryByName(name) != 0;
+    }
+
+    bool Zips::read(const char* name, file::buffer& bf)
+    {
+        MutexAutoLock al(_lock);
+
+        const file_entry* entry = getEntryByName(name);
+        if (!entry)
+            return false;
+        return readEntry(entry, bf);
+    }
+
+    bool Zips::read(const file_entry* entry, file::buffer& bf)
+    {
+        MutexAutoLock al(_lock);
+        return readEntry(entry, bf);
+    }
+
+    void Zips::reset()
+    {
+        MutexAutoLock al(_lock);
+        for (zips::iterator i = _zps.begin(); i != _zps.end(); ++i)
+        {
+            zpitem& f = *i;
+            unzClose(f.handle);
+        }
+
+
+#ifdef OX_DEBUG
+        for (files::iterator i = _files.begin(); i != _files.end(); ++i)
+        {
+            OX_ASSERT(i->second.refs == 0);
+        }
+
+#endif
+        _zps.clear();
+        _files.clear();
+    }
+
+    file_entry* Zips::getEntryByName(const char* name)
+    {
+        char str[255];
+        char* p = str;
+        while (*name)
+        {
+            *p = tolower(*name);
+            name++;
+            ++p;
+        }
+        *p = 0;
+
+        files::iterator it = _files.find(str);
+        if (it != _files.end())
+            return &it->second;
+
+        return 0;
+    }
+
+    /*
+    const file_entry* Zips::getEntry(int index)
+    {
+    return &_files[index];
+    }
+
+    size_t Zips::getNumEntries() const
+    {
+    return _files.size();
+    }
+    */
+     }
+}

+ 67 - 0
oxygine/src/oxygine/core/Zips.h

@@ -0,0 +1,67 @@
+#pragma once
+#include "../oxygine-include.h"
+#include "FileSystem.h"
+#include "../core/Mutex.h"
+#include "../core/file.h"
+#include "../minizip/unzip.h"
+#include <unordered_map>
+#include <vector>
+
+
+namespace oxygine
+{
+    namespace file
+    {
+    struct file_entry
+    {
+        unzFile zp;
+        char name[128];
+        unz_file_pos pos;
+        int refs;
+    };
+
+    class Zips
+    {
+    public:
+        Zips();
+        ~Zips();
+
+        void reset();
+
+        void add(const char* name);
+        void add(const unsigned char* data, unsigned int size);
+        void add(std::vector<char>& data);
+        void remove(const char* name);
+
+        bool read(const char* name, file::buffer& bf);
+        bool read(const file_entry* entry, file::buffer& bf);
+        bool isExists(const char* name);
+
+        file_entry*         getEntryByName(const char* name);
+        const char*         getZipFileName(int i) const { return _zps[i].name; }
+        Mutex&              getMutex() { return _lock; }
+
+    private:
+        friend class ZipFileSystem;
+        void read(unzFile zp);
+
+        typedef std::unordered_map<std::string, file_entry> files;
+        files _files;
+
+        struct zpitem
+        {
+            unzFile handle;
+            std::vector<char> data;
+            char name[255];
+
+            zpitem() : handle(0) { name[0] = 0; }
+        };
+        typedef std::vector<zpitem> zips;
+        zips _zps;
+
+        Mutex _lock;
+    };
+
+    bool read(file_entry* entry, file::buffer& bf);
+    }
+}

+ 56 - 0
oxygine/system_data_demo/build.py

@@ -0,0 +1,56 @@
+import os
+import shutil
+import zipfile
+
+shutil.rmtree("data", True)
+shutil.copytree("original", "data")
+os.system("..\\..\\tools\\oxyresbuild.py -x demo\\res.xml --src_data data --dest_data data\\demo --nopng")
+
+shutil.rmtree("data/demo/anims/")
+
+
+def recursive_zip(zipf, directory, folder = ""):
+    for item in os.listdir(directory):
+        if os.path.isfile(os.path.join(directory, item)):
+            zipf.write(os.path.join(directory, item), folder + os.sep + item)
+        elif os.path.isdir(os.path.join(directory, item)):
+            recursive_zip(zipf, os.path.join(directory, item), folder + os.sep + item)
+      
+      
+import cStringIO
+data = cStringIO.StringIO()
+with zipfile.ZipFile(data, "w", zipfile.ZIP_DEFLATED) as zp:
+    recursive_zip(zp, "data")
+
+fmtH = """
+#pragma once
+#ifndef %(MODULE)s_DATA
+#define %(MODULE)s_DATA
+extern unsigned int %(module)s_size;
+extern const unsigned char %(module)s_data[];
+#endif
+"""
+
+fmtCPP = """
+#include "%(HEADER)s"
+unsigned int %(module)s_size = %(SIZE)d;
+const unsigned char %(module)s_data[] = {%(DATA)s};
+
+"""
+
+def gen(module, data):
+    st = ",".join("0x{:02x}".format(ord(c)) for c in data)
+    MODULE = module.upper()
+    SIZE = len(data)
+    DATA = st
+    args = {"MODULE":MODULE, "SIZE":SIZE, "DATA":DATA, "module":module, "HEADER":module + "_data.h"}
+    return (fmtH % args, fmtCPP % args, )
+    
+rs = gen("system", data.getvalue())
+with open("demo_data.h", "w") as fh:
+    fh.write(rs[0])
+with open("demo_data.cpp", "w") as fh:
+    fh.write(rs[1])
+
+with open("demo.zip", "wb") as zp:
+    zp.write(data.getvalue())

binární
oxygine/system_data_demo/original/demo/anims/loading.png


+ 1 - 1
examples/Demo/data/ext/fonts.xml.ox/bmfc_font/big.fnt → oxygine/system_data_demo/original/demo/fonts/big.fnt

@@ -2,7 +2,7 @@
   <info aa="1" bold="1" charset="" face="Arial" italic="0" outline="0" padding="0,0,0,0" size="-26" smooth="1" spacing="1,1" stretchH="100" unicode="1"/>
   <common alphaChnl="0" base="24" blueChnl="4" greenChnl="4" lineHeight="30" packed="0" pages="1" redChnl="4" scaleH="128" scaleW="512"/>
   <pages>
-    <page file="big_0.png" id="0"/>
+    <page file="big_0.tga" id="0"/>
   </pages>
   <chars count="100">
     <char chnl="15" height="1" id="32" page="0" width="3" x="98" xadvance="7" xoffset="-1" y="23" yoffset="29"/>

binární
oxygine/system_data_demo/original/demo/fonts/big_0.tga


+ 1 - 1
examples/Demo/data/ext/fonts.xml.ox/bmfc_font/main.fnt → oxygine/system_data_demo/original/demo/fonts/main.fnt

@@ -2,7 +2,7 @@
   <info aa="1" bold="1" charset="" face="Arial" italic="0" outline="0" padding="0,0,0,0" size="-16" smooth="1" spacing="1,1" stretchH="100" unicode="1"/>
   <common alphaChnl="0" base="15" blueChnl="4" greenChnl="4" lineHeight="19" packed="0" pages="1" redChnl="4" scaleH="64" scaleW="512"/>
   <pages>
-    <page file="main_0.png" id="0"/>
+    <page file="main_0.tga" id="0"/>
   </pages>
   <chars count="100">
     <char chnl="15" height="1" id="32" page="0" width="3" x="495" xadvance="4" xoffset="-1" y="13" yoffset="18"/>

binární
oxygine/system_data_demo/original/demo/fonts/main_0.tga


+ 11 - 0
oxygine/system_data_demo/original/demo/res.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<resources>
+	<set path = "./anims" />
+	<atlas>
+		<image file="loading.png"/>
+	</atlas>
+	
+	<set path = "./fonts" />
+	<font file="big.fnt" version="7"/>	
+	<font file="main.fnt" version="7"/>	
+</resources>

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů