Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
abhayMore authored Aug 14, 2024
2 parents 71e83b6 + 9d4e7ae commit 67cb1d9
Show file tree
Hide file tree
Showing 73 changed files with 4,161 additions and 4,590 deletions.
34 changes: 0 additions & 34 deletions .clang-format

This file was deleted.

7 changes: 5 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@ jobs:
- name: Build Visualizer
run: xmake --all --yes

# - name: Run tests
# run: xmake test */compile_pass
- name: Run compile tests
run: xmake test */compile_pass

- name: Run tests
run: xmake test */run_5_seconds
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml

This file was deleted.

254 changes: 129 additions & 125 deletions Core/Application/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,138 +1,142 @@
#include "Application.h"
#include <SDL2/SDL.h>
#include "SDL_scancode.h"
#include <chrono>
#include <SDL2/SDL.h>

namespace CGL::Core
{
CGL_DEFINE_LOG_CATEGORY(CoreApp);

bool g_isTestMode{ false };

Application::Application(std::string_view name, i32 argc, char** argv)
: m_isRunning(true)
, m_name(name)
, m_window(nullptr)
{
// Parse command line arguments
for (int i = 1; i < argc; ++i)
{
if (std::string(argv[i]) == "-test")
{
CGL_LOG(CoreApp, Info, "Running Visualizer in test mode");
m_name.append(" - TEST");
g_isTestMode = true;
}
}

if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
std::string err(SDL_GetError());
CGL_LOG(CoreApp, Error, "Failed to initialize SDL: {}", err);
}
else
{
CGL_LOG(CoreApp, Trace, "Core aplication created");
}
}

void Application::Run()
{
CGL_LOG(CoreApp, Trace, "Running application");

auto startTime = std::chrono::steady_clock::now();
OnInit();

SDL_Event e;
while (m_isRunning)
{
// Handle events on queue
while (SDL_PollEvent(&e) != 0)
{
// User requests quit
if (e.type == SDL_QUIT || e.key.keysym.scancode == SDL_SCANCODE_ESCAPE)
{
m_isRunning = false;
}
else if (e.type == SDL_WINDOWEVENT)
{
switch (e.window.event)
{
case SDL_WINDOWEVENT_RESIZED:
OnResize(e.window.data1, e.window.data2);
break;
}
}
}

OnUpdate(e);

// Call begin and end frame before calling render itself
m_renderer->BeginFrame();
OnRender();
m_renderer->EndFrame();

// Check for test mode and elapsed time
if (g_isTestMode)
{
auto currentTime = std::chrono::steady_clock::now();
auto elapsedTime = std::chrono::duration_cast<std::chrono::seconds>(currentTime - startTime).count();
if (elapsedTime >= 5) // Run for 5 Seconds
{
CGL_LOG(CoreApp, Info, "Test run completed after 5 seconds. Shutting Down...");
m_isRunning = false;
}
}
}
OnShutdown();
}
CGL_DEFINE_LOG_CATEGORY(CoreApp);

bool g_isTestMode{ false };

Application::Application(std::string_view name, i32 argc, char** argv)
: m_name(name)
, m_isRunning(true)
, m_window(nullptr)
{
// Parse command line arguments
for (int i = 1; i < argc; ++i)
{
if (std::string(argv[i]) == "-test")
{
CGL_LOG(CoreApp, Info, "Running Visualizer in test mode");
m_name.append(" - TEST");
g_isTestMode = true;
}
}

if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
std::string err(SDL_GetError());
CGL_LOG(CoreApp, Error, "Failed to initialize SDL: {}", err);
}
else
{
CGL_LOG(CoreApp, Trace, "Core aplication created");
}

}

void Application::Run()
{
CGL_LOG(CoreApp, Trace, "Running application");

auto startTime = std::chrono::steady_clock::now();
OnInit();

SDL_Event e;
while (m_isRunning)
{
// Handle events on queue
while (SDL_PollEvent(&e) != 0)
{
// User requests quit
if (e.type == SDL_QUIT || e.key.keysym.scancode == SDL_SCANCODE_ESCAPE)
{
m_isRunning = false;
}
else if (e.type == SDL_WINDOWEVENT)
{
switch (e.window.event)
{
case SDL_WINDOWEVENT_RESIZED:
OnResize(e.window.data1, e.window.data2);
break;
}
}
}

OnUpdate(e);

// Call begin and end frame before calling render itself
m_renderer->BeginFrame();
OnRender();
m_renderer->EndFrame();

// Check for test mode and elapsed time
if (g_isTestMode)
{
auto currentTime = std::chrono::steady_clock::now();
auto elapsedTime = std::chrono::duration_cast<std::chrono::seconds>(currentTime - startTime).count();
if (elapsedTime >= 5) // Run for 5 Seconds
{
CGL_LOG(CoreApp, Info, "Test run completed after 5 seconds. Shutting Down...");
m_isRunning = false;
}
}
}

OnShutdown();
}

bool Application::OnInit()
{
{
// Create SDL window
u32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
u32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;

#if defined(CGL_RHI_OPENGL)
flags |= SDL_WINDOW_OPENGL;
flags |= SDL_WINDOW_OPENGL;
#elif defined(CGL_RHI_VULKAN)
flags |= SDL_WINDOW_VULKAN;
flags |= SDL_WINDOW_VULKAN;
#elif defined(CGL_RHI_METAL)
flags |= SDL_WINDOW_METAL;
flags |= SDL_WINDOW_METAL;
#endif

m_window = SDL_CreateWindow(m_name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, flags);
if (!m_window)
{
std::string err(SDL_GetError());
CGL_LOG(CoreApp, Error, "Failed to create SDL window: {}", err);
return false;
}

// Create renderer
m_renderer = std::make_unique<Graphics::Renderer>(m_window);
if (!m_renderer)
{
CGL_LOG(CoreApp, Error, "Failed to create renderer");
return false;
}

CGL_LOG(CoreApp, Debug, "Core application initialized");
return true;
}

void Application::OnShutdown()
{
m_renderer.reset();

SDL_DestroyWindow(m_window);
SDL_Quit();

CGL_LOG(CoreApp, Debug, "Core application shutdown");
}

void Application::OnResize(u32 width, u32 height)
{
if (m_renderer)
{
m_renderer->Resize(width, height);
}
}
} // namespace CGL::Core
m_window = SDL_CreateWindow(m_name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, flags);
if (!m_window)
{
std::string err(SDL_GetError());
CGL_LOG(CoreApp, Error, "Failed to create SDL window: {}", err);
return false;
}

// Create renderer
m_renderer = std::make_unique<Graphics::Renderer>(m_window);
if (!m_renderer)
{
CGL_LOG(CoreApp, Error, "Failed to create renderer");
return false;
}

CGL_LOG(CoreApp, Debug, "Core application initialized");
return true;
}

void Application::OnShutdown()
{
m_renderer.reset();

SDL_DestroyWindow(m_window);
SDL_Quit();

CGL_LOG(CoreApp, Debug, "Core application shutdown");
}

void Application::OnResize(u32 width, u32 height)
{
if (m_renderer)
{
m_renderer->Resize(width, height);
}
}
}
48 changes: 24 additions & 24 deletions Core/Application/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ struct SDL_Window;

namespace CGL::Core
{
CGL_DECLARE_LOG_CATEGORY(CoreApp);
CGL_DECLARE_LOG_CATEGORY(CoreApp);

class Application
{
public:
public:
Application(std::string_view name, i32 argc, char** argv);
~Application() = default;
class Application
{
public:
public:
Application(std::string_view name, i32 argc, char** argv);
~Application() = default;

inline SDL_Window* GetWindow() const noexcept { return m_window; }
inline SDL_Window* GetWindow() const noexcept { return m_window; }

void Run();
void Run();

protected:
virtual bool OnInit();
virtual void OnUpdate(const SDL_Event& e) = 0;
virtual void OnRender() = 0;
virtual void OnShutdown();
virtual void OnResize(u32 width, u32 height);
protected:
virtual bool OnInit();
virtual void OnUpdate(const SDL_Event& e) = 0;
virtual void OnRender() = 0;
virtual void OnShutdown();
virtual void OnResize(u32 width, u32 height);

inline Graphics::Renderer* GetRenderer() const { return m_renderer.get(); }
inline Graphics::Renderer* GetRenderer() const { return m_renderer.get(); }

protected:
bool m_isRunning;
protected:
bool m_isRunning;

private:
std::string m_name;
SDL_Window* m_window;
std::unique_ptr<Graphics::Renderer> m_renderer;
};
} // namespace CGL::Core
private:
std::string m_name;
SDL_Window* m_window;
std::unique_ptr<Graphics::Renderer> m_renderer;
};
}
10 changes: 5 additions & 5 deletions Core/Application/AssetFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace CGL::Core
{
std::string DataToString(const byte* data, size_t size)
{
return std::string(reinterpret_cast<const char*>(data), size);
}
} // namespace CGL::Core
std::string DataToString(const byte* data, size_t size)
{
return std::string(reinterpret_cast<const char*>(data), size);
}
}
Loading

0 comments on commit 67cb1d9

Please sign in to comment.