From 66fc278ce9e54d83a19bfed7ccfa410815ad393d Mon Sep 17 00:00:00 2001 From: elasota Date: Wed, 20 May 2020 23:33:17 -0400 Subject: [PATCH] Refactor QD ports so they no longer need to be the first member of draw surfaces --- GpApp/Coordinates.cpp | 1 - GpApp/Events.cpp | 111 +---------------------------- GpApp/GameOver.cpp | 2 +- GpApp/HighScores.cpp | 2 +- GpApp/HouseInfo.cpp | 2 +- GpApp/Map.cpp | 2 +- GpApp/ObjectInfo.cpp | 4 +- GpApp/Render.cpp | 2 +- GpApp/RoomInfo.cpp | 2 +- GpApp/Tools.cpp | 2 +- PortabilityLayer/PLQDOffscreen.cpp | 9 +-- PortabilityLayer/PLQDraw.cpp | 10 +-- PortabilityLayer/PLQDraw.h | 7 +- PortabilityLayer/QDGraf.h | 5 +- PortabilityLayer/QDManager.cpp | 14 ++-- PortabilityLayer/QDManager.h | 4 +- PortabilityLayer/QDPort.cpp | 2 +- PortabilityLayer/WindowManager.cpp | 2 +- 18 files changed, 29 insertions(+), 154 deletions(-) diff --git a/GpApp/Coordinates.cpp b/GpApp/Coordinates.cpp index 785af46..6885dde 100644 --- a/GpApp/Coordinates.cpp +++ b/GpApp/Coordinates.cpp @@ -66,7 +66,6 @@ void UpdateCoordWindow (void) { #ifndef COMPILEDEMO Str255 tempStr, numStr; - GrafPtr wasPort; if (coordWindow == nil) return; diff --git a/GpApp/Events.cpp b/GpApp/Events.cpp index 2581c39..f820d1f 100644 --- a/GpApp/Events.cpp +++ b/GpApp/Events.cpp @@ -315,115 +315,6 @@ void HandleKeyEvent (const KeyDownStates &keyStates, const GpKeyboardInputEvent } } -//-------------------------------------------------------------- HandleUpdateEvent -// Handle an update event. - -#if 0 -void HandleUpdateEvent (EventRecord *theEvent) -{ - if ((WindowPtr)theEvent->message == mainWindow) - { - SetPort((GrafPtr)mainWindow); - UpdateMainWindow(); - EndUpdate(mainWindow); - } - else if ((WindowPtr)theEvent->message == mapWindow) - { - SetPort((GrafPtr)mapWindow); - UpdateMapWindow(); - EndUpdate(mapWindow); - } - else if ((WindowPtr)theEvent->message == toolsWindow) - { - SetPort((GrafPtr)toolsWindow); - UpdateToolsWindow(); - EndUpdate(toolsWindow); - } - else if ((WindowPtr)theEvent->message == linkWindow) - { - SetPort((GrafPtr)linkWindow); - UpdateLinkWindow(); - EndUpdate(linkWindow); - } - else if ((WindowPtr)theEvent->message == coordWindow) - { - SetPort((GrafPtr)coordWindow); - UpdateCoordWindow(); - EndUpdate(coordWindow); - } -} - -//-------------------------------------------------------------- HandleOSEvent -// Handle an OS Event (MultiFinder - user has switched in or out of app). - -void HandleOSEvent (EventRecord *theEvent) -{ - PLError_t theErr; - short buttonHit; - - if (theEvent->message & 0x01000000) // suspend or resume event - { - if (theEvent->message & 0x00000001) // resume event - { - if (WhatsOurDepth() != thisMac.isDepth) - { - buttonHit = BitchAboutColorDepth(); - if (buttonHit == 1) // player wants to Quit - { -#ifndef COMPILEDEMO - if (QuerySaveChanges()) - quitting = true; -#else - quitting = true; -#endif - } - else - { - SwitchToDepth(thisMac.isDepth, thisMac.wasColorOrGray); - } - } - switchedOut = false; - InitCursor(); - if ((isPlayMusicIdle) && (theMode != kEditMode)) - { - theErr = StartMusic(); - if (theErr != PLErrors::kNone) - { - YellowAlert(kYellowNoMusic, theErr); - failedMusic = true; - } - } - incrementModeTime = TickCount() + kIdleSplashTicks; - -#ifndef COMPILEDEMO -// if (theMode == kEditMode) -// SeeIfValidScrapAvailable(true); -#endif - } - else // suspend event - { - switchedOut = true; - InitCursor(); - if ((isMusicOn) && (theMode != kEditMode)) - StopTheMusic(); - } - } -} - -//-------------------------------------------------------------- HandleHighLevelEvent -// Handle an AppleEvent (Open Document, Quit Application, etc.). - -void HandleHighLevelEvent (EventRecord *theEvent) -{ - PLError_t theErr; - - theErr = AEProcessAppleEvent(theEvent); - if ((theErr != PLErrors::kNone) && (theErr != errAEEventNotHandled)) - YellowAlert(kYellowAppleEventErr, theErr); -} -#endif - - //-------------------------------------------------------------- HandleSplashResolutionChange void HandleSplashResolutionChange(void) { @@ -496,7 +387,7 @@ void HandleIdleTask (void) HandleEditorResolutionChange(); } - SetPort(&mainWindow->GetDrawSurface()->m_port); + SetPort(mainWindow->GetDrawSurface()); DoMarquee(); if ((autoRoomEdit) && (newRoomNow)) diff --git a/GpApp/GameOver.cpp b/GpApp/GameOver.cpp index 82e2e88..1e5c30a 100644 --- a/GpApp/GameOver.cpp +++ b/GpApp/GameOver.cpp @@ -68,7 +68,7 @@ void DoGameOver (void) DrawSurface *surface = mainWindow->GetDrawSurface(); playing = false; SetUpFinalScreen(); - SetPort((GrafPtr)mainWindow); + SetPort(mainWindow->GetDrawSurface()); ColorRect(surface, mainWindowRect, 244); DoGameOverStarAnimation(); if (!TestHighScore()) diff --git a/GpApp/HighScores.cpp b/GpApp/HighScores.cpp index 5ed82b4..1971bb5 100644 --- a/GpApp/HighScores.cpp +++ b/GpApp/HighScores.cpp @@ -71,7 +71,7 @@ void DoHighScores (void) Rect tempRect; SpinCursor(3); - SetPort(&workSrcMap->m_port); + SetPort(workSrcMap); workSrcMap->SetForeColor(StdColors::Black()); workSrcMap->FillRect(workSrcRect); QSetRect(&tempRect, 0, 0, 640, 480); diff --git a/GpApp/HouseInfo.cpp b/GpApp/HouseInfo.cpp index 936d5ef..5ef61a3 100644 --- a/GpApp/HouseInfo.cpp +++ b/GpApp/HouseInfo.cpp @@ -231,7 +231,7 @@ void DoHouseInfo (void) houseInfoDialog = PortabilityLayer::DialogManager::GetInstance()->LoadDialog(kHouseInfoDialogID, kPutInFront, &substitutions); if (houseInfoDialog == nil) RedAlert(kErrDialogDidntLoad); - SetPort(&houseInfoDialog->GetWindow()->GetDrawSurface()->m_port); + SetPort(houseInfoDialog->GetWindow()->GetDrawSurface()); ShowWindow(houseInfoDialog->GetWindow()); static_cast(houseInfoDialog->GetItems()[kBannerTextItem - 1].GetWidget())->SetMultiLine(true); diff --git a/GpApp/Map.cpp b/GpApp/Map.cpp index fa7a2f4..81855b0 100644 --- a/GpApp/Map.cpp +++ b/GpApp/Map.cpp @@ -415,7 +415,7 @@ void OpenMapWindow (void) PortabilityLayer::WindowManager::GetInstance()->ShowWindow(mapWindow); // FlagWindowFloating(mapWindow); TEMP - use flaoting windows - SetPort(&mapWindow->GetDrawSurface()->m_port); + SetPort(mapWindow->GetDrawSurface()); QSetRect(&mapHScrollRect, -1, mapRoomsHigh * kMapRoomHeight, mapRoomsWide * kMapRoomWidth + 1, mapRoomsHigh * kMapRoomHeight + kMapScrollBarWidth); diff --git a/GpApp/ObjectInfo.cpp b/GpApp/ObjectInfo.cpp index d27c572..00ac626 100644 --- a/GpApp/ObjectInfo.cpp +++ b/GpApp/ObjectInfo.cpp @@ -732,7 +732,7 @@ void DoBlowerObjectInfo (short what) infoDial = PortabilityLayer::DialogManager::GetInstance()->LoadDialog(kBlowerInfoDialogID, kPutInFront, &substitutions); if (infoDial == nil) RedAlert(kErrDialogDidntLoad); - SetPort(&infoDial->GetWindow()->GetDrawSurface()->m_port); + SetPort(infoDial->GetWindow()->GetDrawSurface()); newDirection = thisRoom->objects[objActive].data.a.vector & 0x0F; if (thisRoom->objects[objActive].data.a.initial) @@ -1349,7 +1349,7 @@ void DoLightObjectInfo (void) infoDial = PortabilityLayer::DialogManager::GetInstance()->LoadDialog(kLightInfoDialogID, kPutInFront, &substitutions); if (infoDial == nil) RedAlert(kErrDialogDidntLoad); - SetPort(&infoDial->GetWindow()->GetDrawSurface()->m_port); + SetPort(infoDial->GetWindow()->GetDrawSurface()); if (thisRoom->objects[objActive].data.f.initial) SetDialogItemValue(infoDial, kInitialStateCheckbox, 1); diff --git a/GpApp/Render.cpp b/GpApp/Render.cpp index f022e69..2d78979 100644 --- a/GpApp/Render.cpp +++ b/GpApp/Render.cpp @@ -147,7 +147,7 @@ void DrawReflection (gliderPtr thisGlider, Boolean oneOrTwo) dest = thisGlider->dest; QOffsetRect(&dest, playOriginH - 20, playOriginV - 16); - SetPort(&workSrcMap->m_port); + SetPort(workSrcMap); long numMirrorRects = GetHandleSize(mirrorRects.StaticCast()) / sizeof(Rect); diff --git a/GpApp/RoomInfo.cpp b/GpApp/RoomInfo.cpp index ae087c3..c9da2b1 100644 --- a/GpApp/RoomInfo.cpp +++ b/GpApp/RoomInfo.cpp @@ -465,7 +465,7 @@ void DoRoomInfo(void) roomInfoDialog = PortabilityLayer::DialogManager::GetInstance()->LoadDialog(kRoomInfoDialogID, kPutInFront, &substitutions); if (roomInfoDialog == nil) RedAlert(kErrDialogDidntLoad); - SetPort(&roomInfoDialog->GetWindow()->GetDrawSurface()->m_port); + SetPort(roomInfoDialog->GetWindow()->GetDrawSurface()); { PortabilityLayer::WidgetBasicState state; diff --git a/GpApp/Tools.cpp b/GpApp/Tools.cpp index 42cbaa2..5933cda 100644 --- a/GpApp/Tools.cpp +++ b/GpApp/Tools.cpp @@ -200,7 +200,7 @@ void EraseSelectedTool (void) if (toolsWindow == nil) return; - SetPort(&toolsWindow->GetDrawSurface()->m_port); + SetPort(toolsWindow->GetDrawSurface()); toolIcon = toolSelected; if ((toolMode == kBlowerMode) && (toolIcon >= 7)) diff --git a/PortabilityLayer/PLQDOffscreen.cpp b/PortabilityLayer/PLQDOffscreen.cpp index e4159d2..785f6d0 100644 --- a/PortabilityLayer/PLQDOffscreen.cpp +++ b/PortabilityLayer/PLQDOffscreen.cpp @@ -46,15 +46,10 @@ void OffsetRect(Rect *rect, int right, int down) DrawSurface *GetGraphicsPort() { - PortabilityLayer::QDPort *port = PortabilityLayer::QDManager::GetInstance()->GetPort(); - - DrawSurface *grafPtr = reinterpret_cast(port); - assert(&grafPtr->m_port == port); - - return grafPtr; + return PortabilityLayer::QDManager::GetInstance()->GetPort(); } void SetGraphicsPort(DrawSurface *gw) { - PortabilityLayer::QDManager::GetInstance()->SetPort(&gw->m_port); + PortabilityLayer::QDManager::GetInstance()->SetPort(gw); } diff --git a/PortabilityLayer/PLQDraw.cpp b/PortabilityLayer/PLQDraw.cpp index f07f882..c86c7a9 100644 --- a/PortabilityLayer/PLQDraw.cpp +++ b/PortabilityLayer/PLQDraw.cpp @@ -38,13 +38,7 @@ static inline void InvertPixel8(uint8_t &pixel) pixel = 255 ^ pixel; } - -void GetPort(GrafPtr *graf) -{ - PL_NotYetImplemented(); -} - -void SetPort(GrafPtr graf) +void SetPort(DrawSurface *graf) { PortabilityLayer::QDManager::GetInstance()->SetPort(graf); } @@ -65,7 +59,7 @@ void SetRect(Rect *rect, short left, short top, short right, short bottom) void SetPortWindowPort(WindowPtr window) { PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance(); - PortabilityLayer::QDManager::GetInstance()->SetPort(&window->GetDrawSurface()->m_port); + PortabilityLayer::QDManager::GetInstance()->SetPort(window->GetDrawSurface()); } void SetPortDialogPort(Dialog *dialog) diff --git a/PortabilityLayer/PLQDraw.h b/PortabilityLayer/PLQDraw.h index 961103c..12a1a03 100644 --- a/PortabilityLayer/PLQDraw.h +++ b/PortabilityLayer/PLQDraw.h @@ -58,16 +58,13 @@ private: typedef CIcon *CIconPtr; typedef CIconPtr *CIconHandle; -typedef PortabilityLayer::QDPort GrafPort; -typedef GrafPort *GrafPtr; - typedef Byte Pattern[8]; -void GetPort(GrafPtr *graf); -void SetPort(GrafPtr graf); void SetPortWindowPort(WindowPtr window); void SetPortDialogPort(Dialog *dialog); + +void SetPort(DrawSurface *graf); void EndUpdate(WindowPtr graf); void SetRect(Rect *rect, short left, short top, short right, short bottom); diff --git a/PortabilityLayer/QDGraf.h b/PortabilityLayer/QDGraf.h index 33fcd0b..39c513c 100644 --- a/PortabilityLayer/QDGraf.h +++ b/PortabilityLayer/QDGraf.h @@ -98,11 +98,10 @@ struct DrawSurface PortabilityLayer::RenderedFont *ResolveFont(bool aa) const; - // Must be the first item - PortabilityLayer::QDPort m_port; - IGpDisplayDriverSurface *m_ddSurface; PortabilityLayer::AntiAliasTable *m_cachedAATable; PortabilityLayer::RGBAColor m_cachedAAColor; + + PortabilityLayer::QDPort m_port; }; diff --git a/PortabilityLayer/QDManager.cpp b/PortabilityLayer/QDManager.cpp index f9c33c2..accf8ba 100644 --- a/PortabilityLayer/QDManager.cpp +++ b/PortabilityLayer/QDManager.cpp @@ -16,8 +16,8 @@ namespace PortabilityLayer QDManagerImpl(); void Init() override; - QDPort *GetPort() const override; - void SetPort(QDPort *gw) override; + DrawSurface *GetPort() const override; + void SetPort(DrawSurface *gw) override; PLError_t NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable) override; void DisposeGWorld(DrawSurface *gw) override; QDState *GetState() override; @@ -25,7 +25,7 @@ namespace PortabilityLayer static QDManagerImpl *GetInstance(); private: - QDPort *m_port; + DrawSurface *m_port; static QDManagerImpl ms_instance; }; @@ -39,16 +39,16 @@ namespace PortabilityLayer { } - QDPort *QDManagerImpl::GetPort() const + DrawSurface *QDManagerImpl::GetPort() const { return m_port; } - void QDManagerImpl::SetPort(QDPort *gw) + void QDManagerImpl::SetPort(DrawSurface *gw) { #if GP_DEBUG_CONFIG if (gw) - gw->CheckPortSentinel(); + gw->m_port.CheckPortSentinel(); #endif m_port = gw; @@ -83,7 +83,7 @@ namespace PortabilityLayer QDState *QDManagerImpl::GetState() { - return m_port->GetState(); + return m_port->m_port.GetState(); } QDManagerImpl *QDManagerImpl::GetInstance() diff --git a/PortabilityLayer/QDManager.h b/PortabilityLayer/QDManager.h index 417db96..e23f34f 100644 --- a/PortabilityLayer/QDManager.h +++ b/PortabilityLayer/QDManager.h @@ -16,8 +16,8 @@ namespace PortabilityLayer { public: virtual void Init() = 0; - virtual QDPort *GetPort() const = 0; - virtual void SetPort(QDPort *gw) = 0; + virtual DrawSurface *GetPort() const = 0; + virtual void SetPort(DrawSurface *gw) = 0; virtual PLError_t NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable) = 0; virtual void DisposeGWorld(DrawSurface *gw) = 0; diff --git a/PortabilityLayer/QDPort.cpp b/PortabilityLayer/QDPort.cpp index 04b6056..be49aae 100644 --- a/PortabilityLayer/QDPort.cpp +++ b/PortabilityLayer/QDPort.cpp @@ -35,7 +35,7 @@ namespace PortabilityLayer { #if GP_DEBUG_CONFIG // Detach the port BEFORE destroying it!! - assert(PortabilityLayer::QDManager::GetInstance()->GetPort() != this); + assert(&PortabilityLayer::QDManager::GetInstance()->GetPort()->m_port != this); #endif DisposePixMap(); diff --git a/PortabilityLayer/WindowManager.cpp b/PortabilityLayer/WindowManager.cpp index 2d7b45a..4abf280 100644 --- a/PortabilityLayer/WindowManager.cpp +++ b/PortabilityLayer/WindowManager.cpp @@ -1102,7 +1102,7 @@ namespace PortabilityLayer DetachWindow(window); - if (PortabilityLayer::QDManager::GetInstance()->GetPort() == &windowImpl->GetDrawSurface()->m_port) + if (PortabilityLayer::QDManager::GetInstance()->GetPort() == windowImpl->GetDrawSurface()) PortabilityLayer::QDManager::GetInstance()->SetPort(nullptr); windowImpl->~WindowImpl();