前面介紹類LLFeatureManager的聲明部分,現在繼續前面的內容進行分析,來看看它的實現代碼,到底是怎么獲取文本文件里的內容。先來看看它需要分析顯示特性文件的內容是怎么樣的,如下:
version 10
?
// NOTE: This is mostly identical to featuretable_mac.txt with a few differences
// Should be combined into one table
?
//
// Generates lists of feature mask that can be applied on top of each other.
//
//
?????? //????? Begin comments
//
?????? list <name>
//
?????? Starts a feature list named <name>
//
?????? <name> <available> <recommended>
//
?????? <name> is the name of a feature
//
?????? <available> is 0 or 1, whether the feature is available
//
?????? <recommended> is an S32 which is the recommended value
//
// For now, the first list read sets up all of the default values
//
?
?
//
// All contains everything at their default settings for high end machines
// NOTE: All settings are set to the MIN of applied values, including 'all'!
//
list all
RenderVBO
??????????? 1?? 1
RenderAniso
????????? 1?? 0
RenderAvatarMode
1?? 2
RenderAvatarVP
?????? 1?? 1
RenderDistance
?????? 1?? 128
RenderLighting
?????? 1?? 1
RenderObjectBump
1?? 1
RenderParticleCount?1
?? 4096
RenderRippleWater
??? 1?? 1
RenderTerrainDetail?1
?? 2
VertexShaderEnable
?? 1?? 1
UseOcclusion
???? 1?? 1
RenderCubeMap
??????? 1?? 1
?
//
// Class 0 Hardware (Unknown or just old)
//
list Class0
VertexShaderEnable
?? 1?? 0
RenderVBO
??????????? 1?? 0
RenderDistance
?????? 1?? 64
RenderAvatarVP
?????? 1?? 0
RenderAvatarMode
1?? 0
RenderLighting
?????? 1?? 0
RenderObjectBump
1?? 0
RenderRippleWater
??? 1?? 0
?
//
// Class 1 Hardware
//
list Class1
VertexShaderEnable
?? 1?? 0
RenderVBO
??????????? 1?? 1
RenderDistance
?????? 1?? 96
RenderAvatarVP
?????? 1?? 1
RenderAvatarMode
1?? 0
RenderLighting
?????? 1?? 0
RenderObjectBump
1?? 0
RenderRippleWater
??? 1?? 0
?
//
// Class 2 Hardware (make it purty)
//
list Class2
VertexShaderEnable
?? 1?? 1
RenderAvatarVP
?????? 1?? 1
RenderAvatarMode
1?? 1
RenderLighting
?????? 1?? 1
RenderObjectBump
1?? 1
RenderRippleWater
??? 1?? 1
?
//
// Class 3 Hardware (make it purty)
//
list Class3
VertexShaderEnable
?? 1?? 1
RenderAvatarVP
?????? 1?? 1
RenderAvatarMode
1?? 1
RenderLighting
?????? 1?? 1
RenderObjectBump
1?? 1
RenderRippleWater
??? 1?? 1
?
//
// No Pixel Shaders available
//
list NoPixelShaders
VertexShaderEnable
?? 0?? 0
RenderAvatarVP
?????? 0?0
?
//
// No Vertex Shaders available
//
list NoVertexShaders
VertexShaderEnable
?? 0?? 0
RenderAvatarVP
?????? 0?0
?
//
// "Default" setups for safe, low, medium, high
//
list safe
RenderVBO
??????????? 1?? 0
RenderAniso
????????? 1?? 0
RenderAvatarVP
?????? 0?? 0
RenderLighting
?????? 1?? 0
RenderParticleCount?1
?? 1024
RenderTerrainDetail 1
??? 0
?
?
list low
RenderVBO
??????????? 1?? 0
RenderAniso
????????? 1?? 0
RenderLighting
?????? 1?? 0
?
list medium
RenderLighting
?????? 1?? 0
?
?
//
// CPU based feature masks
//
?
// 1Ghz or less (equiv)
list CPUSlow
RenderParticleCount?1
?? 1024
?
?
//
// RAM based feature masks
//
list RAM256MB
RenderObjectBump
0?? 0
?
?
//
// Graphics card based feature masks
//
list OpenGLPre15
RenderVBO
??????????? 1?? 0
?
list Intel
RenderVBO
??????????? 1?? 0
RenderAniso
????????? 1?? 0
RenderLighting
?????? 1?? 0
RenderTerrainDetail?1
?? 0
?
list GeForce2
RenderVBO
??????????? 1?? 1
RenderAniso
????????? 1?? 0
RenderLighting
?????? 1?? 0
RenderParticleCount?1
?? 2048
RenderTerrainDetail?1
?? 0
?
list ATI_Mobility_Radeon_X3xx
VertexShaderEnable
?? 1?? 0
?
list ATI_Mobility_Radeon_X6xx
VertexShaderEnable
?? 1?? 0
?
?
現在就來查看怎么樣使用代碼來分析上面的文件內容,加載和分析文件代碼如下:
#001?void LLFeatureManager::init()
#002?{
?
下面函數就是打開文件,并分析文件數據。
#003?
?? // load the tables
#004?
?? loadFeatureTables();
#005?
?
下面函數加載
GPU的類內容。
#006?
?? // get the gpu class
#007?
?? loadGPUClass();
#008?
?
下面函數應用所有需要顯示特性。
#009?
?? // apply the base masks, so we know if anything is disabled
#010?
?? applyBaseMasks();
#011?}
?
?
接著來分析函數
loadFeatureTables,它的代碼如下:
#001?BOOL LLFeatureManager::loadFeatureTables()
#002?{
#003?
?? // *TODO - if I or anyone else adds something else to the skipped list
#004?
?? // make this data driven.?Put it in the feature table and parse it
#005?
?? // correctly
?
插入幾個集合。
#006?
?? mSkippedFeatures.insert("RenderAnisotropic");
#007?
?? mSkippedFeatures.insert("RenderGamma");
#008?
?? mSkippedFeatures.insert("RenderVBOEnable");
#009?
?? mSkippedFeatures.insert("RenderFogRatio");
#010?
?
獲取文件所在的目錄。
#011?
?? std::string data_path = gDirUtilp->getAppRODataDir();
#012?
?
獲取目錄分隔符。
#013?
?? data_path += gDirUtilp->getDirDelimiter();
#014?
?
獲取顯示特性文件的名稱。
#015?
?? data_path += FEATURE_TABLE_FILENAME;
#016?
#017?
#018?
?? char??? name[MAX_STRING+1]; /*Flawfinder: ignore*/
#019?
#020?
?? llifstream file;
#021?
?? U32???? version;
#022?
??
?
用
API函數打開文件featuretable.txt。
#023?
?? file.open(data_path.c_str()); ??/*Flawfinder: ignore*/
#024?
?
判斷文件是否打開成功。
#025?
?? if (!file)
#026?
?? {
#027?
?????? llwarns << "Unable to open feature table!" << llendl;
#028?
?????? return FALSE;
#029?
?? }
#030?
?
讀取文件第一行的版本并檢查。
#031?
?? // Check file version
#032?
?? file >> name;
#033?
?? file >> version;
#034?
?? if (strcmp(name, "version"))
#035?
?? {
#036?
?????? llwarns << data_path << " does not appear to be a valid feature table!" << llendl;
#037?
?????? return FALSE;
#038?
?? }
#039?
?
保存文件的版本。
#040?
?? mTableVersion = version;
#041?
?
下面循環地分析這個文件直到文件結束。
#042?
?? LLFeatureList *flp = NULL;
#043?
?? while (!file.eof())
#044?
?? {
#045?
?????? char buffer[MAX_STRING];??????? /*Flawfinder: ignore*/
#046?
?????? name[0] = 0;
#047?
?
讀取一個集合的名稱。
#048?
?????? file >> name;
#049?
??????
?
跳過一些沒用的行內容。
#050?
?????? if (strlen(name) >= 2 && ?? ?/*Flawfinder: ignore*/
#051?
?????????? name[0] == '/' &&
#052?
?????????? name[1] == '/')
#053?
?????? {
#054?
?????????? // This is a comment.
#055?
?????????? file.getline(buffer, MAX_STRING);
#056?
?????????? continue;
#057?
?????? }
#058?
#059?
?????? if (strlen(name) == 0)????? /*Flawfinder: ignore*/
#060?
?????? {
#061?
?????????? // This is a blank line
#062?
?????????? file.getline(buffer, MAX_STRING);
#063?
?????????? continue;
#064?
?????? }
#065?
?
判斷是否讀取一個列表特性字段。
#066?
?????? if (!strcmp(name, "list"))
#067?
?????? {
?
分析到
list一段內容了。
#068?
?????????? if (flp)
#069?
?????????? {
#070?
?????????????? //flp->dump();
#071 ?
?????????? }
?
讀取
list段的名稱。
#072?
?????????? // It's a new mask, create it.
#073?
?????????? file >> name;
#074?
?????????? if (mMaskList.count(name))
#075?
?????????? {
#076?
?????????????? llerrs << "Overriding mask " << name << ", this is invalid!" << llendl;
#077?
?????????? }
#078?
?
創建保存整個
list段的列表管理。
#079?
?????????? flp = new LLFeatureList(name);
#080?
?????????? mMaskList[name] = flp;
#081?
?????? }
#082?
?????? else
#083?
?????? {
?
一行一行地讀取
list中的元素。
#084?
?????????? if (!flp)
#085?
?????????? {
#086?
?????????????? llerrs << "Specified parameter before <list> keyword!" << llendl;
#087?
?????????? }
#088?
?????????? S32 available;
#089 ?
?????????? F32 recommended;
#090?
?????????? file >> available >> recommended;
?
把一行的元素特征保存到創建的
list里。
#091?
?????????? flp->addFeature(name, available, recommended);
#092?
?????? }
#093?
?? }
?
下面關閉文件。
#094?
?? file.close();
#095?
#096?
?? return TRUE;
#097?}
?
上面這段代碼是先分析
eaturetable.txt的版本,然后依次分析list段內容,直到把所有list段內容分析完成,最后把分析出來的特性內容保存到類LLFeatureList列表里面,其它類需要使用時,就可以直接從這個LLFeatureList類里讀取相應的內容出來,達到判斷顯示卡是否滿足運行這個游戲的目的。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
