Loading screen

This commit is contained in:
elasota
2020-10-16 20:06:47 -04:00
parent ad5a0795f4
commit bfb2c727ea
10 changed files with 165 additions and 27 deletions

View File

@@ -6,17 +6,29 @@
//============================================================================ //============================================================================
#include <WindowDef.h>
#include "PLApplication.h" #include "PLApplication.h"
#include "PLKeyEncoding.h" #include "PLKeyEncoding.h"
#include "PLStandardColors.h"
#include "PLSysCalls.h"
#include "Externs.h" #include "Externs.h"
#include "Environ.h" #include "Environ.h"
#include "FontFamily.h"
#include "GpRenderedFontMetrics.h"
#include "HostDisplayDriver.h" #include "HostDisplayDriver.h"
#include "IGpDisplayDriver.h" #include "IGpDisplayDriver.h"
#include "GpIOStream.h" #include "GpIOStream.h"
#include "House.h" #include "House.h"
#include "RenderedFont.h"
#include "ResolveCachingColor.h"
#include "WindowManager.h" #include "WindowManager.h"
WindowPtr loadScreenWindow;
Rect loadScreenProgressBarRect;
int loadScreenProgress;
#define kPrefsVersion 0x0038 #define kPrefsVersion 0x0038
@@ -52,8 +64,8 @@ THandle<void> globalModulePrefs;
//============================================================== Functions //============================================================== Functions
//-------------------------------------------------------------- ReadInPrefs //-------------------------------------------------------------- ReadInPrefs
// Called only once when game launches - reads in the preferences saved<EFBFBD> // Called only once when game launches - reads in the preferences saved?
// from the last time Glider PRO was launched. If no prefs are found,<EFBFBD> // from the last time Glider PRO was launched. If no prefs are found,?
// it assigns default settings. // it assigns default settings.
void ReadInPrefs (void) void ReadInPrefs (void)
@@ -61,7 +73,7 @@ void ReadInPrefs (void)
prefsInfo thePrefs; prefsInfo thePrefs;
THandle<void> modulePrefs; THandle<void> modulePrefs;
if (LoadPrefs(&thePrefs, &modulePrefs, kPrefsVersion)) if (LoadPrefs(&thePrefs, &modulePrefs, kPrefsVersion))
{ {
#ifdef COMPILEDEMO #ifdef COMPILEDEMO
@@ -171,7 +183,7 @@ void ReadInPrefs (void)
isVolume = 1; isVolume = 1;
else if (isVolume > 3) else if (isVolume > 3)
isVolume = 3; isVolume = 3;
isDepthPref = kSwitchIfNeeded; isDepthPref = kSwitchIfNeeded;
isSoundOn = true; isSoundOn = true;
isMusicOn = true; isMusicOn = true;
@@ -223,13 +235,13 @@ void ReadInPrefs (void)
modulePrefs.Dispose(); modulePrefs.Dispose();
} }
if ((numNeighbors > 1) && (thisMac.constrainedScreen.right <= 512)) if ((numNeighbors > 1) && (thisMac.constrainedScreen.right <= 512))
numNeighbors = 1; numNeighbors = 1;
UnivGetSoundVolume(&wasVolume, thisMac.hasSM3); UnivGetSoundVolume(&wasVolume, thisMac.hasSM3);
UnivSetSoundVolume(isVolume, thisMac.hasSM3); UnivSetSoundVolume(isVolume, thisMac.hasSM3);
if (isVolume == 0) if (isVolume == 0)
isSoundOn = false; isSoundOn = false;
else else
@@ -238,15 +250,15 @@ void ReadInPrefs (void)
//-------------------------------------------------------------- WriteOutPrefs //-------------------------------------------------------------- WriteOutPrefs
// Called just before Glider PRO quits. This function writes out<EFBFBD> // Called just before Glider PRO quits. This function writes out?
// the user preferences to disk. // the user preferences to disk.
void WriteOutPrefs (void) void WriteOutPrefs (void)
{ {
prefsInfo thePrefs; prefsInfo thePrefs;
UnivGetSoundVolume(&isVolume, thisMac.hasSM3); UnivGetSoundVolume(&isVolume, thisMac.hasSM3);
#ifdef COMPILEDEMO #ifdef COMPILEDEMO
PasStringCopy("\pDemo House", thePrefs.wasDefaultName); PasStringCopy("\pDemo House", thePrefs.wasDefaultName);
#else #else
@@ -322,10 +334,93 @@ void WriteOutPrefs (void)
SysBeep(1); SysBeep(1);
modulePrefs.Dispose(); modulePrefs.Dispose();
UnivSetSoundVolume(wasVolume, thisMac.hasSM3); UnivSetSoundVolume(wasVolume, thisMac.hasSM3);
} }
void StepLoadScreen(int steps)
{
if (loadScreenWindow)
{
int oldProgress = loadScreenProgress;
int loadScreenMax = 19;
loadScreenProgress = loadScreenProgress + steps;
if (loadScreenProgress > loadScreenMax)
loadScreenProgress = loadScreenMax;
PortabilityLayer::ResolveCachingColor blackColor(StdColors::Black());
int prevStep = oldProgress * loadScreenProgressBarRect.Width() / loadScreenMax;
int thisStep = loadScreenProgress * loadScreenProgressBarRect.Width() / loadScreenMax;
loadScreenWindow->GetDrawSurface()->FillRect(Rect::Create(loadScreenProgressBarRect.top, loadScreenProgressBarRect.left + prevStep, loadScreenProgressBarRect.bottom, loadScreenProgressBarRect.left + thisStep), blackColor);
ForceSyncFrame();
}
SpinCursor(steps);
}
void InitLoadingWindow()
{
static const int kLoadScreenHeight = 32;
static const int kLoadScreenWidth = 256;
ForceSyncFrame();
PLSysCalls::Sleep(1);
int32_t lsX = (thisMac.fullScreen.Width() - kLoadScreenWidth) / 2;
int32_t lsY = (thisMac.fullScreen.Height() - kLoadScreenHeight) / 2;
const Rect loadScreenRect = Rect::Create(lsY, lsX, lsY + kLoadScreenHeight, lsX + kLoadScreenWidth);
const Rect loadScreenLocalRect = Rect::Create(0, 0, loadScreenRect.Height(), loadScreenRect.Width());
PortabilityLayer::WindowDef def = PortabilityLayer::WindowDef::Create(loadScreenRect, PortabilityLayer::WindowStyleFlags::kAlert, true, 0, 0, PSTR(""));
loadScreenWindow = PortabilityLayer::WindowManager::GetInstance()->CreateWindow(def);
PortabilityLayer::WindowManager::GetInstance()->PutWindowBehind(loadScreenWindow, PL_GetPutInFrontWindowPtr());
DrawSurface *surface = loadScreenWindow->GetDrawSurface();
PortabilityLayer::ResolveCachingColor blackColor(StdColors::Black());
PortabilityLayer::ResolveCachingColor whiteColor(StdColors::White());
surface->FillRect(loadScreenLocalRect, whiteColor);
PortabilityLayer::WindowManager::GetInstance()->FlickerWindowIn(loadScreenWindow, 32);
const PLPasStr loadingText = PSTR("Loading...");
PortabilityLayer::RenderedFont *font = GetApplicationFont(18, PortabilityLayer::FontFamilyFlag_None, true);
int32_t textY = (kLoadScreenHeight + font->GetMetrics().m_ascent) / 2;
surface->DrawString(Point::Create(4+16, textY), loadingText, blackColor, font);
static const int32_t loadBarPadding = 16;
int32_t loadBarStartX = static_cast<int32_t>(font->MeasureString(loadingText.UChars(), loadingText.Length())) + 4 + 16 + loadBarPadding;
int32_t loadBarEndX = loadScreenLocalRect.right - loadBarPadding;
loadScreenProgressBarRect = Rect::Create((loadScreenLocalRect.Height() - 8) / 2, loadBarStartX, (loadScreenLocalRect.Height() + 8) / 2, loadBarEndX);
loadScreenProgress = 0;
surface->FrameRect(loadScreenProgressBarRect, blackColor);
}
void PreloadFonts()
{
GetApplicationFont(8, PortabilityLayer::FontFamilyFlag_None, true);
StepLoadScreen(1);
GetApplicationFont(9, PortabilityLayer::FontFamilyFlag_None, true);
StepLoadScreen(1);
GetApplicationFont(9, PortabilityLayer::FontFamilyFlag_Bold, true);
StepLoadScreen(1);
GetApplicationFont(14, PortabilityLayer::FontFamilyFlag_Bold, true);
StepLoadScreen(1);
GetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
StepLoadScreen(1);
GetApplicationFont(10, PortabilityLayer::FontFamilyFlags::FontFamilyFlag_Bold, true);
StepLoadScreen(1);
GetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold, true);
StepLoadScreen(1);
}
//-------------------------------------------------------------- main //-------------------------------------------------------------- main
// Here is main(). The first function called when Glider PRO comes up. // Here is main(). The first function called when Glider PRO comes up.
@@ -337,10 +432,11 @@ int gpAppMain()
Boolean whoCares, copyGood; Boolean whoCares, copyGood;
PL_Init(); PL_Init();
ToolBoxInit(); ToolBoxInit();
CheckOurEnvirons(); CheckOurEnvirons();
InstallResolutionHandler(); InstallResolutionHandler();
if (!thisMac.hasColor) if (!thisMac.hasColor)
RedAlert(kErrNeedColorQD); RedAlert(kErrNeedColorQD);
if (!thisMac.hasSystem7) if (!thisMac.hasSystem7)
@@ -354,7 +450,10 @@ int gpAppMain()
SpinCursor(2); // Tick once to let the display driver flush any resolution changes from prefs SpinCursor(2); // Tick once to let the display driver flush any resolution changes from prefs
FlushResolutionChange(); FlushResolutionChange();
InitLoadingWindow(); StepLoadScreen(2);
PreloadFonts(); StepLoadScreen(2);
#if defined COMPILEDEMO #if defined COMPILEDEMO
copyGood = true; copyGood = true;
#elif defined COMPILENOCP #elif defined COMPILENOCP
@@ -366,18 +465,23 @@ int gpAppMain()
if (!copyGood) if (!copyGood)
encryptedNumber = 0L; encryptedNumber = 0L;
else if (didValidation) else if (didValidation)
WriteOutPrefs(); SpinCursor(3); WriteOutPrefs(); StepLoadScreen(3);
#endif #endif
// if ((thisMac.numScreens > 1) && (isUseSecondScreen)) // if ((thisMac.numScreens > 1) && (isUseSecondScreen))
// ReflectSecondMonitorEnvirons(false, true, true); // ReflectSecondMonitorEnvirons(false, true, true);
HandleDepthSwitching(); HandleDepthSwitching();
VariableInit(); SpinCursor(2); VariableInit(); StepLoadScreen(2);
GetExtraCursors(); SpinCursor(2); GetExtraCursors(); StepLoadScreen(2);
InitMarquee(); InitMarquee();
CreatePointers(); SpinCursor(2); CreatePointers(); StepLoadScreen(2);
InitSrcRects(); InitSrcRects();
CreateOffscreens(); SpinCursor(2); CreateOffscreens(); StepLoadScreen(2);
PortabilityLayer::WindowManager::GetInstance()->FlickerWindowOut(loadScreenWindow, 32);
PortabilityLayer::WindowManager::GetInstance()->DestroyWindow(loadScreenWindow);
PLSysCalls::Sleep(15);
OpenMainWindow(); OpenMainWindow();
if (isDoColorFade) if (isDoColorFade)
@@ -388,27 +492,27 @@ int gpAppMain()
BuildHouseList(); BuildHouseList();
if (OpenHouse()) if (OpenHouse())
whoCares = ReadHouse(); whoCares = ReadHouse();
PlayPrioritySound(kBirdSound, kBirdPriority); PlayPrioritySound(kBirdSound, kBirdPriority);
DelayTicks(6); DelayTicks(6);
InitializeMenus(); InitCursor(); InitializeMenus(); InitCursor();
#if BUILD_ARCADE_VERSION #if BUILD_ARCADE_VERSION
// HideMenuBarOld(); // HideMenuBarOld();
#endif #endif
if (isDoColorFade) if (isDoColorFade)
WashColorIn(); WashColorIn();
UpdateMainWindow(); UpdateMainWindow();
while (!quitting) // this is the main loop while (!quitting) // this is the main loop
HandleEvent(); HandleEvent();
/* /*
#if BUILD_ARCADE_VERSION #if BUILD_ARCADE_VERSION
ShowMenuBarOld(); ShowMenuBarOld();
#endif #endif
*/ */
KillMusic(); KillMusic();
KillSound(); KillSound();
if (houseOpen) if (houseOpen)

View File

@@ -9,6 +9,8 @@ namespace GpDisplayDriverTickStatuses
kFatalFault = 2, kFatalFault = 2,
kApplicationTerminated = 3, kApplicationTerminated = 3,
kSynchronizing = 4,
}; };
} }

View File

@@ -768,7 +768,12 @@ GpDisplayDriverTickStatus_t GpDisplayDriverD3D11::PresentFrameAndSync()
GpDisplayDriverTickStatus_t tickStatus = 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) if (tickStatus == GpDisplayDriverTickStatuses::kSynchronizing)
{
m_frameTimeAccumulated = 0;
break;
}
else if (tickStatus != GpDisplayDriverTickStatuses::kOK)
return tickStatus; return tickStatus;
} }
} }

View File

@@ -79,6 +79,15 @@ GpDisplayDriverTickStatus_t GpAppEnvironment::Tick(IGpFiber *vosFiber)
return GpDisplayDriverTickStatuses::kOK; return GpDisplayDriverTickStatuses::kOK;
} }
break; break;
case ApplicationState_Synchronizing:
if (m_delaySuspendTicks == 0)
m_applicationState = ApplicationState_Running;
else
{
m_delaySuspendTicks--;
return GpDisplayDriverTickStatuses::kSynchronizing;
}
break;
case ApplicationState_Terminated: case ApplicationState_Terminated:
m_applicationFiber->Destroy(); m_applicationFiber->Destroy();
m_applicationFiber = nullptr; m_applicationFiber = nullptr;
@@ -182,6 +191,10 @@ void GpAppEnvironment::DispatchSystemCall(PortabilityLayer::HostSuspendCallID ca
m_applicationState = ApplicationState_TimedSuspend; m_applicationState = ApplicationState_TimedSuspend;
m_delaySuspendTicks = args[0].m_uint; m_delaySuspendTicks = args[0].m_uint;
break; break;
case PortabilityLayer::HostSuspendCallID_ForceSyncFrame:
m_applicationState = ApplicationState_Synchronizing;
m_delaySuspendTicks = 1;
break;
case PortabilityLayer::HostSuspendCallID_CallOnVOSThread: case PortabilityLayer::HostSuspendCallID_CallOnVOSThread:
args[0].m_functionPtr(static_cast<const PortabilityLayer::HostSuspendCallArgument*>(args[1].m_constPointer), static_cast<PortabilityLayer::HostSuspendCallArgument*>(args[2].m_pointer)); args[0].m_functionPtr(static_cast<const PortabilityLayer::HostSuspendCallArgument*>(args[1].m_constPointer), static_cast<PortabilityLayer::HostSuspendCallArgument*>(args[2].m_pointer));
m_applicationState = ApplicationState_Running; m_applicationState = ApplicationState_Running;

View File

@@ -47,6 +47,7 @@ private:
ApplicationState_Terminated, ApplicationState_Terminated,
ApplicationState_SystemCall, ApplicationState_SystemCall,
ApplicationState_TimedSuspend, ApplicationState_TimedSuspend,
ApplicationState_Synchronizing,
}; };
static void StaticAppThreadFunc(void *context); static void StaticAppThreadFunc(void *context);

View File

@@ -9,7 +9,8 @@ namespace PortabilityLayer
HostSuspendCallID_Unknown, HostSuspendCallID_Unknown,
HostSuspendCallID_Delay, HostSuspendCallID_Delay,
HostSuspendCallID_CallOnVOSThread, HostSuspendCallID_CallOnVOSThread,
HostSuspendCallID_ForceSyncFrame
}; };
} }

View File

@@ -108,6 +108,11 @@ void Delay(int ticks, UInt32 *endTickCount)
*endTickCount = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetTickCount(); *endTickCount = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetTickCount();
} }
void ForceSyncFrame()
{
PLSysCalls::ForceSyncFrame();
}
short FindWindow(Point point, WindowPtr *window) short FindWindow(Point point, WindowPtr *window)
{ {
short part = 0; short part = 0;

View File

@@ -216,6 +216,7 @@ void InitCursor();
void HideCursor(); void HideCursor();
void Delay(int ticks, UInt32 *endTickCount); void Delay(int ticks, UInt32 *endTickCount);
void ForceSyncFrame();
short FindWindow(Point point, WindowPtr *window); // Translates global coordinates to window coordinates, returns a region ID short FindWindow(Point point, WindowPtr *window); // Translates global coordinates to window coordinates, returns a region ID
bool TrackGoAway(WindowPtr window, Point point); // Returns true if the close box was actually clicked (?) bool TrackGoAway(WindowPtr window, Point point); // Returns true if the close box was actually clicked (?)

View File

@@ -184,4 +184,9 @@ namespace PLSysCalls
AnimationManager::GetInstance()->TickPlayers(ticks); AnimationManager::GetInstance()->TickPlayers(ticks);
} }
} }
void ForceSyncFrame()
{
PortabilityLayer::SuspendApplication(PortabilityLayer::HostSuspendCallID_ForceSyncFrame, nullptr, nullptr);
}
} }

View File

@@ -7,4 +7,5 @@
namespace PLSysCalls namespace PLSysCalls
{ {
void Sleep(uint32_t ticks); void Sleep(uint32_t ticks);
void ForceSyncFrame();
} }