Working up to start of menu loading

This commit is contained in:
elasota
2019-12-12 23:37:40 -05:00
parent f7335a2c8b
commit c9c6976344
35 changed files with 1316 additions and 398 deletions

View File

@@ -191,7 +191,8 @@ Boolean DoWeHaveSoundManager3 (void)
Boolean DoWeHaveQuickTime (void)
{
return true;
PL_NotYetImplemented_TODO();
return false;
}
//-------------------------------------------------------------- DoWeHaveDragManager
@@ -214,14 +215,14 @@ short WhatsOurDepth (void)
{
case PortabilityLayer::PixelFormat_8BitCustom:
case PortabilityLayer::PixelFormat_8BitStandard:
return 8;
return 8;
case PortabilityLayer::PixelFormat_RGB555:
return 16;
return 16;
case PortabilityLayer::PixelFormat_RGB24:
case PortabilityLayer::PixelFormat_RGB32:
return 32;
default:
return 0;
return 0;
}
}

View File

@@ -446,9 +446,7 @@ void DoSettingsMain (void); // --- Settings.c
void PlayPrioritySound (SInt16, SInt16); // --- Sound.c
void FlushAnyTriggerPlaying (void);
void PlaySound0 (SInt16, SInt16);
void PlaySound1 (SInt16, SInt16);
void PlaySound2 (SInt16, SInt16);
void PlayExclusiveSoundChannel (SInt16, SInt16, SInt16, SInt16);
OSErr LoadTriggerSound (SInt16);
void DumpTriggerSound (void);
void InitSound (void);

View File

@@ -11,7 +11,7 @@
typedef struct
{
Point topLeft; // 4
short distance; // 2
int16_t distance; // 2
Boolean initial; // 1
Boolean state; // 1 F. lf. dn. rt. up
Byte vector; // 1 | x | x | x | x | 8 | 4 | 2 | 1 |
@@ -21,14 +21,14 @@ typedef struct
typedef struct
{
Rect bounds; // 8
short pict; // 2
int16_t pict; // 2
} furnitureType; // total = 10
typedef struct
{
Point topLeft; // 4
short length; // 2 grease spill
short points; // 2 invis bonus
int16_t length; // 2 grease spill
int16_t points; // 2 invis bonus
Boolean state; // 1
Boolean initial; // 1
} bonusType; // total = 10
@@ -36,8 +36,8 @@ typedef struct
typedef struct
{
Point topLeft; // 4
short tall; // 2 invis transport
short where; // 2
int16_t tall; // 2 invis transport
int16_t where; // 2
Byte who; // 1
Byte wide; // 1
} transportType; // total = 10
@@ -45,8 +45,8 @@ typedef struct
typedef struct
{
Point topLeft; // 4
short delay; // 2
short where; // 2
int16_t delay; // 2
int16_t where; // 2
Byte who; // 1
Byte type; // 1
} switchType; // total = 10
@@ -54,7 +54,7 @@ typedef struct
typedef struct
{
Point topLeft; // 4
short length; // 2
int16_t length; // 2
Byte byte0; // 1
Byte byte1; // 1
Boolean initial; // 1
@@ -64,7 +64,7 @@ typedef struct
typedef struct
{
Point topLeft; // 4
short height; // 2 toaster, pict ID
int16_t height; // 2 toaster, pict ID
Byte byte0; // 1
Byte delay; // 1
Boolean initial; // 1
@@ -74,7 +74,7 @@ typedef struct
typedef struct
{
Point topLeft; // 4
short length; // 2
int16_t length; // 2
Byte delay; // 1
Byte byte0; // 1
Boolean initial; // 1
@@ -84,12 +84,12 @@ typedef struct
typedef struct
{
Rect bounds; // 8
short pict; // 2
int16_t pict; // 2
} clutterType; // total = 10
typedef struct
{
short what; // 2
int16_t what; // 2
union
{
blowerType a;
@@ -110,25 +110,25 @@ typedef struct
Str15 names[kMaxScores]; // 16 * 10 = 160
Int32 scores[kMaxScores]; // 4 * 10 = 40
UInt32 timeStamps[kMaxScores]; // 4 * 10 = 40
short levels[kMaxScores]; // 2 * 10 = 20
int16_t levels[kMaxScores]; // 2 * 10 = 20
} scoresType; // total = 292
typedef struct
{
short version; // 2
short wasStarsLeft; // 2
int16_t version; // 2
int16_t wasStarsLeft; // 2
UInt32 timeStamp; // 4
Point where; // 4
Int32 score; // 4
Int32 unusedLong; // 4
Int32 unusedLong2; // 4
short energy; // 2
short bands; // 2
short roomNumber; // 2
short gliderState; // 2
short numGliders; // 2
short foil; // 2
short unusedShort; // 2
int16_t energy; // 2
int16_t bands; // 2
int16_t roomNumber; // 2
int16_t gliderState; // 2
int16_t numGliders; // 2
int16_t foil; // 2
int16_t unusedShort; // 2
Boolean facing; // 1
Boolean showFoil; // 1
} gameType; // total = 40
@@ -166,25 +166,25 @@ typedef struct
typedef struct
{
Str27 name; // 28
short bounds; // 2
int16_t bounds; // 2
Byte leftStart; // 1
Byte rightStart; // 1
Byte unusedByte; // 1
Boolean visited; // 1
short background; // 2
short tiles[kNumTiles]; // 2 * 8
short floor, suite; // 2 + 2
short openings; // 2
short numObjects; // 2
int16_t background; // 2
int16_t tiles[kNumTiles]; // 2 * 8
int16_t floor, suite; // 2 + 2
int16_t openings; // 2
int16_t numObjects; // 2
objectType objects[kMaxRoomObs]; // 24 * 12
} roomType, *roomPtr; // total = 348
typedef struct
{
short version; // 2
short unusedShort; // 2
long timeStamp; // 4
long flags; // 4 (bit 0 = wardBit)
int16_t version; // 2
int16_t unusedShort; // 2
int32_t timeStamp; // 4
int32_t flags; // 4 (bit 0 = wardBit)
Point initial; // 4
Str255 banner; // 256
Str255 trailer; // 256
@@ -192,8 +192,8 @@ typedef struct
gameType savedGame; // 40
Boolean hasGame; // 1
Boolean unusedBoolean; // 1
short firstRoom; // 2
short nRooms; // 2
int16_t firstRoom; // 2
int16_t nRooms; // 2
roomType rooms[1]; // 348 * nRooms
} houseType, *housePtr, **houseHand; // total = 866 +

View File

@@ -182,6 +182,7 @@
<ClCompile Include="SelectHouse.cpp" />
<ClCompile Include="Settings.cpp" />
<ClCompile Include="Sound.cpp" />
<ClCompile Include="SoundSync_Win32.cpp" />
<ClCompile Include="StringUtils.cpp" />
<ClCompile Include="StructuresInit.cpp" />
<ClCompile Include="StructuresInit2.cpp" />
@@ -198,6 +199,35 @@
<Project>{6ec62b0f-9353-40a4-a510-3788f1368b33}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClInclude Include="About.h" />
<ClInclude Include="DialogUtils.h" />
<ClInclude Include="DynamicMaps.h" />
<ClInclude Include="Environ.h" />
<ClInclude Include="Externs.h" />
<ClInclude Include="GameOver.h" />
<ClInclude Include="GliderDefines.h" />
<ClInclude Include="GliderProtos.h" />
<ClInclude Include="GliderStructs.h" />
<ClInclude Include="GliderVars.h" />
<ClInclude Include="House.h" />
<ClInclude Include="MainWindow.h" />
<ClInclude Include="Map.h" />
<ClInclude Include="Marquee.h" />
<ClInclude Include="ObjectEdit.h" />
<ClInclude Include="Objects.h" />
<ClInclude Include="Play.h" />
<ClInclude Include="Player.h" />
<ClInclude Include="Prefix.h" />
<ClInclude Include="RectUtils.h" />
<ClInclude Include="Room.h" />
<ClInclude Include="RoomGraphics.h" />
<ClInclude Include="RubberBands.h" />
<ClInclude Include="Scoreboard.h" />
<ClInclude Include="SoundSync.h" />
<ClInclude Include="Tools.h" />
<ClInclude Include="Utilities.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@@ -210,5 +210,91 @@
<ClCompile Include="GpAppInterface.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SoundSync_Win32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SoundSync.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="About.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DialogUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DynamicMaps.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Environ.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Externs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GameOver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GliderDefines.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GliderProtos.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GliderStructs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GliderVars.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="House.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MainWindow.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Map.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Marquee.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ObjectEdit.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Objects.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Play.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Player.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Prefix.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RectUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Room.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RoomGraphics.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RubberBands.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Scoreboard.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Tools.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Utilities.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -313,6 +313,302 @@ Boolean SaveHouseAs (void)
// With a house open, this function reads in the actual bits of data<74>
// into memory.
void ByteSwapPoint(Point *point)
{
PortabilityLayer::ByteSwap::BigInt16(point->h);
PortabilityLayer::ByteSwap::BigInt16(point->v);
}
void ByteSwapRect(Rect *rect)
{
PortabilityLayer::ByteSwap::BigInt16(rect->top);
PortabilityLayer::ByteSwap::BigInt16(rect->left);
PortabilityLayer::ByteSwap::BigInt16(rect->bottom);
PortabilityLayer::ByteSwap::BigInt16(rect->right);
}
void ByteSwapScores(scoresType *scores)
{
for (int i = 0; i < kMaxScores; i++)
PortabilityLayer::ByteSwap::BigInt32(scores->scores[i]);
for (int i = 0; i < kMaxScores; i++)
PortabilityLayer::ByteSwap::BigUInt32(scores->timeStamps[i]);
for (int i = 0; i < kMaxScores; i++)
PortabilityLayer::ByteSwap::BigInt16(scores->levels[i]);
}
void ByteSwapSavedGame(gameType *game)
{
PortabilityLayer::ByteSwap::BigInt16(game->version);
PortabilityLayer::ByteSwap::BigInt16(game->wasStarsLeft);
PortabilityLayer::ByteSwap::BigUInt32(game->timeStamp);
ByteSwapPoint(&game->where);
PortabilityLayer::ByteSwap::BigInt32(game->score);
PortabilityLayer::ByteSwap::BigInt32(game->unusedLong);
PortabilityLayer::ByteSwap::BigInt32(game->unusedLong2);
PortabilityLayer::ByteSwap::BigInt16(game->energy);
PortabilityLayer::ByteSwap::BigInt16(game->bands);
PortabilityLayer::ByteSwap::BigInt16(game->roomNumber);
PortabilityLayer::ByteSwap::BigInt16(game->gliderState);
PortabilityLayer::ByteSwap::BigInt16(game->numGliders);
PortabilityLayer::ByteSwap::BigInt16(game->foil);
PortabilityLayer::ByteSwap::BigInt16(game->unusedShort);
}
void ByteSwapBlower(blowerType *blower)
{
ByteSwapPoint(&blower->topLeft);
PortabilityLayer::ByteSwap::BigInt16(blower->distance);
}
void ByteSwapFurniture(furnitureType *furniture)
{
ByteSwapRect(&furniture->bounds);
PortabilityLayer::ByteSwap::BigInt16(furniture->pict);
}
void ByteSwapBonus(bonusType *bonus)
{
ByteSwapPoint(&bonus->topLeft);
PortabilityLayer::ByteSwap::BigInt16(bonus->length);
PortabilityLayer::ByteSwap::BigInt16(bonus->points);
}
void ByteSwapTransport(transportType *transport)
{
ByteSwapPoint(&transport->topLeft);
PortabilityLayer::ByteSwap::BigInt16(transport->tall);
PortabilityLayer::ByteSwap::BigInt16(transport->where);
}
void ByteSwapSwitch(switchType *sw)
{
ByteSwapPoint(&sw->topLeft);
PortabilityLayer::ByteSwap::BigInt16(sw->delay);
PortabilityLayer::ByteSwap::BigInt16(sw->where);
}
void ByteSwapLight(lightType *light)
{
ByteSwapPoint(&light->topLeft);
PortabilityLayer::ByteSwap::BigInt16(light->length);
}
void ByteSwapAppliance(applianceType *appliance)
{
ByteSwapPoint(&appliance->topLeft);
PortabilityLayer::ByteSwap::BigInt16(appliance->height);
}
void ByteSwapEnemy(enemyType *enemy)
{
ByteSwapPoint(&enemy->topLeft);
PortabilityLayer::ByteSwap::BigInt16(enemy->length);
}
void ByteSwapClutter(clutterType *clutter)
{
ByteSwapRect(&clutter->bounds);
PortabilityLayer::ByteSwap::BigInt16(clutter->pict);
}
void ByteSwapObject(objectType *obj)
{
PortabilityLayer::ByteSwap::BigInt16(obj->what);
switch (obj->what)
{
case kFloorVent:
case kCeilingVent:
case kFloorBlower:
case kCeilingBlower:
case kSewerGrate:
case kLeftFan:
case kRightFan:
case kTaper:
case kCandle:
case kStubby:
case kTiki:
case kBBQ:
case kInvisBlower:
case kGrecoVent:
case kSewerBlower:
case kLiftArea:
ByteSwapBlower(&obj->data.a);
break;
case kTable:
case kShelf:
case kCabinet:
case kFilingCabinet:
case kWasteBasket:
case kMilkCrate:
case kCounter:
case kDresser:
case kDeckTable:
case kStool:
case kTrunk:
case kInvisObstacle:
case kManhole:
case kBooks:
case kInvisBounce:
ByteSwapFurniture(&obj->data.b);
break;
case kRedClock:
case kBlueClock:
case kYellowClock:
case kCuckoo:
case kPaper:
case kBattery:
case kBands:
case kGreaseRt:
case kGreaseLf:
case kFoil:
case kInvisBonus:
case kStar:
case kSparkle:
case kHelium:
case kSlider:
ByteSwapBonus(&obj->data.c);
break;
case kUpStairs:
case kDownStairs:
case kMailboxLf:
case kMailboxRt:
case kFloorTrans:
case kCeilingTrans:
case kDoorInLf:
case kDoorInRt:
case kDoorExRt:
case kDoorExLf:
case kWindowInLf:
case kWindowInRt:
case kWindowExRt:
case kWindowExLf:
case kInvisTrans:
case kDeluxeTrans:
ByteSwapTransport(&obj->data.d);
break;
case kLightSwitch:
case kMachineSwitch:
case kThermostat:
case kPowerSwitch:
case kKnifeSwitch:
case kInvisSwitch:
case kTrigger:
case kLgTrigger:
case kSoundTrigger:
ByteSwapSwitch(&obj->data.e);
break;
case kCeilingLight:
case kLightBulb:
case kTableLamp:
case kHipLamp:
case kDecoLamp:
case kFlourescent:
case kTrackLight:
case kInvisLight:
ByteSwapLight(&obj->data.f);
break;
case kShredder:
case kToaster:
case kMacPlus:
case kGuitar:
case kTV:
case kCoffee:
case kOutlet:
case kVCR:
case kStereo:
case kMicrowave:
case kCinderBlock:
case kFlowerBox:
case kCDs:
case kCustomPict:
ByteSwapAppliance(&obj->data.g);
break;
case kBalloon:
case kCopterLf:
case kCopterRt:
case kDartLf:
case kDartRt:
case kBall:
case kDrip:
case kFish:
case kCobweb:
ByteSwapEnemy(&obj->data.h);
break;
case kOzma:
case kMirror:
case kMousehole:
case kFireplace:
case kFlower:
case kWallWindow:
case kBear:
case kCalendar:
case kVase1:
case kVase2:
case kBulletin:
case kCloud:
case kFaucet:
case kRug:
case kChimes:
ByteSwapClutter(&obj->data.i);
break;
default:
break;
};
}
void ByteSwapRoom(roomType *room)
{
PortabilityLayer::ByteSwap::BigInt16(room->bounds);
PortabilityLayer::ByteSwap::BigInt16(room->background);
for (int i = 0; i < kNumTiles; i++)
PortabilityLayer::ByteSwap::BigInt16(room->tiles[i]);
PortabilityLayer::ByteSwap::BigInt16(room->floor);
PortabilityLayer::ByteSwap::BigInt16(room->suite);
PortabilityLayer::ByteSwap::BigInt16(room->openings);
PortabilityLayer::ByteSwap::BigInt16(room->numObjects);
for (int i = 0; i < kMaxRoomObs; i++)
ByteSwapObject(room->objects + i);
}
bool ByteSwapHouse(housePtr house, size_t sizeInBytes)
{
PortabilityLayer::ByteSwap::BigInt16(house->version);
PortabilityLayer::ByteSwap::BigInt16(house->unusedShort);
PortabilityLayer::ByteSwap::BigInt32(house->timeStamp);
PortabilityLayer::ByteSwap::BigInt32(house->flags);
ByteSwapPoint(&house->initial);
ByteSwapScores(&house->highScores);
ByteSwapSavedGame(&house->savedGame);
PortabilityLayer::ByteSwap::BigInt16(house->firstRoom);
PortabilityLayer::ByteSwap::BigInt16(house->nRooms);
const size_t roomDataSize = sizeInBytes + sizeof(roomType) - sizeof(houseType);
if (house->nRooms < 1 || roomDataSize / sizeof(roomType) < static_cast<size_t>(house->nRooms))
return false;
const size_t nRooms = static_cast<size_t>(house->nRooms);
for (size_t i = 0; i < nRooms; i++)
ByteSwapRoom(house->rooms + i);
return true;
}
Boolean ReadHouse (void)
{
long byteCount;
@@ -377,6 +673,8 @@ Boolean ReadHouse (void)
HUnlock((Handle)thisHouse);
return(false);
}
ByteSwapHouse(*thisHouse, static_cast<size_t>(byteCount));
numberRooms = (*thisHouse)->nRooms;
#ifdef COMPILEDEMO
@@ -451,6 +749,8 @@ Boolean WriteHouse (Boolean checkIt)
UInt32 timeStamp;
long byteCount;
OSErr theErr;
PL_NotYetImplemented();
if (!houseOpen)
{
@@ -488,7 +788,9 @@ Boolean WriteHouse (Boolean checkIt)
(*thisHouse)->timeStamp = (long)timeStamp;
(*thisHouse)->version = wasHouseVersion;
}
ByteSwapHouse(*thisHouse, static_cast<size_t>(byteCount));
theErr = FSWrite(houseRefNum, &byteCount, *thisHouse);
if (theErr != noErr)
{
@@ -497,6 +799,8 @@ Boolean WriteHouse (Boolean checkIt)
return(false);
}
ByteSwapHouse(*thisHouse, static_cast<size_t>(byteCount));
theErr = SetEOF(houseRefNum, byteCount);
if (theErr != noErr)
{

View File

@@ -15,6 +15,7 @@
#include "Environ.h"
#include "House.h"
#include "RectUtils.h"
#include "VirtualDirectory.h"
#define kLoadHouseDialogID 1000
@@ -557,8 +558,6 @@ void SortHouseList (void)
void DoDirSearch (void)
{
#define kMaxDirectories 32
CInfoPBRec theBlock;
Str255 nameString;
long theDirs[kMaxDirectories];
OSErr theErr, notherErr;
short count, i, currentDir, numDirs;
@@ -566,51 +565,32 @@ void DoDirSearch (void)
for (i = 0; i < kMaxDirectories; i++)
theDirs[i] = 0L;
currentDir = 0;
theDirs[currentDir] = thisMac.dirID;
theDirs[currentDir] = PortabilityLayer::EVirtualDirectory_GameData;
numDirs = 1;
theBlock.hFileInfo.ioCompletion = nil;
theBlock.hFileInfo.ioVRefNum = thisMac.vRefNum;
theBlock.hFileInfo.ioNamePtr = nameString;
while ((currentDir < numDirs) && (currentDir < kMaxDirectories))
{
count = 1;
theErr = noErr;
while (theErr == noErr)
long dirID = theDirs[currentDir];
DirectoryFileListEntry *firstFile = GetDirectoryFiles(theDirs[currentDir]);
for (DirectoryFileListEntry *f = firstFile; f; f = f->nextEntry)
{
SpinCursor(1);
theBlock.hFileInfo.ioFDirIndex = count;
theBlock.hFileInfo.ioDirID = theDirs[currentDir];
theErr = PBGetCatInfo(&theBlock, false);
if (theErr == noErr)
if ((f->finderInfo.fdType == 'gliH') && (f->finderInfo.fdCreator == 'ozm5') && (housesFound < maxFiles))
{
if ((theBlock.hFileInfo.ioFlAttrib & 0x10) == 0x00)
{
if ((theBlock.hFileInfo.ioFlFndrInfo.fdType == 'gliH') &&
(theBlock.hFileInfo.ioFlFndrInfo.fdCreator == 'ozm5') &&
(housesFound < maxFiles))
{
notherErr = FSMakeFSSpec(thisMac.vRefNum,
theBlock.hFileInfo.ioFlParID, nameString,
&theHousesSpecs[housesFound]);
if (notherErr == noErr)
housesFound++;
}
}
else if ((theBlock.hFileInfo.ioFlAttrib & 0x10) == 0x10)
{
if (numDirs < kMaxDirectories)
{
theDirs[numDirs] = theBlock.hFileInfo.ioDirID;
numDirs++;
}
}
count++;
notherErr = FSMakeFSSpec(thisMac.vRefNum, theDirs[currentDir], f->name, &theHousesSpecs[housesFound]);
if (notherErr == noErr)
housesFound++;
}
}
DisposeDirectoryFiles(firstFile);
currentDir++;
}

View File

@@ -9,11 +9,11 @@
#include "PLResources.h"
#include "PLSound.h"
#include "Externs.h"
#include "SoundSync.h"
#define kBaseBufferSoundID 1000
#define kMaxSounds 64
#define kNoSoundPlaying -1
void CallBack0 (SndChannelPtr, SndCommand *);
@@ -28,12 +28,10 @@ OSErr CloseSoundChannels (void);
SndCallBackUPP callBack0UPP, callBack1UPP, callBack2UPP;
SndChannelPtr channel0, channel1, channel2;
Ptr theSoundData[kMaxSounds];
short numSoundsLoaded, priority0, priority1, priority2;
short soundPlaying0, soundPlaying1, soundPlaying2;
short numSoundsLoaded;
Boolean soundLoaded[kMaxSounds], dontLoadSounds;
Boolean channelOpen, isSoundOn, failedSound;
//============================================================== Functions
//-------------------------------------------------------------- PlayPrioritySound
@@ -43,44 +41,33 @@ void PlayPrioritySound (short which, short priority)
if (failedSound || dontLoadSounds)
return;
SoundSyncState ss = SoundSync_ReadAll();
if ((priority == kTriggerPriority) &&
((priority0 == kTriggerPriority) ||
((priority1 == kTriggerPriority)) ||
((priority2 == kTriggerPriority))))
((ss.priority0 == kTriggerPriority) ||
((ss.priority1 == kTriggerPriority)) ||
((ss.priority2 == kTriggerPriority))))
return;
whosLowest = 0;
lowestPriority = priority0;
lowestPriority = ss.priority0;
if (priority1 < lowestPriority)
if (ss.priority1 < lowestPriority)
{
lowestPriority = priority1;
lowestPriority = ss.priority1;
whosLowest = 1;
}
if (priority2 < lowestPriority)
if (ss.priority2 < lowestPriority)
{
lowestPriority = priority2;
lowestPriority = ss.priority2;
whosLowest = 2;
}
if (priority >= lowestPriority)
{
switch (whosLowest)
{
case 0:
PlaySound0(which, priority);
break;
case 1:
PlaySound1(which, priority);
break;
case 2:
PlaySound2(which, priority);
break;
}
PlayExclusiveSoundChannel(whosLowest, which, lowestPriority, priority);
}
}
@@ -90,8 +77,10 @@ void FlushAnyTriggerPlaying (void)
{
SndCommand theCommand;
OSErr theErr;
SoundSyncState ss = SoundSync_ReadAll();
if (priority0 == kTriggerPriority)
if (ss.priority0 == kTriggerPriority)
{
theCommand.cmd = quietCmd;
theCommand.param1 = 0;
@@ -103,7 +92,7 @@ void FlushAnyTriggerPlaying (void)
theErr = SndDoImmediate(channel0, &theCommand);
}
if (priority1 == kTriggerPriority)
if (ss.priority1 == kTriggerPriority)
{
theCommand.cmd = quietCmd;
theCommand.param1 = 0;
@@ -115,7 +104,7 @@ void FlushAnyTriggerPlaying (void)
theErr = SndDoImmediate(channel1, &theCommand);
}
if (priority2 == kTriggerPriority)
if (ss.priority2 == kTriggerPriority)
{
theCommand.cmd = quietCmd;
theCommand.param1 = 0;
@@ -130,85 +119,63 @@ void FlushAnyTriggerPlaying (void)
//-------------------------------------------------------------- PlaySound0
void PlaySound0 (short soundID, short priority)
void PlayExclusiveSoundChannel(short channelIndex, short soundID, short oldPriority, short newPriority)
{
SndCommand theCommand;
OSErr theErr;
if (failedSound || dontLoadSounds)
return;
theErr = noErr;
if (isSoundOn)
SndChannelPtr channel = nil;
switch (channelIndex)
{
priority0 = priority;
soundPlaying0 = soundID;
theCommand.cmd = bufferCmd;
theCommand.param1 = 0;
theCommand.param2 = (intptr_t)(theSoundData[soundID]);
theErr = SndDoImmediate(channel0, &theCommand);
theCommand.cmd = callBackCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoCommand(channel0, &theCommand, true);
case 0:
channel = channel0;
break;
case 1:
channel = channel2;
break;
case 2:
channel = channel2;
break;
default:
return;
}
}
//-------------------------------------------------------------- PlaySound1
void PlaySound1 (short soundID, short priority)
{
SndCommand theCommand;
OSErr theErr;
if (failedSound || dontLoadSounds)
return;
theErr = noErr;
if (isSoundOn)
{
priority1 = priority;
soundPlaying1 = soundID;
if (oldPriority != 0)
{
// Flush the queue and stop the channel, which will remove the pending callback
theCommand.cmd = flushCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoImmediate(channel, &theCommand);
theCommand.cmd = quietCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoImmediate(channel, &theCommand);
SoundSync_ClearPriority(channelIndex);
}
SoundSync_PutPriority(channelIndex, newPriority);
theCommand.cmd = bufferCmd;
theCommand.param1 = 0;
theCommand.param2 = (intptr_t)(theSoundData[soundID]);
theErr = SndDoImmediate(channel1, &theCommand);
theErr = SndDoCommand(channel, &theCommand, true);
theCommand.cmd = callBackCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoCommand(channel1, &theCommand, true);
}
}
theErr = SndDoCommand(channel, &theCommand, true);
//-------------------------------------------------------------- PlaySound2
void PlaySound2 (short soundID, short priority)
{
SndCommand theCommand;
OSErr theErr;
if (failedSound || dontLoadSounds)
return;
theErr = noErr;
if (isSoundOn)
{
theCommand.cmd = bufferCmd;
theCommand.param1 = 0;
theCommand.param2 = (intptr_t)(theSoundData[soundID]);
theErr = SndDoImmediate(channel2, &theCommand);
theCommand.cmd = callBackCmd;
theCommand.param1 = 0;
theCommand.param2 = 0;
theErr = SndDoCommand(channel2, &theCommand, true);
priority2 = priority;
soundPlaying2 = soundID;
if (theErr != noErr)
SoundSync_ClearPriority(channelIndex);
}
}
@@ -216,24 +183,21 @@ void PlaySound2 (short soundID, short priority)
void CallBack0 (SndChannelPtr theChannel, SndCommand *theCommand)
{
priority0 = 0;
soundPlaying0 = kNoSoundPlaying;
SoundSync_ClearPriority(0);
}
//-------------------------------------------------------------- CallBack1
void CallBack1 (SndChannelPtr theChannel, SndCommand *theCommand)
{
priority1 = 0;
soundPlaying1 = kNoSoundPlaying;
SoundSync_ClearPriority(1);
}
//-------------------------------------------------------------- CallBack2
void CallBack2 (SndChannelPtr theChannel, SndCommand *theCommand)
{
priority2 = 0;
soundPlaying2 = kNoSoundPlaying;
SoundSync_ClearPriority(2);
}
//-------------------------------------------------------------- LoadTriggerSound
@@ -423,13 +387,10 @@ void InitSound (void)
channel0 = nil;
channel1 = nil;
channel2 = nil;
priority0 = 0;
priority1 = 0;
priority2 = 0;
soundPlaying0 = kNoSoundPlaying;
soundPlaying1 = kNoSoundPlaying;
soundPlaying2 = kNoSoundPlaying;
SoundSync_ClearPriority(0);
SoundSync_ClearPriority(1);
SoundSync_ClearPriority(2);
theErr = LoadBufferSounds();
if (theErr != noErr)

15
GpApp/SoundSync.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
struct SoundSyncState
{
int16_t priority0;
int16_t priority1;
int16_t priority2;
int16_t priority3;
};
SoundSyncState SoundSync_ReadAll();
void SoundSync_ClearPriority(int index);
void SoundSync_PutPriority(int index, int16_t priority);

31
GpApp/SoundSync_Win32.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include "SoundSync.h"
#include <Windows.h>
#include <string.h>
static volatile uint64_t gs_prioritiesBlob = 0;
SoundSyncState SoundSync_ReadAll()
{
const uint16_t priorities = gs_prioritiesBlob;
SoundSyncState state;
state.priority0 = static_cast<uint16_t>((priorities >> 0) & 0xffff);
state.priority1 = static_cast<uint16_t>((priorities >> 16) & 0xffff);
state.priority2 = static_cast<uint16_t>((priorities >> 32) & 0xffff);
state.priority3 = static_cast<uint16_t>((priorities >> 48) & 0xffff);
return state;
}
void SoundSync_ClearPriority(int index)
{
const uint64_t clearMask = ~(static_cast<int64_t>(0xffff) << (index * 16));
InterlockedAnd(&gs_prioritiesBlob, clearMask);
}
void SoundSync_PutPriority(int index, int16_t priority)
{
const uint64_t insertMask = static_cast<int64_t>(priority) << (index * 16);
InterlockedOr(&gs_prioritiesBlob, insertMask);
}