From c4e93b0ccf7d49a8a8ed536e1bc68f1f06fb0ede Mon Sep 17 00:00:00 2001 From: elasota Date: Thu, 26 Dec 2019 12:58:58 -0500 Subject: [PATCH] Cleanup, add scanline mask builder --- GpApp/AnimCursor.cpp | 3 - GpApp/Banner.cpp | 8 - GpApp/DialogUtils.cpp | 4 - GpApp/Environ.h | 2 +- GpApp/Events.cpp | 2 +- GpApp/GameOver.cpp | 3 - GpApp/HighScores.cpp | 27 -- GpApp/House.cpp | 38 --- GpApp/HouseIO.cpp | 13 - GpApp/HouseInfo.cpp | 11 - GpApp/HouseLegal.cpp | 61 +--- GpApp/InterfaceInit.cpp | 4 - GpApp/Link.cpp | 6 - GpApp/Map.cpp | 10 - GpApp/Marquee.h | 2 +- GpApp/Menu.cpp | 4 +- GpApp/Modes.cpp | 12 - GpApp/Music.cpp | 3 - GpApp/ObjectAdd.cpp | 10 - GpApp/ObjectDraw.cpp | 23 +- GpApp/ObjectDraw2.cpp | 4 - GpApp/ObjectDrawAll.cpp | 5 - GpApp/ObjectEdit.cpp | 47 --- GpApp/ObjectEdit.h | 2 +- GpApp/ObjectRects.cpp | 12 - GpApp/Objects.cpp | 21 -- GpApp/Play.cpp | 7 - GpApp/RectUtils.h | 2 +- GpApp/Room.cpp | 52 +-- GpApp/RoomGraphics.cpp | 14 - GpApp/RoomInfo.cpp | 5 - GpApp/SavedGames.cpp | 4 - GpApp/Sound.cpp | 4 - GpApp/StructuresInit.cpp | 2 - GpApp/Transit.cpp | 8 - GpApp/Triggers.cpp | 3 - GpApp/Utilities.cpp | 29 +- GpD3D/GpSystemServices_Win32.cpp | 15 +- GpD3D/GpSystemServices_Win32.h | 1 + PortabilityLayer/DisplayDeviceManager.cpp | 2 +- PortabilityLayer/HostSystemServices.h | 1 + PortabilityLayer/IPlotter.h | 14 + PortabilityLayer/LinePlotter.cpp | 101 ++++++ PortabilityLayer/LinePlotter.h | 30 ++ PortabilityLayer/PLCore.cpp | 33 +- PortabilityLayer/PLCore.h | 8 - PortabilityLayer/PLQDOffscreen.h | 2 +- .../{PLQuickdraw.cpp => PLQDraw.cpp} | 2 +- PortabilityLayer/{PLQuickdraw.h => PLQDraw.h} | 0 PortabilityLayer/PlotDirection.h | 20 ++ PortabilityLayer/PortabilityLayer.vcxproj | 13 +- .../PortabilityLayer.vcxproj.filters | 39 ++- PortabilityLayer/QDPixMap.h | 2 +- PortabilityLayer/QDState.cpp | 16 +- PortabilityLayer/ScanlineMask.cpp | 80 +++++ PortabilityLayer/ScanlineMask.h | 31 ++ PortabilityLayer/ScanlineMaskBuilder.cpp | 66 ++++ PortabilityLayer/ScanlineMaskBuilder.h | 25 ++ PortabilityLayer/ScanlineMaskConverter.cpp | 318 ++++++++++++++++++ PortabilityLayer/ScanlineMaskConverter.h | 15 + PortabilityLayer/Vec2i.h | 16 +- 61 files changed, 823 insertions(+), 494 deletions(-) create mode 100644 PortabilityLayer/IPlotter.h create mode 100644 PortabilityLayer/LinePlotter.cpp create mode 100644 PortabilityLayer/LinePlotter.h rename PortabilityLayer/{PLQuickdraw.cpp => PLQDraw.cpp} (99%) rename PortabilityLayer/{PLQuickdraw.h => PLQDraw.h} (100%) create mode 100644 PortabilityLayer/PlotDirection.h create mode 100644 PortabilityLayer/ScanlineMask.cpp create mode 100644 PortabilityLayer/ScanlineMask.h create mode 100644 PortabilityLayer/ScanlineMaskBuilder.cpp create mode 100644 PortabilityLayer/ScanlineMaskBuilder.h create mode 100644 PortabilityLayer/ScanlineMaskConverter.cpp create mode 100644 PortabilityLayer/ScanlineMaskConverter.h diff --git a/GpApp/AnimCursor.cpp b/GpApp/AnimCursor.cpp index a295f9d..a638c08 100644 --- a/GpApp/AnimCursor.cpp +++ b/GpApp/AnimCursor.cpp @@ -131,9 +131,6 @@ void InitAnimatedCursor (acurHandle ballCursH) if (!compiledBallCursorH) RedAlert(kErrFailedResourceLoad); - HNoPurge((Handle)ballCursH); - MoveHHi((Handle)ballCursH); - HLock((Handle)ballCursH); if (useColor) useColor = GetColorCursors(ballCursH, compiledBallCursorH); if (!useColor && !GetMonoCursors(ballCursH, compiledBallCursorH)) diff --git a/GpApp/Banner.cpp b/GpApp/Banner.cpp index aeac628..4984230 100644 --- a/GpApp/Banner.cpp +++ b/GpApp/Banner.cpp @@ -90,12 +90,9 @@ void DrawBanner (Point *topLeft) short CountStarsInHouse (void) { short i, h, numRooms, numStars; - char wasState; numStars = 0; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) { @@ -106,7 +103,6 @@ short CountStarsInHouse (void) numStars++; } } - HSetState((Handle)thisHouse, wasState); return (numStars); } @@ -119,12 +115,8 @@ void DrawBannerMessage (Point topLeft) { Str255 bannerStr, subStr; short count; - char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); PasStringCopy((*thisHouse)->banner, bannerStr); - HSetState((Handle)thisHouse, wasState); TextFont(applFont); TextFace(bold); diff --git a/GpApp/DialogUtils.cpp b/GpApp/DialogUtils.cpp index 85e5c00..dbcee20 100644 --- a/GpApp/DialogUtils.cpp +++ b/GpApp/DialogUtils.cpp @@ -143,11 +143,7 @@ void GetDialogRect (Rect *bounds, short dialogID) dlogHandle = (DialogTHndl)GetResource('DLOG', dialogID); if (dlogHandle != nil) { - wasState = HGetState((Handle)dlogHandle); - HLock((Handle)dlogHandle); - *bounds = (**dlogHandle).boundsRect; - HSetState((Handle)dlogHandle, wasState); } } diff --git a/GpApp/Environ.h b/GpApp/Environ.h index b344799..456b4fa 100644 --- a/GpApp/Environ.h +++ b/GpApp/Environ.h @@ -5,7 +5,7 @@ //============================================================================ -#include "PLQuickdraw.h" +#include "PLQDraw.h" typedef struct diff --git a/GpApp/Events.cpp b/GpApp/Events.cpp index 22c412d..a71409f 100644 --- a/GpApp/Events.cpp +++ b/GpApp/Events.cpp @@ -9,7 +9,7 @@ #include "PLAppleEvents.h" #include "PLKeyEncoding.h" #include "PLToolUtils.h" -#include "PLQuickdraw.h" +#include "PLQDraw.h" #include "Externs.h" #include "Environ.h" #include "House.h" diff --git a/GpApp/GameOver.cpp b/GpApp/GameOver.cpp index 0afa12c..4a38e7e 100644 --- a/GpApp/GameOver.cpp +++ b/GpApp/GameOver.cpp @@ -91,10 +91,7 @@ void SetUpFinalScreen (void) if (textDown < 0) textDown = 0; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); PasStringCopy((*thisHouse)->trailer, tempStr); - HSetState((Handle)thisHouse, wasState); count = 0; do diff --git a/GpApp/HighScores.cpp b/GpApp/HighScores.cpp index 4436e50..1bace32 100644 --- a/GpApp/HighScores.cpp +++ b/GpApp/HighScores.cpp @@ -150,8 +150,6 @@ void DrawHighScores (void) TextFace(bold); TextSize(12); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; // message for score #1 PasStringCopy(thisHousePtr->highScores.banner, tempStr); @@ -273,7 +271,6 @@ void DrawHighScores (void) DrawString(tempStr); ForeColor(blackColor); - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- SortHighScores @@ -287,8 +284,6 @@ void SortHighScores (void) short i, h, which; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; for (h = 0; h < kMaxScores; h++) @@ -314,8 +309,6 @@ void SortHighScores (void) } PasStringCopy(thisHousePtr->highScores.banner, tempScores.banner); thisHousePtr->highScores = tempScores; - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- ZeroHighScores @@ -327,8 +320,6 @@ void ZeroHighScores (void) short i; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; PasStringCopy(thisHouseName, thisHousePtr->highScores.banner); @@ -339,8 +330,6 @@ void ZeroHighScores (void) thisHousePtr->highScores.timeStamps[i] = 0L; thisHousePtr->highScores.levels[i] = 0; } - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- ZeroAllButHighestScore @@ -352,8 +341,6 @@ void ZeroAllButHighestScore (void) short i; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; for (i = 1; i < kMaxScores; i++) @@ -363,8 +350,6 @@ void ZeroAllButHighestScore (void) thisHousePtr->highScores.timeStamps[i] = 0L; thisHousePtr->highScores.levels[i] = 0; } - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- TestHighScore @@ -381,8 +366,6 @@ Boolean TestHighScore (void) if (resumedSavedGame) return (false); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; lastHighScore = -1; @@ -415,8 +398,6 @@ Boolean TestHighScore (void) gameDirty = true; } - HSetState((Handle)thisHouse, wasState); - if (placing != -1) { DoHighScores(); @@ -770,18 +751,14 @@ Boolean WriteScoresToDisk (void) } byteCount = sizeof(scoresType); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); theScores = &((*thisHouse)->highScores); theErr = FSWrite(scoresRefNum, &byteCount, (Ptr)theScores); if (!CheckFileError(theErr, PSTR("High Scores File"))) { - HSetState((Handle)thisHouse, wasState); theErr = FSClose(scoresRefNum); return(false); } - HSetState((Handle)thisHouse, wasState); theErr = SetEOF(scoresRefNum, byteCount); if (!CheckFileError(theErr, PSTR("High Scores File"))) @@ -835,18 +812,14 @@ Boolean ReadScoresFromDisk (void) return (false); } - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); theScores = &((*thisHouse)->highScores); theErr = FSRead(scoresRefNum, &byteCount, theScores); if (!CheckFileError(theErr, PSTR("High Scores File"))) { - HSetState((Handle)thisHouse, wasState); theErr = FSClose(scoresRefNum); return (false); } - HSetState((Handle)thisHouse, wasState); theErr = FSClose(scoresRefNum); if (!CheckFileError(theErr, PSTR("High Scores File"))) diff --git a/GpApp/House.cpp b/GpApp/House.cpp index 6ae7420..042ec7c 100644 --- a/GpApp/House.cpp +++ b/GpApp/House.cpp @@ -123,7 +123,6 @@ Boolean InitializeEmptyHouse (void) return (false); } - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; thisHousePtr->version = kHouseVersion; @@ -144,8 +143,6 @@ Boolean InitializeEmptyHouse (void) wardBitSet = false; phoneBitSet = false; - HUnlock((Handle)thisHouse); - numberRooms = 0; mapLeftRoom = 60; mapTopRoom = 50; @@ -174,8 +171,6 @@ short RealRoomNumberCount (void) short realRoomCount, i; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); realRoomCount = (*thisHouse)->nRooms; if (realRoomCount != 0) { @@ -185,7 +180,6 @@ short RealRoomNumberCount (void) realRoomCount--; } } - HSetState((Handle)thisHouse, wasState); return (realRoomCount); } @@ -200,8 +194,6 @@ short GetFirstRoomNumber (void) short firstRoom; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); if ((*thisHouse)->nRooms <= 0) { firstRoom = -1; @@ -213,7 +205,6 @@ short GetFirstRoomNumber (void) if ((firstRoom >= (*thisHouse)->nRooms) || (firstRoom < 0)) firstRoom = 0; } - HSetState((Handle)thisHouse, wasState); return (firstRoom); } @@ -228,15 +219,11 @@ void WhereDoesGliderBegin (Rect *theRect, short mode) Point initialPt; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - if (mode == kResumeGameMode) initialPt = smallGame.where; else if (mode == kNewGameMode) initialPt = (*thisHouse)->initial; - HSetState((Handle)thisHouse, wasState); QSetRect(theRect, 0, 0, kGliderWide, kGliderHigh); QOffsetRect(theRect, initialPt.h, initialPt.v); } @@ -266,8 +253,6 @@ short CountHouseLinks (void) numLinks = 0; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; numRooms = thisHousePtr->nRooms; @@ -303,8 +288,6 @@ short CountHouseLinks (void) } } - HSetState((Handle)thisHouse, wasState); - return (numLinks); } @@ -324,8 +307,6 @@ void GenerateLinksList (void) short floor, suite, roomLinked, objectLinked; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; numRooms = thisHousePtr->nRooms; @@ -382,8 +363,6 @@ void GenerateLinksList (void) } } } - - HSetState((Handle)thisHouse, wasState); } #endif @@ -468,8 +447,6 @@ void SortHouseObjects (void) GenerateLinksList(); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; numRooms = thisHousePtr->nRooms; @@ -498,7 +475,6 @@ void SortHouseObjects (void) } SpinCursor(3); - HSetState((Handle)thisHouse, wasState); if (linksList != nil) DisposePtr((Ptr)linksList); ForceThisRoom(thisRoomNumber); @@ -516,8 +492,6 @@ short CountRoomsVisited (void) short numRooms, r, count; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; numRooms = thisHousePtr->nRooms; count = 0; @@ -528,7 +502,6 @@ short CountRoomsVisited (void) count++; } - HSetState((Handle)thisHouse, wasState); return (count); } @@ -548,8 +521,6 @@ void GenerateRetroLinks (void) for (i = 0; i < kMaxRoomObs; i++) // Initialize array. retroLinkList[i].room = -1; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; numRooms = thisHousePtr->nRooms; @@ -610,8 +581,6 @@ void GenerateRetroLinks (void) } } } - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- UpdateGoToDialog @@ -759,9 +728,6 @@ void ConvertHouseVer1To2 (void) SpinCursor(3); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) { @@ -814,7 +780,6 @@ void ConvertHouseVer1To2 (void) } (*thisHouse)->version = kHouseVersion; - HSetState((Handle)thisHouse, wasState); InitCursor(); CloseMessageWindow(); @@ -834,8 +799,6 @@ void ShiftWholeHouse (short howFar) CopyThisRoomToRoom(); wasRoom = thisRoomNumber; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) @@ -852,7 +815,6 @@ void ShiftWholeHouse (short howFar) } } - HSetState((Handle)thisHouse, wasState); ForceThisRoom(wasRoom); InitCursor(); diff --git a/GpApp/HouseIO.cpp b/GpApp/HouseIO.cpp index 00f9844..30f87c0 100644 --- a/GpApp/HouseIO.cpp +++ b/GpApp/HouseIO.cpp @@ -662,7 +662,6 @@ Boolean ReadHouse (void) YellowAlert(kYellowNoMemory, 10); return(false); } - MoveHHi((Handle)thisHouse); theErr = SetFPos(houseRefNum, fsFromStart, 0L); if (theErr != noErr) @@ -671,13 +670,11 @@ Boolean ReadHouse (void) return(false); } - HLock((Handle)thisHouse); long readByteCount = byteCount; theErr = FSRead(houseRefNum, &readByteCount, *thisHouse); if (theErr != noErr || readByteCount != byteCount || byteCount < static_cast(houseType::kBinaryDataSize)) { CheckFileError(theErr, thisHouseName); - HUnlock((Handle)thisHouse); return(false); } @@ -702,7 +699,6 @@ Boolean ReadHouse (void) numberRooms = 0; noRoomAtAll = true; YellowAlert(kYellowNoRooms, 0); - HUnlock((Handle)thisHouse); return(false); } @@ -710,7 +706,6 @@ Boolean ReadHouse (void) if (wasHouseVersion >= kNewHouseVersion) { YellowAlert(kYellowNewerVersion, 0); - HUnlock((Handle)thisHouse); return(false); } @@ -732,8 +727,6 @@ Boolean ReadHouse (void) phoneBitSet = (((*thisHouse)->flags & 0x00000002) == 0x00000002); bannerStarCountOn = (((*thisHouse)->flags & 0x00000004) == 0x00000000); - HUnlock((Handle)thisHouse); - noRoomAtAll = (RealRoomNumberCount() == 0); thisRoomNumber = -1; previousRoom = -1; @@ -786,7 +779,6 @@ Boolean WriteHouse (Boolean checkIt) if (checkIt) CheckHouseForProblems(); - HLock((Handle)thisHouse); byteCount = GetHandleSize((Handle)thisHouse); if (fileDirty) @@ -815,7 +807,6 @@ Boolean WriteHouse (Boolean checkIt) { CheckFileError(theErr, thisHouseName); ByteSwapHouse(*thisHouse, static_cast(byteCount)); - HUnlock((Handle)thisHouse); return(false); } @@ -824,7 +815,6 @@ Boolean WriteHouse (Boolean checkIt) { CheckFileError(theErr, thisHouseName); ByteSwapHouse(*thisHouse, static_cast(byteCount)); - HUnlock((Handle)thisHouse); return(false); } @@ -834,12 +824,9 @@ Boolean WriteHouse (Boolean checkIt) if (theErr != noErr) { CheckFileError(theErr, thisHouseName); - HUnlock((Handle)thisHouse); return(false); } - HUnlock((Handle)thisHouse); - if (changeLockStateOfHouse) { changeLockStateOfHouse = false; diff --git a/GpApp/HouseInfo.cpp b/GpApp/HouseInfo.cpp index 49c7d0b..f5852e5 100644 --- a/GpApp/HouseInfo.cpp +++ b/GpApp/HouseInfo.cpp @@ -57,9 +57,6 @@ long CountTotalHousePoints (void) pointTotal = (long)RealRoomNumberCount() * (long)kRoomVisitScore; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) { @@ -100,8 +97,6 @@ long CountTotalHousePoints (void) } } - HSetState((Handle)thisHouse, wasState); - return (pointTotal); } @@ -218,9 +213,7 @@ void DoHouseInfo (void) houseFilterUPP = NewModalFilterUPP(HouseFilter); tempPhoneBit = phoneBitSet; - wasState = HGetState((Handle)thisHouse); numRooms = RealRoomNumberCount(); - HLock((Handle)thisHouse); PasStringCopy((*thisHouse)->banner, banner); PasStringCopy((*thisHouse)->trailer, trailer); version = (*thisHouse)->version; @@ -229,7 +222,6 @@ void DoHouseInfo (void) h = (long)(*thisHouse)->rooms[(*thisHouse)->firstRoom].suite; v = (long)(*thisHouse)->rooms[(*thisHouse)->firstRoom].floor; } - HSetState((Handle)thisHouse, wasState); NumToString((long)version >> 8, versStr); // Convert version to two stringsÉ NumToString((long)version % 0x0100, loVers); // the 1's and 1/10th's part. @@ -261,8 +253,6 @@ void DoHouseInfo (void) GetDialogString(houseInfoDialog, kBannerTextItem, banner); GetDialogString(houseInfoDialog, kTrailerTextItem, trailer); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); PasStringCopyNum(banner, (*thisHouse)->banner, 255); PasStringCopyNum(trailer, (*thisHouse)->trailer, 255); if (tempPhoneBit != phoneBitSet) @@ -273,7 +263,6 @@ void DoHouseInfo (void) else (*thisHouse)->flags = (*thisHouse)->flags & 0xFFFFDFFD; } - HSetState((Handle)thisHouse, wasState); fileDirty = true; UpdateMenus(false); diff --git a/GpApp/HouseLegal.cpp b/GpApp/HouseLegal.cpp index ac8e711..3cb45cd 100644 --- a/GpApp/HouseLegal.cpp +++ b/GpApp/HouseLegal.cpp @@ -54,8 +54,6 @@ Boolean KeepObjectLegal (void) if (objActive == kInitialGliderSelected) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); if ((*thisHouse)->initial.h < 0) (*thisHouse)->initial.h = 0; if ((*thisHouse)->initial.v < 0) @@ -64,7 +62,6 @@ Boolean KeepObjectLegal (void) (*thisHouse)->initial.h = kRoomWide - kGliderWide; if ((*thisHouse)->initial.v > (kTileHigh - kGliderHigh)) (*thisHouse)->initial.v = kTileHigh - kGliderHigh; - HSetState((Handle)thisHouse, wasState); return (true); } @@ -605,13 +602,8 @@ void WrapBannerAndTrailer (void) { char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - WrapText((*thisHouse)->banner, 40); WrapText((*thisHouse)->trailer, 64); - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- ValidateNumberOfRooms @@ -623,9 +615,6 @@ void ValidateNumberOfRooms (void) long countedRooms, reportsRooms; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - reportsRooms = (long)(*thisHouse)->nRooms; countedRooms = (GetHandleSize((Handle)thisHouse) - sizeof(houseType)) / sizeof(roomType); @@ -635,8 +624,6 @@ void ValidateNumberOfRooms (void) numberRooms = (*thisHouse)->nRooms; houseErrors++; } - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- CheckDuplicateFloorSuite @@ -654,9 +641,6 @@ void CheckDuplicateFloorSuite (void) if (pidgeonHoles == nil) return; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) { @@ -676,8 +660,6 @@ void CheckDuplicateFloorSuite (void) } } - HSetState((Handle)thisHouse, wasState); - DisposePtr((Ptr)pidgeonHoles); } @@ -691,9 +673,6 @@ void CompressHouse (void) char wasState; Boolean compressing, probing; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - wasFirstRoom = (*thisHouse)->firstRoom; compressing = true; roomNumber = (*thisHouse)->nRooms - 1; // start with last room @@ -729,8 +708,6 @@ void CompressHouse (void) compressing = false; } while (compressing); - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- LopOffExtraRooms @@ -744,9 +721,6 @@ void LopOffExtraRooms (void) char wasState; Str255 message; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - count = 0; r = (*thisHouse)->nRooms; // begin at last room do @@ -763,19 +737,16 @@ void LopOffExtraRooms (void) { r = (*thisHouse)->nRooms - count; newSize = sizeof(houseType) + (sizeof(roomType) * (long)r); - HUnlock((Handle)thisHouse); // resize house handle (shrink) - SetHandleSize((Handle)thisHouse, newSize); + SetHandleSize((Handle)thisHouse, newSize); // resize house handle (shrink) if (MemError() != noErr) // problem? { ForeColor(redColor); GetLocalizedString(16, message); SetMessageWindowMessage(message); } - HLock((Handle)thisHouse); // reflect new room count (*thisHouse)->nRooms -= count; numberRooms = (*thisHouse)->nRooms; } - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- ValidateRoomNumbers @@ -788,9 +759,6 @@ void ValidateRoomNumbers (void) char wasState; Str255 message; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - numRooms = (*thisHouse)->nRooms; if (numRooms < 0) { @@ -823,8 +791,6 @@ void ValidateRoomNumbers (void) } } } - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- CountUntitledRooms @@ -836,9 +802,6 @@ void CountUntitledRooms (void) short i, numRooms; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) { @@ -846,8 +809,6 @@ void CountUntitledRooms (void) (EqualString((*thisHouse)->rooms[i].name, PSTR("Untitled Room"), false, true))) houseErrors++; } - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- CheckRoomNameLength @@ -859,9 +820,6 @@ void CheckRoomNameLength (void) short i, numRooms; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) { @@ -874,8 +832,6 @@ void CheckRoomNameLength (void) houseErrors++; } } - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- MakeSureNumObjectsJives @@ -887,9 +843,6 @@ void MakeSureNumObjectsJives (void) short i, h, numRooms, count; char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) { @@ -908,8 +861,6 @@ void MakeSureNumObjectsJives (void) } } } - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- KeepAllObjectsLegal @@ -922,9 +873,6 @@ void KeepAllObjectsLegal (void) char wasState; Str255 message; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) { @@ -950,8 +898,6 @@ void KeepAllObjectsLegal (void) CopyThisRoomToRoom(); } } - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- CheckForStaircasePairs @@ -965,9 +911,6 @@ void CheckForStaircasePairs (void) Boolean hasStairs; Str255 message; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - numRooms = (*thisHouse)->nRooms; for (i = 0; i < numRooms; i++) { @@ -1040,8 +983,6 @@ void CheckForStaircasePairs (void) } } } - - HSetState((Handle)thisHouse, wasState); } #endif diff --git a/GpApp/InterfaceInit.cpp b/GpApp/InterfaceInit.cpp index 26c1bae..9b77650 100644 --- a/GpApp/InterfaceInit.cpp +++ b/GpApp/InterfaceInit.cpp @@ -83,25 +83,21 @@ void GetExtraCursors (void) handCursorH = GetCursor(kHandCursorID); if (handCursorH == nil) RedAlert(kErrFailedResourceLoad); - HLock((Handle)handCursorH); handCursor = **handCursorH; vertCursorH = GetCursor(kVertCursorID); if (vertCursorH == nil) RedAlert(kErrFailedResourceLoad); - HLock((Handle)vertCursorH); vertCursor = **vertCursorH; horiCursorH = GetCursor(kHoriCursorID); if (horiCursorH == nil) RedAlert(kErrFailedResourceLoad); - HLock((Handle)horiCursorH); horiCursor = **horiCursorH; diagCursorH = GetCursor(kDiagCursorID); if (diagCursorH == nil) RedAlert(kErrFailedResourceLoad); - HLock((Handle)diagCursorH); diagCursor = **diagCursorH; } diff --git a/GpApp/Link.cpp b/GpApp/Link.cpp index 0bb9171..37f352e 100644 --- a/GpApp/Link.cpp +++ b/GpApp/Link.cpp @@ -295,8 +295,6 @@ void DoLink (void) } else { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); if (linkerIsSwitch) { (*thisHouse)->rooms[linkRoom].objects[linkObject].data.e.where = @@ -311,7 +309,6 @@ void DoLink (void) (*thisHouse)->rooms[linkRoom].objects[linkObject].data.d.who = objActive; } - HSetState((Handle)thisHouse, wasState); } fileDirty = true; UpdateMenus(false); @@ -342,8 +339,6 @@ void DoUnlink (void) } else { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); if (linkerIsSwitch) { (*thisHouse)->rooms[linkRoom].objects[linkObject].data.e.where = -1; @@ -354,7 +349,6 @@ void DoUnlink (void) (*thisHouse)->rooms[linkRoom].objects[linkObject].data.d.where = -1; (*thisHouse)->rooms[linkRoom].objects[linkObject].data.d.who = 255; } - HSetState((Handle)thisHouse, wasState); } fileDirty = true; UpdateMenus(false); diff --git a/GpApp/Map.cpp b/GpApp/Map.cpp index bace10e..bef0ed8 100644 --- a/GpApp/Map.cpp +++ b/GpApp/Map.cpp @@ -126,9 +126,6 @@ void FindNewActiveRoomRect (void) activeRoomVisible = false; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - for (i = 0; i < mapRoomsHigh; i++) { for (h = 0; h < mapRoomsWide; h++) @@ -150,8 +147,6 @@ void FindNewActiveRoomRect (void) } } - HSetState((Handle)thisHouse, wasState); - if (activeRoomVisible) { activeRoomRect.right++; @@ -211,9 +206,6 @@ void RedrawMapContents (void) ClipRect(&newClip); } - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - for (i = 0; i < mapRoomsHigh; i++) { for (h = 0; h < mapRoomsWide; h++) @@ -266,8 +258,6 @@ void RedrawMapContents (void) } } - HSetState((Handle)thisHouse, wasState); - ForeColor(blackColor); PenNormal(); diff --git a/GpApp/Marquee.h b/GpApp/Marquee.h index 09d324c..7450b23 100644 --- a/GpApp/Marquee.h +++ b/GpApp/Marquee.h @@ -8,7 +8,7 @@ #pragma once -#include "PLQuickdraw.h" +#include "PLQDraw.h" typedef struct diff --git a/GpApp/Menu.cpp b/GpApp/Menu.cpp index 22914b1..20e0baf 100644 --- a/GpApp/Menu.cpp +++ b/GpApp/Menu.cpp @@ -723,12 +723,10 @@ short QueryResumeGame (void) resumeFilterUPP = NewModalFilterUPP(ResumeFilter); - wasState = HGetState((Handle)thisHouse); // get score & num. gliders - HLock((Handle)thisHouse); + // get score & num. gliders thisHousePtr = *thisHouse; hadPoints = thisHousePtr->savedGame.score; hadGliders = thisHousePtr->savedGame.numGliders; - HSetState((Handle)thisHouse, wasState); NumToString(hadPoints, scoreStr); // param text strings NumToString((long)hadGliders, glidStr); if (hadGliders == 1) diff --git a/GpApp/Modes.cpp b/GpApp/Modes.cpp index 03f7a3b..c9914c8 100644 --- a/GpApp/Modes.cpp +++ b/GpApp/Modes.cpp @@ -165,10 +165,7 @@ void StartGliderMailingIn (gliderPtr thisGlider, Rect *bounds, hotPtr who) objLinked = masterObjects[whoLinked].objectLink; linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect); - HSetState((Handle)thisHouse, wasState); thisGlider->frame = 0; thisGlider->clip = *bounds; @@ -228,10 +225,7 @@ void StartGliderDuctingDown (gliderPtr thisGlider, Rect *bounds, hotPtr who) objLinked = masterObjects[whoLinked].objectLink; linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect); - HSetState((Handle)thisHouse, wasState); thisGlider->frame = 0; thisGlider->clip = *bounds; @@ -261,10 +255,7 @@ void StartGliderDuctingUp (gliderPtr thisGlider, Rect *bounds, hotPtr who) objLinked = masterObjects[whoLinked].objectLink; linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect); - HSetState((Handle)thisHouse, wasState); thisGlider->frame = 0; thisGlider->clip = *bounds; @@ -303,10 +294,7 @@ void StartGliderTransporting (gliderPtr thisGlider, hotPtr who) objLinked = masterObjects[whoLinked].objectLink; linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect); - HSetState((Handle)thisHouse, wasState); thisGlider->dest.right = thisGlider->dest.left + kGliderWide; thisGlider->dest.bottom = thisGlider->dest.top + kGliderHigh; diff --git a/GpApp/Music.cpp b/GpApp/Music.cpp index 45ac85e..a869be6 100644 --- a/GpApp/Music.cpp +++ b/GpApp/Music.cpp @@ -233,15 +233,12 @@ OSErr LoadMusicSounds (void) if (theSound == nil) return (MemError()); - HLock(theSound); soundDataSize = GetHandleSize(theSound) - 20L; - HUnlock(theSound); theMusicData[i] = NewPtr(soundDataSize); if (theMusicData[i] == nil) return (MemError()); - HLock(theSound); BlockMove((Ptr)(static_cast(*theSound) + 20L), theMusicData[i], soundDataSize); ReleaseResource(theSound); } diff --git a/GpApp/ObjectAdd.cpp b/GpApp/ObjectAdd.cpp index 08294ff..b3da983 100644 --- a/GpApp/ObjectAdd.cpp +++ b/GpApp/ObjectAdd.cpp @@ -829,8 +829,6 @@ short FindObjectSlotInRoom (short roomNumber) emptySlot = -1; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNumber]); for (i = 0; i < kMaxRoomObs; i++) @@ -840,9 +838,6 @@ short FindObjectSlotInRoom (short roomNumber) break; } - - HSetState((Handle)thisHouse, wasState); - return (emptySlot); } @@ -855,8 +850,6 @@ Boolean DoesRoomNumHaveObject (short room, short what) char wasState; Boolean hasIt; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[room]); hasIt = false; @@ -868,9 +861,6 @@ Boolean DoesRoomNumHaveObject (short room, short what) break; } - - HSetState((Handle)thisHouse, wasState); - return (hasIt); } diff --git a/GpApp/ObjectDraw.cpp b/GpApp/ObjectDraw.cpp index 4d8d765..96083fe 100644 --- a/GpApp/ObjectDraw.cpp +++ b/GpApp/ObjectDraw.cpp @@ -11,6 +11,9 @@ #include "Objects.h" #include "RectUtils.h" #include "Room.h" +#include "Vec2i.h" +#include "ScanlineMask.h" +#include "ScanlineMaskConverter.h" #define k8WhiteColor 0 @@ -293,16 +296,20 @@ void DrawShelf (Rect *shelfTop) GetGWorld(&wasCPort, &wasWorld); SetGWorld(backSrcMap, nil); - MoveTo(shelfTop->left, shelfTop->bottom); shadowRgn = NewRgn(); if (shadowRgn == nil) RedAlert(kErrUnnaccounted); + + PortabilityLayer::Vec2i poly[5]; + poly[0] = PortabilityLayer::Vec2i(shelfTop->left, shelfTop->bottom); + poly[1] = poly[0] + PortabilityLayer::Vec2i(kShelfShadowOff, kShelfShadowOff); + poly[2] = poly[1] + PortabilityLayer::Vec2i(RectWide(shelfTop) - kShelfDeep, 0); + poly[3] = poly[2] + PortabilityLayer::Vec2i(0, -kShelfThick + 1); + poly[4] = poly[3] + PortabilityLayer::Vec2i(-kShelfShadowOff, -kShelfShadowOff); + + //PortabilityLayer::ScanlineMask *mask = PortabilityLayer::ScanlineMaskConverter::CompilePoly(poly, sizeof(poly) / sizeof(poly[0])); + OpenRgn(); - Line(kShelfShadowOff, kShelfShadowOff); - Line(RectWide(shelfTop) - kShelfDeep, 0); - Line(0, -kShelfThick + 1); - Line(-kShelfShadowOff, -kShelfShadowOff); - LineTo(shelfTop->left, shelfTop->bottom); CloseRgn(shadowRgn); PenPat(GetQDGlobalsGray(&dummyPattern)); PenMode(patOr); @@ -312,7 +319,9 @@ void DrawShelf (Rect *shelfTop) ColorRegion(shadowRgn, k8DkstGrayColor); PenNormal(); DisposeRgn(shadowRgn); - + //mask->Destroy(); + + MoveTo(shelfTop->left, shelfTop->bottom); InsetRect(shelfTop, 0, 1); ColorRect(shelfTop, brownC); InsetRect(shelfTop, 0, -1); diff --git a/GpApp/ObjectDraw2.cpp b/GpApp/ObjectDraw2.cpp index e7d4c6f..9043bdd 100644 --- a/GpApp/ObjectDraw2.cpp +++ b/GpApp/ObjectDraw2.cpp @@ -1146,9 +1146,7 @@ void DrawCalendar (Rect *theRect) if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); - HLock((Handle)thePicture); bounds = (*thePicture)->picFrame.ToRect(); - HUnlock((Handle)thePicture); QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, theRect->left, theRect->top); DrawPicture(thePicture, &bounds); @@ -1182,9 +1180,7 @@ void DrawBulletin (Rect *theRect) if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); - HLock((Handle)thePicture); bounds = (*thePicture)->picFrame.ToRect(); - HUnlock((Handle)thePicture); QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, theRect->left, theRect->top); DrawPicture(thePicture, &bounds); diff --git a/GpApp/ObjectDrawAll.cpp b/GpApp/ObjectDrawAll.cpp index cacae68..d1633c5 100644 --- a/GpApp/ObjectDrawAll.cpp +++ b/GpApp/ObjectDrawAll.cpp @@ -37,9 +37,6 @@ void DrawARoomsObjects (short neighbor, Boolean redraw) ZeroRectCorner(&testRect); isLit = (numLights > 0); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - for (i = 0; i < kMaxRoomObs; i++) { dynamicNum = -1; @@ -960,7 +957,5 @@ void DrawARoomsObjects (short neighbor, Boolean redraw) } } } - - HSetState((Handle)thisHouse, wasState); } diff --git a/GpApp/ObjectEdit.cpp b/GpApp/ObjectEdit.cpp index c7f59f9..52a4674 100644 --- a/GpApp/ObjectEdit.cpp +++ b/GpApp/ObjectEdit.cpp @@ -529,11 +529,8 @@ void DragObject (Point where) if (objActive == kInitialGliderSelected) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); (*thisHouse)->initial.h += deltaH; (*thisHouse)->initial.v += deltaV; - HSetState((Handle)thisHouse, wasState); } else if (objActive == kLeftGliderSelected) { @@ -805,8 +802,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorExLf))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kDoorExLf; @@ -818,7 +813,6 @@ void AddObjectPairing (void) testRoomPtr->objects[emptySlot].data.d.wide = 0; testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); GetLocalizedString(45, message); OpenMessageWindow(message); @@ -839,8 +833,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorExRt))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kDoorExRt; @@ -853,8 +845,6 @@ void AddObjectPairing (void) testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); - GetLocalizedString(45, message); OpenMessageWindow(message); ForeColor(blueColor); @@ -874,8 +864,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorInLfLeft))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kDoorInLf; @@ -888,8 +876,6 @@ void AddObjectPairing (void) testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); - GetLocalizedString(45, message); OpenMessageWindow(message); ForeColor(blueColor); @@ -909,8 +895,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorInRtLeft))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kDoorInRt; @@ -923,8 +907,6 @@ void AddObjectPairing (void) testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); - GetLocalizedString(45, message); OpenMessageWindow(message); ForeColor(blueColor); @@ -944,8 +926,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowExRt))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kWindowExRt; @@ -958,8 +938,6 @@ void AddObjectPairing (void) testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); - GetLocalizedString(45, message); OpenMessageWindow(message); ForeColor(blueColor); @@ -979,8 +957,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowExLf))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kWindowExLf; @@ -993,8 +969,6 @@ void AddObjectPairing (void) testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); - GetLocalizedString(45, message); OpenMessageWindow(message); ForeColor(blueColor); @@ -1014,8 +988,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowInLf))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kWindowInLf; @@ -1028,8 +1000,6 @@ void AddObjectPairing (void) testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); - GetLocalizedString(45, message); OpenMessageWindow(message); ForeColor(blueColor); @@ -1049,8 +1019,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowInRt))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kWindowInRt; @@ -1063,8 +1031,6 @@ void AddObjectPairing (void) testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); - GetLocalizedString(45, message); OpenMessageWindow(message); ForeColor(blueColor); @@ -1084,8 +1050,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDownStairs))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kDownStairs; @@ -1099,8 +1063,6 @@ void AddObjectPairing (void) testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); - GetLocalizedString(45, message); OpenMessageWindow(message); ForeColor(blueColor); @@ -1120,8 +1082,6 @@ void AddObjectPairing (void) emptySlot = FindObjectSlotInRoom(roomNum); if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kUpStairs))) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr->objects[emptySlot].what = kUpStairs; @@ -1135,8 +1095,6 @@ void AddObjectPairing (void) testRoomPtr->numObjects++; - HSetState((Handle)thisHouse, wasState); - GetLocalizedString(45, message); OpenMessageWindow(message); ForeColor(blueColor); @@ -1486,11 +1444,8 @@ void MoveObject (short whichWay, Boolean shiftDown) if (objActive == kInitialGliderSelected) { wasRect = initialGliderRect; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); (*thisHouse)->initial.h += deltaH; (*thisHouse)->initial.v += deltaV; - HSetState((Handle)thisHouse, wasState); } else if (objActive == kLeftGliderSelected) { @@ -2288,9 +2243,7 @@ void GetThisRoomsObjRects (void) } else { - HLock((Handle)thePict); roomObjectRects[i] = (*thePict)->picFrame.ToRect(); - HUnlock((Handle)thePict); } ZeroRectCorner(&roomObjectRects[i]); QOffsetRect(&roomObjectRects[i], diff --git a/GpApp/ObjectEdit.h b/GpApp/ObjectEdit.h index 5d29758..3f2508c 100644 --- a/GpApp/ObjectEdit.h +++ b/GpApp/ObjectEdit.h @@ -8,7 +8,7 @@ #pragma once -#include "PLQuickdraw.h" +#include "PLQDraw.h" extern Rect roomObjectRects[]; diff --git a/GpApp/ObjectRects.cpp b/GpApp/ObjectRects.cpp index 8d2c444..bd76960 100644 --- a/GpApp/ObjectRects.cpp +++ b/GpApp/ObjectRects.cpp @@ -226,9 +226,7 @@ void GetObjectRect (objectPtr who, Rect *itsRect) } else { - HLock((Handle)thePict); *itsRect = (*thePict)->picFrame.ToRect(); - HUnlock((Handle)thePict); } ZeroRectCorner(itsRect); QOffsetRect(itsRect, @@ -1140,9 +1138,6 @@ short GetUpStairsRightEdge (void) rightEdge = kRoomWide; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - for (i = 0; i < kMaxRoomObs; i++) { thisObject = (*thisHouse)->rooms[thisRoomNumber].objects[i]; @@ -1153,8 +1148,6 @@ short GetUpStairsRightEdge (void) } } - HSetState((Handle)thisHouse, wasState); - return (rightEdge); } @@ -1168,9 +1161,6 @@ short GetDownStairsLeftEdge (void) leftEdge = 0; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - for (i = 0; i < kMaxRoomObs; i++) { thisObject = (*thisHouse)->rooms[thisRoomNumber].objects[i]; @@ -1181,8 +1171,6 @@ short GetDownStairsLeftEdge (void) } } - HSetState((Handle)thisHouse, wasState); - return (leftEdge); } diff --git a/GpApp/Objects.cpp b/GpApp/Objects.cpp index 6158186..e16e5bf 100644 --- a/GpApp/Objects.cpp +++ b/GpApp/Objects.cpp @@ -93,8 +93,6 @@ Boolean IsThisValid (short where, short who) itsGood = true; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); switch ((*thisHouse)->rooms[where].objects[who].what) { case kObjectIsEmpty: @@ -116,7 +114,6 @@ Boolean IsThisValid (short where, short who) itsGood = (*thisHouse)->rooms[where].objects[who].data.c.state; break; } - HSetState((Handle)thisHouse, wasState); return (itsGood); } @@ -261,8 +258,6 @@ void ListOneRoomsObjects (short where) if (roomNum == kRoomIsEmpty) return; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); for (n = 0; n < kMaxRoomObs; n++) { if (numMasterObjects < kMaxMasterObjects) @@ -292,7 +287,6 @@ void ListOneRoomsObjects (short where) numLocalMasterObjects++; } } - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- ListAllLocalObjects @@ -306,9 +300,6 @@ void ListAllLocalObjects (void) numLocalMasterObjects = 0; nHotSpots = 0; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - ListOneRoomsObjects(kCentralRoom); if (numNeighbors > 1) @@ -327,8 +318,6 @@ void ListAllLocalObjects (void) ListOneRoomsObjects(kNorthWestRoom); } - HSetState((Handle)thisHouse, wasState); - for (i = 0; i < numMasterObjects; i++) // correlate links withÉ { // index into this list if ((masterObjects[i].roomLink != -1) && // if object has a link @@ -368,8 +357,6 @@ Boolean SetObjectState (short room, short object, short action, short local) char wasState; Boolean changed; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); switch ((*thisHouse)->rooms[room].objects[object].what) { case kFloorVent: @@ -693,7 +680,6 @@ Boolean SetObjectState (short room, short object, short action, short local) break; } - HSetState((Handle)thisHouse, wasState); return (changed); } @@ -707,8 +693,6 @@ Boolean GetObjectState (short room, short object) theState = true; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); switch ((*thisHouse)->rooms[room].objects[object].what) { case kFloorVent: @@ -864,8 +848,6 @@ Boolean GetObjectState (short room, short object) case kChimes: break; } - - HSetState((Handle)thisHouse, wasState); return (theState); } @@ -909,8 +891,6 @@ void BringSendFrontBack (Boolean bringFront) GenerateLinksList(); // Fill in links list with src/destÉ } // data on objects and room numbers. - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); // Lock down house. thisHousePtr = *thisHouse; // Get a pointer to house structure. for (i = 0; i < kMaxRoomObs; i++) // Set up an ordered array. @@ -980,7 +960,6 @@ void BringSendFrontBack (Boolean bringFront) } } - HSetState((Handle)thisHouse, wasState); if (linksList != nil) DisposePtr((Ptr)linksList); diff --git a/GpApp/Play.cpp b/GpApp/Play.cpp index f1001f2..5b1ec22 100644 --- a/GpApp/Play.cpp +++ b/GpApp/Play.cpp @@ -528,9 +528,7 @@ void PlayGame (void) thePicture = GetPicture(kScoreboardPictID); if (!thePicture) RedAlert(kErrFailedGraphicLoad); - HLock((Handle)thePicture); bounds = (*thePicture)->picFrame.ToRect(); - HUnlock((Handle)thePicture); QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, hOffset, 0); DrawPicture(thePicture, &bounds); @@ -579,9 +577,7 @@ void PlayGame (void) thePicture = GetPicture(kScoreboardPictID); if (!thePicture) RedAlert(kErrFailedGraphicLoad); - HLock((Handle)thePicture); bounds = (*thePicture)->picFrame.ToRect(); - HUnlock((Handle)thePicture); QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, hOffset, 0); DrawPicture(thePicture, &bounds); @@ -605,8 +601,6 @@ void SetObjectsToDefaults (void) char wasState; Boolean initState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; numRooms = thisHousePtr->nRooms; @@ -701,7 +695,6 @@ void SetObjectsToDefaults (void) } } } - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- HideGlider diff --git a/GpApp/RectUtils.h b/GpApp/RectUtils.h index 7184e01..6a4d9aa 100644 --- a/GpApp/RectUtils.h +++ b/GpApp/RectUtils.h @@ -8,7 +8,7 @@ #pragma once -#include "PLQuickdraw.h" +#include "PLQDraw.h" void FrameWHRect (short, short, short, short); diff --git a/GpApp/Room.cpp b/GpApp/Room.cpp index e5f342d..b76d85c 100644 --- a/GpApp/Room.cpp +++ b/GpApp/Room.cpp @@ -182,9 +182,6 @@ Boolean CreateNewRoom (short h, short v) for (i = 0; i < kMaxRoomObs; i++) // zero out all objects thisRoom->objects[i].what = kObjectIsEmpty; - wasState = HGetState((Handle)thisHouse); - MoveHHi((Handle)thisHouse); - HLock((Handle)thisHouse); availableRoom = -1; // assume no available rooms if ((*thisHouse)->nRooms > 0) // look for an empty room for (i = 0; i < (*thisHouse)->nRooms; i++) @@ -196,18 +193,13 @@ Boolean CreateNewRoom (short h, short v) if (availableRoom == -1) // found no available rooms { - HUnlock((Handle)thisHouse); howMuch = sizeof(roomType); // add new room to end of house theErr = PtrAndHand((Ptr)thisRoom, (Handle)thisHouse, howMuch); if (theErr != noErr) { YellowAlert(kYellowUnaccounted, theErr); - MoveHHi((Handle)thisHouse); - HLock((Handle)thisHouse); return (false); } - MoveHHi((Handle)thisHouse); - HLock((Handle)thisHouse); (*thisHouse)->nRooms++; // increment nRooms numberRooms = (*thisHouse)->nRooms; previousRoom = thisRoomNumber; @@ -222,8 +214,6 @@ Boolean CreateNewRoom (short h, short v) if (noRoomAtAll) (*thisHouse)->firstRoom = thisRoomNumber; - HSetState((Handle)thisHouse, wasState); - CopyThisRoomToRoom(); UpdateEditWindowTitle(); noRoomAtAll = false; @@ -278,9 +268,7 @@ void ReadyBackground (short theID, short *theTiles) } } - HLock((Handle)thePicture); dest = (*thePicture)->picFrame.ToRect(); - HUnlock((Handle)thePicture); QOffsetRect(&dest, -dest.left, -dest.top); DrawPicture(thePicture, &dest); ReleaseResource((Handle)thePicture); @@ -359,10 +347,7 @@ void CopyThisRoomToRoom (void) if ((noRoomAtAll) || (thisRoomNumber == -1)) return; - tagByte = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); // copy back to house - (*thisHouse)->rooms[thisRoomNumber] = *thisRoom; - HSetState((Handle)thisHouse, tagByte); + (*thisHouse)->rooms[thisRoomNumber] = *thisRoom; // copy back to house } //-------------------------------------------------------------- ForceThisRoom @@ -374,13 +359,10 @@ void ForceThisRoom (short roomNumber) if (roomNumber == -1) return; - tagByte = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); if (roomNumber < (*thisHouse)->nRooms) *thisRoom = (*thisHouse)->rooms[roomNumber]; else YellowAlert(kYellowIllegalRoomNum, 0); - HSetState((Handle)thisHouse, tagByte); previousRoom = thisRoomNumber; thisRoomNumber = roomNumber; @@ -401,8 +383,6 @@ Boolean RoomExists (short suite, short floor, short *roomNum) if (suite < 0) return (foundIt); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; for (i = 0; i < numberRooms; i++) @@ -416,8 +396,6 @@ Boolean RoomExists (short suite, short floor, short *roomNum) } } - HSetState((Handle)thisHouse, wasState); - return (foundIt); } @@ -455,14 +433,11 @@ void DeleteRoom (Boolean doWarn) DeselectObject(); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); wasFloor = (*thisHouse)->rooms[thisRoomNumber].floor; wasSuite = (*thisHouse)->rooms[thisRoomNumber].suite; firstDeleted = ((*thisHouse)->firstRoom == thisRoomNumber); // is room "first" thisRoom->suite = kRoomIsEmpty; (*thisHouse)->rooms[thisRoomNumber].suite = kRoomIsEmpty; - HSetState((Handle)thisHouse, wasState); noRoomAtAll = (RealRoomNumberCount() == 0); // see if now no rooms if (noRoomAtAll) @@ -472,10 +447,7 @@ void DeleteRoom (Boolean doWarn) if (firstDeleted) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); (*thisHouse)->firstRoom = thisRoomNumber; - HSetState((Handle)thisHouse, wasState); } newRoomNow = false; @@ -616,8 +588,6 @@ short GetNeighborRoomNumber (short which) } roomNum = kRoomIsEmpty; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); roomH = (*thisHouse)->rooms[thisRoomNumber].suite + hDelta; roomV = (*thisHouse)->rooms[thisRoomNumber].floor + vDelta; @@ -630,7 +600,6 @@ short GetNeighborRoomNumber (short which) break; } } - HSetState((Handle)thisHouse, wasState); return (roomNum); } @@ -647,9 +616,6 @@ void SetToNearestNeighborRoom (short wasFloor, short wasSuite) char wasState; Boolean finished; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); - finished = false; distance = 1; // we begin our walk a distance of one from source room h = -1; // we begin with the neighbor to the leftÉ @@ -703,8 +669,6 @@ void SetToNearestNeighborRoom (short wasFloor, short wasSuite) } } } while (!finished); - - HSetState((Handle)thisHouse, wasState); } //-------------------------------------------------------------- GetRoomFloorSuite @@ -714,8 +678,6 @@ Boolean GetRoomFloorSuite (short room, short *floor, short *suite) char wasState; Boolean isRoom; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); if ((*thisHouse)->rooms[room].suite == kRoomIsEmpty) { *floor = 0; @@ -728,7 +690,6 @@ Boolean GetRoomFloorSuite (short room, short *floor, short *suite) *floor = (*thisHouse)->rooms[room].floor; isRoom = true; } - HSetState((Handle)thisHouse, wasState); return (isRoom); } @@ -743,8 +704,6 @@ short GetRoomNumber (short floor, short suite) roomNum = kRoomIsEmpty; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); for (i = 0; i < numberRooms; i++) { if (((*thisHouse)->rooms[i].suite == suite) && @@ -754,7 +713,6 @@ short GetRoomNumber (short floor, short suite) break; } } - HSetState((Handle)thisHouse, wasState); return (roomNum); } @@ -769,8 +727,6 @@ Boolean IsRoomAStructure (short roomNum) if (roomNum == kRoomIsEmpty) return (false); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); if ((*thisHouse)->rooms[roomNum].background >= kUserBackground) { if ((*thisHouse)->rooms[roomNum].bounds != 0) @@ -807,7 +763,6 @@ Boolean IsRoomAStructure (short roomNum) break; } } - HSetState((Handle)thisHouse, wasState); return (isStructure); } @@ -950,7 +905,6 @@ short GetOriginalBounding (short theID) else { boundCode = 0; - HLock((Handle)boundsRes); if ((*boundsRes)->left) boundCode += 1; if ((*boundsRes)->top) @@ -959,7 +913,6 @@ short GetOriginalBounding (short theID) boundCode += 4; if ((*boundsRes)->bottom) boundCode += 8; - HUnlock((Handle)boundsRes); ReleaseResource((Handle)boundsRes); } @@ -1033,8 +986,6 @@ short GetNumberOfLights (short where) } else { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; switch (thisHousePtr->rooms[where].background) { @@ -1094,7 +1045,6 @@ short GetNumberOfLights (short where) } } } - HSetState((Handle)thisHouse, wasState); } return (count); } diff --git a/GpApp/RoomGraphics.cpp b/GpApp/RoomGraphics.cpp index def2a67..71bacfa 100644 --- a/GpApp/RoomGraphics.cpp +++ b/GpApp/RoomGraphics.cpp @@ -58,10 +58,7 @@ void DrawLocale (void) tvInRoom = false; tvWithMovieNumber = -1; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); roomV = (*thisHouse)->rooms[thisRoomNumber].floor; - HSetState((Handle)thisHouse, wasState); for (i = 0; i < 9; i++) { @@ -147,9 +144,7 @@ void LoadGraphicSpecial (short resID) } } - HLock((Handle)thePicture); bounds = (*thePicture)->picFrame.ToRect(); - HUnlock((Handle)thePicture); OffsetRect(&bounds, -bounds.left, -bounds.top); DrawPicture(thePicture, &bounds); @@ -167,12 +162,9 @@ void DrawRoomBackground (short who, short where, short elevation) if (where == kCentralRoom) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisBackground = (*thisHouse)->rooms[who].background; for (i = 0; i < kNumTiles; i++) thisTiles[i] = (*thisHouse)->rooms[who].tiles[i]; - HSetState((Handle)thisHouse, wasState); } if ((numLights == 0) && (who != kRoomIsEmpty)) @@ -226,12 +218,9 @@ void DrawRoomBackground (short who, short where, short elevation) } else { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); pictID = (*thisHouse)->rooms[who].background; for (i = 0; i < kNumTiles; i++) tiles[i] = (*thisHouse)->rooms[who].tiles[i]; - HSetState((Handle)thisHouse, wasState); } SetPort((GrafPtr)workSrcMap); @@ -436,10 +425,7 @@ void RedrawRoomLighting (void) char wasState; Boolean wasLit, isLit; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); roomV = (*thisHouse)->rooms[thisRoomNumber].floor; - HSetState((Handle)thisHouse, wasState); wasLit = numLights > 0; numLights = GetNumberOfLights(localNumbers[kCentralRoom]); diff --git a/GpApp/RoomInfo.cpp b/GpApp/RoomInfo.cpp index 2cf2129..e436fcf 100644 --- a/GpApp/RoomInfo.cpp +++ b/GpApp/RoomInfo.cpp @@ -447,10 +447,7 @@ void DoRoomInfo (void) ShowWindow(GetDialogWindow(roomInfoDialog)); DrawDefaultButton(roomInfoDialog); - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); wasFirstRoom = ((*thisHouse)->firstRoom == thisRoomNumber); - HSetState((Handle)thisHouse, wasState); SetDialogItemValue(roomInfoDialog, kRoomFirstCheck, (short)wasFirstRoom); if (tempBack >= kUserBackground) @@ -473,9 +470,7 @@ void DoRoomInfo (void) PasStringCopyNum(tempStr, thisRoom->name, 27); if (wasFirstRoom) { - HLock((Handle)thisHouse); (*thisHouse)->firstRoom = thisRoomNumber; - HUnlock((Handle)thisHouse); } thisRoom->background = tempBack; if (tempBack < kUserBackground) diff --git a/GpApp/SavedGames.cpp b/GpApp/SavedGames.cpp index 78c4188..6ded1ba 100644 --- a/GpApp/SavedGames.cpp +++ b/GpApp/SavedGames.cpp @@ -311,8 +311,6 @@ void SaveGame (Boolean doSave) if (twoPlayerGame) return; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; if (doSave) @@ -343,8 +341,6 @@ void SaveGame (Boolean doSave) thisHousePtr->hasGame = false; } - HSetState((Handle)thisHouse, wasState); - if (doSave) { if (!WriteHouse(theMode == kEditMode)) diff --git a/GpApp/Sound.cpp b/GpApp/Sound.cpp index ddb966c..2ca07b9 100644 --- a/GpApp/Sound.cpp +++ b/GpApp/Sound.cpp @@ -225,7 +225,6 @@ OSErr LoadTriggerSound (short soundID) { soundDataSize = GetHandleSize(theSound) - 20L; theSoundData[kMaxSounds - 1] = NewPtr(soundDataSize); - HLock(theSound); if (theSoundData[kMaxSounds - 1] == nil) { ReleaseResource(theSound); @@ -268,15 +267,12 @@ OSErr LoadBufferSounds (void) if (theSound == nil) return (MemError()); - HLock(theSound); soundDataSize = GetHandleSize(theSound) - 20L; - HUnlock(theSound); theSoundData[i] = NewPtr(soundDataSize); if (theSoundData[i] == nil) return (MemError()); - HLock(theSound); BlockMove((Ptr)((Byte*)(*theSound) + 20L), theSoundData[i], soundDataSize); ReleaseResource(theSound); } diff --git a/GpApp/StructuresInit.cpp b/GpApp/StructuresInit.cpp index cf322e3..d7bd7e5 100644 --- a/GpApp/StructuresInit.cpp +++ b/GpApp/StructuresInit.cpp @@ -81,9 +81,7 @@ void InitScoreboardMap (void) thePicture = GetPicture(kScoreboardPictID); if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); - HLock((Handle)thePicture); bounds = (*thePicture)->picFrame.ToRect(); - HUnlock((Handle)thePicture); QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, hOffset, 0); DrawPicture(thePicture, &bounds); diff --git a/GpApp/Transit.cpp b/GpApp/Transit.cpp index 9fd5186..7d101cb 100644 --- a/GpApp/Transit.cpp +++ b/GpApp/Transit.cpp @@ -31,12 +31,8 @@ extern Boolean playerDead, playerSuicide, tvOn; short WhatAreWeLinkedTo (short where, Byte who) { short what, whatType; - char wasState; - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); what = (*thisHouse)->rooms[where].objects[who].what; - HSetState((Handle)thisHouse, wasState); switch (what) { @@ -430,15 +426,11 @@ void MoveMailToMail (gliderPtr thisGlider) void HandleRoomVisitation (void) { houseType *thisHousePtr; - char wasState; if (!thisRoom->visited) { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); thisHousePtr = *thisHouse; thisHousePtr->rooms[localNumbers[kCentralRoom]].visited = true; - HSetState((Handle)thisHouse, wasState); theScore += kRoomVisitScore; thisRoom->visited = true; } diff --git a/GpApp/Triggers.cpp b/GpApp/Triggers.cpp index 77238e2..d441a8c 100644 --- a/GpApp/Triggers.cpp +++ b/GpApp/Triggers.cpp @@ -173,8 +173,6 @@ void FireTrigger (short index) } else { - wasState = HGetState((Handle)thisHouse); - HLock((Handle)thisHouse); triggeredIs = masterObjects[triggerIs].localLink; switch ((*thisHouse)->rooms[triggers[index].room]. objects[triggers[index].object].what) @@ -189,7 +187,6 @@ void FireTrigger (short index) } break; } - HSetState((Handle)thisHouse, wasState); } } diff --git a/GpApp/Utilities.cpp b/GpApp/Utilities.cpp index 7ae817d..62f3d96 100644 --- a/GpApp/Utilities.cpp +++ b/GpApp/Utilities.cpp @@ -5,7 +5,7 @@ //============================================================================ #include "PLKeyEncoding.h" -#include "PLQuickdraw.h" +#include "PLQDraw.h" #include "PLPasStr.h" #include "PLResources.h" #include "PLSound.h" @@ -302,9 +302,7 @@ void LoadGraphic (short resID) if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); - HLock((Handle)thePicture); bounds = (*thePicture)->picFrame.ToRect(); - HUnlock((Handle)thePicture); OffsetRect(&bounds, -bounds.left, -bounds.top); DrawPicture(thePicture, &bounds); @@ -327,31 +325,6 @@ void LoadScaledGraphic (short resID, Rect *theRect) ReleaseResource((Handle)thePicture); } -//-------------------------------------------------------------- PlotSICN -// Draws a small icon (16 x 16 pixels). -/* -void PlotSICN (Rect *theRect, SICNHand theSICN, long theIndex) -{ - char state; - BitMap srcBits; - - if ((theSICN != nil) && - ((GetHandleSize((Handle)theSICN) / sizeof(SICN)) > theIndex)) - { - state = HGetState((Handle)theSICN); - HLock((Handle)theSICN); - - srcBits.baseAddr = (Ptr)(*theSICN)[theIndex]; - srcBits.rowBytes = 2; - SetRect(&srcBits.bounds, 0, 0, 16, 16); - - CopyBits(&srcBits,&(*qd.thePort).portBits, - &srcBits.bounds, theRect, srcCopy, nil); - - HSetState((Handle) theSICN, state); - } -} -*/ //-------------------------------------------------------------- LargeIconPlot // Draws a standard b&w icon (32 x 32) - resource is an 'ICON'. diff --git a/GpD3D/GpSystemServices_Win32.cpp b/GpD3D/GpSystemServices_Win32.cpp index a2e4153..4fb4dea 100644 --- a/GpD3D/GpSystemServices_Win32.cpp +++ b/GpD3D/GpSystemServices_Win32.cpp @@ -15,10 +15,23 @@ GpSystemServices_Win32::GpSystemServices_Win32() uint32_t GpSystemServices_Win32::GetTime() const { - // PL_NotYetImplemented + //PL_NotYetImplemented_TODO("Time"); return 0; } +void GpSystemServices_Win32::GetLocalDateTime(unsigned int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &second) const +{ + SYSTEMTIME localTime; + GetLocalTime(&localTime); + + year = localTime.wYear; + month = localTime.wMonth; + day = localTime.wDay; + hour = localTime.wHour; + minute = localTime.wMinute; + second = localTime.wSecond; +} + PortabilityLayer::HostMutex *GpSystemServices_Win32::CreateMutex() { return GpMutex_Win32::Create(); diff --git a/GpD3D/GpSystemServices_Win32.h b/GpD3D/GpSystemServices_Win32.h index 0abbdac..cb52809 100644 --- a/GpD3D/GpSystemServices_Win32.h +++ b/GpD3D/GpSystemServices_Win32.h @@ -16,6 +16,7 @@ public: GpSystemServices_Win32(); uint32_t GetTime() const override; + void GetLocalDateTime(unsigned int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &second) const override; PortabilityLayer::HostMutex *CreateMutex() override; PortabilityLayer::HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) override; diff --git a/PortabilityLayer/DisplayDeviceManager.cpp b/PortabilityLayer/DisplayDeviceManager.cpp index 4a3c1b8..829596f 100644 --- a/PortabilityLayer/DisplayDeviceManager.cpp +++ b/PortabilityLayer/DisplayDeviceManager.cpp @@ -1,7 +1,7 @@ #include "DisplayDeviceManager.h" #include "HostDisplayDriver.h" -#include "PLQuickdraw.h" +#include "PLQDraw.h" #include "MemoryManager.h" #include "QDStandardPalette.h" diff --git a/PortabilityLayer/HostSystemServices.h b/PortabilityLayer/HostSystemServices.h index 1063bcd..df779c0 100644 --- a/PortabilityLayer/HostSystemServices.h +++ b/PortabilityLayer/HostSystemServices.h @@ -17,6 +17,7 @@ namespace PortabilityLayer { public: virtual uint32_t GetTime() const = 0; + virtual void GetLocalDateTime(unsigned int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &second) const = 0; virtual HostMutex *CreateMutex() = 0; virtual HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) = 0; diff --git a/PortabilityLayer/IPlotter.h b/PortabilityLayer/IPlotter.h new file mode 100644 index 0000000..93143f7 --- /dev/null +++ b/PortabilityLayer/IPlotter.h @@ -0,0 +1,14 @@ +#pragma once + +#include "PlotDirection.h" + +namespace PortabilityLayer +{ + struct Vec2i; + + struct IPlotter + { + virtual PlotDirection PlotNext() = 0; + virtual const Vec2i &GetPoint() const = 0; + }; +} diff --git a/PortabilityLayer/LinePlotter.cpp b/PortabilityLayer/LinePlotter.cpp new file mode 100644 index 0000000..2ff2f7d --- /dev/null +++ b/PortabilityLayer/LinePlotter.cpp @@ -0,0 +1,101 @@ +#include "LinePlotter.h" +#include "Vec2i.h" + +#include + +namespace PortabilityLayer +{ + LinePlotter::LinePlotter() + : m_point(0, 0) + , m_endPoint(0, 0) + , m_dx(0) + , m_dy(0) + , m_err(0) + , m_xIncrPos(true) + , m_yIncrPos(true) + , m_xMove(PlotDirection_Exhausted) + , m_yMove(PlotDirection_Exhausted) + , m_xyMove(PlotDirection_Exhausted) + { + } + + PlotDirection LinePlotter::PlotNext() + { + if (m_point == m_endPoint) + return PlotDirection_Exhausted; + + bool movedX = false; + const int32_t err2 = 2 * m_err; + if (err2 >= m_dy) + { + m_err += m_dy; + m_point.m_x += m_xIncrPos ? 1 : -1; + movedX = true; + } + + if (err2 <= m_dx) + { + m_err += m_dx; + m_point.m_y += m_yIncrPos ? 1 : -1; + + if (movedX) + return m_xyMove; + else + return m_yMove; + } + else + { + assert(movedX); + return m_xMove; + } + } + + const Vec2i &LinePlotter::GetPoint() const + { + return m_point; + } + + void LinePlotter::Reset(const Vec2i &pointA, const Vec2i &pointB) + { + m_dx = pointB.m_x - pointA.m_x; + if (m_dx < 0) + m_dx = -m_dx; + + m_dy = pointB.m_y - pointA.m_y; + if (m_dy > 0) + m_dy = -m_dy; + + m_xIncrPos = (pointA.m_x < pointB.m_x); + m_yIncrPos = (pointA.m_y < pointB.m_y); + + m_err = m_dx + m_dy; + + m_point = pointA; + m_endPoint = pointB; + + if (m_xIncrPos) + { + if (m_yIncrPos) + m_xyMove = PlotDirection_PosX_PosY; + else + m_xyMove = PlotDirection_PosX_NegY; + + m_xMove = PlotDirection_PosX_0Y; + } + else + { + if (m_yIncrPos) + m_xyMove = PlotDirection_NegX_PosY; + else + m_xyMove = PlotDirection_NegX_NegY; + + m_xMove = PlotDirection_NegX_0Y; + } + + + if (m_yIncrPos) + m_yMove = PlotDirection_0X_PosY; + else + m_yMove = PlotDirection_0X_NegY; + } +} diff --git a/PortabilityLayer/LinePlotter.h b/PortabilityLayer/LinePlotter.h new file mode 100644 index 0000000..c0a4236 --- /dev/null +++ b/PortabilityLayer/LinePlotter.h @@ -0,0 +1,30 @@ +#pragma once + +#include "PlotDirection.h" +#include "Vec2i.h" + +namespace PortabilityLayer +{ + class LinePlotter + { + public: + LinePlotter(); + PlotDirection PlotNext(); + const Vec2i &GetPoint() const; + + void Reset(const Vec2i &pointA, const Vec2i &pointB); + + private: + Vec2i m_point; + Vec2i m_endPoint; + int32_t m_dx; + int32_t m_dy; + int32_t m_err; + bool m_xIncrPos; + bool m_yIncrPos; + + PlotDirection m_xyMove; + PlotDirection m_xMove; + PlotDirection m_yMove; + }; +} diff --git a/PortabilityLayer/PLCore.cpp b/PortabilityLayer/PLCore.cpp index cbd0ba1..ed538c8 100644 --- a/PortabilityLayer/PLCore.cpp +++ b/PortabilityLayer/PLCore.cpp @@ -2,7 +2,7 @@ #include "PLApplication.h" #include "PLPasStr.h" #include "PLKeyEncoding.h" -#include "PLQuickdraw.h" +#include "PLQDraw.h" #include "AEManager.h" #include "DisplayDeviceManager.h" @@ -901,10 +901,17 @@ void GetDateTime(UInt32 *dateTime) void GetTime(DateTimeRec *dateTime) { - PL_NotYetImplemented_TODO("DateTime"); - dateTime->month = 1; - dateTime->hour = 0; - dateTime->minute = 0; + unsigned int year; + unsigned int month; + unsigned int day; + unsigned int hour; + unsigned int minute; + unsigned int second; + PortabilityLayer::HostSystemServices::GetInstance()->GetLocalDateTime(year, month, day, hour, minute, second); + + dateTime->month = month; + dateTime->hour = hour; + dateTime->minute = minute; } UInt32 GetDblTime() @@ -955,22 +962,6 @@ long GetHandleSize(Handle handle) return static_cast(block->m_size); } -void HNoPurge(Handle hdl) -{ -} - -void MoveHHi(Handle hdl) -{ -} - -void HLock(Handle hdl) -{ -} - -void HUnlock(Handle hdl) -{ -} - OSErr PtrAndHand(const void *data, Handle handle, Size size) { PL_NotYetImplemented(); diff --git a/PortabilityLayer/PLCore.h b/PortabilityLayer/PLCore.h index 4a80ad1..0808c6c 100644 --- a/PortabilityLayer/PLCore.h +++ b/PortabilityLayer/PLCore.h @@ -369,11 +369,6 @@ Handle NewHandle(Size size); void DisposeHandle(Handle handle); long GetHandleSize(Handle handle); -void HNoPurge(Handle hdl); // Marks a handle as not purgeable -void MoveHHi(Handle hdl); // Relocates a block to the top of the heap -void HLock(Handle hdl); // Disable relocation -void HUnlock(Handle hdl); // Re-enable relocation - OSErr PtrAndHand(const void *data, Handle handle, Size size); // Appends data to the end of a handle void SetHandleSize(Handle hdl, Size newSize); @@ -384,9 +379,6 @@ void DisposePtr(void *ptr); Size MaxMem(Size *growBytes); void PurgeSpace(long *totalFree, long *contiguousFree); -void HSetState(Handle handle, char state); -char HGetState(Handle handle); - OSErr MemError(); void BlockMove(const void *src, void *dest, Size size); diff --git a/PortabilityLayer/PLQDOffscreen.h b/PortabilityLayer/PLQDOffscreen.h index 7b3839c..7552037 100644 --- a/PortabilityLayer/PLQDOffscreen.h +++ b/PortabilityLayer/PLQDOffscreen.h @@ -3,7 +3,7 @@ #define __PL_QDOFFSCREEN_H__ #include "PLCore.h" -#include "PLQuickdraw.h" +#include "PLQDraw.h" struct ColorTable { diff --git a/PortabilityLayer/PLQuickdraw.cpp b/PortabilityLayer/PLQDraw.cpp similarity index 99% rename from PortabilityLayer/PLQuickdraw.cpp rename to PortabilityLayer/PLQDraw.cpp index 139bad8..99e60af 100644 --- a/PortabilityLayer/PLQuickdraw.cpp +++ b/PortabilityLayer/PLQDraw.cpp @@ -1,4 +1,4 @@ -#include "PLQuickdraw.h" +#include "PLQDraw.h" #include "QDManager.h" #include "QDState.h" #include "DisplayDeviceManager.h" diff --git a/PortabilityLayer/PLQuickdraw.h b/PortabilityLayer/PLQDraw.h similarity index 100% rename from PortabilityLayer/PLQuickdraw.h rename to PortabilityLayer/PLQDraw.h diff --git a/PortabilityLayer/PlotDirection.h b/PortabilityLayer/PlotDirection.h new file mode 100644 index 0000000..3a30596 --- /dev/null +++ b/PortabilityLayer/PlotDirection.h @@ -0,0 +1,20 @@ +#pragma once + +namespace PortabilityLayer +{ + enum PlotDirection + { + PlotDirection_NegX_NegY, + PlotDirection_0X_NegY, + PlotDirection_PosX_NegY, + + PlotDirection_NegX_PosY, + PlotDirection_0X_PosY, + PlotDirection_PosX_PosY, + + PlotDirection_NegX_0Y, + PlotDirection_PosX_0Y, + + PlotDirection_Exhausted, + }; +} diff --git a/PortabilityLayer/PortabilityLayer.vcxproj b/PortabilityLayer/PortabilityLayer.vcxproj index d230dd9..a0605fc 100644 --- a/PortabilityLayer/PortabilityLayer.vcxproj +++ b/PortabilityLayer/PortabilityLayer.vcxproj @@ -163,6 +163,8 @@ + + @@ -194,6 +196,9 @@ + + + @@ -221,7 +226,7 @@ - + @@ -265,6 +270,7 @@ + @@ -286,11 +292,14 @@ - + + + + diff --git a/PortabilityLayer/PortabilityLayer.vcxproj.filters b/PortabilityLayer/PortabilityLayer.vcxproj.filters index 840f09a..6f3321b 100644 --- a/PortabilityLayer/PortabilityLayer.vcxproj.filters +++ b/PortabilityLayer/PortabilityLayer.vcxproj.filters @@ -90,9 +90,6 @@ Header Files - - Header Files - Header Files @@ -369,6 +366,24 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Source Files + @@ -398,9 +413,6 @@ Source Files - - Source Files - Source Files @@ -554,5 +566,20 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + \ No newline at end of file diff --git a/PortabilityLayer/QDPixMap.h b/PortabilityLayer/QDPixMap.h index b4efd15..9ade7f9 100644 --- a/PortabilityLayer/QDPixMap.h +++ b/PortabilityLayer/QDPixMap.h @@ -1,7 +1,7 @@ #pragma once #include "PLBigEndian.h" -#include "PLQuickdraw.h" +#include "PLQDraw.h" #include "GpPixelFormat.h" #include diff --git a/PortabilityLayer/QDState.cpp b/PortabilityLayer/QDState.cpp index 35a28c7..a68a321 100644 --- a/PortabilityLayer/QDState.cpp +++ b/PortabilityLayer/QDState.cpp @@ -1,10 +1,10 @@ #include "QDState.h" -#include "PLQuickdraw.h" -#include "QDStandardPalette.h" - -namespace PortabilityLayer -{ +#include "PLQDraw.h" +#include "QDStandardPalette.h" + +namespace PortabilityLayer +{ QDState::QDState() : m_fontID(applFont) , m_textSize(12) @@ -19,10 +19,10 @@ namespace PortabilityLayer , m_isBackResolved8(false) , m_clipRegion(nullptr) { - m_backUnresolvedColor.r = m_backUnresolvedColor.g = m_backUnresolvedColor.b = m_backUnresolvedColor.a = 255; + m_backUnresolvedColor.r = m_backUnresolvedColor.g = m_backUnresolvedColor.b = m_backUnresolvedColor.a = 255; m_foreUnresolvedColor.r = m_foreUnresolvedColor.g = m_foreUnresolvedColor.b = 0; m_foreUnresolvedColor.a = 255; - m_penPos.h = m_penPos.v = 0; + m_penPos.h = m_penPos.v = 0; } void QDState::SetForeColor(const RGBAColor &color) @@ -77,6 +77,6 @@ namespace PortabilityLayer cached = resolvedColor; return resolvedColor; - } + } } } diff --git a/PortabilityLayer/ScanlineMask.cpp b/PortabilityLayer/ScanlineMask.cpp new file mode 100644 index 0000000..bf6d223 --- /dev/null +++ b/PortabilityLayer/ScanlineMask.cpp @@ -0,0 +1,80 @@ +#include "CoreDefs.h" +#include "ScanlineMask.h" +#include "ScanlineMaskBuilder.h" + +#include +#include + +namespace PortabilityLayer +{ + void ScanlineMask::Destroy() + { + this->~ScanlineMask(); + free(this); + } + + ScanlineMask *ScanlineMask::Create(const ScanlineMaskBuilder &builder) + { + size_t alignedPrefixSize = sizeof(ScanlineMask) + PL_SYSTEM_MEMORY_ALIGNMENT - 1; + alignedPrefixSize -= alignedPrefixSize % PL_SYSTEM_MEMORY_ALIGNMENT; + + const size_t longestSpan = builder.GetLongestSpan(); + const size_t numSpans = builder.GetNumSpans(); + const size_t *spans = builder.GetSpans(); + + size_t storageSize = numSpans; + DataStorage dataStorage = DataStorage_UInt8; + if (longestSpan <= 0xff) + dataStorage = DataStorage_UInt8; + else if (longestSpan <= 0xffff) + { + storageSize *= 2; + dataStorage = DataStorage_UInt16; + } + else if (longestSpan <= 0xffffffff) + { + storageSize *= 4; + dataStorage = DataStorage_UInt32; + } + else + return nullptr; + + void *storage = malloc(alignedPrefixSize + storageSize); + if (!storage) + return nullptr; + + void *spanStorage = static_cast(storage) + alignedPrefixSize; + + ScanlineMask *mask = new (storage) ScanlineMask(dataStorage, spanStorage, numSpans); + + for (size_t i = 0; i < numSpans; i++) + { + switch (dataStorage) + { + case DataStorage_UInt8: + static_cast(spanStorage)[i] = static_cast(spans[i]); + break; + case DataStorage_UInt16: + static_cast(spanStorage)[i] = static_cast(spans[i]); + break; + case DataStorage_UInt32: + static_cast(spanStorage)[i] = static_cast(spans[i]); + break; + } + } + + return mask; + } + + ScanlineMask::ScanlineMask(DataStorage dataStorage, const void *data, size_t numSpans) + : m_dataStorage(dataStorage) + , m_data(data) + , m_numSpans(numSpans) + { + } + + ScanlineMask::~ScanlineMask() + { + } +} + diff --git a/PortabilityLayer/ScanlineMask.h b/PortabilityLayer/ScanlineMask.h new file mode 100644 index 0000000..2e088c6 --- /dev/null +++ b/PortabilityLayer/ScanlineMask.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +namespace PortabilityLayer +{ + class ScanlineMaskBuilder; + + class ScanlineMask + { + public: + void Destroy(); + + static ScanlineMask *Create(const ScanlineMaskBuilder &builder); + + private: + enum DataStorage + { + DataStorage_UInt8, + DataStorage_UInt16, + DataStorage_UInt32, + }; + + explicit ScanlineMask(DataStorage dataStorage, const void *data, size_t numSpans); + ~ScanlineMask(); + + const DataStorage m_dataStorage; + const void *m_data; + const size_t m_numSpans; + }; +} diff --git a/PortabilityLayer/ScanlineMaskBuilder.cpp b/PortabilityLayer/ScanlineMaskBuilder.cpp new file mode 100644 index 0000000..14db444 --- /dev/null +++ b/PortabilityLayer/ScanlineMaskBuilder.cpp @@ -0,0 +1,66 @@ +#include "ScanlineMaskBuilder.h" + +#include + +namespace PortabilityLayer +{ + ScanlineMaskBuilder::ScanlineMaskBuilder() + : m_spans(nullptr) + , m_numSpans(0) + , m_capacity(0) + , m_longestSpan(0) + { + } + + ScanlineMaskBuilder::~ScanlineMaskBuilder() + { + if (m_spans) + realloc(m_spans, 0); + } + + bool ScanlineMaskBuilder::AppendSpan(size_t span) + { + if (span > m_longestSpan) + m_longestSpan = span; + + if (m_capacity == 0) + { + m_capacity = 8; + m_spans = static_cast(realloc(nullptr, sizeof(size_t) * m_capacity)); + if (!m_spans) + return false; + } + + if (m_numSpans == m_capacity) + { + if (m_capacity >= (SIZE_MAX / sizeof(size_t) / 2)) + return false; + + m_capacity *= 2; + void *newSpans = realloc(m_spans, sizeof(size_t) * m_capacity); + if (!newSpans) + return false; + + m_spans = static_cast(newSpans); + } + + m_spans[m_numSpans++] = span; + + return true; + } + + size_t ScanlineMaskBuilder::GetLongestSpan() const + { + return m_longestSpan; + } + + const size_t *ScanlineMaskBuilder::GetSpans() const + { + return m_spans; + } + + size_t ScanlineMaskBuilder::GetNumSpans() const + { + return m_numSpans; + } +} diff --git a/PortabilityLayer/ScanlineMaskBuilder.h b/PortabilityLayer/ScanlineMaskBuilder.h new file mode 100644 index 0000000..744c07a --- /dev/null +++ b/PortabilityLayer/ScanlineMaskBuilder.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +namespace PortabilityLayer +{ + class ScanlineMaskBuilder + { + public: + ScanlineMaskBuilder(); + ~ScanlineMaskBuilder(); + + bool AppendSpan(size_t span); + + size_t GetLongestSpan() const; + const size_t *GetSpans() const; + size_t GetNumSpans() const; + + private: + size_t *m_spans; + size_t m_numSpans; + size_t m_capacity; + size_t m_longestSpan; + }; +} diff --git a/PortabilityLayer/ScanlineMaskConverter.cpp b/PortabilityLayer/ScanlineMaskConverter.cpp new file mode 100644 index 0000000..ec916ff --- /dev/null +++ b/PortabilityLayer/ScanlineMaskConverter.cpp @@ -0,0 +1,318 @@ +#include "ScanlineMaskConverter.h" +#include "ScanlineMask.h" +#include "Vec2i.h" +#include "LinePlotter.h" +#include "ScanlineMaskBuilder.h" +#include "IPlotter.h" + +#include +#include + +#define PL_SCANLINE_MASKS_DEBUGGING 1 + +#if PL_SCANLINE_MASKS_DEBUGGING +#include "stb_image_write.h" +#endif + +// The algorithm that we're trying to emulate consistently paints on covered pixels of a line as in-bounds, +// while also identifying which pixels are part of the poly interior. +// +// We use a plotting algorithm to generate an outline with some rules: +// - If a plot moves vertically in the same direction as the previous vertical movement, then the inversion bit for the pixel is flipped. +// - A scanline is then run across the row, toggling state between inversion points, and filling any that contain a plot point. + +namespace PortabilityLayer +{ + enum PlotterVertical + { + PlotterVertical_NegY, + PlotterVertical_PosY, + + PlotterVertical_None, + }; + + static void FillPresenceFlag(uint8_t *bitfield, size_t element) + { +#if PL_SCANLINE_MASKS_DEBUGGING + bitfield[element * 4] = 255; +#else + bitfield[element / 4] |= 1 << ((element & 3) * 2); +#endif + } + + static bool ReadPresenceFlag(const uint8_t *bitfield, size_t element) + { +#if PL_SCANLINE_MASKS_DEBUGGING + return bitfield[element * 4] == 255;; +#else + return (bitfield[element / 4] & (1 << ((element & 3) * 2))) != 0; +#endif + } + + static void FlipBorderFlag(uint8_t *bitfield, size_t element) + { +#if PL_SCANLINE_MASKS_DEBUGGING + bitfield[element * 4 + 1] ^= 255; +#else + bitfield[element / 4] ^= 2 << ((element & 3) * 2); +#endif + } + + static bool ReadBorderFlag(const uint8_t *bitfield, size_t element) + { +#if PL_SCANLINE_MASKS_DEBUGGING + return bitfield[element * 4 + 1] == 255; +#else + return (bitfield[element / 4] & (2 << ((element & 3) * 2))) != 0; +#endif + } + + static PlotterVertical VerticalForPlotDir(PlotDirection plotDir) + { + switch (plotDir) + { + case PlotDirection_NegX_NegY: + case PlotDirection_0X_NegY: + case PlotDirection_PosX_NegY: + return PlotterVertical_NegY; + case PlotDirection_NegX_PosY: + case PlotDirection_0X_PosY: + case PlotDirection_PosX_PosY: + return PlotterVertical_PosY; + default: + return PlotterVertical_None; + } + } + + static bool FlushScanline(const uint8_t *flagBits, size_t firstElement, size_t width, ScanlineMaskBuilder &maskBuilder) + { + size_t spanStart = 0; + bool isBorderToggleActive = false; + bool maskSpanState = false; + + for (size_t col = 0; col < width; col++) + { + const size_t element = firstElement + col; + + const bool presenceFlag = ReadPresenceFlag(flagBits, element); + const bool borderFlag = ReadBorderFlag(flagBits, element); + + if (borderFlag) + isBorderToggleActive = !isBorderToggleActive; + + const bool elementState = (isBorderToggleActive || presenceFlag); + + if (elementState != maskSpanState) + { + if (!maskBuilder.AppendSpan(col - spanStart)) + return false; + + spanStart = col; + maskSpanState = elementState; + } + } + + if (!maskBuilder.AppendSpan(width - spanStart)) + return false; + + return true; + } + + ScanlineMask *ComputePlot(uint32_t width, uint32_t height, const Vec2i &minPoint, IPlotter &plotter) + { + assert(width > 0 && height > 0); + + if (static_cast(width) * static_cast(height) > SIZE_MAX) + return nullptr; + + const size_t numElements = width * height; + +#if PL_SCANLINE_MASKS_DEBUGGING + const size_t storageSize = numElements * 4; +#else + const size_t storageSize = (numElements * 2 + 7) / 8; +#endif + void *storage = malloc(storageSize); + + if (!storage) + return nullptr; + + uint8_t *flagBits = static_cast(storage); + memset(flagBits, 0, storageSize); + +#if PL_SCANLINE_MASKS_DEBUGGING + { + for (size_t i = 0; i < storageSize; i += 4) + flagBits[i + 3] = 255; + } +#endif + + const Vec2i initialPoint = plotter.GetPoint() - minPoint; + + bool haveFirstVertical = false; + size_t firstVerticalElement = 0; // First element that contains a vertical movement on the first row + PlotterVertical firstVertical = PlotterVertical::PlotterVertical_None; + PlotterVertical lastVertical = PlotterVertical::PlotterVertical_None; + + size_t currentElement = static_cast(initialPoint.m_y) * width + static_cast(initialPoint.m_x); + FillPresenceFlag(flagBits, currentElement); + + for (;;) + { + const size_t prevElement = currentElement; + + const PlotDirection plotDir = plotter.PlotNext(); + if (plotDir == PlotDirection_Exhausted) + break; + + switch (plotDir) + { + case PlotDirection_NegX_NegY: + currentElement = currentElement - 1 - width; + break; + case PlotDirection_0X_NegY: + currentElement = currentElement - width; + break; + case PlotDirection_PosX_NegY: + currentElement = currentElement + 1 - width; + break; + + case PlotDirection_NegX_PosY: + currentElement = currentElement + width - 1; + break; + case PlotDirection_0X_PosY: + currentElement = currentElement + width; + break; + case PlotDirection_PosX_PosY: + currentElement = currentElement + width + 1; + break; + + case PlotDirection_NegX_0Y: + currentElement = currentElement - 1; + break; + case PlotDirection_PosX_0Y: + currentElement = currentElement + 1; + break; + default: + break; + } + + FillPresenceFlag(flagBits, currentElement); + +#if PL_SCANLINE_MASKS_DEBUGGING + const Vec2i expectedPoint = plotter.GetPoint() - minPoint; + const int64_t expectedElement = static_cast(expectedPoint.m_y) * width + expectedPoint.m_x; + assert(currentElement == expectedElement); +#endif + assert(currentElement < numElements); + + const PlotterVertical verticalForPlotDir = VerticalForPlotDir(plotDir); + if (verticalForPlotDir != PlotterVertical_None) + { + if (!haveFirstVertical) + { + haveFirstVertical = true; + firstVerticalElement = prevElement; + firstVertical = verticalForPlotDir; + } + + if (verticalForPlotDir == lastVertical) + FlipBorderFlag(flagBits, prevElement); + + lastVertical = verticalForPlotDir; + } + } + + if (lastVertical == firstVertical) + FlipBorderFlag(flagBits, firstVerticalElement); + + assert(plotter.GetPoint() - minPoint == initialPoint); + + ScanlineMaskBuilder maskBuilder; + + bool failed = false; + for (size_t rowFirstElement = 0; rowFirstElement < numElements; rowFirstElement += width) + { + if (!FlushScanline(flagBits, rowFirstElement, width, maskBuilder)) + { + failed = true; + break; + } + } + + free(storage); + + return ScanlineMask::Create(maskBuilder); + } + + class PolyPlotter final : public IPlotter + { + public: + PolyPlotter(const Vec2i *points, size_t numPoints); + + PlotDirection PlotNext() override; + const Vec2i &GetPoint() const override; + + private: + LinePlotter m_linePlotter; + const Vec2i *m_points; + size_t m_currentTargetPoint; + size_t m_numPoints; + }; + + PolyPlotter::PolyPlotter(const Vec2i *points, size_t numPoints) + : m_points(points) + , m_currentTargetPoint(0) + , m_numPoints(numPoints) + { + m_linePlotter.Reset(points[numPoints - 1], points[0]); + } + + PlotDirection PolyPlotter::PlotNext() + { + if (m_currentTargetPoint == m_numPoints) + return PlotDirection_Exhausted; + + for (;;) + { + const PlotDirection plotDir = m_linePlotter.PlotNext(); + if (plotDir == PlotDirection_Exhausted) + { + m_currentTargetPoint++; + if (m_currentTargetPoint == m_numPoints) + return PlotDirection_Exhausted; + + m_linePlotter.Reset(m_points[m_currentTargetPoint - 1], m_points[m_currentTargetPoint]); + } + else + return plotDir; + } + } + + const Vec2i &PolyPlotter::GetPoint() const + { + return m_linePlotter.GetPoint(); + } + + ScanlineMask *ScanlineMaskConverter::CompilePoly(const Vec2i *points, size_t numPoints) + { + assert(numPoints > 0); + + Vec2i minPoint = points[0]; + Vec2i maxPoint = points[0]; + + for (size_t i = 1; i < numPoints; i++) + { + minPoint.m_x = std::min(minPoint.m_x, points[i].m_x); + minPoint.m_y = std::min(minPoint.m_y, points[i].m_y); + maxPoint.m_x = std::max(maxPoint.m_x, points[i].m_x); + maxPoint.m_y = std::max(maxPoint.m_y, points[i].m_y); + } + + const uint32_t width = static_cast(maxPoint.m_x - minPoint.m_x) + 1; + const uint32_t height = static_cast(maxPoint.m_y - minPoint.m_y) + 1; + + PolyPlotter polyPlotter(points, numPoints); + return ComputePlot(width, height, minPoint, polyPlotter); + } +} diff --git a/PortabilityLayer/ScanlineMaskConverter.h b/PortabilityLayer/ScanlineMaskConverter.h new file mode 100644 index 0000000..d4bcc58 --- /dev/null +++ b/PortabilityLayer/ScanlineMaskConverter.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace PortabilityLayer +{ + class ScanlineMask; + struct Vec2i; + + class ScanlineMaskConverter + { + public: + static ScanlineMask *CompilePoly(const Vec2i *points, size_t numPoints); + }; +} diff --git a/PortabilityLayer/Vec2i.h b/PortabilityLayer/Vec2i.h index e0966fe..c021b84 100644 --- a/PortabilityLayer/Vec2i.h +++ b/PortabilityLayer/Vec2i.h @@ -17,7 +17,10 @@ namespace PortabilityLayer Vec2i operator-(const Vec2i &other) const; Vec2i &operator+=(const Vec2i &other); - Vec2i &operator-=(const Vec2i &other); + Vec2i &operator-=(const Vec2i &other); + + bool operator==(const Vec2i &other) const; + bool operator!=(const Vec2i &other) const; }; inline Vec2i::Vec2i() @@ -60,6 +63,15 @@ namespace PortabilityLayer m_x -= other.m_x; m_y -= other.m_y; return *this; + } + + inline bool Vec2i::operator==(const Vec2i &other) const + { + return m_x == other.m_x && m_y == other.m_y; + } + + inline bool Vec2i::operator!=(const Vec2i &other) const + { + return !((*this) == other); } } -