CONGE-2 Reworked the API for the application to move more of the logic and initialization to the Engine and just have the application specifics in Demo1
This commit is contained in:
parent
194ea8eeef
commit
829c7b5c52
@ -3,6 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "VulkanContext.h"
|
||||||
|
|
||||||
namespace ConjureEngine {
|
namespace ConjureEngine {
|
||||||
Application::Application(const ApplicationInfo &applicationInfo): m_applicationInfo(applicationInfo) {
|
Application::Application(const ApplicationInfo &applicationInfo): m_applicationInfo(applicationInfo) {
|
||||||
@ -15,7 +16,47 @@ namespace ConjureEngine {
|
|||||||
m_vkAppInfo.apiVersion = VK_API_VERSION_1_0;
|
m_vkAppInfo.apiVersion = VK_API_VERSION_1_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Application::Run() const { return 0; }
|
int Application::Run()
|
||||||
void Application::Tick(double deltaTime) const {}
|
{
|
||||||
|
// CREATE SDL WINDOW
|
||||||
|
Window window(this->m_applicationInfo.title.c_str(), m_applicationInfo.window);
|
||||||
|
|
||||||
|
// INIT VULKAN
|
||||||
|
VulkanContext vulkanContext;
|
||||||
|
vulkanContext.AttachTo(window.GetWindow(), this->m_vkAppInfo);
|
||||||
|
|
||||||
|
// INITIALIZATION OF THE WORLD
|
||||||
|
this->Awake();
|
||||||
|
this->Start();
|
||||||
|
|
||||||
|
// MAIN LOOP
|
||||||
|
bool running = true;
|
||||||
|
|
||||||
|
static uint64_t lastTick = SDL_GetTicks64(); // TIME IS IN MS
|
||||||
|
while (running) {
|
||||||
|
|
||||||
|
|
||||||
|
// HANDLE INPUTS HERE (CODE BELOW IS FROM A TUTORIAL)
|
||||||
|
SDL_Event windowEvent;
|
||||||
|
while (SDL_PollEvent(&windowEvent)) {
|
||||||
|
if (windowEvent.type == SDL_QUIT) {
|
||||||
|
running = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TICK SCENE HERE
|
||||||
|
const uint64_t currentTick = SDL_GetTicks64(); // TIME IS IN MS
|
||||||
|
const uint64_t deltaTime = currentTick - lastTick; // TIME IS IN MS
|
||||||
|
this->Tick(static_cast<double>(deltaTime)/1000.f);
|
||||||
|
|
||||||
|
// HANDLE PHYSICS HERE
|
||||||
|
lastTick = currentTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
// CLEANUP HERE
|
||||||
|
this->Destroy();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
} // ConjureEngine
|
} // ConjureEngine
|
||||||
|
|||||||
@ -23,9 +23,29 @@ namespace ConjureEngine {
|
|||||||
explicit Application(const ApplicationInfo &applicationInfo);
|
explicit Application(const ApplicationInfo &applicationInfo);
|
||||||
virtual ~Application() = default;
|
virtual ~Application() = default;
|
||||||
|
|
||||||
virtual int Run() const;
|
int Run();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First function call right after SDL and VULKAN are init
|
||||||
|
*/
|
||||||
|
virtual inline void Awake() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after awake is done
|
||||||
|
*/
|
||||||
|
virtual inline void Start() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called every frame after Start
|
||||||
|
* @param deltaTime Time in seconds since last call to Tick
|
||||||
|
*/
|
||||||
|
virtual inline void Tick(double deltaTime) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call when the application is being closed
|
||||||
|
*/
|
||||||
|
virtual inline void Destroy() {};
|
||||||
|
|
||||||
virtual void Tick(double deltaTime) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -4,14 +4,18 @@
|
|||||||
|
|
||||||
#include "VulkanContext.h"
|
#include "VulkanContext.h"
|
||||||
|
|
||||||
|
#include "Window.h"
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "vulkan/vulkan_metal.h"
|
#include "vulkan/vulkan_metal.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ConjureEngine {
|
namespace ConjureEngine {
|
||||||
VulkanContext::VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo)
|
VulkanContext::VulkanContext()= default;
|
||||||
|
|
||||||
|
void VulkanContext::AttachTo(SDL_Window* window, const VkApplicationInfo& appInfo)
|
||||||
{
|
{
|
||||||
// LOAD THE EXTENSIONS
|
// LOAD THE EXTENSIONS
|
||||||
SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, nullptr);
|
SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, nullptr);
|
||||||
m_extensionNames.reserve(m_extensionCount);
|
m_extensionNames.reserve(m_extensionCount);
|
||||||
SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, m_extensionNames.data());
|
SDL_Vulkan_GetInstanceExtensions(window, &m_extensionCount, m_extensionNames.data());
|
||||||
|
|||||||
@ -9,8 +9,10 @@ namespace ConjureEngine {
|
|||||||
|
|
||||||
class VulkanContext {
|
class VulkanContext {
|
||||||
public:
|
public:
|
||||||
explicit VulkanContext(SDL_Window* window, const VkApplicationInfo& appInfo);
|
explicit VulkanContext();
|
||||||
~VulkanContext();
|
~VulkanContext();
|
||||||
|
void AttachTo(SDL_Window* window, const VkApplicationInfo& appInfo);
|
||||||
|
private:
|
||||||
void EnableGlobalExtentions(SDL_Window* window, VkInstanceCreateInfo &vulkanInfos);
|
void EnableGlobalExtentions(SDL_Window* window, VkInstanceCreateInfo &vulkanInfos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@ -19,31 +19,24 @@ static ConjureEngine::ApplicationInfo appInfo = ConjureEngine::ApplicationInfo
|
|||||||
namespace Demo1 {
|
namespace Demo1 {
|
||||||
Demo1::Demo1(): ConjureEngine::Application(appInfo) {}
|
Demo1::Demo1(): ConjureEngine::Application(appInfo) {}
|
||||||
|
|
||||||
|
void Demo1::Awake()
|
||||||
int Demo1::Run() const {
|
{
|
||||||
ConjureEngine::Window window(appInfo.title.c_str(), m_applicationInfo.window);
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"[DEMO1 - TRACE] - AWAKING");
|
||||||
|
|
||||||
// INIT VULKAN
|
|
||||||
ConjureEngine::VulkanContext vulkanContext(window.GetWindow(), this->m_vkAppInfo);
|
|
||||||
|
|
||||||
bool running = true;
|
|
||||||
while (running) {
|
|
||||||
SDL_Event windowEvent;
|
|
||||||
uint64_t timeSinceStart = SDL_GetTicks64();
|
|
||||||
|
|
||||||
while (SDL_PollEvent(&windowEvent)) {
|
|
||||||
if (windowEvent.type == SDL_QUIT) {
|
|
||||||
running = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->Tick((double)timeSinceStart/1000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Demo1::Tick(double deltaTime) const {}
|
void Demo1::Start()
|
||||||
|
{
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"[DEMO1 - TRACE] - STARTING");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Demo1::Tick(double deltaTime)
|
||||||
|
{
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[DEMO1 - TRACE] - TICKING %f", deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Demo1::Destroy()
|
||||||
|
{
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,"[DEMO1 - TRACE] - DESTROYING");
|
||||||
|
}
|
||||||
|
|
||||||
} // Demo1
|
} // Demo1
|
||||||
|
|||||||
@ -10,8 +10,10 @@ namespace Demo1 {
|
|||||||
class Demo1: public ConjureEngine::Application {
|
class Demo1: public ConjureEngine::Application {
|
||||||
public:
|
public:
|
||||||
Demo1();
|
Demo1();
|
||||||
int Run() const override;
|
void Awake() override;
|
||||||
void Tick(double deltaTime) const override;
|
void Start() override;
|
||||||
|
void Tick(double deltaTime) override;
|
||||||
|
void Destroy() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Demo1
|
} // Demo1
|
||||||
@ -6,7 +6,9 @@ int main ( int argc, char* argv[] )
|
|||||||
{
|
{
|
||||||
SDL_SetMainReady();
|
SDL_SetMainReady();
|
||||||
|
|
||||||
const Demo1::Demo1 app;
|
// I WANT TO CREATE AN APP
|
||||||
|
Demo1::Demo1 app;
|
||||||
|
|
||||||
|
// AND THEN START IT
|
||||||
return app.Run();
|
return app.Run();
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user