Compare commits
5 Commits
9447453e47
...
37c17bdb5c
| Author | SHA1 | Date | |
|---|---|---|---|
| 37c17bdb5c | |||
| fadb73243d | |||
| ab4ca6285e | |||
| 52463322dd | |||
| 0a24a2f3c7 |
@ -7,6 +7,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "Core.h"
|
#include "Core.h"
|
||||||
|
#include "KeyCodes.h"
|
||||||
|
|
||||||
namespace Hazel
|
namespace Hazel
|
||||||
{
|
{
|
||||||
@ -14,9 +15,9 @@ namespace Hazel
|
|||||||
public:
|
public:
|
||||||
virtual ~Input() = default;
|
virtual ~Input() = default;
|
||||||
|
|
||||||
static bool IsKeyPressed(int key);
|
static bool IsKeyPressed(KeyCode key);
|
||||||
|
|
||||||
static bool IsMouseButtonPressed(int button);
|
static bool IsMouseButtonPressed(MouseButton button);
|
||||||
static std::pair<float, float> GetMousePosition();
|
static std::pair<float, float> GetMousePosition();
|
||||||
|
|
||||||
static float GetMouseX();
|
static float GetMouseX();
|
||||||
|
|||||||
5
Hazel/src/Hazel/Core/KeyCodes.cpp
Normal file
5
Hazel/src/Hazel/Core/KeyCodes.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-6-27.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "KeyCodes.h"
|
||||||
28
Hazel/src/Hazel/Core/KeyCodes.h
Normal file
28
Hazel/src/Hazel/Core/KeyCodes.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-6-27.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef KEYCODES_H
|
||||||
|
#define KEYCODES_H
|
||||||
|
#include <SDL3/SDL_keycode.h>
|
||||||
|
#include <SDL3/SDL_mouse.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Hazel
|
||||||
|
{
|
||||||
|
using KeyCode = SDL_Scancode;
|
||||||
|
|
||||||
|
typedef enum MouseButton
|
||||||
|
{
|
||||||
|
BUTTON_LEFT = SDL_BUTTON_LEFT,
|
||||||
|
BUTTON_MIDDLE = SDL_BUTTON_MIDDLE,
|
||||||
|
BUTTON_RIGHT = SDL_BUTTON_RIGHT,
|
||||||
|
BUTTON_X1 = SDL_BUTTON_X1,
|
||||||
|
BUTTON_X2 = SDL_BUTTON_X2,
|
||||||
|
}MouseButton;
|
||||||
|
|
||||||
|
//TODO: use self keycode, not use sdl directly
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //KEYCODES_H
|
||||||
@ -70,11 +70,11 @@ namespace Hazel
|
|||||||
const glm::vec2 delta = (mouse - m_InitialMousePosition) * 0.003f;
|
const glm::vec2 delta = (mouse - m_InitialMousePosition) * 0.003f;
|
||||||
m_InitialMousePosition = mouse;
|
m_InitialMousePosition = mouse;
|
||||||
|
|
||||||
if (Input::IsMouseButtonPressed(SDL_BUTTON_MIDDLE))
|
if (Input::IsMouseButtonPressed(BUTTON_MIDDLE))
|
||||||
MousePan(delta);
|
MousePan(delta);
|
||||||
else if (Input::IsMouseButtonPressed(SDL_BUTTON_LEFT))
|
else if (Input::IsMouseButtonPressed(BUTTON_LEFT))
|
||||||
MouseRotate(delta);
|
MouseRotate(delta);
|
||||||
else if (Input::IsMouseButtonPressed(SDL_BUTTON_RIGHT))
|
else if (Input::IsMouseButtonPressed(BUTTON_RIGHT))
|
||||||
MouseZoom(-delta.y);
|
MouseZoom(-delta.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ namespace Hazel
|
|||||||
m_Distance -= delta * ZoomSpeed();
|
m_Distance -= delta * ZoomSpeed();
|
||||||
if (m_Distance < 1.0f)
|
if (m_Distance < 1.0f)
|
||||||
{
|
{
|
||||||
m_FocalPoint += GetForwardDirection();
|
// m_FocalPoint += GetForwardDirection();
|
||||||
m_Distance = 1.0f;
|
m_Distance = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -159,6 +159,16 @@ namespace Hazel
|
|||||||
CircleCollider2DComponent() = default;
|
CircleCollider2DComponent() = default;
|
||||||
CircleCollider2DComponent(const CircleCollider2DComponent&) = default;
|
CircleCollider2DComponent(const CircleCollider2DComponent&) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename... Components>
|
||||||
|
struct ComponentGroup
|
||||||
|
{
|
||||||
|
};
|
||||||
|
using AllComponents =
|
||||||
|
ComponentGroup<TransformComponent, SpriteRendererComponent,
|
||||||
|
CircleRendererComponent, BoxCollider2DComponent,
|
||||||
|
CircleCollider2DComponent, CameraComponent,
|
||||||
|
NativeScriptComponent, RigidBody2DComponent>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@ namespace Hazel
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
T& AddOrRelpaceComponent(Args&&... args)
|
T& AddOrReplaceComponent(Args&&... args)
|
||||||
{
|
{
|
||||||
T& component = m_Scene->m_Registry.emplace_or_replace<T>(m_EntityHandle, std::forward<Args>(args)...);
|
T& component = m_Scene->m_Registry.emplace_or_replace<T>(m_EntityHandle, std::forward<Args>(args)...);
|
||||||
m_Scene->OnComponentAdded<T>(*this, component);
|
m_Scene->OnComponentAdded<T>(*this, component);
|
||||||
|
|||||||
@ -40,31 +40,42 @@ namespace Hazel
|
|||||||
delete m_PhysicsWorld;
|
delete m_PhysicsWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Component>
|
template<typename... Component>
|
||||||
static void CopyComponent(entt::registry& dst, entt::registry& src, const std::unordered_map<UUID, entt::entity>& enttMap)
|
static void CopyComponent(entt::registry& dst, entt::registry& src, const std::unordered_map<UUID, entt::entity>& enttMap)
|
||||||
|
{
|
||||||
|
|
||||||
|
([&]()
|
||||||
{
|
{
|
||||||
auto view = src.view<Component>();
|
auto view = src.view<Component>();
|
||||||
for (auto e : view)
|
for (auto srcEntity : view)
|
||||||
{
|
{
|
||||||
UUID uuid = src.get<IDComponent>(e).ID;
|
entt::entity dstEntity = enttMap.at(src.get<IDComponent>(srcEntity).ID);
|
||||||
if (enttMap.find(uuid) == enttMap.end())
|
|
||||||
|
auto& srcComponent = src.get<Component>(srcEntity);
|
||||||
|
dst.emplace_or_replace<Component>(dstEntity, srcComponent);
|
||||||
|
}
|
||||||
|
}(), ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Component>
|
||||||
|
static void CopyComponent(ComponentGroup<Component ...>, entt::registry& dst, entt::registry& src, const std::unordered_map<UUID, entt::entity>& enttMap)
|
||||||
{
|
{
|
||||||
HZ_CORE_ERROR("ERROR");
|
CopyComponent<Component ...>(dst, src, enttMap);
|
||||||
assert(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entt::entity entity = enttMap.at(uuid);
|
template<typename... Component>
|
||||||
auto& component = view.get<Component>(e);
|
|
||||||
|
|
||||||
dst.emplace_or_replace<Component>(entity, component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Component>
|
|
||||||
static void CopyComponentIfExists(Entity dst, Entity src)
|
static void CopyComponentIfExists(Entity dst, Entity src)
|
||||||
{
|
{
|
||||||
|
([&](){
|
||||||
if (src.HasComponent<Component>())
|
if (src.HasComponent<Component>())
|
||||||
dst.AddOrRelpaceComponent<Component>(src.GetComponent<Component>());
|
dst.AddOrReplaceComponent<Component>(src.GetComponent<Component>());
|
||||||
|
}(), ...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Component>
|
||||||
|
static void CopyComponentIfExists(ComponentGroup<Component ...>, Entity dst, Entity src)
|
||||||
|
{
|
||||||
|
CopyComponentIfExists<Component ...>(dst, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Scene> Scene::Copy(Ref<Scene> other)
|
Ref<Scene> Scene::Copy(Ref<Scene> other)
|
||||||
@ -89,6 +100,9 @@ namespace Hazel
|
|||||||
enttMap[uuid] = (entt::entity)newEntity;
|
enttMap[uuid] = (entt::entity)newEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy all components except IDComponent and TagComponent
|
||||||
|
CopyComponent(AllComponents{}, dstSceneRegistry, srcSceneRegistry, enttMap);
|
||||||
|
/*
|
||||||
CopyComponent<TransformComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
CopyComponent<TransformComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
||||||
CopyComponent<SpriteRendererComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
CopyComponent<SpriteRendererComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
||||||
CopyComponent<CircleRendererComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
CopyComponent<CircleRendererComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
||||||
@ -97,6 +111,7 @@ namespace Hazel
|
|||||||
CopyComponent<RigidBody2DComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
CopyComponent<RigidBody2DComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
||||||
CopyComponent<BoxCollider2DComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
CopyComponent<BoxCollider2DComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
||||||
CopyComponent<CircleCollider2DComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
CopyComponent<CircleCollider2DComponent>(dstSceneRegistry, srcSceneRegistry, enttMap);
|
||||||
|
*/
|
||||||
|
|
||||||
return newScene;
|
return newScene;
|
||||||
}
|
}
|
||||||
@ -388,6 +403,8 @@ namespace Hazel
|
|||||||
{
|
{
|
||||||
Entity newEntity = CreateEntity(entity.GetName() + " copy");
|
Entity newEntity = CreateEntity(entity.GetName() + " copy");
|
||||||
|
|
||||||
|
CopyComponentIfExists(AllComponents{}, newEntity, entity);
|
||||||
|
/*
|
||||||
CopyComponentIfExists<TransformComponent>(newEntity, entity);
|
CopyComponentIfExists<TransformComponent>(newEntity, entity);
|
||||||
CopyComponentIfExists<SpriteRendererComponent>(newEntity, entity);
|
CopyComponentIfExists<SpriteRendererComponent>(newEntity, entity);
|
||||||
CopyComponentIfExists<CircleRendererComponent>(newEntity, entity);
|
CopyComponentIfExists<CircleRendererComponent>(newEntity, entity);
|
||||||
@ -396,6 +413,7 @@ namespace Hazel
|
|||||||
CopyComponentIfExists<RigidBody2DComponent>(newEntity, entity);
|
CopyComponentIfExists<RigidBody2DComponent>(newEntity, entity);
|
||||||
CopyComponentIfExists<BoxCollider2DComponent>(newEntity, entity);
|
CopyComponentIfExists<BoxCollider2DComponent>(newEntity, entity);
|
||||||
CopyComponentIfExists<CircleCollider2DComponent>(newEntity, entity);
|
CopyComponentIfExists<CircleCollider2DComponent>(newEntity, entity);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity Scene::GetPrimaryCameraEntity()
|
Entity Scene::GetPrimaryCameraEntity()
|
||||||
|
|||||||
@ -8,14 +8,14 @@
|
|||||||
|
|
||||||
namespace Hazel
|
namespace Hazel
|
||||||
{
|
{
|
||||||
bool Input::IsKeyPressed(const int key)
|
bool Input::IsKeyPressed(const KeyCode key)
|
||||||
{
|
{
|
||||||
const auto state = SDL_GetKeyboardState(nullptr);
|
const auto state = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
return state[key];
|
return state[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Input::IsMouseButtonPressed(const int button)
|
bool Input::IsMouseButtonPressed(const MouseButton button)
|
||||||
{
|
{
|
||||||
const auto mod = SDL_GetMouseState(nullptr, nullptr);
|
const auto mod = SDL_GetMouseState(nullptr, nullptr);
|
||||||
return mod & SDL_BUTTON_MASK(button);
|
return mod & SDL_BUTTON_MASK(button);
|
||||||
|
|||||||
@ -146,7 +146,6 @@ namespace Hazel
|
|||||||
if (m_ShowPhysicsColliders)
|
if (m_ShowPhysicsColliders)
|
||||||
{
|
{
|
||||||
// box collider
|
// box collider
|
||||||
|
|
||||||
auto bcview = m_ActiveScene->GetAllEntitiesWith<TransformComponent, BoxCollider2DComponent>();
|
auto bcview = m_ActiveScene->GetAllEntitiesWith<TransformComponent, BoxCollider2DComponent>();
|
||||||
for (auto entity : bcview)
|
for (auto entity : bcview)
|
||||||
{
|
{
|
||||||
@ -169,7 +168,7 @@ namespace Hazel
|
|||||||
Renderer2D::DrawRect(transform, glm::vec4(0.2f, 1.0f, 0.2f, 1.0f));
|
Renderer2D::DrawRect(transform, glm::vec4(0.2f, 1.0f, 0.2f, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// circle collider
|
||||||
auto ccview = m_ActiveScene->GetAllEntitiesWith<TransformComponent, CircleCollider2DComponent>();
|
auto ccview = m_ActiveScene->GetAllEntitiesWith<TransformComponent, CircleCollider2DComponent>();
|
||||||
for (auto entity : ccview)
|
for (auto entity : ccview)
|
||||||
{
|
{
|
||||||
@ -562,7 +561,7 @@ namespace Hazel
|
|||||||
m_CameraController.OnEvent(e);
|
m_CameraController.OnEvent(e);
|
||||||
m_EditorCamera.OnEvent(e);
|
m_EditorCamera.OnEvent(e);
|
||||||
}
|
}
|
||||||
if (e.button.clicks && m_ViewportHovered && !ImGuizmo::IsOver() && Input::IsMouseButtonPressed(SDL_BUTTON_LEFT) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
|
if (e.button.clicks && m_ViewportHovered && !ImGuizmo::IsOver() && Input::IsMouseButtonPressed(BUTTON_LEFT) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
|
||||||
m_SceneHierachyPanel.SetSelectedEntity(m_HoveredEntity);
|
m_SceneHierachyPanel.SetSelectedEntity(m_HoveredEntity);
|
||||||
|
|
||||||
#define SHORTCUT_EXIT (SDL_KMOD_CTRL + SDLK_W)
|
#define SHORTCUT_EXIT (SDL_KMOD_CTRL + SDLK_W)
|
||||||
|
|||||||
Reference in New Issue
Block a user