Cleanup, add scanline mask builder

This commit is contained in:
elasota
2019-12-26 12:58:58 -05:00
parent b10dda4a54
commit c4e93b0ccf
61 changed files with 823 additions and 494 deletions

View File

@@ -131,9 +131,6 @@ void InitAnimatedCursor (acurHandle ballCursH)
if (!compiledBallCursorH) if (!compiledBallCursorH)
RedAlert(kErrFailedResourceLoad); RedAlert(kErrFailedResourceLoad);
HNoPurge((Handle)ballCursH);
MoveHHi((Handle)ballCursH);
HLock((Handle)ballCursH);
if (useColor) if (useColor)
useColor = GetColorCursors(ballCursH, compiledBallCursorH); useColor = GetColorCursors(ballCursH, compiledBallCursorH);
if (!useColor && !GetMonoCursors(ballCursH, compiledBallCursorH)) if (!useColor && !GetMonoCursors(ballCursH, compiledBallCursorH))

View File

@@ -90,12 +90,9 @@ void DrawBanner (Point *topLeft)
short CountStarsInHouse (void) short CountStarsInHouse (void)
{ {
short i, h, numRooms, numStars; short i, h, numRooms, numStars;
char wasState;
numStars = 0; numStars = 0;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
@@ -106,7 +103,6 @@ short CountStarsInHouse (void)
numStars++; numStars++;
} }
} }
HSetState((Handle)thisHouse, wasState);
return (numStars); return (numStars);
} }
@@ -119,12 +115,8 @@ void DrawBannerMessage (Point topLeft)
{ {
Str255 bannerStr, subStr; Str255 bannerStr, subStr;
short count; short count;
char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
PasStringCopy((*thisHouse)->banner, bannerStr); PasStringCopy((*thisHouse)->banner, bannerStr);
HSetState((Handle)thisHouse, wasState);
TextFont(applFont); TextFont(applFont);
TextFace(bold); TextFace(bold);

View File

@@ -143,11 +143,7 @@ void GetDialogRect (Rect *bounds, short dialogID)
dlogHandle = (DialogTHndl)GetResource('DLOG', dialogID); dlogHandle = (DialogTHndl)GetResource('DLOG', dialogID);
if (dlogHandle != nil) if (dlogHandle != nil)
{ {
wasState = HGetState((Handle)dlogHandle);
HLock((Handle)dlogHandle);
*bounds = (**dlogHandle).boundsRect; *bounds = (**dlogHandle).boundsRect;
HSetState((Handle)dlogHandle, wasState);
} }
} }

View File

@@ -5,7 +5,7 @@
//============================================================================ //============================================================================
#include "PLQuickdraw.h" #include "PLQDraw.h"
typedef struct typedef struct

View File

@@ -9,7 +9,7 @@
#include "PLAppleEvents.h" #include "PLAppleEvents.h"
#include "PLKeyEncoding.h" #include "PLKeyEncoding.h"
#include "PLToolUtils.h" #include "PLToolUtils.h"
#include "PLQuickdraw.h" #include "PLQDraw.h"
#include "Externs.h" #include "Externs.h"
#include "Environ.h" #include "Environ.h"
#include "House.h" #include "House.h"

View File

@@ -91,10 +91,7 @@ void SetUpFinalScreen (void)
if (textDown < 0) if (textDown < 0)
textDown = 0; textDown = 0;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
PasStringCopy((*thisHouse)->trailer, tempStr); PasStringCopy((*thisHouse)->trailer, tempStr);
HSetState((Handle)thisHouse, wasState);
count = 0; count = 0;
do do

View File

@@ -150,8 +150,6 @@ void DrawHighScores (void)
TextFace(bold); TextFace(bold);
TextSize(12); TextSize(12);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
// message for score #1 // message for score #1
PasStringCopy(thisHousePtr->highScores.banner, tempStr); PasStringCopy(thisHousePtr->highScores.banner, tempStr);
@@ -273,7 +271,6 @@ void DrawHighScores (void)
DrawString(tempStr); DrawString(tempStr);
ForeColor(blackColor); ForeColor(blackColor);
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- SortHighScores //-------------------------------------------------------------- SortHighScores
@@ -287,8 +284,6 @@ void SortHighScores (void)
short i, h, which; short i, h, which;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
for (h = 0; h < kMaxScores; h++) for (h = 0; h < kMaxScores; h++)
@@ -314,8 +309,6 @@ void SortHighScores (void)
} }
PasStringCopy(thisHousePtr->highScores.banner, tempScores.banner); PasStringCopy(thisHousePtr->highScores.banner, tempScores.banner);
thisHousePtr->highScores = tempScores; thisHousePtr->highScores = tempScores;
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- ZeroHighScores //-------------------------------------------------------------- ZeroHighScores
@@ -327,8 +320,6 @@ void ZeroHighScores (void)
short i; short i;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
PasStringCopy(thisHouseName, thisHousePtr->highScores.banner); PasStringCopy(thisHouseName, thisHousePtr->highScores.banner);
@@ -339,8 +330,6 @@ void ZeroHighScores (void)
thisHousePtr->highScores.timeStamps[i] = 0L; thisHousePtr->highScores.timeStamps[i] = 0L;
thisHousePtr->highScores.levels[i] = 0; thisHousePtr->highScores.levels[i] = 0;
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- ZeroAllButHighestScore //-------------------------------------------------------------- ZeroAllButHighestScore
@@ -352,8 +341,6 @@ void ZeroAllButHighestScore (void)
short i; short i;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
for (i = 1; i < kMaxScores; i++) for (i = 1; i < kMaxScores; i++)
@@ -363,8 +350,6 @@ void ZeroAllButHighestScore (void)
thisHousePtr->highScores.timeStamps[i] = 0L; thisHousePtr->highScores.timeStamps[i] = 0L;
thisHousePtr->highScores.levels[i] = 0; thisHousePtr->highScores.levels[i] = 0;
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- TestHighScore //-------------------------------------------------------------- TestHighScore
@@ -381,8 +366,6 @@ Boolean TestHighScore (void)
if (resumedSavedGame) if (resumedSavedGame)
return (false); return (false);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
lastHighScore = -1; lastHighScore = -1;
@@ -415,8 +398,6 @@ Boolean TestHighScore (void)
gameDirty = true; gameDirty = true;
} }
HSetState((Handle)thisHouse, wasState);
if (placing != -1) if (placing != -1)
{ {
DoHighScores(); DoHighScores();
@@ -770,18 +751,14 @@ Boolean WriteScoresToDisk (void)
} }
byteCount = sizeof(scoresType); byteCount = sizeof(scoresType);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
theScores = &((*thisHouse)->highScores); theScores = &((*thisHouse)->highScores);
theErr = FSWrite(scoresRefNum, &byteCount, (Ptr)theScores); theErr = FSWrite(scoresRefNum, &byteCount, (Ptr)theScores);
if (!CheckFileError(theErr, PSTR("High Scores File"))) if (!CheckFileError(theErr, PSTR("High Scores File")))
{ {
HSetState((Handle)thisHouse, wasState);
theErr = FSClose(scoresRefNum); theErr = FSClose(scoresRefNum);
return(false); return(false);
} }
HSetState((Handle)thisHouse, wasState);
theErr = SetEOF(scoresRefNum, byteCount); theErr = SetEOF(scoresRefNum, byteCount);
if (!CheckFileError(theErr, PSTR("High Scores File"))) if (!CheckFileError(theErr, PSTR("High Scores File")))
@@ -835,18 +812,14 @@ Boolean ReadScoresFromDisk (void)
return (false); return (false);
} }
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
theScores = &((*thisHouse)->highScores); theScores = &((*thisHouse)->highScores);
theErr = FSRead(scoresRefNum, &byteCount, theScores); theErr = FSRead(scoresRefNum, &byteCount, theScores);
if (!CheckFileError(theErr, PSTR("High Scores File"))) if (!CheckFileError(theErr, PSTR("High Scores File")))
{ {
HSetState((Handle)thisHouse, wasState);
theErr = FSClose(scoresRefNum); theErr = FSClose(scoresRefNum);
return (false); return (false);
} }
HSetState((Handle)thisHouse, wasState);
theErr = FSClose(scoresRefNum); theErr = FSClose(scoresRefNum);
if (!CheckFileError(theErr, PSTR("High Scores File"))) if (!CheckFileError(theErr, PSTR("High Scores File")))

View File

@@ -123,7 +123,6 @@ Boolean InitializeEmptyHouse (void)
return (false); return (false);
} }
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
thisHousePtr->version = kHouseVersion; thisHousePtr->version = kHouseVersion;
@@ -144,8 +143,6 @@ Boolean InitializeEmptyHouse (void)
wardBitSet = false; wardBitSet = false;
phoneBitSet = false; phoneBitSet = false;
HUnlock((Handle)thisHouse);
numberRooms = 0; numberRooms = 0;
mapLeftRoom = 60; mapLeftRoom = 60;
mapTopRoom = 50; mapTopRoom = 50;
@@ -174,8 +171,6 @@ short RealRoomNumberCount (void)
short realRoomCount, i; short realRoomCount, i;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
realRoomCount = (*thisHouse)->nRooms; realRoomCount = (*thisHouse)->nRooms;
if (realRoomCount != 0) if (realRoomCount != 0)
{ {
@@ -185,7 +180,6 @@ short RealRoomNumberCount (void)
realRoomCount--; realRoomCount--;
} }
} }
HSetState((Handle)thisHouse, wasState);
return (realRoomCount); return (realRoomCount);
} }
@@ -200,8 +194,6 @@ short GetFirstRoomNumber (void)
short firstRoom; short firstRoom;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
if ((*thisHouse)->nRooms <= 0) if ((*thisHouse)->nRooms <= 0)
{ {
firstRoom = -1; firstRoom = -1;
@@ -213,7 +205,6 @@ short GetFirstRoomNumber (void)
if ((firstRoom >= (*thisHouse)->nRooms) || (firstRoom < 0)) if ((firstRoom >= (*thisHouse)->nRooms) || (firstRoom < 0))
firstRoom = 0; firstRoom = 0;
} }
HSetState((Handle)thisHouse, wasState);
return (firstRoom); return (firstRoom);
} }
@@ -228,15 +219,11 @@ void WhereDoesGliderBegin (Rect *theRect, short mode)
Point initialPt; Point initialPt;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
if (mode == kResumeGameMode) if (mode == kResumeGameMode)
initialPt = smallGame.where; initialPt = smallGame.where;
else if (mode == kNewGameMode) else if (mode == kNewGameMode)
initialPt = (*thisHouse)->initial; initialPt = (*thisHouse)->initial;
HSetState((Handle)thisHouse, wasState);
QSetRect(theRect, 0, 0, kGliderWide, kGliderHigh); QSetRect(theRect, 0, 0, kGliderWide, kGliderHigh);
QOffsetRect(theRect, initialPt.h, initialPt.v); QOffsetRect(theRect, initialPt.h, initialPt.v);
} }
@@ -266,8 +253,6 @@ short CountHouseLinks (void)
numLinks = 0; numLinks = 0;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
numRooms = thisHousePtr->nRooms; numRooms = thisHousePtr->nRooms;
@@ -303,8 +288,6 @@ short CountHouseLinks (void)
} }
} }
HSetState((Handle)thisHouse, wasState);
return (numLinks); return (numLinks);
} }
@@ -324,8 +307,6 @@ void GenerateLinksList (void)
short floor, suite, roomLinked, objectLinked; short floor, suite, roomLinked, objectLinked;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
numRooms = thisHousePtr->nRooms; numRooms = thisHousePtr->nRooms;
@@ -382,8 +363,6 @@ void GenerateLinksList (void)
} }
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
#endif #endif
@@ -468,8 +447,6 @@ void SortHouseObjects (void)
GenerateLinksList(); GenerateLinksList();
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
numRooms = thisHousePtr->nRooms; numRooms = thisHousePtr->nRooms;
@@ -498,7 +475,6 @@ void SortHouseObjects (void)
} }
SpinCursor(3); SpinCursor(3);
HSetState((Handle)thisHouse, wasState);
if (linksList != nil) if (linksList != nil)
DisposePtr((Ptr)linksList); DisposePtr((Ptr)linksList);
ForceThisRoom(thisRoomNumber); ForceThisRoom(thisRoomNumber);
@@ -516,8 +492,6 @@ short CountRoomsVisited (void)
short numRooms, r, count; short numRooms, r, count;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
numRooms = thisHousePtr->nRooms; numRooms = thisHousePtr->nRooms;
count = 0; count = 0;
@@ -528,7 +502,6 @@ short CountRoomsVisited (void)
count++; count++;
} }
HSetState((Handle)thisHouse, wasState);
return (count); return (count);
} }
@@ -548,8 +521,6 @@ void GenerateRetroLinks (void)
for (i = 0; i < kMaxRoomObs; i++) // Initialize array. for (i = 0; i < kMaxRoomObs; i++) // Initialize array.
retroLinkList[i].room = -1; retroLinkList[i].room = -1;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
numRooms = thisHousePtr->nRooms; numRooms = thisHousePtr->nRooms;
@@ -610,8 +581,6 @@ void GenerateRetroLinks (void)
} }
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- UpdateGoToDialog //-------------------------------------------------------------- UpdateGoToDialog
@@ -759,9 +728,6 @@ void ConvertHouseVer1To2 (void)
SpinCursor(3); SpinCursor(3);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
@@ -814,7 +780,6 @@ void ConvertHouseVer1To2 (void)
} }
(*thisHouse)->version = kHouseVersion; (*thisHouse)->version = kHouseVersion;
HSetState((Handle)thisHouse, wasState);
InitCursor(); InitCursor();
CloseMessageWindow(); CloseMessageWindow();
@@ -834,8 +799,6 @@ void ShiftWholeHouse (short howFar)
CopyThisRoomToRoom(); CopyThisRoomToRoom();
wasRoom = thisRoomNumber; wasRoom = thisRoomNumber;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
@@ -852,7 +815,6 @@ void ShiftWholeHouse (short howFar)
} }
} }
HSetState((Handle)thisHouse, wasState);
ForceThisRoom(wasRoom); ForceThisRoom(wasRoom);
InitCursor(); InitCursor();

View File

@@ -662,7 +662,6 @@ Boolean ReadHouse (void)
YellowAlert(kYellowNoMemory, 10); YellowAlert(kYellowNoMemory, 10);
return(false); return(false);
} }
MoveHHi((Handle)thisHouse);
theErr = SetFPos(houseRefNum, fsFromStart, 0L); theErr = SetFPos(houseRefNum, fsFromStart, 0L);
if (theErr != noErr) if (theErr != noErr)
@@ -671,13 +670,11 @@ Boolean ReadHouse (void)
return(false); return(false);
} }
HLock((Handle)thisHouse);
long readByteCount = byteCount; long readByteCount = byteCount;
theErr = FSRead(houseRefNum, &readByteCount, *thisHouse); theErr = FSRead(houseRefNum, &readByteCount, *thisHouse);
if (theErr != noErr || readByteCount != byteCount || byteCount < static_cast<long>(houseType::kBinaryDataSize)) if (theErr != noErr || readByteCount != byteCount || byteCount < static_cast<long>(houseType::kBinaryDataSize))
{ {
CheckFileError(theErr, thisHouseName); CheckFileError(theErr, thisHouseName);
HUnlock((Handle)thisHouse);
return(false); return(false);
} }
@@ -702,7 +699,6 @@ Boolean ReadHouse (void)
numberRooms = 0; numberRooms = 0;
noRoomAtAll = true; noRoomAtAll = true;
YellowAlert(kYellowNoRooms, 0); YellowAlert(kYellowNoRooms, 0);
HUnlock((Handle)thisHouse);
return(false); return(false);
} }
@@ -710,7 +706,6 @@ Boolean ReadHouse (void)
if (wasHouseVersion >= kNewHouseVersion) if (wasHouseVersion >= kNewHouseVersion)
{ {
YellowAlert(kYellowNewerVersion, 0); YellowAlert(kYellowNewerVersion, 0);
HUnlock((Handle)thisHouse);
return(false); return(false);
} }
@@ -732,8 +727,6 @@ Boolean ReadHouse (void)
phoneBitSet = (((*thisHouse)->flags & 0x00000002) == 0x00000002); phoneBitSet = (((*thisHouse)->flags & 0x00000002) == 0x00000002);
bannerStarCountOn = (((*thisHouse)->flags & 0x00000004) == 0x00000000); bannerStarCountOn = (((*thisHouse)->flags & 0x00000004) == 0x00000000);
HUnlock((Handle)thisHouse);
noRoomAtAll = (RealRoomNumberCount() == 0); noRoomAtAll = (RealRoomNumberCount() == 0);
thisRoomNumber = -1; thisRoomNumber = -1;
previousRoom = -1; previousRoom = -1;
@@ -786,7 +779,6 @@ Boolean WriteHouse (Boolean checkIt)
if (checkIt) if (checkIt)
CheckHouseForProblems(); CheckHouseForProblems();
HLock((Handle)thisHouse);
byteCount = GetHandleSize((Handle)thisHouse); byteCount = GetHandleSize((Handle)thisHouse);
if (fileDirty) if (fileDirty)
@@ -815,7 +807,6 @@ Boolean WriteHouse (Boolean checkIt)
{ {
CheckFileError(theErr, thisHouseName); CheckFileError(theErr, thisHouseName);
ByteSwapHouse(*thisHouse, static_cast<size_t>(byteCount)); ByteSwapHouse(*thisHouse, static_cast<size_t>(byteCount));
HUnlock((Handle)thisHouse);
return(false); return(false);
} }
@@ -824,7 +815,6 @@ Boolean WriteHouse (Boolean checkIt)
{ {
CheckFileError(theErr, thisHouseName); CheckFileError(theErr, thisHouseName);
ByteSwapHouse(*thisHouse, static_cast<size_t>(byteCount)); ByteSwapHouse(*thisHouse, static_cast<size_t>(byteCount));
HUnlock((Handle)thisHouse);
return(false); return(false);
} }
@@ -834,12 +824,9 @@ Boolean WriteHouse (Boolean checkIt)
if (theErr != noErr) if (theErr != noErr)
{ {
CheckFileError(theErr, thisHouseName); CheckFileError(theErr, thisHouseName);
HUnlock((Handle)thisHouse);
return(false); return(false);
} }
HUnlock((Handle)thisHouse);
if (changeLockStateOfHouse) if (changeLockStateOfHouse)
{ {
changeLockStateOfHouse = false; changeLockStateOfHouse = false;

View File

@@ -57,9 +57,6 @@ long CountTotalHousePoints (void)
pointTotal = (long)RealRoomNumberCount() * (long)kRoomVisitScore; pointTotal = (long)RealRoomNumberCount() * (long)kRoomVisitScore;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
@@ -100,8 +97,6 @@ long CountTotalHousePoints (void)
} }
} }
HSetState((Handle)thisHouse, wasState);
return (pointTotal); return (pointTotal);
} }
@@ -218,9 +213,7 @@ void DoHouseInfo (void)
houseFilterUPP = NewModalFilterUPP(HouseFilter); houseFilterUPP = NewModalFilterUPP(HouseFilter);
tempPhoneBit = phoneBitSet; tempPhoneBit = phoneBitSet;
wasState = HGetState((Handle)thisHouse);
numRooms = RealRoomNumberCount(); numRooms = RealRoomNumberCount();
HLock((Handle)thisHouse);
PasStringCopy((*thisHouse)->banner, banner); PasStringCopy((*thisHouse)->banner, banner);
PasStringCopy((*thisHouse)->trailer, trailer); PasStringCopy((*thisHouse)->trailer, trailer);
version = (*thisHouse)->version; version = (*thisHouse)->version;
@@ -229,7 +222,6 @@ void DoHouseInfo (void)
h = (long)(*thisHouse)->rooms[(*thisHouse)->firstRoom].suite; h = (long)(*thisHouse)->rooms[(*thisHouse)->firstRoom].suite;
v = (long)(*thisHouse)->rooms[(*thisHouse)->firstRoom].floor; v = (long)(*thisHouse)->rooms[(*thisHouse)->firstRoom].floor;
} }
HSetState((Handle)thisHouse, wasState);
NumToString((long)version >> 8, versStr); // Convert version to two strings<67> NumToString((long)version >> 8, versStr); // Convert version to two strings<67>
NumToString((long)version % 0x0100, loVers); // the 1's and 1/10th's part. 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, kBannerTextItem, banner);
GetDialogString(houseInfoDialog, kTrailerTextItem, trailer); GetDialogString(houseInfoDialog, kTrailerTextItem, trailer);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
PasStringCopyNum(banner, (*thisHouse)->banner, 255); PasStringCopyNum(banner, (*thisHouse)->banner, 255);
PasStringCopyNum(trailer, (*thisHouse)->trailer, 255); PasStringCopyNum(trailer, (*thisHouse)->trailer, 255);
if (tempPhoneBit != phoneBitSet) if (tempPhoneBit != phoneBitSet)
@@ -273,7 +263,6 @@ void DoHouseInfo (void)
else else
(*thisHouse)->flags = (*thisHouse)->flags & 0xFFFFDFFD; (*thisHouse)->flags = (*thisHouse)->flags & 0xFFFFDFFD;
} }
HSetState((Handle)thisHouse, wasState);
fileDirty = true; fileDirty = true;
UpdateMenus(false); UpdateMenus(false);

View File

@@ -54,8 +54,6 @@ Boolean KeepObjectLegal (void)
if (objActive == kInitialGliderSelected) if (objActive == kInitialGliderSelected)
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
if ((*thisHouse)->initial.h < 0) if ((*thisHouse)->initial.h < 0)
(*thisHouse)->initial.h = 0; (*thisHouse)->initial.h = 0;
if ((*thisHouse)->initial.v < 0) if ((*thisHouse)->initial.v < 0)
@@ -64,7 +62,6 @@ Boolean KeepObjectLegal (void)
(*thisHouse)->initial.h = kRoomWide - kGliderWide; (*thisHouse)->initial.h = kRoomWide - kGliderWide;
if ((*thisHouse)->initial.v > (kTileHigh - kGliderHigh)) if ((*thisHouse)->initial.v > (kTileHigh - kGliderHigh))
(*thisHouse)->initial.v = kTileHigh - kGliderHigh; (*thisHouse)->initial.v = kTileHigh - kGliderHigh;
HSetState((Handle)thisHouse, wasState);
return (true); return (true);
} }
@@ -605,13 +602,8 @@ void WrapBannerAndTrailer (void)
{ {
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
WrapText((*thisHouse)->banner, 40); WrapText((*thisHouse)->banner, 40);
WrapText((*thisHouse)->trailer, 64); WrapText((*thisHouse)->trailer, 64);
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- ValidateNumberOfRooms //-------------------------------------------------------------- ValidateNumberOfRooms
@@ -623,9 +615,6 @@ void ValidateNumberOfRooms (void)
long countedRooms, reportsRooms; long countedRooms, reportsRooms;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
reportsRooms = (long)(*thisHouse)->nRooms; reportsRooms = (long)(*thisHouse)->nRooms;
countedRooms = (GetHandleSize((Handle)thisHouse) - countedRooms = (GetHandleSize((Handle)thisHouse) -
sizeof(houseType)) / sizeof(roomType); sizeof(houseType)) / sizeof(roomType);
@@ -635,8 +624,6 @@ void ValidateNumberOfRooms (void)
numberRooms = (*thisHouse)->nRooms; numberRooms = (*thisHouse)->nRooms;
houseErrors++; houseErrors++;
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- CheckDuplicateFloorSuite //-------------------------------------------------------------- CheckDuplicateFloorSuite
@@ -654,9 +641,6 @@ void CheckDuplicateFloorSuite (void)
if (pidgeonHoles == nil) if (pidgeonHoles == nil)
return; return;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
@@ -676,8 +660,6 @@ void CheckDuplicateFloorSuite (void)
} }
} }
HSetState((Handle)thisHouse, wasState);
DisposePtr((Ptr)pidgeonHoles); DisposePtr((Ptr)pidgeonHoles);
} }
@@ -691,9 +673,6 @@ void CompressHouse (void)
char wasState; char wasState;
Boolean compressing, probing; Boolean compressing, probing;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
wasFirstRoom = (*thisHouse)->firstRoom; wasFirstRoom = (*thisHouse)->firstRoom;
compressing = true; compressing = true;
roomNumber = (*thisHouse)->nRooms - 1; // start with last room roomNumber = (*thisHouse)->nRooms - 1; // start with last room
@@ -729,8 +708,6 @@ void CompressHouse (void)
compressing = false; compressing = false;
} }
while (compressing); while (compressing);
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- LopOffExtraRooms //-------------------------------------------------------------- LopOffExtraRooms
@@ -744,9 +721,6 @@ void LopOffExtraRooms (void)
char wasState; char wasState;
Str255 message; Str255 message;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
count = 0; count = 0;
r = (*thisHouse)->nRooms; // begin at last room r = (*thisHouse)->nRooms; // begin at last room
do do
@@ -763,19 +737,16 @@ void LopOffExtraRooms (void)
{ {
r = (*thisHouse)->nRooms - count; r = (*thisHouse)->nRooms - count;
newSize = sizeof(houseType) + (sizeof(roomType) * (long)r); newSize = sizeof(houseType) + (sizeof(roomType) * (long)r);
HUnlock((Handle)thisHouse); // resize house handle (shrink) SetHandleSize((Handle)thisHouse, newSize); // resize house handle (shrink)
SetHandleSize((Handle)thisHouse, newSize);
if (MemError() != noErr) // problem? if (MemError() != noErr) // problem?
{ {
ForeColor(redColor); ForeColor(redColor);
GetLocalizedString(16, message); GetLocalizedString(16, message);
SetMessageWindowMessage(message); SetMessageWindowMessage(message);
} }
HLock((Handle)thisHouse); // reflect new room count
(*thisHouse)->nRooms -= count; (*thisHouse)->nRooms -= count;
numberRooms = (*thisHouse)->nRooms; numberRooms = (*thisHouse)->nRooms;
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- ValidateRoomNumbers //-------------------------------------------------------------- ValidateRoomNumbers
@@ -788,9 +759,6 @@ void ValidateRoomNumbers (void)
char wasState; char wasState;
Str255 message; Str255 message;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
if (numRooms < 0) if (numRooms < 0)
{ {
@@ -823,8 +791,6 @@ void ValidateRoomNumbers (void)
} }
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- CountUntitledRooms //-------------------------------------------------------------- CountUntitledRooms
@@ -836,9 +802,6 @@ void CountUntitledRooms (void)
short i, numRooms; short i, numRooms;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
@@ -846,8 +809,6 @@ void CountUntitledRooms (void)
(EqualString((*thisHouse)->rooms[i].name, PSTR("Untitled Room"), false, true))) (EqualString((*thisHouse)->rooms[i].name, PSTR("Untitled Room"), false, true)))
houseErrors++; houseErrors++;
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- CheckRoomNameLength //-------------------------------------------------------------- CheckRoomNameLength
@@ -859,9 +820,6 @@ void CheckRoomNameLength (void)
short i, numRooms; short i, numRooms;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
@@ -874,8 +832,6 @@ void CheckRoomNameLength (void)
houseErrors++; houseErrors++;
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- MakeSureNumObjectsJives //-------------------------------------------------------------- MakeSureNumObjectsJives
@@ -887,9 +843,6 @@ void MakeSureNumObjectsJives (void)
short i, h, numRooms, count; short i, h, numRooms, count;
char wasState; char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
@@ -908,8 +861,6 @@ void MakeSureNumObjectsJives (void)
} }
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- KeepAllObjectsLegal //-------------------------------------------------------------- KeepAllObjectsLegal
@@ -922,9 +873,6 @@ void KeepAllObjectsLegal (void)
char wasState; char wasState;
Str255 message; Str255 message;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
@@ -950,8 +898,6 @@ void KeepAllObjectsLegal (void)
CopyThisRoomToRoom(); CopyThisRoomToRoom();
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- CheckForStaircasePairs //-------------------------------------------------------------- CheckForStaircasePairs
@@ -965,9 +911,6 @@ void CheckForStaircasePairs (void)
Boolean hasStairs; Boolean hasStairs;
Str255 message; Str255 message;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
numRooms = (*thisHouse)->nRooms; numRooms = (*thisHouse)->nRooms;
for (i = 0; i < numRooms; i++) for (i = 0; i < numRooms; i++)
{ {
@@ -1040,8 +983,6 @@ void CheckForStaircasePairs (void)
} }
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
#endif #endif

View File

@@ -83,25 +83,21 @@ void GetExtraCursors (void)
handCursorH = GetCursor(kHandCursorID); handCursorH = GetCursor(kHandCursorID);
if (handCursorH == nil) if (handCursorH == nil)
RedAlert(kErrFailedResourceLoad); RedAlert(kErrFailedResourceLoad);
HLock((Handle)handCursorH);
handCursor = **handCursorH; handCursor = **handCursorH;
vertCursorH = GetCursor(kVertCursorID); vertCursorH = GetCursor(kVertCursorID);
if (vertCursorH == nil) if (vertCursorH == nil)
RedAlert(kErrFailedResourceLoad); RedAlert(kErrFailedResourceLoad);
HLock((Handle)vertCursorH);
vertCursor = **vertCursorH; vertCursor = **vertCursorH;
horiCursorH = GetCursor(kHoriCursorID); horiCursorH = GetCursor(kHoriCursorID);
if (horiCursorH == nil) if (horiCursorH == nil)
RedAlert(kErrFailedResourceLoad); RedAlert(kErrFailedResourceLoad);
HLock((Handle)horiCursorH);
horiCursor = **horiCursorH; horiCursor = **horiCursorH;
diagCursorH = GetCursor(kDiagCursorID); diagCursorH = GetCursor(kDiagCursorID);
if (diagCursorH == nil) if (diagCursorH == nil)
RedAlert(kErrFailedResourceLoad); RedAlert(kErrFailedResourceLoad);
HLock((Handle)diagCursorH);
diagCursor = **diagCursorH; diagCursor = **diagCursorH;
} }

View File

@@ -295,8 +295,6 @@ void DoLink (void)
} }
else else
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
if (linkerIsSwitch) if (linkerIsSwitch)
{ {
(*thisHouse)->rooms[linkRoom].objects[linkObject].data.e.where = (*thisHouse)->rooms[linkRoom].objects[linkObject].data.e.where =
@@ -311,7 +309,6 @@ void DoLink (void)
(*thisHouse)->rooms[linkRoom].objects[linkObject].data.d.who = (*thisHouse)->rooms[linkRoom].objects[linkObject].data.d.who =
objActive; objActive;
} }
HSetState((Handle)thisHouse, wasState);
} }
fileDirty = true; fileDirty = true;
UpdateMenus(false); UpdateMenus(false);
@@ -342,8 +339,6 @@ void DoUnlink (void)
} }
else else
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
if (linkerIsSwitch) if (linkerIsSwitch)
{ {
(*thisHouse)->rooms[linkRoom].objects[linkObject].data.e.where = -1; (*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.where = -1;
(*thisHouse)->rooms[linkRoom].objects[linkObject].data.d.who = 255; (*thisHouse)->rooms[linkRoom].objects[linkObject].data.d.who = 255;
} }
HSetState((Handle)thisHouse, wasState);
} }
fileDirty = true; fileDirty = true;
UpdateMenus(false); UpdateMenus(false);

View File

@@ -126,9 +126,6 @@ void FindNewActiveRoomRect (void)
activeRoomVisible = false; activeRoomVisible = false;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
for (i = 0; i < mapRoomsHigh; i++) for (i = 0; i < mapRoomsHigh; i++)
{ {
for (h = 0; h < mapRoomsWide; h++) for (h = 0; h < mapRoomsWide; h++)
@@ -150,8 +147,6 @@ void FindNewActiveRoomRect (void)
} }
} }
HSetState((Handle)thisHouse, wasState);
if (activeRoomVisible) if (activeRoomVisible)
{ {
activeRoomRect.right++; activeRoomRect.right++;
@@ -211,9 +206,6 @@ void RedrawMapContents (void)
ClipRect(&newClip); ClipRect(&newClip);
} }
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
for (i = 0; i < mapRoomsHigh; i++) for (i = 0; i < mapRoomsHigh; i++)
{ {
for (h = 0; h < mapRoomsWide; h++) for (h = 0; h < mapRoomsWide; h++)
@@ -266,8 +258,6 @@ void RedrawMapContents (void)
} }
} }
HSetState((Handle)thisHouse, wasState);
ForeColor(blackColor); ForeColor(blackColor);
PenNormal(); PenNormal();

View File

@@ -8,7 +8,7 @@
#pragma once #pragma once
#include "PLQuickdraw.h" #include "PLQDraw.h"
typedef struct typedef struct

View File

@@ -723,12 +723,10 @@ short QueryResumeGame (void)
resumeFilterUPP = NewModalFilterUPP(ResumeFilter); resumeFilterUPP = NewModalFilterUPP(ResumeFilter);
wasState = HGetState((Handle)thisHouse); // get score & num. gliders // get score & num. gliders
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
hadPoints = thisHousePtr->savedGame.score; hadPoints = thisHousePtr->savedGame.score;
hadGliders = thisHousePtr->savedGame.numGliders; hadGliders = thisHousePtr->savedGame.numGliders;
HSetState((Handle)thisHouse, wasState);
NumToString(hadPoints, scoreStr); // param text strings NumToString(hadPoints, scoreStr); // param text strings
NumToString((long)hadGliders, glidStr); NumToString((long)hadGliders, glidStr);
if (hadGliders == 1) if (hadGliders == 1)

View File

@@ -165,10 +165,7 @@ void StartGliderMailingIn (gliderPtr thisGlider, Rect *bounds, hotPtr who)
objLinked = masterObjects[whoLinked].objectLink; objLinked = masterObjects[whoLinked].objectLink;
linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked); linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect); GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect);
HSetState((Handle)thisHouse, wasState);
thisGlider->frame = 0; thisGlider->frame = 0;
thisGlider->clip = *bounds; thisGlider->clip = *bounds;
@@ -228,10 +225,7 @@ void StartGliderDuctingDown (gliderPtr thisGlider, Rect *bounds, hotPtr who)
objLinked = masterObjects[whoLinked].objectLink; objLinked = masterObjects[whoLinked].objectLink;
linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked); linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect); GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect);
HSetState((Handle)thisHouse, wasState);
thisGlider->frame = 0; thisGlider->frame = 0;
thisGlider->clip = *bounds; thisGlider->clip = *bounds;
@@ -261,10 +255,7 @@ void StartGliderDuctingUp (gliderPtr thisGlider, Rect *bounds, hotPtr who)
objLinked = masterObjects[whoLinked].objectLink; objLinked = masterObjects[whoLinked].objectLink;
linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked); linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect); GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect);
HSetState((Handle)thisHouse, wasState);
thisGlider->frame = 0; thisGlider->frame = 0;
thisGlider->clip = *bounds; thisGlider->clip = *bounds;
@@ -303,10 +294,7 @@ void StartGliderTransporting (gliderPtr thisGlider, hotPtr who)
objLinked = masterObjects[whoLinked].objectLink; objLinked = masterObjects[whoLinked].objectLink;
linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked); linkedToWhat = WhatAreWeLinkedTo(transRoom, objLinked);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect); GetObjectRect(&(*thisHouse)->rooms[transRoom].objects[objLinked], &transRect);
HSetState((Handle)thisHouse, wasState);
thisGlider->dest.right = thisGlider->dest.left + kGliderWide; thisGlider->dest.right = thisGlider->dest.left + kGliderWide;
thisGlider->dest.bottom = thisGlider->dest.top + kGliderHigh; thisGlider->dest.bottom = thisGlider->dest.top + kGliderHigh;

View File

@@ -233,15 +233,12 @@ OSErr LoadMusicSounds (void)
if (theSound == nil) if (theSound == nil)
return (MemError()); return (MemError());
HLock(theSound);
soundDataSize = GetHandleSize(theSound) - 20L; soundDataSize = GetHandleSize(theSound) - 20L;
HUnlock(theSound);
theMusicData[i] = NewPtr(soundDataSize); theMusicData[i] = NewPtr(soundDataSize);
if (theMusicData[i] == nil) if (theMusicData[i] == nil)
return (MemError()); return (MemError());
HLock(theSound);
BlockMove((Ptr)(static_cast<Byte*>(*theSound) + 20L), theMusicData[i], soundDataSize); BlockMove((Ptr)(static_cast<Byte*>(*theSound) + 20L), theMusicData[i], soundDataSize);
ReleaseResource(theSound); ReleaseResource(theSound);
} }

View File

@@ -829,8 +829,6 @@ short FindObjectSlotInRoom (short roomNumber)
emptySlot = -1; emptySlot = -1;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNumber]); testRoomPtr = &((*thisHouse)->rooms[roomNumber]);
for (i = 0; i < kMaxRoomObs; i++) for (i = 0; i < kMaxRoomObs; i++)
@@ -840,9 +838,6 @@ short FindObjectSlotInRoom (short roomNumber)
break; break;
} }
HSetState((Handle)thisHouse, wasState);
return (emptySlot); return (emptySlot);
} }
@@ -855,8 +850,6 @@ Boolean DoesRoomNumHaveObject (short room, short what)
char wasState; char wasState;
Boolean hasIt; Boolean hasIt;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[room]); testRoomPtr = &((*thisHouse)->rooms[room]);
hasIt = false; hasIt = false;
@@ -868,9 +861,6 @@ Boolean DoesRoomNumHaveObject (short room, short what)
break; break;
} }
HSetState((Handle)thisHouse, wasState);
return (hasIt); return (hasIt);
} }

View File

@@ -11,6 +11,9 @@
#include "Objects.h" #include "Objects.h"
#include "RectUtils.h" #include "RectUtils.h"
#include "Room.h" #include "Room.h"
#include "Vec2i.h"
#include "ScanlineMask.h"
#include "ScanlineMaskConverter.h"
#define k8WhiteColor 0 #define k8WhiteColor 0
@@ -293,16 +296,20 @@ void DrawShelf (Rect *shelfTop)
GetGWorld(&wasCPort, &wasWorld); GetGWorld(&wasCPort, &wasWorld);
SetGWorld(backSrcMap, nil); SetGWorld(backSrcMap, nil);
MoveTo(shelfTop->left, shelfTop->bottom);
shadowRgn = NewRgn(); shadowRgn = NewRgn();
if (shadowRgn == nil) if (shadowRgn == nil)
RedAlert(kErrUnnaccounted); 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(); OpenRgn();
Line(kShelfShadowOff, kShelfShadowOff);
Line(RectWide(shelfTop) - kShelfDeep, 0);
Line(0, -kShelfThick + 1);
Line(-kShelfShadowOff, -kShelfShadowOff);
LineTo(shelfTop->left, shelfTop->bottom);
CloseRgn(shadowRgn); CloseRgn(shadowRgn);
PenPat(GetQDGlobalsGray(&dummyPattern)); PenPat(GetQDGlobalsGray(&dummyPattern));
PenMode(patOr); PenMode(patOr);
@@ -312,7 +319,9 @@ void DrawShelf (Rect *shelfTop)
ColorRegion(shadowRgn, k8DkstGrayColor); ColorRegion(shadowRgn, k8DkstGrayColor);
PenNormal(); PenNormal();
DisposeRgn(shadowRgn); DisposeRgn(shadowRgn);
//mask->Destroy();
MoveTo(shelfTop->left, shelfTop->bottom);
InsetRect(shelfTop, 0, 1); InsetRect(shelfTop, 0, 1);
ColorRect(shelfTop, brownC); ColorRect(shelfTop, brownC);
InsetRect(shelfTop, 0, -1); InsetRect(shelfTop, 0, -1);

View File

@@ -1146,9 +1146,7 @@ void DrawCalendar (Rect *theRect)
if (thePicture == nil) if (thePicture == nil)
RedAlert(kErrFailedGraphicLoad); RedAlert(kErrFailedGraphicLoad);
HLock((Handle)thePicture);
bounds = (*thePicture)->picFrame.ToRect(); bounds = (*thePicture)->picFrame.ToRect();
HUnlock((Handle)thePicture);
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, theRect->left, theRect->top); QOffsetRect(&bounds, theRect->left, theRect->top);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
@@ -1182,9 +1180,7 @@ void DrawBulletin (Rect *theRect)
if (thePicture == nil) if (thePicture == nil)
RedAlert(kErrFailedGraphicLoad); RedAlert(kErrFailedGraphicLoad);
HLock((Handle)thePicture);
bounds = (*thePicture)->picFrame.ToRect(); bounds = (*thePicture)->picFrame.ToRect();
HUnlock((Handle)thePicture);
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, theRect->left, theRect->top); QOffsetRect(&bounds, theRect->left, theRect->top);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);

View File

@@ -37,9 +37,6 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
ZeroRectCorner(&testRect); ZeroRectCorner(&testRect);
isLit = (numLights > 0); isLit = (numLights > 0);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
for (i = 0; i < kMaxRoomObs; i++) for (i = 0; i < kMaxRoomObs; i++)
{ {
dynamicNum = -1; dynamicNum = -1;
@@ -960,7 +957,5 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
} }
} }
} }
HSetState((Handle)thisHouse, wasState);
} }

View File

@@ -529,11 +529,8 @@ void DragObject (Point where)
if (objActive == kInitialGliderSelected) if (objActive == kInitialGliderSelected)
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
(*thisHouse)->initial.h += deltaH; (*thisHouse)->initial.h += deltaH;
(*thisHouse)->initial.v += deltaV; (*thisHouse)->initial.v += deltaV;
HSetState((Handle)thisHouse, wasState);
} }
else if (objActive == kLeftGliderSelected) else if (objActive == kLeftGliderSelected)
{ {
@@ -805,8 +802,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorExLf))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorExLf)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kDoorExLf; testRoomPtr->objects[emptySlot].what = kDoorExLf;
@@ -818,7 +813,6 @@ void AddObjectPairing (void)
testRoomPtr->objects[emptySlot].data.d.wide = 0; testRoomPtr->objects[emptySlot].data.d.wide = 0;
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
@@ -839,8 +833,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorExRt))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorExRt)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kDoorExRt; testRoomPtr->objects[emptySlot].what = kDoorExRt;
@@ -853,8 +845,6 @@ void AddObjectPairing (void)
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
ForeColor(blueColor); ForeColor(blueColor);
@@ -874,8 +864,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorInLfLeft))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorInLfLeft)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kDoorInLf; testRoomPtr->objects[emptySlot].what = kDoorInLf;
@@ -888,8 +876,6 @@ void AddObjectPairing (void)
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
ForeColor(blueColor); ForeColor(blueColor);
@@ -909,8 +895,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorInRtLeft))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDoorInRtLeft)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kDoorInRt; testRoomPtr->objects[emptySlot].what = kDoorInRt;
@@ -923,8 +907,6 @@ void AddObjectPairing (void)
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
ForeColor(blueColor); ForeColor(blueColor);
@@ -944,8 +926,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowExRt))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowExRt)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kWindowExRt; testRoomPtr->objects[emptySlot].what = kWindowExRt;
@@ -958,8 +938,6 @@ void AddObjectPairing (void)
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
ForeColor(blueColor); ForeColor(blueColor);
@@ -979,8 +957,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowExLf))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowExLf)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kWindowExLf; testRoomPtr->objects[emptySlot].what = kWindowExLf;
@@ -993,8 +969,6 @@ void AddObjectPairing (void)
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
ForeColor(blueColor); ForeColor(blueColor);
@@ -1014,8 +988,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowInLf))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowInLf)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kWindowInLf; testRoomPtr->objects[emptySlot].what = kWindowInLf;
@@ -1028,8 +1000,6 @@ void AddObjectPairing (void)
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
ForeColor(blueColor); ForeColor(blueColor);
@@ -1049,8 +1019,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowInRt))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kWindowInRt)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kWindowInRt; testRoomPtr->objects[emptySlot].what = kWindowInRt;
@@ -1063,8 +1031,6 @@ void AddObjectPairing (void)
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
ForeColor(blueColor); ForeColor(blueColor);
@@ -1084,8 +1050,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDownStairs))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kDownStairs)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kDownStairs; testRoomPtr->objects[emptySlot].what = kDownStairs;
@@ -1099,8 +1063,6 @@ void AddObjectPairing (void)
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
ForeColor(blueColor); ForeColor(blueColor);
@@ -1120,8 +1082,6 @@ void AddObjectPairing (void)
emptySlot = FindObjectSlotInRoom(roomNum); emptySlot = FindObjectSlotInRoom(roomNum);
if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kUpStairs))) if ((emptySlot != -1) && (!DoesRoomNumHaveObject(roomNum, kUpStairs)))
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
testRoomPtr = &((*thisHouse)->rooms[roomNum]); testRoomPtr = &((*thisHouse)->rooms[roomNum]);
testRoomPtr->objects[emptySlot].what = kUpStairs; testRoomPtr->objects[emptySlot].what = kUpStairs;
@@ -1135,8 +1095,6 @@ void AddObjectPairing (void)
testRoomPtr->numObjects++; testRoomPtr->numObjects++;
HSetState((Handle)thisHouse, wasState);
GetLocalizedString(45, message); GetLocalizedString(45, message);
OpenMessageWindow(message); OpenMessageWindow(message);
ForeColor(blueColor); ForeColor(blueColor);
@@ -1486,11 +1444,8 @@ void MoveObject (short whichWay, Boolean shiftDown)
if (objActive == kInitialGliderSelected) if (objActive == kInitialGliderSelected)
{ {
wasRect = initialGliderRect; wasRect = initialGliderRect;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
(*thisHouse)->initial.h += deltaH; (*thisHouse)->initial.h += deltaH;
(*thisHouse)->initial.v += deltaV; (*thisHouse)->initial.v += deltaV;
HSetState((Handle)thisHouse, wasState);
} }
else if (objActive == kLeftGliderSelected) else if (objActive == kLeftGliderSelected)
{ {
@@ -2288,9 +2243,7 @@ void GetThisRoomsObjRects (void)
} }
else else
{ {
HLock((Handle)thePict);
roomObjectRects[i] = (*thePict)->picFrame.ToRect(); roomObjectRects[i] = (*thePict)->picFrame.ToRect();
HUnlock((Handle)thePict);
} }
ZeroRectCorner(&roomObjectRects[i]); ZeroRectCorner(&roomObjectRects[i]);
QOffsetRect(&roomObjectRects[i], QOffsetRect(&roomObjectRects[i],

View File

@@ -8,7 +8,7 @@
#pragma once #pragma once
#include "PLQuickdraw.h" #include "PLQDraw.h"
extern Rect roomObjectRects[]; extern Rect roomObjectRects[];

View File

@@ -226,9 +226,7 @@ void GetObjectRect (objectPtr who, Rect *itsRect)
} }
else else
{ {
HLock((Handle)thePict);
*itsRect = (*thePict)->picFrame.ToRect(); *itsRect = (*thePict)->picFrame.ToRect();
HUnlock((Handle)thePict);
} }
ZeroRectCorner(itsRect); ZeroRectCorner(itsRect);
QOffsetRect(itsRect, QOffsetRect(itsRect,
@@ -1140,9 +1138,6 @@ short GetUpStairsRightEdge (void)
rightEdge = kRoomWide; rightEdge = kRoomWide;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
for (i = 0; i < kMaxRoomObs; i++) for (i = 0; i < kMaxRoomObs; i++)
{ {
thisObject = (*thisHouse)->rooms[thisRoomNumber].objects[i]; thisObject = (*thisHouse)->rooms[thisRoomNumber].objects[i];
@@ -1153,8 +1148,6 @@ short GetUpStairsRightEdge (void)
} }
} }
HSetState((Handle)thisHouse, wasState);
return (rightEdge); return (rightEdge);
} }
@@ -1168,9 +1161,6 @@ short GetDownStairsLeftEdge (void)
leftEdge = 0; leftEdge = 0;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
for (i = 0; i < kMaxRoomObs; i++) for (i = 0; i < kMaxRoomObs; i++)
{ {
thisObject = (*thisHouse)->rooms[thisRoomNumber].objects[i]; thisObject = (*thisHouse)->rooms[thisRoomNumber].objects[i];
@@ -1181,8 +1171,6 @@ short GetDownStairsLeftEdge (void)
} }
} }
HSetState((Handle)thisHouse, wasState);
return (leftEdge); return (leftEdge);
} }

View File

@@ -93,8 +93,6 @@ Boolean IsThisValid (short where, short who)
itsGood = true; itsGood = true;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
switch ((*thisHouse)->rooms[where].objects[who].what) switch ((*thisHouse)->rooms[where].objects[who].what)
{ {
case kObjectIsEmpty: case kObjectIsEmpty:
@@ -116,7 +114,6 @@ Boolean IsThisValid (short where, short who)
itsGood = (*thisHouse)->rooms[where].objects[who].data.c.state; itsGood = (*thisHouse)->rooms[where].objects[who].data.c.state;
break; break;
} }
HSetState((Handle)thisHouse, wasState);
return (itsGood); return (itsGood);
} }
@@ -261,8 +258,6 @@ void ListOneRoomsObjects (short where)
if (roomNum == kRoomIsEmpty) if (roomNum == kRoomIsEmpty)
return; return;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
for (n = 0; n < kMaxRoomObs; n++) for (n = 0; n < kMaxRoomObs; n++)
{ {
if (numMasterObjects < kMaxMasterObjects) if (numMasterObjects < kMaxMasterObjects)
@@ -292,7 +287,6 @@ void ListOneRoomsObjects (short where)
numLocalMasterObjects++; numLocalMasterObjects++;
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- ListAllLocalObjects //-------------------------------------------------------------- ListAllLocalObjects
@@ -306,9 +300,6 @@ void ListAllLocalObjects (void)
numLocalMasterObjects = 0; numLocalMasterObjects = 0;
nHotSpots = 0; nHotSpots = 0;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
ListOneRoomsObjects(kCentralRoom); ListOneRoomsObjects(kCentralRoom);
if (numNeighbors > 1) if (numNeighbors > 1)
@@ -327,8 +318,6 @@ void ListAllLocalObjects (void)
ListOneRoomsObjects(kNorthWestRoom); ListOneRoomsObjects(kNorthWestRoom);
} }
HSetState((Handle)thisHouse, wasState);
for (i = 0; i < numMasterObjects; i++) // correlate links with<74> for (i = 0; i < numMasterObjects; i++) // correlate links with<74>
{ // index into this list { // index into this list
if ((masterObjects[i].roomLink != -1) && // if object has a link 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; char wasState;
Boolean changed; Boolean changed;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
switch ((*thisHouse)->rooms[room].objects[object].what) switch ((*thisHouse)->rooms[room].objects[object].what)
{ {
case kFloorVent: case kFloorVent:
@@ -693,7 +680,6 @@ Boolean SetObjectState (short room, short object, short action, short local)
break; break;
} }
HSetState((Handle)thisHouse, wasState);
return (changed); return (changed);
} }
@@ -707,8 +693,6 @@ Boolean GetObjectState (short room, short object)
theState = true; theState = true;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
switch ((*thisHouse)->rooms[room].objects[object].what) switch ((*thisHouse)->rooms[room].objects[object].what)
{ {
case kFloorVent: case kFloorVent:
@@ -864,8 +848,6 @@ Boolean GetObjectState (short room, short object)
case kChimes: case kChimes:
break; break;
} }
HSetState((Handle)thisHouse, wasState);
return (theState); return (theState);
} }
@@ -909,8 +891,6 @@ void BringSendFrontBack (Boolean bringFront)
GenerateLinksList(); // Fill in links list with src/dest<73> GenerateLinksList(); // Fill in links list with src/dest<73>
} // data on objects and room numbers. } // data on objects and room numbers.
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse); // Lock down house.
thisHousePtr = *thisHouse; // Get a pointer to house structure. thisHousePtr = *thisHouse; // Get a pointer to house structure.
for (i = 0; i < kMaxRoomObs; i++) // Set up an ordered array. 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) if (linksList != nil)
DisposePtr((Ptr)linksList); DisposePtr((Ptr)linksList);

View File

@@ -528,9 +528,7 @@ void PlayGame (void)
thePicture = GetPicture(kScoreboardPictID); thePicture = GetPicture(kScoreboardPictID);
if (!thePicture) if (!thePicture)
RedAlert(kErrFailedGraphicLoad); RedAlert(kErrFailedGraphicLoad);
HLock((Handle)thePicture);
bounds = (*thePicture)->picFrame.ToRect(); bounds = (*thePicture)->picFrame.ToRect();
HUnlock((Handle)thePicture);
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, hOffset, 0); QOffsetRect(&bounds, hOffset, 0);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
@@ -579,9 +577,7 @@ void PlayGame (void)
thePicture = GetPicture(kScoreboardPictID); thePicture = GetPicture(kScoreboardPictID);
if (!thePicture) if (!thePicture)
RedAlert(kErrFailedGraphicLoad); RedAlert(kErrFailedGraphicLoad);
HLock((Handle)thePicture);
bounds = (*thePicture)->picFrame.ToRect(); bounds = (*thePicture)->picFrame.ToRect();
HUnlock((Handle)thePicture);
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, hOffset, 0); QOffsetRect(&bounds, hOffset, 0);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
@@ -605,8 +601,6 @@ void SetObjectsToDefaults (void)
char wasState; char wasState;
Boolean initState; Boolean initState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
numRooms = thisHousePtr->nRooms; numRooms = thisHousePtr->nRooms;
@@ -701,7 +695,6 @@ void SetObjectsToDefaults (void)
} }
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- HideGlider //-------------------------------------------------------------- HideGlider

View File

@@ -8,7 +8,7 @@
#pragma once #pragma once
#include "PLQuickdraw.h" #include "PLQDraw.h"
void FrameWHRect (short, short, short, short); void FrameWHRect (short, short, short, short);

View File

@@ -182,9 +182,6 @@ Boolean CreateNewRoom (short h, short v)
for (i = 0; i < kMaxRoomObs; i++) // zero out all objects for (i = 0; i < kMaxRoomObs; i++) // zero out all objects
thisRoom->objects[i].what = kObjectIsEmpty; thisRoom->objects[i].what = kObjectIsEmpty;
wasState = HGetState((Handle)thisHouse);
MoveHHi((Handle)thisHouse);
HLock((Handle)thisHouse);
availableRoom = -1; // assume no available rooms availableRoom = -1; // assume no available rooms
if ((*thisHouse)->nRooms > 0) // look for an empty room if ((*thisHouse)->nRooms > 0) // look for an empty room
for (i = 0; i < (*thisHouse)->nRooms; i++) for (i = 0; i < (*thisHouse)->nRooms; i++)
@@ -196,18 +193,13 @@ Boolean CreateNewRoom (short h, short v)
if (availableRoom == -1) // found no available rooms if (availableRoom == -1) // found no available rooms
{ {
HUnlock((Handle)thisHouse);
howMuch = sizeof(roomType); // add new room to end of house howMuch = sizeof(roomType); // add new room to end of house
theErr = PtrAndHand((Ptr)thisRoom, (Handle)thisHouse, howMuch); theErr = PtrAndHand((Ptr)thisRoom, (Handle)thisHouse, howMuch);
if (theErr != noErr) if (theErr != noErr)
{ {
YellowAlert(kYellowUnaccounted, theErr); YellowAlert(kYellowUnaccounted, theErr);
MoveHHi((Handle)thisHouse);
HLock((Handle)thisHouse);
return (false); return (false);
} }
MoveHHi((Handle)thisHouse);
HLock((Handle)thisHouse);
(*thisHouse)->nRooms++; // increment nRooms (*thisHouse)->nRooms++; // increment nRooms
numberRooms = (*thisHouse)->nRooms; numberRooms = (*thisHouse)->nRooms;
previousRoom = thisRoomNumber; previousRoom = thisRoomNumber;
@@ -222,8 +214,6 @@ Boolean CreateNewRoom (short h, short v)
if (noRoomAtAll) if (noRoomAtAll)
(*thisHouse)->firstRoom = thisRoomNumber; (*thisHouse)->firstRoom = thisRoomNumber;
HSetState((Handle)thisHouse, wasState);
CopyThisRoomToRoom(); CopyThisRoomToRoom();
UpdateEditWindowTitle(); UpdateEditWindowTitle();
noRoomAtAll = false; noRoomAtAll = false;
@@ -278,9 +268,7 @@ void ReadyBackground (short theID, short *theTiles)
} }
} }
HLock((Handle)thePicture);
dest = (*thePicture)->picFrame.ToRect(); dest = (*thePicture)->picFrame.ToRect();
HUnlock((Handle)thePicture);
QOffsetRect(&dest, -dest.left, -dest.top); QOffsetRect(&dest, -dest.left, -dest.top);
DrawPicture(thePicture, &dest); DrawPicture(thePicture, &dest);
ReleaseResource((Handle)thePicture); ReleaseResource((Handle)thePicture);
@@ -359,10 +347,7 @@ void CopyThisRoomToRoom (void)
if ((noRoomAtAll) || (thisRoomNumber == -1)) if ((noRoomAtAll) || (thisRoomNumber == -1))
return; return;
tagByte = HGetState((Handle)thisHouse); (*thisHouse)->rooms[thisRoomNumber] = *thisRoom; // copy back to house
HLock((Handle)thisHouse); // copy back to house
(*thisHouse)->rooms[thisRoomNumber] = *thisRoom;
HSetState((Handle)thisHouse, tagByte);
} }
//-------------------------------------------------------------- ForceThisRoom //-------------------------------------------------------------- ForceThisRoom
@@ -374,13 +359,10 @@ void ForceThisRoom (short roomNumber)
if (roomNumber == -1) if (roomNumber == -1)
return; return;
tagByte = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
if (roomNumber < (*thisHouse)->nRooms) if (roomNumber < (*thisHouse)->nRooms)
*thisRoom = (*thisHouse)->rooms[roomNumber]; *thisRoom = (*thisHouse)->rooms[roomNumber];
else else
YellowAlert(kYellowIllegalRoomNum, 0); YellowAlert(kYellowIllegalRoomNum, 0);
HSetState((Handle)thisHouse, tagByte);
previousRoom = thisRoomNumber; previousRoom = thisRoomNumber;
thisRoomNumber = roomNumber; thisRoomNumber = roomNumber;
@@ -401,8 +383,6 @@ Boolean RoomExists (short suite, short floor, short *roomNum)
if (suite < 0) if (suite < 0)
return (foundIt); return (foundIt);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
for (i = 0; i < numberRooms; i++) for (i = 0; i < numberRooms; i++)
@@ -416,8 +396,6 @@ Boolean RoomExists (short suite, short floor, short *roomNum)
} }
} }
HSetState((Handle)thisHouse, wasState);
return (foundIt); return (foundIt);
} }
@@ -455,14 +433,11 @@ void DeleteRoom (Boolean doWarn)
DeselectObject(); DeselectObject();
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
wasFloor = (*thisHouse)->rooms[thisRoomNumber].floor; wasFloor = (*thisHouse)->rooms[thisRoomNumber].floor;
wasSuite = (*thisHouse)->rooms[thisRoomNumber].suite; wasSuite = (*thisHouse)->rooms[thisRoomNumber].suite;
firstDeleted = ((*thisHouse)->firstRoom == thisRoomNumber); // is room "first" firstDeleted = ((*thisHouse)->firstRoom == thisRoomNumber); // is room "first"
thisRoom->suite = kRoomIsEmpty; thisRoom->suite = kRoomIsEmpty;
(*thisHouse)->rooms[thisRoomNumber].suite = kRoomIsEmpty; (*thisHouse)->rooms[thisRoomNumber].suite = kRoomIsEmpty;
HSetState((Handle)thisHouse, wasState);
noRoomAtAll = (RealRoomNumberCount() == 0); // see if now no rooms noRoomAtAll = (RealRoomNumberCount() == 0); // see if now no rooms
if (noRoomAtAll) if (noRoomAtAll)
@@ -472,10 +447,7 @@ void DeleteRoom (Boolean doWarn)
if (firstDeleted) if (firstDeleted)
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
(*thisHouse)->firstRoom = thisRoomNumber; (*thisHouse)->firstRoom = thisRoomNumber;
HSetState((Handle)thisHouse, wasState);
} }
newRoomNow = false; newRoomNow = false;
@@ -616,8 +588,6 @@ short GetNeighborRoomNumber (short which)
} }
roomNum = kRoomIsEmpty; roomNum = kRoomIsEmpty;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
roomH = (*thisHouse)->rooms[thisRoomNumber].suite + hDelta; roomH = (*thisHouse)->rooms[thisRoomNumber].suite + hDelta;
roomV = (*thisHouse)->rooms[thisRoomNumber].floor + vDelta; roomV = (*thisHouse)->rooms[thisRoomNumber].floor + vDelta;
@@ -630,7 +600,6 @@ short GetNeighborRoomNumber (short which)
break; break;
} }
} }
HSetState((Handle)thisHouse, wasState);
return (roomNum); return (roomNum);
} }
@@ -647,9 +616,6 @@ void SetToNearestNeighborRoom (short wasFloor, short wasSuite)
char wasState; char wasState;
Boolean finished; Boolean finished;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
finished = false; finished = false;
distance = 1; // we begin our walk a distance of one from source room distance = 1; // we begin our walk a distance of one from source room
h = -1; // we begin with the neighbor to the left<66> h = -1; // we begin with the neighbor to the left<66>
@@ -703,8 +669,6 @@ void SetToNearestNeighborRoom (short wasFloor, short wasSuite)
} }
} }
} while (!finished); } while (!finished);
HSetState((Handle)thisHouse, wasState);
} }
//-------------------------------------------------------------- GetRoomFloorSuite //-------------------------------------------------------------- GetRoomFloorSuite
@@ -714,8 +678,6 @@ Boolean GetRoomFloorSuite (short room, short *floor, short *suite)
char wasState; char wasState;
Boolean isRoom; Boolean isRoom;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
if ((*thisHouse)->rooms[room].suite == kRoomIsEmpty) if ((*thisHouse)->rooms[room].suite == kRoomIsEmpty)
{ {
*floor = 0; *floor = 0;
@@ -728,7 +690,6 @@ Boolean GetRoomFloorSuite (short room, short *floor, short *suite)
*floor = (*thisHouse)->rooms[room].floor; *floor = (*thisHouse)->rooms[room].floor;
isRoom = true; isRoom = true;
} }
HSetState((Handle)thisHouse, wasState);
return (isRoom); return (isRoom);
} }
@@ -743,8 +704,6 @@ short GetRoomNumber (short floor, short suite)
roomNum = kRoomIsEmpty; roomNum = kRoomIsEmpty;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
for (i = 0; i < numberRooms; i++) for (i = 0; i < numberRooms; i++)
{ {
if (((*thisHouse)->rooms[i].suite == suite) && if (((*thisHouse)->rooms[i].suite == suite) &&
@@ -754,7 +713,6 @@ short GetRoomNumber (short floor, short suite)
break; break;
} }
} }
HSetState((Handle)thisHouse, wasState);
return (roomNum); return (roomNum);
} }
@@ -769,8 +727,6 @@ Boolean IsRoomAStructure (short roomNum)
if (roomNum == kRoomIsEmpty) if (roomNum == kRoomIsEmpty)
return (false); return (false);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
if ((*thisHouse)->rooms[roomNum].background >= kUserBackground) if ((*thisHouse)->rooms[roomNum].background >= kUserBackground)
{ {
if ((*thisHouse)->rooms[roomNum].bounds != 0) if ((*thisHouse)->rooms[roomNum].bounds != 0)
@@ -807,7 +763,6 @@ Boolean IsRoomAStructure (short roomNum)
break; break;
} }
} }
HSetState((Handle)thisHouse, wasState);
return (isStructure); return (isStructure);
} }
@@ -950,7 +905,6 @@ short GetOriginalBounding (short theID)
else else
{ {
boundCode = 0; boundCode = 0;
HLock((Handle)boundsRes);
if ((*boundsRes)->left) if ((*boundsRes)->left)
boundCode += 1; boundCode += 1;
if ((*boundsRes)->top) if ((*boundsRes)->top)
@@ -959,7 +913,6 @@ short GetOriginalBounding (short theID)
boundCode += 4; boundCode += 4;
if ((*boundsRes)->bottom) if ((*boundsRes)->bottom)
boundCode += 8; boundCode += 8;
HUnlock((Handle)boundsRes);
ReleaseResource((Handle)boundsRes); ReleaseResource((Handle)boundsRes);
} }
@@ -1033,8 +986,6 @@ short GetNumberOfLights (short where)
} }
else else
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
switch (thisHousePtr->rooms[where].background) switch (thisHousePtr->rooms[where].background)
{ {
@@ -1094,7 +1045,6 @@ short GetNumberOfLights (short where)
} }
} }
} }
HSetState((Handle)thisHouse, wasState);
} }
return (count); return (count);
} }

View File

@@ -58,10 +58,7 @@ void DrawLocale (void)
tvInRoom = false; tvInRoom = false;
tvWithMovieNumber = -1; tvWithMovieNumber = -1;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
roomV = (*thisHouse)->rooms[thisRoomNumber].floor; roomV = (*thisHouse)->rooms[thisRoomNumber].floor;
HSetState((Handle)thisHouse, wasState);
for (i = 0; i < 9; i++) for (i = 0; i < 9; i++)
{ {
@@ -147,9 +144,7 @@ void LoadGraphicSpecial (short resID)
} }
} }
HLock((Handle)thePicture);
bounds = (*thePicture)->picFrame.ToRect(); bounds = (*thePicture)->picFrame.ToRect();
HUnlock((Handle)thePicture);
OffsetRect(&bounds, -bounds.left, -bounds.top); OffsetRect(&bounds, -bounds.left, -bounds.top);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
@@ -167,12 +162,9 @@ void DrawRoomBackground (short who, short where, short elevation)
if (where == kCentralRoom) if (where == kCentralRoom)
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisBackground = (*thisHouse)->rooms[who].background; thisBackground = (*thisHouse)->rooms[who].background;
for (i = 0; i < kNumTiles; i++) for (i = 0; i < kNumTiles; i++)
thisTiles[i] = (*thisHouse)->rooms[who].tiles[i]; thisTiles[i] = (*thisHouse)->rooms[who].tiles[i];
HSetState((Handle)thisHouse, wasState);
} }
if ((numLights == 0) && (who != kRoomIsEmpty)) if ((numLights == 0) && (who != kRoomIsEmpty))
@@ -226,12 +218,9 @@ void DrawRoomBackground (short who, short where, short elevation)
} }
else else
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
pictID = (*thisHouse)->rooms[who].background; pictID = (*thisHouse)->rooms[who].background;
for (i = 0; i < kNumTiles; i++) for (i = 0; i < kNumTiles; i++)
tiles[i] = (*thisHouse)->rooms[who].tiles[i]; tiles[i] = (*thisHouse)->rooms[who].tiles[i];
HSetState((Handle)thisHouse, wasState);
} }
SetPort((GrafPtr)workSrcMap); SetPort((GrafPtr)workSrcMap);
@@ -436,10 +425,7 @@ void RedrawRoomLighting (void)
char wasState; char wasState;
Boolean wasLit, isLit; Boolean wasLit, isLit;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
roomV = (*thisHouse)->rooms[thisRoomNumber].floor; roomV = (*thisHouse)->rooms[thisRoomNumber].floor;
HSetState((Handle)thisHouse, wasState);
wasLit = numLights > 0; wasLit = numLights > 0;
numLights = GetNumberOfLights(localNumbers[kCentralRoom]); numLights = GetNumberOfLights(localNumbers[kCentralRoom]);

View File

@@ -447,10 +447,7 @@ void DoRoomInfo (void)
ShowWindow(GetDialogWindow(roomInfoDialog)); ShowWindow(GetDialogWindow(roomInfoDialog));
DrawDefaultButton(roomInfoDialog); DrawDefaultButton(roomInfoDialog);
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
wasFirstRoom = ((*thisHouse)->firstRoom == thisRoomNumber); wasFirstRoom = ((*thisHouse)->firstRoom == thisRoomNumber);
HSetState((Handle)thisHouse, wasState);
SetDialogItemValue(roomInfoDialog, kRoomFirstCheck, (short)wasFirstRoom); SetDialogItemValue(roomInfoDialog, kRoomFirstCheck, (short)wasFirstRoom);
if (tempBack >= kUserBackground) if (tempBack >= kUserBackground)
@@ -473,9 +470,7 @@ void DoRoomInfo (void)
PasStringCopyNum(tempStr, thisRoom->name, 27); PasStringCopyNum(tempStr, thisRoom->name, 27);
if (wasFirstRoom) if (wasFirstRoom)
{ {
HLock((Handle)thisHouse);
(*thisHouse)->firstRoom = thisRoomNumber; (*thisHouse)->firstRoom = thisRoomNumber;
HUnlock((Handle)thisHouse);
} }
thisRoom->background = tempBack; thisRoom->background = tempBack;
if (tempBack < kUserBackground) if (tempBack < kUserBackground)

View File

@@ -311,8 +311,6 @@ void SaveGame (Boolean doSave)
if (twoPlayerGame) if (twoPlayerGame)
return; return;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
if (doSave) if (doSave)
@@ -343,8 +341,6 @@ void SaveGame (Boolean doSave)
thisHousePtr->hasGame = false; thisHousePtr->hasGame = false;
} }
HSetState((Handle)thisHouse, wasState);
if (doSave) if (doSave)
{ {
if (!WriteHouse(theMode == kEditMode)) if (!WriteHouse(theMode == kEditMode))

View File

@@ -225,7 +225,6 @@ OSErr LoadTriggerSound (short soundID)
{ {
soundDataSize = GetHandleSize(theSound) - 20L; soundDataSize = GetHandleSize(theSound) - 20L;
theSoundData[kMaxSounds - 1] = NewPtr(soundDataSize); theSoundData[kMaxSounds - 1] = NewPtr(soundDataSize);
HLock(theSound);
if (theSoundData[kMaxSounds - 1] == nil) if (theSoundData[kMaxSounds - 1] == nil)
{ {
ReleaseResource(theSound); ReleaseResource(theSound);
@@ -268,15 +267,12 @@ OSErr LoadBufferSounds (void)
if (theSound == nil) if (theSound == nil)
return (MemError()); return (MemError());
HLock(theSound);
soundDataSize = GetHandleSize(theSound) - 20L; soundDataSize = GetHandleSize(theSound) - 20L;
HUnlock(theSound);
theSoundData[i] = NewPtr(soundDataSize); theSoundData[i] = NewPtr(soundDataSize);
if (theSoundData[i] == nil) if (theSoundData[i] == nil)
return (MemError()); return (MemError());
HLock(theSound);
BlockMove((Ptr)((Byte*)(*theSound) + 20L), theSoundData[i], soundDataSize); BlockMove((Ptr)((Byte*)(*theSound) + 20L), theSoundData[i], soundDataSize);
ReleaseResource(theSound); ReleaseResource(theSound);
} }

View File

@@ -81,9 +81,7 @@ void InitScoreboardMap (void)
thePicture = GetPicture(kScoreboardPictID); thePicture = GetPicture(kScoreboardPictID);
if (thePicture == nil) if (thePicture == nil)
RedAlert(kErrFailedGraphicLoad); RedAlert(kErrFailedGraphicLoad);
HLock((Handle)thePicture);
bounds = (*thePicture)->picFrame.ToRect(); bounds = (*thePicture)->picFrame.ToRect();
HUnlock((Handle)thePicture);
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, hOffset, 0); QOffsetRect(&bounds, hOffset, 0);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);

View File

@@ -31,12 +31,8 @@ extern Boolean playerDead, playerSuicide, tvOn;
short WhatAreWeLinkedTo (short where, Byte who) short WhatAreWeLinkedTo (short where, Byte who)
{ {
short what, whatType; short what, whatType;
char wasState;
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
what = (*thisHouse)->rooms[where].objects[who].what; what = (*thisHouse)->rooms[where].objects[who].what;
HSetState((Handle)thisHouse, wasState);
switch (what) switch (what)
{ {
@@ -430,15 +426,11 @@ void MoveMailToMail (gliderPtr thisGlider)
void HandleRoomVisitation (void) void HandleRoomVisitation (void)
{ {
houseType *thisHousePtr; houseType *thisHousePtr;
char wasState;
if (!thisRoom->visited) if (!thisRoom->visited)
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
thisHousePtr = *thisHouse; thisHousePtr = *thisHouse;
thisHousePtr->rooms[localNumbers[kCentralRoom]].visited = true; thisHousePtr->rooms[localNumbers[kCentralRoom]].visited = true;
HSetState((Handle)thisHouse, wasState);
theScore += kRoomVisitScore; theScore += kRoomVisitScore;
thisRoom->visited = true; thisRoom->visited = true;
} }

View File

@@ -173,8 +173,6 @@ void FireTrigger (short index)
} }
else else
{ {
wasState = HGetState((Handle)thisHouse);
HLock((Handle)thisHouse);
triggeredIs = masterObjects[triggerIs].localLink; triggeredIs = masterObjects[triggerIs].localLink;
switch ((*thisHouse)->rooms[triggers[index].room]. switch ((*thisHouse)->rooms[triggers[index].room].
objects[triggers[index].object].what) objects[triggers[index].object].what)
@@ -189,7 +187,6 @@ void FireTrigger (short index)
} }
break; break;
} }
HSetState((Handle)thisHouse, wasState);
} }
} }

View File

@@ -5,7 +5,7 @@
//============================================================================ //============================================================================
#include "PLKeyEncoding.h" #include "PLKeyEncoding.h"
#include "PLQuickdraw.h" #include "PLQDraw.h"
#include "PLPasStr.h" #include "PLPasStr.h"
#include "PLResources.h" #include "PLResources.h"
#include "PLSound.h" #include "PLSound.h"
@@ -302,9 +302,7 @@ void LoadGraphic (short resID)
if (thePicture == nil) if (thePicture == nil)
RedAlert(kErrFailedGraphicLoad); RedAlert(kErrFailedGraphicLoad);
HLock((Handle)thePicture);
bounds = (*thePicture)->picFrame.ToRect(); bounds = (*thePicture)->picFrame.ToRect();
HUnlock((Handle)thePicture);
OffsetRect(&bounds, -bounds.left, -bounds.top); OffsetRect(&bounds, -bounds.left, -bounds.top);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
@@ -327,31 +325,6 @@ void LoadScaledGraphic (short resID, Rect *theRect)
ReleaseResource((Handle)thePicture); 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 //-------------------------------------------------------------- LargeIconPlot
// Draws a standard b&w icon (32 x 32) - resource is an 'ICON'. // Draws a standard b&w icon (32 x 32) - resource is an 'ICON'.

View File

@@ -15,10 +15,23 @@ GpSystemServices_Win32::GpSystemServices_Win32()
uint32_t GpSystemServices_Win32::GetTime() const uint32_t GpSystemServices_Win32::GetTime() const
{ {
// PL_NotYetImplemented //PL_NotYetImplemented_TODO("Time");
return 0; 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() PortabilityLayer::HostMutex *GpSystemServices_Win32::CreateMutex()
{ {
return GpMutex_Win32::Create(); return GpMutex_Win32::Create();

View File

@@ -16,6 +16,7 @@ public:
GpSystemServices_Win32(); GpSystemServices_Win32();
uint32_t GetTime() const override; 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::HostMutex *CreateMutex() override;
PortabilityLayer::HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) override; PortabilityLayer::HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) override;

View File

@@ -1,7 +1,7 @@
#include "DisplayDeviceManager.h" #include "DisplayDeviceManager.h"
#include "HostDisplayDriver.h" #include "HostDisplayDriver.h"
#include "PLQuickdraw.h" #include "PLQDraw.h"
#include "MemoryManager.h" #include "MemoryManager.h"
#include "QDStandardPalette.h" #include "QDStandardPalette.h"

View File

@@ -17,6 +17,7 @@ namespace PortabilityLayer
{ {
public: public:
virtual uint32_t GetTime() const = 0; 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 HostMutex *CreateMutex() = 0;
virtual HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) = 0; virtual HostThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) = 0;

View File

@@ -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;
};
}

View File

@@ -0,0 +1,101 @@
#include "LinePlotter.h"
#include "Vec2i.h"
#include <assert.h>
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;
}
}

View File

@@ -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;
};
}

View File

@@ -2,7 +2,7 @@
#include "PLApplication.h" #include "PLApplication.h"
#include "PLPasStr.h" #include "PLPasStr.h"
#include "PLKeyEncoding.h" #include "PLKeyEncoding.h"
#include "PLQuickdraw.h" #include "PLQDraw.h"
#include "AEManager.h" #include "AEManager.h"
#include "DisplayDeviceManager.h" #include "DisplayDeviceManager.h"
@@ -901,10 +901,17 @@ void GetDateTime(UInt32 *dateTime)
void GetTime(DateTimeRec *dateTime) void GetTime(DateTimeRec *dateTime)
{ {
PL_NotYetImplemented_TODO("DateTime"); unsigned int year;
dateTime->month = 1; unsigned int month;
dateTime->hour = 0; unsigned int day;
dateTime->minute = 0; 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() UInt32 GetDblTime()
@@ -955,22 +962,6 @@ long GetHandleSize(Handle handle)
return static_cast<long>(block->m_size); return static_cast<long>(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) OSErr PtrAndHand(const void *data, Handle handle, Size size)
{ {
PL_NotYetImplemented(); PL_NotYetImplemented();

View File

@@ -369,11 +369,6 @@ Handle NewHandle(Size size);
void DisposeHandle(Handle handle); void DisposeHandle(Handle handle);
long GetHandleSize(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 OSErr PtrAndHand(const void *data, Handle handle, Size size); // Appends data to the end of a handle
void SetHandleSize(Handle hdl, Size newSize); void SetHandleSize(Handle hdl, Size newSize);
@@ -384,9 +379,6 @@ void DisposePtr(void *ptr);
Size MaxMem(Size *growBytes); Size MaxMem(Size *growBytes);
void PurgeSpace(long *totalFree, long *contiguousFree); void PurgeSpace(long *totalFree, long *contiguousFree);
void HSetState(Handle handle, char state);
char HGetState(Handle handle);
OSErr MemError(); OSErr MemError();
void BlockMove(const void *src, void *dest, Size size); void BlockMove(const void *src, void *dest, Size size);

View File

@@ -3,7 +3,7 @@
#define __PL_QDOFFSCREEN_H__ #define __PL_QDOFFSCREEN_H__
#include "PLCore.h" #include "PLCore.h"
#include "PLQuickdraw.h" #include "PLQDraw.h"
struct ColorTable struct ColorTable
{ {

View File

@@ -1,4 +1,4 @@
#include "PLQuickdraw.h" #include "PLQDraw.h"
#include "QDManager.h" #include "QDManager.h"
#include "QDState.h" #include "QDState.h"
#include "DisplayDeviceManager.h" #include "DisplayDeviceManager.h"

View File

@@ -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,
};
}

View File

@@ -163,6 +163,8 @@
<ClInclude Include="HostVOSEventQueue.h" /> <ClInclude Include="HostVOSEventQueue.h" />
<ClInclude Include="InputManager.h" /> <ClInclude Include="InputManager.h" />
<ClInclude Include="IOStream.h" /> <ClInclude Include="IOStream.h" />
<ClInclude Include="IPlotter.h" />
<ClInclude Include="LinePlotter.h" />
<ClInclude Include="MacBinary2.h" /> <ClInclude Include="MacBinary2.h" />
<ClInclude Include="MacFileMem.h" /> <ClInclude Include="MacFileMem.h" />
<ClInclude Include="MacFileInfo.h" /> <ClInclude Include="MacFileInfo.h" />
@@ -194,6 +196,9 @@
<ClInclude Include="PLLowMem.h" /> <ClInclude Include="PLLowMem.h" />
<ClInclude Include="PLMacTypes.h" /> <ClInclude Include="PLMacTypes.h" />
<ClInclude Include="MenuManager.h" /> <ClInclude Include="MenuManager.h" />
<ClInclude Include="PlotDirection.h" />
<ClInclude Include="ScanlineMaskBuilder.h" />
<ClInclude Include="ScanlineMaskConverter.h" />
<ClInclude Include="QDGraf.h" /> <ClInclude Include="QDGraf.h" />
<ClInclude Include="QDManager.h" /> <ClInclude Include="QDManager.h" />
<ClInclude Include="QDPictEmitContext.h" /> <ClInclude Include="QDPictEmitContext.h" />
@@ -221,7 +226,7 @@
<ClInclude Include="PLPasStr.h" /> <ClInclude Include="PLPasStr.h" />
<ClInclude Include="PLQDOffscreen.h" /> <ClInclude Include="PLQDOffscreen.h" />
<ClInclude Include="PLMovies.h" /> <ClInclude Include="PLMovies.h" />
<ClInclude Include="PLQuickdraw.h" /> <ClInclude Include="PLQDraw.h" />
<ClInclude Include="ResourceManager.h" /> <ClInclude Include="ResourceManager.h" />
<ClInclude Include="PLResources.h" /> <ClInclude Include="PLResources.h" />
<ClInclude Include="PLScript.h" /> <ClInclude Include="PLScript.h" />
@@ -265,6 +270,7 @@
<ClCompile Include="HostSystemServices.cpp" /> <ClCompile Include="HostSystemServices.cpp" />
<ClCompile Include="HostVOSEventQueue.cpp" /> <ClCompile Include="HostVOSEventQueue.cpp" />
<ClCompile Include="InputManager.cpp" /> <ClCompile Include="InputManager.cpp" />
<ClCompile Include="LinePlotter.cpp" />
<ClCompile Include="MacBinary2.cpp" /> <ClCompile Include="MacBinary2.cpp" />
<ClCompile Include="MacFileInfo.cpp" /> <ClCompile Include="MacFileInfo.cpp" />
<ClCompile Include="MacFileMem.cpp" /> <ClCompile Include="MacFileMem.cpp" />
@@ -286,11 +292,14 @@
<ClCompile Include="PLNavigation.cpp" /> <ClCompile Include="PLNavigation.cpp" />
<ClCompile Include="PLNumberFormatting.cpp" /> <ClCompile Include="PLNumberFormatting.cpp" />
<ClCompile Include="PLQDOffscreen.cpp" /> <ClCompile Include="PLQDOffscreen.cpp" />
<ClCompile Include="PLQuickdraw.cpp" /> <ClCompile Include="PLQDraw.cpp" />
<ClCompile Include="PLResourceManager.cpp" /> <ClCompile Include="PLResourceManager.cpp" />
<ClCompile Include="PLResources.cpp" /> <ClCompile Include="PLResources.cpp" />
<ClCompile Include="PLSound.cpp" /> <ClCompile Include="PLSound.cpp" />
<ClCompile Include="PLStringCompare.cpp" /> <ClCompile Include="PLStringCompare.cpp" />
<ClCompile Include="ScanlineMask.cpp" />
<ClCompile Include="ScanlineMaskBuilder.cpp" />
<ClCompile Include="ScanlineMaskConverter.cpp" />
<ClCompile Include="QDGraf.cpp" /> <ClCompile Include="QDGraf.cpp" />
<ClCompile Include="QDManager.cpp" /> <ClCompile Include="QDManager.cpp" />
<ClCompile Include="QDPictDecoder.cpp" /> <ClCompile Include="QDPictDecoder.cpp" />

View File

@@ -90,9 +90,6 @@
<ClInclude Include="PLMovies.h"> <ClInclude Include="PLMovies.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="PLQuickdraw.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLMacTypes.h"> <ClInclude Include="PLMacTypes.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@@ -369,6 +366,24 @@
<ClInclude Include="..\GpCommon\GpBitfield.h"> <ClInclude Include="..\GpCommon\GpBitfield.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="LinePlotter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PlotDirection.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PLQDraw.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ScanlineMaskConverter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IPlotter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ScanlineMaskBuilder.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="CFileStream.cpp"> <ClCompile Include="CFileStream.cpp">
@@ -398,9 +413,6 @@
<ClCompile Include="PLResources.cpp"> <ClCompile Include="PLResources.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="PLQuickdraw.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLSound.cpp"> <ClCompile Include="PLSound.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
@@ -554,5 +566,20 @@
<ClCompile Include="..\stb\stb_image_write.c"> <ClCompile Include="..\stb\stb_image_write.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="ScanlineMaskConverter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PLQDraw.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LinePlotter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ScanlineMaskBuilder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ScanlineMask.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "PLBigEndian.h" #include "PLBigEndian.h"
#include "PLQuickdraw.h" #include "PLQDraw.h"
#include "GpPixelFormat.h" #include "GpPixelFormat.h"
#include <stdint.h> #include <stdint.h>

View File

@@ -1,10 +1,10 @@
#include "QDState.h" #include "QDState.h"
#include "PLQuickdraw.h" #include "PLQDraw.h"
#include "QDStandardPalette.h" #include "QDStandardPalette.h"
namespace PortabilityLayer namespace PortabilityLayer
{ {
QDState::QDState() QDState::QDState()
: m_fontID(applFont) : m_fontID(applFont)
, m_textSize(12) , m_textSize(12)
@@ -19,10 +19,10 @@ namespace PortabilityLayer
, m_isBackResolved8(false) , m_isBackResolved8(false)
, m_clipRegion(nullptr) , 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.r = m_foreUnresolvedColor.g = m_foreUnresolvedColor.b = 0;
m_foreUnresolvedColor.a = 255; m_foreUnresolvedColor.a = 255;
m_penPos.h = m_penPos.v = 0; m_penPos.h = m_penPos.v = 0;
} }
void QDState::SetForeColor(const RGBAColor &color) void QDState::SetForeColor(const RGBAColor &color)
@@ -77,6 +77,6 @@ namespace PortabilityLayer
cached = resolvedColor; cached = resolvedColor;
return resolvedColor; return resolvedColor;
} }
} }
} }

View File

@@ -0,0 +1,80 @@
#include "CoreDefs.h"
#include "ScanlineMask.h"
#include "ScanlineMaskBuilder.h"
#include <stdlib.h>
#include <new>
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<uint8_t*>(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<uint8_t*>(spanStorage)[i] = static_cast<uint8_t>(spans[i]);
break;
case DataStorage_UInt16:
static_cast<uint16_t*>(spanStorage)[i] = static_cast<uint16_t>(spans[i]);
break;
case DataStorage_UInt32:
static_cast<uint32_t*>(spanStorage)[i] = static_cast<uint32_t>(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()
{
}
}

View File

@@ -0,0 +1,31 @@
#pragma once
#include <stdint.h>
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;
};
}

View File

@@ -0,0 +1,66 @@
#include "ScanlineMaskBuilder.h"
#include <stdlib.h>
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<size_t*>(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<size_t*>(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;
}
}

View File

@@ -0,0 +1,25 @@
#pragma once
#include <stdint.h>
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;
};
}

View File

@@ -0,0 +1,318 @@
#include "ScanlineMaskConverter.h"
#include "ScanlineMask.h"
#include "Vec2i.h"
#include "LinePlotter.h"
#include "ScanlineMaskBuilder.h"
#include "IPlotter.h"
#include <assert.h>
#include <algorithm>
#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<uint64_t>(width) * static_cast<uint64_t>(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<uint8_t*>(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<uint32_t>(initialPoint.m_y) * width + static_cast<uint32_t>(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<uint32_t>(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<int32_t>(minPoint.m_x, points[i].m_x);
minPoint.m_y = std::min<int32_t>(minPoint.m_y, points[i].m_y);
maxPoint.m_x = std::max<int32_t>(maxPoint.m_x, points[i].m_x);
maxPoint.m_y = std::max<int32_t>(maxPoint.m_y, points[i].m_y);
}
const uint32_t width = static_cast<uint32_t>(maxPoint.m_x - minPoint.m_x) + 1;
const uint32_t height = static_cast<uint32_t>(maxPoint.m_y - minPoint.m_y) + 1;
PolyPlotter polyPlotter(points, numPoints);
return ComputePlot(width, height, minPoint, polyPlotter);
}
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
namespace PortabilityLayer
{
class ScanlineMask;
struct Vec2i;
class ScanlineMaskConverter
{
public:
static ScanlineMask *CompilePoly(const Vec2i *points, size_t numPoints);
};
}

View File

@@ -17,7 +17,10 @@ namespace PortabilityLayer
Vec2i operator-(const Vec2i &other) const; Vec2i operator-(const Vec2i &other) const;
Vec2i &operator+=(const Vec2i &other); 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() inline Vec2i::Vec2i()
@@ -60,6 +63,15 @@ namespace PortabilityLayer
m_x -= other.m_x; m_x -= other.m_x;
m_y -= other.m_y; m_y -= other.m_y;
return *this; 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);
} }
} }