69 lines
1.5 KiB
C++
69 lines
1.5 KiB
C++
#include "AppState.h"
|
|
|
|
#include <SDL3/SDL_log.h>
|
|
|
|
#include "GlobalMemory.h"
|
|
#include "MiscData.h"
|
|
#include "RenderDevice.h"
|
|
|
|
bool AppState::isInit() const
|
|
{
|
|
return window and renderDevice and renderDevice->isInit();
|
|
}
|
|
|
|
void AppState::destroy()
|
|
{
|
|
if (!isInit()) return;
|
|
|
|
renderDevice->waitIdle();
|
|
|
|
Take(miscData)->cleanup(*renderDevice);
|
|
|
|
Take(renderDevice)->destroy();
|
|
SDL_DestroyWindow(Take(window));
|
|
}
|
|
|
|
AppState::AppState(SDL_Window* window, RenderDevice* renderDevice, MiscData* miscData)
|
|
: window{ window }
|
|
, renderDevice{ renderDevice }
|
|
, miscData{ miscData } {
|
|
}
|
|
|
|
AppState* CreateAppState(GlobalMemory* memory, uint32_t const width, uint32_t const height)
|
|
{
|
|
SDL_Window* window = SDL_CreateWindow(
|
|
"Blaze Test",
|
|
static_cast<int>(width),
|
|
static_cast<int>(height),
|
|
SDL_WINDOW_VULKAN);
|
|
if (!window)
|
|
{
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", SDL_GetError());
|
|
return nullptr;
|
|
}
|
|
|
|
auto state = memory->getState();
|
|
RenderDevice* renderDevice = CreateRenderDevice(memory, { .window = window });
|
|
if (!renderDevice->isInit())
|
|
{
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "RenderDevice failed to init");
|
|
return nullptr;
|
|
}
|
|
(void)state;
|
|
|
|
auto* miscDataAllocation = memory->allocate(sizeof(MiscData));
|
|
|
|
MiscData* miscData = new(miscDataAllocation) MiscData{};
|
|
miscData->init(*renderDevice);
|
|
|
|
auto* allocation = memory->allocate(sizeof(AppState));
|
|
AppState* appState = new(allocation) AppState{ window, renderDevice, miscData };
|
|
|
|
return appState;
|
|
}
|
|
|
|
AppState::~AppState()
|
|
{
|
|
ASSERT(!isInit());
|
|
}
|