📄 settings.cpp
字号:
// Settings.cpp: Implementierung der Klasse CSettings.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Settings.h"
//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////
CSettings::CSettings()
{
}
CSettings::~CSettings()
{
}
void CSettings::ReadSettings(char sINIFilename[])
{
// Read the settings into the member data of the class
// Convert the INI filename into a full pathname
char sINIPath[MAX_PATH];
AddModulePath(sINIFilename, sINIPath);
// Size of the world
m_WorldSizeX = GetPrivateProfileInt("World", "WorldSizeX", 100, sINIPath);
m_WorldSizeY = GetPrivateProfileInt("World", "WorldSizeY", 100, sINIPath);
// Landscape step size
char LandscapeStepSize[32];
GetPrivateProfileString("World", "StepSize", "0.2", LandscapeStepSize, 32, sINIPath);
m_LandscapeStepSize = (float) atof(LandscapeStepSize);
// Resolution
m_ResWidth = GetPrivateProfileInt("Resolution", "Width", 320, sINIPath);
m_ResHeight = GetPrivateProfileInt("Resolution", "Height", 240, sINIPath);
// SkyBox texture
GetPrivateProfileString("SkyBox", "Texture", "", m_SkyBoxTexture, MAX_PATH, sINIPath);
// Crosshair texture
GetPrivateProfileString("Crosshair", "Texture", "", m_CrosshairTexture, MAX_PATH, sINIPath);
// Crosshair size
char CrosshairSize[32];
GetPrivateProfileString("Crosshair", "Size", "1.0", CrosshairSize, 32, sINIPath);
m_CrosshairSize = (float) atof(CrosshairSize);
// Crosshair transparency
char CrosshairTransparency[32];
GetPrivateProfileString("Crosshair", "Transparency", "1.0", CrosshairTransparency, 32, sINIPath);
m_CrosshairTransparency = (float) atof(CrosshairTransparency);
// Crosshair flag
m_DrawCrosshair = GetPrivateProfileInt("Crosshair", "DrawCrosshair", 1, sINIPath);
// Number of trees
m_TreeCount = GetPrivateProfileInt("Trees", "Count", 0, sINIPath);
// Font filename
GetPrivateProfileString("Font", "Filename", "", m_FontFilename, MAX_PATH, sINIPath);
// FPS counter flag
m_DrawFPSCounter = GetPrivateProfileInt("FPS", "DrawCounter", 0, sINIPath);
// Mousespeed
m_MouseSpeed = GetPrivateProfileInt("Mouse", "Speed", 5, sINIPath);
// Invert mouse ?
m_MouseInvert = GetPrivateProfileInt("Mouse", "Invert", 0, sINIPath);
// Field of View
m_FOV = GetPrivateProfileInt("View", "FOV", 90, sINIPath);
// Lighting of the sun
char SunLight[32];
GetPrivateProfileString("Sunlight", "Ambient", "0.3", SunLight, 32, sINIPath);
m_SunAmbient = (float) atof(SunLight);
GetPrivateProfileString("Sunlight", "Diffuse", "0.75", SunLight, 32, sINIPath);
m_SunDiffuse = (float) atof(SunLight);
// Fullscreen ?
m_Fullscreen = GetPrivateProfileInt("Resolution", "Fullscreen", 1, sINIPath);
// Filename of heightmap
GetPrivateProfileString("World", "HeightmapFile", "", m_HeightmapFilename, MAX_PATH, sINIPath);
// Flashlight ?
m_FlashlightEnabled = GetPrivateProfileInt("Flashlight", "Enabled", 0, sINIPath);
// Weapon ?
m_WeaponEnabled = GetPrivateProfileInt("Weapon", "Enabled", 0, sINIPath);
// Landscape height scaling
char HeightScaling[32];
GetPrivateProfileString("World", "HeightScaling", "5.0", HeightScaling, 32, sINIPath);
m_LandscapeHeightScaling = (float) atof(HeightScaling);
// Gravity
char Gravity[32];
GetPrivateProfileString("Gravity", "GravityX", "0.0", Gravity, 32, sINIPath);
m_Gravity[x] = (float) atof(Gravity);
GetPrivateProfileString("Gravity", "GravityY", "0.0", Gravity, 32, sINIPath);
m_Gravity[y] = (float) atof(Gravity);
GetPrivateProfileString("Gravity", "GravityZ", "0.0", Gravity, 32, sINIPath);
m_Gravity[z] = (float) atof(Gravity);
// Gravity acceleration
char GravityAcceleration[32];
GetPrivateProfileString("Gravity", "GravityAcceleration", "0.0", GravityAcceleration, 32, sINIPath);
m_GravityAcceleration = (float) atof(GravityAcceleration);
// Slowdown
char Slowdown[32];
GetPrivateProfileString("Motion", "Slowdown", "5.0", Slowdown, 32, sINIPath);
m_SlowDown = (float) atof(Slowdown);
// Mid-air slowdown
char MidAirSlowdown[32];
GetPrivateProfileString("Motion", "MidAirSlowdown", "5.0", MidAirSlowdown, 32, sINIPath);
m_MidAirSlowDown = (float) atof(MidAirSlowdown);
// Speed
char Speed[32];
GetPrivateProfileString("Motion", "Speed", "0.5", Speed, 32, sINIPath);
m_Speed = (float) atof(Speed);
// Smallest force
char SmallestForce[32];
GetPrivateProfileString("Motion", "SmallestForce", "0.0", SmallestForce, 32, sINIPath);
m_SmallestForce = (float) atof(SmallestForce);
// Minimum height
char MinimumHeight[32];
GetPrivateProfileString("Motion", "MinimumHeight", "0.0", MinimumHeight, 32, sINIPath);
m_MinimumHeight = (float) atof(MinimumHeight);
// Acceleration time
m_AccelerationTime = GetPrivateProfileInt("Motion", "AccelerationTime", 100, sINIPath);
// Mid-air acceleration time
m_MidAirAccelerationTime = GetPrivateProfileInt("Motion", "MidAirAccelerationTime", 100, sINIPath);
// Jump force
char JumpForce[32];
GetPrivateProfileString("Motion", "JumpForce", "0.0", JumpForce, 32, sINIPath);
m_JumpForce = (float) atof(JumpForce);
// Maximum acceleration factor
char MaxAccelerationFactor[32];
GetPrivateProfileString("Motion", "MaxAccelerationFactor", "4.0", MaxAccelerationFactor, 32, sINIPath);
m_MaxAccelerationFactor = (float) atof(MaxAccelerationFactor);
// Filename of heightmap
GetPrivateProfileString("Weapon", "Model", "", m_WeaponModel, MAX_PATH, sINIPath);
// Filename of heightmap
GetPrivateProfileString("Weapon", "Skin", "", m_WeaponSkin, MAX_PATH, sINIPath);
// View depth
char ViewDepth[32];
GetPrivateProfileString("View", "Depth", "7.5", ViewDepth, 32, sINIPath);
m_ViewDepth = (float) atof(ViewDepth);
// Size of viewer
char SizeOfViewer[32];
GetPrivateProfileString("View", "SizeOfViewer", "0.0", SizeOfViewer, 32, sINIPath);
m_SizeOfViewer = (float) atof(SizeOfViewer);
// Treesize
char TreeSize[32];
GetPrivateProfileString("Trees", "Size", "0.3", TreeSize, 32, sINIPath);
m_TreeSize = (float) atof(TreeSize);
// Maximum terrain roughness
char MaxTerrainRoughness[32];
GetPrivateProfileString("Trees", "MaxTerrainRoughness", "0.05", MaxTerrainRoughness, 32, sINIPath);
m_MaxTerrainRoughness = (float) atof(MaxTerrainRoughness);
// Tree brightness
char TreeBrightness[32];
GetPrivateProfileString("Trees", "Brightness", "1.0", TreeBrightness, 32, sINIPath);
m_TreeBrightness = (float) atof(TreeBrightness);
}
void CSettings::AddModulePath(char sINIFilename[], char sINIPath[])
{
// Add the path of the executable to the passed INI filename
// Buffer to hold the filename
char sModuleFileName[MAX_PATH];
// Pass NULL to get the handle of the current module
HMODULE hModule = GetModuleHandle(NULL);
// Fill the path into sModuleFileName and get the number of returned chars
int iNumChars = GetModuleFileName(hModule, sModuleFileName, MAX_PATH);
// If the path was received
if (iNumChars)
{
// Loop from the last to the first char
for (int iCurChar=iNumChars-1; iCurChar>=0; iCurChar--)
{
// If the current char is a backslash
if (sModuleFileName[iCurChar] == char('\\'))
{
// Terminate the the string behind the backslash and
sModuleFileName[iCurChar+1] = char('\0');
break;
}
}
// Append INI filename at the end of the path
strcat(sModuleFileName, sINIFilename);
// Copy the full path into the destibation
strcpy(sINIPath, sModuleFileName);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -