diff --git a/JGE/include/JFileSystem.h b/JGE/include/JFileSystem.h index a587c1ca3..3dbe494b9 100644 --- a/JGE/include/JFileSystem.h +++ b/JGE/include/JFileSystem.h @@ -35,6 +35,14 @@ using namespace std; /// ////////////////////////////////////////////////////////////////////////// +class JZipCache { +public: + JZipCache(); + ~JZipCache(); + map dir; + +}; + class JFileSystem { public: @@ -109,10 +117,12 @@ protected: private: static JFileSystem* mInstance; + mapmZipCache; string mResourceRoot; string mZipFileName; char *mPassword; bool mZipAvailable; + void preloadZip(string filename); #if defined (WIN32) || defined (LINUX) FILE *mFile; #else diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index 294e7fad3..6d04ef89d 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -23,6 +23,41 @@ #include #include + +JZipCache::JZipCache(){} + +JZipCache::~JZipCache(){ + map::iterator it; + for (it = dir.begin(); it != dir.end(); it++){ + delete(it->second); + } + dir.clear(); +} + +void JFileSystem::preloadZip(string filename){ + map::iterator it = mZipCache.find(filename); + if (it != mZipCache.end()) return; + + JZipCache * cache = new JZipCache(); + mZipCache[filename] = cache; + + if (!mZipAvailable || !mZipFile) { + AttachZipFile(filename); + if (!mZipAvailable || !mZipFile) return; + } + int err = unzGoToFirstFile (mZipFile); + while (err == UNZ_OK){ + unz_file_pos* filePos = new unz_file_pos(); + char filenameInzip[4096]; + if (unzGetCurrentFileInfo(mZipFile, NULL, filenameInzip, sizeof(filenameInzip), NULL, 0, NULL, 0) == UNZ_OK){ + unzGetFilePos(mZipFile, filePos); + string name = filenameInzip; + cache->dir[name] = filePos; + } + err = unzGoToNextFile(mZipFile); + } +} + JFileSystem* JFileSystem::mInstance = NULL; JFileSystem* JFileSystem::GetInstance() @@ -69,6 +104,12 @@ JFileSystem::JFileSystem() JFileSystem::~JFileSystem() { DetachZipFile(); + + map::iterator it; + for (it = mZipCache.begin(); it != mZipCache.end(); it++){ + delete(it->second); + } + mZipCache.clear(); } @@ -117,10 +158,19 @@ bool JFileSystem::OpenFile(const string &filename) if (mZipAvailable && mZipFile != NULL) { - if (unzLocateFile(mZipFile, filename.c_str(), 0) != UNZ_OK){ + preloadZip(mZipFileName); + map::iterator it = mZipCache.find(mZipFileName); + if (it == mZipCache.end()){ DetachZipFile(); - return OpenFile(filename); - } + return OpenFile(filename); + } + JZipCache * zc = it->second; + map::iterator it2 = zc->dir.find(filename); + if (it2 == zc->dir.end()){ + DetachZipFile(); + return OpenFile(filename); + } + unzGoToFilePos(mZipFile,it2->second); char filenameInzip[256]; unz_file_info fileInfo; diff --git a/projects/mtg/src/GameObserver.cpp b/projects/mtg/src/GameObserver.cpp index 255a71ea9..d4cc7c7ed 100644 --- a/projects/mtg/src/GameObserver.cpp +++ b/projects/mtg/src/GameObserver.cpp @@ -155,6 +155,14 @@ void GameObserver::startGame(int shuffle, int draw){ for (i=0; igame->initGame(shuffle, draw); } + + //Preload images from hand + if (!players[0]->isAI()){ + for (i=0; i< players[0]->game->hand->nb_cards; i++){ + players[0]->game->hand->cards[i]->getThumb(); + players[0]->game->hand->cards[i]->getQuad(); + } + } turn = 0; phaseRing->goToPhase(Constants::MTG_PHASE_FIRSTMAIN, players[0]); currentGamePhase = Constants::MTG_PHASE_FIRSTMAIN;