Compare commits
16 Commits
37c17bdb5c
...
02c7e0fcf9
| Author | SHA1 | Date | |
|---|---|---|---|
| 02c7e0fcf9 | |||
| dd0e9b678c | |||
| d08285b62b | |||
| 8436331a7a | |||
| 6d76832c1d | |||
| aff8d1531c | |||
| 365134ce77 | |||
| 448c162705 | |||
| 71a5a994ff | |||
| 7ec76e23d5 | |||
| b1afcc4166 | |||
| 77f3945ae9 | |||
| f2422abfeb | |||
| 7c5511aa43 | |||
| 9a1700ebf8 | |||
| c17527e3b9 |
@ -1,6 +1,7 @@
|
||||
|
||||
#include "Hazel/Core/Application.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <Hazel/Debug/Instrumentor.h>
|
||||
#include <SDL3/SDL.h>
|
||||
@ -14,17 +15,19 @@ namespace Hazel {
|
||||
Application* Application::s_Instance = nullptr;
|
||||
|
||||
|
||||
Application::Application(const std::string& name, int width, int height)
|
||||
Application::Application(const ApplicationSpecification& specification)
|
||||
: m_Specification(specification)
|
||||
{
|
||||
HZ_PROFILE_FUNCTION();
|
||||
|
||||
if (s_Instance != nullptr)
|
||||
{
|
||||
HZ_CORE_ERROR("Application already exists!");
|
||||
}
|
||||
s_Instance = this;
|
||||
|
||||
m_Window = Window::Create(WindowProps(name, width, height));
|
||||
if (!m_Specification.workingDirectory.empty())
|
||||
std::filesystem::current_path(m_Specification.workingDirectory);
|
||||
|
||||
m_Window = Window::Create(WindowProps(m_Specification.name));
|
||||
m_Window->SetEventCallback(std::bind(&Application::OnEvent, this, std::placeholders::_1));
|
||||
m_Window->SetWindowResizeEventCallback(std::bind(&Application::OnWindowResize, this, std::placeholders::_1));
|
||||
|
||||
|
||||
@ -5,15 +5,37 @@
|
||||
#include "Core.h"
|
||||
#include "Layer.h"
|
||||
#include "LayerStack.h"
|
||||
#include "Log.h"
|
||||
#include "Hazel/Core/TimeStep.h"
|
||||
#include "Hazel/ImGui/ImGuiLayer.h"
|
||||
|
||||
namespace Hazel {
|
||||
|
||||
struct ApplicationCommandLineArgs
|
||||
{
|
||||
int count = 0;
|
||||
char** args = nullptr;
|
||||
|
||||
const char* operator[](int index)
|
||||
{
|
||||
if (index >= count)
|
||||
HZ_CORE_ERROR("args error");
|
||||
return args[count];
|
||||
}
|
||||
};
|
||||
|
||||
struct ApplicationSpecification
|
||||
{
|
||||
std::string name = "Application";
|
||||
std::string workingDirectory;
|
||||
ApplicationCommandLineArgs commandLineArgs;
|
||||
|
||||
};
|
||||
|
||||
class HAZEL_API Application
|
||||
{
|
||||
public:
|
||||
Application(const std::string& name = "Hazel App", int width = 1280, int height = 720);
|
||||
Application(const ApplicationSpecification& specification);
|
||||
virtual ~Application();
|
||||
|
||||
void Run();
|
||||
@ -30,7 +52,10 @@ namespace Hazel {
|
||||
inline Window& GetWindow() const { return *m_Window; }
|
||||
inline static Application& Get() { return *s_Instance; }
|
||||
|
||||
const ApplicationSpecification& GetSpecification() const { return m_Specification; }
|
||||
|
||||
private:
|
||||
ApplicationSpecification m_Specification;
|
||||
Scope<Window> m_Window;
|
||||
ImGuiLayer* m_imguiLayer;
|
||||
bool m_Running = true;
|
||||
@ -46,6 +71,6 @@ namespace Hazel {
|
||||
};
|
||||
|
||||
// to be defined int CLIENT
|
||||
Application* CreateApplication();
|
||||
Application* CreateApplication(ApplicationCommandLineArgs args);
|
||||
|
||||
}
|
||||
|
||||
@ -5,14 +5,14 @@
|
||||
|
||||
#include <SDL3/SDL_main.h>
|
||||
|
||||
extern Hazel::Application* Hazel::CreateApplication();
|
||||
extern Hazel::Application* Hazel::CreateApplication(ApplicationCommandLineArgs args);
|
||||
|
||||
|
||||
int main(int, char**) {
|
||||
int main(int argc, char** argv) {
|
||||
Hazel::Log::init();
|
||||
|
||||
HZ_PROFILE_BEGIN_SESSION("Start", "Start.json");
|
||||
const auto app = Hazel::CreateApplication();
|
||||
const auto app = Hazel::CreateApplication({argc, argv});
|
||||
HZ_PROFILE_END_SESSION();
|
||||
|
||||
HZ_PROFILE_BEGIN_SESSION("Update", "Update.json");
|
||||
|
||||
@ -10,9 +10,9 @@
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
using KeyCode = SDL_Scancode;
|
||||
// using KeyCode = SDL_Scancode;
|
||||
|
||||
typedef enum MouseButton
|
||||
typedef enum class MouseButton
|
||||
{
|
||||
BUTTON_LEFT = SDL_BUTTON_LEFT,
|
||||
BUTTON_MIDDLE = SDL_BUTTON_MIDDLE,
|
||||
@ -22,6 +22,295 @@ namespace Hazel
|
||||
}MouseButton;
|
||||
|
||||
//TODO: use self keycode, not use sdl directly
|
||||
|
||||
typedef enum class KeyCode
|
||||
{
|
||||
A = 4,
|
||||
B = 5,
|
||||
C = 6,
|
||||
D = 7,
|
||||
E = 8,
|
||||
F = 9,
|
||||
G = 10,
|
||||
H = 11,
|
||||
I = 12,
|
||||
J = 13,
|
||||
K = 14,
|
||||
L = 15,
|
||||
M = 16,
|
||||
N = 17,
|
||||
O = 18,
|
||||
P = 19,
|
||||
Q = 20,
|
||||
R = 21,
|
||||
S = 22,
|
||||
T = 23,
|
||||
U = 24,
|
||||
V = 25,
|
||||
W = 26,
|
||||
X = 27,
|
||||
Y = 28,
|
||||
Z = 29,
|
||||
|
||||
NUM1 = 30,
|
||||
NUM2 = 31,
|
||||
NUM3 = 32,
|
||||
NUM4 = 33,
|
||||
NUM5 = 34,
|
||||
NUM6 = 35,
|
||||
NUM7 = 36,
|
||||
NUM8 = 37,
|
||||
NUM9 = 38,
|
||||
NUM0 = 39,
|
||||
|
||||
RETURN = 40,
|
||||
ESCAPE = 41,
|
||||
BACKSPACE = 42,
|
||||
TAB = 43,
|
||||
SPACE = 44,
|
||||
|
||||
MINUS = 45,
|
||||
EQUALS = 46,
|
||||
LEFTBRACKET = 47,
|
||||
RIGHTBRACKET = 48,
|
||||
BACKSLASH = 49,
|
||||
|
||||
NONUSHASH = 50,
|
||||
|
||||
SEMICOLON = 51,
|
||||
APOSTROPHE = 52,
|
||||
GRAVE = 53,
|
||||
|
||||
|
||||
COMMA = 54,
|
||||
PERIOD = 55,
|
||||
SLASH = 56,
|
||||
|
||||
CAPSLOCK = 57,
|
||||
|
||||
F1 = 58,
|
||||
F2 = 59,
|
||||
F3 = 60,
|
||||
F4 = 61,
|
||||
F5 = 62,
|
||||
F6 = 63,
|
||||
F7 = 64,
|
||||
F8 = 65,
|
||||
F9 = 66,
|
||||
F10 = 67,
|
||||
F11 = 68,
|
||||
F12 = 69,
|
||||
|
||||
PRINTSCREEN = 70,
|
||||
SCROLLLOCK = 71,
|
||||
PAUSE = 72,
|
||||
INSERT = 73,
|
||||
|
||||
HOME = 74,
|
||||
PAGEUP = 75,
|
||||
DELETE = 76,
|
||||
END = 77,
|
||||
PAGEDOWN = 78,
|
||||
RIGHT = 79,
|
||||
LEFT = 80,
|
||||
DOWN = 81,
|
||||
UP = 82,
|
||||
|
||||
NUMLOCKCLEAR = 83,
|
||||
|
||||
KP_DIVIDE = 84,
|
||||
KP_MULTIPLY = 85,
|
||||
KP_MINUS = 86,
|
||||
KP_PLUS = 87,
|
||||
KP_ENTER = 88,
|
||||
KP_1 = 89,
|
||||
KP_2 = 90,
|
||||
KP_3 = 91,
|
||||
KP_4 = 92,
|
||||
KP_5 = 93,
|
||||
KP_6 = 94,
|
||||
KP_7 = 95,
|
||||
KP_8 = 96,
|
||||
KP_9 = 97,
|
||||
KP_0 = 98,
|
||||
KP_PERIOD = 99,
|
||||
|
||||
NONUSBACKSLASH = 100,
|
||||
|
||||
|
||||
APPLICATION = 101,
|
||||
POWER = 102,
|
||||
|
||||
KP_EQUALS = 103,
|
||||
F13 = 104,
|
||||
F14 = 105,
|
||||
F15 = 106,
|
||||
F16 = 107,
|
||||
F17 = 108,
|
||||
F18 = 109,
|
||||
F19 = 110,
|
||||
F20 = 111,
|
||||
F21 = 112,
|
||||
F22 = 113,
|
||||
F23 = 114,
|
||||
F24 = 115,
|
||||
EXECUTE = 116,
|
||||
HELP = 117,
|
||||
MENU = 118,
|
||||
SELECT = 119,
|
||||
STOP = 120,
|
||||
AGAIN = 121,
|
||||
UNDO = 122,
|
||||
CUT = 123,
|
||||
COPY = 124,
|
||||
PASTE = 125,
|
||||
FIND = 126,
|
||||
MUTE = 127,
|
||||
VOLUMEUP = 128,
|
||||
VOLUMEDOWN = 129,
|
||||
DE_LOCKINGCAPSLOCK = 130,
|
||||
DE_LOCKINGNUMLOCK = 131,
|
||||
DE_LOCKINGSCROLLLOCK = 132,
|
||||
KP_COMMA = 133,
|
||||
KP_EQUALSAS400 = 134,
|
||||
|
||||
INTERNATIONAL1 = 135,
|
||||
|
||||
INTERNATIONAL2 = 136,
|
||||
INTERNATIONAL3 = 137,
|
||||
INTERNATIONAL4 = 138,
|
||||
INTERNATIONAL5 = 139,
|
||||
INTERNATIONAL6 = 140,
|
||||
INTERNATIONAL7 = 141,
|
||||
INTERNATIONAL8 = 142,
|
||||
INTERNATIONAL9 = 143,
|
||||
LANG1 = 144,
|
||||
LANG2 = 145,
|
||||
LANG3 = 146,
|
||||
LANG4 = 147,
|
||||
LANG5 = 148,
|
||||
LANG6 = 149,
|
||||
LANG7 = 150,
|
||||
LANG8 = 151,
|
||||
LANG9 = 152,
|
||||
|
||||
ALTERASE = 153,
|
||||
SYSREQ = 154,
|
||||
CANCEL = 155,
|
||||
CLEAR = 156,
|
||||
PRIOR = 157,
|
||||
RETURN2 = 158,
|
||||
SEPARATOR = 159,
|
||||
OUT = 160,
|
||||
OPER = 161,
|
||||
CLEARAGAIN = 162,
|
||||
CRSEL = 163,
|
||||
EXSEL = 164,
|
||||
|
||||
KP_00 = 176,
|
||||
KP_000 = 177,
|
||||
THOUSANDSSEPARATOR = 178,
|
||||
DECIMALSEPARATOR = 179,
|
||||
CURRENCYUNIT = 180,
|
||||
CURRENCYSUBUNIT = 181,
|
||||
KP_LEFTPAREN = 182,
|
||||
KP_RIGHTPAREN = 183,
|
||||
KP_LEFTBRACE = 184,
|
||||
KP_RIGHTBRACE = 185,
|
||||
KP_TAB = 186,
|
||||
KP_BACKSPACE = 187,
|
||||
KP_A = 188,
|
||||
KP_B = 189,
|
||||
KP_C = 190,
|
||||
KP_D = 191,
|
||||
KP_E = 192,
|
||||
KP_F = 193,
|
||||
KP_XOR = 194,
|
||||
KP_POWER = 195,
|
||||
KP_PERCENT = 196,
|
||||
KP_LESS = 197,
|
||||
KP_GREATER = 198,
|
||||
KP_AMPERSAND = 199,
|
||||
KP_DBLAMPERSAND = 200,
|
||||
KP_VERTICALBAR = 201,
|
||||
KP_DBLVERTICALBAR = 202,
|
||||
KP_COLON = 203,
|
||||
KP_HASH = 204,
|
||||
KP_SPACE = 205,
|
||||
KP_AT = 206,
|
||||
KP_EXCLAM = 207,
|
||||
KP_MEMSTORE = 208,
|
||||
KP_MEMRECALL = 209,
|
||||
KP_MEMCLEAR = 210,
|
||||
KP_MEMADD = 211,
|
||||
KP_MEMSUBTRACT = 212,
|
||||
KP_MEMMULTIPLY = 213,
|
||||
KP_MEMDIVIDE = 214,
|
||||
KP_PLUSMINUS = 215,
|
||||
KP_CLEAR = 216,
|
||||
KP_CLEARENTRY = 217,
|
||||
KP_BINARY = 218,
|
||||
KP_OCTAL = 219,
|
||||
KP_DECIMAL = 220,
|
||||
KP_HEXADECIMAL = 221,
|
||||
|
||||
LCTRL = 224,
|
||||
LSHIFT = 225,
|
||||
LALT = 226,
|
||||
LGUI = 227,
|
||||
RCTRL = 228,
|
||||
RSHIFT = 229,
|
||||
RALT = 230,
|
||||
RGUI = 231,
|
||||
|
||||
MODE = 257,
|
||||
|
||||
SLEEP = 258,
|
||||
WAKE = 259,
|
||||
|
||||
CHANNEL_INCREMENT = 260,
|
||||
CHANNEL_DECREMENT = 261,
|
||||
|
||||
MEDIA_PLAY = 262,
|
||||
MEDIA_PAUSE = 263,
|
||||
MEDIA_RECORD = 264,
|
||||
MEDIA_FAST_FORWARD = 265,
|
||||
MEDIA_REWIND = 266,
|
||||
MEDIA_NEXT_TRACK = 267,
|
||||
MEDIA_PREVIOUS_TRACK = 268,
|
||||
MEDIA_STOP = 269,
|
||||
MEDIA_EJECT = 270,
|
||||
MEDIA_PLAY_PAUSE = 271,
|
||||
MEDIA_SELECT = 272,
|
||||
|
||||
AC_NEW = 273,
|
||||
AC_OPEN = 274,
|
||||
AC_CLOSE = 275,
|
||||
AC_EXIT = 276,
|
||||
AC_SAVE = 277,
|
||||
AC_PRINT = 278,
|
||||
AC_PROPERTIES = 279,
|
||||
|
||||
AC_SEARCH = 280,
|
||||
AC_HOME = 281,
|
||||
AC_BACK = 282,
|
||||
AC_FORWARD = 283,
|
||||
AC_STOP = 284,
|
||||
AC_REFRESH = 285,
|
||||
AC_BOOKMARKS = 286,
|
||||
|
||||
SOFTLEFT = 287,
|
||||
|
||||
SOFTRIGHT = 288,
|
||||
|
||||
CALL = 289,
|
||||
ENDCALL = 290,
|
||||
|
||||
RESERVED = 400, /**< 400-500 reserved for dynamic keycodes */
|
||||
|
||||
COUNT = 512 /**< not a key, just marks the number of scancodes for array bounds */
|
||||
}KeyCode;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
|
||||
#ifndef UUID_H
|
||||
#define UUID_H
|
||||
#include <xhash>
|
||||
#include "Core.h"
|
||||
|
||||
namespace Hazel
|
||||
@ -24,13 +23,14 @@ namespace Hazel
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<typename T> struct hash;
|
||||
|
||||
template<>
|
||||
struct hash<Hazel::UUID>
|
||||
{
|
||||
std::size_t operator() (const Hazel::UUID& uuid) const
|
||||
{
|
||||
return hash<uint64_t>()((uint64_t)uuid);
|
||||
return (uint64_t)uuid;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -64,17 +64,17 @@ namespace Hazel
|
||||
|
||||
void EditorCamera::OnUpdate(TimeStep ts)
|
||||
{
|
||||
if (Input::IsKeyPressed(SDL_SCANCODE_LALT))
|
||||
if (Input::IsKeyPressed(KeyCode::LALT))
|
||||
{
|
||||
const glm::vec2& mouse{ Input::GetMouseX(), Input::GetMouseY() };
|
||||
const glm::vec2 delta = (mouse - m_InitialMousePosition) * 0.003f;
|
||||
m_InitialMousePosition = mouse;
|
||||
|
||||
if (Input::IsMouseButtonPressed(BUTTON_MIDDLE))
|
||||
if (Input::IsMouseButtonPressed(MouseButton::BUTTON_MIDDLE))
|
||||
MousePan(delta);
|
||||
else if (Input::IsMouseButtonPressed(BUTTON_LEFT))
|
||||
else if (Input::IsMouseButtonPressed(MouseButton::BUTTON_LEFT))
|
||||
MouseRotate(delta);
|
||||
else if (Input::IsMouseButtonPressed(BUTTON_RIGHT))
|
||||
else if (Input::IsMouseButtonPressed(MouseButton::BUTTON_RIGHT))
|
||||
MouseZoom(-delta.y);
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#define TEXTURE_H
|
||||
#include <string>
|
||||
|
||||
#include <Hazel\Core/Core.h>
|
||||
#include <Hazel/Core/Core.h>
|
||||
|
||||
|
||||
namespace Hazel
|
||||
@ -18,6 +18,7 @@ namespace Hazel
|
||||
virtual const uint32_t GetWidth() const = 0;
|
||||
virtual const uint32_t GetHeight() const = 0;
|
||||
virtual const uint32_t GetRendererID() const = 0;
|
||||
virtual const std::string& GetPath() const = 0;
|
||||
|
||||
virtual void Bind(uint32_t slot = 0) const = 0;
|
||||
|
||||
|
||||
@ -220,6 +220,9 @@ namespace Hazel
|
||||
out << YAML::BeginMap; // SpriteRendererComponent
|
||||
auto& spriteRendererComponent = entity.GetComponent<SpriteRendererComponent>();
|
||||
out << YAML::Key << "Color" << YAML::Value << spriteRendererComponent.Color;
|
||||
if (spriteRendererComponent.Texture)
|
||||
out << YAML::Key << "TexturePath" << YAML::Value << spriteRendererComponent.Texture->GetPath();
|
||||
out << YAML::Key << "TilingFactor" << YAML::Value << spriteRendererComponent.TilingFactor;
|
||||
out << YAML::EndMap; // SpriteRendererComponent
|
||||
}
|
||||
|
||||
@ -295,20 +298,47 @@ namespace Hazel
|
||||
bool SceneSerializer::Deserialize(const std::string& filepath)
|
||||
{
|
||||
const std::ifstream stream(filepath);
|
||||
|
||||
if (!stream.is_open())
|
||||
{
|
||||
HZ_CORE_ERROR("Could not open file {0}", filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::stringstream strStream;
|
||||
strStream << stream.rdbuf();
|
||||
|
||||
YAML::Node data = YAML::Load(strStream.str());
|
||||
if (strStream.str().empty())
|
||||
{
|
||||
HZ_CORE_ERROR("Empty scene file: {0}", filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
YAML::Node data;
|
||||
try {
|
||||
data = YAML::Load(strStream.str());
|
||||
}
|
||||
catch (const YAML::Exception& e) {
|
||||
HZ_CORE_ERROR("YAML parsing failed: {0}\nFile: {1}", e.what(), filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data.IsNull() || !data.IsDefined() || !data.IsMap())
|
||||
{
|
||||
HZ_CORE_ERROR("YAML parsing failed: {0}", filepath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data["Scene"])
|
||||
{
|
||||
HZ_CORE_WARN("cannot find key: Scene");
|
||||
HZ_CORE_ERROR("cannot find key: Scene");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
auto sceneName = data["Scene"].as<std::string>();
|
||||
|
||||
HZ_CORE_TRACE("Deserializing Scene {}", strStream.str());
|
||||
HZ_CORE_DEBUG("Deserializing Scene {}", strStream.str());
|
||||
|
||||
auto entities = data["Entities"];
|
||||
if (entities)
|
||||
@ -360,6 +390,9 @@ namespace Hazel
|
||||
{
|
||||
auto& sprite = deserializedEntity.AddComponent<SpriteRendererComponent>();
|
||||
sprite.Color = spriteRendererComponent["Color"].as<glm::vec4>();
|
||||
sprite.TilingFactor = spriteRendererComponent["TilingFactor"].as<float>();
|
||||
if (spriteRendererComponent["TexturePath"])
|
||||
sprite.Texture = Texture2D::Create(spriteRendererComponent["TexturePath"].as<std::string>());
|
||||
}
|
||||
|
||||
auto circleRendererComponent = entity["CircleRendererComponent"];
|
||||
|
||||
@ -41,6 +41,8 @@ namespace Hazel
|
||||
if (!data)
|
||||
{
|
||||
HZ_CORE_ERROR("Failed to load texture {0}", path);
|
||||
stbi_image_free(data);
|
||||
return;
|
||||
}
|
||||
m_Width = width;
|
||||
m_Height = height;
|
||||
|
||||
@ -18,6 +18,7 @@ namespace Hazel
|
||||
|
||||
virtual const uint32_t GetWidth() const override {return m_Width; }
|
||||
virtual const uint32_t GetHeight() const override { return m_Height; }
|
||||
virtual const std::string& GetPath() const override {return m_Path; }
|
||||
|
||||
virtual void Bind(uint32_t slot = 0) const override;
|
||||
|
||||
@ -27,7 +28,7 @@ namespace Hazel
|
||||
|
||||
virtual bool operator==(const Texture& other) const override
|
||||
{
|
||||
return m_RendererID == ((OpenGLTexture2D&)other).m_RendererID;
|
||||
return m_RendererID == other.GetRendererID();
|
||||
}
|
||||
private:
|
||||
std::string m_Path;
|
||||
|
||||
@ -12,13 +12,13 @@ namespace Hazel
|
||||
{
|
||||
const auto state = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
return state[key];
|
||||
return state[(SDL_Scancode)key];
|
||||
}
|
||||
|
||||
bool Input::IsMouseButtonPressed(const MouseButton button)
|
||||
{
|
||||
const auto mod = SDL_GetMouseState(nullptr, nullptr);
|
||||
return mod & SDL_BUTTON_MASK(button);
|
||||
return mod & SDL_BUTTON_MASK((SDL_Scancode)button);
|
||||
}
|
||||
|
||||
std::pair<float, float> Input::GetMousePosition()
|
||||
|
||||
@ -60,5 +60,8 @@ void main()
|
||||
{
|
||||
o_Color = texture(u_Textures[int(v_TexIndex)], Input.TexCoord * Input.TilingFactor) * Input.Color;
|
||||
|
||||
if(o_Color.a == 0.0f)
|
||||
discard;
|
||||
|
||||
o_EntityID = v_EntityID;
|
||||
}
|
||||
|
||||
@ -51,6 +51,14 @@ namespace Hazel
|
||||
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
||||
|
||||
m_GizmoType = ImGuizmo::OPERATION::TRANSLATE;
|
||||
auto commandLineArgs = Application::Get().GetSpecification().commandLineArgs;
|
||||
if (commandLineArgs.count > 1)
|
||||
{
|
||||
auto scenePath = commandLineArgs.args[1];
|
||||
SceneSerializer sceneSerializer(m_ActiveScene);
|
||||
|
||||
sceneSerializer.Deserialize(scenePath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -151,18 +159,12 @@ namespace Hazel
|
||||
{
|
||||
auto [tc, bc2D] = bcview.get<TransformComponent, BoxCollider2DComponent>(entity);
|
||||
|
||||
|
||||
glm::mat4 model = glm::translate(glm::mat4(1.0f), tc.Translation)
|
||||
* glm::rotate(glm::mat4(1.0f), tc.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f))
|
||||
* glm::scale(glm::mat4(1.0f), tc.Scale);
|
||||
|
||||
glm::vec4 worldOffset = model * glm::vec4(bc2D.Offset.x, bc2D.Offset.y, 0.0f, 1.0f);
|
||||
// glm::vec3 translation = glm::vec3(worldOffset) + glm::vec3(0.0f, 0.0f, 0.001f);
|
||||
glm::vec3 scale = tc.Scale * glm::vec3(bc2D.Size * 2.0f, 1.0f);
|
||||
|
||||
glm::mat4 transform =
|
||||
glm::translate(glm::mat4(1.0f), glm::vec3(worldOffset))
|
||||
glm::translate(glm::mat4(1.0f), tc.Translation)
|
||||
* glm::rotate(glm::mat4(1.0f), tc.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f))
|
||||
* glm::translate(glm::mat4(1.0f), glm::vec3(bc2D.Offset, 0.0f))
|
||||
* glm::scale(glm::mat4(1.0f), scale);
|
||||
|
||||
Renderer2D::DrawRect(transform, glm::vec4(0.2f, 1.0f, 0.2f, 1.0f));
|
||||
@ -173,22 +175,29 @@ namespace Hazel
|
||||
for (auto entity : ccview)
|
||||
{
|
||||
auto [tc, cc2D] = ccview.get<TransformComponent, CircleCollider2DComponent>(entity);
|
||||
glm::mat4 model = glm::translate(glm::mat4(1.0f), tc.Translation)
|
||||
* glm::rotate(glm::mat4(1.0f), tc.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f))
|
||||
* glm::scale(glm::mat4(1.0f), tc.Scale);
|
||||
|
||||
glm::vec4 worldOffset = model * glm::vec4(cc2D.Offset.x, cc2D.Offset.y, 0.0f, 1.0f);
|
||||
// glm::vec3 translation = glm::vec3(worldOffset) + glm::vec3(0.0f, 0.0f, 0.001f);
|
||||
glm::vec3 scale = tc.Scale * glm::vec3(cc2D.Radius * 2.05f);
|
||||
|
||||
glm::mat4 transform =
|
||||
glm::translate(glm::mat4(1.0f), glm::vec3(worldOffset))
|
||||
glm::translate(glm::mat4(1.0f), tc.Translation)
|
||||
* glm::rotate(glm::mat4(1.0f), tc.Rotation.z, glm::vec3(0.0f, 0.0f, 1.0f))
|
||||
* glm::translate(glm::mat4(1.0f), glm::vec3(cc2D.Offset, 0.0f))
|
||||
* glm::scale(glm::mat4(1.0f), scale);
|
||||
|
||||
Renderer2D::DrawCircle(transform, glm::vec4(0.2, 1.0f, 0.2f, 1.0f), Renderer2D::GetLineWidth() * 0.015f);
|
||||
}
|
||||
}
|
||||
|
||||
if (Entity selectedEntity = m_SceneHierachyPanel.GetSelectedEntity())
|
||||
{
|
||||
if (!selectedEntity.HasComponent<CameraComponent>())
|
||||
{
|
||||
auto transform = selectedEntity.GetComponent<TransformComponent>();
|
||||
|
||||
Renderer2D::DrawRect(transform.GetTransform(), glm::vec4(0.8f, 0.3f, 0.2f, 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
Renderer2D::EndScene();
|
||||
}
|
||||
|
||||
@ -406,7 +415,7 @@ namespace Hazel
|
||||
float snapValues[3] = {snapValue, snapValue, snapValue};
|
||||
if (ImGuizmo::Manipulate(glm::value_ptr(cameraView), glm::value_ptr(cameraProjection),
|
||||
static_cast<ImGuizmo::OPERATION>(m_GizmoType), ImGuizmo::WORLD,
|
||||
glm::value_ptr(transform), nullptr, snap ? snapValues : nullptr) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
|
||||
glm::value_ptr(transform), nullptr, snap ? snapValues : nullptr) && !Input::IsKeyPressed(KeyCode::LALT))
|
||||
{
|
||||
if (ImGuizmo::IsUsing())
|
||||
{
|
||||
@ -438,9 +447,15 @@ namespace Hazel
|
||||
void EditorLayer::SaveSceneAs() const
|
||||
{
|
||||
std::string filepath = FileDiaglogs::SaveFile("Hazel Scene (*.scene,*.yaml)\0*.scene;*.yaml\0*\0*.*\0\0");
|
||||
if (!filepath.empty())
|
||||
HZ_CORE_INFO("Saving scene to: {}", filepath);
|
||||
if (filepath.empty())
|
||||
{
|
||||
HZ_CORE_WARN("filepath is empty! do not save Scene!");
|
||||
}
|
||||
else
|
||||
{
|
||||
SerializeScene(m_ActiveScene, filepath);
|
||||
HZ_CORE_INFO("scene saved");
|
||||
}
|
||||
}
|
||||
|
||||
@ -484,7 +499,12 @@ namespace Hazel
|
||||
{
|
||||
if (!m_EditorScenePath.empty())
|
||||
{
|
||||
HZ_CORE_INFO("Saving scene: {}", m_EditorScenePath.string());
|
||||
SerializeScene(m_ActiveScene, m_EditorScenePath);
|
||||
HZ_CORE_INFO("scene saved");
|
||||
}else
|
||||
{
|
||||
SaveSceneAs();
|
||||
}
|
||||
}
|
||||
|
||||
@ -561,7 +581,7 @@ namespace Hazel
|
||||
m_CameraController.OnEvent(e);
|
||||
m_EditorCamera.OnEvent(e);
|
||||
}
|
||||
if (e.button.clicks && m_ViewportHovered && !ImGuizmo::IsOver() && Input::IsMouseButtonPressed(BUTTON_LEFT) && !Input::IsKeyPressed(SDL_SCANCODE_LALT))
|
||||
if (e.button.clicks && m_ViewportHovered && !ImGuizmo::IsOver() && Input::IsMouseButtonPressed(MouseButton::BUTTON_LEFT) && !Input::IsKeyPressed(KeyCode::LALT))
|
||||
m_SceneHierachyPanel.SetSelectedEntity(m_HoveredEntity);
|
||||
|
||||
#define SHORTCUT_EXIT (SDL_KMOD_CTRL + SDLK_W)
|
||||
|
||||
@ -50,8 +50,7 @@ namespace Hazel
|
||||
for (auto& directory : std::filesystem::directory_iterator(m_CurrentDirectory))
|
||||
{
|
||||
auto& path = directory.path();
|
||||
auto relativePath = std::filesystem::relative(directory.path(), g_AssetPath);
|
||||
std::string filePathString = relativePath.filename().string();
|
||||
std::string filePathString = path.filename().string();
|
||||
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
|
||||
@ -61,6 +60,7 @@ namespace Hazel
|
||||
|
||||
if (ImGui::BeginDragDropSource())
|
||||
{
|
||||
auto relativePath = std::filesystem::relative(path, g_AssetPath);
|
||||
const wchar_t* itemPath = relativePath.c_str();
|
||||
ImGui::SetDragDropPayload("CONTENT_BROSWER_ITEM", itemPath, (wcslen(itemPath) + 1) * sizeof(wchar_t), ImGuiCond_Once);
|
||||
ImGui::EndDragDropSource();
|
||||
|
||||
@ -44,7 +44,14 @@ namespace Hazel
|
||||
if (ImGui::BeginPopupContextWindow(0, ImGuiPopupFlags_MouseButtonRight | ImGuiPopupFlags_NoOpenOverItems))
|
||||
{
|
||||
if (ImGui::MenuItem("Create Empty Entity"))
|
||||
m_Context->CreateEntity("Empty Entity");
|
||||
{
|
||||
m_SelectionContext = m_Context->CreateEntity("Empty Entity");
|
||||
}
|
||||
else if (ImGui::MenuItem("Create Camera"))
|
||||
{
|
||||
m_SelectionContext = m_Context->CreateEntity("Camera");
|
||||
m_SelectionContext.AddComponent<CameraComponent>();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
|
||||
@ -9,20 +9,23 @@ namespace Hazel
|
||||
class HazelEditor : public Application
|
||||
{
|
||||
public:
|
||||
HazelEditor()
|
||||
: Application("Hazel Editor", 1920, 1080)
|
||||
HazelEditor(const ApplicationSpecification& specification)
|
||||
: Application(specification)
|
||||
{
|
||||
PushLayer(new EditorLayer());
|
||||
}
|
||||
|
||||
~HazelEditor() = default;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
Application* CreateApplication()
|
||||
Application* CreateApplication(ApplicationCommandLineArgs args)
|
||||
{
|
||||
return new HazelEditor();
|
||||
ApplicationSpecification spec;
|
||||
spec.name = "Editor app";
|
||||
spec.commandLineArgs = args;
|
||||
|
||||
return new HazelEditor(spec);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user