📄 settings.cpp
字号:
#include <fstream>#include <string>using namespace std;#include "settings.h"#include "global.h"
/////////////////////////////////////////////////////////////////////////
int GcSettings::screenWidth = SCREEN_WIDTH;
int GcSettings::screenHeight = SCREEN_HEIGHT;
int GcSettings::screenDepth = SCREEN_DEPTH;
int GcSettings::fullScreen = FULL_SCREEN;
int GcSettings::renderMethod = REND_USE_ARRAY;
int GcSettings::useColor = 0;
int GcSettings::useLight = 0;
int GcSettings::useFog = 0;
int GcSettings::fogDepth = 1300;
int GcSettings::drawSkybox = 0;
int GcSettings::showDebug = 0;
int GcSettings::showHUD = 0;
int GcSettings::detailTex = 32;
int GcSettings::scale = 200;
int GcSettings::heightScale = 20;
bool GcSettings::multiTexture = 0;
bool GcSettings::videoMemory = 0;
bool GcSettings::gravity = 0;
char GcSettings::heighMapPath[80];
char GcSettings::landTexPath[80];
/////////////////////////////////////////////////////////////////////////GcSettings::GcSettings(){}/////////////////////////////////////////////////////////////////////////GcSettings::~GcSettings(){}/////////////////////////////////////////////////////////////////////////bool GcSettings::ReadSettings(){
// Default settings sett
strcpy(heighMapPath, "data/heightmaps/Rocky/height.bmp");
strcpy(landTexPath, "data/heightmaps/Rocky/land.tga");
// Open the options file static ifstream fin("data/options.ini"); // Can't open the file? if(!fin) { // The file didn't exist so create one WriteSettings(); // Write the failure to the log file //WriteLog("Failure to read options\n"); // Return failure to read the options return false; }
// Some temp variables string line, setting; int value; const char DELIM = '='; while(getline(fin,line)) // Get a line from the file { setting = line.substr(0, line.find(DELIM)); // Read setting name value = atoi(line.substr(line.find(DELIM)+1).c_str()); // Read value and convert to int (works fine aslong as only bool and int values are being used) // Set setting, all lines without matching if statement here will be ignored if(setting == "screenWidth ") { screenWidth = value;
} else if(setting == "screenHeight ") { screenHeight = value;
} else if(setting == "screenDepth ") { screenDepth = value;
} else if(setting == "fullScreen ") { fullScreen = value;
} else if(setting == "renderMethod ") { renderMethod = value;
} else if(setting == "useColor ") { useColor = value;
} else if(setting == "useLight ") { useLight = value;
}
else if(setting == "useFog ") {
useFog = value;
}
else if(setting == "fogDepth ") {
fogDepth = value;
}
else if(setting == "drawSkybox ") {
drawSkybox = value;
} else if(setting == "showDebug ") { showDebug = value;
} else if(setting == "showHUD ") { showHUD = value;
}
else if(setting == "detailTex ") {
detailTex = value;
} else if(setting == "scale ") { scale = value;
} else if(setting == "heightScale ") { heightScale = value;
}
else if(setting == "heighMapPath ") {
strcpy(heighMapPath, line.substr(line.find(DELIM)+2).c_str());
}
else if(setting == "landTexPath ") {
strcpy(landTexPath, line.substr(line.find(DELIM)+2).c_str());
} } // Close the file fin.close(); return true;}/////////////////////////////////////////////////////////////////////////bool GcSettings::WriteSettings(){ // Open the file for writing static ofstream fout("data/options.ini"); // Can't open the file? if(!fout) { // Write the faliour to write to the log file //WriteLog("Faliour to write options\n"); // Return faliour return false; } // Write the settings fout << "screenWidth = " << screenWidth << endl; fout << "screenHeight = " << screenHeight << endl; fout << "screenDepth = " << screenDepth << endl; fout << "fullScreen = " << fullScreen << endl << endl; fout << "renderMethod = " << renderMethod << endl; fout << "useColor = " << useColor << endl; fout << "useLight = " << useLight << endl << endl;
fout << "useFog = " << useFog << endl;
fout << "fogDepth = " << fogDepth << endl << endl;
fout << "drawSkybox = " << drawSkybox<< endl; fout << "showDebug = " << showDebug << endl; fout << "showHUD = " << showHUD << endl << endl;
fout << "detailTex = " << detailTex << endl << endl; fout << "scale = " << scale << endl; fout << "heightScale = " << heightScale << endl << endl;
fout << "heighMapPath = " << heighMapPath << endl;
fout << "landTexPath = " << landTexPath << endl; // Close the file fout.close(); return true;}/////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -