Fix ModifyRestart CVars

This commit is contained in:
Phillip Stephens 2022-06-12 00:31:26 -07:00
parent 65f5b873c8
commit a3c2638cce
4 changed files with 38 additions and 5 deletions

View File

@ -400,6 +400,8 @@ void CVar::clearModified() {
m_flags &= ~EFlags::Modified; m_flags &= ~EFlags::Modified;
} }
void CVar::forceClearModified() { m_flags &= ~EFlags::Modified; }
void CVar::setModified() { m_flags |= EFlags::Modified; } void CVar::setModified() { m_flags |= EFlags::Modified; }
void CVar::unlock() { void CVar::unlock() {
@ -506,4 +508,4 @@ void CVar::init(EFlags flags, bool removeColor) {
} }
} }
} // namespace hecl } // namespace metaforce

View File

@ -156,6 +156,7 @@ private:
CVar(std::string_view name, std::string_view help, EType type) : m_help(help), m_type(type) { m_name = name; } CVar(std::string_view name, std::string_view help, EType type) : m_help(help), m_type(type) { m_name = name; }
void dispatch(); void dispatch();
void clearModified(); void clearModified();
void forceClearModified();
void setModified(); void setModified();
std::string m_help; std::string m_help;
EType m_type; EType m_type;

View File

@ -123,9 +123,15 @@ void CVarManager::deserialize(CVar* cvar) {
std::find_if(container.cbegin(), container.cend(), [&cvar](const auto& c) { return c.m_name == cvar->name(); }); std::find_if(container.cbegin(), container.cend(), [&cvar](const auto& c) { return c.m_name == cvar->name(); });
if (serialized != container.cend()) { if (serialized != container.cend()) {
if (cvar->m_value != serialized->m_value) { if (cvar->m_value != serialized->m_value) {
CVarUnlocker lc(cvar); {
cvar->fromLiteralToType(serialized->m_value); CVarUnlocker lc(cvar);
cvar->m_wasDeserialized = true; cvar->fromLiteralToType(serialized->m_value);
cvar->m_wasDeserialized = true;
}
if (cvar->modificationRequiresRestart()) {
cvar->dispatch();
cvar->forceClearModified();
}
} }
} }
} }
@ -316,8 +322,10 @@ void CVarManager::restoreDeveloper(bool oldDeveloper) {
} }
void CVarManager::proc() { void CVarManager::proc() {
for (const auto& [name, cvar] : m_cvars) { for (const auto& [name, cvar] : m_cvars) {
if (cvar->isModified() && !cvar->modificationRequiresRestart()) { if (cvar->isModified()) {
cvar->dispatch(); cvar->dispatch();
}
if (cvar->isModified() && !cvar->modificationRequiresRestart()) {
// Clear the modified flag now that we've informed everyone we've changed // Clear the modified flag now that we've informed everyone we've changed
cvar->clearModified(); cvar->clearModified();
} }

View File

@ -426,6 +426,9 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
sortedList.reserve(cvars.size()); sortedList.reserve(cvars.size());
for (auto* cvar : cvars) { for (auto* cvar : cvars) {
if (cvar->isHidden()) {
continue;
}
if (!m_cvarFiltersText.empty()) { if (!m_cvarFiltersText.empty()) {
if (ContainsCaseInsensitive(magic_enum::enum_name(cvar->type()), m_cvarFiltersText) || if (ContainsCaseInsensitive(magic_enum::enum_name(cvar->type()), m_cvarFiltersText) ||
ContainsCaseInsensitive(cvar->name(), m_cvarFiltersText)) { ContainsCaseInsensitive(cvar->name(), m_cvarFiltersText)) {
@ -451,6 +454,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
} }
for (auto* cv : sortedList) { for (auto* cv : sortedList) {
bool modified = cv->isModified();
ImGui::PushID(cv); ImGui::PushID(cv);
ImGui::TableNextRow(); ImGui::TableNextRow();
// Name // Name
@ -468,6 +472,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
bool b = cv->toBoolean(); bool b = cv->toBoolean();
if (ImGui::Checkbox("", &b)) { if (ImGui::Checkbox("", &b)) {
cv->fromBoolean(b); cv->fromBoolean(b);
modified = true;
} }
break; break;
} }
@ -475,6 +480,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
float f = cv->toReal(); float f = cv->toReal();
if (ImGui::DragFloat("", &f)) { if (ImGui::DragFloat("", &f)) {
cv->fromReal(f); cv->fromReal(f);
modified = true;
} }
break; break;
} }
@ -482,6 +488,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
std::array<s32, 1> i{cv->toSigned()}; std::array<s32, 1> i{cv->toSigned()};
if (ImGui::DragScalar("", ImGuiDataType_S32, i.data(), i.size())) { if (ImGui::DragScalar("", ImGuiDataType_S32, i.data(), i.size())) {
cv->fromInteger(i[0]); cv->fromInteger(i[0]);
modified = true;
} }
break; break;
} }
@ -489,6 +496,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
std::array<u32, 1> i{cv->toUnsigned()}; std::array<u32, 1> i{cv->toUnsigned()};
if (ImGui::DragScalar("", ImGuiDataType_U32, i.data(), i.size())) { if (ImGui::DragScalar("", ImGuiDataType_U32, i.data(), i.size())) {
cv->fromInteger(i[0]); cv->fromInteger(i[0]);
modified = true;
} }
break; break;
} }
@ -497,6 +505,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
strcpy(buf, cv->value().c_str()); strcpy(buf, cv->value().c_str());
if (ImGui::InputText("", buf, 4096, ImGuiInputTextFlags_EnterReturnsTrue)) { if (ImGui::InputText("", buf, 4096, ImGuiInputTextFlags_EnterReturnsTrue)) {
cv->fromLiteral(buf); cv->fromLiteral(buf);
modified = true;
} }
break; break;
} }
@ -507,6 +516,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
vec.x() = scalars[0]; vec.x() = scalars[0];
vec.y() = scalars[1]; vec.y() = scalars[1];
cv->fromVec2f(vec); cv->fromVec2f(vec);
modified = true;
} }
break; break;
} }
@ -517,6 +527,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
vec.x() = scalars[0]; vec.x() = scalars[0];
vec.y() = scalars[1]; vec.y() = scalars[1];
cv->fromVec2d(vec); cv->fromVec2d(vec);
modified = true;
} }
break; break;
} }
@ -529,12 +540,14 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
vec.y() = scalars[1]; vec.y() = scalars[1];
vec.z() = scalars[2]; vec.z() = scalars[2];
cv->fromVec3f(vec); cv->fromVec3f(vec);
modified = true;
} }
} else if (ImGui::DragScalarN("", ImGuiDataType_Float, scalars.data(), scalars.size(), 0.1f)) { } else if (ImGui::DragScalarN("", ImGuiDataType_Float, scalars.data(), scalars.size(), 0.1f)) {
vec.x() = scalars[0]; vec.x() = scalars[0];
vec.y() = scalars[1]; vec.y() = scalars[1];
vec.z() = scalars[2]; vec.z() = scalars[2];
cv->fromVec3f(vec); cv->fromVec3f(vec);
modified = true;
} }
break; break;
} }
@ -549,12 +562,14 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
vec.y() = scalars[1]; vec.y() = scalars[1];
vec.z() = scalars[2]; vec.z() = scalars[2];
cv->fromVec3d(vec); cv->fromVec3d(vec);
modified = true;
} }
} else if (ImGui::DragScalarN("", ImGuiDataType_Double, scalars.data(), scalars.size(), 0.1f)) { } else if (ImGui::DragScalarN("", ImGuiDataType_Double, scalars.data(), scalars.size(), 0.1f)) {
vec.x() = scalars[0]; vec.x() = scalars[0];
vec.y() = scalars[1]; vec.y() = scalars[1];
vec.z() = scalars[2]; vec.z() = scalars[2];
cv->fromVec3d(vec); cv->fromVec3d(vec);
modified = true;
} }
break; break;
} }
@ -568,6 +583,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
vec.z() = scalars[2]; vec.z() = scalars[2];
vec.w() = scalars[2]; vec.w() = scalars[2];
cv->fromVec4f(vec); cv->fromVec4f(vec);
modified = true;
} }
} else if (ImGui::DragScalarN("", ImGuiDataType_Float, scalars.data(), scalars.size(), 0.1f)) { } else if (ImGui::DragScalarN("", ImGuiDataType_Float, scalars.data(), scalars.size(), 0.1f)) {
vec.x() = scalars[0]; vec.x() = scalars[0];
@ -575,6 +591,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
vec.z() = scalars[2]; vec.z() = scalars[2];
vec.w() = scalars[2]; vec.w() = scalars[2];
cv->fromVec4f(vec); cv->fromVec4f(vec);
modified = true;
} }
break; break;
} }
@ -590,6 +607,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
vec.z() = scalars[2]; vec.z() = scalars[2];
vec.w() = scalars[2]; vec.w() = scalars[2];
cv->fromVec4d(vec); cv->fromVec4d(vec);
modified = true;
} }
} else if (ImGui::DragScalarN("", ImGuiDataType_Double, scalars.data(), scalars.size(), 0.1f)) { } else if (ImGui::DragScalarN("", ImGuiDataType_Double, scalars.data(), scalars.size(), 0.1f)) {
vec.x() = scalars[0]; vec.x() = scalars[0];
@ -597,6 +615,7 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
vec.z() = scalars[2]; vec.z() = scalars[2];
vec.w() = scalars[2]; vec.w() = scalars[2];
cv->fromVec4d(vec); cv->fromVec4d(vec);
modified = true;
} }
break; break;
} }
@ -604,6 +623,9 @@ void ImGuiConsole::ShowConsoleVariablesWindow() {
ImGui::Text("lawl wut? Please contact a developer, your copy of Metaforce is cursed!"); ImGui::Text("lawl wut? Please contact a developer, your copy of Metaforce is cursed!");
break; break;
} }
if (modified && cv->modificationRequiresRestart()) {
ImGui::Text("Restart required for value to take affect!");
}
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
std::string sv(cv->defaultValue()); std::string sv(cv->defaultValue());
ImGui::SetTooltip("Default: %s", sv.c_str()); ImGui::SetTooltip("Default: %s", sv.c_str());