前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MPQ文件系统优化(续)

MPQ文件系统优化(续)

作者头像
逍遥剑客
发布2018-05-23 11:44:25
9160
发布2018-05-23 11:44:25
举报
文章被收录于专栏:逍遥剑客的游戏开发

天啊, 自己解析(listfile)本身就是一个错误!

因为StormLib在打开MPQ文件时就已经自己解析过了, 没必要多此一举!

而且, 虽然自己缓存一下文件树会加快查找和枚举的速度, 但是, 从字符串构造这个棵树的时间太长了~~~

这就导致了一个很严重的问题: 启动速度慢.......

对于文件树, 游戏没有什么用, 因为游戏读文件时根本不管是什么目录, 你可以把目录也看是文件名的一部分

换句话说, MPQ包里根本就没有目录的概念!

而对于编辑器等需要列举文件/文件夹列表的场合, 直接对所有文件进行枚举再判断字符串即可:

代码语言:javascript
复制
//------------------------------------------------------------------------------  
Array<String>  
MpqArchive::ListFiles(const String& dirPathInMpqArchive, const String& pattern)  
{  
    Array<String> result;  
    String fileMask(dirPathInMpqArchive);  
    fileMask.SubstituteChar('/', '//');  
 if (fileMask[fileMask.Length() - 1] != '//')  
    {  
        fileMask.Append("//");  
    }  
    fileMask.Append(pattern);  
 // start to find  
    SFILE_FIND_DATA findData;  
 BOOL found = TRUE;  
 HANDLE fileHandle = SFileFindFirstFile(this->mpqFileHandle, fileMask.AsCharPtr(), &findData, NULL);   
 while (0 != fileHandle && TRUE == found)  
    {  
        result.Append(String(findData.cFileName).ExtractFileName());  
        found = SFileFindNextFile(fileHandle, &findData);  
    }  
 return result;  
}  

下面是我的"单元"测试程序(嘿嘿, 包装一个好听的名字), 运行一下不会超过2秒, DEBUG模式下

代码语言:javascript
复制
//------------------------------------------------------------------------------  
//  mpqfilesystemtest.cc  
//  (C) 2008 xoyojank  
//------------------------------------------------------------------------------  
#include "stdneb.h"  
#include "mpqfilesystemtest.h"  
#include "interface/iointerface.h"  
namespace Test  
{  
__ImplementClass(Test::MpqFileSystemTest, 'MQFT', Test::TestCase);  
using namespace IO;  
using namespace Interface;  
using namespace Util;  
//------------------------------------------------------------------------------  
/** 
*/ 
void 
MpqFileSystemTest::Run()  
{  
    Ptr<IoServer> ioServer = IoServer::Create();  
    ioServer->SetZipFileSystemEnabled(false);  
    ioServer->RegisterStandardUriSchemes();  
    ioServer->MountWoWMpqArchives();  
 //n_assert(ioServer->IsFileExsit("wow:Creature/Cat/Cat.m2"));  
    Array<String> catFiles = ioServer->ListFiles("wow:Creature/Cat", "*.*");  
 for (IndexT i = 0; i < catFiles.Size(); ++i)  
    {  
        n_printf("%s/n", catFiles[i].AsCharPtr());  
    }  
    Array<String> charDirs = ioServer->ListDirectories("wow:Character", "*");  
 for (IndexT i = 0; i < charDirs.Size(); ++i)  
    {  
        n_printf("%s/n", charDirs[i].AsCharPtr());  
    }  
    URI uri = "wow:Character/BloodElf/HAIR00_00.blp";  
    Ptr<Stream> texture = ioServer->CreateStream(uri);  
    texture->Open();  
    Array<char> buffer(texture->GetSize(), 0, 0);  
    texture->Read(&buffer.Front(), texture->GetSize());  
    texture->Close();  
}  
} // namespace Test  
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2009年01月07日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档