游戲引擎中的文件系統是非常重要的一環,基本的文件系統功能不外乎以下功能:
1.打開文件
2.檢測文件是否存在
3.獲取給定文件目錄列表
4.文件其它操作
5.各類文件的處理(日志,xml等等)
蓋莫游戲引擎也有必要有自己內置的文件系統來管理引擎所使用的文件或者資源。
以下是簡單的測試例子:
1 #include <GEngine/Gaimo.hpp>
2 using namespace std;
3
4 int main(int argc, char **argv)
5 {
6 //! 初始化引擎設備并得到設備指針
7 core::Device* device = core::InitDevice("蓋莫引擎文件系統測試");
8 core::Render::SetClearColor(core::Color(0.5f,0.6f,0.6f));
9
10 //! 獲取文件系統指針
11 core::RefPtr<core::FileSystem> filesystem = device->GetFileSystem();
12 //! 獲取引擎資源管理器
13 core::ResourceManager* resmgr = device->GetResourceManager();
14
15 filesystem->AddToSearchPath("..\\font\\font.zip");
16 bool flag = filesystem->IsExists("accid.ttf");
17 if(flag == false)
18 {
19 ShowMessage(不存在字體文件accid.ttf)
20 device->Close();
21 device->Drop();
22 return -1;
23 }
24
25 //! 讀取文件數據
26 core::RefPtr<core::ReadFile> file = filesystem->OpenRead("accid.ttf");
27
28 //! 使用給定字體文件(ttf)
29 core::RefPtr<core::Text> font = resmgr->GetText("newfont",file,18);
30
31 int fps;
32 char text[255];
33 BEGIN_LOOP(device)
34 glClear(GL_COLOR_BUFFER_BIT);
35 fps = device->GetFPS();
36 sprintf(text,"fps is: %d",fps);
37 font->Render(540,0,text);
38 font->Render(200,80, "This demo is testing GEngine's FileySystem.");
39 font->Render(250,105, "GaimoSoft Studio.");
40 END_LOOP(device)
41
42 device->Close();
43 device->Drop();
44
45 return 0;
46 }
47
48
下面是簡單的貼圖:

從代碼中可以看出引擎對zip壓縮格式是內置支持的