63 lines
1.6 KiB
C++
63 lines
1.6 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 )->destroy( *renderDevice );
|
|
|
|
Take( renderDevice )->destroy();
|
|
SDL_DestroyWindow( Take( window ) );
|
|
}
|
|
|
|
AppState::AppState( SDL_Window* window, RenderDevice* renderDevice, MiscData* miscData )
|
|
: window{ window }, renderDevice{ renderDevice }, miscData{ miscData }, sprintfBuffer{ 0 }
|
|
{}
|
|
|
|
AppState* AppState_Create( 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;
|
|
}
|
|
|
|
RenderDevice* renderDevice = RenderDevice_Create( memory, { .window = window } );
|
|
if ( !renderDevice->isInit() )
|
|
{
|
|
SDL_LogError( SDL_LOG_CATEGORY_APPLICATION, "RenderDevice failed to init" );
|
|
SDL_DestroyWindow( window );
|
|
return nullptr;
|
|
}
|
|
|
|
auto* miscDataAllocation = memory->allocate( sizeof( MiscData ) );
|
|
|
|
MiscData* miscData = new ( miscDataAllocation ) MiscData{};
|
|
if ( !miscData->init( *renderDevice ) ) return nullptr;
|
|
|
|
auto* allocation = memory->allocate( sizeof( AppState ) );
|
|
AppState* appState = new ( allocation ) AppState{ window, renderDevice, miscData };
|
|
|
|
return appState;
|
|
}
|
|
|
|
AppState::~AppState()
|
|
{
|
|
ASSERT( !isInit() );
|
|
}
|