Add support for unpackaged resources to speed up loads on Android, i.e. so we don't have to decompress entire GPAs to load a single resource.

This commit is contained in:
elasota
2020-10-12 18:03:23 -04:00
parent ec56bdace2
commit 1ecef6f8ef
26 changed files with 674 additions and 252 deletions

View File

@@ -419,110 +419,6 @@ void HandleDepthSwitching (void)
PortabilityLayer::HostDisplayDriver::GetInstance()->SetUseICCProfile(isUseICCProfile != 0);
}
//-------------------------------------------------------------- CheckMemorySize
// Tests for a specific amount of memory available. If the required memory<72>
// is not available, attempts to turn off various game features (music, etc.)<29>
// in order to accomodate the constrained memory available.
void CheckMemorySize (void)
{
#define kBaseBytesNeeded 614400L // 600K Base memory
#define kPaddingBytes 204800L // 200K Padding
long bytesNeeded;
long soundBytes, musicBytes;
dontLoadMusic = false;
dontLoadSounds = false;
bytesNeeded = kBaseBytesNeeded; // base memory
soundBytes = SoundBytesNeeded(); // sound memory
if (soundBytes <= 0L)
RedAlert(kErrNoMemory);
else
bytesNeeded += soundBytes;
musicBytes = MusicBytesNeeded(); // music memory
if (musicBytes <= 0L)
RedAlert(kErrNoMemory);
else
bytesNeeded += musicBytes;
bytesNeeded += 4L * (long)thisMac.constrainedScreen.bottom; // main screen
bytesNeeded += (((long)houseRect.right - (long)houseRect.left) *
((long)houseRect.bottom + 1 - (long)houseRect.top) *
(long)thisMac.isDepth) / 8L; // work map
bytesNeeded += 4L * (long)houseRect.bottom;
bytesNeeded += (((long)houseRect.right - (long)houseRect.left) *
((long)houseRect.bottom + 1 - (long)houseRect.top) *
(long)thisMac.isDepth) / 8L; // back map
bytesNeeded += 4L * houseRect.bottom;
bytesNeeded += (((long)houseRect.right - (long)houseRect.left) * 21 *
(long)thisMac.isDepth) / 8L; // scoreboard map
bytesNeeded += (6396L * (long)thisMac.isDepth) / 8L; // more scoreboard
bytesNeeded += (32112L * (long)thisMac.isDepth) / 8L; // glider map
bytesNeeded += (32112L * (long)thisMac.isDepth) / 8L; // glider2 map
bytesNeeded += 32064L / 8L; // glider mask
bytesNeeded += (912L * (long)thisMac.isDepth) / 8L; // glider shadow
bytesNeeded += 864L / 8L; // shadow mask
bytesNeeded += (304L * (long)thisMac.isDepth) / 8L; // rubber bands
bytesNeeded += 288L / 8L; // bands mask
bytesNeeded += (19344L * (long)thisMac.isDepth) / 8L; // blower map
bytesNeeded += 19344L / 8L; // blower mask
bytesNeeded += (17856L * (long)thisMac.isDepth) / 8L; // furniture map
bytesNeeded += 17792L / 8L; // furniture mask
bytesNeeded += (33264L * (long)thisMac.isDepth) / 8L; // prizes map
bytesNeeded += 33176L / 8L; // prizes mask
bytesNeeded += (2904L * (long)thisMac.isDepth) / 8L; // points map
bytesNeeded += 2880L / 8L; // points mask
bytesNeeded += (1848L * (long)thisMac.isDepth) / 8L; // transport map
bytesNeeded += 1792L / 8L; // transport mask
bytesNeeded += (3360L * (long)thisMac.isDepth) / 8L; // switches map
bytesNeeded += (9144L * (long)thisMac.isDepth) / 8L; // lights map
bytesNeeded += 9072L / 8L; // lights mask
bytesNeeded += (21600L * (long)thisMac.isDepth) / 8L; // appliances map
bytesNeeded += 21520L / 8L; // appliances mask
bytesNeeded += (5600L * (long)thisMac.isDepth) / 8L; // toast map
bytesNeeded += 5568L / 8L; // toast mask
bytesNeeded += (1440L * (long)thisMac.isDepth) / 8L; // shredded map
bytesNeeded += 1400L / 8L; // shredded mask
bytesNeeded += (5784L * (long)thisMac.isDepth) / 8L; // balloon map
bytesNeeded += 5760L / 8L; // balloon mask
bytesNeeded += (9632L * (long)thisMac.isDepth) / 8L; // copter map
bytesNeeded += 9600L / 8L; // copter mask
bytesNeeded += (4928L * (long)thisMac.isDepth) / 8L; // dart map
bytesNeeded += 4864L / 8L; // dart mask
bytesNeeded += (2080L * (long)thisMac.isDepth) / 8L; // ball map
bytesNeeded += 2048L / 8L; // ball mask
bytesNeeded += (1168L * (long)thisMac.isDepth) / 8L; // drip map
bytesNeeded += 1152L / 8L; // drip mask
bytesNeeded += (1224L * (long)thisMac.isDepth) / 8L; // enemy map
bytesNeeded += 1188L / 8L; // enemy mask
bytesNeeded += (2064L * (long)thisMac.isDepth) / 8L; // fish map
bytesNeeded += 2048L / 8L; // fish mask
bytesNeeded += (8960L * (long)thisMac.isDepth) / 8L; // clutter map
bytesNeeded += 8832L / 8L; // clutter mask
bytesNeeded += (23040L * (long)thisMac.isDepth) / 8L; // support map
bytesNeeded += (4320L * (long)thisMac.isDepth) / 8L; // angel map
bytesNeeded += 4224L / 8L; // angel mask
bytesNeeded += sizeof(roomType);
bytesNeeded += sizeof(hotObject) * kMaxHotSpots;
bytesNeeded += sizeof(sparkleType) * kMaxSparkles;
bytesNeeded += sizeof(flyingPtType) * kMaxFlyingPts;
bytesNeeded += sizeof(flameType) * kMaxCandles;
bytesNeeded += sizeof(flameType) * kMaxTikis;
bytesNeeded += sizeof(flameType) * kMaxCoals;
bytesNeeded += sizeof(pendulumType) * kMaxPendulums;
bytesNeeded += sizeof(savedType) * kMaxSavedMaps;
bytesNeeded += sizeof(bandType) * kMaxRubberBands;
bytesNeeded += sizeof(greaseType) * kMaxGrease;
bytesNeeded += sizeof(starType) * kMaxStars;
bytesNeeded += sizeof(shredType) * kMaxShredded;
bytesNeeded += sizeof(dynaType) * kMaxDynamicObs;
bytesNeeded += sizeof(objDataType) * kMaxMasterObjects;
bytesNeeded += kDemoLength; SpinCursor(1);
SpinCursor(1);
}
void GetDeviceRect(Rect *rect)
{
unsigned int width;

View File

@@ -14,7 +14,7 @@
namespace PortabilityLayer
{
class ResolveCachingColor;
class ResourceArchive;
struct IResourceArchive;
class ScanlineMask;
class ResTypeID;
struct RGBAColor;
@@ -169,7 +169,6 @@ void CheckOurEnvirons (void);
void InstallResolutionHandler (void);
//void ReflectSecondMonitorEnvirons (Boolean, Boolean, Boolean);
void HandleDepthSwitching (void);
void CheckMemorySize (void);
Boolean CheckFileError (short, const PLPasStr &); // --- File Error.c
@@ -200,7 +199,7 @@ void LoadGraphic (DrawSurface *surface, short resID); // Only loads from app r
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 &);
bool LargeIconPlot (DrawSurface *, PortabilityLayer::IResourceArchive *, short, const Rect &);
void DrawCIcon (DrawSurface *surface, short, short, short);
char KeyMapOffsetFromRawKey (char);
long LongSquareRoot (long);

View File

@@ -235,7 +235,6 @@ void ToggleMusicWhilePlaying (void);
void SetMusicalMode (SInt16);
void InitMusic (void);
void KillMusic (void);
long MusicBytesNeeded (void);
void TellHerNoMusic (void);
Boolean AddNewObject (Point, SInt16, Boolean); // --- ObjectAdd.c
@@ -456,7 +455,6 @@ PLError_t LoadTriggerSound (SInt16);
void DumpTriggerSound (void);
void InitSound (void);
void KillSound (void);
long SoundBytesNeeded (void);
void TellHerNoSounds (void);
void BitchAboutSM3 (void);

View File

@@ -28,7 +28,7 @@
void UpdateGoToDialog (Dialog *);
int16_t GoToFilter (void *context, Dialog *dial, const TimeTaggedVOSEvent *evt);
extern PortabilityLayer::ResourceArchive *houseResFork;
extern PortabilityLayer::IResourceArchive *houseResFork;
houseHand thisHouse;

View File

@@ -36,7 +36,7 @@ Boolean IsFileReadOnly (const VFileSpec &);
AnimationPlayer theMovie;
Rect movieRect;
PortabilityLayer::ResourceArchive *houseResFork;
PortabilityLayer::IResourceArchive *houseResFork;
short wasHouseVersion;
GpIOStream *houseStream;
Boolean houseOpen, fileDirty, gameDirty;

View File

@@ -373,7 +373,6 @@ int gpAppMain()
// ReflectSecondMonitorEnvirons(false, true, true);
HandleDepthSwitching();
VariableInit(); SpinCursor(2);
CheckMemorySize();
GetExtraCursors(); SpinCursor(2);
InitMarquee();
CreatePointers(); SpinCursor(2);

View File

@@ -368,25 +368,6 @@ void KillMusic (void)
musicMutex->Destroy();
}
//-------------------------------------------------------------- MusicBytesNeeded
long MusicBytesNeeded (void)
{
size_t totalBytes;
short i;
totalBytes = 0L;
for (i = 0; i < kMaxMusic; i++)
{
size_t resSize = 0;
if (!PortabilityLayer::ResourceManager::GetInstance()->GetAppResourceArchive()->GetResourceSize('snd ', i + kBaseBufferMusicID, resSize))
return -1;
totalBytes += static_cast<long>(resSize);
}
return totalBytes;
}
//-------------------------------------------------------------- TellHerNoMusic
void TellHerNoMusic (void)

View File

@@ -68,7 +68,7 @@ Boolean originalFloor;
extern IGpCursor *handCursor;
extern short lastBackground;
extern PortabilityLayer::ResourceArchive *houseResFork;
extern PortabilityLayer::IResourceArchive *houseResFork;
//============================================================== Functions

View File

@@ -101,7 +101,7 @@ void UpdateLoadDialog (Dialog *theDialog)
if (SectRect(&dialogRect, &tempRect, &dummyRect))
{
PortabilityLayer::ResourceArchive *resFile = PortabilityLayer::ResourceManager::GetInstance()->LoadResFile(theHousesSpecs[i].m_dir, theHousesSpecs[i].m_name);
PortabilityLayer::IResourceArchive *resFile = PortabilityLayer::ResourceManager::GetInstance()->LoadResFile(theHousesSpecs[i].m_dir, theHousesSpecs[i].m_name);
if (resFile != nullptr)
{
if (!LargeIconPlot(surface, resFile, -16455, tempRect))

View File

@@ -367,27 +367,6 @@ void KillSound (void)
DumpBufferSounds();
}
//-------------------------------------------------------------- SoundBytesNeeded
long SoundBytesNeeded (void)
{
long totalBytes;
short i;
totalBytes = 0L;
for (i = 0; i < kMaxSounds - 1; i++)
{
size_t resSize = 0;
if (!PortabilityLayer::ResourceManager::GetInstance()->GetAppResourceArchive()->GetResourceSize('snd ', i + kBaseBufferSoundID, resSize))
return -1;
totalBytes += static_cast<long>(resSize);
// ReleaseResource(theSound);
}
return totalBytes;
}
//-------------------------------------------------------------- TellHerNoSounds
void TellHerNoSounds (void)

View File

@@ -330,7 +330,7 @@ void LoadScaledGraphicCustom(DrawSurface *surface, short resID, Rect *theRect)
//-------------------------------------------------------------- LargeIconPlot
// Draws a standard b&w icon (32 x 32) - resource is an 'ICON'.
bool LargeIconPlot (DrawSurface *surface, PortabilityLayer::ResourceArchive *resFile, short resID, const Rect &theRect)
bool LargeIconPlot (DrawSurface *surface, PortabilityLayer::IResourceArchive *resFile, short resID, const Rect &theRect)
{
Handle hdl = resFile->LoadResource('icl8', resID);
if (hdl)