Refactoring, clean up shutdown path

This commit is contained in:
elasota
2019-12-31 05:20:07 -05:00
parent 62438ab4f3
commit d9b5dd20d6
16 changed files with 123 additions and 86 deletions

View File

@@ -178,7 +178,7 @@ Boolean OpenHouse (void)
return(false); return(false);
#ifdef COMPILEDEMO #ifdef COMPILEDEMO
if (!EqualString(theHousesSpecs[thisHouseIndex].name, "\pDemo House", false, true)) if (!StrCmp::EqualCaseInsensitive(theHousesSpecs[thisHouseIndex].name, "\pDemo House"))
return (false); return (false);
#endif #endif
@@ -216,7 +216,7 @@ Boolean OpenSpecificHouse (const VFileSpec &specs)
for (i = 0; i < housesFound; i++) for (i = 0; i < housesFound; i++)
{ {
if ((theHousesSpecs[i].m_dir == specs.m_dir) && if ((theHousesSpecs[i].m_dir == specs.m_dir) &&
(EqualString(theHousesSpecs[i].m_name, specs.m_name, false, true))) (StrCmp::EqualCaseInsensitive(theHousesSpecs[i].m_name, specs.m_name)))
{ {
thisHouseIndex = i; thisHouseIndex = i;
PasStringCopy(theHousesSpecs[thisHouseIndex].m_name, thisHouseName); PasStringCopy(theHousesSpecs[thisHouseIndex].m_name, thisHouseName);

View File

@@ -805,7 +805,7 @@ void CountUntitledRooms (void)
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
if (((*thisHouse)->rooms[i].suite != kRoomIsEmpty) && if (((*thisHouse)->rooms[i].suite != kRoomIsEmpty) &&
(EqualString((*thisHouse)->rooms[i].name, PSTR("Untitled Room"), false, true))) (StrCmp::EqualCaseInsensitive((*thisHouse)->rooms[i].name, PSTR("Untitled Room"))))
houseErrors++; houseErrors++;
} }
} }

View File

@@ -226,7 +226,7 @@ return false; // TEMP fix this iwth NavServices
HLock((Handle)thisHouse); HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
if (!EqualString(savedGame->house.name, thisHouseName, true, true)) if (!StrCmp::Equal(savedGame->house.name, thisHouseName))
{ {
SavedGameMismatchError(savedGame->house.name); SavedGameMismatchError(savedGame->house.name);
HSetState((Handle)thisHouse, wasState); HSetState((Handle)thisHouse, wasState);

View File

@@ -533,7 +533,7 @@ void SortHouseList (void)
h = i + 1; h = i + 1;
while (h < housesFound) while (h < housesFound)
{ {
if ((EqualString(theHousesSpecs[i].m_name, theHousesSpecs[h].m_name, true, true)) && if ((StrCmp::Equal(theHousesSpecs[i].m_name, theHousesSpecs[h].m_name)) &&
(theHousesSpecs[i].m_dir == theHousesSpecs[i].m_dir)) (theHousesSpecs[i].m_dir == theHousesSpecs[i].m_dir))
{ {
theHousesSpecs[h] = theHousesSpecs[housesFound - 1]; theHousesSpecs[h] = theHousesSpecs[housesFound - 1];
@@ -616,7 +616,7 @@ void DoDirSearch (void)
thisHouseIndex = 0; thisHouseIndex = 0;
for (i = 0; i < housesFound; i++) for (i = 0; i < housesFound; i++)
{ {
if (EqualString(theHousesSpecs[i].m_name, thisHouseName, false, true)) if (StrCmp::Equal(theHousesSpecs[i].m_name, thisHouseName))
{ {
thisHouseIndex = i; thisHouseIndex = i;
break; break;
@@ -627,7 +627,7 @@ void DoDirSearch (void)
demoHouseIndex = -1; demoHouseIndex = -1;
for (i = 0; i < housesFound; i++) for (i = 0; i < housesFound; i++)
{ {
if (EqualString(theHousesSpecs[i].m_name, PSTR("Demo House"), false, true)) if (StrCmp::Equal(theHousesSpecs[i].m_name, PSTR("Demo House")))
{ {
demoHouseIndex = i; demoHouseIndex = i;
break; break;

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "EGpDisplayDriverType.h" #include "EGpDisplayDriverType.h"
#include "GpDisplayDriverTickStatus.h"
struct IGpDisplayDriver; struct IGpDisplayDriver;
struct IGpFiber; struct IGpFiber;
@@ -8,7 +9,7 @@ struct IGpVOSEventQueue;
struct GpDisplayDriverProperties struct GpDisplayDriverProperties
{ {
typedef void(*TickFunc_t)(void *context, IGpFiber *vosFiber); typedef GpDisplayDriverTickStatus_t (*TickFunc_t)(void *context, IGpFiber *vosFiber);
typedef void(*RenderFunc_t)(void *context); typedef void(*RenderFunc_t)(void *context);
EGpDisplayDriverType m_type; EGpDisplayDriverType m_type;

View File

@@ -0,0 +1,15 @@
#pragma once
namespace GpDisplayDriverTickStatuses
{
enum GpDisplayDriverTickStatus
{
kOK = 0,
kNonFatalFault = 1,
kFatalFault = 2,
kApplicationTerminated = 3,
};
}
typedef GpDisplayDriverTickStatuses::GpDisplayDriverTickStatus GpDisplayDriverTickStatus_t;

View File

@@ -1,10 +1,12 @@
#include "GpAppEnvironment.h" #include "GpAppEnvironment.h"
#include "GpFiberStarter.h" #include "GpFiberStarter.h"
#include "GpAppInterface.h" #include "GpAppInterface.h"
#include "GpDisplayDriverTickStatus.h"
#include "GpFontHandlerFactory.h" #include "GpFontHandlerFactory.h"
#include "GpPLGlueAudioDriver.h" #include "GpPLGlueAudioDriver.h"
#include "GpPLGlueDisplayDriver.h" #include "GpPLGlueDisplayDriver.h"
#include "HostSuspendCallArgument.h" #include "HostSuspendCallArgument.h"
#include "IGpDisplayDriver.h"
#include "IGpFiber.h" #include "IGpFiber.h"
#include "IGpInputDriver.h" #include "IGpInputDriver.h"
@@ -35,7 +37,7 @@ void GpAppEnvironment::Init()
{ {
} }
void GpAppEnvironment::Tick(IGpFiber *vosFiber) GpDisplayDriverTickStatus_t GpAppEnvironment::Tick(IGpFiber *vosFiber)
{ {
GpAppInterface_Get()->PL_IncrementTickCounter(1); GpAppInterface_Get()->PL_IncrementTickCounter(1);
@@ -54,7 +56,7 @@ void GpAppEnvironment::Tick(IGpFiber *vosFiber)
m_applicationState = ApplicationState_Running; m_applicationState = ApplicationState_Running;
break; break;
case ApplicationState_WaitingForEvents: case ApplicationState_WaitingForEvents:
return; return GpDisplayDriverTickStatuses::kOK;
case ApplicationState_Running: case ApplicationState_Running:
SynchronizeState(); SynchronizeState();
m_applicationFiber->YieldTo(); m_applicationFiber->YieldTo();
@@ -75,9 +77,13 @@ void GpAppEnvironment::Tick(IGpFiber *vosFiber)
else else
{ {
m_delaySuspendTicks--; m_delaySuspendTicks--;
return; return GpDisplayDriverTickStatuses::kOK;
} }
break; break;
case ApplicationState_Terminated:
m_applicationFiber->Destroy();
m_applicationFiber = nullptr;
return GpDisplayDriverTickStatuses::kApplicationTerminated;
default: default:
assert(false); assert(false);
break; break;
@@ -124,6 +130,9 @@ void GpAppEnvironment::StaticAppThreadFunc(void *context)
void GpAppEnvironment::AppThreadFunc() void GpAppEnvironment::AppThreadFunc()
{ {
GpAppInterface_Get()->ApplicationMain(); GpAppInterface_Get()->ApplicationMain();
m_applicationState = ApplicationState_Terminated;
m_vosFiber->YieldTo();
} }
void GpAppEnvironment::InitializeApplicationState() void GpAppEnvironment::InitializeApplicationState()

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "GpDisplayDriverTickStatus.h"
#include "GpVOSEventQueue.h" #include "GpVOSEventQueue.h"
#include "HostSuspendCallID.h" #include "HostSuspendCallID.h"
@@ -25,7 +26,7 @@ public:
void Init(); void Init();
void Tick(IGpFiber *vosFiber); GpDisplayDriverTickStatus_t Tick(IGpFiber *vosFiber);
void Render(); void Render();
void SetDisplayDriver(IGpDisplayDriver *displayDriver); void SetDisplayDriver(IGpDisplayDriver *displayDriver);

View File

@@ -169,6 +169,7 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="..\GpCommon\EGpInputDriverType.h" /> <ClInclude Include="..\GpCommon\EGpInputDriverType.h" />
<ClInclude Include="..\GpCommon\EGpStandardCursor.h" /> <ClInclude Include="..\GpCommon\EGpStandardCursor.h" />
<ClInclude Include="..\GpCommon\GpDisplayDriverTickStatus.h" />
<ClInclude Include="..\GpCommon\GpInputDriverProperties.h" /> <ClInclude Include="..\GpCommon\GpInputDriverProperties.h" />
<ClInclude Include="..\GpCommon\IGpColorCursor.h" /> <ClInclude Include="..\GpCommon\IGpColorCursor.h" />
<ClInclude Include="..\GpCommon\IGpAudioChannelCallbacks.h" /> <ClInclude Include="..\GpCommon\IGpAudioChannelCallbacks.h" />

View File

@@ -191,6 +191,9 @@
<ClInclude Include="..\GpCommon\GpInputDriverProperties.h"> <ClInclude Include="..\GpCommon\GpInputDriverProperties.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\GpCommon\GpDisplayDriverTickStatus.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="GpD3D.rc"> <ResourceCompile Include="GpD3D.rc">

View File

@@ -4,6 +4,7 @@
#include "GpFontHandlerFactory.h" #include "GpFontHandlerFactory.h"
#include "GpDisplayDriverFactory.h" #include "GpDisplayDriverFactory.h"
#include "GpDisplayDriverProperties.h" #include "GpDisplayDriverProperties.h"
#include "GpDisplayDriverTickStatus.h"
#include "GpInputDriverFactory.h" #include "GpInputDriverFactory.h"
#include "GpInputDriverProperties.h" #include "GpInputDriverProperties.h"
#include "GpGlobalConfig.h" #include "GpGlobalConfig.h"
@@ -17,9 +18,9 @@
namespace namespace
{ {
void TickAppEnvironment(void *context, IGpFiber *vosFiber) GpDisplayDriverTickStatus_t TickAppEnvironment(void *context, IGpFiber *vosFiber)
{ {
static_cast<GpAppEnvironment*>(context)->Tick(vosFiber); return static_cast<GpAppEnvironment*>(context)->Tick(vosFiber);
} }
void RenderAppEnvironment(void *context) void RenderAppEnvironment(void *context)

View File

@@ -309,7 +309,7 @@ bool GpDisplayDriverD3D11::InitResources()
} }
bool GpDisplayDriverD3D11::PresentFrameAndSync() GpDisplayDriverTickStatus_t GpDisplayDriverD3D11::PresentFrameAndSync()
{ {
SynchronizeCursors(); SynchronizeCursors();
@@ -341,16 +341,16 @@ bool GpDisplayDriverD3D11::PresentFrameAndSync()
UINT lastPresentCount = 0; UINT lastPresentCount = 0;
if (FAILED(m_swapChain->GetLastPresentCount(&lastPresentCount))) if (FAILED(m_swapChain->GetLastPresentCount(&lastPresentCount)))
return false; return GpDisplayDriverTickStatuses::kNonFatalFault;
if (FAILED(m_swapChain->Present1(1, 0, &presentParams))) if (FAILED(m_swapChain->Present1(1, 0, &presentParams)))
return false; return GpDisplayDriverTickStatuses::kNonFatalFault;
//DebugPrintf("r: %i\n", static_cast<int>(r)); //DebugPrintf("r: %i\n", static_cast<int>(r));
DXGI_FRAME_STATISTICS stats; DXGI_FRAME_STATISTICS stats;
if (FAILED(m_swapChain->GetFrameStatistics(&stats))) if (FAILED(m_swapChain->GetFrameStatistics(&stats)))
return false; return GpDisplayDriverTickStatuses::kNonFatalFault;
if (stats.SyncQPCTime.QuadPart != 0) if (stats.SyncQPCTime.QuadPart != 0)
{ {
@@ -440,12 +440,15 @@ bool GpDisplayDriverD3D11::PresentFrameAndSync()
m_frameTimeAccumulated += frameTimeStep; m_frameTimeAccumulated += frameTimeStep;
while (m_frameTimeAccumulated >= m_frameTimeSliceSize) while (m_frameTimeAccumulated >= m_frameTimeSliceSize)
{ {
m_properties.m_tickFunc(m_properties.m_tickFuncContext, m_vosFiber); GpDisplayDriverTickStatus_t tickStatus = m_properties.m_tickFunc(m_properties.m_tickFuncContext, m_vosFiber);
m_frameTimeAccumulated -= m_frameTimeSliceSize; m_frameTimeAccumulated -= m_frameTimeSliceSize;
if (tickStatus != GpDisplayDriverTickStatuses::kOK)
return tickStatus;
} }
} }
return true; return GpDisplayDriverTickStatuses::kOK;
} }
void GpDisplayDriverD3D11::SynchronizeCursors() void GpDisplayDriverD3D11::SynchronizeCursors()
@@ -591,7 +594,9 @@ void GpDisplayDriverD3D11::Run()
} }
else else
{ {
PresentFrameAndSync(); GpDisplayDriverTickStatus_t tickStatus = PresentFrameAndSync();
if (tickStatus == GpDisplayDriverTickStatuses::kFatalFault || tickStatus == GpDisplayDriverTickStatuses::kApplicationTerminated)
break;
} }
} }

View File

@@ -70,7 +70,7 @@ private:
~GpDisplayDriverD3D11(); ~GpDisplayDriverD3D11();
bool InitResources(); bool InitResources();
bool PresentFrameAndSync(); GpDisplayDriverTickStatus_t PresentFrameAndSync();
void SynchronizeCursors(); void SynchronizeCursors();
void ChangeToCursor(HCURSOR cursor); void ChangeToCursor(HCURSOR cursor);

View File

@@ -2,69 +2,59 @@
#include "MacRoman.h" #include "MacRoman.h"
#include <string.h> #include <string.h>
#include <algorithm>
Boolean EqualString(const PLPasStr &string1, const PLPasStr &string2, Boolean caseSensitive, Boolean diacriticSensitive) namespace StrCmp
{ {
const size_t len = string1.Length(); int Compare(const PLPasStr &string1, const PLPasStr &string2)
if (len != string2.Length())
return PL_FALSE;
const uint8_t *chars1 = string1.UChars();
const uint8_t *chars2 = string2.UChars();
if (caseSensitive)
{ {
// Case sensitive const uint8_t *chars1 = string1.UChars();
if (diacriticSensitive) const uint8_t *chars2 = string2.UChars();
{
// Diacritic sensitive const size_t len1 = string1.Length();
return memcmp(chars1, chars2, len) ? PL_FALSE : PL_TRUE; const size_t len2 = string1.Length();
}
const size_t shorterLen = std::min(len1, len2);
int memcmpResult = memcmp(chars1, chars2, shorterLen);
if (memcmpResult != 0)
return memcmpResult;
if (len1 < len2)
return -1;
else if (len2 < len1)
return 1;
else else
{ return 0;
// Diacritic insensitive
for (size_t i = 0; i < len; i++)
{
const uint8_t c1 = chars1[i];
const uint8_t c2 = chars2[i];
if (PortabilityLayer::MacRoman::g_stripDiacritic[c1] != PortabilityLayer::MacRoman::g_stripDiacritic[c2])
return PL_FALSE;
}
return PL_TRUE;
}
} }
else
int CompareCaseInsensitive(const PLPasStr &string1, const PLPasStr &string2)
{ {
// Case insensitive const uint8_t *chars1 = string1.UChars();
if (diacriticSensitive) const uint8_t *chars2 = string2.UChars();
const size_t len1 = string1.Length();
const size_t len2 = string1.Length();
const size_t shorterLen = std::min(len1, len2);
for (size_t i = 0; i < shorterLen; i++)
{ {
// Diacritic sensitive const uint8_t c1 = PortabilityLayer::MacRoman::g_toLower[chars1[i]];
for (size_t i = 0; i < len; i++) const uint8_t c2 = PortabilityLayer::MacRoman::g_toLower[chars2[i]];
{
const uint8_t c1 = chars1[i];
const uint8_t c2 = chars2[i];
if (PortabilityLayer::MacRoman::g_toLower[c1] != PortabilityLayer::MacRoman::g_toLower[c2]) if (c1 < c2)
return PL_FALSE; return -1;
} if (c2 < c1)
return 1;
return PL_TRUE;
} }
if (len1 < len2)
return -1;
else if (len2 < len1)
return 1;
else else
{ return 0;
// Diacritic insensitive
for (size_t i = 0; i < len; i++)
{
const uint8_t c1 = PortabilityLayer::MacRoman::g_stripDiacritic[chars1[i]];
const uint8_t c2 = PortabilityLayer::MacRoman::g_stripDiacritic[chars2[i]];
if (PortabilityLayer::MacRoman::g_toLower[c1] != PortabilityLayer::MacRoman::g_toLower[c2])
return PL_FALSE;
}
return PL_TRUE;
}
} }
} }

View File

@@ -1,10 +1,20 @@
#pragma once #pragma once
#ifndef __PL_STRINGCOMPARE_H__
#define __PL_STRINGCOMPARE_H__
#include "PLCore.h" #include "PLCore.h"
#include "PLPasStr.h" #include "PLPasStr.h"
Boolean EqualString(const PLPasStr &string1, const PLPasStr &string2, Boolean caseSensitive, Boolean diacriticSensitive); namespace StrCmp
{
int CompareCaseInsensitive(const PLPasStr &string1, const PLPasStr &string2);
int Compare(const PLPasStr &string1, const PLPasStr &string2);
#endif inline bool EqualCaseInsensitive(const PLPasStr &string1, const PLPasStr &string2)
{
return CompareCaseInsensitive(string1, string2) == 0;
}
inline bool Equal(const PLPasStr &string1, const PLPasStr &string2)
{
return Compare(string1, string2) == 0;
}
}

View File

@@ -73,7 +73,8 @@ namespace PortabilityLayer
WindowImpl *m_windowStackBottom; WindowImpl *m_windowStackBottom;
static WindowManagerImpl ms_instance; static WindowManagerImpl ms_instance;
static Window ms_putInFront;
static uint8_t ms_putInFrontSentinel;
}; };
WindowImpl::WindowImpl() WindowImpl::WindowImpl()
@@ -335,7 +336,7 @@ namespace PortabilityLayer
Window *WindowManagerImpl::GetPutInFrontSentinel() const Window *WindowManagerImpl::GetPutInFrontSentinel() const
{ {
return &ms_putInFront; return reinterpret_cast<Window*>(&ms_putInFrontSentinel);
} }
void WindowManagerImpl::RenderWindow(WindowImpl *window, IGpDisplayDriver *displayDriver) void WindowManagerImpl::RenderWindow(WindowImpl *window, IGpDisplayDriver *displayDriver)
@@ -356,7 +357,7 @@ namespace PortabilityLayer
} }
WindowManagerImpl WindowManagerImpl::ms_instance; WindowManagerImpl WindowManagerImpl::ms_instance;
Window WindowManagerImpl::ms_putInFront; uint8_t WindowManagerImpl::ms_putInFrontSentinel;
WindowManager *WindowManager::GetInstance() WindowManager *WindowManager::GetInstance()
{ {