mirror of
https://github.com/elasota/Aerofoil.git
synced 2026-03-01 21:34:15 +00:00
Refactoring
This commit is contained in:
@@ -109,7 +109,7 @@ static void HiLiteOkayButton (void)
|
||||
if (thePict != nil)
|
||||
{
|
||||
DrawPicture(thePict, &okayButtonBounds);
|
||||
ReleaseResource((Handle)thePict);
|
||||
DisposeHandle((Handle)thePict);
|
||||
|
||||
okayButtIsHiLit = true;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ static void UnHiLiteOkayButton (void)
|
||||
if (thePict != nil)
|
||||
{
|
||||
DrawPicture(thePict, &okayButtonBounds);
|
||||
ReleaseResource((Handle)thePict);
|
||||
DisposeHandle((Handle)thePict);
|
||||
|
||||
okayButtIsHiLit = false;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ typedef struct
|
||||
} compiledAcurRec, *compiledAcurPtr, **compiledAcurHandle;
|
||||
|
||||
|
||||
Boolean GetMonoCursors (acurHandle, compiledAcurHandle);
|
||||
Boolean GetColorCursors (acurHandle, compiledAcurHandle);
|
||||
void InitAnimatedCursor (acurHandle);
|
||||
|
||||
@@ -47,36 +46,6 @@ Boolean useColorCursor = false;
|
||||
|
||||
|
||||
//============================================================== Functions
|
||||
//-------------------------------------------------------------- GetMonoCursors
|
||||
|
||||
// Loads b&w cursors (for animated beach ball).
|
||||
|
||||
Boolean GetMonoCursors (acurHandle ballCursH, compiledAcurHandle compiledBallCursH)
|
||||
{
|
||||
short i, j;
|
||||
CursHandle cursHdl;
|
||||
|
||||
if (ballCursH) // Were we passed a legit acur handle?
|
||||
{
|
||||
j = (*ballCursH)->n; // Get number of 'frames' in the acur
|
||||
for (i = 0; i < j; i++) // Start walking the frames
|
||||
{
|
||||
cursHdl = GetCursor((*ballCursH)->frame[i].resID);
|
||||
if (cursHdl == nil) // Did the cursor load? It didn't?...
|
||||
{ // Well then, toss what we got.
|
||||
for (j = 0; j < i; j++)
|
||||
DisposeHandle((*compiledBallCursH)->frame[j].cursorHdl);
|
||||
return(false); // And report this to mother.
|
||||
} // However!...
|
||||
else // If cursor loaded ok...
|
||||
{ // Detach it from the resource map...
|
||||
DetachResource((Handle)cursHdl); // And assign to our struct
|
||||
(*compiledBallCursH)->frame[i].cursorHdl = (Handle)cursHdl;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------- GetColorCursors
|
||||
|
||||
@@ -133,8 +102,6 @@ void InitAnimatedCursor (acurHandle ballCursH)
|
||||
|
||||
if (useColor)
|
||||
useColor = GetColorCursors(ballCursH, compiledBallCursorH);
|
||||
if (!useColor && !GetMonoCursors(ballCursH, compiledBallCursorH))
|
||||
RedAlert(kErrFailedResourceLoad);
|
||||
DisposCursors();
|
||||
|
||||
animCursorH = ballCursH;
|
||||
@@ -189,7 +156,7 @@ void DisposCursors (void)
|
||||
|
||||
if (animCursorH != nil)
|
||||
{
|
||||
ReleaseResource((Handle)animCursorH);
|
||||
DisposeHandle((Handle)animCursorH);
|
||||
animCursorH = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,9 +93,10 @@ Boolean CreateNewHouse (void)
|
||||
theErr = fm->CreateFileAtCurrentTime(theSpec.m_dir, theSpec.m_name, 'ozm5', 'gliH');
|
||||
if (!CheckFileError(theErr, PSTR("New House")))
|
||||
return (false);
|
||||
HCreateResFile(theSpec.m_dir, theSpec.m_name);
|
||||
if (ResError() != PLErrors::kNone)
|
||||
YellowAlert(kYellowFailedResCreate, ResError());
|
||||
|
||||
theErr = HCreateResFile(theSpec.m_dir, theSpec.m_name);
|
||||
if (theErr != PLErrors::kNone)
|
||||
YellowAlert(kYellowFailedResCreate, theErr);
|
||||
|
||||
PasStringCopy(theSpec.m_name, thisHouseName);
|
||||
AddExtraHouse(theSpec);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "House.h"
|
||||
#include "IOStream.h"
|
||||
#include "ObjectEdit.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
|
||||
#define kSaveChangesAlert 1002
|
||||
@@ -866,11 +867,12 @@ Boolean CloseHouse (void)
|
||||
|
||||
void OpenHouseResFork (void)
|
||||
{
|
||||
PortabilityLayer::ResourceManager *rm = PortabilityLayer::ResourceManager::GetInstance();
|
||||
if (houseResFork == -1)
|
||||
{
|
||||
houseResFork = FSpOpenResFile(theHousesSpecs[thisHouseIndex], fsCurPerm);
|
||||
if (houseResFork == -1)
|
||||
YellowAlert(kYellowFailedResOpen, ResError());
|
||||
houseResFork = rm->OpenResFork(theHousesSpecs[thisHouseIndex].m_dir, theHousesSpecs[thisHouseIndex].m_name);
|
||||
if (houseResFork < 0)
|
||||
YellowAlert(kYellowFailedResOpen, PLErrors::kResourceError);
|
||||
else
|
||||
UseResFile(houseResFork);
|
||||
}
|
||||
@@ -883,7 +885,9 @@ void CloseHouseResFork (void)
|
||||
{
|
||||
if (houseResFork != -1)
|
||||
{
|
||||
CloseResFile(houseResFork);
|
||||
PortabilityLayer::ResourceManager *rm = PortabilityLayer::ResourceManager::GetInstance();
|
||||
|
||||
rm->CloseResFile(houseResFork);
|
||||
houseResFork = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ void LoadGraphicPlus (short resID, Rect *theRect)
|
||||
}
|
||||
}
|
||||
DrawPicture(thePicture, theRect);
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------- RedrawMapContents
|
||||
|
||||
@@ -261,7 +261,7 @@ PLError_t LoadMusicSounds (void)
|
||||
return PLErrors::kOutOfMemory;
|
||||
|
||||
BlockMove((Ptr)(static_cast<Byte*>(*theSound) + 20L), theMusicData[i], soundDataSize);
|
||||
ReleaseResource(theSound);
|
||||
DisposeHandle(theSound);
|
||||
}
|
||||
return (theErr);
|
||||
}
|
||||
@@ -418,7 +418,7 @@ long MusicBytesNeeded (void)
|
||||
if (theSound == nil)
|
||||
{
|
||||
SetResLoad(true);
|
||||
return ((long)ResError());
|
||||
return -1;
|
||||
}
|
||||
totalBytes += GetMaxResourceSize(theSound);
|
||||
// ReleaseResource(theSound);
|
||||
|
||||
@@ -1158,7 +1158,7 @@ void DrawCalendar (Rect *theRect)
|
||||
QOffsetRect(&bounds, -bounds.left, -bounds.top);
|
||||
QOffsetRect(&bounds, theRect->left, theRect->top);
|
||||
DrawPicture(thePicture, &bounds);
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
|
||||
SetPort((GrafPtr)backSrcMap);
|
||||
TextFace(bold);
|
||||
@@ -1191,7 +1191,7 @@ void DrawBulletin (Rect *theRect)
|
||||
QOffsetRect(&bounds, -bounds.left, -bounds.top);
|
||||
QOffsetRect(&bounds, theRect->left, theRect->top);
|
||||
DrawPicture(thePicture, &bounds);
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
|
||||
SetGraphicsPort(wasCPort);
|
||||
}
|
||||
@@ -1246,7 +1246,7 @@ void DrawPictObject (short what, Rect *theRect)
|
||||
bounds = srcRects[what];
|
||||
QOffsetRect(&bounds, theRect->left, theRect->top);
|
||||
DrawPicture(thePicture, &bounds);
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
|
||||
SetGraphicsPort(wasCPort);
|
||||
}
|
||||
|
||||
@@ -526,7 +526,7 @@ void PlayGame (void)
|
||||
QOffsetRect(&bounds, -bounds.left, -bounds.top);
|
||||
QOffsetRect(&bounds, hOffset, 0);
|
||||
DrawPicture(thePicture, &bounds);
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
}
|
||||
#else
|
||||
// ShowMenuBarOld(); // TEMP
|
||||
@@ -576,7 +576,7 @@ void PlayGame (void)
|
||||
QOffsetRect(&bounds, -bounds.left, -bounds.top);
|
||||
QOffsetRect(&bounds, hOffset, 0);
|
||||
DrawPicture(thePicture, &bounds);
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
|
||||
SetGraphicsPort(wasCPort);
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ void ReadyBackground (short theID, short *theTiles)
|
||||
dest = (*thePicture)->picFrame.ToRect();
|
||||
QOffsetRect(&dest, -dest.left, -dest.top);
|
||||
DrawPicture(thePicture, &dest);
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
|
||||
QSetRect(&src, 0, 0, kTileWide, kTileHigh);
|
||||
QSetRect(&dest, 0, 0, kTileWide, kTileHigh);
|
||||
@@ -913,7 +913,7 @@ short GetOriginalBounding (short theID)
|
||||
boundCode += 4;
|
||||
if ((*boundsRes)->bottom)
|
||||
boundCode += 8;
|
||||
ReleaseResource((Handle)boundsRes);
|
||||
DisposeHandle((Handle)boundsRes);
|
||||
}
|
||||
|
||||
return (boundCode);
|
||||
|
||||
@@ -147,7 +147,7 @@ void LoadGraphicSpecial (short resID)
|
||||
OffsetRect(&bounds, -bounds.left, -bounds.top);
|
||||
DrawPicture(thePicture, &bounds);
|
||||
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------- DrawRoomBackground
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "DialogUtils.h"
|
||||
#include "Externs.h"
|
||||
#include "RectUtils.h"
|
||||
#include "ResourceCompiledRef.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "Utilities.h"
|
||||
|
||||
|
||||
@@ -843,10 +845,10 @@ Boolean PictIDExists (short theID)
|
||||
foundIt = false;
|
||||
}
|
||||
else
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
}
|
||||
else
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
|
||||
// foundIt = false;
|
||||
// numPicts = Count1Resources('PICT');
|
||||
@@ -874,15 +876,13 @@ short GetFirstPICT (void)
|
||||
{
|
||||
Handle resHandle;
|
||||
Str255 resName;
|
||||
ResType resType;
|
||||
short resID;
|
||||
|
||||
resHandle = Get1IndResource('PICT', 1);
|
||||
if (resHandle != nil)
|
||||
{
|
||||
GetResInfo(resHandle, &resID, &resType, resName);
|
||||
ReleaseResource(resHandle);
|
||||
return (resID);
|
||||
const PortabilityLayer::ResourceCompiledRef *resRef = PortabilityLayer::ResourceManager::GetInstance()->ResourceForHandle(reinterpret_cast<PortabilityLayer::MMHandleBlock*>(resHandle));
|
||||
DisposeHandle(resHandle);
|
||||
return resRef->m_resID;
|
||||
}
|
||||
else
|
||||
return (-1);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "FileManager.h"
|
||||
#include "House.h"
|
||||
#include "RectUtils.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "VirtualDirectory.h"
|
||||
|
||||
|
||||
@@ -111,7 +112,7 @@ void UpdateLoadDialog (DialogPtr theDialog)
|
||||
else
|
||||
LoadDialogPICT(theDialog, kLoadIconFirstItem + i - housePage,
|
||||
kDefaultHousePict8);
|
||||
CloseResFile(isResFile);
|
||||
PortabilityLayer::ResourceManager::GetInstance()->CloseResFile(isResFile);
|
||||
}
|
||||
else
|
||||
LoadDialogPICT(theDialog, kLoadIconFirstItem + i - housePage,
|
||||
|
||||
@@ -228,13 +228,13 @@ PLError_t LoadTriggerSound (short soundID)
|
||||
theSoundData[kMaxSounds - 1] = NewPtr(soundDataSize);
|
||||
if (theSoundData[kMaxSounds - 1] == nil)
|
||||
{
|
||||
ReleaseResource(theSound);
|
||||
DisposeHandle(theSound);
|
||||
theErr = PLErrors::kOutOfMemory;
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockMove((Ptr)((Byte*)(*theSound) + 20L), theSoundData[kMaxSounds - 1], soundDataSize);
|
||||
ReleaseResource(theSound);
|
||||
DisposeHandle(theSound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,7 +275,7 @@ PLError_t LoadBufferSounds (void)
|
||||
return (PLErrors::kOutOfMemory);
|
||||
|
||||
BlockMove((Ptr)((Byte*)(*theSound) + 20L), theSoundData[i], soundDataSize);
|
||||
ReleaseResource(theSound);
|
||||
DisposeHandle(theSound);
|
||||
}
|
||||
|
||||
theSoundData[kMaxSounds - 1] = nil;
|
||||
@@ -436,7 +436,7 @@ long SoundBytesNeeded (void)
|
||||
if (theSound == nil)
|
||||
{
|
||||
SetResLoad(true);
|
||||
return ((long)ResError());
|
||||
return -1;
|
||||
}
|
||||
totalBytes += GetMaxResourceSize(theSound);
|
||||
// ReleaseResource(theSound);
|
||||
|
||||
@@ -84,7 +84,7 @@ void InitScoreboardMap (void)
|
||||
QOffsetRect(&bounds, -bounds.left, -bounds.top);
|
||||
QOffsetRect(&bounds, hOffset, 0);
|
||||
DrawPicture(thePicture, &bounds);
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
|
||||
QSetRect(&badgeSrcRect, 0, 0, 32, 66); // 2144 pixels
|
||||
theErr = CreateOffScreenGWorld(&badgeSrcMap, &badgeSrcRect, kPreferredPixelFormat);
|
||||
|
||||
@@ -289,7 +289,7 @@ void CreatePointers (void)
|
||||
else
|
||||
{
|
||||
BlockMove(*tempHandle, demoData, kDemoLength);
|
||||
ReleaseResource(tempHandle);
|
||||
DisposeHandle(tempHandle);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ void LoadGraphic (short resID)
|
||||
OffsetRect(&bounds, -bounds.left, -bounds.top);
|
||||
DrawPicture(thePicture, &bounds);
|
||||
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------- LoadScaledGraphic
|
||||
@@ -304,7 +304,7 @@ void LoadScaledGraphic (short resID, Rect *theRect)
|
||||
if (thePicture == nil)
|
||||
RedAlert(kErrFailedGraphicLoad);
|
||||
DrawPicture(thePicture, theRect);
|
||||
ReleaseResource((Handle)thePicture);
|
||||
DisposeHandle((Handle)thePicture);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------- LargeIconPlot
|
||||
@@ -317,7 +317,7 @@ void LargeIconPlot (Rect *theRect, short theID)
|
||||
|
||||
theErr = GetIconSuite(&theSuite, theID, svAllLargeData);
|
||||
if (theErr == PLErrors::kNone)
|
||||
theErr = PlotIconSuite(theRect, atNone, ttNone, theSuite);
|
||||
theErr = PlotIconSuite(theRect, theSuite);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------- DrawCIcon
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "MMBlock.h"
|
||||
#include "MMHandleBlock.h"
|
||||
#include "ResourceCompiledRef.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
@@ -142,7 +143,8 @@ namespace PortabilityLayer
|
||||
if (!hdl)
|
||||
return;
|
||||
|
||||
assert(hdl->m_rmSelfRef == nullptr);
|
||||
if (hdl->m_rmSelfRef)
|
||||
PortabilityLayer::ResourceManager::GetInstance()->DissociateHandle(hdl);
|
||||
|
||||
if (hdl->m_contents)
|
||||
Release(hdl->m_contents);
|
||||
|
||||
@@ -533,10 +533,10 @@ namespace PortabilityLayer
|
||||
}
|
||||
|
||||
if (icsHandle)
|
||||
ReleaseResource(icsHandle);
|
||||
DisposeHandle(icsHandle);
|
||||
|
||||
if (ics8Handle)
|
||||
ReleaseResource(ics8Handle);
|
||||
DisposeHandle(ics8Handle);
|
||||
|
||||
m_haveIcon = true;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace PLErrors
|
||||
|
||||
kIOError,
|
||||
|
||||
kResourceError,
|
||||
|
||||
kUserCancelled_TEMP,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ MenuHandle GetMenu(int resID)
|
||||
return nullptr;
|
||||
|
||||
const MenuHandle menu = PortabilityLayer::MenuManager::GetInstance()->DeserializeMenu(*menuRes);
|
||||
ReleaseResource(menuRes);
|
||||
DisposeHandle(menuRes);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ PLError_t GetIconSuite(Handle *suite, short resID, IconSuiteFlags flags)
|
||||
return PLErrors::kNone;
|
||||
}
|
||||
|
||||
PLError_t PlotIconSuite(Rect *rect, IconAlignmentType alignType, IconTransformType transformType, Handle iconSuite)
|
||||
PLError_t PlotIconSuite(Rect *rect, Handle iconSuite)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
return PLErrors::kNone;
|
||||
|
||||
@@ -13,15 +13,6 @@ namespace PortabilityLayer
|
||||
|
||||
struct Dialog;
|
||||
|
||||
enum IconAlignmentType
|
||||
{
|
||||
atNone
|
||||
};
|
||||
|
||||
enum IconTransformType
|
||||
{
|
||||
ttNone
|
||||
};
|
||||
|
||||
enum IconSuiteFlags
|
||||
{
|
||||
@@ -103,7 +94,7 @@ void BeginUpdate(WindowPtr graf);
|
||||
void EndUpdate(WindowPtr graf);
|
||||
|
||||
PLError_t GetIconSuite(Handle *suite, short resID, IconSuiteFlags flags);
|
||||
PLError_t PlotIconSuite(Rect *rect, IconAlignmentType alignType, IconTransformType transformType, Handle iconSuite);
|
||||
PLError_t PlotIconSuite(Rect *rect, Handle iconSuite);
|
||||
|
||||
CIconHandle GetCIcon(short resID);
|
||||
PLError_t PlotCIcon(Rect *rect, CIconHandle icon);
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include "MacBinary2.h"
|
||||
#include "MacFileMem.h"
|
||||
#include "MemReaderStream.h"
|
||||
#include "MemoryManager.h"
|
||||
#include "MMHandleBlock.h"
|
||||
#include "ResourceCompiledTypeList.h"
|
||||
#include "ResourceFile.h"
|
||||
#include "PLPasStr.h"
|
||||
#include "PLErrorCodes.h"
|
||||
@@ -15,6 +18,8 @@
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MMHandleBlock;
|
||||
|
||||
class ResourceManagerImpl final : public ResourceManager
|
||||
{
|
||||
public:
|
||||
@@ -26,11 +31,16 @@ namespace PortabilityLayer
|
||||
void SetResLoad(bool load) override;
|
||||
|
||||
short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) override;
|
||||
void CloseResFile(short ref) override;
|
||||
|
||||
MMHandleBlock *GetResource(const ResTypeID &resType, int id) override;
|
||||
|
||||
short GetCurrentResFile() const override;
|
||||
void SetCurrentResFile(short ref) override;
|
||||
|
||||
void DissociateHandle(MMHandleBlock *hdl) const override;
|
||||
const ResourceCompiledRef *ResourceForHandle(MMHandleBlock *hdl) const override;
|
||||
|
||||
static ResourceManagerImpl *GetInstance();
|
||||
|
||||
private:
|
||||
@@ -38,9 +48,11 @@ namespace PortabilityLayer
|
||||
{
|
||||
short m_prevFile;
|
||||
short m_nextFile;
|
||||
ResourceFile* m_resourceFile;
|
||||
ResourceFile *m_resourceFile;
|
||||
};
|
||||
|
||||
void UnloadAndDestroyResourceFile(ResourceFile *rf);
|
||||
|
||||
std::vector<ResFileSlot> m_resFiles;
|
||||
short m_firstResFile;
|
||||
short m_lastResFile;
|
||||
@@ -66,7 +78,10 @@ namespace PortabilityLayer
|
||||
void ResourceManagerImpl::Shutdown()
|
||||
{
|
||||
for (std::vector<ResFileSlot>::iterator it = m_resFiles.begin(), itEnd = m_resFiles.end(); it != itEnd; ++it)
|
||||
delete it->m_resourceFile;
|
||||
{
|
||||
if (it->m_resourceFile)
|
||||
UnloadAndDestroyResourceFile(it->m_resourceFile);
|
||||
}
|
||||
|
||||
m_resFiles.clear();
|
||||
}
|
||||
@@ -81,6 +96,43 @@ namespace PortabilityLayer
|
||||
m_currentResFile = ref;
|
||||
}
|
||||
|
||||
void ResourceManagerImpl::DissociateHandle(MMHandleBlock *hdl) const
|
||||
{
|
||||
assert(hdl->m_rmSelfRef);
|
||||
assert(hdl->m_rmSelfRef->m_handle == hdl);
|
||||
hdl->m_rmSelfRef->m_handle = nullptr;
|
||||
hdl->m_rmSelfRef = nullptr;
|
||||
}
|
||||
|
||||
const ResourceCompiledRef *ResourceManagerImpl::ResourceForHandle(MMHandleBlock *hdl) const
|
||||
{
|
||||
return hdl->m_rmSelfRef;
|
||||
}
|
||||
|
||||
void ResourceManagerImpl::UnloadAndDestroyResourceFile(ResourceFile *rf)
|
||||
{
|
||||
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
|
||||
|
||||
ResourceCompiledTypeList *rtls = nullptr;
|
||||
size_t numRTLs = 0;
|
||||
rf->GetAllResourceTypeLists(rtls, numRTLs);
|
||||
|
||||
for (size_t i = 0; i < numRTLs; i++)
|
||||
{
|
||||
const ResourceCompiledTypeList &rtl = rtls[i];
|
||||
|
||||
const size_t numRefs = rtl.m_numRefs;
|
||||
for (size_t r = 0; r < numRefs; r++)
|
||||
{
|
||||
const ResourceCompiledRef &ref = rtl.m_firstRef[r];
|
||||
if (MMHandleBlock *hdl = ref.m_handle)
|
||||
mm->ReleaseHandle(hdl);
|
||||
}
|
||||
}
|
||||
|
||||
delete rf;
|
||||
}
|
||||
|
||||
ResourceManagerImpl *ResourceManagerImpl::GetInstance()
|
||||
{
|
||||
return &ms_instance;
|
||||
@@ -146,6 +198,32 @@ namespace PortabilityLayer
|
||||
return rfid;
|
||||
}
|
||||
|
||||
void ResourceManagerImpl::CloseResFile(short ref)
|
||||
{
|
||||
ResFileSlot &slot = m_resFiles[ref];
|
||||
delete slot.m_resourceFile;
|
||||
slot.m_resourceFile = 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;
|
||||
}
|
||||
|
||||
MMHandleBlock *ResourceManagerImpl::GetResource(const ResTypeID &resType, int id)
|
||||
{
|
||||
short searchIndex = m_currentResFile;
|
||||
|
||||
@@ -63,29 +63,12 @@ int Count1Resources(UInt32 resType)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HCreateResFile(PortabilityLayer::VirtualDirectory_t dirID, const PLPasStr &name)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
PLError_t ResError()
|
||||
PLError_t HCreateResFile(PortabilityLayer::VirtualDirectory_t dirID, const PLPasStr &name)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
return PLErrors::kNone;
|
||||
}
|
||||
|
||||
short FSpOpenResFile(const VFileSpec &spec, int permission)
|
||||
{
|
||||
PortabilityLayer::ResourceManager *rm = PortabilityLayer::ResourceManager::GetInstance();
|
||||
|
||||
return rm->OpenResFork(spec.m_dir, spec.m_name);
|
||||
}
|
||||
|
||||
void CloseResFile(short refNum)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
void SetResLoad(Boolean load)
|
||||
{
|
||||
PortabilityLayer::ResourceManager::GetInstance()->SetResLoad(load != 0);
|
||||
@@ -98,11 +81,6 @@ long GetMaxResourceSize(Handle res)
|
||||
return resRef->GetSize();
|
||||
}
|
||||
|
||||
void GetResInfo(Handle res, short *resID, ResType *resType, Str255 resName)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
}
|
||||
|
||||
short HOpenResFile(PortabilityLayer::VirtualDirectory_t dirID, const PLPasStr &name, int permissions)
|
||||
{
|
||||
PL_NotYetImplemented();
|
||||
|
||||
@@ -4,31 +4,20 @@
|
||||
|
||||
#include "PLCore.h"
|
||||
|
||||
struct ResType
|
||||
{
|
||||
};
|
||||
|
||||
class PLPasStr;
|
||||
|
||||
void DetachResource(Handle hdl);
|
||||
void ReleaseResource(Handle hdl);
|
||||
|
||||
short CurResFile();
|
||||
void UseResFile(short fid);
|
||||
Handle Get1Resource(UInt32 resID, int index);
|
||||
Handle Get1IndResource(UInt32 resID, int index);
|
||||
int Count1Resources(UInt32 resType);
|
||||
|
||||
void HCreateResFile(PortabilityLayer::VirtualDirectory_t dirID, const PLPasStr &name);
|
||||
PLError_t ResError();
|
||||
|
||||
short FSpOpenResFile(const VFileSpec &spec, int permission);
|
||||
void CloseResFile(short refNum);
|
||||
PLError_t HCreateResFile(PortabilityLayer::VirtualDirectory_t dirID, const PLPasStr &name);
|
||||
|
||||
void SetResLoad(Boolean load); // Sets whether resources should be loaded when requested
|
||||
|
||||
long GetMaxResourceSize(Handle res);
|
||||
void GetResInfo(Handle res, short *resID, ResType *resType, Str255 resName);
|
||||
|
||||
// This should return -1 on error?
|
||||
short HOpenResFile(PortabilityLayer::VirtualDirectory_t dirID, const PLPasStr &name, int permissions);
|
||||
|
||||
@@ -338,6 +338,12 @@ namespace PortabilityLayer
|
||||
return memcmp(&resTypeID, &typeList.m_resType, 4);
|
||||
}
|
||||
|
||||
void ResourceFile::GetAllResourceTypeLists(ResourceCompiledTypeList *&outTypeLists, size_t &outCount) const
|
||||
{
|
||||
outTypeLists = m_compiledTypeListBlob;
|
||||
outCount = m_numResourceTypes;
|
||||
}
|
||||
|
||||
const ResourceCompiledTypeList *ResourceFile::GetResourceTypeList(const ResTypeID &resType)
|
||||
{
|
||||
const ResourceCompiledTypeList *tlStart = m_compiledTypeListBlob;
|
||||
|
||||
@@ -17,12 +17,13 @@ namespace PortabilityLayer
|
||||
class ResourceFile
|
||||
{
|
||||
public:
|
||||
|
||||
ResourceFile();
|
||||
~ResourceFile();
|
||||
|
||||
bool Load(IOStream *stream);
|
||||
|
||||
void GetAllResourceTypeLists(ResourceCompiledTypeList *&outTypeLists, size_t &outCount) const;
|
||||
|
||||
const ResourceCompiledTypeList *GetResourceTypeList(const ResTypeID &resType);
|
||||
MMHandleBlock *GetResource(const ResTypeID &resType, int id, bool load);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ class PLPasStr;
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MMHandleBlock;
|
||||
struct ResourceCompiledRef;
|
||||
class ResTypeID;
|
||||
|
||||
class ResourceManager
|
||||
@@ -18,11 +19,16 @@ namespace PortabilityLayer
|
||||
virtual void SetResLoad(bool load) = 0;
|
||||
|
||||
virtual short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) = 0;
|
||||
virtual void CloseResFile(short ref) = 0;
|
||||
|
||||
virtual MMHandleBlock *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 ResourceCompiledRef *ResourceForHandle(MMHandleBlock *hdl) const = 0;
|
||||
|
||||
static ResourceManager *GetInstance();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user