Merge commit 'c46f861'

This commit is contained in:
Phillip Stephens 2018-01-13 23:38:17 -08:00
commit 4543e2a87e
7 changed files with 132 additions and 89 deletions

View File

@ -22,17 +22,17 @@ enum class EType : atUint8
enum EFlags
{
All = -1, // NOTE: is this really necessary? It seems rather overkill
System = (1 << 0),
Game = (1 << 1),
Editor = (1 << 2),
Gui = (1 << 3),
Cheat = (1 << 4),
Hidden = (1 << 5),
ReadOnly = (1 << 6),
Archive = (1 << 7),
Modified = (1 << 8),
ModifyRestart = (1 << 9) /*!< If this bit is set, any modification will inform the user that a restart is required */
System = (1 << 0),
Game = (1 << 1),
Editor = (1 << 2),
Gui = (1 << 3),
Cheat = (1 << 4),
Hidden = (1 << 5),
ReadOnly = (1 << 6),
Archive = (1 << 7),
InternalArchivable = (1 << 8),
Modified = (1 << 9),
ModifyRestart = (1 << 10) /*!< If this bit is set, any modification will inform the user that a restart is required */
};
ENABLE_BITWISE_ENUM(EFlags)
@ -42,7 +42,6 @@ public:
DECL_YAML
String<-1> m_name;
String<-1> m_value;
Value<EType> m_type;
};
struct CVarContainer : public athena::io::DNAYaml<athena::BigEndian>
@ -93,8 +92,8 @@ public:
bool fromInteger(int val);
bool fromLiteral(std::string_view val);
bool fromLiteral(std::wstring_view val);
bool fromLiteralToType(std::string_view val);
bool fromLiteralToType(std::wstring_view val);
bool fromLiteralToType(std::string_view val, bool setDefault = false);
bool fromLiteralToType(std::wstring_view val, bool setDefault = false);
bool isFloat() const { return m_type == EType::Float; }
bool isBoolean() const { return m_type == EType::Boolean; }
@ -107,6 +106,9 @@ public:
bool isCheat() const;
bool isHidden() const;
bool isArchive() const;
bool isInternalArchivable() const;
bool wasDeserialized() const;
bool hasDefaultValue() const;
void clearModified();
void setModified();
@ -132,11 +134,13 @@ public:
private:
void dispatch();
EType m_type;
std::string m_help;
std::string m_defaultValue;
EFlags m_flags;
EFlags m_oldFlags;
bool m_unlocked = false;
bool m_wasDeserialized = false;
CVarManager& m_mgr;

View File

@ -11,7 +11,9 @@ namespace Runtime
{
class FileStoreManager;
}
extern CVar* com_developer;
extern CVar* com_configfile;
extern CVar* com_enableCheats;
class CVarManager final
{
using CVarContainer = DNACVAR::CVarContainer;
@ -21,8 +23,7 @@ class CVarManager final
CVar* ret(new CVar(name, value, help, flags, *this));
if (registerCVar(ret))
{
if (ret->isArchive())
deserialize(ret);
deserialize(ret);
return ret;
}
delete ret;

View File

@ -10,7 +10,7 @@
namespace hecl
{
class CVar;
struct SConsoleCommand
{
std::string m_displayName;
@ -67,11 +67,14 @@ private:
std::vector<std::string> m_commandHistory;
int m_cursorPosition = -1;
int m_currentCommand = -1;
int m_maxLines = 0;
size_t m_maxLines = 0;
bool m_overwrite : 1;
bool m_cursorAtEnd : 1;
State m_state = State::Closed;
CVar* m_conSpeed;
CVar* m_conHeight;
float m_cachedConSpeed;
float m_cachedConHeight;
public:
Console(class CVarManager*);
void registerCommand(std::string_view name, std::string_view helpText, std::string_view usage, const std::function<void(Console*, const std::vector<std::string>&)>&& func);

View File

@ -140,7 +140,7 @@ atVec4f CVar::toVec4f(bool* isValid) const
return atVec4f{};
}
if (isValid != NULL)
if (isValid != nullptr)
*isValid = true;
atVec4f vec;
@ -346,7 +346,7 @@ bool CVar::fromLiteral(std::wstring_view val)
return true;
}
bool CVar::fromLiteralToType(std::string_view val)
bool CVar::fromLiteralToType(std::string_view val, bool setDefault)
{
switch (m_type)
{
@ -382,10 +382,12 @@ bool CVar::fromLiteralToType(std::string_view val)
return fromVec4f(vec);
}
}
if (setDefault)
m_value = m_defaultValue;
return false;
}
bool CVar::fromLiteralToType(std::wstring_view val)
bool CVar::fromLiteralToType(std::wstring_view val, bool setDefault)
{
switch (m_type)
{
@ -421,6 +423,8 @@ bool CVar::fromLiteralToType(std::wstring_view val)
return fromVec4f(vec);
}
}
if (setDefault)
m_value = m_defaultValue;
return false;
}
@ -435,6 +439,12 @@ bool CVar::isHidden() const { return int(m_flags & EFlags::Hidden) != 0; }
bool CVar::isArchive() const { return int(m_flags & EFlags::Archive) != 0; }
bool CVar::isInternalArchivable() const { return int(m_flags & EFlags::InternalArchivable) != 0; }
bool CVar::wasDeserialized() const { return m_wasDeserialized; }
bool CVar::hasDefaultValue() const { return m_defaultValue == m_value; }
void CVar::clearModified()
{
if (!modificationRequiresRestart())

View File

@ -15,14 +15,14 @@ CVar* com_enableCheats = nullptr;
CVarManager* CVarManager::m_instance = nullptr;
logvisor::Module CVarLog("CVarManager");
static logvisor::Module CVarLog("CVarManager");
CVarManager::CVarManager(hecl::Runtime::FileStoreManager& store, bool useBinary)
: m_store(store),
m_useBinary(useBinary)
{
m_instance = this;
com_configfile = newCVar("config", "File to store configuration", std::string("config"), CVar::EFlags::System);
com_developer = newCVar("developer", "Enables developer mode", false, (CVar::EFlags::System | CVar::EFlags::Cheat | CVar::EFlags::ReadOnly));
com_developer = newCVar("developer", "Enables developer mode", false, (CVar::EFlags::System | CVar::EFlags::ReadOnly | CVar::EFlags::InternalArchivable));
com_enableCheats = newCVar("iamaweiner", "Enable cheats", false, (CVar::EFlags::System | CVar::EFlags::ReadOnly | CVar::EFlags::Hidden));
}
@ -83,7 +83,7 @@ std::vector<CVar*> CVarManager::cvars() const
void CVarManager::deserialize(CVar* cvar)
{
if (!cvar || !cvar->isArchive())
if (!cvar || (!cvar->isArchive() && !cvar->isInternalArchivable()))
return;
CVarContainer container;
@ -122,14 +122,14 @@ void CVarManager::deserialize(CVar* cvar)
if (serialized != container.cvars.end())
{
DNACVAR::CVar& tmp = *serialized;
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());
return;
}
if (cvar->m_value != tmp.m_value)
cvar->m_value = tmp.m_value;
{
cvar->unlock();
cvar->fromLiteralToType(tmp.m_value, true);
cvar->m_wasDeserialized = true;
cvar->lock();
}
}
}
}
@ -138,13 +138,13 @@ void CVarManager::serialize()
{
CVarContainer container;
for (const std::pair<std::string, CVar*>& pair : m_cvars)
if (pair.second->isArchive())
if (pair.second->isArchive() || (pair.second->isInternalArchivable() && pair.second->wasDeserialized() && !pair.second->hasDefaultValue()))
{
CVar tmp = *pair.second;
container.cvars.push_back(tmp);
}
container.cvarCount = container.cvars.size();
container.cvarCount = atUint32(container.cvars.size());
#if _WIN32
hecl::SystemString filename = hecl::SystemString(m_store.getStoreRoot()) + _S('/') + com_configfile->toWideLiteral();
@ -173,7 +173,7 @@ CVarManager* CVarManager::instance()
return m_instance;
}
void CVarManager::list(Console* con, const std::vector<std::string> &args)
void CVarManager::list(Console* con, const std::vector<std::string>& /*args*/)
{
for (const auto& cvar : m_cvars)
{

View File

@ -16,6 +16,10 @@ Console::Console(CVarManager* cvarMgr)
registerCommand("listCVars", "Lists all available CVars", "", std::bind(&CVarManager::list, cvarMgr, std::placeholders::_1, std::placeholders::_2));
registerCommand("setCVar", "Sets a given Console Variable to the specified value", "<cvar> <value>", std::bind(&CVarManager::setCVar, cvarMgr, std::placeholders::_1, std::placeholders::_2));
registerCommand("getCVar", "Prints the value stored in the specified Console Variable", "<cvar>", std::bind(&CVarManager::getCVar, cvarMgr, std::placeholders::_1, std::placeholders::_2));
m_conSpeed = cvarMgr->findOrMakeCVar("con_speed", "Speed at which the console opens and closes, calculated as pixels per second", 1.f,
hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive);
m_conHeight = cvarMgr->findOrMakeCVar("con_height", "Maximum absolute height of the console, height is calculated from the top of the window, expects values ranged from [0.f,1.f]", 0.5f,
hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive);
}
void Console::registerCommand(std::string_view name, std::string_view helpText, std::string_view usage, const std::function<void(Console*, const std::vector<std::string> &)>&& func)
@ -110,6 +114,18 @@ void Console::report(Level level, const char* fmt, ...)
void Console::proc()
{
if (m_conHeight->isModified())
{
m_cachedConHeight = m_conHeight->toFloat();
m_conHeight->clearModified();
}
if (m_conSpeed->isModified())
{
m_cachedConSpeed = m_conSpeed->toFloat();
m_conSpeed->clearModified();
}
if (m_state == State::Opened)
{
printf("\r%s ", m_commandString.c_str());
@ -121,22 +137,22 @@ void Console::proc()
m_state = State::Closed;
if (m_cursorPosition > (int)m_commandString.size() - 1)
m_cursorPosition = (int)m_commandString.size() - 1;
if (m_cursorPosition > int(m_commandString.size() - 1))
m_cursorPosition = int(m_commandString.size() - 1);
if (m_cursorPosition < -1)
m_cursorPosition = -1;
if (m_logOffset > (int)m_log.size() - 1)
m_logOffset = (int)m_log.size() - 1;
if (m_logOffset > int(m_log.size() - 1))
m_logOffset = int(m_log.size() - 1);
if (m_logOffset < 0)
m_logOffset = 0;
}
void Console::draw(boo::IGraphicsCommandQueue* gfxQ)
void Console::draw(boo::IGraphicsCommandQueue* /*gfxQ*/)
{
}
void Console::handleCharCode(unsigned long chr, boo::EModifierKey mod, bool repeat)
void Console::handleCharCode(unsigned long chr, boo::EModifierKey /*mod*/, bool /*repeat*/)
{
if (chr == U'`' || chr == U'~')
{
@ -148,21 +164,21 @@ void Console::handleCharCode(unsigned long chr, boo::EModifierKey mod, bool repe
if (m_state == State::Opened)
{
if (!m_commandString.empty() && m_cursorPosition + 1 < m_commandString.size())
if (!m_commandString.empty() && m_cursorPosition + 1 < int(m_commandString.size()))
{
if (m_overwrite)
m_commandString[m_cursorPosition + 1] = chr;
m_commandString[unsigned(m_cursorPosition + 1)] = char(chr);
else
m_commandString.insert(m_commandString.begin() + m_cursorPosition + 1, chr);
m_commandString.insert(m_commandString.begin() + m_cursorPosition + 1, char(chr));
}
else
m_commandString += chr;
m_commandString += char(chr);
++m_cursorPosition;
}
}
void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, bool repeat)
void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, bool /*repeat*/)
{
if (m_state != Opened)
return;
@ -178,9 +194,9 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
{
if (int(mod & boo::EModifierKey::Ctrl) != 0)
{
int index = m_commandString.rfind(' ', m_cursorPosition - 1);
size_t index = m_commandString.rfind(' ', size_t(m_cursorPosition - 1));
if (index == (int)std::string::npos)
if (index == std::string::npos)
{
m_commandString.clear();
m_cursorPosition = -1;
@ -188,14 +204,14 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
else
{
m_commandString.erase(index, (index - m_commandString.size()));
m_cursorPosition = index;
m_cursorPosition = int(index);
}
break;
}
if (m_cursorPosition < 0)
break;
m_commandString.erase(m_cursorPosition, 1);
m_commandString.erase(size_t(m_cursorPosition), 1);
--m_cursorPosition;
}
break;
@ -205,25 +221,25 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
if (!m_commandString.empty())
{
// Don't try to delete if the cursor is at the end of the line
if ((m_cursorPosition + 1) >= (int)m_commandString.size())
if ((m_cursorPosition + 1) >= int(m_commandString.size()))
break;
if (int(mod & boo::EModifierKey::Ctrl) != 0)
{
int index = m_commandString.find_first_of(' ', m_cursorPosition + 1);
size_t index = m_commandString.find_first_of(' ', size_t(m_cursorPosition + 1));
if (index != std::string::npos)
m_commandString.erase(m_cursorPosition + 1, index + 1);
m_commandString.erase(size_t(m_cursorPosition + 1), index + 1);
else
m_commandString.erase(m_cursorPosition + 1, (m_cursorPosition + 1) - m_commandString.size());
m_commandString.erase(size_t(m_cursorPosition + 1), size_t(m_cursorPosition + 1) - m_commandString.size());
break;
}
m_commandString.erase(m_cursorPosition + 1, 1);
m_commandString.erase(size_t(m_cursorPosition + 1), 1);
}
break;
}
case boo::ESpecialKey::PgUp:
{
if (m_logOffset < (int)(m_log.size() - m_maxLines) - 1)
if (m_logOffset < int(m_log.size() - m_maxLines) - 1)
m_logOffset++;
break;
}
@ -250,7 +266,7 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
break;
if (int(mod & boo::EModifierKey::Ctrl) != 0)
m_cursorPosition = (int)m_commandString.rfind(' ', m_cursorPosition) - 1;
m_cursorPosition = int(m_commandString.rfind(' ', size_t(m_cursorPosition) - 1));
else
m_cursorPosition--;
@ -260,19 +276,19 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
}
case boo::ESpecialKey::Right:
{
if (m_cursorPosition >= (int)m_commandString.size() - 1)
if (m_cursorPosition >= int(m_commandString.size() - 1))
break;
if (int(mod & boo::EModifierKey::Ctrl) != 0)
{
if (m_commandString[m_cursorPosition] == ' ')
if (m_commandString[size_t(m_cursorPosition)] == ' ')
m_cursorPosition++;
int tmpPos = m_commandString.find(' ', m_cursorPosition);
size_t tmpPos = m_commandString.find(' ', size_t(m_cursorPosition));
if (tmpPos == std::string::npos)
m_cursorPosition = m_commandString.size() - 1;
m_cursorPosition = int(m_commandString.size() - 1);
else
m_cursorPosition = tmpPos;
m_cursorPosition = int(tmpPos);
}
else
m_cursorPosition++;
@ -289,11 +305,11 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
m_currentCommand++;
if (m_currentCommand > (int)m_commandHistory.size() - 1)
m_currentCommand = (int)m_commandHistory.size() - 1;
if (m_currentCommand > int(m_commandHistory.size() - 1))
m_currentCommand = int(m_commandHistory.size() - 1);
m_commandString = m_commandHistory[m_currentCommand];
m_cursorPosition = m_commandString.size();
m_commandString = m_commandHistory[size_t(m_currentCommand)];
m_cursorPosition = int(m_commandString.size() - 1);
break;
}
case boo::ESpecialKey::Down:
@ -303,28 +319,28 @@ void Console::handleSpecialKeyDown(boo::ESpecialKey sp, boo::EModifierKey mod, b
m_currentCommand--;
if (m_currentCommand >= 0)
{
m_commandString = m_commandHistory[m_currentCommand];
m_commandString = m_commandHistory[size_t(m_currentCommand)];
}
else if (m_currentCommand <= -1)
{
m_currentCommand = -1;
m_commandString.clear();
}
m_cursorPosition = m_commandString.size();
m_cursorPosition = int(m_commandString.size());
break;
}
case boo::ESpecialKey::Home:
m_cursorPosition = -1;
break;
case boo::ESpecialKey::End:
m_cursorPosition = m_commandString.size() - 1;
m_cursorPosition = int(m_commandString.size() - 1);
break;
default:
break;
}
}
void Console::handleSpecialKeyUp(boo::ESpecialKey sp, boo::EModifierKey mod)
void Console::handleSpecialKeyUp(boo::ESpecialKey /*sp*/, boo::EModifierKey /*mod*/)
{
}

View File

@ -12,16 +12,12 @@
using namespace std::literals;
namespace hecl::Database
{
std::vector<const struct DataSpecEntry*> DATA_SPEC_REGISTRY;
}
struct HECLWindowCallback : boo::IWindowCallback
{
bool m_sizeDirty = false;
boo::SWindowRect m_latestSize;
void resized(const boo::SWindowRect& rect, bool sync)
virtual ~HECLWindowCallback();
void resized(const boo::SWindowRect& rect, bool /*sync*/)
{
m_sizeDirty = true;
m_latestSize = rect;
@ -47,6 +43,11 @@ struct HECLWindowCallback : boo::IWindowCallback
}
};
HECLWindowCallback::~HECLWindowCallback()
{
}
struct HECLApplicationCallback : boo::IApplicationCallback
{
HECLWindowCallback m_windowCb;
@ -57,13 +58,15 @@ struct HECLApplicationCallback : boo::IApplicationCallback
bool m_running = true;
HECLApplicationCallback()
: m_fileStoreMgr("heclTest"),
: m_fileStoreMgr(_S("heclTest")),
m_cvarManager(m_fileStoreMgr),
m_console(&m_cvarManager)
{
m_console.registerCommand("quit"sv, "Quits application"sv, "", std::bind(&HECLApplicationCallback::quit, this, std::placeholders::_1, std::placeholders::_2));
}
virtual ~HECLApplicationCallback();
int appMain(boo::IApplication* app)
{
hecl::VerbosityLevel = 2;
@ -123,7 +126,7 @@ struct HECLApplicationCallback : boo::IApplicationCallback
gfxF->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{
boo::SWindowRect mainWindowRect = m_mainWindow->getWindowFrame();
renderTex = ctx.newRenderTexture(mainWindowRect.size[0], mainWindowRect.size[1],
renderTex = ctx.newRenderTexture(size_t(mainWindowRect.size[0]), size_t(mainWindowRect.size[1]),
boo::TextureClampMode::Repeat, 0, 0);
/* Generate meta structure (usually statically serialized) */
@ -169,8 +172,8 @@ struct HECLApplicationCallback : boo::IApplicationCallback
for (int i=0 ; i<256 ; ++i)
for (int j=0 ; j<256 ; ++j)
{
tex[i][j][0] = i;
tex[i][j][1] = j;
tex[i][j][0] = uint8_t(i);
tex[i][j][1] = uint8_t(i);
tex[i][j][2] = 0;
tex[i][j][3] = 0xff;
}
@ -217,8 +220,8 @@ struct HECLApplicationCallback : boo::IApplicationCallback
if (m_windowCb.m_sizeDirty)
{
gfxQ->resizeRenderTexture(renderTex,
m_windowCb.m_latestSize.size[0],
m_windowCb.m_latestSize.size[1]);
size_t(m_windowCb.m_latestSize.size[0]),
size_t(m_windowCb.m_latestSize.size[1]));
m_windowCb.m_sizeDirty = false;
}
@ -230,12 +233,12 @@ struct HECLApplicationCallback : boo::IApplicationCallback
r.location[1] = 0;
gfxQ->setViewport(r);
gfxQ->setScissor(r);
float rgba[] = {sinf(frameIdx / 60.0), cosf(frameIdx / 60.0), 0.0, 1.0};
float rgba[] = {sinf(frameIdx / 60.0f), cosf(frameIdx / 60.0f), 0.0f, 1.0f};
gfxQ->setClearColor(rgba);
gfxQ->clearTarget();
vuboData.modelview[3][0] = sinf(frameIdx / 60.0) * 0.5;
vuboData.modelview[3][1] = cosf(frameIdx / 60.0) * 0.5;
vuboData.modelview[3][0] = sinf(frameIdx / 60.0f) * 0.5f;
vuboData.modelview[3][1] = cosf(frameIdx / 60.0f) * 0.5f;
vubo.cast<boo::IGraphicsBufferD>()->load(&vuboData, sizeof(vuboData));
gfxQ->setShaderDataBinding(binding);
@ -248,31 +251,32 @@ struct HECLApplicationCallback : boo::IApplicationCallback
}
std::unique_lock<std::mutex> finallk(loadmt);
m_cvarManager.serialize();
finallk.unlock();
gfxQ->stopRenderer();
loadcv.notify_one();
loaderThr.join();
return 0;
}
void appQuitting(boo::IApplication* app)
void appQuitting(boo::IApplication* /*app*/)
{
m_running = false;
}
void quit(hecl::Console* con, const std::vector<std::string>& args)
void quit(hecl::Console* /*con*/, const std::vector<std::string>& /*args*/)
{
m_running = false;
}
};
void AthenaExcHandler(athena::error::Level level,
const char* file, const char* function,
const char* file, const char* /*function*/,
int line, const char* fmt, ...)
{
static logvisor::Module Log("heclTest::AthenaExcHandler");
va_list ap;
va_start(ap, fmt);
Log.reportSource(logvisor::Level(level), file, line, fmt, ap);
Log.reportSource(logvisor::Level(level), file, uint32_t(line), fmt, ap);
va_end(ap);
}
@ -324,3 +328,8 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int)
return wmain(argc+1, booArgv);
}
#endif
HECLApplicationCallback::~HECLApplicationCallback()
{
}