From 37a36a8155adb00914c0ef28ede7260cd8677d66 Mon Sep 17 00:00:00 2001 From: Mitch Andrews Date: Sun, 16 Jul 2023 02:49:45 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=A3=20Couple=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed mouse input and position in the UI Fixed physics updating Fixed textures not loading if their raw counterpart didn't exist ME_HARDSTUCK for disabling all copy/move constructors --- Modules/Dementia/Source/Dementia.h | 5 +- Modules/Dementia/Source/Math/Vector2.h | 5 + .../Havana/Source/Widgets/SceneViewWidget.cpp | 19 +++- Modules/Moonlight/Source/Graphics/Texture.cpp | 6 +- Source/Components/Physics/Rigidbody.h | 1 + Source/Components/Transform.h | 5 +- Source/Cores/PhysicsCore.cpp | 29 +++-- Source/Cores/UI/UICore.cpp | 104 +++++++++--------- Source/ECS/ComponentStorage.h | 3 +- Source/ECS/EntityIdPool.h | 3 +- Source/Engine/World.h | 4 +- Source/Game.h | 49 ++++----- 12 files changed, 125 insertions(+), 108 deletions(-) diff --git a/Modules/Dementia/Source/Dementia.h b/Modules/Dementia/Source/Dementia.h index 6a52e155..4fbc6708 100644 --- a/Modules/Dementia/Source/Dementia.h +++ b/Modules/Dementia/Source/Dementia.h @@ -2,9 +2,6 @@ #define forever for(;;) -#define ME_DISABLE_DEFAULT_CONSTRUCTOR(Class) \ -Class() = delete; - #define ME_DISABLE_COPY_CONSTRUCTOR(Class) \ Class(const Class&) = delete; @@ -21,6 +18,8 @@ Class& operator=(Class&&) = delete; #define ME_NONMOVABLE(Class) ME_DISABLE_MOVE_CONSTRUCTOR(Class); ME_DISABLE_MOVE_ASSIGNMENT(Class); +#define ME_HARDSTUCK(Class) ME_NONCOPYABLE(Class); ME_NONMOVABLE(Class); + #ifndef IN_USE #define IN_USE && #endif /* IN USE */ diff --git a/Modules/Dementia/Source/Math/Vector2.h b/Modules/Dementia/Source/Math/Vector2.h index 87d11072..277e8650 100644 --- a/Modules/Dementia/Source/Math/Vector2.h +++ b/Modules/Dementia/Source/Math/Vector2.h @@ -68,6 +68,11 @@ struct Vector2 return Vector2(InternalVec + other.InternalVec); } + Vector2 operator-( const Vector2& other ) + { + return Vector2( InternalVec - other.InternalVec ); + } + Vector2 operator/(const float& other) { return Vector2(InternalVec.x / other, InternalVec.y / other); diff --git a/Modules/Havana/Source/Widgets/SceneViewWidget.cpp b/Modules/Havana/Source/Widgets/SceneViewWidget.cpp index 71b3a484..c39a3ebe 100644 --- a/Modules/Havana/Source/Widgets/SceneViewWidget.cpp +++ b/Modules/Havana/Source/Widgets/SceneViewWidget.cpp @@ -15,6 +15,8 @@ #include #include "Profiling/BasicFrameProfile.h" #include "UI/Colors.h" +#include "Components/Physics/Rigidbody.h" +#include "Physics/RigidBodyWithCollisionEvents.h" #if USING( ME_EDITOR ) @@ -244,7 +246,8 @@ void SceneViewWidget::Render() SceneViewRenderLocation = Vector2(ImGui::GetCursorPos().x, ImGui::GetCursorPos().y); GizmoRenderLocation = Vector2(ImGui::GetCursorScreenPos().x, ImGui::GetCursorScreenPos().y); - Vector2 availableSpace = Vector2(ImGui::GetWindowSize().x, ImGui::GetWindowSize().y - SceneViewRenderLocation.y); + Vector2 availableSpace = Vector2( ImGui::GetWindowSize().x, ImGui::GetWindowSize().y - SceneViewRenderLocation.y ); + Vector2 heightSub = { 0.f, SceneViewRenderLocation.y }; Vector2 viewportRenderSize = availableSpace; float scale = 1.f; switch (CurrentDisplayParams.Type) @@ -313,6 +316,7 @@ void SceneViewWidget::Render() default: break; } + GetEngine().GetInput().SetMouseOffset( (GizmoRenderLocation + SceneViewRenderLocation) - heightSub ); Moonlight::FrameBuffer* currentView = (MainCamera) ? MainCamera->Buffer : nullptr; @@ -414,6 +418,19 @@ void SceneViewWidget::DrawGuizmo() { SelectedTransform.lock()->SetScale(modifiedScale); } + + EntityHandle& selectedEntity = SelectedTransform.lock()->Parent; + if ( SelectedTransform.lock()->IsDirty() && selectedEntity->HasComponent() ) + { + btTransform trans; + btRigidBodyWithEvents* rigidbody = selectedEntity->GetComponent().InternalRigidbody; + Vector3 transPos = SelectedTransform.lock()->GetWorldPosition(); + Quaternion rotation = SelectedTransform.lock()->GetRotation(); + trans.setRotation( btQuaternion( rotation.x, rotation.y, rotation.z, rotation.w ) ); + trans.setOrigin( btVector3( transPos.x, transPos.y, transPos.z ) ); + rigidbody->setWorldTransform( trans ); + rigidbody->activate(); + } } } } diff --git a/Modules/Moonlight/Source/Graphics/Texture.cpp b/Modules/Moonlight/Source/Graphics/Texture.cpp index 95b703b6..260b584b 100644 --- a/Modules/Moonlight/Source/Graphics/Texture.cpp +++ b/Modules/Moonlight/Source/Graphics/Texture.cpp @@ -46,13 +46,13 @@ namespace Moonlight void Texture::Load() { uint64_t flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_W_MIRROR; - - if (!FilePath.Exists) + Path compiledTexture( FilePath.FullPath + ".dds" ); + if (!compiledTexture.Exists) { return; } - const auto* memory = Moonlight::LoadMemory(Path(FilePath.FullPath + ".dds")); + const auto* memory = Moonlight::LoadMemory( compiledTexture ); if (memory) { if (bimg::ImageContainer* imageContainer = bimg::imageParse(Moonlight::getDefaultAllocator(), memory->data, memory->size)) diff --git a/Source/Components/Physics/Rigidbody.h b/Source/Components/Physics/Rigidbody.h index a644a680..971f713c 100644 --- a/Source/Components/Physics/Rigidbody.h +++ b/Source/Components/Physics/Rigidbody.h @@ -12,6 +12,7 @@ class Rigidbody : public Component { friend class PhysicsCore; + friend class SceneViewWidget; public: enum class ColliderType : unsigned int diff --git a/Source/Components/Transform.h b/Source/Components/Transform.h index 65648899..cd17c6b1 100644 --- a/Source/Components/Transform.h +++ b/Source/Components/Transform.h @@ -64,10 +64,9 @@ class Transform void Reset(); - ME_NONCOPYABLE( Transform ) - ME_NONMOVABLE( Transform ) + ME_HARDSTUCK( Transform ) - void SetParent( Transform& NewParent ); + void SetParent( Transform& NewParent ); void RemoveChild( Transform* TargetTransform ); Transform* GetChildByName( const std::string& inName ); const std::vector>& GetChildren() const; diff --git a/Source/Cores/PhysicsCore.cpp b/Source/Cores/PhysicsCore.cpp index 18b04679..3f4fb6a5 100644 --- a/Source/Cores/PhysicsCore.cpp +++ b/Source/Cores/PhysicsCore.cpp @@ -98,8 +98,8 @@ void PhysicsCore::Update(const UpdateContext& inUpdateContext) int batchSize = batchEnd - batchBegin; //YIKES(std::to_string(batchBegin) + " End:" + std::to_string(batchEnd) + " Size:" + std::to_string(batchSize)); - Job* root2 = pool.CreateClosureJobAsChild([this, &PhysicsEntites, batchBegin, batchEnd, batchSize, inUpdateContext](Job& job) { - OPTICK_CATEGORY("Job::UpdatePhysics", Optick::Category::Physics); + //Job* root2 = pool.CreateClosureJobAsChild([this, &PhysicsEntites, batchBegin, batchEnd, batchSize, inUpdateContext](Job& job) { + // OPTICK_CATEGORY("Job::UpdatePhysics", Optick::Category::Physics); for (int entIndex = batchBegin; entIndex < batchEnd; ++entIndex) { @@ -114,17 +114,16 @@ void PhysicsCore::Update(const UpdateContext& inUpdateContext) btRigidBody* rigidbody = RigidbodyComponent.InternalRigidbody; - - if (TransformComponent.IsDirty()) - { - btTransform trans; - Vector3 transPos = TransformComponent.GetWorldPosition(); - trans.setRotation(btQuaternion(TransformComponent.GetRotation().x, TransformComponent.GetRotation().y, TransformComponent.GetRotation().z, TransformComponent.GetRotation().w)); - trans.setOrigin(btVector3(transPos.x, transPos.y, transPos.z)); - rigidbody->setWorldTransform(trans); - rigidbody->activate(); - } - else if (RigidbodyComponent.IsDynamic()) + //if (TransformComponent.IsDirty()) + //{ + // btTransform trans; + // Vector3 transPos = TransformComponent.GetWorldPosition(); + // trans.setRotation(btQuaternion(TransformComponent.GetRotation().x, TransformComponent.GetRotation().y, TransformComponent.GetRotation().z, TransformComponent.GetRotation().w)); + // trans.setOrigin(btVector3(transPos.x, transPos.y, transPos.z)); + // rigidbody->setWorldTransform(trans); + // rigidbody->activate(); + //} + if (RigidbodyComponent.IsDynamic()) { btTransform& trans = rigidbody->getWorldTransform(); btQuaternion rot; @@ -170,9 +169,9 @@ void PhysicsCore::Update(const UpdateContext& inUpdateContext) TransformComponent.SetWorldPosition(Controller.GetPosition()); } } - }, rootJob); + //}, rootJob); - worker->Submit(root2); + //worker->Submit(root2); //GetEngine().GetJobEngine().AddWork(m_callBack); //GetEngine().GetJobEngine().Wait(); //burst.AddWork2(job, sizeof(Burst::LambdaWorkEntry)); diff --git a/Source/Cores/UI/UICore.cpp b/Source/Cores/UI/UICore.cpp index c8106c8d..39bb4287 100644 --- a/Source/Cores/UI/UICore.cpp +++ b/Source/Cores/UI/UICore.cpp @@ -31,7 +31,7 @@ UICore::UICore(IWindow* window, BGFXRenderer* renderer) config.font_family_standard = "Arial"; config.use_gpu_renderer = false; // ?????? - config.resource_path = "M:\\Projects\\C++\\stack\\Engine\\Modules\\Havana\\..\\..\\..\\Build\\Debug Editor"; + config.resource_path = "M:\\Projects\\C++\\stack\\Engine\\Modules\\Havana\\..\\..\\..\\.build\\editor_release"; //config_.cache_path = ultralight::String16(std::string(fileSystemRoot.Directory + "ultralight.log").c_str()); m_context.reset(new GPUContext()); @@ -109,57 +109,57 @@ void UICore::Update(const UpdateContext& inUpdateContext) ultralight::MouseEvent mouseEvent; mouseEvent.type = ultralight::MouseEvent::kType_MouseMoved; -// Vector2 mousePosition = GetEngine().GetInput().GetMousePosition(); -// -//#if USING( ME_EDITOR ) -// if (!static_cast(GetEngine().GetGame())->IsGameRunning()) -// { -// return; -// } -// -// Havana* editor = static_cast(GetEngine().GetWorld().lock()->GetCore(EditorCore::GetTypeId()))->GetEditor(); -// -// Vector2 windowPosition = GetEngine().GetWindow()->GetPosition(); -// -// mouseEvent.x = (windowPosition.X() + mousePosition.X()) - editor->GameViewRenderLocation.X(); -// mouseEvent.y = (windowPosition.Y() + mousePosition.Y()) - editor->GameViewRenderLocation.Y(); -// -// if (mousePosition.IsZero()) -// { -// return; -// } -//#else -// mouseEvent.x = mousePosition.X(); -// mouseEvent.y = mousePosition.Y(); -//#endif -// -// static bool hasPressed = false; -// if (GetEngine().GetInput().GetMouseState().leftButton && !hasPressed) -// { -// mouseEvent.button = ultralight::MouseEvent::Button::kButton_Left; -// mouseEvent.type = ultralight::MouseEvent::kType_MouseDown; -// hasPressed = true; -// } -// else if (!GetEngine().GetInput().GetMouseState().leftButton && hasPressed) -// { -// mouseEvent.button = ultralight::MouseEvent::Button::kButton_Left; -// mouseEvent.type = ultralight::MouseEvent::kType_MouseUp; -// hasPressed = false; -// } -// else -// { -// mouseEvent.button = ultralight::MouseEvent::Button::kButton_None; -// } -// -//#if USING( ME_EDITOR ) -// //if (m_renderer->GetViewportMode() == ViewportMode::Game) -//#endif -// { -// for (auto& view : m_overlays) -// { -// view->view()->FireMouseEvent(mouseEvent); -// } -// } + Vector2 mousePosition = GetEngine().GetInput().GetMousePosition(); + +#if USING( ME_EDITOR ) + //if ( !static_cast( GetEngine().GetGame() )->IsGameRunning() ) + //{ + // return; + //} + + //Havana* editor = static_cast( GetEngine().GetWorld().lock()->GetCore( EditorCore::GetTypeId() ) )->GetEditor(); + + Vector2 windowPosition = GetEngine().GetWindow()->GetPosition(); + Vector2 offset = GetEngine().GetInput().GetMouseOffset(); + mouseEvent.x = ( windowPosition.x + mousePosition.x ) - offset.x;// + windowPosition.x + offset.x; + mouseEvent.y = ( windowPosition.y + mousePosition.y ) - offset.y;// + windowPosition.y - offset.y; + + if ( mousePosition.IsZero() ) + { + return; + } +#else + mouseEvent.x = mousePosition.x; + mouseEvent.y = mousePosition.y; +#endif + + static bool hasPressed = false; + if (GetEngine().GetInput().WasMouseButtonPressed(MouseButton::Left) && !hasPressed ) + { + mouseEvent.button = ultralight::MouseEvent::Button::kButton_Left; + mouseEvent.type = ultralight::MouseEvent::kType_MouseDown; + hasPressed = true; + } + else if (!GetEngine().GetInput().WasMouseButtonPressed( MouseButton::Left ) && hasPressed) + { + mouseEvent.button = ultralight::MouseEvent::Button::kButton_Left; + mouseEvent.type = ultralight::MouseEvent::kType_MouseUp; + hasPressed = false; + } + else + { + mouseEvent.button = ultralight::MouseEvent::Button::kButton_None; + } + +#if USING( ME_EDITOR ) + //if (m_renderer->GetViewportMode() == ViewportMode::Game) +#endif + { + for (auto& view : m_overlays) + { + view->view()->FireMouseEvent(mouseEvent); + } + } // Update internal logic (timers, event callbacks, etc.) m_uiRenderer->Update(); diff --git a/Source/ECS/ComponentStorage.h b/Source/ECS/ComponentStorage.h index 4cd855a2..83794d49 100644 --- a/Source/ECS/ComponentStorage.h +++ b/Source/ECS/ComponentStorage.h @@ -14,8 +14,7 @@ class ComponentStorage ComponentStorage(std::size_t InEntityAmount); ~ComponentStorage(); - ME_NONCOPYABLE(ComponentStorage) - ME_NONMOVABLE(ComponentStorage) + ME_HARDSTUCK(ComponentStorage) void AddComponent(Entity& InEntity, SharedPtr InComponent, TypeId InComponentTypeId); diff --git a/Source/ECS/EntityIdPool.h b/Source/ECS/EntityIdPool.h index 9565e363..59f07ee8 100644 --- a/Source/ECS/EntityIdPool.h +++ b/Source/ECS/EntityIdPool.h @@ -8,8 +8,7 @@ class EntityIdPool public: EntityIdPool(std::size_t InPoolSize); - ME_NONCOPYABLE(EntityIdPool); - ME_NONMOVABLE(EntityIdPool); + ME_HARDSTUCK(EntityIdPool); EntityID Create(); diff --git a/Source/Engine/World.h b/Source/Engine/World.h index 464e3a43..a8e4bca0 100644 --- a/Source/Engine/World.h +++ b/Source/Engine/World.h @@ -79,8 +79,8 @@ class World World(std::size_t InEntityPoolSize); ~World(); - ME_NONCOPYABLE(World); - ME_NONMOVABLE(World); + ME_HARDSTUCK(World); + bool IsLoading = true; BaseCore* AddCoreByName(const std::string& core); std::unordered_map m_loadedCores; diff --git a/Source/Game.h b/Source/Game.h index a72ef395..2b7c32a2 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -1,4 +1,4 @@ -// 2018 Mitchell Andrews +// 2023 Mitchell Andrews #pragma once #include "Dementia.h" #include "Core/UpdateContext.h" @@ -14,11 +14,30 @@ class Game virtual void OnUpdate(const UpdateContext& inUpdateContext) = 0; virtual void OnEnd() = 0; virtual void PostRender() = 0; - ME_NONCOPYABLE(Game) - ME_NONMOVABLE(Game) + ME_HARDSTUCK(Game) }; -#ifndef __cplusplus_winrt +//#if USING( ME_PLATFORM_UWP ) +//#include "SDL.h" +//#include "SDL_video.h" +//#include "SDL_main.h" +//#include +//#define ME_APPLICATION_MAIN(className) \ +// int _main(int argc, char** argv) { \ +// className app(argc, argv); \ +// GetEngine().Init(&app); \ +// GetEngine().Run(); \ +// return 0; \ +// } \ +// __pragma(warning(push)) \ +// __pragma(warning(disable: 4447)) \ +// int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { \ +// if(FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) \ +// return 1; \ +// return SDL_WinRTRunApp(_main, nullptr); \ +// } \ +// __pragma(warning(pop)) +//#else #define ME_APPLICATION_MAIN(className) \ int main(int argc, char** argv) { \ className app(argc, argv); \ @@ -26,24 +45,4 @@ class Game GetEngine().Run(); \ return 0; \ } -#else -#include "SDL.h" -#include "SDL_video.h" -#include "SDL_main.h" -#include -#define ME_APPLICATION_MAIN(className) \ - int _main(int argc, char** argv) { \ - className app(argc, argv); \ - GetEngine().Init(&app); \ - GetEngine().Run(); \ - return 0; \ - } \ - __pragma(warning(push)) \ - __pragma(warning(disable: 4447)) \ - int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { \ - if(FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) \ - return 1; \ - return SDL_WinRTRunApp(_main, nullptr); \ - } \ - __pragma(warning(pop)) -#endif +//#endif