rename g_config
This commit is contained in:
parent
5ab943ce13
commit
b1ec45783e
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
Configs g_config;
|
Configs g_configs;
|
||||||
|
|
||||||
bool Configs::load(const std::string& fileName)
|
bool Configs::load(const std::string& fileName)
|
||||||
{
|
{
|
||||||
|
@ -99,43 +99,43 @@ void Configs::setValue(const std::string &key, bool value)
|
||||||
setValue(key,"false");
|
setValue(key,"false");
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Configs::getString(const std::string &key)
|
const std::string &Configs::getString(const std::string &key) const
|
||||||
{
|
{
|
||||||
auto iter = m_confsMap.find(key);
|
auto it = m_confsMap.find(key);
|
||||||
if(iter == m_confsMap.end()) {
|
if(it == m_confsMap.end()) {
|
||||||
warning("Config value %s not found", key.c_str());
|
warning("Config value %s not found", key.c_str());
|
||||||
static std::string emptystr;
|
static std::string emptystr;
|
||||||
return emptystr;
|
return emptystr;
|
||||||
}
|
}
|
||||||
return iter->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Configs::getFloat(const std::string &key)
|
float Configs::getFloat(const std::string &key) const
|
||||||
{
|
{
|
||||||
auto iter = m_confsMap.find(key);
|
auto it = m_confsMap.find(key);
|
||||||
if(iter == m_confsMap.end()) {
|
if(it == m_confsMap.end()) {
|
||||||
warning("Config value %s not found", key.c_str());
|
warning("Config value %s not found", key.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return convertType<float, std::string>(iter->second);
|
return convertType<float, std::string>(it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Configs::getBoolean(const std::string &key)
|
bool Configs::getBoolean(const std::string &key) const
|
||||||
{
|
{
|
||||||
auto iter = m_confsMap.find(key);
|
auto it = m_confsMap.find(key);
|
||||||
if(iter == m_confsMap.end()) {
|
if(it == m_confsMap.end()) {
|
||||||
warning("Config value %s not found", key.c_str());
|
warning("Config value %s not found", key.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return (iter->second == "true");
|
return (it->second == "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
int Configs::getInteger(const std::string &key)
|
int Configs::getInteger(const std::string &key) const
|
||||||
{
|
{
|
||||||
auto iter = m_confsMap.find(key);
|
auto it = m_confsMap.find(key);
|
||||||
if(iter == m_confsMap.end()) {
|
if(it == m_confsMap.end()) {
|
||||||
warning("Config value %s not found", key.c_str());
|
warning("Config value %s not found", key.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return convertType<int, std::string>(iter->second);
|
return convertType<int, std::string>(it->second);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,16 +44,16 @@ public:
|
||||||
void setValue(const std::string &key, bool value);
|
void setValue(const std::string &key, bool value);
|
||||||
void setValue(const std::string &key, int value);
|
void setValue(const std::string &key, int value);
|
||||||
|
|
||||||
const std::string &getString(const std::string &key);
|
const std::string &getString(const std::string &key) const;
|
||||||
float getFloat(const std::string &key);
|
float getFloat(const std::string &key) const;
|
||||||
bool getBoolean(const std::string &key);
|
bool getBoolean(const std::string &key) const;
|
||||||
int getInteger(const std::string &key);
|
int getInteger(const std::string &key) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_fileName;
|
std::string m_fileName;
|
||||||
std::map<std::string, std::string> m_confsMap;
|
std::map<std::string, std::string> m_confsMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Configs g_config;
|
extern Configs g_configs;
|
||||||
|
|
||||||
#endif // CONFIGS_H
|
#endif // CONFIGS_H
|
||||||
|
|
|
@ -36,12 +36,10 @@ public:
|
||||||
/// Load font from file
|
/// Load font from file
|
||||||
bool load(const std::string &file);
|
bool load(const std::string &file);
|
||||||
|
|
||||||
std::string& getName() { return m_name; }
|
const std::string& getName() const { return m_name; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Font> FontPtr;
|
|
||||||
|
|
||||||
#endif // FONT_H
|
#endif // FONT_H
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
void init();
|
void init();
|
||||||
void terminate();
|
void terminate();
|
||||||
|
|
||||||
|
/// Check if a GL extension is supported
|
||||||
bool isExtensionSupported(const char *extension);
|
bool isExtensionSupported(const char *extension);
|
||||||
|
|
||||||
/// Called after every window resize
|
/// Called after every window resize
|
||||||
|
|
32
src/main.cpp
32
src/main.cpp
|
@ -53,22 +53,22 @@ void setDefaultConfigs()
|
||||||
int defHeight = 480;
|
int defHeight = 480;
|
||||||
|
|
||||||
// init on screen center
|
// init on screen center
|
||||||
g_config.setValue("window x", (Platform::getDisplayWidth() - defWidth)/2);
|
g_configs.setValue("window x", (Platform::getDisplayWidth() - defWidth)/2);
|
||||||
g_config.setValue("window y", (Platform::getDisplayHeight() - defHeight)/2);
|
g_configs.setValue("window y", (Platform::getDisplayHeight() - defHeight)/2);
|
||||||
|
|
||||||
g_config.setValue("window width", defWidth);
|
g_configs.setValue("window width", defWidth);
|
||||||
g_config.setValue("window height", defHeight);
|
g_configs.setValue("window height", defHeight);
|
||||||
g_config.setValue("window maximized", false);
|
g_configs.setValue("window maximized", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveConfigs()
|
void saveConfigs()
|
||||||
{
|
{
|
||||||
g_config.setValue("window x", Platform::getWindowX());
|
g_configs.setValue("window x", Platform::getWindowX());
|
||||||
g_config.setValue("window y", Platform::getWindowY());
|
g_configs.setValue("window y", Platform::getWindowY());
|
||||||
g_config.setValue("window width", Platform::getWindowWidth());
|
g_configs.setValue("window width", Platform::getWindowWidth());
|
||||||
g_config.setValue("window height", Platform::getWindowHeight());
|
g_configs.setValue("window height", Platform::getWindowHeight());
|
||||||
g_config.setValue("window maximized", Platform::isWindowMaximized());
|
g_configs.setValue("window maximized", Platform::isWindowMaximized());
|
||||||
g_config.save();
|
g_configs.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
|
@ -90,16 +90,16 @@ int main(int argc, const char *argv[])
|
||||||
setDefaultConfigs();
|
setDefaultConfigs();
|
||||||
|
|
||||||
// load configurations
|
// load configurations
|
||||||
if(!g_config.load("config.yml"))
|
if(!g_configs.load("config.yml"))
|
||||||
notice("Could not read configuration file, default configurations will be used.");
|
notice("Could not read configuration file, default configurations will be used.");
|
||||||
|
|
||||||
notice("OTClient 0.1.0");
|
notice("OTClient 0.1.0");
|
||||||
|
|
||||||
// create the window
|
// create the window
|
||||||
Platform::createWindow(g_config.getInteger("window x"), g_config.getInteger("window y"),
|
Platform::createWindow(g_configs.getInteger("window x"), g_configs.getInteger("window y"),
|
||||||
g_config.getInteger("window width"), g_config.getInteger("window height"),
|
g_configs.getInteger("window width"), g_configs.getInteger("window height"),
|
||||||
640, 480,
|
640, 480,
|
||||||
g_config.getBoolean("window maximized"));
|
g_configs.getBoolean("window maximized"));
|
||||||
Platform::setWindowTitle("OTClient");
|
Platform::setWindowTitle("OTClient");
|
||||||
Platform::setVsync();
|
Platform::setVsync();
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ int main(int argc, const char *argv[])
|
||||||
|
|
||||||
// state scope
|
// state scope
|
||||||
{
|
{
|
||||||
std::shared_ptr<MenuState> menuState(new MenuState());
|
std::shared_ptr<MenuState> menuState(new MenuState);
|
||||||
g_engine.changeState(menuState.get());
|
g_engine.changeState(menuState.get());
|
||||||
|
|
||||||
Platform::showWindow();
|
Platform::showWindow();
|
||||||
|
|
Loading…
Reference in New Issue