forked from pioneerspacesim/pioneer
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make screen config be configurable from the UI (hit escape). progress…
… on startup since it is getting sluggish git-svn-id: https://pioneer.svn.sourceforge.net/svnroot/pioneer/trunk@618 e632f14b-6550-0410-b89e-a82653faca30
- Loading branch information
tompox
committed
Jul 5, 2010
1 parent
6aade5a
commit 32e1e8c
Showing
14 changed files
with
328 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "libs.h" | ||
#include "IniConfig.h" | ||
|
||
void IniConfig::Load(const std::string &filename) | ||
{ | ||
this->clear(); | ||
this->filename = filename; | ||
FILE *f = fopen(filename.c_str(), "r"); | ||
if (f) { | ||
char buf[1024]; | ||
while (fgets(buf, sizeof(buf), f)) { | ||
if (buf[0] == '#') continue; | ||
char *sep = strchr(buf, '='); | ||
char *kend = sep; | ||
if (!sep) continue; | ||
*sep = 0; | ||
// strip whitespace | ||
while (isspace(*(--kend))) *kend = 0; | ||
while (isspace(*(++sep))) *sep = 0; | ||
// snip \r, \n | ||
char *vend = sep; | ||
while (*(++vend)) if ((*vend == '\r') || (*vend == '\n')) { *vend = 0; break; } | ||
std::string key = std::string(buf); | ||
std::string val = std::string(sep); | ||
(*this)[key] = val; | ||
} | ||
fclose(f); | ||
} else { | ||
// set defaults | ||
(*this)["DisableShaders"] = "0"; | ||
(*this)["DisableSound"] = "0"; | ||
(*this)["StartFullscreen"] = "1"; | ||
(*this)["ScrWidth"] = "0"; | ||
(*this)["ScrHeight"] = "0"; | ||
(*this)["DetailCities"] = "1"; | ||
(*this)["DetailPlanets"] = "1"; | ||
} | ||
} | ||
|
||
bool IniConfig::Save() | ||
{ | ||
FILE *f = fopen(filename.c_str(), "w"); | ||
if (!f) { | ||
return false; | ||
} else { | ||
for (std::map<std::string, std::string>::const_iterator i = begin(); i!=end(); ++i) { | ||
fprintf(f, "%s=%s\n", (*i).first.c_str(), (*i).second.c_str()); | ||
} | ||
fclose(f); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef INICONFIG_H | ||
#define INICONFIG_H | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
class IniConfig: private std::map<std::string, std::string> { | ||
public: | ||
void Load(const std::string &filename); | ||
void SetInt(const char *key, int val) { | ||
(*this)[key] = stringf(64, "%d", val); | ||
} | ||
int Int(const char *key) { | ||
return atoi((*this)[key].c_str()); | ||
} | ||
float Float(const char *key) { | ||
float val; | ||
if (sscanf((*this)[key].c_str(), "%f", &val)==1) return val; | ||
else return 0; | ||
} | ||
std::string String(const char *key) { | ||
return (*this)[key]; | ||
} | ||
bool Save(); | ||
private: | ||
std::string filename; | ||
}; | ||
|
||
#endif /* INICONFIG_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.