From 6f214552e734eed02c15faff749290845b48abc4 Mon Sep 17 00:00:00 2001 From: Marcus Weber Date: Fri, 12 Aug 2022 12:18:37 +0200 Subject: [PATCH] Release v1.1.2. --- CHANGELOG.md | 9 ++ CMakeLists.txt | 2 +- .../ramses_adaptor/LuaInterfaceAdaptor.h | 3 + .../ramses_adaptor/LuaInterfaceAdaptor.cpp | 33 +++++++- .../tests/LinkOptimization_test.cpp | 28 +++---- .../tests/LuaInterfaceAdaptor_test.cpp | 83 +++++++++++++++---- 6 files changed, 127 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43e96cb2..64c923ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,15 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h --> +## [1.1.2] Lua Interface Naming Bugfix + +### Fixes +* Change names of LuaInterface objects in the LogicEngine to match the conventions used for LuaScripts. In particular + * LuaInterface objects outside any PrefabInstance use the LuaInterface name in the LogicEngine. + * LuaInterfaces which are direct children of a non-nested PrefabInstance are named `.` + * All other LuaInterfaces have the object ID of the LuaInterface object appended `-`. + + ## [1.1.1] Lua Interface, Timer, and Animation Bugfixes ### Fixes diff --git a/CMakeLists.txt b/CMakeLists.txt index bf738713..3cc5cdb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 3.19) SET(CMAKE_CONFIGURATION_TYPES "Debug;RelWithDebInfo") -project(RaCoOS VERSION 1.1.1) +project(RaCoOS VERSION 1.1.2) SET(RACO_RELEASE_DIRECTORY ${CMAKE_BINARY_DIR}/release) diff --git a/components/libRamsesBase/include/ramses_adaptor/LuaInterfaceAdaptor.h b/components/libRamsesBase/include/ramses_adaptor/LuaInterfaceAdaptor.h index 43290405..c82a76cc 100644 --- a/components/libRamsesBase/include/ramses_adaptor/LuaInterfaceAdaptor.h +++ b/components/libRamsesBase/include/ramses_adaptor/LuaInterfaceAdaptor.h @@ -31,6 +31,7 @@ class LuaInterfaceAdaptor : public UserTypeObjectAdaptordispatcher()->registerOnPropertyChange("children", [this](core::ValueHandle handle) { + if (parent_ != editorObject_->getParent()) { + setupParentSubscription(); + tagDirty(); + recreateStatus_ = true; + } + })), linksLifecycleSubscription_{sceneAdaptor_->dispatcher()->registerOnLinksLifeCycle( [this](const core::LinkDescriptor& link) { if (sceneAdaptor_->optimizeForExport() && (link.start.object() == editorObject_ || link.end.object() == editorObject_)) { @@ -47,6 +56,20 @@ LuaInterfaceAdaptor::LuaInterfaceAdaptor(SceneAdaptor* sceneAdaptor, std::shared recreateStatus_ = true; } })} { + setupParentSubscription(); +} + +void LuaInterfaceAdaptor::setupParentSubscription() { + parent_ = editorObject_->getParent(); + + if (parent_ && parent_->as()) { + parentNameSubscription_ = sceneAdaptor_->dispatcher()->registerOn({parent_, &user_types::LuaScript::objectName_}, [this]() { + tagDirty(); + recreateStatus_ = true; + }); + } else { + parentNameSubscription_ = components::Subscription{}; + } } void LuaInterfaceAdaptor::getLogicNodes(std::vector& logicNodes) const { @@ -72,7 +95,15 @@ void LuaInterfaceAdaptor::onRuntimeError(core::Errors& errors, std::string const std::string LuaInterfaceAdaptor::generateRamsesObjectName() const { - return editorObject_->objectName() + "-" + editorObject_->objectID(); + auto prefabInstOuter = raco::core::PrefabOperations::findOuterContainingPrefabInstance(editorObject_); + if (prefabInstOuter) { + if (prefabInstOuter == parent_) { + return parent_->objectName() + "." + editorObject_->objectName(); + } else { + return editorObject_->objectName() + "-" + editorObject_->objectID(); + } + } + return editorObject_->objectName(); } bool LuaInterfaceAdaptor::sync(core::Errors* errors) { diff --git a/components/libRamsesBase/tests/LinkOptimization_test.cpp b/components/libRamsesBase/tests/LinkOptimization_test.cpp index 2ae0596f..dae0c7c3 100644 --- a/components/libRamsesBase/tests/LinkOptimization_test.cpp +++ b/components/libRamsesBase/tests/LinkOptimization_test.cpp @@ -106,8 +106,8 @@ TEST_F(LuaLinkOptimizationFixture, link_opt_level_up) { commandInterface.set({ start, {"inputs", "string"} }, std::string("asdf")); dispatch(); - auto startEngineObject = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); - auto midEngineObject = select(sceneContext.logicEngine(), std::string("mid-" + mid->objectID()).c_str()); + auto startEngineObject = select(sceneContext.logicEngine(), std::string("start").c_str()); + auto midEngineObject = select(sceneContext.logicEngine(), std::string("mid").c_str()); auto endEngineObject = select(sceneContext.logicEngine(), std::string("end").c_str()); ASSERT_TRUE(startEngineObject == nullptr); ASSERT_TRUE(midEngineObject == nullptr); @@ -135,8 +135,8 @@ TEST_F(LuaLinkOptimizationFixture, link_opt_level_up) { dispatch(); - startEngineObject = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); - midEngineObject = select(sceneContext.logicEngine(), std::string("mid-" + mid->objectID()).c_str()); + startEngineObject = select(sceneContext.logicEngine(), std::string("start").c_str()); + midEngineObject = select(sceneContext.logicEngine(), std::string("mid").c_str()); endEngineObject = select(sceneContext.logicEngine(), std::string("end").c_str()); ASSERT_TRUE(startEngineObject != nullptr); ASSERT_TRUE(midEngineObject == nullptr); @@ -178,8 +178,8 @@ TEST_F(LuaLinkOptimizationFixture, link_opt_level_same) { commandInterface.set({ start, {"inputs", "string"} }, std::string("asdf")); dispatch(); - auto startEngineObject = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); - auto midEngineObject = select(sceneContext.logicEngine(), std::string("mid-" + mid->objectID()).c_str()); + auto startEngineObject = select(sceneContext.logicEngine(), std::string("start").c_str()); + auto midEngineObject = select(sceneContext.logicEngine(), std::string("mid").c_str()); auto endEngineObject = select(sceneContext.logicEngine(), std::string("end").c_str()); ASSERT_TRUE(startEngineObject == nullptr); ASSERT_TRUE(midEngineObject == nullptr); @@ -207,8 +207,8 @@ TEST_F(LuaLinkOptimizationFixture, link_opt_level_same) { dispatch(); - startEngineObject = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); - midEngineObject = select(sceneContext.logicEngine(), std::string("mid-" + mid->objectID()).c_str()); + startEngineObject = select(sceneContext.logicEngine(), std::string("start").c_str()); + midEngineObject = select(sceneContext.logicEngine(), std::string("mid").c_str()); endEngineObject = select(sceneContext.logicEngine(), std::string("end").c_str()); ASSERT_TRUE(startEngineObject != nullptr); @@ -243,9 +243,9 @@ TEST_F(LuaLinkOptimizationFixture, link_opt_level_down) { commandInterface.set({ start_b, {"inputs", "float"} }, 2.0); dispatch(); - auto startAEngineObject = select(sceneContext.logicEngine(), std::string("start_a-" + start_a->objectID()).c_str()); - auto startBEngineObject = select(sceneContext.logicEngine(), std::string("start_b-" + start_b->objectID()).c_str()); - auto midEngineObject = select(sceneContext.logicEngine(), std::string("mid-" + mid->objectID()).c_str()); + auto startAEngineObject = select(sceneContext.logicEngine(), std::string("start_a").c_str()); + auto startBEngineObject = select(sceneContext.logicEngine(), std::string("start_b").c_str()); + auto midEngineObject = select(sceneContext.logicEngine(), std::string("mid").c_str()); auto endEngineObject = select(sceneContext.logicEngine(), std::string("end").c_str()); ASSERT_TRUE(startAEngineObject == nullptr); ASSERT_TRUE(startBEngineObject == nullptr); @@ -258,9 +258,9 @@ TEST_F(LuaLinkOptimizationFixture, link_opt_level_down) { dispatch(); - startAEngineObject = select(sceneContext.logicEngine(), std::string("start_a-" + start_a->objectID()).c_str()); - startBEngineObject = select(sceneContext.logicEngine(), std::string("start_b-" + start_b->objectID()).c_str()); - midEngineObject = select(sceneContext.logicEngine(), std::string("mid-" + mid->objectID()).c_str()); + startAEngineObject = select(sceneContext.logicEngine(), std::string("start_a").c_str()); + startBEngineObject = select(sceneContext.logicEngine(), std::string("start_b").c_str()); + midEngineObject = select(sceneContext.logicEngine(), std::string("mid").c_str()); endEngineObject = select(sceneContext.logicEngine(), std::string("end").c_str()); ASSERT_TRUE(startAEngineObject != nullptr); ASSERT_TRUE(startBEngineObject != nullptr); diff --git a/components/libRamsesBase/tests/LuaInterfaceAdaptor_test.cpp b/components/libRamsesBase/tests/LuaInterfaceAdaptor_test.cpp index 91b6e268..d7f322a1 100644 --- a/components/libRamsesBase/tests/LuaInterfaceAdaptor_test.cpp +++ b/components/libRamsesBase/tests/LuaInterfaceAdaptor_test.cpp @@ -11,6 +11,10 @@ #include "RamsesBaseFixture.h" +#include "user_types/Node.h" +#include "user_types/Prefab.h" +#include "user_types/PrefabInstance.h" + #include "ramses_adaptor/LuaInterfaceAdaptor.h" using namespace raco::user_types; @@ -84,11 +88,60 @@ TEST_F(LuaInterfaceAdaptorFixture, valid_text) { dispatch(); ASSERT_EQ(sceneContext.logicEngine().getCollection().size(), 1); - auto engineObject = select(sceneContext.logicEngine(), std::string("interface-" + interface->objectID()).c_str()); + auto engineObject = select(sceneContext.logicEngine(), std::string("interface").c_str()); ASSERT_TRUE(engineObject != nullptr); ASSERT_EQ(engineObject->getUserId(), interface->objectIDAsRamsesLogicID()); } +TEST_F(LuaInterfaceAdaptorFixture, name_prefab_inst) { + auto interfaceFile = defaultFile(); + + auto prefab = create("prefab"); + auto interface = create_lua_interface("interface", interfaceFile, prefab); + + auto inst = create_prefabInstance("inst", prefab); + + dispatch(); + + auto engineObj = select(sceneContext.logicEngine(), "inst.interface"); + ASSERT_TRUE(engineObj != nullptr); + + commandInterface.set({inst, &PrefabInstance::objectName_}, std::string("asdf")); + dispatch(); + + engineObj = select(sceneContext.logicEngine(), "inst.interface"); + ASSERT_TRUE(engineObj == nullptr); + engineObj = select(sceneContext.logicEngine(), "asdf.interface"); + ASSERT_TRUE(engineObj != nullptr); +} + +TEST_F(LuaInterfaceAdaptorFixture, name_prefab_inst_nested) { + auto interfaceFile = defaultFile(); + + auto prefab = create("prefab"); + auto interface = create_lua_interface("interface", interfaceFile, prefab); + + auto prefab_outer = create("prefab_outer"); + auto inst_inner = create_prefabInstance("inst_inner", prefab, prefab_outer); + + auto inst = create_prefabInstance("inst", prefab_outer); + auto inst_nested = inst->children_->asVector()[0]->as(); + auto intf_nested = inst_nested->children_->asVector()[0]; + + dispatch(); + + auto engineObject = select(sceneContext.logicEngine(), std::string("interface-" + intf_nested->objectID()).c_str()); + ASSERT_TRUE(engineObject != nullptr); + + //commandInterface.set({inst, &PrefabInstance::template_}, prefab); + //dispatch(); + + //engineObject = select(sceneContext.logicEngine(), std::string("interface-" + intf_nested->objectID()).c_str()); + //ASSERT_TRUE(engineObject == nullptr); + //engineObject = select(sceneContext.logicEngine(), "inst.interface"); + //ASSERT_TRUE(engineObject != nullptr); +} + TEST_F(LuaInterfaceAdaptorFixture, change_name) { auto interfaceFile = defaultFile(); auto interface = create_lua_interface("interface", interfaceFile); @@ -96,7 +149,7 @@ TEST_F(LuaInterfaceAdaptorFixture, change_name) { dispatch(); ASSERT_EQ(sceneContext.logicEngine().getCollection().size(), 1); - auto engineObject = select(sceneContext.logicEngine(), std::string("interface-" + interface->objectID()).c_str()); + auto engineObject = select(sceneContext.logicEngine(), std::string("interface").c_str()); ASSERT_TRUE(engineObject != nullptr); ASSERT_EQ(engineObject->getUserId(), interface->objectIDAsRamsesLogicID()); @@ -104,8 +157,8 @@ TEST_F(LuaInterfaceAdaptorFixture, change_name) { dispatch(); ASSERT_EQ(sceneContext.logicEngine().getCollection().size(), 1); - ASSERT_EQ(select(sceneContext.logicEngine(), std::string("interface-" + interface->objectID()).c_str()), nullptr); - engineObject = select(sceneContext.logicEngine(), std::string("newName-" + interface->objectID()).c_str()); + ASSERT_EQ(select(sceneContext.logicEngine(), std::string("interface").c_str()), nullptr); + engineObject = select(sceneContext.logicEngine(), std::string("newName").c_str()); ASSERT_TRUE(engineObject != nullptr); ASSERT_EQ(engineObject->getUserId(), interface->objectIDAsRamsesLogicID()); } @@ -115,7 +168,7 @@ TEST_F(LuaInterfaceAdaptorFixture, change_property_value) { auto interface = create_lua_interface("interface", interfaceFile); dispatch(); - auto engineObject = select(sceneContext.logicEngine(), std::string("interface-" + interface->objectID()).c_str()); + auto engineObject = select(sceneContext.logicEngine(), std::string("interface").c_str()); ASSERT_EQ(engineObject->getInputs()->getChild("float")->get(), 0.0); ASSERT_EQ(engineObject->getInputs()->getChild("vector2f")->get().value()[1], 0.0); @@ -185,7 +238,7 @@ TEST_F(LuaInterfaceAdaptorFixture, link_invalid_interface_to_invalid_script) { // test shouldn't crash here dispatch(); - auto ramsesStart = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); + auto ramsesStart = select(sceneContext.logicEngine(), std::string("start").c_str()); auto ramsesEnd = select(sceneContext.logicEngine(), "end"); EXPECT_EQ(ramsesStart, nullptr); EXPECT_EQ(ramsesEnd, nullptr); @@ -204,8 +257,8 @@ TEST_F(LuaInterfaceAdaptorFixture, link_invalid_interface_to_invalid_interface) // test shouldn't crash here dispatch(); - auto ramsesStart = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); - auto ramsesEnd = select(sceneContext.logicEngine(), std::string("end-" + end->objectID()).c_str()); + auto ramsesStart = select(sceneContext.logicEngine(), std::string("start").c_str()); + auto ramsesEnd = select(sceneContext.logicEngine(), std::string("end").c_str()); EXPECT_EQ(ramsesStart, nullptr); EXPECT_EQ(ramsesEnd, nullptr); @@ -225,7 +278,7 @@ TEST_F(LuaInterfaceAdaptorFixture, link_empty_interface_to_empty_script) { // test shouldn't crash here dispatch(); - auto ramsesStart = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); + auto ramsesStart = select(sceneContext.logicEngine(), std::string("start").c_str()); auto ramsesEnd = select(sceneContext.logicEngine(), "end"); EXPECT_NE(ramsesStart, nullptr); EXPECT_NE(ramsesEnd, nullptr); @@ -245,8 +298,8 @@ TEST_F(LuaInterfaceAdaptorFixture, link_empty_interface_to_empty_interface) { // test shouldn't crash here dispatch(); - auto ramsesStart = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); - auto ramsesEnd = select(sceneContext.logicEngine(), std::string("end-" + end->objectID()).c_str()); + auto ramsesStart = select(sceneContext.logicEngine(), std::string("start").c_str()); + auto ramsesEnd = select(sceneContext.logicEngine(), std::string("end").c_str()); EXPECT_NE(ramsesStart, nullptr); EXPECT_NE(ramsesEnd, nullptr); @@ -272,8 +325,8 @@ TEST_F(LuaInterfaceAdaptorFixture, link_individual_propagate_values) { commandInterface.set({start, {"inputs", "string"}}, std::string("asdf")); dispatch(); - auto startEngineObject = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); - auto endEngineObject = select(sceneContext.logicEngine(), std::string("end-" + end->objectID()).c_str()); + auto startEngineObject = select(sceneContext.logicEngine(), std::string("start").c_str()); + auto endEngineObject = select(sceneContext.logicEngine(), std::string("end").c_str()); ASSERT_TRUE(startEngineObject != nullptr); ASSERT_TRUE(endEngineObject != nullptr); @@ -346,8 +399,8 @@ TEST_F(LuaInterfaceAdaptorFixture, link_container_propagate_values) { commandInterface.set({start, {"inputs", "string"}}, std::string("asdf")); dispatch(); - auto startEngineObject = select(sceneContext.logicEngine(), std::string("start-" + start->objectID()).c_str()); - auto endEngineObject = select(sceneContext.logicEngine(), std::string("end-" + end->objectID()).c_str()); + auto startEngineObject = select(sceneContext.logicEngine(), std::string("start").c_str()); + auto endEngineObject = select(sceneContext.logicEngine(), std::string("end").c_str()); ASSERT_TRUE(startEngineObject != nullptr); ASSERT_TRUE(endEngineObject != nullptr);