From 0ae5755abbf2ebf206a6e2757a6a83c6b9b97f8d Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 8 Nov 2022 22:36:03 +0100 Subject: [PATCH 1/2] Implement TestModels/T3D --- CHANGELOG.md | 1 + apps/openmw/mwscript/docs/vmformat.txt | 3 +- apps/openmw/mwscript/miscextensions.cpp | 71 ++++++++++++++++++++++++- components/compiler/extensions0.cpp | 2 + components/compiler/opcodes.hpp | 1 + 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc4ac92339..4099a8b70a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ Feature #6979: Add support of loading and displaying LOD assets purely based on their filename extension Feature #6983: PCVisionBonus script functions Feature #6995: Localize the "show effect duration" option + Feature #7058: Implement TestModels (T3D) console command 0.48.0 ------ diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 7197be48ba..d34c39c9df 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -484,5 +484,6 @@ op 0x2000321: ReloadLua op 0x2000322: GetPCVisionBonus op 0x2000323: SetPCVisionBonus op 0x2000324: ModPCVisionBonus +op 0x2000325: TestModels, T3D -opcodes 0x2000325-0x3ffffff unused +opcodes 0x2000326-0x3ffffff unused diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 604fc06fe4..445fe61f89 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -19,11 +19,28 @@ #include #include - +#include + +#include +#include +#include +#include +#include +#include +#include +#include #include #include +#include #include +#include +#include #include +#include +#include +#include +#include +#include #include #include @@ -1574,6 +1591,57 @@ namespace MWScript } }; + class OpTestModels : public Interpreter::Opcode0 + { + template + void test(int& count) const + { + Resource::SceneManager* sceneManager + = MWBase::Environment::get().getResourceSystem()->getSceneManager(); + const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); + for (const T& record : store.get()) + { + MWWorld::ManualRef ref(store, record.mId); + std::string model = ref.getPtr().getClass().getModel(ref.getPtr()); + if (!model.empty()) + { + sceneManager->getTemplate(model); + ++count; + } + } + } + + public: + void execute(Interpreter::Runtime& runtime) override + { + runtime.getContext().report("Loading all models. This may take a while..."); + int count = 0; + + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + test(count); + + std::stringstream message; + message << "Attempted to load " << count << " models. Check the log for details."; + runtime.getContext().report(message.str()); + } + }; + void installOpcodes(Interpreter::Interpreter& interpreter) { interpreter.installSegment5(Compiler::Misc::opcodeMenuMode); @@ -1699,6 +1767,7 @@ namespace MWScript interpreter.installSegment5(Compiler::Misc::opcodeToggleRecastMesh); interpreter.installSegment5(Compiler::Misc::opcodeHelp); interpreter.installSegment5(Compiler::Misc::opcodeReloadLua); + interpreter.installSegment5(Compiler::Misc::opcodeTestModels); } } } diff --git a/components/compiler/extensions0.cpp b/components/compiler/extensions0.cpp index 13e4c63b1f..6f57ee7673 100644 --- a/components/compiler/extensions0.cpp +++ b/components/compiler/extensions0.cpp @@ -325,6 +325,8 @@ namespace Compiler extensions.registerInstruction("togglerecastmesh", "", opcodeToggleRecastMesh); extensions.registerInstruction("help", "", opcodeHelp); extensions.registerInstruction("reloadlua", "", opcodeReloadLua); + extensions.registerInstruction("testmodels", "", opcodeTestModels); + extensions.registerInstruction("t3d", "", opcodeTestModels); } } diff --git a/components/compiler/opcodes.hpp b/components/compiler/opcodes.hpp index c0d35f0fac..2ec31c7588 100644 --- a/components/compiler/opcodes.hpp +++ b/components/compiler/opcodes.hpp @@ -320,6 +320,7 @@ namespace Compiler const int opcodeStartScriptExplicit = 0x200031d; const int opcodeHelp = 0x2000320; const int opcodeReloadLua = 0x2000321; + const int opcodeTestModels = 0x2000325; } namespace Sky From b94818b24a1502603525ab2bc7bdbb2ca125ce93 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 10 Nov 2022 17:24:58 +0100 Subject: [PATCH 2/2] Tweak message and temporarily set model ttl to 0 --- apps/openmw/mwscript/miscextensions.cpp | 8 ++++++-- components/resource/resourcemanager.hpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 445fe61f89..3898afd36d 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -1614,7 +1614,10 @@ namespace MWScript public: void execute(Interpreter::Runtime& runtime) override { - runtime.getContext().report("Loading all models. This may take a while..."); + Resource::SceneManager* sceneManager + = MWBase::Environment::get().getResourceSystem()->getSceneManager(); + double delay = sceneManager->getExpiryDelay(); + sceneManager->setExpiryDelay(0.0); int count = 0; test(count); @@ -1636,8 +1639,9 @@ namespace MWScript test(count); test(count); + sceneManager->setExpiryDelay(delay); std::stringstream message; - message << "Attempted to load " << count << " models. Check the log for details."; + message << "Attempted to load models for " << count << " objects. Check the log for details."; runtime.getContext().report(message.str()); } }; diff --git a/components/resource/resourcemanager.hpp b/components/resource/resourcemanager.hpp index 655076e65b..d53c4230f0 100644 --- a/components/resource/resourcemanager.hpp +++ b/components/resource/resourcemanager.hpp @@ -60,7 +60,7 @@ namespace Resource /// How long to keep objects in cache after no longer being referenced. void setExpiryDelay(double expiryDelay) override { mExpiryDelay = expiryDelay; } - float getExpiryDelay() const { return mExpiryDelay; } + double getExpiryDelay() const { return mExpiryDelay; } const VFS::Manager* getVFS() const { return mVFS; }