Files
Aerofoil/AerofoilX/GpMain_SDL_X.cpp

101 lines
3.1 KiB
C++
Raw Normal View History

2021-03-18 17:08:11 -04:00
#include "SDL.h"
#include "SDL_main.h"
#include "GpMain.h"
2021-04-28 20:06:51 +02:00
#include "GpAllocator_C.h"
2021-03-18 17:08:11 -04:00
#include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
#include "GpFileSystem_X.h"
#include "GpLogDriver_X.h"
#include "GpFontHandlerFactory.h"
#include "GpInputDriverFactory.h"
#include "GpAppInterface.h"
#include "GpSystemServices_X.h"
#include "GpVOSEvent.h"
#include "GpX.h"
#include "IGpFileSystem.h"
#include "IGpThreadEvent.h"
#include "IGpVOSEventQueue.h"
#include <string>
#ifdef __MACOS__
#include "MacInit.h"
#endif
2021-03-18 17:08:11 -04:00
GpXGlobals g_gpXGlobals;
IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProperties &properties);
IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties);
IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverProperties &properties);
2023-05-23 10:07:51 -04:00
#ifndef _WIN32
2021-04-11 14:07:16 +02:00
int main(int argc, char *argv[])
#else
2021-03-18 17:08:11 -04:00
SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[])
2021-04-11 14:07:16 +02:00
#endif
2021-03-18 17:08:11 -04:00
{
2021-04-27 10:38:09 -04:00
bool enableLogging = false;
for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-diagnostics"))
enableLogging = true;
}
2021-03-18 17:08:11 -04:00
#ifndef __MACOS__
2021-03-18 17:08:11 -04:00
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0)
#else
if (MacInit())
#endif
2021-03-18 17:08:11 -04:00
return -1;
GpFileSystem_X::GetInstance()->Init();
2021-04-27 10:38:09 -04:00
IGpLogDriver *logger = nullptr;
if (enableLogging)
{
GpLogDriver_X::Init();
logger = GpLogDriver_X::GetInstance();
}
2021-03-18 17:08:11 -04:00
GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_X::GetInstance());
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_X::GetInstance());
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_X::GetInstance());
2021-05-14 21:40:56 +02:00
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
2021-03-18 17:08:11 -04:00
g_gpGlobalConfig.m_displayDriverType = EGpDisplayDriverType_SDL_GL2;
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_SDL2;
2021-05-04 16:05:15 +02:00
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_None;
2021-03-18 17:08:11 -04:00
EGpInputDriverType inputDrivers[] =
{
EGpInputDriverType_SDL2_Gamepad
};
g_gpGlobalConfig.m_inputDriverTypes = inputDrivers;
g_gpGlobalConfig.m_numInputDrivers = sizeof(inputDrivers) / sizeof(inputDrivers[0]);
g_gpGlobalConfig.m_osGlobals = &g_gpXGlobals;
g_gpGlobalConfig.m_logger = logger;
g_gpGlobalConfig.m_systemServices = GpSystemServices_X::GetInstance();
2021-05-14 21:40:56 +02:00
g_gpGlobalConfig.m_allocator = GpAllocator_C::GetInstance();
2021-03-18 17:08:11 -04:00
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);
GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType_SDL2_Gamepad, GpDriver_CreateInputDriver_SDL2_Gamepad);
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "SDL environment configured, starting up");
int returnCode = GpMain::Run();
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "SDL environment exited with code %i, cleaning up", returnCode);
return returnCode;
}