From 2df12e101ee391772c7ef31ba1564bd7cd91e2e4 Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 1 Jan 2022 16:59:27 +0100 Subject: [PATCH] Disable static value evaluation for visible expression when optimizations are turned off --- .../Game/IW4/Menu/MenuConverterIW4.cpp | 19 ++++++++++++++++--- .../Game/IW4/Menu/MenuParsingIW4IT.cpp | 8 ++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp index b6ce81f4..70283454 100644 --- a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp +++ b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp @@ -493,10 +493,23 @@ namespace IW4 if (expression == nullptr) return nullptr; - if (expression->IsStatic()) + bool isStatic; + bool isTruthy; + if(m_disable_optimizations) { - const auto staticValue = expression->Evaluate(); - if (staticValue.IsTruthy()) + const auto* staticValue = dynamic_cast(expression); + isStatic = staticValue != nullptr; + isTruthy = isStatic && staticValue->IsTruthy(); + } + else + { + isStatic = expression->IsStatic(); + isTruthy = isStatic && expression->Evaluate().IsTruthy(); + } + + if (isStatic) + { + if (isTruthy) window->dynamicFlags[0] |= WINDOW_FLAG_VISIBLE; return nullptr; } diff --git a/test/ObjLoadingTests/Game/IW4/Menu/MenuParsingIW4IT.cpp b/test/ObjLoadingTests/Game/IW4/Menu/MenuParsingIW4IT.cpp index 27d45937..703e2dba 100644 --- a/test/ObjLoadingTests/Game/IW4/Menu/MenuParsingIW4IT.cpp +++ b/test/ObjLoadingTests/Game/IW4/Menu/MenuParsingIW4IT.cpp @@ -192,12 +192,8 @@ namespace test::game::iw4::menu::parsing::it REQUIRE(menu->window.rect.vertAlign == 2); REQUIRE(menu->window.style == 5); - REQUIRE(menu->visibleExp != nullptr); - REQUIRE(menu->visibleExp->entries != nullptr); - REQUIRE(menu->visibleExp->numEntries == 1); - REQUIRE(menu->visibleExp->entries[0].type == expressionEntryType::EET_OPERAND); - REQUIRE(menu->visibleExp->entries[0].data.operand.dataType == expDataType::VAL_INT); - REQUIRE(menu->visibleExp->entries[0].data.operand.internals.intVal > 0); + REQUIRE(menu->visibleExp == nullptr); + REQUIRE(menu->window.dynamicFlags[0] & WINDOW_FLAG_VISIBLE); REQUIRE(menu->onOpen != nullptr); REQUIRE(menu->onOpen->eventHandlerCount == 1);