Files
Aerofoil/GpShell/GpMain.cpp

146 lines
4.6 KiB
C++
Raw Permalink Normal View History

#include "GpMain.h"
2021-03-26 17:05:38 -04:00
#include "GpAppInterface.h"
#include "GpAudioDriverFactory.h"
#include "GpAudioDriverProperties.h"
#include "GpDisplayDriverFactory.h"
#include "GpDisplayDriverProperties.h"
2019-12-31 05:20:07 -05:00
#include "GpDisplayDriverTickStatus.h"
#include "GpFontHandlerFactory.h"
#include "GpFontHandlerProperties.h"
2019-12-29 17:39:19 -05:00
#include "GpInputDriverFactory.h"
#include "GpInputDriverProperties.h"
#include "GpGlobalConfig.h"
#include "GpAppEnvironment.h"
2021-04-28 01:46:07 -04:00
#include "IGpAllocator.h"
#include "IGpAudioDriver.h"
#include "IGpDisplayDriver.h"
2020-09-12 14:01:51 -04:00
#include "IGpFontHandler.h"
2019-12-29 17:39:19 -05:00
#include "IGpInputDriver.h"
2024-08-07 01:44:02 -04:00
#include "IGpLogDriver.h"
#include <string.h>
2019-12-29 17:39:19 -05:00
#include <stdlib.h>
namespace
{
2019-12-21 18:40:17 -05:00
void RenderAppEnvironment(void *context)
{
static_cast<GpAppEnvironment*>(context)->Render();
}
bool AdjustRequestedResolution(void *context, uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY)
{
return static_cast<GpAppEnvironment*>(context)->AdjustRequestedResolution(physicalWidth, physicalHeight, virtualWidth, virtualheight, pixelScaleX, pixelScaleY);
}
}
int GpMain::Run()
{
2019-12-24 02:35:24 -05:00
GpVOSEventQueue *eventQueue = new GpVOSEventQueue();
GpAppEnvironment *appEnvironment = new GpAppEnvironment();
2021-04-28 01:46:07 -04:00
IGpAllocator *alloc = g_gpGlobalConfig.m_allocator;
GpDisplayDriverProperties ddProps;
memset(&ddProps, 0, sizeof(ddProps));
ddProps.m_frameTimeLockNumerator = 1;
ddProps.m_frameTimeLockDenominator = 60;
// +/- 1% tolerance for frame time variance
ddProps.m_frameTimeLockMinNumerator = 99;
ddProps.m_frameTimeLockMinDenominator = 6000;
ddProps.m_frameTimeLockMaxNumerator = 101;
ddProps.m_frameTimeLockMaxDenominator = 6000;
2019-12-21 18:40:17 -05:00
ddProps.m_renderFunc = RenderAppEnvironment;
ddProps.m_renderFuncContext = appEnvironment;
ddProps.m_adjustRequestedResolutionFunc = AdjustRequestedResolution;
ddProps.m_adjustRequestedResolutionFuncContext = appEnvironment;
ddProps.m_type = g_gpGlobalConfig.m_displayDriverType;
2019-12-22 00:35:30 -05:00
ddProps.m_osGlobals = g_gpGlobalConfig.m_osGlobals;
2019-12-24 02:35:24 -05:00
ddProps.m_eventQueue = eventQueue;
ddProps.m_logger = g_gpGlobalConfig.m_logger;
ddProps.m_systemServices = g_gpGlobalConfig.m_systemServices;
2021-04-28 01:46:07 -04:00
ddProps.m_alloc = g_gpGlobalConfig.m_allocator;
GpAudioDriverProperties adProps;
memset(&adProps, 0, sizeof(adProps));
GpFontHandlerProperties fontProps;
memset(&fontProps, 0, sizeof(fontProps));
fontProps.m_type = g_gpGlobalConfig.m_fontHandlerType;
2021-04-28 01:46:07 -04:00
fontProps.m_alloc = g_gpGlobalConfig.m_allocator;
// The sample rate used in all of Glider PRO's sound is 0x56ee8ba3
// This appears to be the "standard" Mac sample rate, probably rounded from 244800/11.
2019-12-29 17:39:19 -05:00
adProps.m_type = g_gpGlobalConfig.m_audioDriverType;
adProps.m_sampleRate = (244800 * 2 + 11) / (11 * 2);
#if !GP_DEBUG_CONFIG
2020-03-01 17:01:35 -05:00
adProps.m_debug = false;
#else
adProps.m_debug = true;
2020-03-01 17:01:35 -05:00
#endif
adProps.m_logger = g_gpGlobalConfig.m_logger;
2020-09-28 09:58:19 -04:00
adProps.m_systemServices = g_gpGlobalConfig.m_systemServices;
2021-04-28 01:46:07 -04:00
adProps.m_alloc = g_gpGlobalConfig.m_allocator;
2021-04-28 01:46:07 -04:00
IGpInputDriver **inputDrivers = static_cast<IGpInputDriver**>(alloc->Alloc(sizeof(IGpInputDriver*) * g_gpGlobalConfig.m_numInputDrivers));
2019-12-29 17:39:19 -05:00
size_t numCreatedInputDrivers = 0;
if (inputDrivers)
{
for (size_t i = 0; i < g_gpGlobalConfig.m_numInputDrivers; i++)
{
GpInputDriverProperties inputProps;
memset(&inputProps, 0, sizeof(inputProps));
inputProps.m_type = g_gpGlobalConfig.m_inputDriverTypes[i];
inputProps.m_eventQueue = eventQueue;
2021-04-28 01:46:07 -04:00
inputProps.m_alloc = g_gpGlobalConfig.m_allocator;
2019-12-29 17:39:19 -05:00
if (IGpInputDriver *driver = GpInputDriverFactory::CreateInputDriver(inputProps))
inputDrivers[numCreatedInputDrivers++] = driver;
}
}
IGpDisplayDriver *displayDriver = GpDisplayDriverFactory::CreateDisplayDriver(ddProps);
IGpAudioDriver *audioDriver = GpAudioDriverFactory::CreateAudioDriver(adProps);
2020-09-12 14:01:51 -04:00
IGpFontHandler *fontHandler = GpFontHandlerFactory::CreateFontHandler(fontProps);
appEnvironment->Init();
appEnvironment->SetDisplayDriver(displayDriver);
appEnvironment->SetAudioDriver(audioDriver);
2019-12-29 17:39:19 -05:00
appEnvironment->SetInputDrivers(inputDrivers, numCreatedInputDrivers);
2019-12-21 18:40:17 -05:00
appEnvironment->SetFontHandler(fontHandler);
2019-12-24 02:35:24 -05:00
appEnvironment->SetVOSEventQueue(eventQueue);
appEnvironment->SetSystemServices(g_gpGlobalConfig.m_systemServices);
// Start the display loop
2024-08-07 01:44:02 -04:00
if (displayDriver->Init())
{
appEnvironment->Run();
}
else
{
IGpLogDriver *logger = g_gpGlobalConfig.m_logger;
if (logger)
logger->Printf(IGpLogDriver::Category_Error, "Failed to start display driver");
return -1;
}
2019-12-29 17:39:19 -05:00
// Clean up
if (inputDrivers)
{
for (size_t i = 0; i < numCreatedInputDrivers; i++)
inputDrivers[i]->Shutdown();
2021-04-28 01:46:07 -04:00
alloc->Release(inputDrivers);
2019-12-29 17:39:19 -05:00
}
return 0;
}