Refactor neighboring rooms sync-ups. Remove all of the neighboring room objects and recreate them, which fixes a bunch of problems with objects becoming out-of-frame after resize.

This commit is contained in:
elasota
2020-04-05 18:34:37 -04:00
parent b827048c36
commit d7353ff6ed
8 changed files with 163 additions and 27 deletions

View File

@@ -5,6 +5,7 @@
//============================================================================
#include "ArrayTools.h"
#include "Externs.h"
#include "Environ.h"
#include "MainWindow.h"
@@ -68,7 +69,7 @@ void NilSavedMaps (void)
// room that it obscured so that, should the player get the object,<2C>
// it can be made to "disappear".
short BackUpToSavedMap (Rect *theRect, short where, short who)
short BackUpToSavedMap (Rect *theRect, SInt16 where, SInt16 who)
{
Rect mapRect;
PLError_t theErr;
@@ -98,7 +99,7 @@ short BackUpToSavedMap (Rect *theRect, short where, short who)
// a slot in the pixmap array for the object. It re-copies the background<6E>
// and is needed when the lights in the room go on or off.
short ReBackUpSavedMap (Rect *theRect, short where, short who)
SInt16 ReBackUpSavedMap (Rect *theRect, SInt16 where, SInt16 who)
{
Rect mapRect;
short i, foundIndex;
@@ -123,7 +124,54 @@ short ReBackUpSavedMap (Rect *theRect, short where, short who)
}
}
return (foundIndex);
return BackUpToSavedMap(theRect, where, who);
}
//-------------------------------------------------------------- RemoveFromSavedMap
template<class T>
void RemapDynamicObject(T *arr, short &count, int removedIndex, int substituteIndex)
{
short countCopy = count;
for (int i = 0; i < countCopy; i++)
{
if (arr[i].who == removedIndex)
{
PortabilityLayer::ArrayTools::RemoveFromArray(arr, countCopy, i);
i--;
}
else if (arr[i].who == substituteIndex)
arr[i].who = removedIndex;
}
count = countCopy;
}
SInt16 RemoveFromSavedMap (SInt16 index)
{
int swappedIn = numSavedMaps - 1;
RemapDynamicObject(flames, numFlames, index, swappedIn);
RemapDynamicObject(tikiFlames, numTikiFlames, index, swappedIn);
RemapDynamicObject(bbqCoals, numCoals, index, swappedIn);
RemapDynamicObject(pendulums, numPendulums, index, swappedIn);
RemapDynamicObject(theStars, numStars, index, swappedIn);
RemapGreaseSavedMap(index, swappedIn);
// Have to do this explicitly so we don't trash the draw surface pointer
if (swappedIn != index)
{
savedType &dest = savedMaps[index];
savedType &src = savedMaps[swappedIn];
DisposeGWorld(dest.map);
dest = src;
src.map = nil;
}
numSavedMaps--;
return -1;
}
//-------------------------------------------------------------- RestoreFromSavedMap
@@ -292,7 +340,7 @@ void BackUpFlames (Rect *src, short index)
// Like the above function but this is called when the lighting changes<65>
// in a room (lights go on or off).
void ReBackUpFlames (short where, short who, short h, short v)
Boolean ReBackUpFlames (short where, short who, short h, short v)
{
short i, f;
@@ -306,18 +354,20 @@ void ReBackUpFlames (short where, short who, short h, short v)
{
QOffsetRect(&flames[f].dest, h - 8 - flames[f].dest.left, v - 15 - flames[f].dest.top);
BackUpFlames(&flames[f].dest, i);
return;
return true;
}
}
}
}
return false;
}
//-------------------------------------------------------------- AddCandleFlame
// This adds a candle flame to tha array of flames.
void AddCandleFlame (short where, short who, short h, short v)
void AddCandleFlame (SInt16 where, SInt16 who, SInt16 h, SInt16 v)
{
Rect src, bounds;
short savedNum;
@@ -377,7 +427,7 @@ void BackUpTikiFlames (Rect *src, short index)
// This is like the function ReBackUpFlames() but customized for Tiki torches.
void ReBackUpTikiFlames (short where, short who, short h, short v)
Boolean ReBackUpTikiFlames (short where, short who, short h, short v)
{
short i, f;
@@ -391,11 +441,13 @@ void ReBackUpTikiFlames (short where, short who, short h, short v)
{
QOffsetRect(&tikiFlames[f].dest, h - tikiFlames[f].dest.left, v - tikiFlames[f].dest.top);
BackUpTikiFlames(&tikiFlames[f].dest, i);
return;
return true;
}
}
}
}
return false;
}
//-------------------------------------------------------------- AddTikiFlame
@@ -464,7 +516,7 @@ void BackUpBBQCoals (Rect *src, short index)
// Sense a pattern here?
void ReBackUpBBQCoals (short where, short who, short h, short v)
Boolean ReBackUpBBQCoals (short where, short who, short h, short v)
{
short i, f;
@@ -478,11 +530,13 @@ void ReBackUpBBQCoals (short where, short who, short h, short v)
{
QOffsetRect(&bbqCoals[f].dest, h - bbqCoals[f].dest.left, v - bbqCoals[f].dest.top);
BackUpBBQCoals(&bbqCoals[f].dest, i);
return;
return true;
}
}
}
}
return false;
}
//-------------------------------------------------------------- AddBBQCoals
@@ -549,7 +603,7 @@ void BackUpPendulum (Rect *src, short index)
// Backs up the pendulums in the event of lights going on or off.
void ReBackUpPendulum (short where, short who, short h, short v)
Boolean ReBackUpPendulum (short where, short who, short h, short v)
{
short i, f;
@@ -567,18 +621,20 @@ void ReBackUpPendulum (short where, short who, short h, short v)
pendulumDest.left = h;
pendulumDest.top = v;
BackUpPendulum(&pendulumDest, i);
return;
return true;
}
}
}
}
return false;
}
//-------------------------------------------------------------- AddPendulum
// Adds a pendulum to the array of pendulums.
void AddPendulum (short where, short who, short h, short v)
void AddPendulum (SInt16 where, SInt16 who, SInt16 h, SInt16 v)
{
Rect src, bounds;
short savedNum;
@@ -808,3 +864,14 @@ void ZeroFlamesAndTheLike (void)
numChimes = 0;
}
void RemoveSavedMapsNotInRoom(SInt16 where)
{
for (int i = 0; i < numSavedMaps; i++)
{
if (savedMaps[i].where != where)
{
RemoveFromSavedMap(i);
i--;
}
}
}

View File

@@ -440,6 +440,29 @@ void HandleSplashResolutionChange(void)
//DumpScreenOn(&justRoomsRect);
}
void HandleEditorResolutionChange(void)
{
FlushResolutionChange();
RecomputeInterfaceRects();
RecreateOffscreens();
CloseMainWindow();
OpenMainWindow();
UpdateMainWindow();
//ResetLocale(true);
InitScoreboardMap();
//RefreshScoreboard(wasScoreboardTitleMode);
//DumpScreenOn(&justRoomsRect);
if (toolsWindow)
PortabilityLayer::WindowManager::GetInstance()->PutWindowBehind(toolsWindow, PortabilityLayer::WindowManager::GetInstance()->GetPutInFrontSentinel());
if (mapWindow)
PortabilityLayer::WindowManager::GetInstance()->PutWindowBehind(mapWindow, PortabilityLayer::WindowManager::GetInstance()->GetPutInFrontSentinel());
}
//-------------------------------------------------------------- HandleIdleTask
// Handle some processing during event lulls.
@@ -447,6 +470,11 @@ void HandleIdleTask (void)
{
if (theMode == kEditMode)
{
if (thisMac.isResolutionDirty)
{
HandleEditorResolutionChange();
}
SetPort(&mainWindow->GetDrawSurface()->m_port);
DoMarquee();

View File

@@ -25,16 +25,17 @@ void ToggleCoordinateWindow (void);
void NilSavedMaps (void); // --- DynamicMaps.c
SInt16 BackUpToSavedMap (Rect *, SInt16, SInt16);
SInt16 ReBackUpSavedMap (Rect *, SInt16, SInt16);
SInt16 RemoveFromSavedMap(SInt16);
void RestoreFromSavedMap (SInt16, SInt16, Boolean);
void AddSparkle (Rect *);
void AddFlyingPoint (Rect *, SInt16, SInt16, SInt16);
void ReBackUpFlames (SInt16, SInt16, SInt16, SInt16);
Boolean ReBackUpFlames (SInt16, SInt16, SInt16, SInt16);
void AddCandleFlame (SInt16, SInt16, SInt16, SInt16);
void ReBackUpTikiFlames (SInt16, SInt16, SInt16, SInt16);
Boolean ReBackUpTikiFlames (SInt16, SInt16, SInt16, SInt16);
void AddTikiFlame (SInt16, SInt16, SInt16, SInt16);
void ReBackUpBBQCoals (SInt16, SInt16, SInt16, SInt16);
Boolean ReBackUpBBQCoals (SInt16, SInt16, SInt16, SInt16);
void AddBBQCoals (SInt16, SInt16, SInt16, SInt16);
void ReBackUpPendulum (SInt16, SInt16, SInt16, SInt16);
Boolean ReBackUpPendulum (SInt16, SInt16, SInt16, SInt16);
void AddPendulum (SInt16, SInt16, SInt16, SInt16);
void ReBackUpStar (SInt16, SInt16, SInt16, SInt16);
void AddStar (SInt16, SInt16, SInt16, SInt16);
@@ -43,6 +44,7 @@ void StopStar (SInt16, SInt16);
void AddAShreddedGlider (Rect *);
void RemoveShreds (void);
void ZeroFlamesAndTheLike (void);
void RemoveSavedMapsNotInRoom (SInt16);
void CheckDynamicCollision (SInt16, gliderPtr, Boolean); // --- Dynamics.c
Boolean DidBandHitDynamic (SInt16);
@@ -87,6 +89,7 @@ SInt16 AddGrease (SInt16, SInt16, SInt16, SInt16, SInt16, Boolean);
void SpillGrease (SInt16, SInt16);
void RedrawAllGrease (void);
void FixupFallenGrease(SInt16 where, SInt16 who, SInt16 h, SInt16 v, Boolean *isDynamic);
void RemapGreaseSavedMap(SInt16 removedItem, SInt16 substituteItem);
void DoHighScores (void); // --- HighScores.c
void SortHighScores (void);

View File

@@ -322,3 +322,15 @@ void FixupFallenGrease(SInt16 where, SInt16 who, SInt16 h, SInt16 v, Boolean *is
*isDynamic = false;
}
void RemapGreaseSavedMap(SInt16 removedItem, SInt16 substituteItem)
{
for (int i = 0; i < numGrease; i++)
{
if (grease[i].mapNum == substituteItem)
{
grease[i].mapNum = removedItem;
return;
}
}
}

View File

@@ -44,11 +44,12 @@ extern Boolean shadowVisible, takingTheStairs;
void ResetLocale (Boolean soft)
{
short i;
char wasState;
if (soft)
{
RemoveSavedMapsNotInRoom(localNumbers[kCentralRoom]);
ZeroDinahsNotInRoom(localNumbers[kCentralRoom]);
}
else
{
@@ -62,7 +63,7 @@ void ResetLocale (Boolean soft)
tvInRoom = false;
tvWithMovieNumber = -1;
for (i = 0; i < 9; i++)
for (int i = 0; i < 9; i++)
{
localNumbers[i] = GetNeighborRoomNumber(i);
isStructure[i] = IsRoomAStructure(localNumbers[i]);
@@ -84,39 +85,39 @@ void ResetLocale (Boolean soft)
{
numLights = GetNumberOfLights(localNumbers[kNorthWestRoom]);
DrawRoomBackground(localNumbers[kNorthWestRoom], kNorthWestRoom, roomV + 1);
DrawARoomsObjects(kNorthWestRoom, soft);
DrawARoomsObjects(kNorthWestRoom, false);
numLights = GetNumberOfLights(localNumbers[kNorthEastRoom]);
DrawRoomBackground(localNumbers[kNorthEastRoom], kNorthEastRoom, roomV + 1);
DrawARoomsObjects(kNorthEastRoom, soft);
DrawARoomsObjects(kNorthEastRoom, false);
numLights = GetNumberOfLights(localNumbers[kNorthRoom]);
DrawRoomBackground(localNumbers[kNorthRoom], kNorthRoom, roomV + 1);
DrawARoomsObjects(kNorthRoom, soft);
DrawARoomsObjects(kNorthRoom, false);
numLights = GetNumberOfLights(localNumbers[kSouthWestRoom]);
DrawRoomBackground(localNumbers[kSouthWestRoom], kSouthWestRoom, roomV - 1);
DrawARoomsObjects(kSouthWestRoom, soft);
DrawARoomsObjects(kSouthWestRoom, false);
numLights = GetNumberOfLights(localNumbers[kSouthEastRoom]);
DrawRoomBackground(localNumbers[kSouthEastRoom], kSouthEastRoom, roomV - 1);
DrawARoomsObjects(kSouthEastRoom, soft);
DrawARoomsObjects(kSouthEastRoom, false);
numLights = GetNumberOfLights(localNumbers[kSouthRoom]);
DrawRoomBackground(localNumbers[kSouthRoom], kSouthRoom, roomV - 1);
DrawARoomsObjects(kSouthRoom, soft);
DrawARoomsObjects(kSouthRoom, false);
}
if (numNeighbors > 1)
{
numLights = GetNumberOfLights(localNumbers[kWestRoom]);
DrawRoomBackground(localNumbers[kWestRoom], kWestRoom, roomV);
DrawARoomsObjects(kWestRoom, soft);
DrawARoomsObjects(kWestRoom, false);
DrawLighting();
numLights = GetNumberOfLights(localNumbers[kEastRoom]);
DrawRoomBackground(localNumbers[kEastRoom], kEastRoom, roomV);
DrawARoomsObjects(kEastRoom, soft);
DrawARoomsObjects(kEastRoom, false);
DrawLighting();
}

View File

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

View File

@@ -146,6 +146,7 @@
<ClInclude Include="AEHandlerDesc.h" />
<ClInclude Include="AEManager.h" />
<ClInclude Include="AntiAliasTable.h" />
<ClInclude Include="ArrayTools.h" />
<ClInclude Include="BinarySearch.h" />
<ClInclude Include="BinHex4.h" />
<ClInclude Include="BitmapImage.h" />

View File

@@ -480,6 +480,9 @@
<ClInclude Include="TextPlacer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ArrayTools.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CFileStream.cpp">