mirror of https://github.com/AxioDL/metaforce.git
Simplify findCVar
This commit is contained in:
parent
9c053b53e8
commit
b7fda5a620
|
@ -3,33 +3,43 @@
|
||||||
#include <Specter/Specter.hpp>
|
#include <Specter/Specter.hpp>
|
||||||
#include <Runtime/CVarManager.hpp>
|
#include <Runtime/CVarManager.hpp>
|
||||||
#include <Runtime/CGameAllocator.hpp>
|
#include <Runtime/CGameAllocator.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace RUDE
|
namespace RUDE
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Application : boo::IApplicationCallback
|
struct Application : boo::IApplicationCallback
|
||||||
{
|
{
|
||||||
Retro::CGameAllocator m_allocator;
|
|
||||||
HECL::Runtime::FileStoreManager m_fileMgr;
|
HECL::Runtime::FileStoreManager m_fileMgr;
|
||||||
Specter::FontCache m_fontCache;
|
Specter::FontCache m_fontCache;
|
||||||
Specter::RootView m_rootView;
|
Specter::RootView m_rootView;
|
||||||
Retro::CVarManager m_cvarManager;
|
Retro::CVarManager m_cvarManager;
|
||||||
boo::IWindow* m_mainWindow;
|
boo::IWindow* m_mainWindow;
|
||||||
|
Zeus::CColor m_clearColor;
|
||||||
bool m_running = true;
|
bool m_running = true;
|
||||||
|
|
||||||
Application() : m_fileMgr(_S("rude")), m_fontCache(m_fileMgr), m_rootView(m_fontCache), m_cvarManager(m_fileMgr, true){}
|
|
||||||
|
void onCVarModified(Retro::CVar* cvar)
|
||||||
|
{
|
||||||
|
if (cvar == m_cvarManager.findCVar("r_clearColor"))
|
||||||
|
m_clearColor = cvar->toColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
Application() : m_fileMgr(_S("rude")), m_fontCache(m_fileMgr), m_rootView(m_fontCache), m_cvarManager(m_fileMgr){}
|
||||||
|
|
||||||
int appMain(boo::IApplication* app)
|
int appMain(boo::IApplication* app)
|
||||||
{
|
{
|
||||||
m_allocator.Initialize();
|
|
||||||
m_mainWindow = app->newWindow(_S("RUDE"));
|
m_mainWindow = app->newWindow(_S("RUDE"));
|
||||||
m_rootView.setWindow(m_mainWindow, 1.0f);
|
m_rootView.setWindow(m_mainWindow, 1.0f);
|
||||||
m_cvarManager.serialize();
|
m_cvarManager.serialize();
|
||||||
|
Retro::CVar* tmp = m_cvarManager.findCVar("r_clearcolor");
|
||||||
|
Retro::CVar::ListenerFunc listen = std::bind(&Application::onCVarModified, this, std::placeholders::_1);
|
||||||
|
if (tmp)
|
||||||
|
tmp->addListener(listen);
|
||||||
|
|
||||||
while (m_running)
|
while (m_running)
|
||||||
{
|
{
|
||||||
|
m_cvarManager.update();
|
||||||
m_mainWindow->waitForRetrace();
|
m_mainWindow->waitForRetrace();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ CVarManager::~CVarManager()
|
||||||
|
|
||||||
void CVarManager::update()
|
void CVarManager::update()
|
||||||
{
|
{
|
||||||
for (const std::pair<std::string, CVar*> pair : m_cvars)
|
for (const std::pair<std::string, CVar*>& pair : m_cvars)
|
||||||
if (pair.second->isModified())
|
if (pair.second->isModified())
|
||||||
{
|
{
|
||||||
pair.second->dispatch();
|
pair.second->dispatch();
|
||||||
|
@ -49,20 +49,19 @@ bool CVarManager::registerCVar(CVar* cvar)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CVar* CVarManager::findCVar(const std::string &name)
|
CVar* CVarManager::findCVar(std::string name)
|
||||||
{
|
{
|
||||||
std::string tmp = std::string(name);
|
Athena::utility::tolower(name);
|
||||||
Athena::utility::tolower(tmp);
|
if (m_cvars.find(name) == m_cvars.end())
|
||||||
if (m_cvars.find(tmp) == m_cvars.end())
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return m_cvars[tmp];
|
return m_cvars[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CVar*> CVarManager::archivedCVars() const
|
std::vector<CVar*> CVarManager::archivedCVars() const
|
||||||
{
|
{
|
||||||
std::vector<CVar*> ret;
|
std::vector<CVar*> ret;
|
||||||
for (std::pair<std::string, CVar*> pair : m_cvars)
|
for (const std::pair<std::string, CVar*>& pair : m_cvars)
|
||||||
if (pair.second->isArchive())
|
if (pair.second->isArchive())
|
||||||
ret.push_back(pair.second);
|
ret.push_back(pair.second);
|
||||||
|
|
||||||
|
@ -72,7 +71,7 @@ std::vector<CVar*> CVarManager::archivedCVars() const
|
||||||
std::vector<CVar*> CVarManager::cvars() const
|
std::vector<CVar*> CVarManager::cvars() const
|
||||||
{
|
{
|
||||||
std::vector<CVar*> ret;
|
std::vector<CVar*> ret;
|
||||||
for (std::pair<std::string, CVar*> pair : m_cvars)
|
for (const std::pair<std::string, CVar*>& pair : m_cvars)
|
||||||
ret.push_back(pair.second);
|
ret.push_back(pair.second);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -90,12 +89,12 @@ void CVarManager::deserialize(CVar* cvar)
|
||||||
HECL::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toLiteral();
|
HECL::SystemString filename = m_store.getStoreRoot() + _S('/') + com_configfile->toLiteral();
|
||||||
#endif
|
#endif
|
||||||
HECL::Sstat st;
|
HECL::Sstat st;
|
||||||
if (HECL::Stat(filename.c_str(), &st) || !S_ISREG(st.st_mode))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (m_useBinary)
|
if (m_useBinary)
|
||||||
{
|
{
|
||||||
filename += _S(".bin");
|
filename += _S(".bin");
|
||||||
|
if (HECL::Stat(filename.c_str(), &st) || !S_ISREG(st.st_mode))
|
||||||
|
return;
|
||||||
Athena::io::FileReader reader(filename);
|
Athena::io::FileReader reader(filename);
|
||||||
if (reader.isOpen())
|
if (reader.isOpen())
|
||||||
container.read(reader);
|
container.read(reader);
|
||||||
|
@ -103,6 +102,8 @@ void CVarManager::deserialize(CVar* cvar)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
filename += _S(".yaml");
|
filename += _S(".yaml");
|
||||||
|
if (HECL::Stat(filename.c_str(), &st) || !S_ISREG(st.st_mode))
|
||||||
|
return;
|
||||||
FILE* f = HECL::Fopen(filename.c_str(), _S("rb"));
|
FILE* f = HECL::Fopen(filename.c_str(), _S("rb"));
|
||||||
if (f)
|
if (f)
|
||||||
container.fromYAMLFile(f);
|
container.fromYAMLFile(f);
|
||||||
|
@ -117,7 +118,7 @@ void CVarManager::deserialize(CVar* cvar)
|
||||||
|
|
||||||
if (serialized != container.cvars.end())
|
if (serialized != container.cvars.end())
|
||||||
{
|
{
|
||||||
DNACVAR::CVar tmp = *serialized;
|
DNACVAR::CVar& tmp = *serialized;
|
||||||
if (tmp.m_type != cvar->type())
|
if (tmp.m_type != cvar->type())
|
||||||
{
|
{
|
||||||
CVarLog.report(LogVisor::Error, _S("Stored type for %s does not match actual type!"), tmp.m_name.c_str());
|
CVarLog.report(LogVisor::Error, _S("Stored type for %s does not match actual type!"), tmp.m_name.c_str());
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
|
|
||||||
bool registerCVar(CVar* cvar);
|
bool registerCVar(CVar* cvar);
|
||||||
|
|
||||||
CVar* findCVar(const std::string& name);
|
CVar* findCVar(std::string name);
|
||||||
|
|
||||||
std::vector<CVar*> archivedCVars() const;
|
std::vector<CVar*> archivedCVars() const;
|
||||||
std::vector<CVar*> cvars() const;
|
std::vector<CVar*> cvars() const;
|
||||||
|
|
Loading…
Reference in New Issue