Mpq file system optimization (continued)

Source: Internet
Author: User

God, parsing by yourself (listfile) is an error!

Because stormlib has already parsed itself when opening the mpq file, there is no need to do so!

Besides, although caching the file tree by yourself will speed up searching and enumeration, it takes too long to construct the tree from a string ~~~

This leads to a very serious problem: Slow startup .......

For the file tree, the game is useless, because when the game reads files, no matter what directory, you can view the directory as part of the file name.

In other words, there is no directory in the mpq package!

When the editor needs to list files/folders, You can enumerate all files and then judge the string:

// Configure <br/> array <string> <br/> mpqarchive: listfiles (const string & dirpathinmpqarchive, const string & pattern) <br/>{< br/> array <string> result; <br/> string filemask (dirpathinmpqarchive); <br/> filemask. substitutechar ('/', '//'); <br/> If (filemask [filemask. length ()-1]! = '//') <Br/>{< br/> filemask. append ("//"); <br/>}< br/> filemask. append (pattern); <br/> // start to find <br/> sfile_find_data finddata; <br/> bool found = true; <br/> handle filehandle = sfilefindfirstfile (this-> mpqfilehandle, filemask. ascharptr (), & finddata, null); <br/> while (0! = Filehandle & True = found) <br/>{< br/> result. append (string (finddata. cfilename ). extractfilename (); <br/> found = sfilefindnextfile (filehandle, & finddata); <br/>}</P> <p> return result; <br/>}< br/>

The following is my "unit" Test Program (hey, pack a nice name). It will not take more than 2 seconds to run. In debug mode

// ------------------------------------------------------------------------------ <Br/> // mpqfilesystemtest. CC <br/> // (c) 2008 xoyojank <br/> // -------------------------------------------------------------------------------- <br/> # include "stdneb. H "<br/> # include" mpqfilesystemtest. H "<br/> # include" interface/iointerface. H "</P> <p> namespace test <br/>{< br/>__ implementclass (test: mpqfilesystemtest, 'mqft ', test: testcase ); </P> <p> using namespace IO; <br/> using namespace interface; <br/> using namespace util; </P> <p> // example <br/>/** <br/> */<br/> void <br/> mpqfilesystemtest: Run () <br/>{< br/> PTR <ioserver> ioserver = ioserver: Create (); <br/> ioserver-> setzipfilesystemenabled (false ); <br/> ioserver-> registerstandardurischemes (); <br/> ioserver-> mountwowmpqarchives (); <br/> // n_assert (ioserver-> isfileexsit ("Wow: creature/CAT/cat. m2 "); <br/> array <string> catfiles = ioserver-> listfiles (" Wow: creature/cat ","*. * "); <br/> for (indext I = 0; I <catfiles. size (); ++ I) <br/>{< br/> n_printf ("% s/n", catfiles [I]. ascharptr (); <br/>}< br/> array <string> chardirs = ioserver-> listdirectories ("Wow: character ","*"); <br/> for (indext I = 0; I <chardirs. size (); ++ I) <br/>{< br/> n_printf ("% s/n", chardirs [I]. ascharptr (); <br/>}< br/> URI uri = "Wow: character/bloodelf/hair00_00.blp "; <br/> PTR <stream> Texture = ioserver-> createstream (URI); <br/> texture-> open (); <br/> array <char> buffer (texture-> getsize (), 0, 0); <br/> texture-> Read (& buffer. front (), texture-> getsize (); <br/> texture-> close (); <br/>}</P> <p >}// namespace test </P> <p>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.