Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::Application Class Reference

The core application class that manages the main loop, window, layers, and event handling. More...

#include <Application.h>

Inheritance diagram for Muto::Application:
Muto::Mutare Muto::Mutare SandboxApp SandboxApp

Public Member Functions

 Application (ApplicationSettings settings)
 Constructs the Application with the given settings.
 
 Application (const std::string &name="")
 Constructs the Application with the given name.
 
void Close ()
 Closes the application.
 
ImGuiLayer * GetImGuiLayer ()
 Retrieves the ImGui layer.
 
ApplicationSettings & GetSettings ()
 Retrieves the application settings.
 
const ApplicationSettings & GetSettings () const
 Retrieves the application settings as a const reference.
 
Window & GetWindow ()
 Retrieves the application window.
 
void OnEvent (Event &e)
 Handles incoming events and dispatches them to the appropriate handlers.
 
void PushLayer (Layer *layer)
 Adds a layer to the application layer stack.
 
void PushOverlay (Layer *overlay)
 Adds an overlay layer to the application layer stack.
 
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.
 
void Run ()
 Starts the main application loop.
 
virtual ~Application ()
 

Static Public Member Functions

static Application & Get ()
 Retrieves the singleton instance of the Application.
 

Private Member Functions

MutoResult InitFileSystem ()
 Initializes the file system for the application.
 
MutoResult InitFileSystem (ApplicationSettings &Settings)
 Initializes the file system for the application with the given settings.
 
bool OnWindowClose (WindowCloseEvent &e)
 Event handler for window close events.
 
bool OnWindowResize (WindowResizeEvent &e)
 Event handler for window resize events.
 
std::string ResolvePath_AssetsDirectory (const std::string &Path) const
 Resolves the full path to a resource based on the application's assets directory.
 
std::string ResolvePath_ProjectDirectory (const std::string &Path) const
 Resolves the full path to a resource based on the application's project directory.
 
std::string ResolvePath_WorkingDirectory (const std::string &Path) const
 Resolves the full path to a resource based on the application's working directory.
 

Private Attributes

ImGuiLayer * m_ImGuiLayer
 ImGui layer for rendering GUI elements.
 
float m_LastFrameTime = 0.0f
 Time of the last frame, used for calculating timestep.
 
LayerStack m_LayerStack
 Stack of layers managed by the application.
 
bool m_Minimized = false
 Flag indicating whether the application is minimized.
 
bool m_Running = true
 Flag indicating whether the application is running.
 
Scope< ApplicationSettings > m_Settings
 Scoped pointer to the application settings.
 
Scope< Window > m_Window
 Scoped pointer to the applications underlying window.
 

Static Private Attributes

static Application * s_Instance = nullptr
 

Detailed Description

The core application class that manages the main loop, window, layers, and event handling.

Todo:

Update class to accept ApplicationSettings in constructor and verify its utility/use

Create a dedicated ResourceManager class to handle resource path resolution and management

Constructor & Destructor Documentation

◆ Application() [1/2]

Muto::Application::Application ( const std::string &  name = "")

Constructs the Application with the given name.

Parameters
nameThe name of the application. Defaults to an empty string.
20 {
22 MU_CORE_ASSERT(!s_Instance, "Application already exists!");
23 s_Instance = this;
24
25 m_Window = Window::Create(WindowProps(name));
26 m_Window->SetEventCallback(BIND_EVENT_FN(OnEvent));
27 m_Window->SetVSync(false);
28
29 m_ImGuiLayer = new ImGuiLayer();
31
32 m_Settings = CreateScope<ApplicationSettings>(ApplicationSettings());
33 m_Settings->ApplicationName = name;
34 m_Settings->Width = m_Window->GetWidth();
35 m_Settings->Height = m_Window->GetHeight();
36
37 MutoResult result = InitFileSystem();
38 if (!result.IsSuccess())
39 {
40 MU_CORE_ERROR("Application::InitFileSystem() was not successful. Message: {0}", result.ResultMessage);
41 MU_CORE_ASSERT(false, result.ReturnError());
42 }
43
44 // Init the renderer at the end to ensure pathing has been setup correctly for any resources that may be needed during initialization.
46 }
#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_FUNCTION()
Definition Instrumentor.h:240
#define MU_CORE_ERROR(...)
error: indicates an error that has occurred
Definition Log.h:42
void OnEvent(Event &e)
Handles incoming events and dispatches them to the appropriate handlers.
Definition Application.cpp:108
void PushOverlay(Layer *overlay)
Adds an overlay layer to the application layer stack.
Definition Application.cpp:96
Scope< ApplicationSettings > m_Settings
Scoped pointer to the application settings.
Definition Application.h:174
static Application * s_Instance
Definition Application.h:177
ImGuiLayer * m_ImGuiLayer
ImGui layer for rendering GUI elements.
Definition Application.h:159
Scope< Window > m_Window
Scoped pointer to the applications underlying window.
Definition Application.h:156
MutoResult InitFileSystem()
Initializes the file system for the application.
Definition Application.cpp:295
static void Init()
Initializes the renderer.
Definition Renderer.cpp:16
static Scope< Window > Create(const WindowProps &props=WindowProps())
Creates a window instance with the specified properties.
Definition WindowsWindow.cpp:20
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51

References Muto::ImGuiLayer::ImGuiLayer(), Muto::Renderer::Init(), InitFileSystem(), Muto::MutoResult::IsSuccess(), m_ImGuiLayer, PushOverlay(), Muto::MutoResult::ResultMessage, and s_Instance.

◆ Application() [2/2]

Muto::Application::Application ( ApplicationSettings  settings)

Constructs the Application with the given settings.

Parameters
settingsThe settings to configure the application.
49 {
51 MU_CORE_ASSERT(!s_Instance, "Application already exists!");
52 s_Instance = this;
53
54 m_Window = Window::Create(WindowProps(settings.ApplicationName, settings.Width, settings.Height));
55 m_Window->SetEventCallback(BIND_EVENT_FN(OnEvent));
56 m_Window->SetVSync(settings.EnableVSync);
57
59 if (m_Settings->RendererAPIType == RenderAPI::API::RAPI_None)
60 {
61 m_Settings->EnableImGui = false;
62 MU_CORE_WARN("RenderAPI is set to None, disabling ImGui.");
63 }
64 if (m_Settings->EnableImGui)
65 {
66 m_ImGuiLayer = new ImGuiLayer();
68 }
69 else
70 {
71 m_ImGuiLayer = nullptr;
72 }
73
74 MutoResult result = InitFileSystem(*m_Settings);
75 if (!result.IsSuccess())
76 {
77 MU_CORE_ERROR("Application::InitFileSystem( *m_Settings ) was not successful. Message: {0}", result.ResultMessage);
78 MU_CORE_ASSERT(false, result.ReturnError());
79 }
80
81 // Init the renderer at the end to ensure pathing has been setup correctly for any resources that may be needed during initialization.
83 }
#define MU_CORE_WARN(...)
warn: indicates a potential issue or important event
Definition Log.h:40

References Muto::ImGuiLayer::ImGuiLayer(), Muto::Renderer::Init(), Muto::MutoResult::IsSuccess(), m_ImGuiLayer, PushOverlay(), Muto::MutoResult::ResultMessage, and s_Instance.

Referenced by SandboxApp::SandboxApp().

◆ ~Application()

Muto::Application::~Application ( )
virtual
86 {
87 }

Member Function Documentation

◆ Close()

void Muto::Application::Close ( )

Closes the application.

104 {
105 m_Running = false;
106 }
bool m_Running
Flag indicating whether the application is running.
Definition Application.h:162

References m_Running.

Referenced by Muto::EditorLayer::OnImGuiRender().

◆ Get()

◆ GetImGuiLayer()

ImGuiLayer * Muto::Application::GetImGuiLayer ( )
inline

Retrieves the ImGui layer.

104{ return m_ImGuiLayer; }

References m_ImGuiLayer.

Referenced by Muto::EditorLayer::OnImGuiRender().

◆ GetSettings() [1/2]

ApplicationSettings & Muto::Application::GetSettings ( )
inline

Retrieves the application settings.

113{ return *m_Settings; }

◆ GetSettings() [2/2]

const ApplicationSettings & Muto::Application::GetSettings ( ) const
inline

Retrieves the application settings as a const reference.

116{ return *m_Settings; }

◆ GetWindow()

Window & Muto::Application::GetWindow ( )
inline

◆ InitFileSystem() [1/2]

MutoResult Muto::Application::InitFileSystem ( )
private

Initializes the file system for the application.

Ensure working directory exists

Ensure project directory exists

Ensure assets directory exists

Ensure working directory exists

Ensure project directory exists

Ensure assets directory exists

296 {
297 MutoResult result;
298
299 if (GW::GReturn::SUCCESS != m_Settings->FileSystem.Create())
300 {
301 result = MutoResult(MU_RETURN::FAILURE, "Failed to create file system.");
302 MU_CORE_ERROR("Failed to create file system.");
303 return result;
304 }
305
306 char currentWorkingDirectory[255];
307 if (GW::GReturn::SUCCESS != m_Settings->FileSystem.GetCurrentWorkingDirectory(currentWorkingDirectory, sizeof(currentWorkingDirectory)))
308 {
309 result = MutoResult(MU_RETURN::FAILURE, "Failed to get current working directory.");
310 MU_CORE_ERROR("Failed to get current working directory.");
311 return result;
312 }
313 else
314 {
316 MU_CORE_INFO("Current working directory: {0}", m_Settings->WorkingDirectory);
317 }
318
319
321 std::filesystem::path workDir = m_Settings->WorkingDirectory;
322 if (!std::filesystem::exists(workDir))
323 {
324 result = MutoResult(MU_RETURN::FAILURE, "Working directory does not exist.");
325 MU_CORE_ERROR("Working directory does not exist: {0}", m_Settings->WorkingDirectory);
326 return result;
327 }
328 else
329 {
330 MU_CORE_INFO("Working directory exists: {0}", m_Settings->WorkingDirectory);
331 }
332 if (!m_Settings->ProjectDirectory.empty() && !Muto::IsAbsolutePath(m_Settings->ProjectDirectory))
333 {
334 m_Settings->ProjectDirectory = Muto::JoinPaths(m_Settings->WorkingDirectory, m_Settings->ProjectDirectory);
335 MU_CORE_INFO("Resolved relative Project directory to: {0}", m_Settings->ProjectDirectory);
336 }
337
338
340 if (!m_Settings->WorkingDirectory.empty())
341 {
342 if (m_Settings->ProjectDirectory.empty())
343 {
344 m_Settings->ProjectDirectory = Muto::JoinPaths(m_Settings->WorkingDirectory, "Project");
345 MU_CORE_INFO("Project directory is: {0}", m_Settings->ProjectDirectory);
346 }
347
348 std::filesystem::path projDir = Muto::NormalizePath(m_Settings->ProjectDirectory);
349 if (!std::filesystem::exists(projDir))
350 {
351 if (std::filesystem::create_directories(projDir))
352 {
353 MU_CORE_INFO("Project directory created: {0}", m_Settings->ProjectDirectory);
354 }
355 else
356 {
357 result = MutoResult(MU_RETURN::FAILURE, "Failed to create project directory.");
358 MU_CORE_ERROR("Failed to create project directory: {0}", m_Settings->ProjectDirectory);
359 return result;
360 }
361 }
362 else
363 {
364 MU_CORE_INFO("Project directory already exists: {0}", m_Settings->ProjectDirectory);
365 }
366 }
367 else
368 {
369 MU_CORE_WARN("Working directory is empty, cannot create project directory path.");
370 }
371 if (!m_Settings->AssetsDirectory.empty() && !Muto::IsAbsolutePath(m_Settings->AssetsDirectory))
372 {
373 m_Settings->AssetsDirectory = Muto::JoinPaths(m_Settings->WorkingDirectory, m_Settings->AssetsDirectory);
374 MU_CORE_INFO("Resolved relative Assets directory to: {0}", m_Settings->AssetsDirectory);
375 }
376
377
379 if (m_Settings->AssetsDirectory.empty())
380 {
381 if (!m_Settings->ProjectDirectory.empty())
382 {
383 m_Settings->AssetsDirectory = Muto::JoinPaths(m_Settings->ProjectDirectory, "Assets");
384 MU_CORE_INFO("Assets directory is: {0}", m_Settings->AssetsDirectory);
385 }
386 else
387 {
388 MU_CORE_WARN("Project directory is empty, cannot create assets directory path.");
389 }
390 }
391
392 if (!m_Settings->AssetsDirectory.empty())
393 {
394 std::filesystem::path assetsDir = Muto::NormalizePath(m_Settings->AssetsDirectory);
395 if (!std::filesystem::exists(assetsDir))
396 {
397 if (std::filesystem::create_directories(assetsDir))
398 {
399 MU_CORE_INFO("Assets directory created: {0}", m_Settings->AssetsDirectory);
400 }
401 else
402 {
403 result = MutoResult(MU_RETURN::FAILURE, "Failed to create assets directory.");
404 MU_CORE_ERROR("Failed to create assets directory: {0}", m_Settings->AssetsDirectory);
405 return result;
406 }
407 }
408 else
409 {
410 MU_CORE_INFO("Assets directory already exists: {0}", m_Settings->AssetsDirectory);
411 }
412 }
413 return result;
414 }
#define MU_CORE_INFO(...)
info: general information about application flow
Definition Log.h:38
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

References Muto::FAILURE.

Referenced by Application().

◆ InitFileSystem() [2/2]

MutoResult Muto::Application::InitFileSystem ( ApplicationSettings &  Settings)
private

Initializes the file system for the application with the given settings.

Parameters
SettingsThe settings to configure the file system.

Ensure working directory exists

Ensure project directory exists

Ensure assets directory exists

Ensure working directory exists

Ensure project directory exists

Ensure assets directory exists

417 {
418 MutoResult result;
419 if (GW::GReturn::SUCCESS != settings.FileSystem.Create())
420 {
421 result = MutoResult(MU_RETURN::FAILURE, "Failed to create file system.");
422 MU_CORE_ERROR("Failed to create file system.");
423 return result;
424 }
425
426 char currentWorkingDirectory[255];
427 if (settings.WorkingDirectory.empty())
428 {
429 if (GW::GReturn::SUCCESS != settings.FileSystem.GetCurrentWorkingDirectory(currentWorkingDirectory, sizeof(currentWorkingDirectory)))
430 {
431 result = MutoResult(MU_RETURN::FAILURE, "Failed to get current working directory.");
432 MU_CORE_ERROR("Failed to get current working directory.");
433 return result;
434 }
435 else
436 {
438 MU_CORE_INFO("Current working directory: {0}", settings.WorkingDirectory);
439 }
440 }
441 else
442 {
443 if (GW::GReturn::SUCCESS != settings.FileSystem.SetCurrentWorkingDirectory(Muto::NormalizePath(settings.WorkingDirectory).c_str()))
444 {
445 result = MutoResult(MU_RETURN::FAILURE, "Failed to set current working directory.");
446 MU_CORE_ASSERT(false, "Failed to set current working directory.");
447 return result;
448 }
449 else
450 {
451 MU_CORE_INFO("Current working directory: {0}", settings.WorkingDirectory);
452 }
453 }
454
456 std::filesystem::path workDir = settings.WorkingDirectory;
457 if (!std::filesystem::exists(workDir))
458 {
459 result = MutoResult(MU_RETURN::FAILURE, "Working directory does not exist.");
460 MU_CORE_ERROR("Working directory does not exist: {0}", settings.WorkingDirectory);
461 return result;
462 }
463 else
464 {
465 MU_CORE_INFO("Working directory exists: {0}", settings.WorkingDirectory);
466 }
467 if (!settings.ProjectDirectory.empty() && !Muto::IsAbsolutePath(settings.ProjectDirectory))
468 {
469 settings.ProjectDirectory = Muto::JoinPaths(settings.WorkingDirectory, settings.ProjectDirectory);
470 MU_CORE_INFO("Resolved relative Project directory to: {0}", settings.ProjectDirectory);
471 }
472 if (settings.ProjectDirectory.empty())
473 {
474 settings.ProjectDirectory = Muto::JoinPaths(settings.WorkingDirectory, "Project");
475 MU_CORE_INFO("Project Directory is: {0}", settings.ProjectDirectory);
476 }
477 else
478 {
479 MU_CORE_INFO("Project Directory is: {0}", settings.ProjectDirectory);
480 }
481
483 std::filesystem::path projDir = settings.ProjectDirectory;
484 if (!std::filesystem::exists(projDir))
485 {
486 if (std::filesystem::create_directories(projDir))
487 {
488 MU_CORE_INFO("Project directory created: {0}", settings.ProjectDirectory);
489 }
490 else
491 {
492 result = MutoResult(MU_RETURN::FAILURE, "Failed to create project directory.");
493 MU_CORE_ERROR("Failed to create project directory: {0}", settings.ProjectDirectory);
494 return result;
495 }
496 }
497 else
498 {
499 MU_CORE_INFO("Project directory already exists: {0}", settings.ProjectDirectory);
500 }
501 if (!settings.AssetsDirectory.empty() && !Muto::IsAbsolutePath(settings.AssetsDirectory))
502 {
503 settings.AssetsDirectory = Muto::JoinPaths(settings.WorkingDirectory, settings.AssetsDirectory);
504 MU_CORE_INFO("Resolved relative Assets directory to: {0}", settings.AssetsDirectory);
505 }
506
507 if (settings.AssetsDirectory.empty())
508 {
509 settings.AssetsDirectory = Muto::JoinPaths(settings.ProjectDirectory, "Assets");
510 MU_CORE_INFO("Assets Directory was empty. It defaulted to: {0}", settings.AssetsDirectory);
511 }
512 else
513 {
514 MU_CORE_INFO("Assets Directory is: {0}", settings.AssetsDirectory);
515 }
517 std::filesystem::path assetsDir = settings.AssetsDirectory;
518 if (!std::filesystem::exists(assetsDir))
519 {
520 if (std::filesystem::create_directories(assetsDir))
521 {
522 MU_CORE_INFO("Assets directory created: {0}", settings.AssetsDirectory);
523 }
524 else
525 {
526 result = MutoResult(MU_RETURN::FAILURE, "Failed to create assets directory.");
527 MU_CORE_ERROR("Failed to create assets directory: {0}", settings.AssetsDirectory);
528 return result;
529 }
530 }
531 else
532 {
533 MU_CORE_INFO("Assets directory already exists: {0}", settings.AssetsDirectory);
534 }
535
536 return result;
537 }

References Muto::ApplicationSettings::AssetsDirectory, Muto::FAILURE, Muto::IsAbsolutePath(), Muto::JoinPaths(), Muto::NormalizePath(), Muto::ApplicationSettings::ProjectDirectory, and Muto::ApplicationSettings::WorkingDirectory.

◆ OnEvent()

void Muto::Application::OnEvent ( Event &  e)

Handles incoming events and dispatches them to the appropriate handlers.

109 {
111 EventDispatcher dispatcher(e);
112 dispatcher.Dispatch<WindowCloseEvent>(BIND_EVENT_FN(OnWindowClose));
113 dispatcher.Dispatch<WindowResizeEvent>(BIND_EVENT_FN(OnWindowResize));
114
115 for (auto it = m_LayerStack.rbegin(); it != m_LayerStack.rend(); ++it)
116 {
117 if (e.Handled)
118 break;
119 (*it)->OnEvent(e);
120 }
121
122 }
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
LayerStack m_LayerStack
Stack of layers managed by the application.
Definition Application.h:168
std::vector< Layer * >::reverse_iterator rend()
Returns a reverse iterator to the end of the layer stack.
Definition LayerStack.h:48
std::vector< Layer * >::reverse_iterator rbegin()
Returns a reverse iterator to the beginning of the layer stack.
Definition LayerStack.h:46

References Muto::EventDispatcher::EventDispatcher(), Muto::Event::Handled, OnWindowClose(), and OnWindowResize().

◆ OnWindowClose()

bool Muto::Application::OnWindowClose ( WindowCloseEvent &  e)
private

Event handler for window close events.

273 {
275 m_Running = false;
276 return true;
277 }

References m_Running.

Referenced by OnEvent().

◆ OnWindowResize()

bool Muto::Application::OnWindowResize ( WindowResizeEvent &  e)
private

Event handler for window resize events.

280 {
282 if (e.GetWidth() == 0 || e.GetHeight() == 0)
283 {
284 m_Minimized = true;
285 return false;
286 }
287
288 m_Minimized = false;
289 Renderer::OnWindowResize(e.GetWidth(), e.GetHeight());
290 m_Settings->Width = e.GetWidth();
291 m_Settings->Height = e.GetHeight();
292 return false;
293 }
bool m_Minimized
Flag indicating whether the application is minimized.
Definition Application.h:165
static void OnWindowResize(uint32_t width, uint32_t height)
Handles window resize events by resizing the viewport.
Definition Renderer.cpp:24

References Muto::WindowResizeEvent::GetHeight(), Muto::WindowResizeEvent::GetWidth(), m_Minimized, and Muto::Renderer::OnWindowResize().

Referenced by OnEvent().

◆ PushLayer()

void Muto::Application::PushLayer ( Layer *  layer)

Adds a layer to the application layer stack.

90 {
93 layer->OnAttach();
94 }
void PushLayer(Layer *layer)
Adds the layer to the stack at the position before the first overlay.
Definition LayerStack.cpp:19

References Muto::Layer::OnAttach().

Referenced by Muto::Mutare::Mutare(), SandboxApp::SandboxApp(), and SandboxApp::SandboxApp().

◆ PushOverlay()

void Muto::Application::PushOverlay ( Layer *  overlay)

Adds an overlay layer to the application layer stack.

97 {
100 overlay->OnAttach();
101 }
void PushOverlay(Layer *overlay)
Pushes the overlay layer on top of all other layers.
Definition LayerStack.cpp:26

References Muto::Layer::OnAttach().

Referenced by Application(), and Application().

◆ ResolvePath()

std::string Muto::Application::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.

Parameters
PathThe path to the resource.
ModeThe mode to use for resolving the path. Defaults to PathResolveMode::AssetsDirectory.
167 {
168 if (path.empty())
169 {
170 MU_CORE_WARN("ResolvePath called with empty path.");
171 return std::string();
172 }
173
174 std::string resolvedPath;
175 switch (mode)
176 {
179 break;
182 break;
185 break;
186 default:
187 MU_CORE_WARN("ResolvePath called with unknown PathResolveMode.");
188 resolvedPath = std::string();
189 break;
190 }
191 return resolvedPath;
192 }
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
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
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

References Muto::AssetsDirectory, Muto::ProjectDirectory, ResolvePath_AssetsDirectory(), ResolvePath_ProjectDirectory(), ResolvePath_WorkingDirectory(), and Muto::WorkingDirectory.

Referenced by Muto::Renderer2D::Init(), and Muto::ImGuiLayer::OnAttach().

◆ ResolvePath_AssetsDirectory()

std::string Muto::Application::ResolvePath_AssetsDirectory ( const std::string &  Path) const
private

Resolves the full path to a resource based on the application's assets directory.

Parameters
PathThe path to the resource.
247 {
248 std::string resultPath;
249
250 if (m_Settings->AssetsDirectory.empty())
251 {
252 MU_CORE_WARN("AssetsDirectory is empty, cannot resolve path.");
253 return std::string();
254 }
255
256 if (path.empty())
257 {
258 MU_CORE_WARN("ResolvePath_AssetsDirectory called with empty path.");
259 return std::string();
260 }
261
263 {
264 MU_CORE_WARN("ResolvePath_AssetsDirectory called with an absolute path: {0}", path);
266 }
267
268 resultPath = Muto::JoinPaths(m_Settings->AssetsDirectory, path);
269 return resultPath;
270 }

References Muto::IsAbsolutePath(), and Muto::NormalizePath().

Referenced by ResolvePath().

◆ ResolvePath_ProjectDirectory()

std::string Muto::Application::ResolvePath_ProjectDirectory ( const std::string &  Path) const
private

Resolves the full path to a resource based on the application's project directory.

Parameters
PathThe path to the resource.
221 {
222 std::string resultPath;
223
224 if (m_Settings->ProjectDirectory.empty())
225 {
226 MU_CORE_WARN("ProjectDirectory is empty, cannot resolve path.");
227 return std::string();
228 }
229
230 if (path.empty())
231 {
232 MU_CORE_WARN("ResolvePath_ProjectDirectory called with empty path.");
233 return std::string();
234 }
235
237 {
238 MU_CORE_WARN("ResolvePath_ProjectDirectory called with an absolute path: {0}", path);
240 }
241
242 resultPath = Muto::JoinPaths(m_Settings->ProjectDirectory, path);
243 return resultPath;
244 }

References Muto::IsAbsolutePath(), and Muto::NormalizePath().

Referenced by ResolvePath().

◆ ResolvePath_WorkingDirectory()

std::string Muto::Application::ResolvePath_WorkingDirectory ( const std::string &  Path) const
private

Resolves the full path to a resource based on the application's working directory.

Parameters
PathThe path to the resource.
195 {
196 std::string resultPath;
197
198 if (m_Settings->WorkingDirectory.empty())
199 {
200 MU_CORE_WARN("WorkingDirectory is empty, cannot resolve path.");
201 return std::string();
202 }
203
204 if (path.empty())
205 {
206 MU_CORE_WARN("ResolvePath_WorkingDirectory called with empty path.");
207 return std::string();
208 }
209
211 {
212 MU_CORE_WARN("ResolvePath_WorkingDirectory called with an absolute path: {0}", path);
214 }
215
216 resultPath = Muto::JoinPaths(m_Settings->WorkingDirectory, path);
217 return resultPath;
218 }

References Muto::IsAbsolutePath(), and Muto::NormalizePath().

Referenced by ResolvePath().

◆ Run()

void Muto::Application::Run ( )

Starts the main application loop.

Todo:

Add Layer rendering into the main loop

Add separate threads for rendering and updating

Todo:
split the Run function into separate functions for update and render, and add a thread for each
Todo:
split the Run function into separate functions for update and render, and add a thread for each
Todo:
Platform::GetTime()
Todo:
Sort layers

Update layers

ImGui render layers

Todo:
Add a Layer render function and call it here for all Layers

Update window second

Todo:
Platform::GetTime()
Todo:
Sort layers

Update layers

ImGui render layers

Todo:
Add a Layer render function and call it here for all Layers

Update window second

126 {
128 while (m_Running)
129 {
130 MU_PROFILE_SCOPE("RunLoop");
132 float time = (float)glfwGetTime();
133 Timestep timestep = time - m_LastFrameTime;
135
136 if (!m_Minimized)
137 {
138 MU_PROFILE_SCOPE("LayerStack OnUpdate");
139
141
143 for (auto layer : m_LayerStack)
144 layer->OnUpdate(timestep);
145 }
146
147 {
148 MU_PROFILE_SCOPE("ImGuiLayer OnImGuiRender");
151 for (auto layer : m_LayerStack)
152 layer->OnImGuiRender();
153 m_ImGuiLayer->End();
154 }
155
157
158 {
159 MU_PROFILE_SCOPE("Window OnUpdate");
161 m_Window->OnUpdate();
162 }
163 };
164 }
#define MU_PROFILE_SCOPE(name)
Definition Instrumentor.h:239
float m_LastFrameTime
Time of the last frame, used for calculating timestep.
Definition Application.h:171
virtual void End()
Definition ImGuiLayer.cpp:111
virtual void Begin()
Definition ImGuiLayer.cpp:102

References Muto::ImGuiLayer::Begin(), Muto::ImGuiLayer::End(), m_ImGuiLayer, m_LastFrameTime, m_Minimized, and m_Running.

Member Data Documentation

◆ m_ImGuiLayer

ImGuiLayer* Muto::Application::m_ImGuiLayer
private

ImGui layer for rendering GUI elements.

Referenced by Application(), Application(), GetImGuiLayer(), and Run().

◆ m_LastFrameTime

float Muto::Application::m_LastFrameTime = 0.0f
private

Time of the last frame, used for calculating timestep.

Referenced by Run().

◆ m_LayerStack

LayerStack Muto::Application::m_LayerStack
private

Stack of layers managed by the application.

◆ m_Minimized

bool Muto::Application::m_Minimized = false
private

Flag indicating whether the application is minimized.

Referenced by OnWindowResize(), and Run().

◆ m_Running

bool Muto::Application::m_Running = true
private

Flag indicating whether the application is running.

Referenced by Close(), OnWindowClose(), and Run().

◆ m_Settings

Scope<ApplicationSettings> Muto::Application::m_Settings
private

Scoped pointer to the application settings.

◆ m_Window

Scope<Window> Muto::Application::m_Window
private

Scoped pointer to the applications underlying window.

◆ s_Instance

Application * Muto::Application::s_Instance = nullptr
staticprivate

Referenced by Application(), Application(), and Get().


The documentation for this class was generated from the following files: