添加spdlog 和 glfw
This commit is contained in:
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[submodule "Prism/vendor/spdlog"]
|
||||||
|
path = Prism/vendor/spdlog
|
||||||
|
url = https://github.com/gabime/spdlog.git
|
||||||
|
[submodule "Prism/vendor/glfw"]
|
||||||
|
path = Prism/vendor/glfw
|
||||||
|
url = https://github.com/glfw/glfw.git
|
||||||
@ -1,7 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.31)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(Prism)
|
project(Prism)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||||
|
|||||||
@ -2,11 +2,21 @@
|
|||||||
// Created by sfd on 25-11-15.
|
// Created by sfd on 25-11-15.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Editor.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main()
|
#include "Prism/Core/Application.h"
|
||||||
|
#include "Prism/Core/EntryPoint.h"
|
||||||
|
|
||||||
|
|
||||||
|
class Editor : public Prism::Application
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Editor()
|
||||||
{
|
{
|
||||||
std::cout << "Hello World!\n";
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Prism::Application* Prism::CreateApplication()
|
||||||
|
{
|
||||||
|
return new Editor();
|
||||||
|
}
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by sfd on 25-11-15.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef EDITOR_H
|
|
||||||
#define EDITOR_H
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //EDITOR_H
|
|
||||||
@ -3,16 +3,30 @@ project(Prism)
|
|||||||
file(GLOB_RECURSE SRC_SOURCE src/**.cpp)
|
file(GLOB_RECURSE SRC_SOURCE src/**.cpp)
|
||||||
|
|
||||||
|
|
||||||
|
# configure
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
|
add_subdirectory(vendor/spdlog EXCLUDE_FROM_ALL)
|
||||||
|
add_subdirectory(vendor/glfw EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
|
|
||||||
# static library
|
# static library
|
||||||
set(STATIC_LIBRARY ${PROJECT_NAME}-static)
|
set(STATIC_LIBRARY ${PROJECT_NAME}-static)
|
||||||
|
|
||||||
add_library(${STATIC_LIBRARY} STATIC ${SRC_SOURCE})
|
add_library(${STATIC_LIBRARY} STATIC ${SRC_SOURCE})
|
||||||
|
|
||||||
target_compile_definitions(${STATIC_LIBRARY} PRIVATE PRISM_STATIC)
|
target_compile_definitions(${STATIC_LIBRARY} PRIVATE
|
||||||
|
PRISM_STATIC
|
||||||
|
$<$<CONFIG:Debug>:PM_ENABLE_ASSERTS>
|
||||||
|
)
|
||||||
|
|
||||||
target_include_directories(${STATIC_LIBRARY} PUBLIC
|
target_include_directories(${STATIC_LIBRARY} PUBLIC
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
||||||
|
|
||||||
|
)
|
||||||
|
target_link_libraries(${STATIC_LIBRARY} PRIVATE
|
||||||
|
spdlog
|
||||||
|
glfw
|
||||||
)
|
)
|
||||||
set_target_properties(${STATIC_LIBRARY} PROPERTIES
|
set_target_properties(${STATIC_LIBRARY} PROPERTIES
|
||||||
OUTPUT_NAME ${PROJECT_NAME}
|
OUTPUT_NAME ${PROJECT_NAME}
|
||||||
@ -25,10 +39,17 @@ set(SHARED_LIBRARY ${PROJECT_NAME}-shared)
|
|||||||
|
|
||||||
add_library(${SHARED_LIBRARY} SHARED ${SRC_SOURCE})
|
add_library(${SHARED_LIBRARY} SHARED ${SRC_SOURCE})
|
||||||
|
|
||||||
target_compile_definitions(${SHARED_LIBRARY} PRIVATE PRISM_SHARED BUILD_PRISM_DLL)
|
target_compile_definitions(${SHARED_LIBRARY} PRIVATE
|
||||||
|
PRISM_SHARED BUILD_PRISM_DLL
|
||||||
|
$<$<CONFIG:Debug>:PM_ENABLE_ASSERTS>
|
||||||
|
)
|
||||||
|
|
||||||
target_include_directories(${SHARED_LIBRARY} PUBLIC
|
target_include_directories(${SHARED_LIBRARY} PUBLIC
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
||||||
|
)
|
||||||
|
target_link_libraries(${SHARED_LIBRARY} PRIVATE
|
||||||
|
spdlog
|
||||||
|
glfw
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(${SHARED_LIBRARY} PROPERTIES
|
set_target_properties(${SHARED_LIBRARY} PROPERTIES
|
||||||
|
|||||||
@ -5,4 +5,13 @@
|
|||||||
#ifndef PRISM_H
|
#ifndef PRISM_H
|
||||||
#define PRISM_H
|
#define PRISM_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "Prism/Core/Application.h"
|
||||||
|
#include "Prism/Core/EntryPoint.h"
|
||||||
|
#include "Prism/Core/Events/ApplicationEvent.h"
|
||||||
|
#include "Prism/Core/Events/Event.h"
|
||||||
|
#include "Prism/Core/Events/KeyEvent.h"
|
||||||
|
#include "Prism/Core/Events/MouseEvent.h"
|
||||||
|
|
||||||
|
|
||||||
#endif //PRISM_H
|
#endif //PRISM_H
|
||||||
|
|||||||
@ -1,12 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by sfd on 25-11-15.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Application.h"
|
|
||||||
|
|
||||||
namespace Prism
|
|
||||||
{
|
|
||||||
Application::Application()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by sfd on 25-11-15.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef APPLICATION_H
|
|
||||||
#define APPLICATION_H
|
|
||||||
|
|
||||||
#include "Core/Core.h"
|
|
||||||
|
|
||||||
namespace Prism
|
|
||||||
{
|
|
||||||
class PRISM_API Application
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Application();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif //APPLICATION_H
|
|
||||||
50
Prism/src/Prism/Core/Application.cpp
Normal file
50
Prism/src/Prism/Core/Application.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-15.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
namespace Prism
|
||||||
|
{
|
||||||
|
#define BIND_EVENT_FN(fn) std::bind(&Application::##fn, this, std::placeholders::_1)
|
||||||
|
|
||||||
|
Application::Application()
|
||||||
|
{
|
||||||
|
m_Window = std::unique_ptr<Window>(Window::Create());
|
||||||
|
m_Window->SetEventCallback(BIND_EVENT_FN(OnEvent));
|
||||||
|
}
|
||||||
|
|
||||||
|
Application::~Application()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::Run()
|
||||||
|
{
|
||||||
|
while (m_Running)
|
||||||
|
{
|
||||||
|
m_Window->OnUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::OnEvent(Event& e)
|
||||||
|
{
|
||||||
|
EventDispatcher dispatcher(e);
|
||||||
|
dispatcher.Dispatch<WindowResizeEvent>(BIND_EVENT_FN(OnWindowResize));
|
||||||
|
dispatcher.Dispatch<WindowCloseEvent>(BIND_EVENT_FN(OnWindowClose));
|
||||||
|
|
||||||
|
PM_CORE_INFO("{}", e.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::OnWindowResize(const WindowResizeEvent& e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::OnWindowClose(WindowCloseEvent& e)
|
||||||
|
{
|
||||||
|
m_Running = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
Prism/src/Prism/Core/Application.h
Normal file
45
Prism/src/Prism/Core/Application.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-15.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef APPLICATION_H
|
||||||
|
#define APPLICATION_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "Core.h"
|
||||||
|
#include "Window.h"
|
||||||
|
#include "Events/ApplicationEvent.h"
|
||||||
|
|
||||||
|
namespace Prism
|
||||||
|
{
|
||||||
|
class PRISM_API Application
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Application();
|
||||||
|
virtual ~Application();
|
||||||
|
|
||||||
|
void Run();
|
||||||
|
|
||||||
|
virtual void OnInit() {}
|
||||||
|
virtual void OnUpdate() {}
|
||||||
|
virtual void OnShutdown() {}
|
||||||
|
|
||||||
|
virtual void OnEvent(Event& e);
|
||||||
|
private:
|
||||||
|
bool OnWindowResize(const WindowResizeEvent& e);
|
||||||
|
bool OnWindowClose(WindowCloseEvent& e);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<Window> m_Window;
|
||||||
|
|
||||||
|
bool m_Running = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// this function will implemented by client
|
||||||
|
Application* CreateApplication();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //APPLICATION_H
|
||||||
63
Prism/src/Prism/Core/Core.cpp
Normal file
63
Prism/src/Prism/Core/Core.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-15.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Core.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
namespace Prism {
|
||||||
|
|
||||||
|
void InitializeCore()
|
||||||
|
{
|
||||||
|
Log::Init();
|
||||||
|
|
||||||
|
PM_CORE_TRACE("Initializing...");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShutdownCore()
|
||||||
|
{
|
||||||
|
PM_CORE_TRACE("Shutting down...");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#if defined(_WIN32)
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
|
||||||
|
BOOL APIENTRY DllMain(HMODULE hModule,
|
||||||
|
DWORD ul_reason_for_call,
|
||||||
|
LPVOID lpReserved
|
||||||
|
)
|
||||||
|
{
|
||||||
|
switch (ul_reason_for_call)
|
||||||
|
{
|
||||||
|
case DLL_PROCESS_ATTACH:
|
||||||
|
Prism::InitializeCore();
|
||||||
|
break;
|
||||||
|
case DLL_THREAD_ATTACH:
|
||||||
|
case DLL_THREAD_DETACH:
|
||||||
|
break;
|
||||||
|
case DLL_PROCESS_DETACH:
|
||||||
|
Prism::ShutdownCore();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#elif defined(__linux__) || defined(__unix__)
|
||||||
|
|
||||||
|
__attribute__((constructor))
|
||||||
|
static void library_load() {
|
||||||
|
Prism::InitializeCore();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((destructor))
|
||||||
|
static void library_unload() {
|
||||||
|
Prism::ShutdownCore();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -15,5 +15,22 @@
|
|||||||
#define PRISM_API
|
#define PRISM_API
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define BIT(x) (1 << x)
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PM_ENABLE_ASSERTS
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define PM_DEBUGBREAK() __debugbreak()
|
||||||
|
#elif defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
|
||||||
|
#define PM_DEBUGBREAK() asm("int3")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PM_ASSERT(x, ...) { if(!(x)) { PM_ERROR("Assertion Failed: {0}", __VA_ARGS__); PM_DEBUGBREAK(); } }
|
||||||
|
#define PM_CORE_ASSERT(x, ...) { if(!(x)) { PM_CORE_ERROR("Assertion Failed: {0}", __VA_ARGS__); PM_DEBUGBREAK(); } }
|
||||||
|
#else
|
||||||
|
#define PM_ASSERT(x, ...)
|
||||||
|
#define PM_CORE_ASSERT(x, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif //CORE_H
|
#endif //CORE_H
|
||||||
|
|||||||
19
Prism/src/Prism/Core/EntryPoint.h
Normal file
19
Prism/src/Prism/Core/EntryPoint.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-15.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef ENTRYPOINT_H
|
||||||
|
#define ENTRYPOINT_H
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
|
extern Prism::Application* Prism::CreateApplication();
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
Prism::Application* app = Prism::CreateApplication();
|
||||||
|
app->Run();
|
||||||
|
delete app;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //ENTRYPOINT_H
|
||||||
76
Prism/src/Prism/Core/Events/ApplicationEvent.h
Normal file
76
Prism/src/Prism/Core/Events/ApplicationEvent.h
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef APPLICATIONEVENT_H
|
||||||
|
#define APPLICATIONEVENT_H
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
|
namespace Prism {
|
||||||
|
|
||||||
|
class PRISM_API WindowResizeEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WindowResizeEvent(const uint32_t width, const uint32_t height)
|
||||||
|
: m_Width(width), m_Height(height)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int GetWidth() const { return m_Width; }
|
||||||
|
inline unsigned int GetHeight() const { return m_Height; }
|
||||||
|
|
||||||
|
std::string ToString() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "WindowResizeEvent: " << m_Width << ", " << m_Height;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(WindowResize)
|
||||||
|
EVENT_CLASS_CATEGORY(EventCategoryApplication)
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t m_Width, m_Height;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API WindowCloseEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WindowCloseEvent() {}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(WindowClose)
|
||||||
|
EVENT_CLASS_CATEGORY(EventCategoryApplication)
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API AppTickEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppTickEvent() {}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(AppTick)
|
||||||
|
EVENT_CLASS_CATEGORY(EventCategoryApplication)
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API AppUpdateEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppUpdateEvent() {}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(AppUpdate)
|
||||||
|
EVENT_CLASS_CATEGORY(EventCategoryApplication)
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API AppRenderEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppRenderEvent() {}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(AppRender)
|
||||||
|
EVENT_CLASS_CATEGORY(EventCategoryApplication)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //APPLICATIONEVENT_H
|
||||||
87
Prism/src/Prism/Core/Events/Event.h
Normal file
87
Prism/src/Prism/Core/Events/Event.h
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef EVENT_H
|
||||||
|
#define EVENT_H
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
#include "../Core.h"
|
||||||
|
|
||||||
|
namespace Prism
|
||||||
|
{
|
||||||
|
enum class EventType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved,
|
||||||
|
AppTick, AppUpdate, AppRender,
|
||||||
|
KeyPressed, KeyReleased,
|
||||||
|
MouseButtonPressed, MouseButtonReleased, MouseMoved, MouseScrolled
|
||||||
|
};
|
||||||
|
|
||||||
|
enum EventCategory
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
EventCategoryApplication = BIT(0),
|
||||||
|
EventCategoryInput = BIT(1),
|
||||||
|
EventCategoryKeyboard = BIT(2),
|
||||||
|
EventCategoryMouse = BIT(3),
|
||||||
|
EventCategoryMouseButton = BIT(4)
|
||||||
|
};
|
||||||
|
|
||||||
|
#define EVENT_CLASS_TYPE(type) static EventType GetStaticType() { return EventType::##type; }\
|
||||||
|
virtual EventType GetEventType() const override { return GetStaticType(); }\
|
||||||
|
virtual const char* GetName() const override { return #type; }
|
||||||
|
|
||||||
|
#define EVENT_CLASS_CATEGORY(category) virtual int GetCategoryFlags() const override { return category; }
|
||||||
|
|
||||||
|
class PRISM_API Event
|
||||||
|
{
|
||||||
|
friend class EventDispatcher;
|
||||||
|
public:
|
||||||
|
virtual EventType GetEventType() const = 0;
|
||||||
|
virtual const char* GetName() const = 0;
|
||||||
|
virtual int GetCategoryFlags() const = 0;
|
||||||
|
virtual std::string ToString() const { return GetName(); }
|
||||||
|
|
||||||
|
inline bool IsInCategory(EventCategory category)
|
||||||
|
{
|
||||||
|
return GetCategoryFlags() & category;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
bool m_Handled = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EventDispatcher
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
using EventFn = std::function<bool(T&)>;
|
||||||
|
public:
|
||||||
|
EventDispatcher(Event& event)
|
||||||
|
: m_Event(event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool Dispatch(EventFn<T> func)
|
||||||
|
{
|
||||||
|
if (m_Event.GetEventType() == T::GetStaticType())
|
||||||
|
{
|
||||||
|
m_Event.m_Handled = func(*(T*)&m_Event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
Event& m_Event;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& os, const Event& e)
|
||||||
|
{
|
||||||
|
return os << e.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //EVENT_H
|
||||||
62
Prism/src/Prism/Core/Events/KeyEvent.h
Normal file
62
Prism/src/Prism/Core/Events/KeyEvent.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef KEYEVENT_H
|
||||||
|
#define KEYEVENT_H
|
||||||
|
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
|
namespace Prism {
|
||||||
|
|
||||||
|
class PRISM_API KeyEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline int GetKeyCode() const { return m_KeyCode; }
|
||||||
|
|
||||||
|
EVENT_CLASS_CATEGORY(EventCategoryKeyboard | EventCategoryInput)
|
||||||
|
protected:
|
||||||
|
KeyEvent(int keycode)
|
||||||
|
: m_KeyCode(keycode) {}
|
||||||
|
|
||||||
|
int m_KeyCode;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API KeyPressedEvent : public KeyEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KeyPressedEvent(int keycode, int repeatCount)
|
||||||
|
: KeyEvent(keycode), m_RepeatCount(repeatCount) {}
|
||||||
|
|
||||||
|
inline int GetRepeatCount() const { return m_RepeatCount; }
|
||||||
|
|
||||||
|
std::string ToString() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "KeyPressedEvent: " << m_KeyCode << " (" << m_RepeatCount << " repeats)";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(KeyPressed)
|
||||||
|
private:
|
||||||
|
int m_RepeatCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API KeyReleasedEvent : public KeyEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KeyReleasedEvent(int keycode)
|
||||||
|
: KeyEvent(keycode) {}
|
||||||
|
|
||||||
|
std::string ToString() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "KeyReleasedEvent: " << m_KeyCode;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(KeyReleased)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //KEYEVENT_H
|
||||||
106
Prism/src/Prism/Core/Events/MouseEvent.h
Normal file
106
Prism/src/Prism/Core/Events/MouseEvent.h
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MOUSEEVENT_H
|
||||||
|
#define MOUSEEVENT_H
|
||||||
|
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
|
namespace Prism {
|
||||||
|
|
||||||
|
class PRISM_API MouseMovedEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MouseMovedEvent(float x, float y, float dx, float dy)
|
||||||
|
: m_MouseX(x), m_MouseY(y), m_MouseDX(x), m_MouseDY(dy) {}
|
||||||
|
|
||||||
|
inline float GetX() const { return m_MouseX; }
|
||||||
|
inline float GetY() const { return m_MouseY; }
|
||||||
|
|
||||||
|
std::string ToString() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "MouseMovedEvent: " << m_MouseX << ", " << m_MouseY;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(MouseMoved)
|
||||||
|
EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput)
|
||||||
|
private:
|
||||||
|
float m_MouseX, m_MouseY;
|
||||||
|
};
|
||||||
|
class PRISM_API MouseScrolledEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MouseScrolledEvent(float offsetX, float offsetY)
|
||||||
|
: m_XOffset(offsetX), m_YOffset(offsetY) {}
|
||||||
|
|
||||||
|
inline float GetOffsetX() const { return m_XOffset; }
|
||||||
|
inline float GetOffsetY() const { return m_YOffset; }
|
||||||
|
|
||||||
|
std::string ToString() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "MouseScrolledEvent: " << m_XOffset << ", " << m_YOffset;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(MouseScrolled)
|
||||||
|
EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput)
|
||||||
|
private:
|
||||||
|
float m_XOffset, m_YOffset;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API MouseButtonEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline int GetMouseButton() const { return m_Button; }
|
||||||
|
|
||||||
|
EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput)
|
||||||
|
protected:
|
||||||
|
MouseButtonEvent(int button)
|
||||||
|
: m_Button(button) {}
|
||||||
|
|
||||||
|
int m_Button;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API MouseButtonPressedEvent : public MouseButtonEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MouseButtonPressedEvent(int button, int repeatCount)
|
||||||
|
: MouseButtonEvent(button), m_RepeatCount(repeatCount) {}
|
||||||
|
|
||||||
|
inline int GetRepeatCount() const { return m_RepeatCount; }
|
||||||
|
|
||||||
|
std::string ToString() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "MouseButtonPressedEvent: " << m_Button;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(MouseButtonPressed)
|
||||||
|
private:
|
||||||
|
int m_RepeatCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API MouseButtonReleasedEvent : public MouseButtonEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MouseButtonReleasedEvent(const int button)
|
||||||
|
: MouseButtonEvent(button) {}
|
||||||
|
|
||||||
|
std::string ToString() const override
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "MouseButtonReleasedEvent: " << m_Button;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_CLASS_TYPE(MouseButtonReleased)
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //MOUSEEVENT_H
|
||||||
29
Prism/src/Prism/Core/Log.cpp
Normal file
29
Prism/src/Prism/Core/Log.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-15.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
#include "spdlog/sinks/stdout_color_sinks-inl.h"
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define LOG_LEVEL spdlog::level::trace
|
||||||
|
#else
|
||||||
|
#define LOG_LEVEL spdlog::level::trace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Prism
|
||||||
|
{
|
||||||
|
std::shared_ptr<spdlog::logger> Log::s_CoreLogger;
|
||||||
|
std::shared_ptr<spdlog::logger> Log::s_ClientLogger;
|
||||||
|
|
||||||
|
void Log::Init()
|
||||||
|
{
|
||||||
|
spdlog::set_pattern("%^[%T] [%n]%v%$");
|
||||||
|
s_CoreLogger = spdlog::stdout_color_mt("PRISM");
|
||||||
|
s_CoreLogger->set_level(LOG_LEVEL);
|
||||||
|
|
||||||
|
s_ClientLogger = spdlog::stdout_color_mt("APP");
|
||||||
|
s_ClientLogger->set_level(LOG_LEVEL);
|
||||||
|
}
|
||||||
|
}
|
||||||
43
Prism/src/Prism/Core/Log.h
Normal file
43
Prism/src/Prism/Core/Log.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-15.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef LOG_H
|
||||||
|
#define LOG_H
|
||||||
|
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "spdlog/fmt/bundled/ostream.h"
|
||||||
|
|
||||||
|
#include "Core.h"
|
||||||
|
|
||||||
|
namespace Prism
|
||||||
|
{
|
||||||
|
class Log
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void Init();
|
||||||
|
|
||||||
|
inline static std::shared_ptr<spdlog::logger>& GetCoreLogger() { return s_CoreLogger; }
|
||||||
|
inline static std::shared_ptr<spdlog::logger>& GetClientLogger() { return s_ClientLogger; }
|
||||||
|
private:
|
||||||
|
static std::shared_ptr<spdlog::logger> s_CoreLogger;
|
||||||
|
static std::shared_ptr<spdlog::logger> s_ClientLogger;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define PM_CORE_TRACE(...) ::Prism::Log::GetCoreLogger()->trace("[TRACE]: " __VA_ARGS__)
|
||||||
|
#define PM_CORE_DEBUG(...) ::Prism::Log::GetCoreLogger()->debug("[DEBUG]: " __VA_ARGS__)
|
||||||
|
#define PM_CORE_INFO(...) ::Prism::Log::GetCoreLogger()->info("[INFO]: " __VA_ARGS__)
|
||||||
|
#define PM_CORE_WARN(...) ::Prism::Log::GetCoreLogger()->warn("[WARN]: " __VA_ARGS__)
|
||||||
|
#define PM_CORE_ERROR(...) ::Prism::Log::GetCoreLogger()->error("[ERROR]: " __VA_ARGS__)
|
||||||
|
#define PM_CORE_FATAL(...) ::Prism::Log::GetCoreLogger()->critical("[FATAL]: " __VA_ARGS__)
|
||||||
|
|
||||||
|
#define PM_CLIENT_TRACE(...) ::Prism::Log::GetClientLogger()->trace("[TRACE]: " __VA_ARGS__)
|
||||||
|
#define PM_CLIENT_DEBUG(...) ::Prism::Log::GetClientLogger()->debug("[DEBUG]: " __VA_ARGS__)
|
||||||
|
#define PM_CLIENT_INFO(...) ::Prism::Log::GetClientLogger()->info("[INFO]: " __VA_ARGS__)
|
||||||
|
#define PM_CLIENT_WARN(...) ::Prism::Log::GetClientLogger()->warn("[WARN]: " __VA_ARGS__)
|
||||||
|
#define PM_CLIENT_ERROR(...) ::Prism::Log::GetClientLogger()->error("[ERROR]: " __VA_ARGS__)
|
||||||
|
#define PM_CLIENT_FATAL(...) ::Prism::Log::GetClientLogger()->critical("[FATAL]: " __VA_ARGS__)
|
||||||
|
|
||||||
|
#endif //LOG_H
|
||||||
10
Prism/src/Prism/Core/Window.cpp
Normal file
10
Prism/src/Prism/Core/Window.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Window.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Prism
|
||||||
|
{
|
||||||
|
}
|
||||||
50
Prism/src/Prism/Core/Window.h
Normal file
50
Prism/src/Prism/Core/Window.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef WINDOW_H
|
||||||
|
#define WINDOW_H
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Events/Event.h"
|
||||||
|
#include "Prism/Core/Core.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Prism
|
||||||
|
{
|
||||||
|
struct WindowProps
|
||||||
|
{
|
||||||
|
std::string Title;
|
||||||
|
unsigned int Width;
|
||||||
|
unsigned int Height;
|
||||||
|
|
||||||
|
WindowProps(const std::string& title = "Prism Engine",
|
||||||
|
unsigned int width = 1280,
|
||||||
|
unsigned int height = 720)
|
||||||
|
: Title(title), Width(width), Height(height)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PRISM_API Window
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using EventCallbackFn = std::function<void(Event&)>;
|
||||||
|
|
||||||
|
virtual ~Window() {}
|
||||||
|
|
||||||
|
virtual void OnUpdate() = 0;
|
||||||
|
virtual void SetEventCallback(const EventCallbackFn& callback) = 0;
|
||||||
|
virtual unsigned int GetWidth() const = 0;
|
||||||
|
virtual unsigned int GetHeight() const = 0;
|
||||||
|
|
||||||
|
virtual void SetVSync(bool enable) = 0;
|
||||||
|
virtual bool const IsVSync() const = 0;
|
||||||
|
|
||||||
|
static Window* Create(const WindowProps& props = WindowProps());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //WINDOW_H
|
||||||
101
Prism/src/Prism/Platform/Windows/WindowsWindow.cpp
Normal file
101
Prism/src/Prism/Platform/Windows/WindowsWindow.cpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "WindowsWindow.h"
|
||||||
|
|
||||||
|
#include "Prism/Core/Log.h"
|
||||||
|
#include "Prism/Core/Events/ApplicationEvent.h"
|
||||||
|
|
||||||
|
namespace Prism
|
||||||
|
{
|
||||||
|
|
||||||
|
static bool s_GLFWInitialized = false;
|
||||||
|
|
||||||
|
static void GLFWErrorCallback(int error, const char* description)
|
||||||
|
{
|
||||||
|
PM_CORE_ERROR("GLFW Error ({0}): {1}", error, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Window* Window::Create(const WindowProps& props)
|
||||||
|
{
|
||||||
|
return new WindowsWindow(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowsWindow::WindowsWindow(const WindowProps& props)
|
||||||
|
{
|
||||||
|
WindowsWindow::Init(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowsWindow::~WindowsWindow()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowsWindow::OnUpdate()
|
||||||
|
{
|
||||||
|
glfwPollEvents();
|
||||||
|
glfwSwapBuffers(m_Window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowsWindow::SetVSync(bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
else
|
||||||
|
glfwSwapInterval(0);
|
||||||
|
|
||||||
|
m_Data.VSync = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowsWindow::Init(const WindowProps& props)
|
||||||
|
{
|
||||||
|
m_Data.Title = props.Title;
|
||||||
|
m_Data.Width = props.Width;
|
||||||
|
m_Data.Height = props.Height;
|
||||||
|
|
||||||
|
PM_CORE_INFO("Creating window {0}, ({1}, {2})", props.Title, props.Width, props.Height);
|
||||||
|
|
||||||
|
if (!s_GLFWInitialized)
|
||||||
|
{
|
||||||
|
int success = glfwInit();
|
||||||
|
PM_CORE_ASSERT(success, "Could not initialize GLFW!");
|
||||||
|
glfwSetErrorCallback(GLFWErrorCallback);
|
||||||
|
|
||||||
|
s_GLFWInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Window = glfwCreateWindow((int)props.Width, (int)props.Height, m_Data.Title.c_str(), nullptr, nullptr);
|
||||||
|
glfwMakeContextCurrent(m_Window);
|
||||||
|
glfwSetWindowUserPointer(m_Window, &m_Data);
|
||||||
|
SetVSync(true);
|
||||||
|
|
||||||
|
// Set GLFW callbacks
|
||||||
|
glfwSetWindowSizeCallback(m_Window, [](GLFWwindow* window, int width, int height)
|
||||||
|
{
|
||||||
|
auto& data = *((WindowData*)glfwGetWindowUserPointer(window));
|
||||||
|
data.Width = width;
|
||||||
|
data.Height = height;
|
||||||
|
|
||||||
|
WindowResizeEvent event(width, height);
|
||||||
|
data.EventCallback(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
glfwSetWindowCloseCallback(m_Window, [](GLFWwindow* window)
|
||||||
|
{
|
||||||
|
auto& data = *((WindowData*)glfwGetWindowUserPointer(window));
|
||||||
|
|
||||||
|
WindowCloseEvent event;
|
||||||
|
data.EventCallback(event);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowsWindow::Shutdown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
49
Prism/src/Prism/Platform/Windows/WindowsWindow.h
Normal file
49
Prism/src/Prism/Platform/Windows/WindowsWindow.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
//
|
||||||
|
// Created by sfd on 25-11-16.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef WINDOWSWINDOW_H
|
||||||
|
#define WINDOWSWINDOW_H
|
||||||
|
#include "Prism/Core/Window.h"
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
namespace Prism
|
||||||
|
{
|
||||||
|
class WindowsWindow : public Window
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WindowsWindow(const WindowProps& props);
|
||||||
|
virtual ~WindowsWindow();
|
||||||
|
|
||||||
|
void OnUpdate() override;
|
||||||
|
|
||||||
|
inline uint32_t GetWidth() const override { return m_Data.Width; }
|
||||||
|
inline uint32_t GetHeight() const override { return m_Data.Height; }
|
||||||
|
|
||||||
|
inline void SetEventCallback(const EventCallbackFn& callback) override { m_Data.EventCallback = callback; }
|
||||||
|
bool const IsVSync() const override { return m_Data.VSync; }
|
||||||
|
void SetVSync(bool enable) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void Init(const WindowProps& props);
|
||||||
|
virtual void Shutdown();
|
||||||
|
|
||||||
|
private:
|
||||||
|
GLFWwindow* m_Window;
|
||||||
|
|
||||||
|
struct WindowData
|
||||||
|
{
|
||||||
|
std::string Title;
|
||||||
|
uint32_t Width, Height;
|
||||||
|
bool VSync;
|
||||||
|
|
||||||
|
EventCallbackFn EventCallback;
|
||||||
|
};
|
||||||
|
WindowData m_Data;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //WINDOWSWINDOW_H
|
||||||
1
Prism/vendor/glfw
vendored
Submodule
1
Prism/vendor/glfw
vendored
Submodule
Submodule Prism/vendor/glfw added at 162896e5b9
1
Prism/vendor/spdlog
vendored
Submodule
1
Prism/vendor/spdlog
vendored
Submodule
Submodule Prism/vendor/spdlog added at cdbd64e230
@ -2,4 +2,21 @@
|
|||||||
// Created by sfd on 25-11-15.
|
// Created by sfd on 25-11-15.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Sandbox.h"
|
|
||||||
|
#include "Prism/Core/Application.h"
|
||||||
|
#include "Prism/Core/EntryPoint.h"
|
||||||
|
|
||||||
|
class Sandbox : public Prism::Application
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Sandbox()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Prism::Application* Prism::CreateApplication()
|
||||||
|
{
|
||||||
|
return new Sandbox();
|
||||||
|
}
|
||||||
|
|||||||
@ -1,12 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by sfd on 25-11-15.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SANDBOX_H
|
|
||||||
#define SANDBOX_H
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //SANDBOX_H
|
|
||||||
Reference in New Issue
Block a user