Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Defines_Macros.h
Go to the documentation of this file.
1#pragma once
2/// @file Defines_Macros.h
3/// @author Damon S. Green II
4/// @brief Provides commonly used macros along with project wide typedefs.
5
6
7/// @brief Macro to shift 1 by x positions to create a bitmask.
8/// @param x The number of positions to shift.
9/// @return The resulting bitmask.
10/// @note This macro is typically used for defining event categories.
11/// @warning Be cautious when using this macro with values greater than or equal to the number of bits in an integer, as it may lead to undefined behavior.
12/// @attention This macro is not type-safe; consider using constexpr functions or enum classes for better type safety.
13#define BIT(x) (1 << x)
14
15/// @brief Binds a member function as an event handler.
16/// @param fn The member function to bind.
17#define MU_BIND_EVENT_FN(fn) [this](auto&&... args) -> decltype(auto) { return this->fn(std::forward<decltype(args)>(args)...); }
18
19/// @brief Binds the given member function of the Application class as an event handler.
20/// @param x The member function to bind.
21#define BIND_EVENT_FN(x) std::bind(&Application::x, this, std::placeholders::_1)
22
23/// @brief Macro to define event type in event subclasses.
24/// @param type The event type to define.
25#define EVENT_CLASS_TYPE(type) static EventType GetStaticType() { return EventType::ET_##type; }
26 virtual EventType GetEventType() const override { return GetStaticType(); }
27 virtual const char* GetName() const override { return #type; }
28
29/// @brief Macro to define event category in event subclasses.
30/// @param category The event category to define.
31#define EVENT_CLASS_CATEGORY(category) virtual int GetCategoryFlags() const override { return category; }
32
33
34/// @namespace Muto
35/// @brief The main namespace for the Muto engine.
36namespace Muto {
37 /// @brief A smart pointer type representing exclusive ownership of an object.
38 ///
39 /// @tparam T The type of object to manage.
40 /// @note This is an alias for std::unique_ptr.
41 template <typename T>
42 using Scope = std::unique_ptr<T>;
43
44 /// @brief Creates a Scope (unique_ptr) for the given type and constructor arguments.
45 ///
46 /// @tparam T The type of object to create.
47 /// @tparam Args The types of constructor arguments.
48 /// @param args The constructor arguments.
49 /// @return A Scope (unique_ptr) managing the created object.
50 template <typename T, typename... Args>
51 constexpr Scope<T> CreateScope(Args&&... args)
52 {
53 return std::make_unique<T>(std::forward<Args>(args)...);
54 }
55
56
57 /// @brief A smart pointer type representing shared ownership of an object.
58 ///
59 /// @tparam T The type of object to manage.
60 /// @note This is an alias for std::shared_ptr.
61 template <typename T>
62 using Ref = std::shared_ptr<T>;
63
64 /// @brief Creates a Ref (shared_ptr) for the given type and constructor arguments.
65 ///
66 /// @tparam T The type of object to create.
67 /// @tparam Args The types of constructor arguments.
68 /// @param args The constructor arguments.
69 /// @return A Ref (shared_ptr) managing the created object.
70 template <typename T, typename... Args>
71 constexpr Ref<T> CreateRef(Args&&... args)
72 {
73 return std::make_shared<T>(std::forward<Args>(args)...);
74 }
75
76}
#define MU_CORE_ASSERT(x,...)
Definition Asserts.h:32
#define BIND_EVENT_FN(x)
Binds the given member function of the Application class as an event handler.
Definition Defines_Macros.h:21
#define MU_PROFILE_SCOPE(name)
Definition Instrumentor.h:239
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
#define MU_CORE_WARN(...)
warn: indicates a potential issue or important event
Definition Log.h:40
#define MU_CORE_ERROR(...)
error: indicates an error that has occurred
Definition Log.h:42
#define MU_CORE_INFO(...)
info: general information about application flow
Definition Log.h:38
The core application class that manages the main loop, window, layers, and event handling.
Definition Application.h:70
void OnEvent(Event &e)
Handles incoming events and dispatches them to the appropriate handlers.
Definition Application.cpp:108
float m_LastFrameTime
Time of the last frame, used for calculating timestep.
Definition Application.h:171
void PushLayer(Layer *layer)
Adds a layer to the application layer stack.
Definition Application.cpp:89
virtual ~Application()
Definition Application.cpp:85
void PushOverlay(Layer *overlay)
Adds an overlay layer to the application layer stack.
Definition Application.cpp:96
bool m_Running
Flag indicating whether the application is running.
Definition Application.h:162
Application(ApplicationSettings settings)
Constructs the Application with the given settings.
Definition Application.cpp:48
std::string ResolvePath(const std::string &Path, PathResolveMode Mode=PathResolveMode::AssetsDirectory) const
Resolves the full path to a resource based on a relative path and the application's settings.
Definition Application.cpp:166
std::string ResolvePath_AssetsDirectory(const std::string &Path) const
Resolves the full path to a resource based on the application's assets directory.
Definition Application.cpp:246
void Close()
Closes the application.
Definition Application.cpp:103
static Application * s_Instance
Definition Application.h:177
std::string ResolvePath_WorkingDirectory(const std::string &Path) const
Resolves the full path to a resource based on the application's working directory.
Definition Application.cpp:194
ImGuiLayer * m_ImGuiLayer
ImGui layer for rendering GUI elements.
Definition Application.h:159
bool m_Minimized
Flag indicating whether the application is minimized.
Definition Application.h:165
Application(const std::string &name="")
Constructs the Application with the given name.
Definition Application.cpp:19
std::string ResolvePath_ProjectDirectory(const std::string &Path) const
Resolves the full path to a resource based on the application's project directory.
Definition Application.cpp:220
bool OnWindowClose(WindowCloseEvent &e)
Event handler for window close events.
Definition Application.cpp:272
bool OnWindowResize(WindowResizeEvent &e)
Event handler for window resize events.
Definition Application.cpp:279
MutoResult InitFileSystem(ApplicationSettings &Settings)
Initializes the file system for the application with the given settings.
Definition Application.cpp:416
MutoResult InitFileSystem()
Initializes the file system for the application.
Definition Application.cpp:295
void Run()
Starts the main application loop.
Definition Application.cpp:125
Stack-based templated event dispatcher.
Definition Event.h:66
EventDispatcher(Event &event)
Construct an EventDispatcher for a specific event.
Definition Event.h:76
Abstract base class for all events.
Definition Event.h:35
bool Handled
Indicates whether the event has been handled.
Definition Event.h:60
Definition ImGuiLayer.h:16
virtual void End()
Definition ImGuiLayer.cpp:111
ImGuiLayer()
Definition ImGuiLayer.cpp:22
virtual void Begin()
Definition ImGuiLayer.cpp:102
Represents a reusable application layer that receives lifecycle callbacks (attach,...
Definition Layer.h:17
virtual void OnAttach()
Called when the layer is attached to the application.
Definition Layer.h:28
A logging utility class for the Vesper engine.
Definition Log.h:17
static std::shared_ptr< spdlog::logger > & GetClientLogger()
Returns the client logger instance.
Definition Log.h:26
static void Init()
Initializes the logging system.
Definition Log.cpp:16
static std::shared_ptr< spdlog::logger > & GetCoreLogger()
Returns the core logger instance.
Definition Log.h:24
static std::shared_ptr< spdlog::logger > s_CoreLogger
Definition Log.h:28
static std::shared_ptr< spdlog::logger > s_ClientLogger
Definition Log.h:29
The main renderer class responsible for managing rendering operations.
Definition Renderer.h:15
static void OnWindowResize(uint32_t width, uint32_t height)
Handles window resize events by resizing the viewport.
Definition Renderer.cpp:24
static void Init()
Initializes the renderer.
Definition Renderer.cpp:16
Represents a time step in seconds.
Definition Timestep.h:11
Event for registering window close.
Definition ApplicationEvent.h:49
Event for registering window resize.
Definition ApplicationEvent.h:16
unsigned int GetWidth() const
Get the new width of the window.
Definition ApplicationEvent.h:27
unsigned int GetHeight() const
Get the new height of the window.
Definition ApplicationEvent.h:29
The main namespace for the Muto engine.
Definition Application.cpp:15
std::string ProjectDirectory
The project directory of the application.
Definition Application.h:38
MU_RETURN
Definition Enums.h:6
static std::string NormalizePath(const std::string &path)
Normalizes path separators to forward slashes for cross-platform consistency.
Definition ResourceManager.h:10
static std::string JoinPaths(const std::string &base, const std::string &relative)
Joins two path segments with proper separator handling.
Definition ResourceManager.h:22
static bool IsAbsolutePath(const std::string &path)
Determines whether the given path is an absolute path (Unix-style, Windows-style, or drive-letter).
Definition ResourceManager.h:47
PathResolveMode
Specifies the mode for resolving resource paths in the application.
Definition Application.h:22
constexpr Ref< T > CreateRef(Args &&... args)
Creates a Ref (shared_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:71
std::string WorkingDirectory
The working directory of the application.
Definition Application.h:35
std::string AssetsDirectory
The assets directory of the application.
Definition Application.h:41
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51
Holds configuration settings for the application.
Definition Application.h:30
Definition MutoResult.h:8
std::string ResultMessage
Definition MutoResult.h:10
bool IsSuccess()
Definition MutoResult.h:16