Fix artifacts if a resize reordered the saved maps of an item.

(Happens in Slumberland if resizing the window from 1600x900 to 800x600 in the second room, then picking up the cuckoo.)
This commit is contained in:
elasota
2020-04-25 00:50:28 -04:00
parent b5a3db860f
commit c357ca2b7c
7 changed files with 52 additions and 42 deletions

View File

@@ -59,6 +59,7 @@ void NilSavedMaps (void)
}
savedMaps[i].where = -1;
savedMaps[i].who = -1;
savedMaps[i].component = -1;
}
numSavedMaps = 0;
}
@@ -69,7 +70,7 @@ void NilSavedMaps (void)
// room that it obscured so that, should the player get the object,<2C>
// it can be made to "disappear".
short BackUpToSavedMap (Rect *theRect, SInt16 where, SInt16 who)
short BackUpToSavedMap (Rect *theRect, SInt16 where, SInt16 who, SInt16 component)
{
Rect mapRect;
PLError_t theErr;
@@ -89,6 +90,7 @@ short BackUpToSavedMap (Rect *theRect, SInt16 where, SInt16 who)
savedMaps[numSavedMaps].where = where;
savedMaps[numSavedMaps].who = who;
savedMaps[numSavedMaps].component = component;
numSavedMaps++;
return (numSavedMaps - 1); // return array index
@@ -99,7 +101,7 @@ short BackUpToSavedMap (Rect *theRect, SInt16 where, SInt16 who)
// a slot in the pixmap array for the object. It re-copies the background<6E>
// and is needed when the lights in the room go on or off.
SInt16 ReBackUpSavedMap (Rect *theRect, SInt16 where, SInt16 who)
SInt16 ReBackUpSavedMap (Rect *theRect, SInt16 where, SInt16 who, SInt16 component)
{
Rect mapRect;
short i, foundIndex;
@@ -108,7 +110,7 @@ SInt16 ReBackUpSavedMap (Rect *theRect, SInt16 where, SInt16 who)
for (i = 0; i < numSavedMaps; i++)
{
if ((savedMaps[i].where == where) && (savedMaps[i].who == who))
if ((savedMaps[i].where == where) && (savedMaps[i].who == who) && (savedMaps[i].component == component))
{
foundIndex = i;
mapRect = *theRect;
@@ -124,7 +126,7 @@ SInt16 ReBackUpSavedMap (Rect *theRect, SInt16 where, SInt16 who)
}
}
return BackUpToSavedMap(theRect, where, who);
return BackUpToSavedMap(theRect, where, who, component);
}
//-------------------------------------------------------------- RemoveFromSavedMap
@@ -179,14 +181,14 @@ SInt16 RemoveFromSavedMap (SInt16 index)
// This copies the saved background swatch to the screen - effectively<6C>
// covering up or "erasing" the object.
void RestoreFromSavedMap (short where, short who, Boolean doSparkle)
void RestoreFromSavedMap (SInt16 where, SInt16 who, SInt16 component, Boolean doSparkle)
{
Rect mapRect, bounds;
short i;
for (i = 0; i < numSavedMaps; i++)
{
if ((savedMaps[i].where == where) && (savedMaps[i].who == who) &&
if ((savedMaps[i].where == where) && (savedMaps[i].who == who) && (savedMaps[i].component == component) &&
(savedMaps[i].map != nil))
{
mapRect = savedMaps[i].dest;
@@ -384,7 +386,7 @@ void AddCandleFlame (SInt16 where, SInt16 who, SInt16 h, SInt16 v)
QOffsetRect(&src, 2, 0);
}
QSetRect(&bounds, 0, 0, 16, 15 * kNumCandleFlames);
savedNum = BackUpToSavedMap(&bounds, where, who);
savedNum = BackUpToSavedMap(&bounds, where, who, kCandleFlameComponent);
if (savedNum != -1)
{
BackUpFlames(&src, savedNum);
@@ -471,7 +473,7 @@ void AddTikiFlame (short where, short who, short h, short v)
}
QOffsetRect(&src, h, v);
QSetRect(&bounds, 0, 0, 8, 10 * kNumTikiFlames);
savedNum = BackUpToSavedMap(&bounds, where, who);
savedNum = BackUpToSavedMap(&bounds, where, who, kTikiFlamesComponent);
if (savedNum != -1)
{
BackUpTikiFlames(&src, savedNum);
@@ -560,7 +562,7 @@ void AddBBQCoals (short where, short who, short h, short v)
}
QOffsetRect(&src, h, v);
QSetRect(&bounds, 0, 0, 32, 9 * kNumBBQCoals);
savedNum = BackUpToSavedMap(&bounds, where, who);
savedNum = BackUpToSavedMap(&bounds, where, who, kBBQCoalsComponent);
if (savedNum != -1)
{
BackUpBBQCoals(&src, savedNum);
@@ -644,7 +646,7 @@ void AddPendulum (SInt16 where, SInt16 who, SInt16 h, SInt16 v)
clockFrame = 10;
QSetRect(&bounds, 0, 0, 32, 28 * kNumPendulums);
savedNum = BackUpToSavedMap(&bounds, where, who);
savedNum = BackUpToSavedMap(&bounds, where, who, kPendulumComponent);
if (savedNum != -1)
{
QSetRect(&src, 0, 0, 32, 28);
@@ -745,7 +747,7 @@ void AddStar (short where, short who, short h, short v)
QOffsetRect(&src, h, v);
QSetRect(&bounds, 0, 0, 32, 31 * 6);
savedNum = BackUpToSavedMap(&bounds, where, who);
savedNum = BackUpToSavedMap(&bounds, where, who, kStarComponent);
if (savedNum != -1)
{
BackUpStar(&src, savedNum);

View File

@@ -621,3 +621,10 @@ static const Boolean kFaceLeft = FALSE; // Conflicts with GP input driver
#define kDemoLength 6702
#define kGamepadDeadzone 4096 // Out of 32768
#define kDefaultComponent 0
#define kCandleFlameComponent 1
#define kTikiFlamesComponent 1
#define kBBQCoalsComponent 1
#define kPendulumComponent 1
#define kStarComponent 1

View File

@@ -23,10 +23,10 @@ void CloseCoordWindow (void);
void ToggleCoordinateWindow (void);
void NilSavedMaps (void); // --- DynamicMaps.c
SInt16 BackUpToSavedMap (Rect *, SInt16, SInt16);
SInt16 ReBackUpSavedMap (Rect *, SInt16, SInt16);
SInt16 BackUpToSavedMap (Rect *theRect, SInt16 where, SInt16 who, SInt16 component);
SInt16 ReBackUpSavedMap (Rect *theRect, SInt16 where, SInt16 who, SInt16 component);
SInt16 RemoveFromSavedMap(SInt16);
void RestoreFromSavedMap (SInt16, SInt16, Boolean);
void RestoreFromSavedMap (SInt16 where, SInt16 who, SInt16 component, Boolean doSparkle);
void AddSparkle (Rect *);
void AddFlyingPoint (Rect *, SInt16, SInt16, SInt16);
Boolean ReBackUpFlames (SInt16, SInt16, SInt16, SInt16);

View File

@@ -241,6 +241,7 @@ typedef struct
DrawSurface *map;
short where;
short who;
short component;
} savedType, *savedPtr;
typedef struct

View File

@@ -213,7 +213,7 @@ short AddGrease (short where, short who, short h, short v,
QOffsetRect(&src, h, v);
QSetRect(&bounds, 0, 0, 32, 27 * 4);
savedNum = BackUpToSavedMap(&bounds, where, who);
savedNum = BackUpToSavedMap(&bounds, where, who, kDefaultComponent);
if (savedNum != -1)
{
BackupGrease (&src, savedNum, isRight);
@@ -332,5 +332,5 @@ void RemapGreaseSavedMap(SInt16 removedItem, SInt16 substituteItem)
grease[i].mapNum = removedItem;
return;
}
}
}
}

View File

@@ -769,7 +769,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kBeepsSound, kBeepsPriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
AddFlyingPoint(&bounds, 100, thisGlider->hVel / 2, thisGlider->vVel / 2);
thisGlider->hVel /= 4;
thisGlider->vVel /= 4;
@@ -785,7 +785,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kBuzzerSound, kBuzzerPriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
AddFlyingPoint(&bounds, 300, thisGlider->hVel / 2, thisGlider->vVel / 2);
thisGlider->hVel /= 4;
thisGlider->vVel /= 4;
@@ -801,7 +801,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kDingSound, kDingPriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
AddFlyingPoint(&bounds, 500, thisGlider->hVel / 2, thisGlider->vVel / 2);
thisGlider->hVel /= 4;
thisGlider->vVel /= 4;
@@ -817,7 +817,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kCuckooSound, kCuckooPriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
StopPendulum(thisRoomNumber, masterObjects[whoLinked].objectNum);
AddFlyingPoint(&bounds, 1000, thisGlider->hVel / 2, thisGlider->vVel / 2);
thisGlider->hVel /= 4;
@@ -834,7 +834,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kEnergizeSound, kEnergizePriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
AddSparkle(&bounds);
thisGlider->hVel /= 2;
thisGlider->vVel /= 2;
@@ -853,7 +853,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kEnergizeSound, kEnergizePriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
AddSparkle(&bounds);
thisGlider->hVel /= 2;
thisGlider->vVel /= 2;
@@ -875,7 +875,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kEnergizeSound, kEnergizePriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
AddSparkle(&bounds);
thisGlider->hVel /= 2;
thisGlider->vVel /= 2;
@@ -903,7 +903,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kEnergizeSound, kEnergizePriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
AddSparkle(&bounds);
thisGlider->hVel /= 2;
thisGlider->vVel /= 2;
@@ -936,7 +936,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kEnergizeSound, kEnergizePriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
AddSparkle(&bounds);
StopStar(thisRoomNumber, masterObjects[whoLinked].objectNum);
numStarsRemaining--;
@@ -959,7 +959,7 @@ void HandleRewards (gliderPtr thisGlider, hotPtr who)
{
PlayPrioritySound(kEnergizeSound, kEnergizePriority);
RestoreFromSavedMap(thisRoomNumber,
masterObjects[whoLinked].objectNum, false);
masterObjects[whoLinked].objectNum, kDefaultComponent, false);
AddSparkle(&bounds);
thisGlider->hVel /= 2;
thisGlider->vVel /= 2;
@@ -1050,12 +1050,12 @@ void HandleSwitches (hotPtr who)
case kFoil:
case kStar:
case kHelium:
RestoreFromSavedMap(roomLinked, objectLinked, true);
RestoreFromSavedMap(roomLinked, objectLinked, kDefaultComponent, true);
AddSparkle(&bounds);
break;
case kCuckoo:
RestoreFromSavedMap(roomLinked, objectLinked, true);
RestoreFromSavedMap(roomLinked, objectLinked, kDefaultComponent, true);
StopPendulum(roomLinked, objectLinked);
break;

View File

@@ -301,9 +301,9 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
if (redraw)
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i);
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
else
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i);
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
if (legit != -1)
DrawRedClock(&itsRect);
}
@@ -315,9 +315,9 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
if (redraw)
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i);
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
else
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i);
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
if (legit != -1)
DrawBlueClock(&itsRect);
}
@@ -329,9 +329,9 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
if (redraw)
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i);
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
else
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i);
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
if (legit != -1)
DrawYellowClock(&itsRect);
}
@@ -343,9 +343,9 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
if (redraw)
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i);
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
else
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i);
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
if (legit != -1)
{
DrawCuckoo(&itsRect);
@@ -369,9 +369,9 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
if (redraw)
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i);
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
else
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i);
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
if (legit != -1)
DrawSimplePrizes(thisObject.what, &itsRect);
}
@@ -435,9 +435,9 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
if (redraw)
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i);
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
else
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i);
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
if (legit != -1)
DrawFoil(&itsRect);
}
@@ -453,9 +453,9 @@ void DrawARoomsObjects (short neighbor, Boolean redraw)
if (SectRect(&itsRect, &testRect, &whoCares))
{
if (redraw)
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i);
legit = ReBackUpSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
else
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i);
legit = BackUpToSavedMap(&itsRect, localNumbers[neighbor], i, kDefaultComponent);
if (legit != -1)
{
if (redraw)