Compare commits

...

26 Commits
1.0a1 ... 1.0a3

Author SHA1 Message Date
elasota
69e3fb3023 Handle Quit event more gracefully 2020-04-18 05:51:39 -04:00
elasota
94f26d0be1 Redraw grease on room lighting change. Fixes regression where grease would not be visible after turning lights on. 2020-04-18 05:23:40 -04:00
elasota
d893b356f1 Fix dynamic indexes desynchronizing on resolution change (fixes Slumberland boombox switch not working if you change resolution on the screen with the switch) 2020-04-18 00:42:45 -04:00
elasota
c3f3fb4621 Override alt-enter behavior, use borderless fullscreen instead of exclusive fullscreen. This should fix the game breaking when bringing up the open file dialog in fullscreen.
(Note that this doesn't handle resolution changes yet)
2020-04-18 00:18:20 -04:00
elasota
0335dd7786 Fix alt-enter 2020-04-06 03:34:31 -04:00
elasota
ffd9d9cc1f Keep level editor windows in screen bounds 2020-04-05 22:31:22 -04:00
elasota
f46ae55d62 Merge branch 'resizable' 2020-04-05 18:38:05 -04:00
elasota
5c1aacc268 Fix memory corruption on victory screen 2020-04-05 18:36:27 -04:00
elasota
d7353ff6ed Refactor neighboring rooms sync-ups. Remove all of the neighboring room objects and recreate them, which fixes a bunch of problems with objects becoming out-of-frame after resize. 2020-04-05 18:34:37 -04:00
elasota
b827048c36 Account for chrome padding and menu bar when auto-relocating windows 2020-04-05 18:30:04 -04:00
elasota
f56d879d12 Fix mirrors on resize 2020-04-05 04:51:58 -04:00
elasota
1269294d28 Center windows when over max resolution 2020-04-05 02:15:49 -04:00
elasota
643bc7b761 Remove scoreboard vertical offset (which doesn't work) 2020-04-05 01:51:42 -04:00
elasota
2f663646f5 Remove unused menu bar window 2020-04-05 00:35:01 -04:00
elasota
f4a57dba6e Redraw scoreboard on splash screen res change 2020-04-05 00:32:13 -04:00
elasota
7404c60a96 Disable Alt-Enter 2020-04-05 00:31:55 -04:00
elasota
805638f2c9 Fix TV and splash on res change 2020-04-04 18:50:45 -04:00
elasota
59e9a9480e Fix high score background drawing white after a win 2020-04-04 17:49:45 -04:00
elasota
49d1d6124a Fix off-center high score screen at high resolutions 2020-04-04 17:46:38 -04:00
elasota
129396ef53 Fix more dynamics, fix end screen stars with large vertical resolutions 2020-04-04 17:46:19 -04:00
elasota
1cdd372e35 Fix up most other appliances and enemies on res change 2020-04-02 20:44:24 -04:00
elasota
9a4f3f0e67 Fix candle flames and grease spill progression on res change 2020-04-02 01:47:25 -04:00
elasota
db89bf178c Fix grease on res change 2020-04-01 23:35:10 -04:00
elasota
793822fbb4 EOL fixes 2020-04-01 23:34:55 -04:00
elasota
66a709ad2a Fix memory corruption 2020-04-01 23:29:48 -04:00
elasota
6326a0b2d9 Partial resolution change support 2020-04-01 14:53:44 -04:00
60 changed files with 1975 additions and 837 deletions

View File

@@ -94,6 +94,11 @@ void GpAppEnvironment::Render()
GpAppInterface_Get()->PL_Render(m_displayDriver);
}
bool GpAppEnvironment::AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY)
{
return GpAppInterface_Get()->PL_AdjustRequestedResolution(physicalWidth, physicalHeight, virtualWidth, virtualheight, pixelScaleX, pixelScaleY);
}
void GpAppEnvironment::SetDisplayDriver(IGpDisplayDriver *displayDriver)
{
m_displayDriver = displayDriver;
@@ -170,6 +175,10 @@ void GpAppEnvironment::DispatchSystemCall(PortabilityLayer::HostSuspendCallID ca
m_applicationState = ApplicationState_TimedSuspend;
m_delaySuspendTicks = args[0].m_uint;
break;
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));
m_applicationState = ApplicationState_Running;
break;
default:
assert(false);
}

View File

@@ -28,6 +28,7 @@ public:
GpDisplayDriverTickStatus_t Tick(IGpFiber *vosFiber);
void Render();
bool AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY);
void SetDisplayDriver(IGpDisplayDriver *displayDriver);
void SetAudioDriver(IGpAudioDriver *audioDriver);

View File

@@ -13,6 +13,8 @@
#include <assert.h>
extern GpWindowsGlobals g_gpWindowsGlobals;
class GpDirectoryCursor_Win32 final : public PortabilityLayer::HostDirectoryCursor
{
public:
@@ -307,6 +309,7 @@ bool GpFileSystem_Win32::PromptSaveFile(PortabilityLayer::VirtualDirectory_t vir
ofn.nMaxFile = MAX_PATH;
ofn.lpstrInitialDir = baseDir;
ofn.Flags = OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT;
ofn.hwndOwner = g_gpWindowsGlobals.m_hwnd;
if (!GetSaveFileNameW(&ofn))
return false;
@@ -387,6 +390,7 @@ bool GpFileSystem_Win32::PromptOpenFile(PortabilityLayer::VirtualDirectory_t vir
ofn.nMaxFile = MAX_PATH;
ofn.lpstrInitialDir = baseDir;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST;
ofn.hwndOwner = g_gpWindowsGlobals.m_hwnd;
if (!GetOpenFileNameW(&ofn))
return false;

View File

@@ -27,6 +27,11 @@ namespace
{
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()
@@ -52,6 +57,9 @@ int GpMain::Run()
ddProps.m_renderFunc = RenderAppEnvironment;
ddProps.m_renderFuncContext = appEnvironment;
ddProps.m_adjustRequestedResolutionFunc = AdjustRequestedResolution;
ddProps.m_adjustRequestedResolutionFuncContext = appEnvironment;
ddProps.m_type = g_gpGlobalConfig.m_displayDriverType;
ddProps.m_osGlobals = g_gpGlobalConfig.m_osGlobals;
ddProps.m_eventQueue = eventQueue;

View File

@@ -24,7 +24,7 @@ extern "C" __declspec(dllimport) IGpAudioDriver *GpDriver_CreateAudioDriver_XAud
extern "C" __declspec(dllimport) IGpDisplayDriver *GpDriver_CreateDisplayDriver_D3D11(const GpDisplayDriverProperties &properties);
extern "C" __declspec(dllimport) IGpInputDriver *GpDriver_CreateInputDriver_XInput(const GpInputDriverProperties &properties);
static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t eventType, GpMouseButton_t button, int32_t x, int32_t y)
static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t eventType, GpMouseButton_t button, int32_t x, int32_t y, float pixelScaleX, float pixelScaleY)
{
if (GpVOSEvent *evt = eventQueue->QueueEvent())
{
@@ -35,6 +35,12 @@ static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t even
mEvent.m_x = x;
mEvent.m_y = y;
mEvent.m_eventType = eventType;
if (pixelScaleX != 1.0f)
mEvent.m_x = static_cast<int32_t>(static_cast<float>(x) / pixelScaleX);
if (pixelScaleY != 1.0f)
mEvent.m_y = static_cast<int32_t>(static_cast<float>(y) / pixelScaleX);
}
}
@@ -291,7 +297,7 @@ static void PostKeyboardEvent(IGpVOSEventQueue *eventQueue, GpKeyboardInputEvent
}
}
static void TranslateWindowsMessage(const MSG *msg, IGpVOSEventQueue *eventQueue)
static void TranslateWindowsMessage(const MSG *msg, IGpVOSEventQueue *eventQueue, float pixelScaleX, float pixelScaleY)
{
WPARAM wParam = msg->wParam;
LPARAM lParam = msg->lParam;
@@ -299,40 +305,40 @@ static void TranslateWindowsMessage(const MSG *msg, IGpVOSEventQueue *eventQueue
switch (msg->message)
{
case WM_LBUTTONDOWN:
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kLeft, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kLeft, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
break;
case WM_LBUTTONUP:
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kLeft, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kLeft, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
break;
case WM_MBUTTONDOWN:
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kMiddle, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kMiddle, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
break;
case WM_MBUTTONUP:
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kMiddle, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kMiddle, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
break;
case WM_RBUTTONDOWN:
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kRight, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kRight, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
break;
case WM_RBUTTONUP:
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kRight, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kRight, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
break;
case WM_XBUTTONDOWN:
if (GET_XBUTTON_WPARAM(wParam) == XBUTTON1)
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kX1, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kX1, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
else if (GET_XBUTTON_WPARAM(wParam) == XBUTTON2)
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kX2, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kDown, GpMouseButtons::kX2, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
break;
case WM_XBUTTONUP:
if (GET_XBUTTON_WPARAM(wParam) == XBUTTON1)
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kX1, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kX1, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
else if (GET_XBUTTON_WPARAM(wParam) == XBUTTON2)
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kX2, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kUp, GpMouseButtons::kX2, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
break;
case WM_MOUSEMOVE:
PostMouseEvent(eventQueue, GpMouseEventTypes::kMove, GpMouseButtons::kNone, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
PostMouseEvent(eventQueue, GpMouseEventTypes::kMove, GpMouseButtons::kNone, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), pixelScaleX, pixelScaleY);
break;
case WM_MOUSELEAVE:
PostMouseEvent(eventQueue, GpMouseEventTypes::kLeave, GpMouseButtons::kNone, 0, 0);
PostMouseEvent(eventQueue, GpMouseEventTypes::kLeave, GpMouseButtons::kNone, 0, 0, pixelScaleX, pixelScaleY);
break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
@@ -373,6 +379,12 @@ static void TranslateWindowsMessage(const MSG *msg, IGpVOSEventQueue *eventQueue
PostKeyboardEvent(eventQueue, keyEventType, subset, key, (lParam & 0xffff));
}
break;
case WM_QUIT:
{
if (GpVOSEvent *evt = eventQueue->QueueEvent())
evt->m_eventType = GpVOSEventTypes::kQuit;
}
break;
default:
break;
}
@@ -388,6 +400,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpWindowsGlobals.m_cmdLine = lpCmdLine;
g_gpWindowsGlobals.m_nCmdShow = nCmdShow;
g_gpWindowsGlobals.m_baseDir = GpFileSystem_Win32::GetInstance()->GetBasePath();
g_gpWindowsGlobals.m_hwnd = nullptr;
g_gpWindowsGlobals.m_createFiberFunc = GpFiber_Win32::Create;
g_gpWindowsGlobals.m_loadCursorFunc = GpCursor_Win32::Load;

View File

@@ -149,10 +149,10 @@ static void UpdateMainPict (Dialog *theDial)
DrawDialogUserText2(theDial, 7, theStr);
PasStringCopy(PSTR("Screen: "), theStr); // display screen size/depth
NumToString((long)(thisMac.screen.right - thisMac.screen.left), theStr2);
NumToString((long)(thisMac.fullScreen.right - thisMac.fullScreen.left), theStr2);
PasStringConcat(theStr, theStr2);
PasStringConcat(theStr, PSTR("x"));
NumToString((long)(thisMac.screen.bottom - thisMac.screen.top), theStr2);
NumToString((long)(thisMac.fullScreen.bottom - thisMac.fullScreen.top), theStr2);
PasStringConcat(theStr, theStr2);
PasStringConcat(theStr, PSTR("x"));
NumToString((long)thisMac.isDepth, theStr2);

View File

@@ -7,6 +7,7 @@
#include "PLAppleEvents.h"
#include "AppEventHandler.h"
#include "DialogManager.h"
#include "Externs.h"
#include "House.h"
@@ -168,12 +169,38 @@ PLError_t MyGotRequiredParams (const AppleEvent *theAE)
PLErrors::kInvalidParameter;
}
class SystemEventHandlerImpl : public PortabilityLayer::IAppEventHandler
{
public:
void OnQuit() override;
static SystemEventHandlerImpl *GetInstance();
private:
static SystemEventHandlerImpl ms_instance;
};
void SystemEventHandlerImpl::OnQuit()
{
quitting = true;
}
SystemEventHandlerImpl *SystemEventHandlerImpl::GetInstance()
{
return &ms_instance;
}
SystemEventHandlerImpl SystemEventHandlerImpl::ms_instance;
//-------------------------------------------------------------- SetUpAppleEvents
// Initializes all handlers, etc. for dealing with Apple Events.
void SetUpAppleEvents (void)
{
PLError_t theErr;
PortabilityLayer::AppEventHandler::SetInstance(SystemEventHandlerImpl::GetInstance());
openAppAEUPP = NewAEEventHandlerProc(DoOpenAppAE);
openDocAEUPP = NewAEEventHandlerProc(DoOpenDocAE);

View File

@@ -50,7 +50,7 @@ void DrawBanner (Point *topLeft)
PLError_t theErr;
QSetRect(&wholePage, 0, 0, 330, 220);
mapBounds = thisMac.screen;
mapBounds = thisMac.fullScreen;
ZeroRectCorner(&mapBounds);
CenterRectInRect(&wholePage, &mapBounds);
topLeft->h = wholePage.left;
@@ -203,8 +203,8 @@ void DisplayStarsRemaining (void)
DrawSurface *surface = mainWindow->GetDrawSurface();
QSetRect(&bounds, 0, 0, 256, 64);
CenterRectInRect(&bounds, &thisMac.screen);
QOffsetRect(&bounds, -thisMac.screen.left, -thisMac.screen.top);
CenterRectInRect(&bounds, &thisMac.fullScreen);
QOffsetRect(&bounds, -thisMac.fullScreen.left, -thisMac.fullScreen.top);
src = bounds;
InsetRect(&src, 64, 32);

View File

@@ -5,6 +5,7 @@
//============================================================================
#include "ArrayTools.h"
#include "Externs.h"
#include "Environ.h"
#include "MainWindow.h"
@@ -68,7 +69,7 @@ void NilSavedMaps (void)
// room that it obscured so that, should the player get the object,É
// it can be made to "disappear".
short BackUpToSavedMap (Rect *theRect, short where, short who)
short BackUpToSavedMap (Rect *theRect, SInt16 where, SInt16 who)
{
Rect mapRect;
PLError_t theErr;
@@ -98,7 +99,7 @@ short BackUpToSavedMap (Rect *theRect, short where, short who)
// a slot in the pixmap array for the object. It re-copies the backgroundÉ
// and is needed when the lights in the room go on or off.
short ReBackUpSavedMap (Rect *theRect, short where, short who)
SInt16 ReBackUpSavedMap (Rect *theRect, SInt16 where, SInt16 who)
{
Rect mapRect;
short i, foundIndex;
@@ -112,6 +113,8 @@ short ReBackUpSavedMap (Rect *theRect, short where, short who)
foundIndex = i;
mapRect = *theRect;
ZeroRectCorner(&mapRect);
savedMaps[foundIndex].dest = *theRect;
CopyBits((BitMap *)*GetGWorldPixMap(backSrcMap),
GetPortBitMapForCopyBits(savedMaps[foundIndex].map),
@@ -121,7 +124,54 @@ short ReBackUpSavedMap (Rect *theRect, short where, short who)
}
}
return (foundIndex);
return BackUpToSavedMap(theRect, where, who);
}
//-------------------------------------------------------------- RemoveFromSavedMap
template<class T>
void RemapDynamicObject(T *arr, short &count, int removedIndex, int substituteIndex)
{
short countCopy = count;
for (int i = 0; i < countCopy; i++)
{
if (arr[i].who == removedIndex)
{
PortabilityLayer::ArrayTools::RemoveFromArray(arr, countCopy, i);
i--;
}
else if (arr[i].who == substituteIndex)
arr[i].who = removedIndex;
}
count = countCopy;
}
SInt16 RemoveFromSavedMap (SInt16 index)
{
int swappedIn = numSavedMaps - 1;
RemapDynamicObject(flames, numFlames, index, swappedIn);
RemapDynamicObject(tikiFlames, numTikiFlames, index, swappedIn);
RemapDynamicObject(bbqCoals, numCoals, index, swappedIn);
RemapDynamicObject(pendulums, numPendulums, index, swappedIn);
RemapDynamicObject(theStars, numStars, index, swappedIn);
RemapGreaseSavedMap(index, swappedIn);
// Have to do this explicitly so we don't trash the draw surface pointer
if (swappedIn != index)
{
savedType &dest = savedMaps[index];
savedType &src = savedMaps[swappedIn];
DisposeGWorld(dest.map);
dest = src;
src.map = nil;
}
numSavedMaps--;
return -1;
}
//-------------------------------------------------------------- RestoreFromSavedMap
@@ -290,7 +340,7 @@ void BackUpFlames (Rect *src, short index)
// Like the above function but this is called when the lighting changesÉ
// in a room (lights go on or off).
void ReBackUpFlames (short where, short who)
Boolean ReBackUpFlames (short where, short who, short h, short v)
{
short i, f;
@@ -302,19 +352,22 @@ void ReBackUpFlames (short where, short who)
{
if (flames[f].who == i)
{
QOffsetRect(&flames[f].dest, h - 8 - flames[f].dest.left, v - 15 - flames[f].dest.top);
BackUpFlames(&flames[f].dest, i);
return;
return true;
}
}
}
}
return false;
}
//-------------------------------------------------------------- AddCandleFlame
// This adds a candle flame to tha array of flames.
void AddCandleFlame (short where, short who, short h, short v)
void AddCandleFlame (SInt16 where, SInt16 who, SInt16 h, SInt16 v)
{
Rect src, bounds;
short savedNum;
@@ -374,7 +427,7 @@ void BackUpTikiFlames (Rect *src, short index)
// This is like the function ReBackUpFlames() but customized for Tiki torches.
void ReBackUpTikiFlames (short where, short who)
Boolean ReBackUpTikiFlames (short where, short who, short h, short v)
{
short i, f;
@@ -386,12 +439,15 @@ void ReBackUpTikiFlames (short where, short who)
{
if (tikiFlames[f].who == i)
{
QOffsetRect(&tikiFlames[f].dest, h - tikiFlames[f].dest.left, v - tikiFlames[f].dest.top);
BackUpTikiFlames(&tikiFlames[f].dest, i);
return;
return true;
}
}
}
}
return false;
}
//-------------------------------------------------------------- AddTikiFlame
@@ -460,7 +516,7 @@ void BackUpBBQCoals (Rect *src, short index)
// Sense a pattern here?
void ReBackUpBBQCoals (short where, short who)
Boolean ReBackUpBBQCoals (short where, short who, short h, short v)
{
short i, f;
@@ -472,12 +528,15 @@ void ReBackUpBBQCoals (short where, short who)
{
if (bbqCoals[f].who == i)
{
QOffsetRect(&bbqCoals[f].dest, h - bbqCoals[f].dest.left, v - bbqCoals[f].dest.top);
BackUpBBQCoals(&bbqCoals[f].dest, i);
return;
return true;
}
}
}
}
return false;
}
//-------------------------------------------------------------- AddBBQCoals
@@ -544,7 +603,7 @@ void BackUpPendulum (Rect *src, short index)
// Backs up the pendulums in the event of lights going on or off.
void ReBackUpPendulum (short where, short who)
Boolean ReBackUpPendulum (short where, short who, short h, short v)
{
short i, f;
@@ -556,19 +615,26 @@ void ReBackUpPendulum (short where, short who)
{
if (pendulums[f].who == i)
{
BackUpPendulum(&pendulums[f].dest, i);
return;
Rect &pendulumDest = pendulums[f].dest;
pendulumDest.right += h - pendulumDest.left;
pendulumDest.bottom += v - pendulumDest.top;
pendulumDest.left = h;
pendulumDest.top = v;
BackUpPendulum(&pendulumDest, i);
return true;
}
}
}
}
return false;
}
//-------------------------------------------------------------- AddPendulum
// Adds a pendulum to the array of pendulums.
void AddPendulum (short where, short who, short h, short v)
void AddPendulum (SInt16 where, SInt16 who, SInt16 h, SInt16 v)
{
Rect src, bounds;
short savedNum;
@@ -636,7 +702,7 @@ void BackUpStar (Rect *src, short index)
// Re-backs up the stars - in the event of lighting switch.
void ReBackUpStar (short where, short who)
void ReBackUpStar (short where, short who, short h, short v)
{
short i, f;
@@ -648,6 +714,7 @@ void ReBackUpStar (short where, short who)
{
if (theStars[f].who == i)
{
QOffsetRect(&theStars[f].dest, h - theStars[f].dest.left, v - theStars[f].dest.top);
BackUpStar(&theStars[f].dest, i);
return;
}
@@ -797,3 +864,14 @@ void ZeroFlamesAndTheLike (void)
numChimes = 0;
}
void RemoveSavedMapsNotInRoom(SInt16 where)
{
for (int i = 0; i < numSavedMaps; i++)
{
if (savedMaps[i].where != where)
{
RemoveFromSavedMap(i);
i--;
}
}
}

View File

@@ -153,6 +153,48 @@ void RenderDynamics (void)
}
}
//-------------------------------------------------------------- ZeroDinah
void ZeroDinah(dynaType &dinah)
{
dinah.type = kObjectIsEmpty;
QSetRect(&dinah.dest, 0, 0, 0, 0);
QSetRect(&dinah.whole, 0, 0, 0, 0);
dinah.hVel = 0;
dinah.vVel = 0;
dinah.count = 0;
dinah.frame = 0;
dinah.timer = 0;
dinah.position = 0;
dinah.room = 0;
dinah.byte0 = 0;
dinah.active = false;
}
//-------------------------------------------------------------- ZeroDinahsNotInRoom
void ZeroDinahsNotInRoom (SInt16 room)
{
short i;
short newNumDynamics = 0;
for (i = 0; i < numDynamics; i++)
{
dynaType &dinah = dinahs[i];
if (dinah.room == room)
{
if (newNumDynamics != numDynamics)
memcpy(&dinahs[newNumDynamics], &dinahs[i], sizeof(dynaType));
newNumDynamics++;
}
}
for (i = newNumDynamics; i < kMaxDynamicObs; i++)
ZeroDinah(dinahs[i]);
numDynamics = newNumDynamics;
}
//-------------------------------------------------------------- ZeroDinahs
// This clears all dynamics - zeros them all out. Used to initialize them.
@@ -162,20 +204,8 @@ void ZeroDinahs (void)
short i;
for (i = 0; i < kMaxDynamicObs; i++)
{
dinahs[i].type = kObjectIsEmpty;
QSetRect(&dinahs[i].dest, 0, 0, 0, 0);
QSetRect(&dinahs[i].whole, 0, 0, 0, 0);
dinahs[i].hVel = 0;
dinahs[i].vVel = 0;
dinahs[i].count = 0;
dinahs[i].frame = 0;
dinahs[i].timer = 0;
dinahs[i].position = 0;
dinahs[i].room = 0;
dinahs[i].byte0 = 0;
dinahs[i].active = false;
}
ZeroDinah(dinahs[i]);
numDynamics = 0;
}
@@ -185,371 +215,494 @@ void ZeroDinahs (void)
// This function sets up the structures to handle them.
short AddDynamicObject (short what, Rect *where, objectType *who,
short room, short index, Boolean isOn)
short room, short index, Boolean isOn, Boolean keepExisting)
{
short position, velocity;
Boolean lilFrame;
if (numDynamics >= kMaxDynamicObs)
return (-1);
dinahs[numDynamics].type = what;
switch (what)
short dynIndex = -1;
if (!keepExisting)
{
case kSparkle:
dinahs[numDynamics].dest = sparkleSrc[0];
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest, where->left, where->top);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = 0;
dinahs[numDynamics].vVel = 0;
dinahs[numDynamics].count = 0;
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = RandomInt(60) + 15;
dinahs[numDynamics].position = 0;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kToaster:
dinahs[numDynamics].dest = breadSrc[0];
CenterRectInRect(&dinahs[numDynamics].dest, where);
VOffsetRect(&dinahs[numDynamics].dest,
where->top - dinahs[numDynamics].dest.top);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = where->top + 2; // hVel used as clip
position = who->data.g.height; // reverse engineer init. vel.
velocity = 0;
do
if (numDynamics >= kMaxDynamicObs)
return (-1);
dynIndex = numDynamics;
numDynamics++;
dinahs[dynIndex].type = what;
}
else
{
for (int i = 0; i < numDynamics; i++)
{
velocity++;
position -= velocity;
if (dinahs[i].type == what && dinahs[i].room == room && dinahs[i].byte0 == index)
{
dynIndex = i;
break;
}
}
while (position > 0);
dinahs[numDynamics].vVel = -velocity;
dinahs[numDynamics].count = velocity; // count = initial velocity
dinahs[numDynamics].frame = (short)who->data.g.delay * 3;
dinahs[numDynamics].timer = dinahs[numDynamics].frame;
dinahs[numDynamics].position = 0; // launch/idle state
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kMacPlus:
dinahs[numDynamics].dest = plusScreen1;
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest,
where->left + playOriginH + 10,
where->top + playOriginV + 7);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = 0;
dinahs[numDynamics].vVel = 0;
dinahs[numDynamics].count = 0;
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = 0;
dinahs[numDynamics].position = 0;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kTV:
dinahs[numDynamics].dest = tvScreen1;
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest,
where->left + playOriginH + 17,
where->top + playOriginV + 10);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = 0;
dinahs[numDynamics].vVel = 0;
dinahs[numDynamics].count = 0;
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = 0;
dinahs[numDynamics].position = 0;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kCoffee:
dinahs[numDynamics].dest = coffeeLight1;
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest,
where->left + playOriginH + 32,
where->top + playOriginV + 57);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = 0;
dinahs[numDynamics].vVel = 0;
dinahs[numDynamics].count = 0;
dinahs[numDynamics].frame = 0;
if (isOn)
dinahs[numDynamics].timer = 200;
else
dinahs[numDynamics].timer = 0;
dinahs[numDynamics].position = 0;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kOutlet:
dinahs[numDynamics].dest = outletSrc[0];
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest,
where->left + playOriginH,
where->top + playOriginV);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = numLights;
dinahs[numDynamics].vVel = 0;
dinahs[numDynamics].count = ((short)who->data.g.delay * 6) / kTicksPerFrame;
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = dinahs[numDynamics].count;
dinahs[numDynamics].position = 0; // launch/idle state
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kVCR:
dinahs[numDynamics].dest = vcrTime1;
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest,
where->left + playOriginH + 64,
where->top + playOriginV + 6);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = 0;
dinahs[numDynamics].vVel = 0;
dinahs[numDynamics].count = 0;
dinahs[numDynamics].frame = 0;
if (isOn)
dinahs[numDynamics].timer = 115;
else
dinahs[numDynamics].timer = 0;
dinahs[numDynamics].position = 0;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kStereo:
dinahs[numDynamics].dest = stereoLight1;
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest,
where->left + playOriginH + 56,
where->top + playOriginV + 20);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = 0;
dinahs[numDynamics].vVel = 0;
dinahs[numDynamics].count = 0;
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = 0;
dinahs[numDynamics].position = 0;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kMicrowave:
dinahs[numDynamics].dest = microOn;
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest,
where->left + playOriginH + 14,
where->top + playOriginV + 13);
dinahs[numDynamics].dest.right = dinahs[numDynamics].dest.left + 48;
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = 0;
dinahs[numDynamics].vVel = 0;
dinahs[numDynamics].count = 0;
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = 0;
dinahs[numDynamics].position = 0;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kBalloon:
dinahs[numDynamics].dest = balloonSrc[0];
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest, where->left, 0);
dinahs[numDynamics].dest.bottom = kBalloonStart;
dinahs[numDynamics].dest.top = dinahs[numDynamics].dest.bottom -
RectTall(&balloonSrc[0]);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = 0;
dinahs[numDynamics].vVel = -2;
dinahs[numDynamics].count = ((short)who->data.h.delay * 6) / kTicksPerFrame;
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = dinahs[numDynamics].count;
dinahs[numDynamics].position = 0;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn; // initially idle
break;
case kCopterLf:
case kCopterRt:
dinahs[numDynamics].dest = copterSrc[0];
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest, where->left, 0);
dinahs[numDynamics].dest.top = kCopterStart;
dinahs[numDynamics].dest.bottom = dinahs[numDynamics].dest.top +
RectTall(&copterSrc[0]);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
if (what == kCopterLf)
dinahs[numDynamics].hVel = -1;
else
dinahs[numDynamics].hVel = 1;
dinahs[numDynamics].vVel = 2;
dinahs[numDynamics].count = ((short)who->data.h.delay * 6) / kTicksPerFrame;
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = dinahs[numDynamics].count;
dinahs[numDynamics].position = dinahs[numDynamics].dest.left;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn; // initially idle
break;
case kDartLf:
case kDartRt:
dinahs[numDynamics].dest = dartSrc[0];
ZeroRectCorner(&dinahs[numDynamics].dest);
if (what == kDartLf)
{
QOffsetRect(&dinahs[numDynamics].dest,
kRoomWide - RectWide(&dartSrc[0]), where->top);
dinahs[numDynamics].hVel = -kDartVelocity;
dinahs[numDynamics].frame = 0;
}
else
{
QOffsetRect(&dinahs[numDynamics].dest, 0, where->top);
dinahs[numDynamics].hVel = kDartVelocity;
dinahs[numDynamics].frame = 2;
}
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].vVel = 2;
dinahs[numDynamics].count = ((short)who->data.h.delay * 6) / kTicksPerFrame;
dinahs[numDynamics].timer = dinahs[numDynamics].count;
dinahs[numDynamics].position = dinahs[numDynamics].dest.top;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn; // initially idle
break;
case kBall:
dinahs[numDynamics].dest = ballSrc[0];
ZeroRectCorner(&dinahs[numDynamics].dest);
QOffsetRect(&dinahs[numDynamics].dest,
where->left, where->top);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = 0;
position = who->data.h.length; // reverse engineer init. vel.
velocity = 0;
evenFrame = true;
lilFrame = true;
do
{
if (lilFrame)
velocity++;
lilFrame = !lilFrame;
position -= velocity;
}
while (position > 0);
dinahs[numDynamics].vVel = -velocity;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].count = -velocity; // count = initial velocity
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = 0;
dinahs[numDynamics].position = dinahs[numDynamics].dest.bottom;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].active = isOn;
break;
case kDrip:
dinahs[numDynamics].dest = dripSrc[0];
CenterRectInRect(&dinahs[numDynamics].dest, where);
VOffsetRect(&dinahs[numDynamics].dest,
where->top - dinahs[numDynamics].dest.top);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = dinahs[numDynamics].dest.top; // remember
dinahs[numDynamics].vVel = 0;
dinahs[numDynamics].count = ((short)who->data.h.delay * 6) / kTicksPerFrame;
dinahs[numDynamics].frame = 3;
dinahs[numDynamics].timer = dinahs[numDynamics].count;
dinahs[numDynamics].position = dinahs[numDynamics].dest.top +
who->data.h.length;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
case kFish:
dinahs[numDynamics].dest = fishSrc[0];
QOffsetRect(&dinahs[numDynamics].dest,
where->left + 10, where->top + 8);
dinahs[numDynamics].whole = dinahs[numDynamics].dest;
dinahs[numDynamics].hVel = ((short)who->data.h.delay * 6) / kTicksPerFrame;
position = who->data.g.height; // reverse engineer init. vel.
velocity = 0;
evenFrame = true;
lilFrame = true;
do
{
if (lilFrame)
velocity++;
lilFrame = !lilFrame;
position -= velocity;
}
while (position > 0);
dinahs[numDynamics].vVel = -velocity;
dinahs[numDynamics].count = -velocity; // count = initial velocity
dinahs[numDynamics].frame = 0;
dinahs[numDynamics].timer = dinahs[numDynamics].hVel;
dinahs[numDynamics].position = dinahs[numDynamics].dest.bottom;
dinahs[numDynamics].room = room;
dinahs[numDynamics].byte0 = (Byte)index;
dinahs[numDynamics].byte1 = 0;
dinahs[numDynamics].moving = false;
dinahs[numDynamics].active = isOn;
break;
default:
return (-1);
break;
if (dynIndex == -1)
return (-1);
}
numDynamics++;
return (numDynamics - 1);
}
switch (what)
{
case kSparkle:
dinahs[dynIndex].dest = sparkleSrc[0];
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest, where->left, where->top);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = 0;
dinahs[dynIndex].vVel = 0;
dinahs[dynIndex].count = 0;
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = RandomInt(60) + 15;
dinahs[dynIndex].position = 0;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
break;
case kToaster:
{
short baselineDelta = 0;
if (keepExisting)
baselineDelta = dinahs[dynIndex].dest.top - (where->top - 2);
dinahs[dynIndex].dest = breadSrc[0];
CenterRectInRect(&dinahs[dynIndex].dest, where);
VOffsetRect(&dinahs[dynIndex].dest,
where->top - dinahs[dynIndex].dest.top + baselineDelta);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
dinahs[dynIndex].hVel = where->top + 2; // hVel used as clip
if (!keepExisting)
{
position = who->data.g.height; // reverse engineer init. vel.
velocity = 0;
do
{
velocity++;
position -= velocity;
} while (position > 0);
dinahs[dynIndex].vVel = -velocity;
dinahs[dynIndex].count = velocity; // count = initial velocity
dinahs[dynIndex].frame = (short)who->data.g.delay * 3;
dinahs[dynIndex].timer = dinahs[dynIndex].frame;
dinahs[dynIndex].position = 0; // launch/idle state
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
}
break;
case kMacPlus:
dinahs[dynIndex].dest = plusScreen1;
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest,
where->left + playOriginH + 10,
where->top + playOriginV + 7);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = 0;
dinahs[dynIndex].vVel = 0;
dinahs[dynIndex].count = 0;
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = 0;
dinahs[dynIndex].position = 0;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
break;
case kTV:
dinahs[dynIndex].dest = tvScreen1;
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest,
where->left + playOriginH + 17,
where->top + playOriginV + 10);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = 0;
dinahs[dynIndex].vVel = 0;
dinahs[dynIndex].count = 0;
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = 0;
dinahs[dynIndex].position = 0;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
break;
case kCoffee:
dinahs[dynIndex].dest = coffeeLight1;
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest,
where->left + playOriginH + 32,
where->top + playOriginV + 57);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = 0;
dinahs[dynIndex].vVel = 0;
dinahs[dynIndex].count = 0;
dinahs[dynIndex].frame = 0;
if (isOn)
dinahs[dynIndex].timer = 200;
else
dinahs[dynIndex].timer = 0;
dinahs[dynIndex].position = 0;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
break;
case kOutlet:
dinahs[dynIndex].dest = outletSrc[0];
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest,
where->left + playOriginH,
where->top + playOriginV);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = numLights;
dinahs[dynIndex].vVel = 0;
dinahs[dynIndex].count = ((short)who->data.g.delay * 6) / kTicksPerFrame;
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = dinahs[dynIndex].count;
dinahs[dynIndex].position = 0; // launch/idle state
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
break;
case kVCR:
dinahs[dynIndex].dest = vcrTime1;
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest,
where->left + playOriginH + 64,
where->top + playOriginV + 6);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = 0;
dinahs[dynIndex].vVel = 0;
dinahs[dynIndex].count = 0;
dinahs[dynIndex].frame = 0;
if (isOn)
dinahs[dynIndex].timer = 115;
else
dinahs[dynIndex].timer = 0;
dinahs[dynIndex].position = 0;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
break;
case kStereo:
dinahs[dynIndex].dest = stereoLight1;
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest,
where->left + playOriginH + 56,
where->top + playOriginV + 20);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = 0;
dinahs[dynIndex].vVel = 0;
dinahs[dynIndex].count = 0;
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = 0;
dinahs[dynIndex].position = 0;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
break;
case kMicrowave:
dinahs[dynIndex].dest = microOn;
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest,
where->left + playOriginH + 14,
where->top + playOriginV + 13);
dinahs[dynIndex].dest.right = dinahs[dynIndex].dest.left + 48;
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = 0;
dinahs[dynIndex].vVel = 0;
dinahs[dynIndex].count = 0;
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = 0;
dinahs[dynIndex].position = 0;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
break;
case kBalloon:
{
short baselineDelta = 0;
if (keepExisting)
baselineDelta = dinahs[dynIndex].dest.bottom - kBalloonStart;
dinahs[dynIndex].dest = balloonSrc[0];
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest, where->left, 0);
dinahs[dynIndex].dest.bottom = kBalloonStart + baselineDelta;
dinahs[dynIndex].dest.top = dinahs[dynIndex].dest.bottom -
RectTall(&balloonSrc[0]);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = 0;
dinahs[dynIndex].vVel = -2;
dinahs[dynIndex].count = ((short)who->data.h.delay * 6) / kTicksPerFrame;
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = dinahs[dynIndex].count;
dinahs[dynIndex].position = 0;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn; // initially idle
}
}
break;
case kCopterLf:
case kCopterRt:
{
short baselineDeltaH = 0;
short baselineDeltaV = 0;
if (keepExisting)
{
baselineDeltaH = dinahs[dynIndex].dest.left - dinahs[dynIndex].position;
baselineDeltaV = dinahs[dynIndex].dest.top - kCopterStart;
}
dinahs[dynIndex].dest = copterSrc[0];
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest, where->left, 0);
dinahs[dynIndex].dest.top = kCopterStart + baselineDeltaV;
dinahs[dynIndex].dest.bottom = dinahs[dynIndex].dest.top +
RectTall(&copterSrc[0]);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].position = dinahs[dynIndex].dest.left;
if (what == kCopterLf)
dinahs[dynIndex].hVel = -1;
else
dinahs[dynIndex].hVel = 1;
dinahs[dynIndex].vVel = 2;
dinahs[dynIndex].count = ((short)who->data.h.delay * 6) / kTicksPerFrame;
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = dinahs[dynIndex].count;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn; // initially idle
}
}
break;
case kDartLf:
case kDartRt:
dinahs[dynIndex].dest = dartSrc[0];
ZeroRectCorner(&dinahs[dynIndex].dest);
if (what == kDartLf)
{
QOffsetRect(&dinahs[dynIndex].dest,
kRoomWide - RectWide(&dartSrc[0]), where->top);
dinahs[dynIndex].hVel = -kDartVelocity;
dinahs[dynIndex].frame = 0;
}
else
{
QOffsetRect(&dinahs[dynIndex].dest, 0, where->top);
dinahs[dynIndex].hVel = kDartVelocity;
dinahs[dynIndex].frame = 2;
}
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
dinahs[dynIndex].position = dinahs[dynIndex].dest.top;
if (!keepExisting)
{
dinahs[dynIndex].vVel = 2;
dinahs[dynIndex].count = ((short)who->data.h.delay * 6) / kTicksPerFrame;
dinahs[dynIndex].timer = dinahs[dynIndex].count;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn; // initially idle
}
break;
case kBall:
{
short baselineDelta = 0;
if (keepExisting)
baselineDelta = dinahs[dynIndex].dest.bottom - dinahs[dynIndex].position;
dinahs[dynIndex].dest = ballSrc[0];
ZeroRectCorner(&dinahs[dynIndex].dest);
QOffsetRect(&dinahs[dynIndex].dest,
where->left, where->top + baselineDelta);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].position = dinahs[dynIndex].dest.bottom;
dinahs[dynIndex].hVel = 0;
position = who->data.h.length; // reverse engineer init. vel.
velocity = 0;
evenFrame = true;
lilFrame = true;
do
{
if (lilFrame)
velocity++;
lilFrame = !lilFrame;
position -= velocity;
} while (position > 0);
dinahs[dynIndex].vVel = -velocity;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].count = -velocity; // count = initial velocity
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = 0;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].active = isOn;
}
}
break;
case kDrip:
{
short baselineDelta = 0;
if (keepExisting)
baselineDelta = dinahs[dynIndex].dest.top - dinahs[dynIndex].hVel;
dinahs[dynIndex].dest = dripSrc[0];
CenterRectInRect(&dinahs[dynIndex].dest, where);
VOffsetRect(&dinahs[dynIndex].dest,
where->top - dinahs[dynIndex].dest.top + baselineDelta);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].hVel = dinahs[dynIndex].dest.top; // remember
dinahs[dynIndex].position = dinahs[dynIndex].dest.top +
who->data.h.length;
dinahs[dynIndex].vVel = 0;
dinahs[dynIndex].count = ((short)who->data.h.delay * 6) / kTicksPerFrame;
dinahs[dynIndex].frame = 3;
dinahs[dynIndex].timer = dinahs[dynIndex].count;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
}
break;
case kFish:
{
short baselineDelta = 0;
if (keepExisting)
baselineDelta = dinahs[dynIndex].dest.bottom - dinahs[dynIndex].position;
dinahs[dynIndex].dest = fishSrc[0];
QOffsetRect(&dinahs[dynIndex].dest,
where->left + 10, where->top + 8 + baselineDelta);
dinahs[dynIndex].whole = dinahs[dynIndex].dest;
if (!keepExisting)
{
dinahs[dynIndex].position = dinahs[dynIndex].dest.bottom;
dinahs[dynIndex].hVel = ((short)who->data.h.delay * 6) / kTicksPerFrame;
position = who->data.g.height; // reverse engineer init. vel.
velocity = 0;
evenFrame = true;
lilFrame = true;
do
{
if (lilFrame)
velocity++;
lilFrame = !lilFrame;
position -= velocity;
} while (position > 0);
dinahs[dynIndex].vVel = -velocity;
dinahs[dynIndex].count = -velocity; // count = initial velocity
dinahs[dynIndex].frame = 0;
dinahs[dynIndex].timer = dinahs[dynIndex].hVel;
dinahs[dynIndex].room = room;
dinahs[dynIndex].byte0 = (Byte)index;
dinahs[dynIndex].byte1 = 0;
dinahs[dynIndex].moving = false;
dinahs[dynIndex].active = isOn;
}
}
break;
default:
break;
}
return dynIndex;
}

View File

@@ -8,12 +8,16 @@
#include "PLResources.h"
#include "PLPasStr.h"
#include "DisplayDeviceManager.h"
#include "Externs.h"
#include "Environ.h"
#include "HostDisplayDriver.h"
#include "HostSystemServices.h"
#include "MenuManager.h"
#include "IGpDisplayDriver.h"
#include "WindowManager.h"
#include <algorithm>
#define kSwitchDepthAlert 130
#define kSetMemoryAlert 180
@@ -272,6 +276,30 @@ short HowManyUsableScreens (Boolean use1Bit, Boolean use4Bit, Boolean use8Bit)
return 1;
}
//-------------------------------------------------------------- FlushResolutionChange
void FlushResolutionChange(void)
{
if (thisMac.isResolutionDirty)
{
GetDeviceRect(&thisMac.fullScreen);
thisMac.constrainedScreen = thisMac.fullScreen;
if (thisMac.constrainedScreen.Width() > kMaxViewWidth)
{
thisMac.constrainedScreen.left = 0;
thisMac.constrainedScreen.right = kMaxViewWidth;
}
if (thisMac.constrainedScreen.Height() > kMaxViewHeight)
{
thisMac.constrainedScreen.top = 0;
thisMac.constrainedScreen.bottom = kMaxViewHeight;
}
thisMac.gray = thisMac.fullScreen;
thisMac.gray.top = 20;
thisMac.isResolutionDirty = false;
}
}
//-------------------------------------------------------------- CheckOurEnvirons
// Calls all the above functions in order to fill out a sort of "spec sheet"É
// for the current Mac.
@@ -293,10 +321,57 @@ void CheckOurEnvirons (void)
thisMac.can4Bit = true;
thisMac.can8Bit = true;
thisMac.numScreens = HowManyUsableScreens(false, true, true);
GetDeviceRect(&thisMac.screen);
thisMac.wasDepth = WhatsOurDepth();
thisMac.wasColorOrGray = AreWeColorOrGrayscale();
thisMac.isResolutionDirty = true;
FlushResolutionChange();
}
//-------------------------------------------------------------- HandleResolutionChange
// Installs handler
void HandleResolutionChange(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight)
{
PortabilityLayer::WindowManager::GetInstance()->HandleScreenResolutionChange(prevWidth, prevHeight, newWidth, newHeight);
PortabilityLayer::MenuManager::GetInstance()->DrawMenuBar();
thisMac.isResolutionDirty = true; // Because of legacy code, we don't want to update thisMac.screen immediately, but rather, let the editor or game pick it up
}
class GpAppResolutionChangeHandler final : public PortabilityLayer::DisplayDeviceManager::IResolutionChangeHandler
{
public:
void OnResolutionChanged(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight) override
{
HandleResolutionChange(prevWidth, prevHeight, newWidth, newHeight);
}
void AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualHeight, float &pixelScaleX, float &pixelScaleY) override
{
double xMul = static_cast<double>(physicalWidth) / 640;
double yMul = static_cast<double>(physicalHeight) / 480;
xMul = floor(xMul);
yMul = floor(yMul);
double minMul = std::max<double>(1.0, std::min(xMul, yMul));
virtualWidth = physicalWidth / minMul;
virtualHeight = physicalHeight / minMul;
pixelScaleX = static_cast<float>(minMul);
pixelScaleY = static_cast<float>(minMul);
}
static GpAppResolutionChangeHandler ms_instance;
};
GpAppResolutionChangeHandler GpAppResolutionChangeHandler::ms_instance;
//-------------------------------------------------------------- InstallResolutionHandler
// Installs handler
void InstallResolutionHandler(void)
{
PortabilityLayer::DisplayDeviceManager::GetInstance()->SetResolutionChangeHandler(&GpAppResolutionChangeHandler::ms_instance);
}
//-------------------------------------------------------------- ReflectMonitor2Environs
@@ -410,7 +485,7 @@ void CheckMemorySize (void)
RedAlert(kErrNoMemory);
else
bytesNeeded += musicBytes;
bytesNeeded += 4L * (long)thisMac.screen.bottom; // main screen
bytesNeeded += 4L * (long)thisMac.constrainedScreen.bottom; // main screen
bytesNeeded += (((long)houseRect.right - (long)houseRect.left) *
((long)houseRect.bottom + 1 - (long)houseRect.top) *
(long)thisMac.isDepth) / 8L; // work map

View File

@@ -10,7 +10,7 @@
typedef struct
{
Rect screen, gray;
Rect fullScreen, constrainedScreen, gray;
long dirID;
short wasDepth, isDepth;
short numScreens;
@@ -28,9 +28,10 @@ typedef struct
Boolean hasSM3;
Boolean hasQT;
Boolean hasDrag;
Boolean isResolutionDirty;
} macEnviron;
extern macEnviron thisMac;
void FlushResolutionChange(void);

View File

@@ -17,6 +17,7 @@
#include "House.h"
#include "InputManager.h"
#include "ObjectEdit.h"
#include "Rect2i.h"
#include "WindowManager.h"
@@ -30,6 +31,7 @@ void HandleIdleTask (void);
void IncrementMode (void);
long lastUp, incrementModeTime;
UInt32 doubleTime;
Point lastWhere;
@@ -81,7 +83,7 @@ void HandleMouseEvent (const GpMouseInputEvent &theEvent, uint32_t tick)
break;
case RegionIDs::kTitleBar:
PortabilityLayer::WindowManager::GetInstance()->DragWindow(whichWindow, evtPoint, thisMac.screen);
PortabilityLayer::WindowManager::GetInstance()->DragWindow(whichWindow, evtPoint, thisMac.fullScreen);
if (whichWindow == mainWindow)
GetWindowLeftTop(whichWindow, &isEditH, &isEditV);
else if (whichWindow == mapWindow)
@@ -349,11 +351,6 @@ void HandleUpdateEvent (EventRecord *theEvent)
UpdateCoordWindow();
EndUpdate(coordWindow);
}
else if ((WindowPtr)theEvent->message == menuWindow)
{
UpdateMenuBarWindow(menuWindow->GetDrawSurface());
EndUpdate(menuWindow);
}
}
//-------------------------------------------------------------- HandleOSEvent
@@ -426,6 +423,68 @@ void HandleHighLevelEvent (EventRecord *theEvent)
}
#endif
//-------------------------------------------------------------- HandleSplashResolutionChange
void HandleSplashResolutionChange(void)
{
FlushResolutionChange();
RecomputeInterfaceRects();
RecreateOffscreens();
CloseMainWindow();
OpenMainWindow();
UpdateMainWindow();
//ResetLocale(true);
InitScoreboardMap();
//RefreshScoreboard(wasScoreboardTitleMode);
//DumpScreenOn(&justRoomsRect);
}
void KeepWindowInBounds(Window *window)
{
if (!window)
return;
PortabilityLayer::Rect2i windowRect = PortabilityLayer::WindowManager::GetInstance()->GetWindowFullRect(window);
int32_t topNudge = std::max<int32_t>(kScoreboardTall - windowRect.Top(), 0);
int32_t bottomNudge = std::min<int32_t>(thisMac.fullScreen.bottom - windowRect.Bottom(), 0);
int32_t leftNudge = std::max<int32_t>(-windowRect.Left(), 0);
int32_t rightNudge = std::min<int32_t>(thisMac.fullScreen.right - windowRect.Right(), 0);
window->m_wmX += leftNudge + rightNudge;
window->m_wmY += topNudge + bottomNudge;
}
void HandleEditorResolutionChange(void)
{
FlushResolutionChange();
RecomputeInterfaceRects();
RecreateOffscreens();
CloseMainWindow();
OpenMainWindow();
UpdateMainWindow();
//ResetLocale(true);
InitScoreboardMap();
//RefreshScoreboard(wasScoreboardTitleMode);
//DumpScreenOn(&justRoomsRect);
if (toolsWindow)
PortabilityLayer::WindowManager::GetInstance()->PutWindowBehind(toolsWindow, PortabilityLayer::WindowManager::GetInstance()->GetPutInFrontSentinel());
if (mapWindow)
PortabilityLayer::WindowManager::GetInstance()->PutWindowBehind(mapWindow, PortabilityLayer::WindowManager::GetInstance()->GetPutInFrontSentinel());
KeepWindowInBounds(mainWindow);
KeepWindowInBounds(toolsWindow);
KeepWindowInBounds(mapWindow);
}
//-------------------------------------------------------------- HandleIdleTask
// Handle some processing during event lulls.
@@ -433,6 +492,11 @@ void HandleIdleTask (void)
{
if (theMode == kEditMode)
{
if (thisMac.isResolutionDirty)
{
HandleEditorResolutionChange();
}
SetPort(&mainWindow->GetDrawSurface()->m_port);
DoMarquee();
@@ -443,6 +507,14 @@ void HandleIdleTask (void)
newRoomNow = false;
}
}
if (theMode == kSplashMode)
{
if (thisMac.isResolutionDirty)
{
HandleSplashResolutionChange();
}
}
}
//-------------------------------------------------------------- HandleEvent

View File

@@ -167,6 +167,7 @@ void IgnoreThisClick (void);
short WhatsOurDepth (void); // --- Environs.c
void SwitchToDepth (short, Boolean);
void CheckOurEnvirons (void);
void InstallResolutionHandler (void);
//void ReflectSecondMonitorEnvirons (Boolean, Boolean, Boolean);
void HandleDepthSwitching (void);
void RestoreColorDepth (void);

View File

@@ -102,10 +102,10 @@ void SetUpFinalScreen (void)
do
{
GetLineOfText(tempStr, count, subStr);
offset = ((thisMac.screen.right - thisMac.screen.left) -
surface->MeasureString(subStr)) / 2;
surface->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold);
offset = ((thisMac.constrainedScreen.right - thisMac.constrainedScreen.left) -
surface->MeasureString(subStr)) / 2;
surface->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255));
const Point textShadowPos = Point::Create(offset + 1, textDown + 33 + (count * 20));
@@ -146,6 +146,12 @@ void DoGameOverStarAnimation (void)
long nextLoop;
short which, i, count, pass;
Boolean noInteruption;
short starFallSpeed = kStarFalls;
const int kStarSpacing = 32;
const int kAngelSpeed = 2;
const int kStarsReserved = 5;
const int kMaxFramesAlive = (kStarSpacing * kStarsReserved + kAngelSpeed - 1) / kAngelSpeed;
angelDest = angelSrcRect;
QOffsetRect(&angelDest, -96, 0);
@@ -154,14 +160,19 @@ void DoGameOverStarAnimation (void)
count = 0;
pass = 0;
FlushEvents(everyEvent, 0);
if (workSrcRect.bottom - angelDest.bottom > kMaxFramesAlive * starFallSpeed)
starFallSpeed = (workSrcRect.bottom - angelDest.bottom + kMaxFramesAlive - 1) / kMaxFramesAlive;
while (noInteruption)
{
if ((angelDest.left % 32) == 0) // add a star
if ((angelDest.left % kStarSpacing) == 0) // add a star
{
PlayPrioritySound(kMysticSound, kMysticPriority);
which = angelDest.left / 32;
which = which % 5;
which = angelDest.left / kStarSpacing;
which = which % kStarsReserved;
if (which < 0)
which += kStarsReserved;
ZeroRectCorner(&pages[which].dest);
QOffsetRect(&pages[which].dest, angelDest.left, angelDest.bottom);
if (count < (which + 1))
@@ -182,13 +193,13 @@ void DoGameOverStarAnimation (void)
&pages[i].dest);
pages[i].was = pages[i].dest;
pages[i].was.top -= kStarFalls;
pages[i].was.top -= starFallSpeed;
AddRectToWorkRectsWhole(&pages[i].was);
AddRectToBackRects(&pages[i].dest);
if (pages[i].dest.top < workSrcRect.bottom)
QOffsetRect(&pages[i].dest, 0, kStarFalls);
QOffsetRect(&pages[i].dest, 0, starFallSpeed);
}
if (angelDest.left <= (workSrcRect.right + 2))
@@ -197,11 +208,11 @@ void DoGameOverStarAnimation (void)
(BitMap *)*GetGWorldPixMap(angelMaskMap),
(BitMap *)*GetGWorldPixMap(workSrcMap),
&angelSrcRect, &angelSrcRect, &angelDest);
angelDest.left -= 2;
angelDest.left -= kAngelSpeed;
AddRectToWorkRectsWhole(&angelDest);
angelDest.left += 2;
angelDest.left += kAngelSpeed;
AddRectToBackRects(&angelDest);
QOffsetRect(&angelDest, 2, 0);
QOffsetRect(&angelDest, kAngelSpeed, 0);
pass = 0;
}
@@ -283,14 +294,14 @@ void InitDiedGameOver (void)
for (i = 0; i < 8; i++) // initialize dest page rects
{
QSetRect(&pages[i].dest, 0, 0, 32, 32);
CenterRectInRect(&pages[i].dest, &thisMac.screen);
QOffsetRect(&pages[i].dest, -thisMac.screen.left, -thisMac.screen.top);
CenterRectInRect(&pages[i].dest, &thisMac.constrainedScreen);
QOffsetRect(&pages[i].dest, -thisMac.constrainedScreen.left, -thisMac.constrainedScreen.top);
if (i < 4)
QOffsetRect(&pages[i].dest, -kPageSpacing * (4 - i), 0);
else
QOffsetRect(&pages[i].dest, kPageSpacing * (i - 3), 0);
QOffsetRect(&pages[i].dest, (thisMac.screen.right - thisMac.screen.left) / -2,
(thisMac.screen.right - thisMac.screen.left) / -2);
QOffsetRect(&pages[i].dest, (thisMac.constrainedScreen.right - thisMac.constrainedScreen.left) / -2,
(thisMac.constrainedScreen.right - thisMac.constrainedScreen.left) / -2);
if (pages[i].dest.left % 2 == 1)
QOffsetRect(&pages[i].dest, 1, 0);
pages[i].was = pages[i].dest;
@@ -306,7 +317,7 @@ void InitDiedGameOver (void)
}
pagesStuck = 0;
stopPages = ((thisMac.screen.bottom - thisMac.screen.top) / 2) - 16;
stopPages = ((thisMac.constrainedScreen.bottom - thisMac.constrainedScreen.top) / 2) - 16;
}
//-------------------------------------------------------------- HandlePages

View File

@@ -265,7 +265,7 @@
#define kMaxDynamicObs 18
#define kMaxMasterObjects 216 // kMaxRoomObs * 9
#define kMaxViewWidth 1536
#define kMaxViewHeight 1026
#define kMaxViewHeight (kTileHigh*3+20)
#define kSelectTool 0
@@ -510,8 +510,6 @@
#define kNoCeilingLimit -10
#define kNoFloorLimit 332
#define kScoreboardHigh 0
#define kScoreboardLow 1
#define kScoreboardTall 20
#define kHouseVersion 0x0200

View File

@@ -25,24 +25,26 @@ void ToggleCoordinateWindow (void);
void NilSavedMaps (void); // --- DynamicMaps.c
SInt16 BackUpToSavedMap (Rect *, SInt16, SInt16);
SInt16 ReBackUpSavedMap (Rect *, SInt16, SInt16);
SInt16 RemoveFromSavedMap(SInt16);
void RestoreFromSavedMap (SInt16, SInt16, Boolean);
void AddSparkle (Rect *);
void AddFlyingPoint (Rect *, SInt16, SInt16, SInt16);
void ReBackUpFlames (SInt16, SInt16);
Boolean ReBackUpFlames (SInt16, SInt16, SInt16, SInt16);
void AddCandleFlame (SInt16, SInt16, SInt16, SInt16);
void ReBackUpTikiFlames (SInt16, SInt16);
Boolean ReBackUpTikiFlames (SInt16, SInt16, SInt16, SInt16);
void AddTikiFlame (SInt16, SInt16, SInt16, SInt16);
void ReBackUpBBQCoals (SInt16, SInt16);
Boolean ReBackUpBBQCoals (SInt16, SInt16, SInt16, SInt16);
void AddBBQCoals (SInt16, SInt16, SInt16, SInt16);
void ReBackUpPendulum (SInt16, SInt16);
Boolean ReBackUpPendulum (SInt16, SInt16, SInt16, SInt16);
void AddPendulum (SInt16, SInt16, SInt16, SInt16);
void ReBackUpStar (SInt16, SInt16);
void ReBackUpStar (SInt16, SInt16, SInt16, SInt16);
void AddStar (SInt16, SInt16, SInt16, SInt16);
void StopPendulum (SInt16, SInt16);
void StopStar (SInt16, SInt16);
void AddAShreddedGlider (Rect *);
void RemoveShreds (void);
void ZeroFlamesAndTheLike (void);
void RemoveSavedMapsNotInRoom (SInt16);
void CheckDynamicCollision (SInt16, gliderPtr, Boolean); // --- Dynamics.c
Boolean DidBandHitDynamic (SInt16);
@@ -73,17 +75,21 @@ void HandleFish (SInt16);
void HandleDynamics (void); // --- Dynamics3.c
void RenderDynamics (void);
void ZeroDinahs (void);
SInt16 AddDynamicObject (SInt16, Rect *, objectType *, SInt16, SInt16, Boolean);
void ZeroDinahsNotInRoom (SInt16);
SInt16 AddDynamicObject(SInt16 what, Rect *where, objectType *who, SInt16 room, SInt16 index, Boolean isOn, Boolean keepExisting);
void DoGameOver (void); // --- GameOver.c
void FlagGameOver (void);
void DoDiedGameOver (void);
void HandleGrease (void); // --- Grease.c
SInt16 ReBackUpGrease (SInt16, SInt16);
SInt16 ReBackUpGrease (SInt16 where, SInt16 who, SInt16 h, SInt16 v);
SInt16 AddGrease (SInt16, SInt16, SInt16, SInt16, SInt16, Boolean);
void SpillGrease (SInt16, SInt16);
void RedrawAllGrease (void);
void FixupFallenGrease(SInt16 where, SInt16 who, SInt16 h, SInt16 v, Boolean *isDynamic);
void RemapGreaseSavedMap(SInt16 removedItem, SInt16 substituteItem);
void DoHighScores (void); // --- HighScores.c
void SortHighScores (void);
@@ -132,6 +138,7 @@ void FlagStillOvers (gliderPtr);
void InitializeMenus (void); // --- InterfaceInit.c
void GetExtraCursors (void);
void RecomputeInterfaceRects (void);
void VariableInit (void);
void GetDemoInput (gliderPtr); // --- Input.c
@@ -147,7 +154,6 @@ void HandleLinkClick (Point);
void RedrawSplashScreen (void); // --- MainWindow.c
void UpdateMainWindow (void);
void UpdateMenuBarWindow (DrawSurface *surface);
void OpenMainWindow (void);
void CloseMainWindow (void);
void ZoomBetweenWindows (void);
@@ -257,8 +263,8 @@ void DrawBlueClock (Rect *);
void DrawYellowClock (Rect *);
void DrawCuckoo (Rect *);
void DrawSimplePrizes (SInt16, Rect *);
void DrawGreaseRt (Rect *, SInt16, Boolean);
void DrawGreaseLf (Rect *, SInt16, Boolean);
void DrawGreaseRt (Rect *, SInt16, Boolean, Boolean);
void DrawGreaseLf (Rect *, SInt16, Boolean, Boolean);
void DrawFoil (Rect *);
void DrawInvisBonus (Rect *);
void DrawSlider (Rect *);
@@ -407,7 +413,8 @@ Boolean DoesRoomHaveFloor (void);
Boolean DoesRoomHaveCeiling (void);
void ReadyLevel (void); // --- RoomGraphics.c
void DrawLocale (void);
void ResetLocale (Boolean soft);
void DrawLocale (Boolean soft);
void RedrawRoomLighting (void);
Boolean PictIDExists (SInt16); // --- RoomInfo.c
@@ -428,8 +435,6 @@ void QuickBatteryRefresh (Boolean);
void QuickBandsRefresh (Boolean);
void QuickFoilRefresh (Boolean);
void HandleScore (void);
void AdjustScoreboardHeight (void);
void BlackenScoreboard (DrawSurface *);
//void PutRoomScrap (void); // --- Scrap.c
//void PutObjectScrap (void);
@@ -470,6 +475,7 @@ void InitEnemies (void);
void CreateOffscreens (void); // --- StructuresInit2.c
void CreatePointers (void);
void InitSrcRects (void);
PLError_t RecreateOffscreens (void);
void UpdateToolsWindow (void); // --- Tools.c
void EraseSelectedTool (void);

View File

@@ -25,6 +25,7 @@ public:
void PL_HostFontHandler_SetInstance(PortabilityLayer::HostFontHandler *instance) override;
void PL_HostVOSEventQueue_SetInstance(PortabilityLayer::HostVOSEventQueue *instance) override;
void PL_InstallHostSuspendHook(PortabilityLayer::HostSuspendHook_t hook, void *context) override;
bool PL_AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY) override;
};
@@ -79,6 +80,19 @@ void GpAppInterfaceImpl::PL_InstallHostSuspendHook(PortabilityLayer::HostSuspend
PortabilityLayer::InstallHostSuspendHook(hook, context);
}
bool GpAppInterfaceImpl::PL_AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY)
{
PortabilityLayer::DisplayDeviceManager::IResolutionChangeHandler *handler = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetResolutionChangeHandler();
if (!handler)
return false;
handler->AdjustRequestedResolution(physicalWidth, physicalHeight, virtualWidth, virtualheight, pixelScaleX, pixelScaleY);
return true;
}
static GpAppInterfaceImpl gs_application;

View File

@@ -28,8 +28,7 @@ short numGrease;
extern hotPtr hotSpots;
extern savedType savedMaps[];
extern Point shieldPt;
extern Rect greaseSrcRt[], greaseSrcLf[], shieldRect;
extern Rect greaseSrcRt[], greaseSrcLf[];
//============================================================== Functions
@@ -168,7 +167,7 @@ void BackupGrease (Rect *src, short index, Boolean isRight)
// off or on the lights). It assumes certain data strucutures areÉ
// already declared from an earlier call to the above funciton.
short ReBackUpGrease (short where, short who)
short ReBackUpGrease (short where, short who, short h, short v)
{
Rect src;
short i;
@@ -179,6 +178,13 @@ short ReBackUpGrease (short where, short who)
{
if ((grease[i].mode == kGreaseIdle) || (grease[i].mode == kGreaseFalling))
{
greasePtr greaseItem = &grease[i];
const short hDelta = h - grease[i].dest.left;
const short vDelta = v - grease[i].dest.top;
QOffsetRect(&greaseItem->dest, hDelta, vDelta);
greaseItem->start += hDelta;
greaseItem->stop += hDelta;
src = grease[i].dest;
BackupGrease(&src, grease[i].mapNum, grease[i].isRight);
}
@@ -269,10 +275,12 @@ void RedrawAllGrease (void)
for (i = 0; i < numGrease; i++)
{
if (grease[i].mode == kGreaseIdle)
continue;
src = hotSpots[grease[i].hotNum].bounds;
if ((grease[i].where == thisRoomNumber) &&
((src.bottom - src.top) == 2) &&
(grease[i].mode != kGreaseIdle))
((src.bottom - src.top) == 2))
{
QOffsetRect(&src, playOriginH, playOriginV);
@@ -288,3 +296,41 @@ void RedrawAllGrease (void)
}
}
void FixupFallenGrease(SInt16 where, SInt16 who, SInt16 h, SInt16 v, Boolean *isDynamic)
{
short i;
for (i = 0; i < numGrease; i++)
{
greasePtr greaseItem = grease + i;
if ((greaseItem->where == where) && (greaseItem->who == who))
{
short hDelta = h - greaseItem->dest.left;
short vDelta = v - greaseItem->dest.top;
QOffsetRect(&greaseItem->dest, hDelta, vDelta);
greaseItem->start += hDelta;
greaseItem->stop += hDelta;
if (greaseItem->mode != kGreaseIdle)
{
hotPtr hotSpot = &hotSpots[greaseItem->hotNum];
//QOffsetRect(&hotSpot->bounds, hDelta, vDelta);
}
*isDynamic = true;
return;
}
}
*isDynamic = false;
}
void RemapGreaseSavedMap(SInt16 removedItem, SInt16 substituteItem)
{
for (int i = 0; i < numGrease; i++)
{
if (grease[i].mapNum == substituteItem)
{
grease[i].mapNum = removedItem;
return;
}
}
}

View File

@@ -23,6 +23,7 @@
#include "IOStream.h"
#include "MainWindow.h"
#include "RectUtils.h"
#include "PLStandardColors.h"
#include "PLTimeTaggedVOSEvent.h"
#include "Utilities.h"
@@ -70,6 +71,7 @@ void DoHighScores (void)
SpinCursor(3);
SetPort(&workSrcMap->m_port);
workSrcMap->SetForeColor(StdColors::Black());
workSrcMap->FillRect(workSrcRect);
QSetRect(&tempRect, 0, 0, 640, 480);
QOffsetRect(&tempRect, splashOriginH, splashOriginV);
@@ -123,7 +125,7 @@ void DrawHighScores (DrawSurface *surface)
PortabilityLayer::RGBAColor whiteColor = PortabilityLayer::RGBAColor::Create(255, 255, 255, 255);
PortabilityLayer::RGBAColor blueColor = PortabilityLayer::RGBAColor::Create(0, 0, 255, 255);
scoreLeft = ((thisMac.screen.right - thisMac.screen.left) - kScoreWide) / 2;
scoreLeft = ((thisMac.constrainedScreen.right - thisMac.constrainedScreen.left) - kScoreWide) / 2;
dropIt = 129 + splashOriginV;
QSetRect(&tempRect, 0, 0, 332, 30);

View File

@@ -26,12 +26,10 @@ struct IGpCursor;
extern THandle<Rect> mirrorRects;
extern WindowPtr mapWindow, toolsWindow, linkWindow;
extern WindowPtr menuWindow;
extern Rect shieldRect, boardSrcRect, localRoomsDest[];
extern Rect boardSrcRect, localRoomsDest[];
extern IGpCursor *handCursor, *vertCursor, *horiCursor;
extern IGpCursor *diagCursor;
extern MenuHandle appleMenu, gameMenu, optionsMenu, houseMenu;
extern Point shieldPt;
extern long incrementModeTime;
extern UInt32 doubleTime;
extern short fadeInSequence[], idleMode;
@@ -99,6 +97,40 @@ void GetExtraCursors (void)
RedAlert(kErrFailedResourceLoad);
}
//-------------------------------------------------------------- RecomputeScreenRects
void RecomputeInterfaceRects (void)
{
houseRect = thisMac.constrainedScreen;
houseRect.bottom -= kScoreboardTall;
if (houseRect.right > kMaxViewWidth)
houseRect.right = kMaxViewWidth;
if (houseRect.bottom > kMaxViewHeight)
houseRect.bottom = kMaxViewHeight;
// NOTE: This is actually buggy, since the visible area is houseRect, not screen.
// We preserve the buggy behavior for authenticity unless the window is very tall.
short poHeight = RectTall(&thisMac.constrainedScreen);
if (poHeight > kMaxViewHeight - kScoreboardTall)
poHeight = kMaxViewHeight - kScoreboardTall;
playOriginH = (RectWide(&thisMac.constrainedScreen) - kRoomWide) / 2;
playOriginV = (poHeight - kTileHigh) / 2;
for (int i = 0; i < 9; i++)
{
QSetRect(&localRoomsDest[i], 0, 0, kRoomWide, kTileHigh);
QOffsetRect(&localRoomsDest[i], playOriginH, playOriginV);
}
QOffsetRect(&localRoomsDest[kNorthRoom], 0, -kVertLocalOffset);
QOffsetRect(&localRoomsDest[kNorthEastRoom], kRoomWide, -kVertLocalOffset);
QOffsetRect(&localRoomsDest[kEastRoom], kRoomWide, 0);
QOffsetRect(&localRoomsDest[kSouthEastRoom], kRoomWide, kVertLocalOffset);
QOffsetRect(&localRoomsDest[kSouthRoom], 0, kVertLocalOffset);
QOffsetRect(&localRoomsDest[kSouthWestRoom], -kRoomWide, kVertLocalOffset);
QOffsetRect(&localRoomsDest[kWestRoom], -kRoomWide, 0);
QOffsetRect(&localRoomsDest[kNorthWestRoom], -kRoomWide, -kVertLocalOffset);
}
//-------------------------------------------------------------- VariableInit
// All the simple interface variables are intialized here - Booleans,É
@@ -108,10 +140,6 @@ void VariableInit (void)
{
short i;
shieldPt.h = 0;
shieldPt.v = 0;
shieldRect = thisMac.screen;
menusUp = false;
quitting = false;
houseOpen = false;
@@ -184,30 +212,6 @@ void VariableInit (void)
coordWindow = nil;
toolSrcMap = nil;
nailSrcMap = nil;
menuWindow = nil;
houseRect = thisMac.screen;
houseRect.bottom -= kScoreboardTall;
if (houseRect.right > kMaxViewWidth)
houseRect.right = kMaxViewWidth;
if (houseRect.bottom > kMaxViewHeight)
houseRect.bottom = kMaxViewHeight;
playOriginH = (RectWide(&thisMac.screen) - kRoomWide) / 2;
playOriginV = (RectTall(&thisMac.screen) - kTileHigh) / 2;
for (i = 0; i < 9; i++)
{
QSetRect(&localRoomsDest[i], 0, 0, kRoomWide, kTileHigh);
QOffsetRect(&localRoomsDest[i], playOriginH, playOriginV);
}
QOffsetRect(&localRoomsDest[kNorthRoom], 0, -kVertLocalOffset);
QOffsetRect(&localRoomsDest[kNorthEastRoom], kRoomWide, -kVertLocalOffset);
QOffsetRect(&localRoomsDest[kEastRoom], kRoomWide, 0);
QOffsetRect(&localRoomsDest[kSouthEastRoom], kRoomWide, kVertLocalOffset);
QOffsetRect(&localRoomsDest[kSouthRoom], 0, kVertLocalOffset);
QOffsetRect(&localRoomsDest[kSouthWestRoom], -kRoomWide, kVertLocalOffset);
QOffsetRect(&localRoomsDest[kWestRoom], -kRoomWide, 0);
QOffsetRect(&localRoomsDest[kNorthWestRoom], -kRoomWide, -kVertLocalOffset);
RecomputeInterfaceRects();
}

View File

@@ -204,7 +204,7 @@ void ReadInPrefs (void)
doBitchDialogs = true;
}
if ((numNeighbors > 1) && (thisMac.screen.right <= 512))
if ((numNeighbors > 1) && (thisMac.constrainedScreen.right <= 512))
numNeighbors = 1;
UnivGetSoundVolume(&wasVolume, thisMac.hasSM3);
@@ -315,6 +315,7 @@ int gpAppMain()
ToolBoxInit();
CheckOurEnvirons();
InstallResolutionHandler();
if (!thisMac.hasColor)
RedAlert(kErrNeedColorQD);
if (!thisMac.hasSystem7)

View File

@@ -11,7 +11,9 @@
#include "Externs.h"
#include "Environ.h"
#include "FontFamily.h"
#include "HostDisplayDriver.h"
#include "House.h"
#include "IGpDisplayDriver.h"
#include "InputManager.h"
#include "MenuManager.h"
#include "QDPixMap.h"
@@ -30,7 +32,7 @@
void DrawOnSplash (DrawSurface *surface);
void SetPaletteToGrays (void);
void HardDrawMainWindow (void);
void KeepWindowInBounds(Window *window);
CTabHandle theCTab;
PixMapHandle thePMap;
@@ -41,7 +43,7 @@ IGpCursor *diagCursor;
Rect workSrcRect;
DrawSurface *workSrcMap;
Rect mainWindowRect;
WindowPtr mainWindow, menuWindow, boardWindow;
WindowPtr mainWindow, boardWindow;
short isEditH, isEditV;
short playOriginH, playOriginV;
short splashOriginH, splashOriginV;
@@ -165,22 +167,6 @@ void UpdateMainWindow (void)
splashDrawn = true;
}
//-------------------------------------------------------------- UpdateMenuBarWindow
// Ugly kludge to cover over the menu bar when playing game on 2nd monitor.
void UpdateMenuBarWindow (DrawSurface *surface)
{
Rect bounds;
if (menuWindow == nil)
return;
GetLocalWindowRect(menuWindow, &bounds);
surface->SetForeColor(StdColors::Black());
surface->FillRect(bounds);
}
//-------------------------------------------------------------- OpenMainWindow
// Opens up the main window (how it does this depends on mode were in).
@@ -197,10 +183,8 @@ void OpenMainWindow (void)
if (theMode == kEditMode)
{
if (menuWindow != nil)
PortabilityLayer::WindowManager::GetInstance()->DestroyWindow(menuWindow);
menuWindow = nil;
PortabilityLayer::HostDisplayDriver::GetInstance()->SetBackgroundColor(51, 51, 102, 255);
QSetRect(&mainWindowRect, 0, 0, 512, 322);
mainWindow = GetNewCWindow(kEditWindowID, nil, kPutInFront);
SizeWindow(mainWindow, mainWindowRect.right,
@@ -223,22 +207,22 @@ void OpenMainWindow (void)
whichRoom = GetFirstRoomNumber();
CopyRoomToThisRoom(whichRoom);
ReflectCurrentRoom(false);
KeepWindowInBounds(mainWindow);
}
else
{
if (menuWindow == nil)
{
menuWindow = GetNewCWindow(kMenuWindowID, nil, kPutInFront);
SizeWindow(menuWindow, RectWide(&thisMac.screen), 20, false);
MoveWindow(menuWindow, thisMac.screen.left,
thisMac.screen.top, true);
ShowWindow(menuWindow);
}
#ifdef NDEBUG
PortabilityLayer::HostDisplayDriver::GetInstance()->SetBackgroundColor(0, 0, 0, 255);
#else
PortabilityLayer::HostDisplayDriver::GetInstance()->SetBackgroundColor(51, 0, 0, 255);
#endif
if (boardWindow == nil)
{
PortabilityLayer::WindowManager *windowManager = PortabilityLayer::WindowManager::GetInstance();
Rect scorebarRect = thisMac.screen;
Rect scorebarRect = thisMac.constrainedScreen;
scorebarRect.bottom = scorebarRect.top + kScoreboardTall;
PortabilityLayer::WindowDef windowDef = PortabilityLayer::WindowDef::Create(scorebarRect, PortabilityLayer::WindowStyleFlags::kBorderless, true, 0, 0, PSTR("Scoreboard"));
@@ -248,14 +232,18 @@ void OpenMainWindow (void)
else
PL_NotYetImplemented_TODO("Errors");
}
mainWindowRect = thisMac.screen;
mainWindowRect = thisMac.constrainedScreen;
ZeroRectCorner(&mainWindowRect);
mainWindowRect.bottom -= 20; // thisMac.menuHigh
mainWindowRect.bottom -= kScoreboardTall; // thisMac.menuHigh
mainWindow = GetNewCWindow(kMainWindowID, nil, kPutInFront);
SizeWindow(mainWindow, mainWindowRect.right - mainWindowRect.left,
mainWindowRect.bottom - mainWindowRect.top, false);
MoveWindow(mainWindow, thisMac.screen.left,
thisMac.screen.top + 20, true); // thisMac.menuHigh
const short mainWindowLeft = (thisMac.fullScreen.left + thisMac.fullScreen.right + thisMac.constrainedScreen.left - thisMac.constrainedScreen.right) / 2;
const short mainWindowTop = (thisMac.fullScreen.top + thisMac.fullScreen.bottom + thisMac.constrainedScreen.top - thisMac.constrainedScreen.bottom) / 2 + kScoreboardTall;
MoveWindow(boardWindow, mainWindowLeft, 0, true);
MoveWindow(mainWindow, mainWindowLeft, mainWindowTop, true); // thisMac.menuHigh
ShowWindow(mainWindow);
SetPortWindowPort(mainWindow);
@@ -267,15 +255,14 @@ void OpenMainWindow (void)
mainWindowSurface->SetBackColor(StdColors::White());
mainWindowSurface->FillRect(mainWindowRect);
splashOriginH = ((thisMac.screen.right - thisMac.screen.left) - 640) / 2;
splashOriginH = ((thisMac.constrainedScreen.right - thisMac.constrainedScreen.left) - 640) / 2;
if (splashOriginH < 0)
splashOriginH = 0;
splashOriginV = ((thisMac.screen.bottom - thisMac.screen.top) - 480) / 2;
splashOriginV = ((thisMac.constrainedScreen.bottom - thisMac.constrainedScreen.top) - 480) / 2;
if (splashOriginV < 0)
splashOriginV = 0;
workSrcMap->FillRect(workSrcRect);
LoadGraphic(workSrcMap, kSplash8BitPICT);
// if ((fadeGraysOut) && (isDoColorFade))
// {
@@ -288,6 +275,7 @@ void OpenMainWindow (void)
// }
SetPortWindowPort(mainWindow);
UpdateMainWindow();
}
CopyBits((BitMap *)*GetGWorldPixMap(workSrcMap),

View File

@@ -40,6 +40,7 @@ void LiveVScrollAction (ControlHandle, short);
Boolean QueryNewRoom (void);
void CreateNailOffscreen (void);
void KillNailOffscreen (void);
void KeepWindowInBounds (Window *window);
Rect nailSrcRect, activeRoomRect, wasActiveRoomRect;
Rect mapHScrollRect, mapVScrollRect, mapCenterRect;
@@ -430,6 +431,8 @@ void OpenMapWindow (void)
CenterMapOnRoom(thisRoom->suite, thisRoom->floor);
UpdateMapWindow();
KeepWindowInBounds(mapWindow);
}
UpdateMapCheckmark(true);

View File

@@ -1224,7 +1224,7 @@ void DrawSimplePrizes (short what, Rect *theRect)
//-------------------------------------------------------------- DrawGreaseRt
void DrawGreaseRt (Rect *theRect, short distance, Boolean state)
void DrawGreaseRt (Rect *theRect, short distance, Boolean state, Boolean drawSpill)
{
Rect spill, dest;
@@ -1243,18 +1243,21 @@ void DrawGreaseRt (Rect *theRect, short distance, Boolean state)
(BitMap *)*GetGWorldPixMap(bonusMaskMap),
(BitMap *)*GetGWorldPixMap(backSrcMap),
&greaseSrcRt[3], &greaseSrcRt[3], &dest);
QSetRect(&spill, 0, -2, distance - 5, 0);
QOffsetRect(&spill, dest.right - 1, dest.bottom);
backSrcMap->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255));
backSrcMap->FillRect(spill);
if (drawSpill)
{
QSetRect(&spill, 0, -2, distance - 5, 0);
QOffsetRect(&spill, dest.right - 1, dest.bottom);
backSrcMap->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255));
backSrcMap->FillRect(spill);
}
}
}
//-------------------------------------------------------------- DrawGreaseLf
void DrawGreaseLf (Rect *theRect, short distance, Boolean state)
void DrawGreaseLf (Rect *theRect, short distance, Boolean state, Boolean drawSpill)
{
Rect spill, dest;
DrawSurface *wasCPort;
@@ -1275,11 +1278,14 @@ void DrawGreaseLf (Rect *theRect, short distance, Boolean state)
(BitMap *)*GetGWorldPixMap(backSrcMap),
&greaseSrcLf[3], &greaseSrcLf[3], &dest);
backSrcMap->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255));
if (drawSpill)
{
backSrcMap->SetForeColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255));
QSetRect(&spill, -distance + 5, -2, 0, 0);
QOffsetRect(&spill, dest.left + 1, dest.bottom);
backSrcMap->FillRect(spill);
QSetRect(&spill, -distance + 5, -2, 0, 0);
QOffsetRect(&spill, dest.left + 1, dest.bottom);
backSrcMap->FillRect(spill);
}
}
}

View File

@@ -73,11 +73,13 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
DrawSimpleBlowers(thisObject.what, &itsRect);
if (neighbor == kCentralRoom)
{
const short h = itsRect.left + 10;
const short v = itsRect.top + 7;
if (redraw)
ReBackUpFlames(localNumbers[neighbor], i);
ReBackUpFlames(localNumbers[neighbor], i, h, v);
else
AddCandleFlame(localNumbers[neighbor], i,
itsRect.left + 10, itsRect.top + 7);
h, v);
}
else
{
@@ -88,11 +90,13 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
rectB.bottom += kFloorSupportTall;
if (!SectRect(&rectA, &rectB, &whoCares))
{
const short h = itsRect.left + 10;
const short v = itsRect.top + 7;
if (redraw)
ReBackUpFlames(localNumbers[neighbor], i);
ReBackUpFlames(localNumbers[neighbor], i, h, v);
else
AddCandleFlame(localNumbers[neighbor], i,
itsRect.left + 10, itsRect.top + 7);
h, v);
}
}
}
@@ -107,11 +111,13 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
DrawSimpleBlowers(thisObject.what, &itsRect);
if (neighbor == kCentralRoom)
{
const short h = itsRect.left + 14;
const short v = itsRect.top + 7;
if (redraw)
ReBackUpFlames(localNumbers[neighbor], i);
ReBackUpFlames(localNumbers[neighbor], i, h, v);
else
AddCandleFlame(localNumbers[neighbor], i,
itsRect.left + 14, itsRect.top + 7);
h, v);
}
else
{
@@ -122,11 +128,13 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
rectB.bottom += kFloorSupportTall;
if (!SectRect(&rectA, &rectB, &whoCares))
{
const short h = itsRect.left + 14;
const short v = itsRect.top + 7;
if (redraw)
ReBackUpFlames(localNumbers[neighbor], i);
ReBackUpFlames(localNumbers[neighbor], i, h, v);
else
AddCandleFlame(localNumbers[neighbor], i,
itsRect.left + 14, itsRect.top + 7);
h, v);
}
}
}
@@ -141,11 +149,13 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
DrawSimpleBlowers(thisObject.what, &itsRect);
if (neighbor == kCentralRoom)
{
const short h = itsRect.left + 9;
const short v = itsRect.top + 7;
if (redraw)
ReBackUpFlames(localNumbers[neighbor], i);
ReBackUpFlames(localNumbers[neighbor], i, h, v);
else
AddCandleFlame(localNumbers[neighbor], i,
itsRect.left + 9, itsRect.top + 7);
h, v);
}
else
{
@@ -156,26 +166,31 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
rectB.bottom += kFloorSupportTall;
if (!SectRect(&rectA, &rectB, &whoCares))
{
const short h = itsRect.left + 9;
const short v = itsRect.top + 7;
if (redraw)
ReBackUpFlames(localNumbers[neighbor], i);
ReBackUpFlames(localNumbers[neighbor], i, h, v);
else
AddCandleFlame(localNumbers[neighbor], i,
itsRect.left + 9, itsRect.top + 7);
h, v);
}
}
}
break;
case kTiki:
GetObjectRect(&thisObject, &itsRect);
OffsetRectRoomRelative(&itsRect, neighbor);
if (isLit)
DrawTiki(&itsRect, playOriginV + VerticalRoomOffset(neighbor));
if (redraw)
ReBackUpTikiFlames(localNumbers[neighbor], i);
else
AddTikiFlame(localNumbers[neighbor], i,
itsRect.left + 10, itsRect.top - 9);
{
GetObjectRect(&thisObject, &itsRect);
OffsetRectRoomRelative(&itsRect, neighbor);
const short h = itsRect.left + 10;
const short v = itsRect.top - 9;
if (isLit)
DrawTiki(&itsRect, playOriginV + VerticalRoomOffset(neighbor));
if (redraw)
ReBackUpTikiFlames(localNumbers[neighbor], i, h, v);
else
AddTikiFlame(localNumbers[neighbor], i, h, v);
}
break;
case kBBQ:
@@ -183,13 +198,14 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
OffsetRectRoomRelative(&itsRect, neighbor);
if (SectRect(&itsRect, &testRect, &whoCares))
{
const short h = itsRect.left + 16;
const short v = itsRect.top + 9;
if (isLit)
DrawPictSansWhiteObject(thisObject.what, &itsRect);
if (redraw)
ReBackUpBBQCoals(localNumbers[neighbor], i);
ReBackUpBBQCoals(localNumbers[neighbor], i, h, v);
else
AddBBQCoals(localNumbers[neighbor], i,
itsRect.left + 16, itsRect.top + 9);
AddBBQCoals(localNumbers[neighbor], i, h, v);
}
break;
@@ -333,8 +349,10 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (legit != -1)
{
DrawCuckoo(&itsRect);
short pendulumH = itsRect.left + 4;
short pendulumV = itsRect.top + 46;
if (redraw)
ReBackUpPendulum(localNumbers[neighbor], i);
ReBackUpPendulum(localNumbers[neighbor], i, pendulumH, pendulumV);
else
AddPendulum(localNumbers[neighbor], i,
itsRect.left + 4, itsRect.top + 46);
@@ -367,17 +385,22 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
if (redraw)
dynamicNum = ReBackUpGrease(localNumbers[neighbor], i);
dynamicNum = ReBackUpGrease(localNumbers[neighbor], i, itsRect.left, itsRect.top);
else
dynamicNum = AddGrease(localNumbers[neighbor], i,
itsRect.left, itsRect.top,
thisObject.data.c.length, true);
if (dynamicNum != -1)
DrawGreaseRt(&itsRect, thisObject.data.c.length, true);
DrawGreaseRt(&itsRect, thisObject.data.c.length, true, false);
}
}
else // fallen
DrawGreaseRt(&itsRect, thisObject.data.c.length, false);
{
Boolean isDynamic = false;
if (redraw)
FixupFallenGrease(localNumbers[neighbor], i, itsRect.left, itsRect.top, &isDynamic);
DrawGreaseRt(&itsRect, thisObject.data.c.length, false, !isDynamic);
}
break;
case kGreaseLf:
@@ -388,17 +411,22 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
if (redraw)
dynamicNum = ReBackUpGrease(localNumbers[neighbor], i);
dynamicNum = ReBackUpGrease(localNumbers[neighbor], i, itsRect.left, itsRect.top);
else
dynamicNum = AddGrease(localNumbers[neighbor], i,
itsRect.left, itsRect.top,
thisObject.data.c.length, false);
if (dynamicNum != -1)
DrawGreaseLf(&itsRect, thisObject.data.c.length, true);
DrawGreaseLf(&itsRect, thisObject.data.c.length, true, false);
}
}
else
DrawGreaseLf(&itsRect, thisObject.data.c.length, false);
{
Boolean isDynamic = false;
if (redraw)
FixupFallenGrease(localNumbers[neighbor], i, itsRect.left, itsRect.top, &isDynamic);
DrawGreaseLf(&itsRect, thisObject.data.c.length, false, !isDynamic);
}
break;
case kFoil:
@@ -431,7 +459,7 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (legit != -1)
{
if (redraw)
ReBackUpStar(localNumbers[neighbor], i);
ReBackUpStar(localNumbers[neighbor], i, itsRect.left, itsRect.top);
else
AddStar(localNumbers[neighbor], i, itsRect.left,
itsRect.top);
@@ -445,12 +473,12 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
OffsetRectRoomRelative(&itsRect, neighbor);
if (SectRect(&itsRect, &testRect, &whoCares))
{
if ((!redraw) && (neighbor == kCentralRoom))
if (neighbor == kCentralRoom)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kSparkle, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.c.state);
localNumbers[neighbor], i, thisObject.data.c.state, redraw);
}
}
break;
@@ -641,12 +669,12 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
DrawSimpleAppliance(thisObject.what, &itsRect);
if ((!redraw) && (neighbor == kCentralRoom))
if (neighbor == kCentralRoom)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kToaster, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state);
localNumbers[neighbor], i, thisObject.data.g.state, redraw);
}
}
break;
@@ -657,13 +685,10 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
DrawMacPlus(&itsRect, thisObject.data.g.state, isLit);
if (!redraw)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kMacPlus, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state);
}
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kMacPlus, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state, redraw);
}
break;
@@ -673,8 +698,7 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
#ifdef COMPILEQT
if ((thisMac.hasQT) && (hasMovie) && (neighbor == kCentralRoom) &&
(!tvInRoom))
if ((thisMac.hasQT) && (hasMovie) && (neighbor == kCentralRoom))
{
whoCares = tvScreen1;
ZeroRectCorner(&whoCares);
@@ -683,16 +707,18 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
CenterRectInRect(&movieRect, &whoCares);
theMovie.m_renderRect = movieRect;
theMovie.m_constrainRect = whoCares;
tvOn = thisObject.data.g.state;
if (!tvInRoom)
tvOn = thisObject.data.g.state;
}
#endif
DrawTV(&itsRect, thisObject.data.g.state, isLit);
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kTV, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state, redraw);
if (!redraw)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kTV, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state);
#ifdef COMPILEQT
if ((thisMac.hasQT) && (hasMovie) && (neighbor == kCentralRoom) &&
(!tvInRoom))
@@ -711,13 +737,10 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
DrawCoffee(&itsRect, thisObject.data.g.state, isLit);
if (!redraw)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kCoffee, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state);
}
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kCoffee, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state, redraw);
}
break;
@@ -728,13 +751,10 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
{
if (isLit)
DrawOutlet(&itsRect);
if (!redraw)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kOutlet, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state);
}
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kOutlet, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state, redraw);
}
break;
@@ -744,13 +764,10 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
DrawVCR(&itsRect, thisObject.data.g.state, isLit);
if (!redraw)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kVCR, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state);
}
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kVCR, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state, redraw);
}
break;
@@ -760,13 +777,10 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
DrawStereo(&itsRect, isPlayMusicGame, isLit);
if (!redraw)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kStereo, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state);
}
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kStereo, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state, redraw);
}
break;
@@ -776,79 +790,76 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
DrawMicrowave(&itsRect, thisObject.data.g.state, isLit);
if (!redraw)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kMicrowave, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state);
}
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kMicrowave, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.g.state, redraw);
}
break;
case kBalloon:
if ((neighbor == kCentralRoom) && (!redraw))
if (neighbor == kCentralRoom)
{
GetObjectRect(&thisObject, &itsRect);
OffsetRectRoomRelative(&itsRect, neighbor);
QOffsetRect(&itsRect, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kBalloon, &itsRect, &thisObject,
localNumbers[neighbor], i, thisObject.data.h.state);
localNumbers[neighbor], i, thisObject.data.h.state, redraw);
}
break;
case kCopterLf:
if ((neighbor == kCentralRoom) && (!redraw))
if (neighbor == kCentralRoom)
{
GetObjectRect(&thisObject, &itsRect);
OffsetRectRoomRelative(&itsRect, neighbor);
QOffsetRect(&itsRect, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kCopterLf, &itsRect, &thisObject,
localNumbers[neighbor], i, thisObject.data.h.state);
localNumbers[neighbor], i, thisObject.data.h.state, redraw);
}
break;
case kCopterRt:
if ((neighbor == kCentralRoom) && (!redraw))
if (neighbor == kCentralRoom)
{
GetObjectRect(&thisObject, &itsRect);
OffsetRectRoomRelative(&itsRect, neighbor);
QOffsetRect(&itsRect, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kCopterRt, &itsRect, &thisObject,
localNumbers[neighbor], i, thisObject.data.h.state);
localNumbers[neighbor], i, thisObject.data.h.state, redraw);
}
break;
case kDartLf:
if ((neighbor == kCentralRoom) && (!redraw))
if (neighbor == kCentralRoom)
{
GetObjectRect(&thisObject, &itsRect);
OffsetRectRoomRelative(&itsRect, neighbor);
QOffsetRect(&itsRect, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kDartLf, &itsRect, &thisObject,
localNumbers[neighbor], i, thisObject.data.h.state);
localNumbers[neighbor], i, thisObject.data.h.state, redraw);
}
break;
case kDartRt:
if ((neighbor == kCentralRoom) && (!redraw))
if (neighbor == kCentralRoom)
{
GetObjectRect(&thisObject, &itsRect);
OffsetRectRoomRelative(&itsRect, neighbor);
QOffsetRect(&itsRect, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kDartRt, &itsRect, &thisObject,
localNumbers[neighbor], i, thisObject.data.h.state);
localNumbers[neighbor], i, thisObject.data.h.state, redraw);
}
break;
case kBall:
if ((neighbor == kCentralRoom) && (!redraw))
if (neighbor == kCentralRoom)
{
GetObjectRect(&thisObject, &itsRect);
OffsetRectRoomRelative(&itsRect, neighbor);
QOffsetRect(&itsRect, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kBall, &itsRect, &thisObject,
localNumbers[neighbor], i, thisObject.data.h.state);
localNumbers[neighbor], i, thisObject.data.h.state, redraw);
}
break;
@@ -858,12 +869,12 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
DrawDrip(&itsRect);
if ((!redraw) && (neighbor == kCentralRoom))
if (neighbor == kCentralRoom)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kDrip, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.h.state);
localNumbers[neighbor], i, thisObject.data.h.state, redraw);
}
}
break;
@@ -874,12 +885,12 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
DrawFish(thisObject.what, &itsRect);
if ((!redraw) && (neighbor == kCentralRoom))
if (neighbor == kCentralRoom)
{
rectA = itsRect;
QOffsetRect(&rectA, -playOriginH, -playOriginV);
dynamicNum = AddDynamicObject(kFish, &rectA, &thisObject,
localNumbers[neighbor], i, thisObject.data.h.state);
localNumbers[neighbor], i, thisObject.data.h.state, redraw);
}
}
break;
@@ -897,7 +908,7 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
OffsetRectRoomRelative(&itsRect, neighbor);
if ((SectRect(&itsRect, &testRect, &whoCares)) && isLit)
DrawMirror(&itsRect);
if ((neighbor == kCentralRoom) && (!redraw))
if (neighbor == kCentralRoom)
{
InsetRect(&itsRect, 4, 4);
AddToMirrorRegion(&itsRect);
@@ -942,15 +953,12 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
}
}
if (!redraw) // set up links
for (n = 0; n < numMasterObjects; n++)
{
for (n = 0; n < numMasterObjects; n++)
{
if ((masterObjects[n].objectNum == i) &&
(masterObjects[n].roomNum == localNumbers[neighbor]))
masterObjects[n].dynaNum = dynamicNum;
}
if ((masterObjects[n].objectNum == i) &&
(masterObjects[n].roomNum == localNumbers[neighbor]))
masterObjects[n].dynaNum = dynamicNum;
}
}
}

View File

@@ -2388,7 +2388,7 @@ void DrawThisRoomsObjects (void)
if (!thisRoom->objects[i].data.c.initial)
QOffsetRect(&tempRect, -8, 0);
DrawGreaseRt(&tempRect, thisRoom->objects[i].data.c.length,
thisRoom->objects[i].data.c.initial);
thisRoom->objects[i].data.c.initial, true);
break;
case kGreaseLf:
@@ -2396,7 +2396,7 @@ void DrawThisRoomsObjects (void)
if (!thisRoom->objects[i].data.c.initial)
QOffsetRect(&tempRect, 8, 0);
DrawGreaseLf(&tempRect, thisRoom->objects[i].data.c.length,
thisRoom->objects[i].data.c.initial);
thisRoom->objects[i].data.c.initial, true);
break;
case kFoil:

View File

@@ -8,6 +8,7 @@
#include "PLResources.h"
#include "PLStandardColors.h"
#include "DisplayDeviceManager.h"
#include "Externs.h"
#include "Environ.h"
#include "House.h"
@@ -53,7 +54,6 @@ short batteryTotal, bandsTotal, foilTotal, mortals;
Boolean playing, evenFrame, twoPlayerGame, showFoil, demoGoing;
Boolean doBackground, playerSuicide, phoneBitSet, tvOn;
extern WindowPtr menuWindow;
extern VFileSpec *theHousesSpecs;
extern demoPtr demoData;
extern gameType smallGame;
@@ -66,6 +66,7 @@ extern short numStarsRemaining, numChimes, saidFollow;
extern Boolean quitting, isMusicOn, gameOver, hasMirror, onePlayerLeft;
extern Boolean isPlayMusicIdle, failedMusic, quickerTransitions;
extern Boolean switchedOut;
extern short wasScoreboardTitleMode;
//============================================================== Functions
@@ -77,7 +78,6 @@ void NewGame (short mode)
PLError_t theErr;
Boolean wasPlayMusicPref;
AdjustScoreboardHeight();
gameOver = false;
theMode = kPlayMode;
if (isPlayMusicGame)
@@ -136,7 +136,7 @@ void NewGame (short mode)
DrawSurface *mainWindowSurface = mainWindow->GetDrawSurface();
tempRect = thisMac.screen;
tempRect = thisMac.constrainedScreen;
tempRect.top = tempRect.bottom - 20; // thisMac.menuHigh
mainWindowSurface->FillRect(tempRect);
@@ -156,7 +156,7 @@ void NewGame (short mode)
// DebugStr("\pIf screen isn't black, exit to shell."); // TEMP TEMP TEMP
DrawLocale();
ResetLocale(false);
RefreshScoreboard(kNormalTitleMode);
// if (quickerTransitions)
// DissBitsChunky(&justRoomsRect);
@@ -362,12 +362,37 @@ void SetHouseToSavedRoom (void)
ForceThisRoom(smallGame.roomNumber);
}
//-------------------------------------------------------------- HandleGameResolutionChange
void HandleGameResolutionChange(void)
{
FlushResolutionChange();
RecomputeInterfaceRects();
RecreateOffscreens();
CloseMainWindow();
OpenMainWindow();
if (hasMovie)
theMovie.m_surface = &mainWindow->m_surface;
ResetLocale(true);
InitScoreboardMap();
RefreshScoreboard(wasScoreboardTitleMode);
DumpScreenOn(&justRoomsRect);
}
//-------------------------------------------------------------- PlayGame
void PlayGame (void)
{
while ((playing) && (!quitting))
{
if (thisMac.isResolutionDirty)
{
HandleGameResolutionChange();
}
gameFrame++;
evenFrame = !evenFrame;
@@ -725,12 +750,12 @@ void RestoreEntireGameScreen (void)
#endif
DrawSurface *surface = mainWindow->GetDrawSurface();
tempRect = thisMac.screen;
tempRect = thisMac.constrainedScreen;
surface->SetForeColor(StdColors::Black());
surface->FillRect(tempRect);
DrawLocale();
ResetLocale(false);
RefreshScoreboard(kNormalTitleMode);
// if (quickerTransitions)
// DissBitsChunky(&justRoomsRect);

View File

@@ -34,9 +34,7 @@ void CopyRectsQD (void);
Rect work2MainRects[kMaxGarbageRects];
Rect back2WorkRects[kMaxGarbageRects];
Rect shieldRect;
THandle<Rect> mirrorRects;
Point shieldPt;
long nextFrame;
short numWork2Main, numBack2Work;
Boolean hasMirror;

View File

@@ -42,33 +42,45 @@ extern Boolean shadowVisible, takingTheStairs;
//============================================================== Functions
//-------------------------------------------------------------- DrawLocale
void DrawLocale (void)
void ResetLocale (Boolean soft)
{
short i, roomV;
char wasState;
DrawSurface *wasCPort;
ZeroFlamesAndTheLike();
ZeroDinahs();
KillAllBands();
ZeroMirrorRegion();
ZeroTriggers();
numTempManholes = 0;
FlushAnyTriggerPlaying();
DumpTriggerSound();
tvInRoom = false;
tvWithMovieNumber = -1;
roomV = (*thisHouse)->rooms[thisRoomNumber].floor;
for (i = 0; i < 9; i++)
if (soft)
{
localNumbers[i] = GetNeighborRoomNumber(i);
isStructure[i] = IsRoomAStructure(localNumbers[i]);
RemoveSavedMapsNotInRoom(localNumbers[kCentralRoom]);
ZeroDinahsNotInRoom(localNumbers[kCentralRoom]);
// Clear all dinah indexes, they'll be remapped
for (int i = 0; i < numMasterObjects; i++)
masterObjects[i].dynaNum = -1;
}
ListAllLocalObjects();
wasCPort = GetGraphicsPort();
else
{
ZeroFlamesAndTheLike();
ZeroDinahs();
KillAllBands();
ZeroTriggers();
numTempManholes = 0;
FlushAnyTriggerPlaying();
DumpTriggerSound();
tvInRoom = false;
tvWithMovieNumber = -1;
for (int i = 0; i < 9; i++)
{
localNumbers[i] = GetNeighborRoomNumber(i);
isStructure[i] = IsRoomAStructure(localNumbers[i]);
}
ListAllLocalObjects();
}
ZeroMirrorRegion();
takingTheStairs = false;
DrawSurface *wasCPort = GetGraphicsPort();
const short roomV = (*thisHouse)->rooms[thisRoomNumber].floor;
backSrcMap->SetForeColor(StdColors::Black());
backSrcMap->FillRect(backSrcRect);
@@ -115,14 +127,16 @@ void DrawLocale (void)
numLights = GetNumberOfLights(localNumbers[kCentralRoom]);
DrawRoomBackground(localNumbers[kCentralRoom], kCentralRoom, roomV);
DrawARoomsObjects(kCentralRoom, false);
DrawARoomsObjects(kCentralRoom, soft);
DrawLighting();
if (numNeighbors > 3)
DrawFloorSupport();
RestoreWorkMap();
shadowVisible = IsShadowVisible();
takingTheStairs = false;
if (soft)
RedrawAllGrease();
SetGraphicsPort(wasCPort);
}
@@ -385,7 +399,7 @@ void ReadyLevel (void)
#endif
DetermineRoomOpenings();
DrawLocale();
ResetLocale(false);
InitGarbageRects();
}
@@ -418,9 +432,10 @@ void RedrawRoomLighting (void)
{
DrawRoomBackground(localNumbers[kCentralRoom], kCentralRoom, roomV);
DrawARoomsObjects(kCentralRoom, true);
RedrawAllGrease();
DrawLighting();
UpdateOutletsLighting(localNumbers[kCentralRoom], numLights);
if (numNeighbors > 3)
DrawFloorSupport();
RestoreWorkMap();

View File

@@ -42,7 +42,7 @@ Rect badgesBlankRects[4], badgesBadgesRects[4];
Rect badgesDestRects[4];
DrawSurface *boardPSrcMap;
long displayedScore;
short wasScoreboardMode;
short wasScoreboardTitleMode;
Boolean doRollScore;
extern Rect localRoomsDest[], justRoomsRect;
@@ -63,6 +63,7 @@ void MarkScoreboardPortDirty(void)
void RefreshScoreboard (SInt16 mode)
{
wasScoreboardTitleMode = mode;
doRollScore = true;
RefreshRoomTitle(mode);
@@ -407,52 +408,3 @@ void QuickFoilRefresh (Boolean flash)
MarkScoreboardPortDirty();
}
//-------------------------------------------------------------- AdjustScoreboardHeight
void AdjustScoreboardHeight (void)
{
short offset, newMode;
if (numNeighbors == 9)
newMode = kScoreboardHigh;
else
newMode = kScoreboardLow;
if (wasScoreboardMode != newMode)
{
switch (newMode)
{
case kScoreboardHigh: // 9 neighbors
offset = localRoomsDest[kCentralRoom].top;
offset = -offset;
justRoomsRect = workSrcRect;
break;
case kScoreboardLow: // 1 or 3 neighbors
offset = localRoomsDest[kCentralRoom].top;
justRoomsRect = workSrcRect;
justRoomsRect.top = localRoomsDest[kCentralRoom].top;
justRoomsRect.bottom = localRoomsDest[kCentralRoom].bottom;
break;
}
QOffsetRect(&boardDestRect, 0, offset);
QOffsetRect(&boardGQDestRect, 0, offset);
QOffsetRect(&boardPQDestRect, 0, offset);
QOffsetRect(&badgesDestRects[kBatteryBadge], 0, offset);
QOffsetRect(&badgesDestRects[kBandsBadge], 0, offset);
QOffsetRect(&badgesDestRects[kFoilBadge], 0, offset);
QOffsetRect(&badgesDestRects[kHeliumBadge], 0, offset);
wasScoreboardMode = newMode;
}
}
//-------------------------------------------------------------- BlackenScoreboard
void BlackenScoreboard (DrawSurface *surface)
{
UpdateMenuBarWindow(surface);
}

View File

@@ -1031,7 +1031,7 @@ void DoDisplayPrefs (void)
break;
case kDisplay3Item:
if (thisMac.screen.right > 512)
if (thisMac.constrainedScreen.right > 512)
{
FrameDisplayIcon(prefDlg, StdColors::White());
numNeighbors = 3;
@@ -1040,7 +1040,7 @@ void DoDisplayPrefs (void)
break;
case kDisplay9Item:
if (thisMac.screen.right > 512)
if (thisMac.constrainedScreen.right > 512)
{
FrameDisplayIcon(prefDlg, StdColors::White());
numNeighbors = 9;

View File

@@ -52,7 +52,6 @@ extern Rect boardPQDestRect, boardGQDestRect, badgesBlankRects[];
extern Rect badgesBadgesRects[], badgesDestRects[];
extern Rect nailSrcRect, sparkleSrc[];
extern Rect pointsSrc[], breadSrc[];
extern short wasScoreboardMode;
//============================================================== Functions
@@ -60,20 +59,22 @@ extern short wasScoreboardMode;
// Any graphics and structures relating to the scoreboard that appearsÉ
// across the top of the game are initialized and loaded up here.
void InitScoreboardMap (void)
void InitScoreboardMap(void)
{
Rect bounds;
THandle<BitmapImage> thePicture;
DrawSurface *wasCPort;
PLError_t theErr;
short hOffset;
wasScoreboardMode = kScoreboardHigh;
if (boardSrcMap)
DisposeGWorld(boardSrcMap);
boardSrcRect = houseRect;
ZeroRectCorner(&boardSrcRect);
boardSrcRect.bottom = kScoreboardTall;
theErr = CreateOffScreenGWorld(&boardSrcMap, &boardSrcRect, kPreferredPixelFormat);
if (boardSrcRect.right >= 640)
hOffset = (RectWide(&boardSrcRect) - kMaxViewWidth) / 2;
else
@@ -86,40 +87,50 @@ void InitScoreboardMap (void)
QOffsetRect(&bounds, hOffset, 0);
boardSrcMap->DrawPicture(thePicture, bounds);
thePicture.Dispose();
QSetRect(&badgeSrcRect, 0, 0, 32, 66); // 2144 pixels
theErr = CreateOffScreenGWorld(&badgeSrcMap, &badgeSrcRect, kPreferredPixelFormat);
LoadGraphic(badgeSrcMap, kBadgePictID);
if (!badgeSrcMap)
{
theErr = CreateOffScreenGWorld(&badgeSrcMap, &badgeSrcRect, kPreferredPixelFormat);
LoadGraphic(badgeSrcMap, kBadgePictID);
}
boardDestRect = boardSrcRect;
hOffset = (RectWide(&houseRect) - 640) / 2;
if (hOffset < 0)
hOffset = -128;
QSetRect(&boardTSrcRect, 0, 0, 256, 12); // room title
theErr = CreateOffScreenGWorld(&boardTSrcMap, &boardTSrcRect, kPreferredPixelFormat);
if (!boardTSrcMap)
{
theErr = CreateOffScreenGWorld(&boardTSrcMap, &boardTSrcRect, kPreferredPixelFormat);
boardTSrcMap->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold);
}
boardTDestRect = boardTSrcRect;
QOffsetRect(&boardTDestRect, 137 + hOffset, 5);
boardTSrcMap->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold);
QSetRect(&boardGSrcRect, 0, 0, 20, 10); // # gliders
theErr = CreateOffScreenGWorld(&boardGSrcMap, &boardGSrcRect, kPreferredPixelFormat);
if (!boardGSrcMap)
{
theErr = CreateOffScreenGWorld(&boardGSrcMap, &boardGSrcRect, kPreferredPixelFormat);
boardGSrcMap->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold);
}
boardGDestRect = boardGSrcRect;
QOffsetRect(&boardGDestRect, 526 + hOffset, 5);
boardGSrcMap->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold);
QSetRect(&boardPSrcRect, 0, 0, 64, 10); // points
theErr = CreateOffScreenGWorld(&boardPSrcMap, &boardPSrcRect, kPreferredPixelFormat);
if (!boardPSrcMap)
{
theErr = CreateOffScreenGWorld(&boardPSrcMap, &boardPSrcRect, kPreferredPixelFormat);
boardPSrcMap->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold);
}
boardPDestRect = boardPSrcRect;
QOffsetRect(&boardPDestRect, 570 + hOffset, 5); // total = 6396 pixels
boardPQDestRect = boardPDestRect;
boardGQDestRect = boardGDestRect;
boardPSrcMap->SetApplicationFont(12, PortabilityLayer::FontFamilyFlag_Bold);
QSetRect(&badgesBlankRects[0], 0, 0, 16, 16); // foil
QOffsetRect(&badgesBlankRects[0], 0, 0);
QSetRect(&badgesBlankRects[1], 0, 0, 16, 16); // rubber bands

View File

@@ -11,6 +11,7 @@
#include "GameOver.h"
#include "MainWindow.h"
#include "Objects.h"
#include "QDManager.h"
#include "RectUtils.h"
#include "ResourceManager.h"
#include "Room.h"
@@ -112,6 +113,34 @@ void InitAngel (void)
LoadGraphic(angelMaskMap, kAngelPictID + 1);
}
//-------------------------------------------------------------- RecreateOffscreens
// Recreates resolution-dependent offscreen work
PLError_t RecreateOffscreens(void)
{
PLError_t theErr;
PortabilityLayer::QDManager::GetInstance()->SetPort(nullptr);
if (workSrcMap)
DisposeGWorld(workSrcMap);
if (backSrcMap)
DisposeGWorld(backSrcMap);
justRoomsRect = houseRect;
ZeroRectCorner(&justRoomsRect);
workSrcRect = houseRect; // Set up work map
ZeroRectCorner(&workSrcRect);
theErr = CreateOffScreenGWorld(&workSrcMap, &workSrcRect, kPreferredPixelFormat);
backSrcRect = houseRect; // Set up background map
ZeroRectCorner(&backSrcRect);
theErr = CreateOffScreenGWorld(&backSrcMap, &backSrcRect, kPreferredPixelFormat);
return PLErrors::kNone;
}
//-------------------------------------------------------------- CreateOffscreens
// All "utility" or "work" offscreen pix/bit maps are created here.
// These would be offscreens that are reused throughout a game - theyÉ
@@ -121,17 +150,8 @@ void InitAngel (void)
void CreateOffscreens (void)
{
PLError_t theErr;
justRoomsRect = houseRect;
ZeroRectCorner(&justRoomsRect);
workSrcRect = houseRect; // Set up work map
ZeroRectCorner(&workSrcRect);
theErr = CreateOffScreenGWorld(&workSrcMap, &workSrcRect, kPreferredPixelFormat);
backSrcRect = houseRect; // Set up background map
ZeroRectCorner(&backSrcRect);
theErr = CreateOffScreenGWorld(&backSrcMap, &backSrcRect, kPreferredPixelFormat);
theErr = RecreateOffscreens();
InitScoreboardMap(); SpinCursor(1);
InitGliderMap(); SpinCursor(1);

View File

@@ -61,6 +61,7 @@ void FrameSelectedTool (DrawSurface *);
void DrawToolName (DrawSurface *);
void DrawToolTiles (DrawSurface *);
void SwitchToolModes (short);
void KeepWindowInBounds (Window *window);
Rect toolsWindowRect, toolSrcRect, toolTextRect;
@@ -350,6 +351,8 @@ void OpenToolsWindow (void)
SwitchToolModes(toolMode);
toolSelected = kSelectTool;
KeepWindowInBounds(toolsWindow);
}
UpdateToolsCheckmark(true);

View File

@@ -109,7 +109,7 @@ void OpenMessageWindow (const PLPasStr &title)
SetRect(&mssgWindowRect, 0, 0, 256, kMessageWindowTall);
Rect placementRect = mssgWindowRect;
CenterRectInRect(&placementRect, &thisMac.screen);
CenterRectInRect(&placementRect, &thisMac.fullScreen);
const PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(placementRect, windowStyle, false, 0, 0, title);

View File

@@ -3,6 +3,8 @@
#include "EGpDisplayDriverType.h"
#include "GpDisplayDriverTickStatus.h"
#include <stdint.h>
struct IGpDisplayDriver;
struct IGpFiber;
struct IGpVOSEventQueue;
@@ -11,6 +13,7 @@ struct GpDisplayDriverProperties
{
typedef GpDisplayDriverTickStatus_t (*TickFunc_t)(void *context, IGpFiber *vosFiber);
typedef void(*RenderFunc_t)(void *context);
typedef bool(*AdjustRequestedResolutionFunc_t)(void *context, uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY);
EGpDisplayDriverType m_type;
@@ -32,5 +35,8 @@ struct GpDisplayDriverProperties
RenderFunc_t m_renderFunc;
void *m_renderFuncContext;
AdjustRequestedResolutionFunc_t m_adjustRequestedResolutionFunc;
void *m_adjustRequestedResolutionFuncContext;
IGpVOSEventQueue *m_eventQueue;
};

View File

@@ -235,6 +235,14 @@ struct GpMouseInputEvent
GpMouseButton_t m_button;
};
struct GpVideoResolutionChangedEvent
{
uint32_t m_prevWidth;
uint32_t m_prevHeight;
uint32_t m_newWidth;
uint32_t m_newHeight;
};
namespace GpVOSEventTypes
{
enum GpVOSEventType
@@ -242,6 +250,8 @@ namespace GpVOSEventTypes
kKeyboardInput,
kMouseInput,
kGamepadInput,
kVideoResolutionChanged,
kQuit
};
}
@@ -254,6 +264,7 @@ struct GpVOSEvent
GpKeyboardInputEvent m_keyboardInputEvent;
GpMouseInputEvent m_mouseInputEvent;
GpGamepadInputEvent m_gamepadInputEvent;
GpVideoResolutionChangedEvent m_resolutionChangedEvent;
};
EventUnion m_event;

View File

@@ -21,9 +21,10 @@ struct GpWindowsGlobals
HINSTANCE m_hPrevInstance;
LPCSTR m_cmdLine;
LPCWSTR m_baseDir;
HWND m_hwnd;
int m_nCmdShow;
IGpFiber *(*m_createFiberFunc)(LPVOID fiber);
IGpCursor_Win32 *(*m_loadCursorFunc)(const wchar_t *path);
void (*m_translateWindowsMessageFunc)(const MSG *msg, IGpVOSEventQueue *eventQueue);
void (*m_translateWindowsMessageFunc)(const MSG *msg, IGpVOSEventQueue *eventQueue, float pixelScaleX, float pixelScaleY);
};

View File

@@ -23,4 +23,8 @@ public:
virtual void SetStandardCursor(EGpStandardCursor_t standardCursor) = 0;
virtual void UpdatePalette(const void *paletteData) = 0;
virtual void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) = 0;
virtual void RequestToggleFullScreen(uint32_t timestamp) = 0;
};

View File

@@ -2,9 +2,11 @@
#include "GpApplicationName.h"
#include "GpDisplayDriverD3D11.h"
#include "GpDisplayDriverSurfaceD3D11.h"
#include "GpVOSEvent.h"
#include "GpWindows.h"
#include "IGpCursor_Win32.h"
#include "IGpFiber.h"
#include "IGpVOSEventQueue.h"
#include <d3d11.h>
#include <dxgi1_2.h>
@@ -54,6 +56,7 @@ LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (message)
{
case WM_DESTROY:
case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
@@ -64,8 +67,10 @@ LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hWnd, message, wParam, lParam);
}
void StartD3DForWindow(HWND hWnd, GpComPtr<IDXGISwapChain1>& outSwapChain, GpComPtr<ID3D11Device>& outDevice, GpComPtr<ID3D11DeviceContext>& outContext)
bool InitSwapChainForWindow(HWND hWnd, ID3D11Device *device, GpComPtr<IDXGISwapChain1>& outSwapChain)
{
outSwapChain = nullptr;
DXGI_SWAP_CHAIN_DESC1 swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
@@ -76,6 +81,50 @@ void StartD3DForWindow(HWND hWnd, GpComPtr<IDXGISwapChain1>& outSwapChain, GpCom
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
HRESULT result;
IDXGIDevice2 *dxgiDevice = nullptr;
result = device->QueryInterface(__uuidof(IDXGIDevice2), reinterpret_cast<void**>(&dxgiDevice));
if (result != S_OK)
return false;
IDXGIAdapter *dxgiAdapter = nullptr;
result = dxgiDevice->GetAdapter(&dxgiAdapter);
if (result != S_OK)
return false;
IDXGIFactory2 *dxgiFactory = nullptr;
result = dxgiAdapter->GetParent(__uuidof(IDXGIFactory2), reinterpret_cast<void**>(&dxgiFactory));
if (result != S_OK)
return false;
IDXGISwapChain1 *swapChain = nullptr;
result = dxgiFactory->CreateSwapChainForHwnd(device, hWnd, &swapChainDesc, nullptr, nullptr, &swapChain);
if (result != S_OK)
return false;
result = dxgiFactory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_ALT_ENTER);
if (result != S_OK)
return false;
outSwapChain = swapChain;
return true;
}
bool ResizeSwapChain(IDXGISwapChain1 *swapChain, UINT width, UINT height)
{
HRESULT result;
result = swapChain->ResizeBuffers(0, width, height, DXGI_FORMAT_R8G8B8A8_UNORM, 0);
if (result != S_OK)
return false;
return true;
}
void StartD3DForWindow(HWND hWnd, GpComPtr<IDXGISwapChain1>& outSwapChain, GpComPtr<ID3D11Device>& outDevice, GpComPtr<ID3D11DeviceContext>& outContext)
{
DXGI_SWAP_CHAIN_FULLSCREEN_DESC swapChainFullscreenDesc;
ZeroMemory(&swapChainFullscreenDesc, sizeof(swapChainFullscreenDesc));
@@ -90,7 +139,9 @@ void StartD3DForWindow(HWND hWnd, GpComPtr<IDXGISwapChain1>& outSwapChain, GpCom
D3D_FEATURE_LEVEL_10_0
};
#ifndef NDEBUG
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
ID3D11Device *device = NULL;
ID3D11DeviceContext *context = NULL;
@@ -100,27 +151,57 @@ void StartD3DForWindow(HWND hWnd, GpComPtr<IDXGISwapChain1>& outSwapChain, GpCom
HRESULT result = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, featureLevels, sizeof(featureLevels) / sizeof(featureLevels[0]),
D3D11_SDK_VERSION, &device, &selectedFeatureLevel, &context);
IDXGIDevice2 *dxgiDevice = nullptr;
result = device->QueryInterface(__uuidof(IDXGIDevice2), reinterpret_cast<void**>(&dxgiDevice));
IDXGIAdapter *dxgiAdapter = nullptr;
result = dxgiDevice->GetAdapter(&dxgiAdapter);
IDXGIFactory2 *dxgiFactory = nullptr;
result = dxgiAdapter->GetParent(__uuidof(IDXGIFactory2), reinterpret_cast<void**>(&dxgiFactory));
IDXGISwapChain1 *swapChain = nullptr;
result = dxgiFactory->CreateSwapChainForHwnd(device, hWnd, &swapChainDesc, nullptr, nullptr, &swapChain);
InitSwapChainForWindow(hWnd, device, outSwapChain);
// GP TODO: Fix the error handling here, it's bad...
outSwapChain = swapChain;
outDevice = device;
outContext = context;
}
bool GpDisplayDriverD3D11::InitResources()
bool ResizeD3DWindow(HWND hWnd, DWORD &windowWidth, DWORD &windowHeight, LONG desiredWidth, LONG desiredHeight, DWORD windowStyle, HMENU menus)
{
if (desiredWidth < 640)
desiredWidth = 640;
else if (desiredWidth > MAXDWORD)
desiredWidth = MAXDWORD;
if (desiredHeight < 480)
desiredHeight = 480;
else if (desiredHeight > MAXDWORD)
desiredHeight = MAXDWORD;
RECT windowRect;
GetClientRect(hWnd, &windowRect);
windowRect.right = windowRect.left + desiredWidth;
windowRect.bottom = windowRect.top + desiredHeight;
LONG_PTR style = GetWindowLongPtrA(hWnd, GWL_STYLE);
if (!AdjustWindowRect(&windowRect, static_cast<DWORD>(style), menus != nullptr))
return false;
SetWindowPos(hWnd, HWND_TOP, windowRect.left, windowRect.top, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, SWP_NOZORDER | SWP_NOMOVE);
windowWidth = desiredWidth;
windowHeight = desiredHeight;
return true;
}
bool GpDisplayDriverD3D11::DetachSwapChain()
{
m_deviceContext->OMSetRenderTargets(0, nullptr, nullptr);
m_backBufferRTV = nullptr;
m_backBufferTexture = nullptr;
m_deviceContext->ClearState();
m_deviceContext->Flush();
return true;
}
bool GpDisplayDriverD3D11::InitBackBuffer()
{
// Fetch back buffer
m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<LPVOID*>(m_backBufferTexture.GetMutablePtr()));
{
@@ -136,6 +217,14 @@ bool GpDisplayDriverD3D11::InitResources()
return false;
}
return true;
}
bool GpDisplayDriverD3D11::InitResources()
{
if (!InitBackBuffer())
return false;
// Quad vertex constant buffer
{
D3D11_BUFFER_DESC bufferDesc;
@@ -314,9 +403,7 @@ GpDisplayDriverTickStatus_t GpDisplayDriverD3D11::PresentFrameAndSync()
{
SynchronizeCursors();
float clearColor[4] = { 0.2f, 0.2f, 0.4f, 1.0f };
m_deviceContext->ClearRenderTargetView(m_backBufferRTV, clearColor);
m_deviceContext->ClearRenderTargetView(m_backBufferRTV, m_bgColor);
ID3D11RenderTargetView *const rtv = m_backBufferRTV;
m_deviceContext->OMSetRenderTargets(1, &rtv, nullptr);
@@ -325,8 +412,8 @@ GpDisplayDriverTickStatus_t GpDisplayDriverD3D11::PresentFrameAndSync()
D3D11_VIEWPORT viewport;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = static_cast<FLOAT>(m_windowWidth);
viewport.Height = static_cast<FLOAT>(m_windowHeight);
viewport.Width = static_cast<FLOAT>(m_windowWidthPhysical);
viewport.Height = static_cast<FLOAT>(m_windowHeightPhysical);
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
@@ -504,7 +591,7 @@ void GpDisplayDriverD3D11::ChangeToCursor(HCURSOR cursor)
if (m_mouseIsInClientArea)
::SetCursor(cursor);
SetClassLongPtrW(m_hwnd, GCLP_HCURSOR, reinterpret_cast<LONG_PTR>(cursor));
SetClassLongPtrW(m_osGlobals->m_hwnd, GCLP_HCURSOR, reinterpret_cast<LONG_PTR>(cursor));
}
void GpDisplayDriverD3D11::ChangeToStandardCursor(EGpStandardCursor_t cursor)
@@ -524,6 +611,105 @@ void GpDisplayDriverD3D11::ChangeToStandardCursor(EGpStandardCursor_t cursor)
}
}
void GpDisplayDriverD3D11::BecomeFullScreen(LONG &windowStyle)
{
assert(!m_isFullScreen);
RECT windowRect;
if (!GetWindowRect(m_osGlobals->m_hwnd, &windowRect))
return; // ???
HMONITOR monitor = MonitorFromRect(&windowRect, MONITOR_DEFAULTTONULL);
if (!monitor)
{
// If the window is off-screen, use the primary monitor
monitor = MonitorFromRect(&windowRect, MONITOR_DEFAULTTOPRIMARY);
}
else
{
// Otherwise, use the nearest
monitor = MonitorFromRect(&windowRect, MONITOR_DEFAULTTONEAREST);
}
if (!monitor)
return; // No monitor?
MONITORINFO monitorInfo;
monitorInfo.cbSize = sizeof(monitorInfo);
if (!GetMonitorInfoA(monitor, &monitorInfo))
return;
m_windowModeRevertRect = windowRect;
SetWindowLongPtr(m_osGlobals->m_hwnd, GWL_STYLE, WS_VISIBLE | WS_POPUP);
SetWindowPos(m_osGlobals->m_hwnd, HWND_TOP, monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top, monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top, SWP_FRAMECHANGED);
m_isFullScreen = true;
windowStyle = (WS_VISIBLE | WS_POPUP);
}
void GpDisplayDriverD3D11::BecomeWindowed(LONG &windowStyle)
{
assert(m_isFullScreen);
RECT revertRect = m_windowModeRevertRect;
HMONITOR monitor = MonitorFromRect(&m_windowModeRevertRect, MONITOR_DEFAULTTONULL);
if (!monitor)
{
// If the window is off-screen, use the primary monitor
monitor = MonitorFromRect(&revertRect, MONITOR_DEFAULTTOPRIMARY);
if (!monitor)
return;
MONITORINFO monitorInfo;
monitorInfo.cbSize = sizeof(monitorInfo);
if (!GetMonitorInfoA(monitor, &monitorInfo))
return;
RECT monitorRect = monitorInfo.rcWork;
LONG monitorWidth = monitorRect.right - monitorRect.left;
LONG monitorHeight = monitorRect.bottom - monitorRect.top;
LONG revertHeight = revertRect.bottom - revertRect.top;
LONG revertWidth = revertRect.right - revertRect.left;
if (revertWidth > monitorWidth)
revertWidth = monitorWidth;
if (revertHeight > monitorHeight)
revertHeight = monitorHeight;
revertRect.bottom = revertRect.top + revertHeight;
revertRect.right = revertRect.right + revertWidth;
LONG xDelta = 0;
if (revertRect.right > monitorRect.right)
xDelta = monitorRect.right - revertRect.right;
else if (revertRect.left < monitorRect.left)
xDelta = monitorRect.left - revertRect.left;
LONG yDelta = 0;
if (revertRect.bottom > monitorRect.bottom)
yDelta = monitorRect.bottom - revertRect.bottom;
else if (revertRect.top < monitorRect.top)
yDelta = monitorRect.top - revertRect.top;
revertRect.left = revertRect.left + xDelta;
revertRect.top = revertRect.top + yDelta;
revertRect.bottom = revertRect.top + revertHeight;
revertRect.right = revertRect.right + revertWidth;
}
SetWindowLongPtr(m_osGlobals->m_hwnd, GWL_STYLE, WS_VISIBLE | WS_OVERLAPPEDWINDOW);
SetWindowPos(m_osGlobals->m_hwnd, HWND_TOP, revertRect.left, revertRect.top, revertRect.right - revertRect.left, revertRect.bottom - revertRect.top, SWP_FRAMECHANGED);
m_isFullScreen = false;
windowStyle = (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
}
void GpDisplayDriverD3D11::Run()
{
WNDCLASSEX wc;
@@ -550,14 +736,14 @@ void GpDisplayDriverD3D11::Run()
HMENU menus = NULL;
// TODO: Fix the resolution here
RECT wr = { 0, 0, m_windowWidth, m_windowHeight };
RECT wr = { 0, 0, m_windowWidthPhysical, m_windowHeightPhysical };
AdjustWindowRect(&wr, windowStyle, menus != NULL);
m_hwnd = CreateWindowExW(NULL, L"GPD3D11WindowClass", GP_APPLICATION_NAME_W L" (Direct3D 11)", WS_OVERLAPPEDWINDOW, 300, 300, wr.right - wr.left, wr.bottom - wr.top, NULL, menus, m_osGlobals->m_hInstance, NULL);
m_osGlobals->m_hwnd = CreateWindowExW(NULL, L"GPD3D11WindowClass", GP_APPLICATION_NAME_W L" (Direct3D 11)", WS_OVERLAPPEDWINDOW, 300, 300, wr.right - wr.left, wr.bottom - wr.top, NULL, menus, m_osGlobals->m_hInstance, NULL);
ShowWindow(m_hwnd, m_osGlobals->m_nCmdShow);
ShowWindow(m_osGlobals->m_hwnd, m_osGlobals->m_nCmdShow);
StartD3DForWindow(m_hwnd, m_swapChain, m_device, m_deviceContext);
StartD3DForWindow(m_osGlobals->m_hwnd, m_swapChain, m_device, m_deviceContext);
InitResources();
@@ -571,9 +757,6 @@ void GpDisplayDriverD3D11::Run()
{
DispatchMessage(&msg);
if (msg.message == WM_QUIT)
break;
else
{
if (msg.message == WM_MOUSEMOVE)
{
@@ -586,7 +769,7 @@ void GpDisplayDriverD3D11::Run()
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = m_hwnd;
tme.hwndTrack = m_osGlobals->m_hwnd;
tme.dwHoverTime = HOVER_DEFAULT;
TrackMouseEvent(&tme);
}
@@ -594,11 +777,59 @@ void GpDisplayDriverD3D11::Run()
else if (msg.message == WM_MOUSELEAVE)
m_mouseIsInClientArea = false;
m_osGlobals->m_translateWindowsMessageFunc(&msg, m_properties.m_eventQueue);
m_osGlobals->m_translateWindowsMessageFunc(&msg, m_properties.m_eventQueue, m_pixelScaleX, m_pixelScaleY);
}
}
else
{
if (m_isFullScreen != m_isFullScreenDesired)
{
if (m_isFullScreenDesired)
BecomeFullScreen(windowStyle);
else
BecomeWindowed(windowStyle);
}
RECT clientRect;
GetClientRect(m_osGlobals->m_hwnd, &clientRect);
unsigned int desiredWidth = clientRect.right - clientRect.left;
unsigned int desiredHeight = clientRect.bottom - clientRect.top;
if (clientRect.right - clientRect.left != m_windowWidthPhysical || clientRect.bottom - clientRect.top != m_windowHeightPhysical)
{
uint32_t prevWidth = m_windowWidthPhysical;
uint32_t prevHeight = m_windowHeightPhysical;
uint32_t virtualWidth = m_windowWidthVirtual;
uint32_t virtualHeight = m_windowHeightVirtual;
float pixelScaleX = 1.0f;
float pixelScaleY = 1.0f;
if (m_properties.m_adjustRequestedResolutionFunc(m_properties.m_adjustRequestedResolutionFuncContext, desiredWidth, desiredHeight, virtualWidth, virtualHeight, pixelScaleX, pixelScaleY))
{
bool resizedOK = ResizeD3DWindow(m_osGlobals->m_hwnd, m_windowWidthPhysical, m_windowHeightPhysical, desiredWidth, desiredHeight, windowStyle, menus);
resizedOK = resizedOK && DetachSwapChain();
resizedOK = resizedOK && ResizeSwapChain(m_swapChain, m_windowWidthPhysical, m_windowHeightPhysical);
resizedOK = resizedOK && InitBackBuffer();
if (!resizedOK)
break; // Critical video driver error, exit
m_windowWidthVirtual = virtualWidth;
m_windowHeightVirtual = virtualHeight;
m_pixelScaleX = pixelScaleX;
m_pixelScaleY = pixelScaleY;
if (GpVOSEvent *resizeEvent = m_properties.m_eventQueue->QueueEvent())
{
resizeEvent->m_eventType = GpVOSEventTypes::kVideoResolutionChanged;
resizeEvent->m_event.m_resolutionChangedEvent.m_prevWidth = prevWidth;
resizeEvent->m_event.m_resolutionChangedEvent.m_prevHeight = prevHeight;
resizeEvent->m_event.m_resolutionChangedEvent.m_newWidth = m_windowWidthVirtual;
resizeEvent->m_event.m_resolutionChangedEvent.m_newHeight = m_windowHeightVirtual;
}
}
}
GpDisplayDriverTickStatus_t tickStatus = PresentFrameAndSync();
if (tickStatus == GpDisplayDriverTickStatuses::kFatalFault || tickStatus == GpDisplayDriverTickStatuses::kApplicationTerminated)
break;
@@ -618,9 +849,9 @@ void GpDisplayDriverD3D11::Shutdown()
void GpDisplayDriverD3D11::GetDisplayResolution(unsigned int *width, unsigned int *height, GpPixelFormat_t *pixelFormat)
{
if (width)
*width = m_windowWidth;
*width = m_windowWidthVirtual;
if (height)
*height = m_windowHeight;
*height = m_windowHeightVirtual;
if (pixelFormat)
*pixelFormat = GpPixelFormats::k8BitStandard;
}
@@ -641,8 +872,8 @@ void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, int32_t
//m_deviceContext->OMSetDepthStencilState(m_drawQuadDepthStencilState, 0);
{
const float twoDivWidth = 2.0f / static_cast<float>(m_windowWidth);
const float negativeTwoDivHeight = -2.0f / static_cast<float>(m_windowHeight);
const float twoDivWidth = 2.0f / static_cast<float>(m_windowWidthVirtual);
const float negativeTwoDivHeight = -2.0f / static_cast<float>(m_windowHeightVirtual);
DrawQuadVertexConstants constantsData;
constantsData.m_ndcOriginX = static_cast<float>(x) * twoDivWidth - 1.0f;
@@ -779,6 +1010,23 @@ void GpDisplayDriverD3D11::UpdatePalette(const void *paletteData)
m_deviceContext->Unmap(m_paletteTexture, 0);
}
}
void GpDisplayDriverD3D11::SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
m_bgColor[0] = static_cast<float>(r) / 255.0f;
m_bgColor[1] = static_cast<float>(g) / 255.0f;
m_bgColor[2] = static_cast<float>(b) / 255.0f;
m_bgColor[3] = static_cast<float>(a) / 255.0f;
}
void GpDisplayDriverD3D11::RequestToggleFullScreen(uint32_t timestamp)
{
// Alt-Enter gets re-sent after a full-screen toggle, so we ignore toggle requests until half a second has seconds have elapsed
if (timestamp > m_lastFullScreenToggleTimeStamp + 30)
{
m_isFullScreenDesired = !m_isFullScreenDesired;
m_lastFullScreenToggleTimeStamp = timestamp;
}
}
GpDisplayDriverD3D11 *GpDisplayDriverD3D11::Create(const GpDisplayDriverProperties &properties)
{
@@ -792,8 +1040,12 @@ GpDisplayDriverD3D11 *GpDisplayDriverD3D11::Create(const GpDisplayDriverProperti
GpDisplayDriverD3D11::GpDisplayDriverD3D11(const GpDisplayDriverProperties &properties)
: m_properties(properties)
, m_frameTimeAccumulated(0)
, m_windowWidth(640)
, m_windowHeight(480)
, m_windowWidthPhysical(640)
, m_windowHeightPhysical(480)
, m_windowWidthVirtual(640)
, m_windowHeightVirtual(480)
, m_pixelScaleX(1.0f)
, m_pixelScaleY(1.0f)
, m_vosFiber(nullptr)
, m_osGlobals(static_cast<GpWindowsGlobals*>(properties.m_osGlobals))
, m_pendingCursor(nullptr)
@@ -801,8 +1053,12 @@ GpDisplayDriverD3D11::GpDisplayDriverD3D11(const GpDisplayDriverProperties &prop
, m_currentStandardCursor(EGpStandardCursors::kArrow)
, m_pendingStandardCursor(EGpStandardCursors::kArrow)
, m_mouseIsInClientArea(false)
, m_isFullScreen(false)
, m_isFullScreenDesired(false)
, m_lastFullScreenToggleTimeStamp(0)
{
memset(&m_syncTimeBase, 0, sizeof(m_syncTimeBase));
memset(&m_windowModeRevertRect, 0, sizeof(m_windowModeRevertRect));
QueryPerformanceFrequency(&m_QPFrequency);
@@ -811,6 +1067,11 @@ GpDisplayDriverD3D11::GpDisplayDriverD3D11(const GpDisplayDriverProperties &prop
m_arrowCursor = reinterpret_cast<HCURSOR>(LoadImageW(nullptr, MAKEINTRESOURCEW(OCR_NORMAL), IMAGE_CURSOR, 0, 0, LR_SHARED));
m_ibeamCursor = reinterpret_cast<HCURSOR>(LoadImageW(nullptr, MAKEINTRESOURCEW(OCR_IBEAM), IMAGE_CURSOR, 0, 0, LR_SHARED));
m_waitCursor = reinterpret_cast<HCURSOR>(LoadImageW(nullptr, MAKEINTRESOURCEW(OCR_WAIT), IMAGE_CURSOR, 0, 0, LR_SHARED));
m_bgColor[0] = 0;
m_bgColor[1] = 0;
m_bgColor[2] = 0;
m_bgColor[3] = 255;
}
GpDisplayDriverD3D11::~GpDisplayDriverD3D11()

View File

@@ -46,6 +46,10 @@ public:
void UpdatePalette(const void *paletteData) override;
void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) override;
void RequestToggleFullScreen(uint32_t timestamp) override;
static GpDisplayDriverD3D11 *Create(const GpDisplayDriverProperties &properties);
private:
@@ -70,6 +74,8 @@ private:
GpDisplayDriverD3D11(const GpDisplayDriverProperties &properties);
~GpDisplayDriverD3D11();
bool DetachSwapChain();
bool InitBackBuffer();
bool InitResources();
GpDisplayDriverTickStatus_t PresentFrameAndSync();
@@ -77,6 +83,9 @@ private:
void ChangeToCursor(HCURSOR cursor);
void ChangeToStandardCursor(EGpStandardCursor_t cursor);
void BecomeFullScreen(LONG &windowStyle);
void BecomeWindowed(LONG &windowStyle);
GpComPtr<IDXGISwapChain1> m_swapChain;
GpComPtr<ID3D11Device> m_device;
GpComPtr<ID3D11DeviceContext> m_deviceContext;
@@ -104,11 +113,20 @@ private:
UINT m_expectedSyncDelta;
bool m_isResettingSwapChain;
bool m_isFullScreen;
bool m_isFullScreenDesired;
RECT m_windowModeRevertRect;
uint32_t m_lastFullScreenToggleTimeStamp;
LONGLONG m_frameTimeAccumulated;
LONGLONG m_frameTimeSliceSize;
DWORD m_windowWidth;
DWORD m_windowHeight;
DWORD m_windowWidthPhysical; // Physical resolution is the resolution of the actual window
DWORD m_windowHeightPhysical;
DWORD m_windowWidthVirtual; // Virtual resolution is the resolution reported to teh game
DWORD m_windowHeightVirtual;
float m_pixelScaleX;
float m_pixelScaleY;
IGpCursor_Win32 *m_activeCursor;
IGpCursor_Win32 *m_pendingCursor;
@@ -122,5 +140,6 @@ private:
HCURSOR m_arrowCursor;
HCURSOR m_waitCursor;
HCURSOR m_ibeamCursor;
HWND m_hwnd;
float m_bgColor[4];
};

View File

@@ -0,0 +1,16 @@
#include "AppEventHandler.h"
namespace PortabilityLayer
{
IAppEventHandler *AppEventHandler::ms_instance;
IAppEventHandler *AppEventHandler::GetInstance()
{
return ms_instance;
}
void AppEventHandler::SetInstance(IAppEventHandler *instance)
{
ms_instance = instance;
}
}

View File

@@ -0,0 +1,19 @@
#pragma once
namespace PortabilityLayer
{
struct IAppEventHandler
{
virtual void OnQuit() = 0;
};
class AppEventHandler
{
public:
static IAppEventHandler *GetInstance();
static void SetInstance(IAppEventHandler *instance);
private:
static IAppEventHandler *ms_instance;
};
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include <stdint.h>
namespace PortabilityLayer
{
class ArrayTools
{
public:
template<class T, class TSize, class TIndex>
static void RemoveFromArray(T *arr, TSize &count, TIndex index)
{
TSize countCopy = count;
countCopy--;
if (countCopy != index)
arr[index] = arr[countCopy];
count = static_cast<TSize>(countCopy);
}
};
}

View File

@@ -22,6 +22,9 @@ namespace PortabilityLayer
void IncrementTickCount(uint32_t count) override;
uint32_t GetTickCount() override;
void SetResolutionChangeHandler(IResolutionChangeHandler *handler) override;
IResolutionChangeHandler *GetResolutionChangeHandler() const override;
static DisplayDeviceManagerImpl *GetInstance();
private:
@@ -29,6 +32,8 @@ namespace PortabilityLayer
GpPixelFormat_t m_pixelFormat;
bool m_paletteIsDirty;
IResolutionChangeHandler *m_resChangeHandler;
PortabilityLayer::RGBAColor *m_palette;
uint8_t m_paletteStorage[256 * sizeof(PortabilityLayer::RGBAColor) + GP_SYSTEM_MEMORY_ALIGNMENT];
@@ -39,6 +44,7 @@ namespace PortabilityLayer
: m_tickCount(1)
, m_paletteIsDirty(true)
, m_pixelFormat(GpPixelFormats::k8BitStandard)
, m_resChangeHandler(nullptr)
{
uint8_t *paletteStorage = m_paletteStorage;
while (reinterpret_cast<intptr_t>(paletteStorage) % GP_SYSTEM_MEMORY_ALIGNMENT != 0)
@@ -93,6 +99,15 @@ namespace PortabilityLayer
return m_tickCount;
}
void DisplayDeviceManagerImpl::SetResolutionChangeHandler(IResolutionChangeHandler *handler)
{
m_resChangeHandler = handler;
}
DisplayDeviceManagerImpl::IResolutionChangeHandler *DisplayDeviceManagerImpl::GetResolutionChangeHandler() const
{
return m_resChangeHandler;
}
DisplayDeviceManagerImpl *DisplayDeviceManagerImpl::GetInstance()
{

View File

@@ -1,28 +1,39 @@
#pragma once
#ifndef __PL_DEVICE_MANAGER_H__
#define __PL_DEVICE_MANAGER_H__
#pragma once
#ifndef __PL_DEVICE_MANAGER_H__
#define __PL_DEVICE_MANAGER_H__
#include <stdint.h>
#include "GpPixelFormat.h"
struct IGpDisplayDriver;
namespace PortabilityLayer
{
class DisplayDeviceManager
{
public:
virtual void Init() = 0;
struct IGpDisplayDriver;
namespace PortabilityLayer
{
class DisplayDeviceManager
{
public:
struct IResolutionChangeHandler
{
virtual void OnResolutionChanged(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight) = 0;
virtual void AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY) = 0;
};
virtual void Init() = 0;
virtual void Shutdown() = 0;
virtual GpPixelFormat_t GetPixelFormat() const = 0;
virtual void SyncPalette(IGpDisplayDriver *displayDriver) = 0;
virtual void IncrementTickCount(uint32_t count) = 0;
virtual uint32_t GetTickCount() = 0;
static DisplayDeviceManager *GetInstance();
};
}
#endif
virtual void SyncPalette(IGpDisplayDriver *displayDriver) = 0;
virtual void IncrementTickCount(uint32_t count) = 0;
virtual uint32_t GetTickCount() = 0;
virtual void SetResolutionChangeHandler(IResolutionChangeHandler *handler) = 0;
virtual IResolutionChangeHandler *GetResolutionChangeHandler() const = 0;
static DisplayDeviceManager *GetInstance();
public:
};
}
#endif

View File

@@ -6,6 +6,7 @@
#include "MacFileMem.h"
#include "PLPasStr.h"
#include "PLErrorCodes.h"
#include "PLSysCalls.h"
#include "ResTypeID.h"
#include "HostSystemServices.h"
@@ -184,7 +185,7 @@ namespace PortabilityLayer
bool FileManagerImpl::PromptOpenFile(VirtualDirectory_t dirID, char *path, size_t &outPathLength, size_t pathCapacity)
{
return PortabilityLayer::HostFileSystem::GetInstance()->PromptOpenFile(dirID, path, outPathLength, pathCapacity);
return PLSysCalls::PromptOpenFile(dirID, path, outPathLength, pathCapacity);
}
FileManagerImpl *FileManagerImpl::GetInstance()

View File

@@ -38,14 +38,15 @@ public:
virtual int ApplicationMain() = 0;
virtual void PL_IncrementTickCounter(uint32_t count) = 0;
virtual void PL_Render(IGpDisplayDriver *displayDriver) = 0;
virtual void PL_HostAudioDriver_SetInstance(IGpAudioDriver *instance) = 0;
virtual void PL_HostFileSystem_SetInstance(PortabilityLayer::HostFileSystem *instance) = 0;
virtual void PL_HostDisplayDriver_SetInstance(IGpDisplayDriver *instance) = 0;
virtual void PL_HostSystemServices_SetInstance(PortabilityLayer::HostSystemServices *instance) = 0;
virtual void PL_HostFontHandler_SetInstance(PortabilityLayer::HostFontHandler *instance) = 0;
virtual void PL_HostVOSEventQueue_SetInstance(PortabilityLayer::HostVOSEventQueue *instance) = 0;
virtual void PL_InstallHostSuspendHook(PortabilityLayer::HostSuspendHook_t hook, void *context) = 0;
virtual void PL_HostAudioDriver_SetInstance(IGpAudioDriver *instance) = 0;
virtual void PL_InstallHostSuspendHook(PortabilityLayer::HostSuspendHook_t hook, void *context) = 0;
virtual bool PL_AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY) = 0;
};
GP_APP_DLL_EXPORT_API GpAppInterface *GpAppInterface_Get();

View File

@@ -12,6 +12,7 @@ namespace PortabilityLayer
int32_t m_int;
size_t m_size;
void *m_pointer;
const void *m_constPointer;
const void *m_constPointer;
void (*m_functionPtr)(const HostSuspendCallArgument *args, HostSuspendCallArgument *returnValue);
};
}

View File

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

View File

@@ -145,6 +145,7 @@ namespace PortabilityLayer
PLPasStr GetItemText(const THandle<Menu> &menu, unsigned int index) const override;
bool IsPointInMenuBar(const Vec2i &point) const override;
uint16_t GetMenuBarHeight() const override;
bool FindMenuShortcut(uint16_t &menuID, uint16_t &itemID, uint8_t shortcutChar) override;
void MenuSelect(const Vec2i &initialPoint, int16_t *outMenu, uint16_t *outItem) override;
@@ -598,6 +599,10 @@ namespace PortabilityLayer
return point.m_y >= 0 && static_cast<uint32_t>(point.m_y) < kMenuBarHeight;
}
uint16_t MenuManagerImpl::GetMenuBarHeight() const
{
return kMenuBarHeight;
}
bool MenuManagerImpl::FindMenuShortcut(uint16_t &menuID, uint16_t &itemID, uint8_t shortcutChar)
{

View File

@@ -40,6 +40,7 @@ namespace PortabilityLayer
virtual PLPasStr GetItemText(const THandle<Menu> &menu, unsigned int index) const = 0;
virtual bool IsPointInMenuBar(const Vec2i &point) const = 0;
virtual uint16_t GetMenuBarHeight() const = 0;
virtual bool FindMenuShortcut(uint16_t &menuID, uint16_t &itemID, uint8_t shortcutChar) = 0;
virtual void MenuSelect(const Vec2i &initialPoint, int16_t *outMenu, uint16_t *outItem) = 0;

View File

@@ -1,4 +1,5 @@
#include "PLCore.h"
#include "AppEventHandler.h"
#include "PLEventQueue.h"
#include "PLKeyEncoding.h"
#include "PLMovies.h"
@@ -6,7 +7,10 @@
#include "PLTimeTaggedVOSEvent.h"
#include "DisplayDeviceManager.h"
#include "GpVOSEvent.h"
#include "IGpDisplayDriver.h"
#include "InputManager.h"
#include "HostDisplayDriver.h"
#include "HostFileSystem.h"
#include "HostSuspendCallArgument.h"
#include "HostSuspendHook.h"
#include "HostVOSEventQueue.h"
@@ -47,6 +51,13 @@ static void TranslateGamepadInputEvent(const GpGamepadInputEvent &vosEvent, Port
PL_DEAD(queue);
}
static void TranslateVideoResolutionChangedEvent(const GpVideoResolutionChangedEvent &evt)
{
PortabilityLayer::DisplayDeviceManager::IResolutionChangeHandler *chgHandler = PortabilityLayer::DisplayDeviceManager::GetInstance()->GetResolutionChangeHandler();
if (chgHandler)
chgHandler->OnResolutionChanged(evt.m_prevWidth, evt.m_prevHeight, evt.m_newWidth, evt.m_newHeight);
}
static void TranslateKeyboardInputEvent(const GpVOSEvent &vosEventBase, uint32_t timestamp, PortabilityLayer::EventQueue *queue)
{
const GpKeyboardInputEvent &vosEvent = vosEventBase.m_event.m_keyboardInputEvent;
@@ -59,6 +70,20 @@ static void TranslateKeyboardInputEvent(const GpVOSEvent &vosEventBase, uint32_t
if (vosEvent.m_eventType == GpKeyboardInputEventTypes::kUp || vosEvent.m_eventType == GpKeyboardInputEventTypes::kDown)
inputManager->ApplyKeyboardEvent(vosEvent);
// Special handling of alt-enter, redirect to display driver
if (vosEventBase.m_eventType == GpKeyboardInputEventTypes::kDown &&
vosEventBase.m_event.m_keyboardInputEvent.m_keyIDSubset == GpKeyIDSubsets::kSpecial &&
vosEventBase.m_event.m_keyboardInputEvent.m_key.m_specialKey == GpKeySpecials::kEnter)
{
const KeyDownStates *keyStates = inputManager->GetKeys();
if (keyStates->m_special.Get(GpKeySpecials::kLeftAlt) || keyStates->m_special.Get(GpKeySpecials::kRightAlt))
{
IGpDisplayDriver *dd = PortabilityLayer::HostDisplayDriver::GetInstance();
if (dd)
dd->RequestToggleFullScreen(timestamp);
}
}
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
*evt = TimeTaggedVOSEvent::Create(vosEventBase, timestamp);
}
@@ -108,6 +133,17 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po
case GpVOSEventTypes::kGamepadInput:
TranslateGamepadInputEvent(vosEvent->m_event.m_gamepadInputEvent, queue);
break;
case GpVOSEventTypes::kVideoResolutionChanged:
TranslateVideoResolutionChangedEvent(vosEvent->m_event.m_resolutionChangedEvent);
break;
case GpVOSEventTypes::kQuit:
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
*evt = TimeTaggedVOSEvent::Create(*vosEvent, timestamp);
if (PortabilityLayer::IAppEventHandler *appHandler = PortabilityLayer::AppEventHandler::GetInstance())
appHandler->OnQuit();
break;
}
}
@@ -139,4 +175,63 @@ namespace PLSysCalls
AnimationManager::GetInstance()->TickPlayers(ticks);
}
}
static void PromptOpenFileCallback(const PortabilityLayer::HostSuspendCallArgument *args, PortabilityLayer::HostSuspendCallArgument *returnValue)
{
bool result = PortabilityLayer::HostFileSystem::GetInstance()->PromptOpenFile(static_cast<PortabilityLayer::VirtualDirectory_t>(args[0].m_int), static_cast<char*>(args[1].m_pointer), *static_cast<size_t*>(args[2].m_pointer), args[3].m_uint);
returnValue->m_uint = (result ? 1 : 0);
}
bool PromptOpenFile(PortabilityLayer::VirtualDirectory_t dirID, char *path, size_t &outPathLength, size_t pathCapacity)
{
PortabilityLayer::HostSuspendCallArgument cbArgs[4];
cbArgs[0].m_int = static_cast<int32_t>(dirID);
cbArgs[1].m_pointer = path;
cbArgs[2].m_pointer = &outPathLength;
cbArgs[3].m_size = pathCapacity;
PortabilityLayer::HostSuspendCallArgument cbReturnValue;
PortabilityLayer::HostSuspendCallArgument dispatchArgs[3];
dispatchArgs[0].m_functionPtr = PromptOpenFileCallback;
dispatchArgs[1].m_constPointer = cbArgs;
dispatchArgs[2].m_pointer = &cbReturnValue;
PortabilityLayer::SuspendApplication(PortabilityLayer::HostSuspendCallID_CallOnVOSThread, dispatchArgs, nullptr);
return cbReturnValue.m_uint != 0;
}
static void PromptSaveFileCallback(const PortabilityLayer::HostSuspendCallArgument *args, PortabilityLayer::HostSuspendCallArgument *returnValue)
{
bool result = PortabilityLayer::HostFileSystem::GetInstance()->PromptSaveFile(
static_cast<PortabilityLayer::VirtualDirectory_t>(args[0].m_int),
static_cast<char*>(args[1].m_pointer),
*static_cast<size_t*>(args[2].m_pointer),
args[3].m_uint,
static_cast<const char*>(args[4].m_constPointer));
returnValue->m_uint = (result ? 1 : 0);
}
bool PromptSaveFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, char *path, size_t &outPathLength, size_t pathCapacity, const char *initialFileName)
{
PortabilityLayer::HostSuspendCallArgument cbArgs[5];
cbArgs[0].m_int = static_cast<int32_t>(virtualDirectory);
cbArgs[1].m_pointer = path;
cbArgs[2].m_pointer = &outPathLength;
cbArgs[3].m_size = pathCapacity;
cbArgs[3].m_constPointer = initialFileName;
PortabilityLayer::HostSuspendCallArgument cbReturnValue;
PortabilityLayer::HostSuspendCallArgument dispatchArgs[3];
dispatchArgs[0].m_functionPtr = PromptSaveFileCallback;
dispatchArgs[1].m_constPointer = cbArgs;
dispatchArgs[2].m_pointer = &cbReturnValue;
PortabilityLayer::SuspendApplication(PortabilityLayer::HostSuspendCallID_CallOnVOSThread, dispatchArgs, nullptr);
return cbReturnValue.m_uint != 0;
}
}

View File

@@ -1,8 +1,12 @@
#pragma once
#include <stdint.h>
#include "VirtualDirectory.h"
#include <stdint.h>
namespace PLSysCalls
{
{
void Sleep(uint32_t ticks);
bool PromptOpenFile(PortabilityLayer::VirtualDirectory_t dirID, char *path, size_t &outPathLength, size_t pathCapacity);
bool PromptSaveFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, char *path, size_t &outPathLength, size_t pathCapacity, const char *initialFileName);
}

View File

@@ -146,6 +146,8 @@
<ClInclude Include="AEHandlerDesc.h" />
<ClInclude Include="AEManager.h" />
<ClInclude Include="AntiAliasTable.h" />
<ClInclude Include="AppEventHandler.h" />
<ClInclude Include="ArrayTools.h" />
<ClInclude Include="BinarySearch.h" />
<ClInclude Include="BinHex4.h" />
<ClInclude Include="BitmapImage.h" />
@@ -302,6 +304,7 @@
<ClCompile Include="..\stb\stb_image_write.c" />
<ClCompile Include="AEManager.cpp" />
<ClCompile Include="AntiAliasTable.cpp" />
<ClCompile Include="AppEventHandler.cpp" />
<ClCompile Include="BinHex4.cpp" />
<ClCompile Include="BitmapImage.cpp" />
<ClCompile Include="ByteSwap.cpp" />

View File

@@ -480,6 +480,12 @@
<ClInclude Include="TextPlacer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ArrayTools.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AppEventHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CFileStream.cpp">
@@ -755,5 +761,8 @@
<ClCompile Include="TextPlacer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AppEventHandler.cpp">
<Filter>Header Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -14,9 +14,12 @@
#include "QDManager.h"
#include "QDPixMap.h"
#include "PLTimeTaggedVOSEvent.h"
#include "Rect2i.h"
#include "Vec2i.h"
#include "WindowDef.h"
#include <algorithm>
struct GDevice;
namespace PortabilityLayer
@@ -127,9 +130,12 @@ namespace PortabilityLayer
void DestroyWindow(Window *window) override;
void DragWindow(Window *window, const Point &startPoint, const Rect &constraintRect) override;
void SetWindowTitle(Window *window, const PLPasStr &title) override;
Rect2i GetWindowFullRect(Window *window) const override;
void RenderFrame(IGpDisplayDriver *displayDriver) override;
void HandleScreenResolutionChange(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight) override;
Window *GetPutInFrontSentinel() const override;
static WindowManagerImpl *GetInstance();
@@ -553,7 +559,13 @@ namespace PortabilityLayer
void WindowImpl::GetChromePadding(uint16_t padding[WindowChromeSides::kCount]) const
{
return m_chromeTheme->GetChromePadding(this, padding);
if (m_chromeTheme)
m_chromeTheme->GetChromePadding(this, padding);
else
{
for (int i = 0; i < WindowChromeSides::kCount; i++)
padding[i] = 0;
}
}
void WindowImpl::GetChromeDimensions(int width, int height, Rect dimensions[WindowChromeSides::kCount]) const
@@ -572,6 +584,9 @@ namespace PortabilityLayer
bool WindowImpl::GetChromeInteractionZone(const Vec2i &point, RegionID_t &outRegion) const
{
if (!m_chromeTheme)
return false;
return m_chromeTheme->GetChromeInteractionZone(this, point, outRegion);
}
@@ -784,6 +799,18 @@ namespace PortabilityLayer
static_cast<WindowImpl*>(window)->SetTitle(title);
}
Rect2i WindowManagerImpl::GetWindowFullRect(Window *window) const
{
WindowImpl *windowImpl = static_cast<WindowImpl*>(window);
uint16_t padding[WindowChromeSides::kCount];
windowImpl->GetChromePadding(padding);
const Rect portRect = windowImpl->m_surface.m_port.GetRect();
return Rect2i(window->m_wmY - padding[WindowChromeSides::kTop], window->m_wmX - padding[WindowChromeSides::kLeft], window->m_wmY + portRect.Height() + padding[WindowChromeSides::kBottom], window->m_wmX + portRect.Width() + padding[WindowChromeSides::kRight]);
}
void WindowManagerImpl::RenderFrame(IGpDisplayDriver *displayDriver)
{
PortabilityLayer::DisplayDeviceManager *dd = PortabilityLayer::DisplayDeviceManager::GetInstance();
@@ -798,6 +825,53 @@ namespace PortabilityLayer
}
}
void WindowManagerImpl::HandleScreenResolutionChange(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight)
{
const uint32_t menuBarHeight = PortabilityLayer::MenuManager::GetInstance()->GetMenuBarHeight();
for (PortabilityLayer::WindowImpl *window = m_windowStackTop; window != nullptr; window = window->GetWindowBelow())
{
uint16_t chromePadding[WindowChromeSides::kCount];
window->GetChromePadding(chromePadding);
const Rect surfaceRect = window->GetDrawSurface()->m_port.GetRect();
uint32_t paddedWidth = surfaceRect.Width() + chromePadding[WindowChromeSides::kLeft] + chromePadding[WindowChromeSides::kRight];
uint32_t paddedHeight = surfaceRect.Height() + chromePadding[WindowChromeSides::kTop] + chromePadding[WindowChromeSides::kBottom];
int64_t newX = 0;
if (newWidth <= paddedWidth || prevWidth <= paddedWidth)
newX = (static_cast<int64_t>(newWidth) - paddedWidth) / 2;
else
{
uint32_t prevClearanceX = prevWidth - paddedWidth;
uint32_t newClearanceX = newWidth - paddedWidth;
newX = static_cast<int64_t>(window->m_wmX) * static_cast<int64_t>(newClearanceX) / static_cast<int64_t>(prevClearanceX);
}
int64_t newY = 0;
if (window->m_wmY < static_cast<int32_t>(menuBarHeight))
newY = window->m_wmY;
else
{
if (newHeight <= (paddedHeight + menuBarHeight) || prevHeight <= paddedHeight + menuBarHeight)
newY = (static_cast<int64_t>(newHeight) - paddedHeight - menuBarHeight) / 2 + menuBarHeight;
else
{
uint32_t prevClearanceY = prevHeight - paddedHeight - menuBarHeight;
uint32_t newClearanceY = newHeight - paddedHeight - menuBarHeight;
newY = (static_cast<int64_t>(window->m_wmY) - static_cast<int64_t>(menuBarHeight) - chromePadding[WindowChromeSides::kTop]) * static_cast<int64_t>(newClearanceY) / static_cast<int64_t>(prevClearanceY) + menuBarHeight + chromePadding[WindowChromeSides::kTop];
}
}
newX = std::max<int64_t>(0, std::min<int64_t>(newX, newWidth - 1));
newY = std::max<int64_t>(0, std::min<int64_t>(newY, newHeight - 1));
window->m_wmX = static_cast<int32_t>(newX);
window->m_wmY = static_cast<int32_t>(newY);
}
}
void WindowManagerImpl::ResizeWindow(Window *window, int width, int height)
{
static_cast<WindowImpl*>(window)->Resize(width, height);

View File

@@ -1,5 +1,7 @@
#pragma once
#include <stdint.h>
struct Window;
struct DrawSurface;
struct GDevice;
@@ -12,6 +14,7 @@ struct Window;
namespace PortabilityLayer
{
struct WindowDef;
struct Rect2i;
class WindowManager
{
@@ -27,9 +30,12 @@ namespace PortabilityLayer
virtual void DestroyWindow(Window *window) = 0;
virtual void DragWindow(Window *window, const Point &startPoint, const Rect &constraintRect) = 0;
virtual void SetWindowTitle(Window *window, const PLPasStr &title) = 0;
virtual Rect2i GetWindowFullRect(Window *window) const = 0;
virtual void RenderFrame(IGpDisplayDriver *displayDriver) = 0;
virtual void HandleScreenResolutionChange(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight) = 0;
static WindowManager *GetInstance();
};
}

View File

@@ -6,7 +6,7 @@ namespace PortabilityLayer
{
class IOStream;
struct ZipCentralDirectoryFileHeader;
class ZipFileProxy
{
public: