diff --git a/GpApp/About.cpp b/GpApp/About.cpp index 8742e5f..f63c19e 100644 --- a/GpApp/About.cpp +++ b/GpApp/About.cpp @@ -12,6 +12,7 @@ #include "PLSound.h" #include "PLPasStr.h" #include "PLSysCalls.h" +#include "PLTimeTaggedVOSEvent.h" #include "PLWidgets.h" #include "About.h" #include "DialogManager.h" @@ -19,8 +20,8 @@ #include "Environ.h" #include "Externs.h" #include "HostSystemServices.h" +#include "ResourceManager.h" #include "ScanlineMask.h" -#include "PLTimeTaggedVOSEvent.h" static void HiLiteOkayButton (DrawSurface *surface); @@ -49,16 +50,13 @@ void DoAbout (void) StringPtr messagePtr; VersRecHndl version; ControlHandle itemHandle; - short hit, wasResFile; - - wasResFile = CurResFile(); - UseResFile(thisMac.thisResFile); + short hit; aboutDialog = PortabilityLayer::DialogManager::GetInstance()->LoadDialog(kAboutDialogID, PL_GetPutInFrontWindowPtr()); // if (aboutDialog == nil) // RedAlert(kErrDialogDidntLoad); - version = GetResource('vers', 1).StaticCast(); + version = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('vers', 1).StaticCast(); if (version != nil) { messagePtr = (**version).shortVersion + 1 + (**version).shortVersion[0]; @@ -86,8 +84,6 @@ void DoAbout (void) while (hit != kOkayButton); aboutDialog->Destroy(); - - UseResFile(wasResFile); } //============================================================== Static Functions @@ -101,7 +97,7 @@ static void HiLiteOkayButton (DrawSurface *surface) if (!okayButtIsHiLit) { - thePict = GetPicture(kOkayButtPICTHiLit); + thePict = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', kOkayButtPICTHiLit).StaticCast(); if (thePict != nil) { surface->DrawPicture(thePict, okayButtonBounds); @@ -123,7 +119,7 @@ static void UnHiLiteOkayButton (DrawSurface *surface) if (okayButtIsHiLit) { - thePict = GetPicture(kOkayButtPICTNotHiLit); + thePict = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', kOkayButtPICTNotHiLit).StaticCast(); if (thePict != nil) { surface->DrawPicture(thePict, okayButtonBounds); diff --git a/GpApp/AnimCursor.cpp b/GpApp/AnimCursor.cpp index e3d5840..e2cb6d4 100644 --- a/GpApp/AnimCursor.cpp +++ b/GpApp/AnimCursor.cpp @@ -13,6 +13,7 @@ #include "HostDisplayDriver.h" #include "IGpColorCursor.h" #include "IGpDisplayDriver.h" +#include "ResourceManager.h" #define rAcurID 128 @@ -97,7 +98,7 @@ void InitAnimatedCursor (acurHandle ballCursH) compiledAcurHandle compiledBallCursorH; if (ballCursH == nil) - ballCursH = GetResource('acur', 128).StaticCast(); + ballCursH = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('acur', 128).StaticCast(); if (ballCursH && ballCursH != animCursorH) { compiledBallCursorH = NewHandle(sizeof(compiledAcurRec) * (*ballCursH)->n).StaticCast(); @@ -122,7 +123,7 @@ void InitAnimatedCursor (acurHandle ballCursH) void LoadCursors (void) { - InitAnimatedCursor(GetResource('acur', rAcurID).StaticCast()); + InitAnimatedCursor(PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('acur', rAcurID).StaticCast()); } //-------------------------------------------------------------- DisposCursors diff --git a/GpApp/Coordinates.cpp b/GpApp/Coordinates.cpp index 898ddee..a812486 100644 --- a/GpApp/Coordinates.cpp +++ b/GpApp/Coordinates.cpp @@ -13,6 +13,7 @@ #include "Marquee.h" #include "ObjectEdit.h" #include "RectUtils.h" +#include "WindowDef.h" #include "WindowManager.h" @@ -126,13 +127,15 @@ void OpenCoordWindow (void) if (coordWindow == nil) { + const uint16_t windowStyle = PortabilityLayer::WindowStyleFlags::kTitleBar | PortabilityLayer::WindowStyleFlags::kMiniBar; + QSetRect(&coordWindowRect, 0, 0, 50, 38); if (thisMac.hasColor) coordWindow = NewCWindow(nil, &coordWindowRect, - PSTR("Tools"), false, kWindoidWDEF, kPutInFront, true, 0L); + PSTR("Tools"), false, windowStyle, kPutInFront, true, 0L); else coordWindow = NewWindow(nil, &coordWindowRect, - PSTR("Tools"), false, kWindoidWDEF, kPutInFront, true, 0L); + PSTR("Tools"), false, windowStyle, kPutInFront, true, 0L); if (coordWindow == nil) RedAlert(kErrNoMemory); diff --git a/GpApp/DialogUtils.cpp b/GpApp/DialogUtils.cpp index 6302673..02afff5 100644 --- a/GpApp/DialogUtils.cpp +++ b/GpApp/DialogUtils.cpp @@ -15,7 +15,7 @@ #include "DialogUtils.h" #include "Externs.h" #include "FontFamily.h" - +#include "ResourceManager.h" #define kActive 0 #define kInactive 255 @@ -144,7 +144,7 @@ void GetDialogRect (Rect *bounds, short dialogID) { Byte wasState; - Handle dlogHandle = GetResource('DLOG', dialogID).StaticCast(); + Handle dlogHandle = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('DLOG', dialogID).StaticCast(); if (dlogHandle != nil) { BERect dataRect = **dlogHandle.StaticCast(); @@ -693,7 +693,7 @@ void LoadDialogPICT (Dialog *theDialog, short item, short theID) Rect iRect = theDialog->GetItems()[item - 1].GetWidget()->GetRect();; - thePict = GetPicture(theID); + thePict = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', theID).StaticCast(); if (thePict) theDialog->GetWindow()->GetDrawSurface()->DrawPicture(thePict, iRect); } diff --git a/GpApp/Environ.cpp b/GpApp/Environ.cpp index 467e512..5ecad82 100644 --- a/GpApp/Environ.cpp +++ b/GpApp/Environ.cpp @@ -279,7 +279,6 @@ short HowManyUsableScreens (Boolean use1Bit, Boolean use4Bit, Boolean use8Bit) void CheckOurEnvirons (void) { - thisMac.thisResFile = CurResFile(); thisMac.vRefNum = 0; // TEMP thisMac.dirID = 0; // TEMP thisMac.hasGestalt = true; // TEMP diff --git a/GpApp/Environ.h b/GpApp/Environ.h index 456b4fa..8e6dad3 100644 --- a/GpApp/Environ.h +++ b/GpApp/Environ.h @@ -13,7 +13,6 @@ typedef struct Rect screen, gray; long dirID; short wasDepth, isDepth; - short thisResFile; short numScreens; short vRefNum; Boolean can1Bit; diff --git a/GpApp/Externs.h b/GpApp/Externs.h index c58dcf4..437b276 100644 --- a/GpApp/Externs.h +++ b/GpApp/Externs.h @@ -15,6 +15,7 @@ namespace PortabilityLayer { class ResourceArchive; class ScanlineMask; + class ResTypeID; } #define kPreferredDepth 8 @@ -174,6 +175,8 @@ void SetAppMemorySize (long); Boolean CheckFileError (short, const PLPasStr &); // --- File Error.c +THandle LoadHouseResource(const PortabilityLayer::ResTypeID &resTypeID, int16_t resID); // --- HouseIO.c + Boolean SavePrefs (prefsInfo *, short); // --- Prefs.c Boolean LoadPrefs (prefsInfo *, short); @@ -193,8 +196,10 @@ void FindOurDevice (void); short RandomInt (short); long RandomLong (long); void RedAlert (short); -void LoadGraphic (DrawSurface *, short); -void LoadScaledGraphic (DrawSurface *, short, Rect *); +void LoadGraphic (DrawSurface *surface, short resID); // Only loads from app resources +void LoadGraphicCustom (DrawSurface *surface, short resID); // Supports custom graphics +void LoadScaledGraphic (DrawSurface *, short, Rect *); // Only loads from app resources +void LoadScaledGraphicCustom (DrawSurface *, short, Rect *); // Supports custom graphics bool LargeIconPlot (DrawSurface *, PortabilityLayer::ResourceArchive *, short, const Rect &); void DrawCIcon (DrawSurface *surface, short, short, short); char KeyMapOffsetFromRawKey (char); @@ -226,6 +231,7 @@ void CloseThisWindow (WindowPtr *); // THREEWORDINLINE(0x4218, 0x10B8, 0x0260); #endif + #include "GliderDefines.h" #include "GliderStructs.h" #include "GliderVars.h" diff --git a/GpApp/GliderDefines.h b/GpApp/GliderDefines.h index ce5ff9e..bbe5861 100644 --- a/GpApp/GliderDefines.h +++ b/GpApp/GliderDefines.h @@ -528,8 +528,6 @@ #define kInitialGliderSelected -2 #define kLeftGliderSelected -3 #define kRightGliderSelected -4 -#define kWindoidWDEF 2048 -#define kWindoidGrowWDEF 2064 #define kTicksPerFrame 2 #define kStarPictID 1995 #define kNumUndergroundFloors 8 diff --git a/GpApp/House.cpp b/GpApp/House.cpp index 58c8b2a..1ebd46e 100644 --- a/GpApp/House.cpp +++ b/GpApp/House.cpp @@ -242,8 +242,9 @@ void WhereDoesGliderBegin (Rect *theRect, short mode) Boolean HouseHasOriginalPicts (void) { short nPicts; - - nPicts = Count1Resources('PICT'); + + PL_NotYetImplemented(); nPicts = 0; + //nPicts = Count1Resources('PICT'); return (nPicts > 0); } diff --git a/GpApp/HouseIO.cpp b/GpApp/HouseIO.cpp index 85bccc4..f63f09e 100644 --- a/GpApp/HouseIO.cpp +++ b/GpApp/HouseIO.cpp @@ -15,6 +15,7 @@ #include "Environ.h" #include "FileManager.h" #include "HostFileSystem.h" +#include "HostSystemServices.h" #include "House.h" #include "IOStream.h" #include "ObjectEdit.h" @@ -34,12 +35,14 @@ Boolean IsFileReadOnly (const VFileSpec &); Movie theMovie; Rect movieRect; -short houseResFork, wasHouseVersion; +PortabilityLayer::ResourceArchive *houseResFork; +short wasHouseVersion; PortabilityLayer::IOStream *houseStream; Boolean houseOpen, fileDirty, gameDirty; Boolean changeLockStateOfHouse, saveHouseLocked, houseIsReadOnly; Boolean hasMovie, tvInRoom; + extern VFileSpec *theHousesSpecs; extern short thisHouseIndex, tvWithMovieNumber; extern short numberRooms, housesFound; @@ -324,8 +327,28 @@ void ByteSwapRect(Rect *rect) PortabilityLayer::ByteSwap::BigInt16(rect->right); } +template +void SanitizePascalStr(uint8_t(&chars)[TSize]) +{ + const size_t maxLength = TSize - 1; + size_t strLength = chars[0]; + if (strLength > maxLength) + { + strLength = maxLength; + chars[0] = static_cast(maxLength); + } + + for (size_t i = 1 + strLength; i < TSize; i++) + chars[i] = 0; +} + void ByteSwapScores(scoresType *scores) { + SanitizePascalStr(scores->banner); + + for (int i = 0; i < kMaxScores; i++) + SanitizePascalStr(scores->names[i]); + for (int i = 0; i < kMaxScores; i++) PortabilityLayer::ByteSwap::BigInt32(scores->scores[i]); @@ -568,6 +591,8 @@ void ByteSwapObject(objectType *obj) void ByteSwapRoom(roomType *room) { + SanitizePascalStr(room->name); + PortabilityLayer::ByteSwap::BigInt16(room->bounds); PortabilityLayer::ByteSwap::BigInt16(room->background); @@ -590,19 +615,23 @@ bool ByteSwapHouse(housePtr house, size_t sizeInBytes) PortabilityLayer::ByteSwap::BigInt32(house->timeStamp); PortabilityLayer::ByteSwap::BigInt32(house->flags); ByteSwapPoint(&house->initial); + SanitizePascalStr(house->banner); + SanitizePascalStr(house->trailer); ByteSwapScores(&house->highScores); ByteSwapSavedGame(&house->savedGame); PortabilityLayer::ByteSwap::BigInt16(house->firstRoom); PortabilityLayer::ByteSwap::BigInt16(house->nRooms); const size_t roomDataSize = sizeInBytes - houseType::kBinaryDataSize; - if (house->nRooms < 1 || roomDataSize / sizeof(roomType) < static_cast(house->nRooms)) + if (house->nRooms < 0 || roomDataSize / sizeof(roomType) < static_cast(house->nRooms)) return false; const size_t nRooms = static_cast(house->nRooms); for (size_t i = 0; i < nRooms; i++) ByteSwapRoom(house->rooms + i); + house->padding = 0; + return true; } @@ -748,8 +777,6 @@ Boolean WriteHouse (Boolean checkIt) UInt32 timeStamp; long byteCount; PLError_t theErr; - - PL_NotYetImplemented(); if (!houseOpen) { @@ -772,9 +799,10 @@ Boolean WriteHouse (Boolean checkIt) if (fileDirty) { - GetDateTime(&timeStamp); - timeStamp &= 0x7FFFFFFF; - + int64_t currentTime = PortabilityLayer::HostSystemServices::GetInstance()->GetTime(); + if (currentTime > 0x7fffffff) + currentTime = 0x7fffffff; + if (changeLockStateOfHouse) houseUnlocked = !saveHouseLocked; @@ -869,13 +897,11 @@ Boolean CloseHouse (void) void OpenHouseResFork (void) { PortabilityLayer::ResourceManager *rm = PortabilityLayer::ResourceManager::GetInstance(); - if (houseResFork == -1) + if (houseResFork == nullptr) { - houseResFork = rm->OpenResFork(theHousesSpecs[thisHouseIndex].m_dir, theHousesSpecs[thisHouseIndex].m_name); - if (houseResFork < 0) + houseResFork = rm->LoadResFile(theHousesSpecs[thisHouseIndex].m_dir, theHousesSpecs[thisHouseIndex].m_name); + if (!houseResFork) YellowAlert(kYellowFailedResOpen, PLErrors::kResourceError); - else - UseResFile(houseResFork); } } @@ -884,12 +910,12 @@ void OpenHouseResFork (void) void CloseHouseResFork (void) { - if (houseResFork != -1) + if (houseResFork) { PortabilityLayer::ResourceManager *rm = PortabilityLayer::ResourceManager::GetInstance(); - rm->CloseResFile(houseResFork); - houseResFork = -1; + houseResFork->Destroy(); + houseResFork = nullptr; } } @@ -965,3 +991,14 @@ Boolean IsFileReadOnly (const VFileSpec &spec) { return PortabilityLayer::FileManager::GetInstance()->FileLocked(spec.m_dir, spec.m_name); } + +//-------------------------------------------------------------- LoadHousePicture + +THandle LoadHouseResource(const PortabilityLayer::ResTypeID &resTypeID, int16_t resID) +{ + THandle hdl = houseResFork->LoadResource(resTypeID, resID); + if (hdl != nullptr) + return hdl; + + return PortabilityLayer::ResourceManager::GetInstance()->GetAppResource(resTypeID, resID); +} diff --git a/GpApp/InterfaceInit.cpp b/GpApp/InterfaceInit.cpp index 434b86e..28c45dd 100644 --- a/GpApp/InterfaceInit.cpp +++ b/GpApp/InterfaceInit.cpp @@ -35,7 +35,7 @@ extern long incrementModeTime; extern UInt32 doubleTime; extern short fadeInSequence[], idleMode; extern short toolSelected, lastBackground, wasFlower, numExtraHouses; -extern short houseResFork, lastHighScore, maxFiles, willMaxFiles; +extern short lastHighScore, maxFiles, willMaxFiles; extern Boolean quitting, playing, fadeGraysOut; extern Boolean houseOpen, newRoomNow, evenFrame, menusUp, demoGoing; extern Boolean twoPlayerGame, paused, hasMirror, splashDrawn; @@ -151,7 +151,6 @@ void VariableInit (void) thisRoomNumber = 0; previousRoom = -1; toolSelected = kSelectTool; - houseResFork = -1; lastBackground = kBaseBackgroundID; wasFlower = RandomInt(kNumFlowers); lastHighScore = -1; diff --git a/GpApp/Link.cpp b/GpApp/Link.cpp index 23b4d89..65edaa5 100644 --- a/GpApp/Link.cpp +++ b/GpApp/Link.cpp @@ -13,6 +13,7 @@ #include "RectUtils.h" #include "PLButtonWidget.h" #include "PLWidgets.h" +#include "WindowDef.h" #include "WindowManager.h" #define kLinkControlID 130 @@ -220,13 +221,15 @@ void OpenLinkWindow (void) if (linkWindow == nil) { + const uint16_t windowStyle = PortabilityLayer::WindowStyleFlags::kTitleBar | PortabilityLayer::WindowStyleFlags::kMiniBar; + QSetRect(&linkWindowRect, 0, 0, 129, 30); if (thisMac.hasColor) linkWindow = NewCWindow(nil, &linkWindowRect, - PSTR("Link"), false, kWindoidWDEF, kPutInFront, true, 0L); + PSTR("Link"), false, windowStyle, kPutInFront, true, 0L); else linkWindow = NewWindow(nil, &linkWindowRect, - PSTR("Link"), false, kWindoidWDEF, kPutInFront, true, 0L); + PSTR("Link"), false, windowStyle, kPutInFront, true, 0L); MoveWindow(linkWindow, isLinkH, isLinkV, true); diff --git a/GpApp/MainWindow.cpp b/GpApp/MainWindow.cpp index 5f764e0..1a9a6d8 100644 --- a/GpApp/MainWindow.cpp +++ b/GpApp/MainWindow.cpp @@ -242,7 +242,7 @@ void OpenMainWindow (void) Rect scorebarRect = thisMac.screen; scorebarRect.bottom = scorebarRect.top + kScoreboardTall; - PortabilityLayer::WindowDef windowDef = PortabilityLayer::WindowDef::Create(scorebarRect, 0, true, false, 0, 0, PSTR("Scoreboard")); + PortabilityLayer::WindowDef windowDef = PortabilityLayer::WindowDef::Create(scorebarRect, PortabilityLayer::WindowStyleFlags::kBorderless, true, false, 0, 0, PSTR("Scoreboard")); boardWindow = windowManager->CreateWindow(windowDef); if (boardWindow != nil) windowManager->PutWindowBehind(boardWindow, PL_GetPutInFrontWindowPtr()); diff --git a/GpApp/Map.cpp b/GpApp/Map.cpp index 48fc7b6..bc867e0 100644 --- a/GpApp/Map.cpp +++ b/GpApp/Map.cpp @@ -167,10 +167,10 @@ void LoadGraphicPlus (DrawSurface *surface, short resID, const Rect &theRect) { THandle thePicture; - thePicture = GetPicture(resID); + thePicture = LoadHouseResource('PICT', resID).StaticCast(); if (thePicture == nil) { - thePicture = GetResource('Date', resID).StaticCast(); + thePicture = LoadHouseResource('Date', resID).StaticCast(); if (thePicture == nil) { return; @@ -361,7 +361,9 @@ void OpenMapWindow (void) mapRoomsWide * kMapRoomWidth + kMapScrollBarWidth - 2, mapRoomsHigh * kMapRoomHeight + kMapScrollBarWidth - 2); - PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(mapWindowRect, kWindoidGrowWDEF, false, true, 0, 0, PSTR("Map")); + const uint16_t windowStyle = PortabilityLayer::WindowStyleFlags::kTitleBar | PortabilityLayer::WindowStyleFlags::kResizable | PortabilityLayer::WindowStyleFlags::kMiniBar; + + PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(mapWindowRect, windowStyle, false, true, 0, 0, PSTR("Map")); mapWindow = PortabilityLayer::WindowManager::GetInstance()->CreateWindow(wdef); diff --git a/GpApp/Music.cpp b/GpApp/Music.cpp index 0b167ea..dd8eb3b 100644 --- a/GpApp/Music.cpp +++ b/GpApp/Music.cpp @@ -15,6 +15,7 @@ #include "HostMutex.h" #include "HostSystemServices.h" #include "MemoryManager.h" +#include "ResourceManager.h" #define kBaseBufferMusicID 2000 @@ -212,7 +213,7 @@ PLError_t LoadMusicSounds (void) for (i = 0; i < kMaxMusic; i++) { - theSound = ParseAndConvertSound(GetResource('snd ', i + kBaseBufferMusicID)); + theSound = ParseAndConvertSound(PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('snd ', i + kBaseBufferMusicID)); if (theSound == nil) return PLErrors::kOutOfMemory; @@ -364,24 +365,18 @@ void KillMusic (void) long MusicBytesNeeded (void) { - Handle theSound; - long totalBytes; + size_t totalBytes; short i; totalBytes = 0L; - SetResLoad(false); for (i = 0; i < kMaxMusic; i++) { - theSound = GetResource('snd ', i + kBaseBufferMusicID); - if (theSound == nil) - { - SetResLoad(true); + size_t resSize = 0; + if (!PortabilityLayer::ResourceManager::GetInstance()->GetAppResourceArchive()->GetResourceSize('snd ', i + kBaseBufferMusicID, resSize)) return -1; - } - totalBytes += GetMaxResourceSize(theSound); -// ReleaseResource(theSound); + + totalBytes += static_cast(resSize); } - SetResLoad(true); return totalBytes; } diff --git a/GpApp/ObjectDraw2.cpp b/GpApp/ObjectDraw2.cpp index 8a57e1a..8d04a2c 100644 --- a/GpApp/ObjectDraw2.cpp +++ b/GpApp/ObjectDraw2.cpp @@ -15,6 +15,7 @@ #include "Environ.h" #include "Objects.h" #include "RectUtils.h" +#include "ResourceManager.h" #include "Room.h" #include "Utilities.h" #include "PLHacks.h" @@ -1052,7 +1053,7 @@ void DrawCalendar (Rect *theRect) wasCPort = GetGraphicsPort(); SetGraphicsPort(backSrcMap); - thePicture = GetPicture(kCalendarPictID); + thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', kCalendarPictID).StaticCast(); if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); @@ -1078,7 +1079,7 @@ void DrawBulletin (Rect *theRect) Rect bounds; THandle thePicture; - thePicture = GetPicture(kBulletinPictID); + thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', kBulletinPictID).StaticCast(); if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); @@ -1128,7 +1129,7 @@ void DrawPictObject (short what, Rect *theRect) break; } - thePicture = GetPicture(pictID); + thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', pictID).StaticCast(); if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); @@ -1295,7 +1296,7 @@ void DrawCustPictSansWhite (short pictID, Rect *theRect) bounds = *theRect; ZeroRectCorner(&bounds); theErr = CreateOffScreenGWorld(&tempMap, &bounds, kPreferredPixelFormat); - LoadGraphic(tempMap, pictID); + LoadGraphicCustom(tempMap, pictID); CopyBits((BitMap *)*GetGWorldPixMap(tempMap), (BitMap *)*GetGWorldPixMap(backSrcMap), diff --git a/GpApp/ObjectEdit.cpp b/GpApp/ObjectEdit.cpp index 3aec11d..251ed5e 100644 --- a/GpApp/ObjectEdit.cpp +++ b/GpApp/ObjectEdit.cpp @@ -18,6 +18,7 @@ #include "Objects.h" #include "Play.h" #include "RectUtils.h" +#include "ResourceManager.h" #include "Room.h" @@ -2237,7 +2238,7 @@ void GetThisRoomsObjRects (void) break; case kCustomPict: - thePict = GetPicture(thisRoom->objects[i].data.g.height); + thePict = LoadHouseResource('PICT', thisRoom->objects[i].data.g.height).StaticCast(); if (thePict == nil) { thisRoom->objects[i].data.g.height = 10000; diff --git a/GpApp/ObjectRects.cpp b/GpApp/ObjectRects.cpp index 316fc1b..8e45ce3 100644 --- a/GpApp/ObjectRects.cpp +++ b/GpApp/ObjectRects.cpp @@ -218,7 +218,7 @@ void GetObjectRect (objectPtr who, Rect *itsRect) break; case kCustomPict: - thePict = GetPicture(who->data.g.height); + thePict = LoadHouseResource('PICT', who->data.g.height).StaticCast(); if (thePict == nil) { who->data.g.height = 10000; diff --git a/GpApp/Room.cpp b/GpApp/Room.cpp index 18c3dc9..e3b16ad 100644 --- a/GpApp/Room.cpp +++ b/GpApp/Room.cpp @@ -261,10 +261,10 @@ void ReadyBackground (short theID, short *theTiles) return; } - thePicture = GetPicture(theID); + thePicture = LoadHouseResource('PICT', theID).StaticCast(); if (thePicture == nil) { - thePicture = GetResource('Date', theID).StaticCast(); + thePicture = LoadHouseResource('Date', theID).StaticCast(); if (thePicture == nil) { YellowAlert(kYellowNoBackground, 0); @@ -907,7 +907,10 @@ short GetOriginalBounding (short theID) boundsHand boundsRes; short boundCode; - boundsRes = GetResource('bnds', theID).StaticCast(); + boundsRes = LoadHouseResource('bnds', theID).StaticCast(); + if (boundsRes.MMBlock()->m_size != sizeof(boundsType)) + return 0; // Corrupted resource + if (boundsRes == nil) { if (PictIDExists(theID)) diff --git a/GpApp/RoomGraphics.cpp b/GpApp/RoomGraphics.cpp index f1b0f3c..130d8f4 100644 --- a/GpApp/RoomGraphics.cpp +++ b/GpApp/RoomGraphics.cpp @@ -134,13 +134,13 @@ void LoadGraphicSpecial (DrawSurface *surface, short resID) Rect bounds; THandle thePicture; - thePicture = GetPicture(resID); + thePicture = LoadHouseResource('PICT', resID).StaticCast(); if (thePicture == nil) { - thePicture = GetResource('Date', resID).StaticCast(); + thePicture = LoadHouseResource('Date', resID).StaticCast(); if (thePicture == nil) { - thePicture = GetPicture(2000); + thePicture = LoadHouseResource('PICT', 2000).StaticCast(); if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); } diff --git a/GpApp/RoomInfo.cpp b/GpApp/RoomInfo.cpp index 0561d1c..d8b3512 100644 --- a/GpApp/RoomInfo.cpp +++ b/GpApp/RoomInfo.cpp @@ -59,7 +59,7 @@ Boolean originalLeftOpen, originalTopOpen, originalRightOpen, originalBottomOpe Boolean originalFloor; extern Cursor handCursor; -extern short houseResFork, lastBackground; +extern short lastBackground; //============================================================== Functions @@ -459,9 +459,9 @@ void DoRoomInfo (void) } if ((tempBack == 2002) || (tempBack == 2011) || (tempBack == 2016) || (tempBack == 2017)) - LoadScaledGraphic(tileSrcMap, tempBack - 800, &tileSrcRect); + LoadScaledGraphicCustom(tileSrcMap, tempBack - 800, &tileSrcRect); else - LoadScaledGraphic(tileSrcMap, tempBack, &tileSrcRect); + LoadScaledGraphicCustom(tileSrcMap, tempBack, &tileSrcRect); for (i = 0; i < kNumTiles; i++) tempTiles[i] = thisRoom->tiles[i]; @@ -547,7 +547,7 @@ void DoRoomInfo (void) if ((tempBack != newBack) || (forceDraw)) { tempBack = newBack; - LoadScaledGraphic(tileSrcMap, tempBack, &tileSrcRect); + LoadScaledGraphicCustom(tileSrcMap, tempBack, &tileSrcRect); InvalWindowRect(roomInfoDialog->GetWindow(), &tileSrc); InvalWindowRect(roomInfoDialog->GetWindow(), &tileDest); } @@ -573,9 +573,9 @@ void DoRoomInfo (void) tempBack = newBack; if ((tempBack == 2002) || (tempBack == 2011) || (tempBack == 2016) || (tempBack == 2017)) - LoadScaledGraphic(tileSrcMap, tempBack - 800, &tileSrcRect); + LoadScaledGraphicCustom(tileSrcMap, tempBack - 800, &tileSrcRect); else - LoadScaledGraphic(tileSrcMap, tempBack, &tileSrcRect); + LoadScaledGraphicCustom(tileSrcMap, tempBack, &tileSrcRect); InvalWindowRect(roomInfoDialog->GetWindow(), &tileSrc); InvalWindowRect(roomInfoDialog->GetWindow(), &tileDest); } @@ -586,7 +586,7 @@ void DoRoomInfo (void) if (tempBack != newBack) { tempBack = newBack; - LoadScaledGraphic(tileSrcMap, tempBack, &tileSrcRect); + LoadScaledGraphicCustom(tileSrcMap, tempBack, &tileSrcRect); InvalWindowRect(roomInfoDialog->GetWindow(), &tileSrc); InvalWindowRect(roomInfoDialog->GetWindow(), &tileDest); } @@ -857,7 +857,7 @@ short ChooseOriginalArt (short was) Boolean PictIDExists (short theID) { - THandle thePicture; + THandle thePicture; // Handle resHandle; // Str255 resName; // ResType resType; @@ -867,10 +867,10 @@ Boolean PictIDExists (short theID) foundIt = true; - thePicture = GetPicture(theID); + thePicture = LoadHouseResource('PICT', theID); if (thePicture == nil) { - thePicture = GetResource('Date', theID).StaticCast(); + thePicture = LoadHouseResource('Date', theID); if (thePicture == nil) { foundIt = false; @@ -907,8 +907,11 @@ short GetFirstPICT (void) { Handle resHandle; Str255 resName; - - resHandle = Get1IndResource('PICT', 1); + + PL_NotYetImplemented(); + + //resHandle = Get1IndResource('PICT', 1); + resHandle = Handle(); if (resHandle != nil) { const PortabilityLayer::ResourceArchiveRef *resRef = PortabilityLayer::ResourceManager::GetInstance()->ResourceForHandle(resHandle.MMBlock()); diff --git a/GpApp/Sound.cpp b/GpApp/Sound.cpp index c921d35..26b56a5 100644 --- a/GpApp/Sound.cpp +++ b/GpApp/Sound.cpp @@ -10,6 +10,7 @@ #include "PLSound.h" #include "Externs.h" #include "MemoryManager.h" +#include "ResourceManager.h" #include "SoundSync.h" #include "VirtualDirectory.h" #include "WaveFormat.h" @@ -187,7 +188,7 @@ PLError_t LoadTriggerSound (short soundID) theErr = PLErrors::kNone; - theSound = ParseAndConvertSound(GetResource('snd ', soundID)); + theSound = ParseAndConvertSound(LoadHouseResource('snd ', soundID)); if (theSound == nil) { theErr = PLErrors::kFileNotFound; @@ -234,7 +235,7 @@ PLError_t LoadBufferSounds (void) for (i = 0; i < kMaxSounds - 1; i++) { - theSound = ParseAndConvertSound(GetResource('snd ', i + kBaseBufferSoundID)); + theSound = ParseAndConvertSound(PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('snd ', i + kBaseBufferSoundID)); if (theSound == nil) return (PLErrors::kOutOfMemory); @@ -369,24 +370,20 @@ void KillSound (void) long SoundBytesNeeded (void) { - Handle theSound; long totalBytes; short i; totalBytes = 0L; - SetResLoad(false); for (i = 0; i < kMaxSounds - 1; i++) { - theSound = GetResource('snd ', i + kBaseBufferSoundID); - if (theSound == nil) - { - SetResLoad(true); + size_t resSize = 0; + if (!PortabilityLayer::ResourceManager::GetInstance()->GetAppResourceArchive()->GetResourceSize('snd ', i + kBaseBufferSoundID, resSize)) return -1; - } - totalBytes += GetMaxResourceSize(theSound); + + totalBytes += static_cast(resSize); // ReleaseResource(theSound); } - SetResLoad(true); + return totalBytes; } diff --git a/GpApp/StructuresInit.cpp b/GpApp/StructuresInit.cpp index 95e69c6..9faa655 100644 --- a/GpApp/StructuresInit.cpp +++ b/GpApp/StructuresInit.cpp @@ -14,6 +14,7 @@ #include "Play.h" #include "Player.h" #include "RectUtils.h" +#include "ResourceManager.h" #include "RubberBands.h" #include "Scoreboard.h" #include "Utilities.h" @@ -77,7 +78,7 @@ void InitScoreboardMap (void) hOffset = (RectWide(&boardSrcRect) - kMaxViewWidth) / 2; else hOffset = -576; - thePicture = GetPicture(kScoreboardPictID); + thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', kScoreboardPictID).StaticCast(); if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); bounds = (*thePicture)->GetRect(); diff --git a/GpApp/StructuresInit2.cpp b/GpApp/StructuresInit2.cpp index 5852592..8189a59 100644 --- a/GpApp/StructuresInit2.cpp +++ b/GpApp/StructuresInit2.cpp @@ -12,6 +12,7 @@ #include "MainWindow.h" #include "Objects.h" #include "RectUtils.h" +#include "ResourceManager.h" #include "Room.h" #include "RoomGraphics.h" #include "Utilities.h" @@ -260,7 +261,7 @@ void CreatePointers (void) demoData = (demoPtr)NewPtr(kDemoLength); if (demoData == nil) RedAlert(kErrNoMemory); - tempHandle = GetResource('demo', 128); + tempHandle = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('demo', 128); if (tempHandle == nil) RedAlert(kErrNoMemory); else diff --git a/GpApp/Tools.cpp b/GpApp/Tools.cpp index a1e622f..cb81abe 100644 --- a/GpApp/Tools.cpp +++ b/GpApp/Tools.cpp @@ -300,7 +300,9 @@ void OpenToolsWindow (void) QOffsetRect(&toolTextRect, 0, 157 - 15); { - PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(toolsWindowRect, kWindoidWDEF, false, true, 0, 0, PSTR("Tools")); + const uint16_t windowStyle = PortabilityLayer::WindowStyleFlags::kTitleBar | PortabilityLayer::WindowStyleFlags::kMiniBar; + + PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(toolsWindowRect, windowStyle, false, true, 0, 0, PSTR("Tools")); toolsWindow = wm->CreateWindow(wdef); } diff --git a/GpApp/Utilities.cpp b/GpApp/Utilities.cpp index 0cfabed..257b480 100644 --- a/GpApp/Utilities.cpp +++ b/GpApp/Utilities.cpp @@ -213,7 +213,6 @@ PLError_t CreateOffScreenGWorld (DrawSurface **theGWorld, Rect *bounds, GpPixelF return theErr; } - //-------------------------------------------------------------- KillOffScreenPixMap // Destroys memory allocated by an offscreen pix map. /* @@ -255,7 +254,7 @@ void LoadGraphic (DrawSurface *surface, short resID) Rect bounds; THandle thePicture; - thePicture = GetPicture(resID); + thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', resID).StaticCast(); if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); @@ -266,6 +265,24 @@ void LoadGraphic (DrawSurface *surface, short resID) thePicture.Dispose(); } +//-------------------------------------------------------------- LoadGraphicCustom +// Same as LoadGraphic but supports custom graphics +void LoadGraphicCustom(DrawSurface *surface, short resID) +{ + Rect bounds; + THandle thePicture; + + thePicture = LoadHouseResource('PICT', resID).StaticCast(); + if (thePicture == nil) + RedAlert(kErrFailedGraphicLoad); + + bounds = (*thePicture)->GetRect(); + OffsetRect(&bounds, -bounds.left, -bounds.top); + surface->DrawPicture(thePicture, bounds); + + thePicture.Dispose(); +} + //-------------------------------------------------------------- LoadScaledGraphic // Loads the specified 'PICT' and draws it mapped to the rectangleÉ // specified. If this rect isn't the same size of the 'PICT', scalingÉ @@ -275,7 +292,23 @@ void LoadScaledGraphic (DrawSurface *surface, short resID, Rect *theRect) { THandle thePicture; - thePicture = GetPicture(resID); + thePicture = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', resID).StaticCast(); + if (thePicture == nil) + RedAlert(kErrFailedGraphicLoad); + surface->DrawPicture(thePicture, *theRect); + thePicture.Dispose(); +} + +//-------------------------------------------------------------- LoadScaledGraphic +// Loads the specified 'PICT' and draws it mapped to the rectangleÉ +// specified. If this rect isn't the same size of the 'PICT', scalingÉ +// will occur. + +void LoadScaledGraphicCustom(DrawSurface *surface, short resID, Rect *theRect) +{ + THandle thePicture; + + thePicture = LoadHouseResource('PICT', resID).StaticCast(); if (thePicture == nil) RedAlert(kErrFailedGraphicLoad); surface->DrawPicture(thePicture, *theRect); @@ -287,7 +320,7 @@ void LoadScaledGraphic (DrawSurface *surface, short resID, Rect *theRect) bool LargeIconPlot (DrawSurface *surface, PortabilityLayer::ResourceArchive *resFile, short resID, const Rect &theRect) { - Handle hdl = resFile->GetResource('icl8', resID, true); + Handle hdl = resFile->LoadResource('icl8', resID); if (hdl) { THandle img = PortabilityLayer::IconLoader::GetInstance()->LoadSimpleColorIcon(hdl); @@ -302,7 +335,7 @@ bool LargeIconPlot (DrawSurface *surface, PortabilityLayer::ResourceArchive *res return true; } - hdl = resFile->GetResource('ICN#', resID, true); + hdl = resFile->LoadResource('ICN#', resID); if (hdl) { THandle img = PortabilityLayer::IconLoader::GetInstance()->LoadBWIcon(hdl); diff --git a/GpApp/WindowUtils.cpp b/GpApp/WindowUtils.cpp index 5de63b0..14b0af7 100644 --- a/GpApp/WindowUtils.cpp +++ b/GpApp/WindowUtils.cpp @@ -10,7 +10,8 @@ #include "Environ.h" #include "PLStandardColors.h" #include "RectUtils.h" - +#include "WindowDef.h" +#include "WindowManager.h" #define kFloatingKind 2048 #define kMessageWindowTall 48 @@ -101,16 +102,16 @@ Boolean IsWindowFloating (WindowPtr theWindow) void OpenMessageWindow (const PLPasStr &title) { + const uint16_t windowStyle = PortabilityLayer::WindowStyleFlags::kTitleBar; + Rect mssgWindowRect; SetRect(&mssgWindowRect, 0, 0, 256, kMessageWindowTall); - if (thisMac.hasColor) - mssgWindow = NewCWindow(nil, &mssgWindowRect, - title, false, noGrowDocProc, kPutInFront, false, 0L); - else - mssgWindow = NewWindow(nil, &mssgWindowRect, - title, false, noGrowDocProc, kPutInFront, false, 0L); - + + const PortabilityLayer::WindowDef wdef = PortabilityLayer::WindowDef::Create(mssgWindowRect, windowStyle, false, false, 0, 0, title); + + mssgWindow = PortabilityLayer::WindowManager::GetInstance()->CreateWindow(wdef); + if (mssgWindow != nil) { ShowWindow(mssgWindow); @@ -155,9 +156,7 @@ void SetMessageWindowMessage (StringPtr message) void CloseMessageWindow (void) { - if (mssgWindow != nil) - DisposeWindow(mssgWindow); - mssgWindow = nil; + CloseThisWindow(&mssgWindow); } //-------------------------------------------------------------- CloseThisWindow @@ -168,7 +167,7 @@ void CloseMessageWindow (void) void CloseThisWindow (WindowPtr *theWindow) { if (*theWindow != nil) - DisposeWindow(*theWindow); + PortabilityLayer::WindowManager::GetInstance()->DestroyWindow(*theWindow); *theWindow = nil; } diff --git a/PortabilityLayer/DialogManager.cpp b/PortabilityLayer/DialogManager.cpp index d07d6df..5748bcd 100644 --- a/PortabilityLayer/DialogManager.cpp +++ b/PortabilityLayer/DialogManager.cpp @@ -404,7 +404,7 @@ namespace PortabilityLayer { ResourceManager *rm = ResourceManager::GetInstance(); - THandle dlogH = rm->GetResource('DLOG', resID).StaticCast(); + THandle dlogH = rm->GetAppResource('DLOG', resID).StaticCast(); const uint8_t *dlogData = *dlogH; const uint8_t *dlogDataEnd = dlogData + dlogH.MMBlock()->m_size; @@ -434,7 +434,7 @@ namespace PortabilityLayer WindowManager *wm = PortabilityLayer::WindowManager::GetInstance(); - WindowDef wdef = WindowDef::Create(rect, 0, header.m_visible != 0, header.m_hasCloseBox != 0, header.m_referenceConstant, positionSpec, PLPasStr(titlePStr)); + WindowDef wdef = WindowDef::Create(rect, WindowStyleFlags::kAlert, header.m_visible != 0, header.m_hasCloseBox != 0, header.m_referenceConstant, positionSpec, PLPasStr(titlePStr)); Window *window = wm->CreateWindow(wdef); if (!window) { @@ -499,7 +499,7 @@ namespace PortabilityLayer { ResourceManager *rm = ResourceManager::GetInstance(); - THandle dtemplateH = rm->GetResource('DITL', resID).StaticCast(); + THandle dtemplateH = rm->GetAppResource('DITL', resID).StaticCast(); if (!dtemplateH) return nullptr; diff --git a/PortabilityLayer/IconLoader.cpp b/PortabilityLayer/IconLoader.cpp index 4fbdd68..e2cc284 100644 --- a/PortabilityLayer/IconLoader.cpp +++ b/PortabilityLayer/IconLoader.cpp @@ -56,7 +56,7 @@ namespace PortabilityLayer bool IconLoaderImpl::LoadColorIcon(const int16_t id, THandle &outColorImage, THandle &outBWImage, THandle &outMaskImage) { - THandle data = PortabilityLayer::ResourceManager::GetInstance()->GetResource('cicn', id).StaticCast(); + THandle data = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('cicn', id).StaticCast(); if (!data) return false; diff --git a/PortabilityLayer/MenuManager.cpp b/PortabilityLayer/MenuManager.cpp index b6639a7..635ad4a 100644 --- a/PortabilityLayer/MenuManager.cpp +++ b/PortabilityLayer/MenuManager.cpp @@ -595,8 +595,8 @@ namespace PortabilityLayer { ResourceManager *resManager = ResourceManager::GetInstance(); - Handle icsHandle = GetResource('ics#', kIconResID); - Handle ics8Handle = GetResource('ics8', kIconResID); + Handle icsHandle = resManager->GetAppResource('ics#', kIconResID); + Handle ics8Handle = resManager->GetAppResource('ics8', kIconResID); if (icsHandle && ics8Handle) { diff --git a/PortabilityLayer/PLCore.cpp b/PortabilityLayer/PLCore.cpp index a099211..14268a5 100644 --- a/PortabilityLayer/PLCore.cpp +++ b/PortabilityLayer/PLCore.cpp @@ -87,7 +87,7 @@ Rect BERect::ToRect() const CursHandle GetCursor(int cursorID) { - return GetResource('CURS', cursorID).ReinterpretCast(); + return PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('CURS', cursorID).ReinterpretCast(); } void HideCursor() @@ -119,17 +119,6 @@ short Alert(int dialogID, void *unknown) return 0; } -Handle GetResource(int32_t resType, int id) -{ - return PortabilityLayer::ResourceManager::GetInstance()->GetResource(PortabilityLayer::ResTypeID(resType), id); -} - -Handle GetResource(const char(&resTypeLiteral)[5], int id) -{ - PL_NotYetImplemented(); - return nullptr; -} - short FindWindow(Point point, WindowPtr *window) { short part = 0; @@ -198,7 +187,7 @@ void GetWindowBounds(WindowPtr window, WindowRegionType windowRegion, Rect *rect WindowPtr GetNewCWindow(int resID, void *storage, WindowPtr behind) { - Handle windowResource = GetResource('WIND', resID); + Handle windowResource = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('WIND', resID); if (!windowResource) return nullptr; @@ -361,7 +350,7 @@ void GetIndString(unsigned char *str, int stringsID, int fnameIndex) if (fnameIndex < 1) return; - THandle istrRes = PortabilityLayer::ResourceManager::GetInstance()->GetResource('STR#', stringsID).StaticCast(); + THandle istrRes = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('STR#', stringsID).StaticCast(); if (istrRes && *istrRes) { const uint8_t *contentsBytes = *istrRes; @@ -626,7 +615,7 @@ void *NewPtrClear(Size size) void DisposePtr(void *ptr) { - PL_NotYetImplemented(); + PortabilityLayer::MemoryManager::GetInstance()->Release(ptr); } void BlockMove(const void *src, void *dest, Size size) diff --git a/PortabilityLayer/PLCore.h b/PortabilityLayer/PLCore.h index 493c3c8..3b850dc 100644 --- a/PortabilityLayer/PLCore.h +++ b/PortabilityLayer/PLCore.h @@ -222,11 +222,6 @@ enum EventCode kHighLevelEvent, }; -enum BuiltinWDEFs -{ - noGrowDocProc = 4, // Movable, not resizable -}; - static const int everyEvent = -1; static const int iBeamCursor = 1; @@ -251,9 +246,6 @@ void SetBuiltinCursor(int builtinCursor); void Delay(int ticks, UInt32 *endTickCount); short Alert(int dialogID, void *unknown); -Handle GetResource(int32_t resType, int id); -Handle GetResource(const char(&resTypeLiteral)[5], int id); - short FindWindow(Point point, WindowPtr *window); // Translates global coordinates to window coordinates, returns a region ID void DragWindow(WindowPtr window, Point start, Rect *bounds); // Drags the window (probably not implemented) void SendBehind(WindowPtr window, WindowPtr behind); diff --git a/PortabilityLayer/PLImageWidget.cpp b/PortabilityLayer/PLImageWidget.cpp index c108463..7a0e0ee 100644 --- a/PortabilityLayer/PLImageWidget.cpp +++ b/PortabilityLayer/PLImageWidget.cpp @@ -15,7 +15,7 @@ namespace PortabilityLayer bool ImageWidget::Init(const WidgetBasicState &state) { - m_pict = PortabilityLayer::ResourceManager::GetInstance()->GetResource('PICT', state.m_resID).StaticCast(); + m_pict = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', state.m_resID).StaticCast(); if (!m_pict) return false; diff --git a/PortabilityLayer/PLMenus.cpp b/PortabilityLayer/PLMenus.cpp index 4c966d1..d0a2245 100644 --- a/PortabilityLayer/PLMenus.cpp +++ b/PortabilityLayer/PLMenus.cpp @@ -3,6 +3,7 @@ #include "MenuManager.h" #include "QDManager.h" +#include "ResourceManager.h" // Menu resource structure: // uint16 menu ID @@ -21,7 +22,7 @@ MenuHandle GetMenu(int resID) { - Handle menuRes = GetResource('MENU', resID); + Handle menuRes = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('MENU', resID); if (!menuRes) return nullptr; diff --git a/PortabilityLayer/PLQDOffscreen.cpp b/PortabilityLayer/PLQDOffscreen.cpp index 67d7519..e4159d2 100644 --- a/PortabilityLayer/PLQDOffscreen.cpp +++ b/PortabilityLayer/PLQDOffscreen.cpp @@ -36,11 +36,6 @@ PixMapHandle GetGWorldPixMap(DrawSurface *gworld) return gworld->m_port.GetPixMap(); } -THandle GetPicture(short resID) -{ - return PortabilityLayer::ResourceManager::GetInstance()->GetResource('PICT', resID).StaticCast(); -} - void OffsetRect(Rect *rect, int right, int down) { rect->left += right; diff --git a/PortabilityLayer/PLQDOffscreen.h b/PortabilityLayer/PLQDOffscreen.h index c7dbd80..391a0ea 100644 --- a/PortabilityLayer/PLQDOffscreen.h +++ b/PortabilityLayer/PLQDOffscreen.h @@ -22,8 +22,6 @@ void DisposeGWorld(DrawSurface *gworld); PixMapHandle GetGWorldPixMap(DrawSurface *gworld); -THandle GetPicture(short resID); - void OffsetRect(Rect *rect, int right, int down); DrawSurface *GetGraphicsPort(); diff --git a/PortabilityLayer/PLQDraw.cpp b/PortabilityLayer/PLQDraw.cpp index 4f93f5d..dc0606a 100644 --- a/PortabilityLayer/PLQDraw.cpp +++ b/PortabilityLayer/PLQDraw.cpp @@ -1382,7 +1382,7 @@ void GetIndPattern(Pattern *pattern, int patListID, int index) if (index < 1) return; - THandle patternList = PortabilityLayer::ResourceManager::GetInstance()->GetResource('PAT#', patListID).StaticCast(); + THandle patternList = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PAT#', patListID).StaticCast(); const uint8_t *patternRes = *patternList; int numPatterns = (patternRes[0] << 8) | patternRes[1]; diff --git a/PortabilityLayer/PLResourceManager.cpp b/PortabilityLayer/PLResourceManager.cpp index 044ed73..e08b3f0 100644 --- a/PortabilityLayer/PLResourceManager.cpp +++ b/PortabilityLayer/PLResourceManager.cpp @@ -20,7 +20,7 @@ #include "ZipFileProxy.h" #include "ZipFile.h" -#include +#include namespace ResourceValidationRules { @@ -104,75 +104,42 @@ namespace PortabilityLayer void Init() override; void Shutdown() override; - - void SetResLoad(bool load) override; + + THandle GetAppResource(const ResTypeID &resTypeID, int16_t resID) const override; + ResourceArchive *GetAppResourceArchive() const override; ResourceArchive *LoadResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) const override; - short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) override; - void CloseResFile(short ref) override; PLError_t CreateBlankResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) override; - THandle GetResource(const ResTypeID &resType, int id) override; - - short GetCurrentResFile() const override; - void SetCurrentResFile(short ref) override; - void DissociateHandle(MMHandleBlock *hdl) const override; const ResourceArchiveRef *ResourceForHandle(MMHandleBlock *hdl) const override; static ResourceManagerImpl *GetInstance(); private: - struct ResFileSlot - { - short m_prevFile; - short m_nextFile; - ResourceArchive *m_resourceArchive; - }; - void UnloadAndDestroyResourceFile(ResourceArchive *rf); - std::vector m_resFiles; - short m_firstResFile; - short m_lastResFile; - short m_currentResFile; - bool m_load; + ResourceArchive *m_appResArchive; static ResourceManagerImpl ms_instance; }; ResourceManagerImpl::ResourceManagerImpl() - : m_currentResFile(-1) - , m_firstResFile(-1) - , m_lastResFile(-1) - , m_load(true) + : m_appResArchive(nullptr) { } void ResourceManagerImpl::Init() { - m_currentResFile = OpenResFork(VirtualDirectories::kApplicationData, PSTR("ApplicationResources")); + m_appResArchive = LoadResFile(VirtualDirectories::kApplicationData, PSTR("ApplicationResources")); } void ResourceManagerImpl::Shutdown() { - for (std::vector::iterator it = m_resFiles.begin(), itEnd = m_resFiles.end(); it != itEnd; ++it) - { - if (it->m_resourceArchive) - UnloadAndDestroyResourceFile(it->m_resourceArchive); - } + if (m_appResArchive) + m_appResArchive->Destroy(); - m_resFiles.clear(); - } - - short ResourceManagerImpl::GetCurrentResFile() const - { - return m_currentResFile; - } - - void ResourceManagerImpl::SetCurrentResFile(short ref) - { - m_currentResFile = ref; + m_appResArchive = nullptr; } void ResourceManagerImpl::DissociateHandle(MMHandleBlock *hdl) const @@ -198,11 +165,6 @@ namespace PortabilityLayer return &ms_instance; } - void ResourceManagerImpl::SetResLoad(bool load) - { - m_load = load; - } - ResourceArchive *ResourceManagerImpl::LoadResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) const { IOStream *fStream = nullptr; @@ -227,82 +189,6 @@ namespace PortabilityLayer return archive; } - short ResourceManagerImpl::OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) - { - const size_t numSlots = m_resFiles.size(); - size_t resFileIndex = numSlots; - - for (size_t i = 0; i < numSlots; i++) - { - if (m_resFiles[i].m_resourceArchive == nullptr) - { - resFileIndex = i; - break; - } - } - - if (resFileIndex == 0x7fff) - return -1; - - - ResourceArchive *resFile = LoadResFile(virtualDir, filename); - - if (!resFile) - return -1; - - ResFileSlot slot; - slot.m_resourceArchive = resFile; - slot.m_prevFile = m_lastResFile; - slot.m_nextFile = -1; - - if (resFileIndex == numSlots) - m_resFiles.push_back(slot); - else - m_resFiles[resFileIndex] = slot; - - const short rfid = static_cast(resFileIndex); - - if (m_firstResFile < 0) - m_firstResFile = rfid; - - if (m_lastResFile >= 0) - m_resFiles[m_lastResFile].m_nextFile = rfid; - - m_lastResFile = rfid; - m_currentResFile = rfid; // Resource Manager is supposed to reset the search stack on new file open - - return rfid; - } - - void ResourceManagerImpl::CloseResFile(short ref) - { - ResFileSlot &slot = m_resFiles[ref]; - - assert(slot.m_resourceArchive != nullptr); - - slot.m_resourceArchive->Destroy(); - slot.m_resourceArchive = nullptr; - - if (m_lastResFile == ref) - m_lastResFile = slot.m_prevFile; - - if (slot.m_prevFile >= 0) - { - ResFileSlot &prevFileSlot = m_resFiles[slot.m_prevFile]; - prevFileSlot.m_nextFile = slot.m_nextFile; - } - - if (slot.m_nextFile >= 0) - { - ResFileSlot &nextFileSlot = m_resFiles[slot.m_nextFile]; - nextFileSlot.m_prevFile = slot.m_prevFile; - } - - slot.m_nextFile = slot.m_prevFile = -1; - - m_currentResFile = m_lastResFile; - } - PLError_t ResourceManagerImpl::CreateBlankResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) { PortabilityLayer::IOStream *stream = nullptr; @@ -331,22 +217,17 @@ namespace PortabilityLayer return PLErrors::kNone; } - THandle ResourceManagerImpl::GetResource(const ResTypeID &resType, int id) + THandle ResourceManagerImpl::GetAppResource(const ResTypeID &resType, int16_t resID) const { - short searchIndex = m_currentResFile; - while (searchIndex >= 0) - { - const ResFileSlot& slot = m_resFiles[searchIndex]; - assert(slot.m_resourceArchive); + if (!m_appResArchive) + return THandle(); - THandle resHdl = slot.m_resourceArchive->GetResource(resType, id, m_load); - if (resHdl != nullptr) - return resHdl; + return m_appResArchive->LoadResource(resType, resID); + } - searchIndex = slot.m_prevFile; - } - - return nullptr; + ResourceArchive *ResourceManagerImpl::GetAppResourceArchive() const + { + return m_appResArchive; } ResourceManagerImpl ResourceManagerImpl::ms_instance; @@ -395,6 +276,23 @@ namespace PortabilityLayer PortabilityLayer::MemoryManager::GetInstance()->Release(this); } + THandle ResourceArchive::LoadResource(const ResTypeID &resTypeID, int id) + { + return GetResource(resTypeID, id, true); + } + + bool ResourceArchive::GetResourceSize(const ResTypeID &resTypeID, int id, size_t &outSize) + { + THandle hdl = GetResource(resTypeID, id, false); + if (const PortabilityLayer::MMHandleBlock *hdlBlock = hdl.MMBlock()) + { + outSize = hdlBlock->m_rmSelfRef->m_size; + return true; + } + + return false; + } + THandle ResourceArchive::GetResource(const ResTypeID &resTypeID, int id, bool load) { const char *extension = ".bin"; diff --git a/PortabilityLayer/PLResources.cpp b/PortabilityLayer/PLResources.cpp index 027e96e..ccb3d49 100644 --- a/PortabilityLayer/PLResources.cpp +++ b/PortabilityLayer/PLResources.cpp @@ -9,46 +9,6 @@ #include -struct PLOpenedResFile -{ - bool m_isOpen; -}; - -static const unsigned int kPLMaxOpenedResFiles = 64; -static PLOpenedResFile gs_resFiles[kPLMaxOpenedResFiles]; - -short CurResFile() -{ - return PortabilityLayer::ResourceManager::GetInstance()->GetCurrentResFile(); -} - -void UseResFile(short fid) -{ - PortabilityLayer::ResourceManager::GetInstance()->SetCurrentResFile(fid); -} - -Handle Get1Resource(UInt32 resID, int index) -{ - PL_NotYetImplemented(); - return nullptr; -} - -Handle Get1IndResource(UInt32 resID, int index) -{ - PL_NotYetImplemented(); - return nullptr; -} - -int Count1Resources(UInt32 resType) -{ - PL_NotYetImplemented(); - return 0; -} - -void SetResLoad(Boolean load) -{ - PortabilityLayer::ResourceManager::GetInstance()->SetResLoad(load != 0); -} long GetMaxResourceSize(Handle res) { @@ -56,9 +16,3 @@ long GetMaxResourceSize(Handle res) const PortabilityLayer::ResourceArchiveRef *resRef = hBlock->m_rmSelfRef; return resRef->m_size; } - -short HOpenResFile(PortabilityLayer::VirtualDirectory_t dirID, const PLPasStr &name, int permissions) -{ - PL_NotYetImplemented(); - return 0; -} diff --git a/PortabilityLayer/PLResources.h b/PortabilityLayer/PLResources.h index 4c718ca..60ceeaf 100644 --- a/PortabilityLayer/PLResources.h +++ b/PortabilityLayer/PLResources.h @@ -1,24 +1,8 @@ #pragma once -#ifndef __PL_RESOURCES_H__ -#define __PL_RESOURCES_H__ #include "PLCore.h" class PLPasStr; -short CurResFile(); -void UseResFile(short fid); -Handle Get1Resource(UInt32 resID, int index); -Handle Get1IndResource(UInt32 resID, int index); -int Count1Resources(UInt32 resType); - -void SetResLoad(Boolean load); // Sets whether resources should be loaded when requested - long GetMaxResourceSize(Handle res); - -// This should return -1 on error? -short HOpenResFile(PortabilityLayer::VirtualDirectory_t dirID, const PLPasStr &name, int permissions); - - -#endif diff --git a/PortabilityLayer/ResourceManager.h b/PortabilityLayer/ResourceManager.h index 62c3385..f3378df 100644 --- a/PortabilityLayer/ResourceManager.h +++ b/PortabilityLayer/ResourceManager.h @@ -30,12 +30,15 @@ namespace PortabilityLayer static ResourceArchive *Create(ZipFileProxy *zipFileProxy, IOStream *stream); void Destroy(); - THandle GetResource(const ResTypeID &resTypeID, int id, bool load); + THandle LoadResource(const ResTypeID &resTypeID, int id); + bool GetResourceSize(const ResTypeID &resTypeID, int id, size_t &outSize); private: ResourceArchive(ZipFileProxy *zipFileProxy, IOStream *stream, ResourceArchiveRef *resourceHandles); ~ResourceArchive(); + THandle GetResource(const ResTypeID &resTypeID, int id, bool load); + ZipFileProxy *m_zipFileProxy; IOStream *m_stream; ResourceArchiveRef *m_resourceHandles; @@ -47,18 +50,12 @@ namespace PortabilityLayer virtual void Init() = 0; virtual void Shutdown() = 0; - virtual void SetResLoad(bool load) = 0; + virtual THandle GetAppResource(const ResTypeID &resTypeID, int16_t resID) const = 0; + virtual ResourceArchive *GetAppResourceArchive() const = 0; virtual ResourceArchive *LoadResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) const = 0; - virtual short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) = 0; - virtual void CloseResFile(short ref) = 0; virtual PLError_t CreateBlankResFile(VirtualDirectory_t virtualDir, const PLPasStr &filename) = 0; - virtual THandle GetResource(const ResTypeID &resType, int id) = 0; - - virtual short GetCurrentResFile() const = 0; - virtual void SetCurrentResFile(short ref) = 0; - virtual void DissociateHandle(MMHandleBlock *hdl) const = 0; virtual const ResourceArchiveRef *ResourceForHandle(MMHandleBlock *hdl) const = 0; diff --git a/PortabilityLayer/WindowDef.cpp b/PortabilityLayer/WindowDef.cpp index dd644fa..1f6a77a 100644 --- a/PortabilityLayer/WindowDef.cpp +++ b/PortabilityLayer/WindowDef.cpp @@ -19,6 +19,34 @@ namespace PortabilityLayer uint8_t m_titleLength; }; + enum WDefPositionSpecs + { + kPosSpec_CommonBits = 0x200a, + + kPosSpec_LocationMask = 0x1800, + kPosSpec_Location_Center = 0x0800, + kPosSpec_Location_AlertPosition = 0x1000, + kPosSpec_Location_Stagger = 0x1800, + + kPosSpec_SubsetMask = 0xc000, + kPosSpec_Subset_MainScreen = 0x0000, + kPosSpec_Subset_ParentWindow = 0x8000, + kPosSpec_Subset_ParentWindowsScreen = 0x4000, + }; + + enum Styles + { + kStyle_BarResizable = 0, + kStyle_Bar = 4, + kStyle_BarResizableExpandable = 8, + kStyle_BarExpandable = 12, + kStyle_Box = 2, + kStyle_BoxShadow = 3, + kStyle_BarCloseBoxBlack = 16, + kStyle_Alert = 1, + kStyle_BarNoMinimize = 5, + }; + GP_STATIC_ASSERT(sizeof(WindowDefPart1) == 19); WindowDefPart1 wdefPart1; @@ -26,8 +54,23 @@ namespace PortabilityLayer if (stream->Read(&wdefPart1, sizeof(wdefPart1)) != sizeof(wdefPart1)) return false; + uint16_t styleFlags = 0; + + switch (static_cast(wdefPart1.m_wdefResID)) + { + case kStyle_Bar: + case kStyle_BarNoMinimize: + styleFlags = WindowStyleFlags::kTitleBar; + break; + case kStyle_Box: + styleFlags = 0; + break; + default: + return false; // Unsupported window style + } + m_initialRect = wdefPart1.m_initialRect.ToRect(); - m_wdefResID = wdefPart1.m_wdefResID; + m_styleFlags = styleFlags; m_visibilityStatus = wdefPart1.m_visibilityStatus; m_hasCloseBox = wdefPart1.m_hasCloseBox; m_referenceConstant = wdefPart1.m_referenceConstant; @@ -44,11 +87,11 @@ namespace PortabilityLayer return true; } - WindowDef WindowDef::Create(const Rect &initialRect, int16_t wdefID, bool isVisible, bool hasCloseBox, uint32_t refConstant, uint16_t positionSpec, const PLPasStr &title) + WindowDef WindowDef::Create(const Rect &initialRect, uint16_t styleFlags, bool isVisible, bool hasCloseBox, uint32_t refConstant, uint16_t positionSpec, const PLPasStr &title) { WindowDef wdef; wdef.m_initialRect = initialRect; - wdef.m_wdefResID = wdefID; + wdef.m_styleFlags = styleFlags; wdef.m_visibilityStatus = isVisible ? 1 : 0; wdef.m_hasCloseBox = hasCloseBox ? 1 : 0; wdef.m_referenceConstant = refConstant; diff --git a/PortabilityLayer/WindowDef.h b/PortabilityLayer/WindowDef.h index aba08a8..c58864c 100644 --- a/PortabilityLayer/WindowDef.h +++ b/PortabilityLayer/WindowDef.h @@ -9,10 +9,22 @@ namespace PortabilityLayer { class IOStream; + namespace WindowStyleFlags + { + enum WindowStyleFlag + { + kTitleBar = 1, + kBorderless = 2, + kResizable = 4, + kMiniBar = 8, + kAlert = 16, + }; + } + struct WindowDef { Rect m_initialRect; - int16_t m_wdefResID; + uint16_t m_styleFlags; uint16_t m_visibilityStatus; uint16_t m_hasCloseBox; uint32_t m_referenceConstant; @@ -21,6 +33,6 @@ namespace PortabilityLayer bool Deserialize(IOStream *stream); - static WindowDef Create(const Rect &initialRect, int16_t wdefID, bool isVisible, bool hasCloseBox, uint32_t refConstant, uint16_t positionSpec, const PLPasStr &title); + static WindowDef Create(const Rect &initialRect, uint16_t styleFlags, bool isVisible, bool hasCloseBox, uint32_t refConstant, uint16_t positionSpec, const PLPasStr &title); }; }