From 84defabb6bfc803632e1115c418499b3812a1c72 Mon Sep 17 00:00:00 2001 From: Bashar Ahmed Date: Mon, 7 Mar 2022 22:09:31 +0530 Subject: [PATCH] minor scripting changes --- rootex/assets/scenes/pause.scene.json | 12 +------ .../components/physics/rigid_body_component.h | 4 +-- .../visual/model/renderable_component.cpp | 11 ++---- rootex/framework/system.cpp | 34 +++++++++++-------- rootex/script/interpreter.cpp | 7 +++- 5 files changed, 31 insertions(+), 37 deletions(-) diff --git a/rootex/assets/scenes/pause.scene.json b/rootex/assets/scenes/pause.scene.json index 4ff62614d..f99ffade2 100644 --- a/rootex/assets/scenes/pause.scene.json +++ b/rootex/assets/scenes/pause.scene.json @@ -28,17 +28,7 @@ ], "entity": { "components": { - "MusicComponent": { - "attenuationModel": 53251, - "audio": "rootex/assets/ball.wav", - "isAttenuated": false, - "isLooping": true, - "maxDistance": 100.0, - "playOnStart": true, - "referenceDistance": 1.0, - "rollOffFactor": 1.0, - "volume": 1.0 - }, + "TextUIComponent": { "color": { "a": 1.0, diff --git a/rootex/framework/components/physics/rigid_body_component.h b/rootex/framework/components/physics/rigid_body_component.h index d5019a335..91b66942e 100644 --- a/rootex/framework/components/physics/rigid_body_component.h +++ b/rootex/framework/components/physics/rigid_body_component.h @@ -49,13 +49,13 @@ class RigidBodyComponent : public CollisionComponent, public btMotionState void getWorldTransform(btTransform& worldTrans) const override; void setWorldTransform(const btTransform& worldTrans) override; - void updateTransform(); - void handleHit(Hit* hit) override; public: virtual ~RigidBodyComponent() = default; + void updateTransform(); + void applyForce(const Vector3& force); void applyTorque(const Vector3& torque); diff --git a/rootex/framework/components/visual/model/renderable_component.cpp b/rootex/framework/components/visual/model/renderable_component.cpp index 4290d9723..6972fd85d 100644 --- a/rootex/framework/components/visual/model/renderable_component.cpp +++ b/rootex/framework/components/visual/model/renderable_component.cpp @@ -232,12 +232,12 @@ void RenderableComponent::draw() ImGui::BeginGroup(); ImGui::Text("%s", newMaterial->getPath().filename().generic_string().c_str()); - if (ImGui::Button((ICON_ROOTEX_PENCIL_SQUARE_O "##" + newMaterial->getPath().generic_string()).c_str())) + if (ImGui::Button((ICON_ROOTEX_PENCIL_SQUARE_O "##1" + newMaterial->getPath().generic_string()).c_str())) { EventManager::GetSingleton()->call(EditorEvents::EditorOpenFile, VariantVector { newMaterial->getPath().generic_string(), (int)newMaterial->getType() }); } ImGui::SameLine(); - if (ImGui::Button((ICON_ROOTEX_FOLDER_OPEN "##" + newMaterial->getPath().generic_string()).c_str())) + if (ImGui::Button((ICON_ROOTEX_FOLDER_OPEN "##2" + newMaterial->getPath().generic_string()).c_str())) { if (Optional result = OS::SelectFile("Material(*.rmat)\0*.rmat\0", "game/assets/materials/")) { @@ -245,13 +245,6 @@ void RenderableComponent::draw() } } ImGui::SameLine(); - if (ImGui::Button((ICON_ROOTEX_FOLDER_OPEN "##" + oldMaterial->getPath().generic_string()).c_str())) - { - if (Optional result = OS::SelectFile("Material(*.rmat)\0*.rmat\0", "game/assets/materials/")) - { - setMaterialOverride(oldMaterial, ResourceLoader::CreateMaterialResourceFile(*result)); - } - } ImGui::EndGroup(); ImGui::NextColumn(); ImGui::Separator(); diff --git a/rootex/framework/system.cpp b/rootex/framework/system.cpp index a19ecdcb3..9fc55ac43 100644 --- a/rootex/framework/system.cpp +++ b/rootex/framework/system.cpp @@ -55,23 +55,29 @@ void System::setActive(bool enabled) void System::pause() { - for (auto& systemType : GetSystems()) - { - for (auto& system : systemType) - { - system->m_IsSystemPaused = true; - } - } + EventManager::GetSingleton()->defer([]() + { + for (auto& systemType : GetSystems()) + { + for (auto& system : systemType) + { + system->m_IsSystemPaused = true; + } + } + }); } void System::unPause() { - for (auto& systemType : GetSystems()) - { - for (auto& system : systemType) - { - system->m_IsSystemPaused = false; - } - } + EventManager::GetSingleton()->defer([]() + { + for (auto& systemType : GetSystems()) + { + for (auto& system : systemType) + { + system->m_IsSystemPaused = false; + } + } + }); } void System::draw() diff --git a/rootex/script/interpreter.cpp b/rootex/script/interpreter.cpp index 64fc7c178..323c63df8 100644 --- a/rootex/script/interpreter.cpp +++ b/rootex/script/interpreter.cpp @@ -260,6 +260,7 @@ void LuaInterpreter::registerTypes() resourceLoader["CreateAnimatedModel"] = &ResourceLoader::CreateAnimatedModelResourceFile; resourceLoader["CreateCollisionModel"] = &ResourceLoader::CreateAnimatedModelResourceFile; resourceLoader["CreateParticleEffectResourceFile"] = &ResourceLoader::CreateParticleEffectResourceFile; + resourceLoader["CreateMaterialResourceFile"] = &ResourceLoader::CreateMaterialResourceFile; } { sol::usertype resourceFile = rootex.new_usertype("ResourceFile"); @@ -491,7 +492,7 @@ void LuaInterpreter::registerTypes() transformComponent["getPosition"] = &TransformComponent::getPosition; transformComponent["setPosition"] = &TransformComponent::setPosition; - + transformComponent["getScale"] = &TransformComponent::getScale; transformComponent["setScale"] = &TransformComponent::setScale; @@ -521,6 +522,8 @@ void LuaInterpreter::registerTypes() "ModelComponent", sol::base_classes, sol::bases()); modelComponent["getModelResourceFile"] = &ModelComponent::getModelResourceFile; + modelComponent["setMaterialOverride"] = &RenderableComponent::setMaterialOverride; + modelComponent["getMaterialOverride"] = &RenderableComponent::getMaterialOverride; } { sol::usertype animatedModelComponent = rootex.new_usertype( @@ -620,6 +623,8 @@ void LuaInterpreter::registerTypes() rigidBodyComponent["applyTorque"] = &RigidBodyComponent::applyTorque; rigidBodyComponent["setAxisLock"] = &RigidBodyComponent::setAxisLock; rigidBodyComponent["translate"] = &RigidBodyComponent::translate; + + rigidBodyComponent["update"] = &RigidBodyComponent::updateTransform; } { sol::usertype bcc = rootex.new_usertype(