Cleanup
This commit is contained in:
parent
2a1ccfe3a8
commit
a12e3b53f2
4 changed files with 16 additions and 366 deletions
|
@ -72,10 +72,11 @@
|
|||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)libs\kaguya-1.3.2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
|
@ -88,9 +89,10 @@
|
|||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)libs\kaguya-1.3.2\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
|
@ -101,6 +103,18 @@
|
|||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Shader.cpp" />
|
||||
<ClCompile Include="src\Actor.cpp" />
|
||||
|
@ -112,7 +126,6 @@
|
|||
<ClCompile Include="src\BehaviourTreeNode.cpp" />
|
||||
<ClCompile Include="src\BehaviourTreeSelector.cpp" />
|
||||
<ClCompile Include="src\BehaviourTreeSequencer.cpp" />
|
||||
<ClCompile Include="src\Config.cpp" />
|
||||
<ClCompile Include="src\Entity.cpp" />
|
||||
<ClCompile Include="src\ExploreNode.cpp" />
|
||||
<ClCompile Include="src\FieldOfView.cpp" />
|
||||
|
@ -146,37 +159,6 @@
|
|||
<ClCompile Include="src\World.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\another_binding_api.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\compatibility.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\config.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\detail\lua_function_def.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\detail\lua_ref_impl.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\detail\lua_table_def.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\detail\lua_variant_def.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\error_handler.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\exception.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\function_tuple_def.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\kaguya.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\lua_ref.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\lua_ref_function.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\lua_ref_table.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\metatable.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\native_function.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\native_function_cxx03.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\native_function_cxx11.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\object.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\optional.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\preprocess.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\preprocess_repeate.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\push_any.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\push_tuple.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\ref_tuple.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\state.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\traits.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\type.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\utility.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\utility_cxx03.hpp" />
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\utility_cxx11.hpp" />
|
||||
<ClInclude Include="src\Shader.h" />
|
||||
<ClInclude Include="src\Actor.h" />
|
||||
<ClInclude Include="src\App.h" />
|
||||
|
@ -188,7 +170,6 @@
|
|||
<ClInclude Include="src\BehaviourTreeSelector.h" />
|
||||
<ClInclude Include="src\BehaviourTreeSequencer.h" />
|
||||
<ClInclude Include="src\Color.h" />
|
||||
<ClInclude Include="src\Config.h" />
|
||||
<ClInclude Include="src\Entity.h" />
|
||||
<ClInclude Include="src\ExploreNode.h" />
|
||||
<ClInclude Include="src\FieldOfView.h" />
|
||||
|
|
|
@ -42,9 +42,6 @@
|
|||
<ClCompile Include="src\BehaviourTreeSequencer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Config.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Entity.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -143,99 +140,6 @@
|
|||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\another_binding_api.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\compatibility.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\config.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\error_handler.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\exception.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\function_tuple_def.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\kaguya.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\lua_ref.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\lua_ref_function.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\lua_ref_table.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\metatable.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\native_function.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\native_function_cxx03.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\native_function_cxx11.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\object.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\optional.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\preprocess.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\preprocess_repeate.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\push_any.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\push_tuple.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\ref_tuple.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\state.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\traits.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\type.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\utility.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\utility_cxx03.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\utility_cxx11.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\detail\lua_function_def.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\detail\lua_ref_impl.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\detail\lua_table_def.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="libs\kaguya-1.3.2\include\kaguya\detail\lua_variant_def.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Actor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -266,9 +170,6 @@
|
|||
<ClInclude Include="src\Color.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Config.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Entity.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
|
206
src/Config.cpp
206
src/Config.cpp
|
@ -1,206 +0,0 @@
|
|||
#include "Config.h"
|
||||
#include <cctype>
|
||||
#include <functional>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool isFloat(const string &myString) {
|
||||
istringstream iss(myString);
|
||||
float f;
|
||||
iss >> noskipws >> f; // noskipws considers leading whitespace invalid
|
||||
// Check the entire string was consumed and if either failbit or badbit is set
|
||||
return iss.eof() && !iss.fail();
|
||||
}
|
||||
|
||||
bool isInt(const string &myString) {
|
||||
istringstream iss(myString);
|
||||
int i;
|
||||
iss >> noskipws >> i; // noskipws considers leading whitespace invalid
|
||||
// Check the entire string was consumed and if either failbit or badbit is set
|
||||
return iss.eof() && !iss.fail();
|
||||
}
|
||||
|
||||
// trim from start (in place)
|
||||
static inline void ltrim(string &s) {
|
||||
s.erase(s.begin(), find_if(s.begin(), s.end(),
|
||||
not1(ptr_fun<int, int>(isspace))));
|
||||
}
|
||||
|
||||
// trim from end (in place)
|
||||
static inline void rtrim(string &s) {
|
||||
s.erase(find_if(s.rbegin(), s.rend(),
|
||||
not1(ptr_fun<int, int>(isspace))).base(), s.end());
|
||||
}
|
||||
|
||||
// trim from both ends (in place)
|
||||
static inline void trim(string &s) {
|
||||
ltrim(s);
|
||||
rtrim(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Config::Config(string path) {
|
||||
this->path = std::move(path);
|
||||
}
|
||||
|
||||
void Config::load() {
|
||||
strings.clear();
|
||||
bools.clear();
|
||||
floats.clear();
|
||||
|
||||
ifstream conf(path);
|
||||
if (conf.is_open()) {
|
||||
string line;
|
||||
while (getline(conf, line)) {
|
||||
unsigned int pos = line.find('=');
|
||||
if (pos > 0) {
|
||||
string key = line.substr(0, pos);
|
||||
string value = line.substr(pos + 1, line.length());
|
||||
|
||||
trim(key);
|
||||
trim(value);
|
||||
|
||||
if (bools.find(key) != bools.end() ||
|
||||
strings.find(key) != strings.end() ||
|
||||
ints.find(key) != ints.end() ||
|
||||
floats.find(key) != floats.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isInt(value)) {
|
||||
int ival = stoi(value);
|
||||
ints.insert(pair<string, float>{key, ival});
|
||||
}
|
||||
else if (isFloat(value)) {
|
||||
float fval = stof(value);
|
||||
floats.insert(pair<string, float>{key, fval});
|
||||
}
|
||||
else if (value.find("true") == 0 && value.length() == 4) {
|
||||
bools.insert(pair<string, bool>{key, true});
|
||||
}
|
||||
else if (value.find("false") == 0 && value.length() == 5) {
|
||||
bools.insert(pair<string, bool>{key, false});
|
||||
}
|
||||
else {
|
||||
strings.insert(pair<string, string>{key, value});
|
||||
}
|
||||
}
|
||||
}
|
||||
conf.close();
|
||||
}
|
||||
}
|
||||
|
||||
void Config::save() {
|
||||
ofstream conf(path, ios::trunc);
|
||||
if (conf.is_open()) {
|
||||
vector<string> vec;
|
||||
for (auto it : ints) {
|
||||
vec.push_back(it.first + " = " + to_string(it.second));
|
||||
}
|
||||
for (auto it : floats) {
|
||||
vec.push_back(it.first + " = " + to_string(it.second));
|
||||
}
|
||||
for (auto it : bools) {
|
||||
string b;
|
||||
if (it.second) {
|
||||
b = "true";
|
||||
}
|
||||
else {
|
||||
b = "false";
|
||||
}
|
||||
vec.push_back(it.first + " = " + b);
|
||||
}
|
||||
for (auto it : strings) {
|
||||
vec.push_back(it.first + " = " + it.second);
|
||||
}
|
||||
sort(vec.begin(), vec.end());
|
||||
for (auto it : vec) {
|
||||
conf << it << "\n";
|
||||
}
|
||||
conf.close();
|
||||
}
|
||||
}
|
||||
|
||||
void Config::deleteValue(string key) {
|
||||
strings.erase(key);
|
||||
ints.erase(key);
|
||||
floats.erase(key);
|
||||
bools.erase(key);
|
||||
}
|
||||
|
||||
string Config::getString(string key, string defaultvalue) {
|
||||
auto iter = strings.find(key);
|
||||
if (iter != strings.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
else {
|
||||
deleteValue(key);
|
||||
strings.insert(pair<string, string>{key, defaultvalue});
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
int Config::getInt(string key, int defaultvalue) {
|
||||
auto iter = ints.find(key);
|
||||
if (iter != ints.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
else {
|
||||
deleteValue(key);
|
||||
ints.insert(pair<string, int>{key, defaultvalue});
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
float Config::getFloat(std::string key, float defaultvalue) {
|
||||
auto iter = floats.find(key);
|
||||
if (iter != floats.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
else {
|
||||
deleteValue(key);
|
||||
floats.insert(pair<string, float>{key, defaultvalue});
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
bool Config::getBool(std::string key, bool defaultvalue) {
|
||||
auto iter = bools.find(key);
|
||||
if (iter != bools.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
else {
|
||||
deleteValue(key);
|
||||
bools.insert(pair<string, bool>{key, defaultvalue});
|
||||
return defaultvalue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Config::~Config() = default;
|
||||
|
||||
void Config::setString(std::string key, std::string value) {
|
||||
deleteValue(key);
|
||||
strings.insert(pair<string, string>{key, value});
|
||||
}
|
||||
|
||||
void Config::setInt(std::string key, int value) {
|
||||
deleteValue(key);
|
||||
ints.insert(pair<string, int>{key, value});
|
||||
}
|
||||
|
||||
void Config::setFloat(std::string key, float value) {
|
||||
deleteValue(key);
|
||||
floats.insert(pair<string, float>{key, value});
|
||||
}
|
||||
|
||||
void Config::setBool(std::string key, bool value) {
|
||||
deleteValue(key);
|
||||
bools.insert(pair<string, bool>{key, value});
|
||||
}
|
26
src/Config.h
26
src/Config.h
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class Config {
|
||||
std::string path;
|
||||
std::map<std::string, std::string> strings;
|
||||
std::map<std::string, float> floats;
|
||||
std::map<std::string, int> ints;
|
||||
std::map<std::string, bool> bools;
|
||||
public:
|
||||
Config(std::string path);
|
||||
void load();
|
||||
void save();
|
||||
void deleteValue(std::string key);
|
||||
std::string getString(std::string key, std::string defaultvalue);
|
||||
int getInt(std::string key, int defaultvalue);
|
||||
float getFloat(std::string key, float defaultvalue);
|
||||
bool getBool(std::string key, bool defaultvalue);
|
||||
void setString(std::string key, std::string value);
|
||||
void setInt(std::string key, int value);
|
||||
void setFloat(std::string key, float value);
|
||||
void setBool(std::string key, bool value);
|
||||
~Config();
|
||||
};
|
||||
|
Loading…
Add table
Reference in a new issue