Skip to content

Commit

Permalink
🥣 Couple fixes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wobbier committed Jul 16, 2023
1 parent c466c66 commit 37a36a8
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 108 deletions.
5 changes: 2 additions & 3 deletions Modules/Dementia/Source/Dementia.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 */
Expand Down
5 changes: 5 additions & 0 deletions Modules/Dementia/Source/Math/Vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion Modules/Havana/Source/Widgets/SceneViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <Cores/UI/UICore.h>
#include "Profiling/BasicFrameProfile.h"
#include "UI/Colors.h"
#include "Components/Physics/Rigidbody.h"
#include "Physics/RigidBodyWithCollisionEvents.h"

#if USING( ME_EDITOR )

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -313,6 +316,7 @@ void SceneViewWidget::Render()
default:
break;
}
GetEngine().GetInput().SetMouseOffset( (GizmoRenderLocation + SceneViewRenderLocation) - heightSub );

Moonlight::FrameBuffer* currentView = (MainCamera) ? MainCamera->Buffer : nullptr;

Expand Down Expand Up @@ -414,6 +418,19 @@ void SceneViewWidget::DrawGuizmo()
{
SelectedTransform.lock()->SetScale(modifiedScale);
}

EntityHandle& selectedEntity = SelectedTransform.lock()->Parent;
if ( SelectedTransform.lock()->IsDirty() && selectedEntity->HasComponent<Rigidbody>() )
{
btTransform trans;
btRigidBodyWithEvents* rigidbody = selectedEntity->GetComponent<Rigidbody>().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();
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Moonlight/Source/Graphics/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions Source/Components/Physics/Rigidbody.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Rigidbody
: public Component<Rigidbody>
{
friend class PhysicsCore;
friend class SceneViewWidget;
public:

enum class ColliderType : unsigned int
Expand Down
5 changes: 2 additions & 3 deletions Source/Components/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SharedPtr<Transform>>& GetChildren() const;
Expand Down
29 changes: 14 additions & 15 deletions Source/Cores/PhysicsCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
104 changes: 52 additions & 52 deletions Source/Cores/UI/UICore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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<EditorApp*>(GetEngine().GetGame())->IsGameRunning())
// {
// return;
// }
//
// Havana* editor = static_cast<EditorCore*>(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<EditorApp*>( GetEngine().GetGame() )->IsGameRunning() )
//{
// return;
//}

//Havana* editor = static_cast<EditorCore*>( 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();
Expand Down
3 changes: 1 addition & 2 deletions Source/ECS/ComponentStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<BaseComponent> InComponent, TypeId InComponentTypeId);

Expand Down
3 changes: 1 addition & 2 deletions Source/ECS/EntityIdPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class EntityIdPool
public:
EntityIdPool(std::size_t InPoolSize);

ME_NONCOPYABLE(EntityIdPool);
ME_NONMOVABLE(EntityIdPool);
ME_HARDSTUCK(EntityIdPool);

EntityID Create();

Expand Down
4 changes: 2 additions & 2 deletions Source/Engine/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeId, BaseCore*> m_loadedCores;
Expand Down
49 changes: 24 additions & 25 deletions Source/Game.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 2018 Mitchell Andrews
// 2023 Mitchell Andrews
#pragma once
#include "Dementia.h"
#include "Core/UpdateContext.h"
Expand All @@ -14,36 +14,35 @@ 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 <wrl.h>
//#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); \
GetEngine().Init(&app); \
GetEngine().Run(); \
return 0; \
}
#else
#include "SDL.h"
#include "SDL_video.h"
#include "SDL_main.h"
#include <wrl.h>
#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

0 comments on commit 37a36a8

Please sign in to comment.