mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
Refactoring
This commit is contained in:
@@ -71,7 +71,7 @@ namespace PortabilityLayer
|
||||
|
||||
GpPixelFormat_t DisplayDeviceManagerImpl::GetPixelFormat() const
|
||||
{
|
||||
return m_pixelFormat;
|
||||
return m_pixelFormat;
|
||||
}
|
||||
|
||||
void DisplayDeviceManagerImpl::SyncPalette(IGpDisplayDriver *displayDriver)
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#include "MemoryManager.h"
|
||||
#include "MMBlock.h"
|
||||
#include "MMHandleBlock.h"
|
||||
#include "ResourceCompiledRef.h"
|
||||
#include "ResourceCompiledRef.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
@@ -141,8 +142,9 @@ 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);
|
||||
|
@@ -336,6 +336,12 @@ namespace PortabilityLayer
|
||||
int ResourceFile::CompiledTypeListSearchPredicate(const ResTypeID &resTypeID, const ResourceCompiledTypeList &typeList)
|
||||
{
|
||||
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)
|
||||
|
@@ -1,51 +1,52 @@
|
||||
#pragma once
|
||||
#ifndef __PL_RESOURCE_FILE_H__
|
||||
#define __PL_RESOURCE_FILE_H__
|
||||
|
||||
#include "ResTypeID.h"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class IOStream;
|
||||
class MacFileMem;
|
||||
struct MMHandleBlock;
|
||||
struct ResourceCompiledRef;
|
||||
struct ResourceCompiledTypeList;
|
||||
class ResTypeID;
|
||||
|
||||
class ResourceFile
|
||||
{
|
||||
public:
|
||||
|
||||
ResourceFile();
|
||||
~ResourceFile();
|
||||
|
||||
bool Load(IOStream *stream);
|
||||
|
||||
const ResourceCompiledTypeList *GetResourceTypeList(const ResTypeID &resType);
|
||||
MMHandleBlock *GetResource(const ResTypeID &resType, int id, bool load);
|
||||
|
||||
private:
|
||||
|
||||
uint8_t *m_resDataBlob;
|
||||
size_t m_resDataBlobSize;
|
||||
|
||||
uint8_t *m_resNameBlob;
|
||||
size_t m_resNameBlobSize;
|
||||
|
||||
ResourceCompiledRef *m_compiledRefBlob;
|
||||
size_t m_numResources;
|
||||
|
||||
ResourceCompiledTypeList *m_compiledTypeListBlob;
|
||||
size_t m_numResourceTypes;
|
||||
|
||||
static bool CompiledRefSortPredicate(const ResourceCompiledRef &a, const ResourceCompiledRef &b);
|
||||
static bool CompiledTypeListSortPredicate(const ResourceCompiledTypeList &a, const ResourceCompiledTypeList &b);
|
||||
|
||||
static int CompiledRefSearchPredicate(int resID, const ResourceCompiledRef &ref);
|
||||
static int CompiledTypeListSearchPredicate(const ResTypeID &resTypeID, const ResourceCompiledTypeList &typeList);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef __PL_RESOURCE_FILE_H__
|
||||
#define __PL_RESOURCE_FILE_H__
|
||||
|
||||
#include "ResTypeID.h"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class IOStream;
|
||||
class MacFileMem;
|
||||
struct MMHandleBlock;
|
||||
struct ResourceCompiledRef;
|
||||
struct ResourceCompiledTypeList;
|
||||
class ResTypeID;
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
|
||||
uint8_t *m_resDataBlob;
|
||||
size_t m_resDataBlobSize;
|
||||
|
||||
uint8_t *m_resNameBlob;
|
||||
size_t m_resNameBlobSize;
|
||||
|
||||
ResourceCompiledRef *m_compiledRefBlob;
|
||||
size_t m_numResources;
|
||||
|
||||
ResourceCompiledTypeList *m_compiledTypeListBlob;
|
||||
size_t m_numResourceTypes;
|
||||
|
||||
static bool CompiledRefSortPredicate(const ResourceCompiledRef &a, const ResourceCompiledRef &b);
|
||||
static bool CompiledTypeListSortPredicate(const ResourceCompiledTypeList &a, const ResourceCompiledTypeList &b);
|
||||
|
||||
static int CompiledRefSearchPredicate(int resID, const ResourceCompiledRef &ref);
|
||||
static int CompiledTypeListSearchPredicate(const ResTypeID &resTypeID, const ResourceCompiledTypeList &typeList);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -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