[Scummvm-git-logs] scummvm master -> ab669cbb6b740290447aac68bde51c2b6468d244
sluicebox
noreply at scummvm.org
Sun Aug 18 00:57:22 UTC 2024
This automated email contains information about 10 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
c1256d2fc3 ENGINES: Update Advanced Detector comments
29ebd43d2e SCI: Cleanup warning messages
5761f2d768 AGI: Remove AgiLoader::unloadResource implementations
6b50eadebf AGI: Remove "agi" prefix from AgiEngine method names
8b5dd0ce2e AGI: Cleanup picture/view unload
fb35bc6aa9 AGI: Cleanup AgiLoader
22dc206476 AGI: Remove AgiLoader::loadResource implementations
4bba0c332e AGI: Cleanup AgiLoader initialization
65b606feb7 AGI: Cleanup AgiDir initialization
ab669cbb6b AGI: Cleanup warning messages
Commit: c1256d2fc365cfcb9ca8a2ddae4d7efed6bcf17e
https://github.com/scummvm/scummvm/commit/c1256d2fc365cfcb9ca8a2ddae4d7efed6bcf17e
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:54:12-07:00
Commit Message:
ENGINES: Update Advanced Detector comments
Changed paths:
engines/advancedDetector.h
diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h
index 9acb3b0b22a..6647952cb32 100644
--- a/engines/advancedDetector.h
+++ b/engines/advancedDetector.h
@@ -307,7 +307,7 @@ struct ADDetectedGameExtraInfo {
struct ADDetectedGame {
bool hasUnknownFiles; /*!< Whether the game has unknown files. */
FilePropertiesMap matchedFiles; /*!< List of the files that were used to match the game. */
- const ADGameDescription *desc; /*!< Human-readable game title. */
+ const ADGameDescription *desc; /*!< Matching game description from detection table. */
ADDetectedGame() : desc(nullptr), hasUnknownFiles(false) {}
/**
@@ -521,7 +521,7 @@ public:
protected:
/**
- * A hashmap of files and their MD5 checksums.
+ * A hashmap of file paths and their file system nodes.
*/
typedef Common::HashMap<Common::Path, Common::FSNode, Common::Path::IgnoreCase_Hash, Common::Path::IgnoreCase_EqualTo> FileMap;
@@ -645,7 +645,7 @@ public:
public:
/**
- * A hashmap of files and their MD5 checksums.
+ * A hashmap of file paths and their file system nodes.
*/
typedef Common::HashMap<Common::Path, Common::FSNode, Common::Path::IgnoreCase_Hash, Common::Path::IgnoreCase_EqualTo> FileMap;
Commit: 29ebd43d2e17ad89961ba39a5d18e9a2943ea0ab
https://github.com/scummvm/scummvm/commit/29ebd43d2e17ad89961ba39a5d18e9a2943ea0ab
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:54:13-07:00
Commit Message:
SCI: Cleanup warning messages
Changed paths:
engines/sci/console.cpp
engines/sci/detection.cpp
engines/sci/engine/scriptdebug.cpp
engines/sci/sci.cpp
engines/sci/sound/drivers/casio.cpp
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index f70bb2da9e4..99cf183dec6 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -304,7 +304,7 @@ void Console::postEnter() {
playVideo(*videoDecoder);
_engine->_gfxCursor->kernelShow();
} else
- warning("Could not play video %s\n", _videoFile.toString(Common::Path::kNativeSeparator).c_str());
+ warning("Could not play video %s", _videoFile.toString(Common::Path::kNativeSeparator).c_str());
_videoFile.clear();
_videoFrameDelay = 0;
diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp
index 8ff876fd1f2..d2049a29768 100644
--- a/engines/sci/detection.cpp
+++ b/engines/sci/detection.cpp
@@ -246,7 +246,7 @@ ADDetectedGame SciMetaEngineDetection::fallbackDetect(const FileMap &allFiles, c
if (ConfMan.hasKey("always_run_fallback_detection_extern")) {
if (ConfMan.getBool("always_run_fallback_detection_extern") == false) {
- warning("SCI: Fallback detection is disabled.");
+ warning("SCI: Fallback detection is disabled");
return ADDetectedGame();
}
}
@@ -255,7 +255,7 @@ ADDetectedGame SciMetaEngineDetection::fallbackDetect(const FileMap &allFiles, c
if (!enginePlugin) {
static bool warn = true;
if (warn) {
- warning("Engine plugin for SCI not present. Fallback detection is disabled.");
+ warning("Engine plugin for SCI not present. Fallback detection is disabled");
warn = false;
}
return ADDetectedGame();
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index 779587229b1..c3d4ba319e2 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -626,7 +626,7 @@ void Kernel::dissectScript(int scriptNumber, Vocabulary *vocab) {
Resource *script = _resMan->findResource(ResourceId(kResourceTypeScript, scriptNumber), false);
if (!script) {
- warning("dissectScript(): Script not found!\n");
+ warning("dissectScript(): Script not found");
return;
}
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index e937ed08d52..3feae4168c2 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -384,7 +384,7 @@ Common::Error SciEngine::run() {
// we try to find the super class address of the game object, we can't do that earlier
const Object *gameObject = segMan->getObject(_gameObjectAddress);
if (!gameObject) {
- warning("Could not get game object, aborting...");
+ warning("Could not get game object, aborting");
return Common::kUnknownError;
}
diff --git a/engines/sci/sound/drivers/casio.cpp b/engines/sci/sound/drivers/casio.cpp
index bfa47cf1a00..80f5aaae74a 100644
--- a/engines/sci/sound/drivers/casio.cpp
+++ b/engines/sci/sound/drivers/casio.cpp
@@ -397,7 +397,7 @@ MidiPlayer_Casio::~MidiPlayer_Casio() {
int MidiPlayer_Casio::open(ResourceManager* resMan) {
if (_version < SCI_VERSION_0_LATE || _version > SCI_VERSION_01) {
- warning("CASIO: Unsupported SCI version.");
+ warning("CASIO: Unsupported SCI version");
return -1;
}
Commit: 5761f2d768290dc9d6a89c5a2a46ea51d4847aac
https://github.com/scummvm/scummvm/commit/5761f2d768290dc9d6a89c5a2a46ea51d4847aac
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:56:29-07:00
Commit Message:
AGI: Remove AgiLoader::unloadResource implementations
All three implementations were the same
Changed paths:
engines/agi/agi.cpp
engines/agi/agi.h
engines/agi/loader_v1.cpp
engines/agi/loader_v2.cpp
engines/agi/loader_v3.cpp
diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index 6ed402a1f6c..a90a97a13cc 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -174,12 +174,12 @@ int AgiEngine::agiInit() {
void AgiEngine::agiUnloadResources() {
// Make sure logic 0 is always loaded
for (int i = 1; i < MAX_DIRECTORY_ENTRIES; i++) {
- _loader->unloadResource(RESOURCETYPE_LOGIC, i);
+ agiUnloadResource(RESOURCETYPE_LOGIC, i);
}
for (int i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
- _loader->unloadResource(RESOURCETYPE_VIEW, i);
- _loader->unloadResource(RESOURCETYPE_PICTURE, i);
- _loader->unloadResource(RESOURCETYPE_SOUND, i);
+ agiUnloadResource(RESOURCETYPE_VIEW, i);
+ agiUnloadResource(RESOURCETYPE_PICTURE, i);
+ agiUnloadResource(RESOURCETYPE_SOUND, i);
}
}
@@ -189,7 +189,7 @@ void AgiEngine::agiDeinit() {
_words->clearEgoWords(); // remove all words from memory
agiUnloadResources(); // unload resources in memory
- _loader->unloadResource(RESOURCETYPE_LOGIC, 0);
+ agiUnloadResource(RESOURCETYPE_LOGIC, 0);
_objects.clear();
_words->unloadDictionary();
@@ -219,7 +219,22 @@ int AgiEngine::agiLoadResource(int16 resourceType, int16 resourceNr) {
}
void AgiEngine::agiUnloadResource(int16 resourceType, int16 resourceNr) {
- _loader->unloadResource(resourceType, resourceNr);
+ switch (resourceType) {
+ case RESOURCETYPE_LOGIC:
+ unloadLogic(resourceNr);
+ break;
+ case RESOURCETYPE_PICTURE:
+ _picture->unloadPicture(resourceNr);
+ break;
+ case RESOURCETYPE_VIEW:
+ unloadView(resourceNr);
+ break;
+ case RESOURCETYPE_SOUND:
+ _sound->unloadSound(resourceNr);
+ break;
+ default:
+ break;
+ }
}
struct GameSettings {
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 1f0dfe25b36..b2362bafeef 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -562,7 +562,6 @@ public:
virtual int init() = 0;
virtual int detectGame() = 0;
virtual int loadResource(int16 resourceType, int16 resourceNr) = 0;
- virtual void unloadResource(int16 resourceType, int16 resourceNr) = 0;
virtual int loadObjects(const char *fname) = 0;
virtual int loadWords(const char *fname) = 0;
};
@@ -583,7 +582,6 @@ public:
int init() override;
int detectGame() override;
int loadResource(int16 resourceType, int16 resourceNr) override;
- void unloadResource(int16 resourceType, int16 resourceNr) override;
int loadObjects(const char *fname) override;
int loadWords(const char *fname) override;
};
@@ -607,7 +605,6 @@ public:
int init() override;
int detectGame() override;
int loadResource(int16 resourceType, int16 resourceNr) override;
- void unloadResource(int16 resourceType, int16 resourceNr) override;
int loadObjects(const char *fname) override;
int loadWords(const char *fname) override;
};
@@ -628,7 +625,6 @@ public:
int init() override;
int detectGame() override;
int loadResource(int16 resourceType, int16 resourceNr) override;
- void unloadResource(int16 resourceType, int16 resourceNr) override;
int loadObjects(const char *fname) override;
int loadWords(const char *fname) override;
};
diff --git a/engines/agi/loader_v1.cpp b/engines/agi/loader_v1.cpp
index c6441a4d416..196ca1bb268 100644
--- a/engines/agi/loader_v1.cpp
+++ b/engines/agi/loader_v1.cpp
@@ -208,7 +208,7 @@ int AgiLoader_v1::loadResource(int16 resourceType, int16 resourceNr) {
case RESOURCETYPE_LOGIC:
if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) {
debugC(3, kDebugLevelResources, "loading logic resource %d", resourceNr);
- unloadResource(RESOURCETYPE_LOGIC, resourceNr);
+ _vm->agiUnloadResource(RESOURCETYPE_LOGIC, resourceNr);
// load raw resource into data
data = loadVolRes(&_vm->_game.dirLogic[resourceNr]);
@@ -232,7 +232,7 @@ int AgiLoader_v1::loadResource(int16 resourceType, int16 resourceNr) {
// if loaded but not cached, unload it
// if cached but not loaded, etc
- unloadResource(RESOURCETYPE_PICTURE, resourceNr);
+ _vm->agiUnloadResource(RESOURCETYPE_PICTURE, resourceNr);
data = loadVolRes(&_vm->_game.dirPic[resourceNr]);
if (data != nullptr) {
@@ -267,7 +267,7 @@ int AgiLoader_v1::loadResource(int16 resourceType, int16 resourceNr) {
break;
debugC(3, kDebugLevelResources, "loading view resource %d", resourceNr);
- unloadResource(RESOURCETYPE_VIEW, resourceNr);
+ _vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
data = loadVolRes(&_vm->_game.dirView[resourceNr]);
if (data) {
_vm->_game.dirView[resourceNr].flags |= RES_LOADED;
@@ -285,25 +285,6 @@ int AgiLoader_v1::loadResource(int16 resourceType, int16 resourceNr) {
return ec;
}
-void AgiLoader_v1::unloadResource(int16 resourceType, int16 resourceNr) {
- switch (resourceType) {
- case RESOURCETYPE_LOGIC:
- _vm->unloadLogic(resourceNr);
- break;
- case RESOURCETYPE_PICTURE:
- _vm->_picture->unloadPicture(resourceNr);
- break;
- case RESOURCETYPE_VIEW:
- _vm->unloadView(resourceNr);
- break;
- case RESOURCETYPE_SOUND:
- _vm->_sound->unloadSound(resourceNr);
- break;
- default:
- break;
- }
-}
-
int AgiLoader_v1::loadObjects(const char *fname) {
if (_vm->getGameID() == GID_BC) {
Common::File f;
diff --git a/engines/agi/loader_v2.cpp b/engines/agi/loader_v2.cpp
index 639fffb9181..c93dbeeb77b 100644
--- a/engines/agi/loader_v2.cpp
+++ b/engines/agi/loader_v2.cpp
@@ -141,25 +141,6 @@ int AgiLoader_v2::init() {
return ec;
}
-void AgiLoader_v2::unloadResource(int16 resourceType, int16 resourceNr) {
- switch (resourceType) {
- case RESOURCETYPE_LOGIC:
- _vm->unloadLogic(resourceNr);
- break;
- case RESOURCETYPE_PICTURE:
- _vm->_picture->unloadPicture(resourceNr);
- break;
- case RESOURCETYPE_VIEW:
- _vm->unloadView(resourceNr);
- break;
- case RESOURCETYPE_SOUND:
- _vm->_sound->unloadSound(resourceNr);
- break;
- default:
- break;
- }
-}
-
/**
* This function loads a raw resource into memory,
* if further decoding is required, it must be done by another
@@ -232,7 +213,7 @@ int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) {
case RESOURCETYPE_LOGIC:
if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) {
debugC(3, kDebugLevelResources, "loading logic resource %d", resourceNr);
- unloadResource(RESOURCETYPE_LOGIC, resourceNr);
+ _vm->agiUnloadResource(RESOURCETYPE_LOGIC, resourceNr);
// load raw resource into data
data = loadVolRes(&_vm->_game.dirLogic[resourceNr]);
@@ -244,7 +225,7 @@ int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) {
}
// if logic was cached, we get here
- // reset code pointers incase it was cached
+ // reset code pointers in case it was cached
_vm->_game.logics[resourceNr].cIP = _vm->_game.logics[resourceNr].sIP;
break;
@@ -258,7 +239,7 @@ int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) {
// if loaded but not cached, unload it
// if cached but not loaded, etc
- unloadResource(RESOURCETYPE_PICTURE, resourceNr);
+ _vm->agiUnloadResource(RESOURCETYPE_PICTURE, resourceNr);
data = loadVolRes(&_vm->_game.dirPic[resourceNr]);
if (data != nullptr) {
@@ -293,7 +274,7 @@ int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) {
break;
debugC(3, kDebugLevelResources, "loading view resource %d", resourceNr);
- unloadResource(RESOURCETYPE_VIEW, resourceNr);
+ _vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
data = loadVolRes(&_vm->_game.dirView[resourceNr]);
if (data) {
_vm->_game.dirView[resourceNr].flags |= RES_LOADED;
diff --git a/engines/agi/loader_v3.cpp b/engines/agi/loader_v3.cpp
index b45ca86d12b..0a73ae00ddd 100644
--- a/engines/agi/loader_v3.cpp
+++ b/engines/agi/loader_v3.cpp
@@ -138,25 +138,6 @@ int AgiLoader_v3::init() {
return ec;
}
-void AgiLoader_v3::unloadResource(int16 resourceType, int16 resourceNr) {
- switch (resourceType) {
- case RESOURCETYPE_LOGIC:
- _vm->unloadLogic(resourceNr);
- break;
- case RESOURCETYPE_PICTURE:
- _vm->_picture->unloadPicture(resourceNr);
- break;
- case RESOURCETYPE_VIEW:
- _vm->unloadView(resourceNr);
- break;
- case RESOURCETYPE_SOUND:
- _vm->_sound->unloadSound(resourceNr);
- break;
- default:
- break;
- }
-}
-
/**
* This function loads a raw resource into memory.
* If further decoding is required, it must be done by another
@@ -234,7 +215,7 @@ int AgiLoader_v3::loadResource(int16 resourceType, int16 resourceNr) {
// and build the message list (if logic is in memory)
if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) {
// if logic is already in memory, unload it
- unloadResource(RESOURCETYPE_LOGIC, resourceNr);
+ _vm->agiUnloadResource(RESOURCETYPE_LOGIC, resourceNr);
// load raw resource into data
data = loadVolRes(&_vm->_game.dirLogic[resourceNr]);
@@ -258,7 +239,7 @@ int AgiLoader_v3::loadResource(int16 resourceType, int16 resourceNr) {
// if picture is currently NOT loaded *OR* cacheing is off,
// unload the resource (caching==off) and reload it
if (~_vm->_game.dirPic[resourceNr].flags & RES_LOADED) {
- unloadResource(RESOURCETYPE_PICTURE, resourceNr);
+ _vm->agiUnloadResource(RESOURCETYPE_PICTURE, resourceNr);
data = loadVolRes(&_vm->_game.dirPic[resourceNr]);
if (data != nullptr) {
_vm->_game.pictures[resourceNr].rdata = data;
@@ -292,7 +273,7 @@ int AgiLoader_v3::loadResource(int16 resourceType, int16 resourceNr) {
if (_vm->_game.dirView[resourceNr].flags & RES_LOADED)
break;
- unloadResource(RESOURCETYPE_VIEW, resourceNr);
+ _vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
data = loadVolRes(&_vm->_game.dirView[resourceNr]);
if (data != nullptr) {
_vm->_game.dirView[resourceNr].flags |= RES_LOADED;
Commit: 6b50eadebf23566b415179e6ad6abd941771bde3
https://github.com/scummvm/scummvm/commit/6b50eadebf23566b415179e6ad6abd941771bde3
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:56:29-07:00
Commit Message:
AGI: Remove "agi" prefix from AgiEngine method names
Changed paths:
engines/agi/agi.cpp
engines/agi/agi.h
engines/agi/console.cpp
engines/agi/cycle.cpp
engines/agi/loader_v1.cpp
engines/agi/loader_v2.cpp
engines/agi/loader_v3.cpp
engines/agi/op_cmd.cpp
engines/agi/saveload.cpp
engines/agi/sprite.cpp
engines/agi/view.cpp
diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index a90a97a13cc..5cab6a3cabd 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -171,15 +171,15 @@ int AgiEngine::agiInit() {
return ec;
}
-void AgiEngine::agiUnloadResources() {
+void AgiEngine::unloadResources() {
// Make sure logic 0 is always loaded
for (int i = 1; i < MAX_DIRECTORY_ENTRIES; i++) {
- agiUnloadResource(RESOURCETYPE_LOGIC, i);
+ unloadResource(RESOURCETYPE_LOGIC, i);
}
for (int i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
- agiUnloadResource(RESOURCETYPE_VIEW, i);
- agiUnloadResource(RESOURCETYPE_PICTURE, i);
- agiUnloadResource(RESOURCETYPE_SOUND, i);
+ unloadResource(RESOURCETYPE_VIEW, i);
+ unloadResource(RESOURCETYPE_PICTURE, i);
+ unloadResource(RESOURCETYPE_SOUND, i);
}
}
@@ -188,15 +188,15 @@ void AgiEngine::agiDeinit() {
return;
_words->clearEgoWords(); // remove all words from memory
- agiUnloadResources(); // unload resources in memory
- agiUnloadResource(RESOURCETYPE_LOGIC, 0);
+ unloadResources(); // unload resources in memory
+ unloadResource(RESOURCETYPE_LOGIC, 0);
_objects.clear();
_words->unloadDictionary();
clearImageStack();
}
-int AgiEngine::agiLoadResource(int16 resourceType, int16 resourceNr) {
+int AgiEngine::loadResource(int16 resourceType, int16 resourceNr) {
int ec = _loader->loadResource(resourceType, resourceNr);
// WORKAROUND: Patches broken picture 147 in a corrupted Amiga version of Gold Rush! (v2.05 1989-03-09).
@@ -218,7 +218,7 @@ int AgiEngine::agiLoadResource(int16 resourceType, int16 resourceNr) {
return ec;
}
-void AgiEngine::agiUnloadResource(int16 resourceType, int16 resourceNr) {
+void AgiEngine::unloadResource(int16 resourceType, int16 resourceNr) {
switch (resourceType) {
case RESOURCETYPE_LOGIC:
unloadLogic(resourceNr);
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index b2362bafeef..9eebdebba49 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -850,9 +850,12 @@ public:
int agiInit();
void agiDeinit();
- int agiLoadResource(int16 resourceType, int16 resourceNr);
- void agiUnloadResource(int16 resourceType, int16 resourceNr);
- void agiUnloadResources();
+ int loadResource(int16 resourceType, int16 resourceNr);
+ void unloadResource(int16 resourceType, int16 resourceNr);
+ /**
+ * Unload all resources except Logic 0
+ */
+ void unloadResources();
int getKeypress() override;
bool isKeypress() override;
diff --git a/engines/agi/console.cpp b/engines/agi/console.cpp
index f7f10cca6f9..c8d006715f9 100644
--- a/engines/agi/console.cpp
+++ b/engines/agi/console.cpp
@@ -159,7 +159,7 @@ bool Console::Cmd_Version(int argc, const char **argv) {
bool scriptLoadedByUs = false;
if (!(game->dirLogic[scriptNr].flags & RES_LOADED)) {
// But not currently loaded? -> load it now
- if (_vm->agiLoadResource(RESOURCETYPE_LOGIC, scriptNr) != errOK) {
+ if (_vm->loadResource(RESOURCETYPE_LOGIC, scriptNr) != errOK) {
// In case we can't load the source, skip it
continue;
}
@@ -259,7 +259,7 @@ bool Console::Cmd_Version(int argc, const char **argv) {
}
if (scriptLoadedByUs) {
- _vm->agiUnloadResource(RESOURCETYPE_LOGIC, scriptNr);
+ _vm->unloadResource(RESOURCETYPE_LOGIC, scriptNr);
}
}
diff --git a/engines/agi/cycle.cpp b/engines/agi/cycle.cpp
index 4d76fd55c7a..2b4f5f06e36 100644
--- a/engines/agi/cycle.cpp
+++ b/engines/agi/cycle.cpp
@@ -58,7 +58,7 @@ void AgiEngine::newRoom(int16 newRoomNr) {
screenObj.cycleTimeCount = 1;
screenObj.stepSize = 1;
}
- agiUnloadResources();
+ unloadResources();
_game.playerControl = true;
_game.block.active = false;
@@ -69,7 +69,7 @@ void AgiEngine::newRoom(int16 newRoomNr) {
setVar(VM_VAR_BORDER_CODE, 0);
setVar(VM_VAR_EGO_VIEW_RESOURCE, screenObjEgo->currentViewNr);
- agiLoadResource(RESOURCETYPE_LOGIC, newRoomNr);
+ loadResource(RESOURCETYPE_LOGIC, newRoomNr);
// Reposition ego in the new room
switch (getVar(VM_VAR_BORDER_TOUCH_EGO)) {
@@ -96,7 +96,7 @@ void AgiEngine::newRoom(int16 newRoomNr) {
screenObjEgo->flags &= ~fDidntMove;
// animateObject(0);
- agiLoadResource(RESOURCETYPE_VIEW, screenObjEgo->currentViewNr);
+ loadResource(RESOURCETYPE_VIEW, screenObjEgo->currentViewNr);
setView(screenObjEgo, screenObjEgo->currentViewNr);
} else {
diff --git a/engines/agi/loader_v1.cpp b/engines/agi/loader_v1.cpp
index 196ca1bb268..788d55cc607 100644
--- a/engines/agi/loader_v1.cpp
+++ b/engines/agi/loader_v1.cpp
@@ -208,7 +208,7 @@ int AgiLoader_v1::loadResource(int16 resourceType, int16 resourceNr) {
case RESOURCETYPE_LOGIC:
if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) {
debugC(3, kDebugLevelResources, "loading logic resource %d", resourceNr);
- _vm->agiUnloadResource(RESOURCETYPE_LOGIC, resourceNr);
+ _vm->unloadResource(RESOURCETYPE_LOGIC, resourceNr);
// load raw resource into data
data = loadVolRes(&_vm->_game.dirLogic[resourceNr]);
@@ -232,7 +232,7 @@ int AgiLoader_v1::loadResource(int16 resourceType, int16 resourceNr) {
// if loaded but not cached, unload it
// if cached but not loaded, etc
- _vm->agiUnloadResource(RESOURCETYPE_PICTURE, resourceNr);
+ _vm->unloadResource(RESOURCETYPE_PICTURE, resourceNr);
data = loadVolRes(&_vm->_game.dirPic[resourceNr]);
if (data != nullptr) {
@@ -267,7 +267,7 @@ int AgiLoader_v1::loadResource(int16 resourceType, int16 resourceNr) {
break;
debugC(3, kDebugLevelResources, "loading view resource %d", resourceNr);
- _vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
+ _vm->unloadResource(RESOURCETYPE_VIEW, resourceNr);
data = loadVolRes(&_vm->_game.dirView[resourceNr]);
if (data) {
_vm->_game.dirView[resourceNr].flags |= RES_LOADED;
diff --git a/engines/agi/loader_v2.cpp b/engines/agi/loader_v2.cpp
index c93dbeeb77b..87c76145d4d 100644
--- a/engines/agi/loader_v2.cpp
+++ b/engines/agi/loader_v2.cpp
@@ -213,7 +213,7 @@ int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) {
case RESOURCETYPE_LOGIC:
if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) {
debugC(3, kDebugLevelResources, "loading logic resource %d", resourceNr);
- _vm->agiUnloadResource(RESOURCETYPE_LOGIC, resourceNr);
+ _vm->unloadResource(RESOURCETYPE_LOGIC, resourceNr);
// load raw resource into data
data = loadVolRes(&_vm->_game.dirLogic[resourceNr]);
@@ -239,7 +239,7 @@ int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) {
// if loaded but not cached, unload it
// if cached but not loaded, etc
- _vm->agiUnloadResource(RESOURCETYPE_PICTURE, resourceNr);
+ _vm->unloadResource(RESOURCETYPE_PICTURE, resourceNr);
data = loadVolRes(&_vm->_game.dirPic[resourceNr]);
if (data != nullptr) {
@@ -274,7 +274,7 @@ int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) {
break;
debugC(3, kDebugLevelResources, "loading view resource %d", resourceNr);
- _vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
+ _vm->unloadResource(RESOURCETYPE_VIEW, resourceNr);
data = loadVolRes(&_vm->_game.dirView[resourceNr]);
if (data) {
_vm->_game.dirView[resourceNr].flags |= RES_LOADED;
diff --git a/engines/agi/loader_v3.cpp b/engines/agi/loader_v3.cpp
index 0a73ae00ddd..f3506c6595a 100644
--- a/engines/agi/loader_v3.cpp
+++ b/engines/agi/loader_v3.cpp
@@ -215,7 +215,7 @@ int AgiLoader_v3::loadResource(int16 resourceType, int16 resourceNr) {
// and build the message list (if logic is in memory)
if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) {
// if logic is already in memory, unload it
- _vm->agiUnloadResource(RESOURCETYPE_LOGIC, resourceNr);
+ _vm->unloadResource(RESOURCETYPE_LOGIC, resourceNr);
// load raw resource into data
data = loadVolRes(&_vm->_game.dirLogic[resourceNr]);
@@ -239,7 +239,7 @@ int AgiLoader_v3::loadResource(int16 resourceType, int16 resourceNr) {
// if picture is currently NOT loaded *OR* cacheing is off,
// unload the resource (caching==off) and reload it
if (~_vm->_game.dirPic[resourceNr].flags & RES_LOADED) {
- _vm->agiUnloadResource(RESOURCETYPE_PICTURE, resourceNr);
+ _vm->unloadResource(RESOURCETYPE_PICTURE, resourceNr);
data = loadVolRes(&_vm->_game.dirPic[resourceNr]);
if (data != nullptr) {
_vm->_game.pictures[resourceNr].rdata = data;
@@ -273,7 +273,7 @@ int AgiLoader_v3::loadResource(int16 resourceType, int16 resourceNr) {
if (_vm->_game.dirView[resourceNr].flags & RES_LOADED)
break;
- _vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
+ _vm->unloadResource(RESOURCETYPE_VIEW, resourceNr);
data = loadVolRes(&_vm->_game.dirView[resourceNr]);
if (data != nullptr) {
_vm->_game.dirView[resourceNr].flags |= RES_LOADED;
diff --git a/engines/agi/op_cmd.cpp b/engines/agi/op_cmd.cpp
index 90b7ccc3724..21c77d465d9 100644
--- a/engines/agi/op_cmd.cpp
+++ b/engines/agi/op_cmd.cpp
@@ -270,39 +270,39 @@ void cmdNewRoomF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
void cmdLoadView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 resourceNr = parameter[0];
- vm->agiLoadResource(RESOURCETYPE_VIEW, resourceNr);
+ vm->loadResource(RESOURCETYPE_VIEW, resourceNr);
}
void cmdLoadLogic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 resourceNr = parameter[0];
- vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
+ vm->loadResource(RESOURCETYPE_LOGIC, resourceNr);
}
void cmdLoadSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 resourceNr = parameter[0];
- vm->agiLoadResource(RESOURCETYPE_SOUND, resourceNr);
+ vm->loadResource(RESOURCETYPE_SOUND, resourceNr);
}
void cmdLoadViewF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 varNr = parameter[0];
byte value = vm->getVar(varNr);
- vm->agiLoadResource(RESOURCETYPE_VIEW, value);
+ vm->loadResource(RESOURCETYPE_VIEW, value);
}
void cmdLoadLogicF(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 varNr = parameter[0];
byte value = vm->getVar(varNr);
- vm->agiLoadResource(RESOURCETYPE_LOGIC, value);
+ vm->loadResource(RESOURCETYPE_LOGIC, value);
}
void cmdDiscardView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 resourceNr = parameter[0];
- vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr);
+ vm->unloadResource(RESOURCETYPE_VIEW, resourceNr);
}
void cmdObjectOnAnything(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -971,7 +971,7 @@ void cmdSetSimple(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 resourceNr = vm->getVar(varNr);
spritesMgr->eraseSprites();
- vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr);
+ vm->loadResource(RESOURCETYPE_PICTURE, resourceNr);
// Draw the picture. Similar to void cmdDraw_pic(AgiGame *state, AgiEngine *vm, uint8 *p).
vm->_picture->decodePicture(resourceNr, false, true);
@@ -1223,7 +1223,7 @@ void cmdLoadPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 resourceNr = vm->getVar(varNr);
spritesMgr->eraseSprites();
- vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr);
+ vm->loadResource(RESOURCETYPE_PICTURE, resourceNr);
spritesMgr->buildAllSpriteLists();
spritesMgr->drawAllSpriteLists();
}
@@ -1232,7 +1232,7 @@ void cmdLoadPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 varNr = parameter[0];
uint16 resourceNr = vm->getVar(varNr);
- vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr);
+ vm->loadResource(RESOURCETYPE_PICTURE, resourceNr);
}
void cmdDiscardPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
@@ -2301,7 +2301,7 @@ void cmdSetItemView(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
void cmdCallV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 resourceNr = parameter[0];
- vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
+ vm->loadResource(RESOURCETYPE_LOGIC, resourceNr);
// FIXME: The following instruction looks incomplete.
// Maybe something is meant to be assigned to, or read from,
// the logic_list entry?
@@ -2315,7 +2315,7 @@ void cmdNewRoomV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 resourceNr = parameter[0];
warning("cmdNewRoomV1()");
- vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
+ vm->loadResource(RESOURCETYPE_LOGIC, resourceNr);
state->max_logics = 1;
state->logic_list[1] = resourceNr;
vm->setVar(13, 1);
@@ -2325,7 +2325,7 @@ void cmdNewRoomVV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) {
uint16 resourceNr = vm->getVar(parameter[0]);
warning("cmdNewRoomVV1()");
- vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr);
+ vm->loadResource(RESOURCETYPE_LOGIC, resourceNr);
state->max_logics = 1;
state->logic_list[1] = resourceNr;
vm->setVar(13, 1);
@@ -2365,7 +2365,7 @@ int AgiEngine::runLogic(int16 logicNr) {
// If logic not loaded, load it
if (~_game.dirLogic[logicNr].flags & RES_LOADED) {
debugC(4, kDebugLevelScripts, "logic %d not loaded!", logicNr);
- agiLoadResource(RESOURCETYPE_LOGIC, logicNr);
+ loadResource(RESOURCETYPE_LOGIC, logicNr);
}
_game.curLogicNr = logicNr;
diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp
index bb0e6aa296b..2d776256956 100644
--- a/engines/agi/saveload.cpp
+++ b/engines/agi/saveload.cpp
@@ -573,32 +573,32 @@ int AgiEngine::loadGame(const Common::String &fileName, bool checkId) {
for (i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
if (in->readByte() & RES_LOADED)
- agiLoadResource(RESOURCETYPE_LOGIC, i);
+ loadResource(RESOURCETYPE_LOGIC, i);
else
- agiUnloadResource(RESOURCETYPE_LOGIC, i);
+ unloadResource(RESOURCETYPE_LOGIC, i);
_game.logics[i].sIP = in->readSint16BE();
_game.logics[i].cIP = in->readSint16BE();
}
for (i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
if (in->readByte() & RES_LOADED)
- agiLoadResource(RESOURCETYPE_PICTURE, i);
+ loadResource(RESOURCETYPE_PICTURE, i);
else
- agiUnloadResource(RESOURCETYPE_PICTURE, i);
+ unloadResource(RESOURCETYPE_PICTURE, i);
}
for (i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
if (in->readByte() & RES_LOADED)
- agiLoadResource(RESOURCETYPE_VIEW, i);
+ loadResource(RESOURCETYPE_VIEW, i);
else
- agiUnloadResource(RESOURCETYPE_VIEW, i);
+ unloadResource(RESOURCETYPE_VIEW, i);
}
for (i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
if (in->readByte() & RES_LOADED)
- agiLoadResource(RESOURCETYPE_SOUND, i);
+ loadResource(RESOURCETYPE_SOUND, i);
else
- agiUnloadResource(RESOURCETYPE_SOUND, i);
+ unloadResource(RESOURCETYPE_SOUND, i);
}
// game.pictures - loaded above
@@ -705,7 +705,7 @@ int AgiEngine::loadGame(const Common::String &fileName, bool checkId) {
continue;
if (!(_game.dirView[screenObj->currentViewNr].flags & RES_LOADED))
- agiLoadResource(RESOURCETYPE_VIEW, screenObj->currentViewNr);
+ loadResource(RESOURCETYPE_VIEW, screenObj->currentViewNr);
setView(screenObj, screenObj->currentViewNr); // Fix v->view_data
setLoop(screenObj, screenObj->currentLoopNr); // Fix v->loop_data
@@ -1037,11 +1037,11 @@ void AgiEngine::replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
switch (type) {
case ADD_PIC:
debugC(8, kDebugLevelMain, "--- decoding picture %d ---", p1);
- agiLoadResource(RESOURCETYPE_PICTURE, p1);
+ loadResource(RESOURCETYPE_PICTURE, p1);
_picture->decodePicture(p1, p2, p3 != 0);
break;
case ADD_VIEW:
- agiLoadResource(RESOURCETYPE_VIEW, p1);
+ loadResource(RESOURCETYPE_VIEW, p1);
_sprites->addToPic(p1, p2, p3, p4, p5, p6, p7);
break;
default:
diff --git a/engines/agi/sprite.cpp b/engines/agi/sprite.cpp
index 844ca850c48..849857f27e9 100644
--- a/engines/agi/sprite.cpp
+++ b/engines/agi/sprite.cpp
@@ -406,7 +406,7 @@ void SpritesMgr::showObject(int16 viewNr) {
ScreenObjEntry screenObj;
uint8 *backgroundBuffer = nullptr;
- _vm->agiLoadResource(RESOURCETYPE_VIEW, viewNr);
+ _vm->loadResource(RESOURCETYPE_VIEW, viewNr);
_vm->setView(&screenObj, viewNr);
screenObj.ySize_prev = screenObj.celData->height;
diff --git a/engines/agi/view.cpp b/engines/agi/view.cpp
index 40f9100888b..3cb2e2fe213 100644
--- a/engines/agi/view.cpp
+++ b/engines/agi/view.cpp
@@ -426,7 +426,7 @@ void AgiEngine::setView(ScreenObjEntry *screenObj, int16 viewNr) {
// Original interpreter bombs out in this situation saying "view not loaded, Press ESC to quit"
warning("setView() called on screen object %d to use view %d, but view not loaded", screenObj->objectNr, viewNr);
warning("probably game script bug, trying to load view into memory");
- if (agiLoadResource(RESOURCETYPE_VIEW, viewNr) != errOK) {
+ if (loadResource(RESOURCETYPE_VIEW, viewNr) != errOK) {
// loading failed, we better error() out now
error("setView() called to set view %d for screen object %d, which is not loaded atm and loading failed", viewNr, screenObj->objectNr);
return;
Commit: 8b5dd0ce2e13987d99eb6978fda0ea132d0145ab
https://github.com/scummvm/scummvm/commit/8b5dd0ce2e13987d99eb6978fda0ea132d0145ab
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:56:29-07:00
Commit Message:
AGI: Cleanup picture/view unload
Changed paths:
engines/agi/picture.cpp
engines/agi/picture.h
engines/agi/view.cpp
diff --git a/engines/agi/picture.cpp b/engines/agi/picture.cpp
index 211432ce18b..93a59702f4c 100644
--- a/engines/agi/picture.cpp
+++ b/engines/agi/picture.cpp
@@ -985,14 +985,13 @@ int PictureMgr::decodePicture(byte *data, uint32 length, int clr, int pic_width,
* resource data.
* @param picNr AGI picture resource number
*/
-int PictureMgr::unloadPicture(int picNr) {
+void PictureMgr::unloadPicture(int picNr) {
// remove visual buffer & priority buffer if they exist
if (_vm->_game.dirPic[picNr].flags & RES_LOADED) {
free(_vm->_game.pictures[picNr].rdata);
+ _vm->_game.pictures[picNr].rdata = nullptr;
_vm->_game.dirPic[picNr].flags &= ~RES_LOADED;
}
-
- return errOK;
}
void PictureMgr::clear() {
diff --git a/engines/agi/picture.h b/engines/agi/picture.h
index b259dd38ebe..f7e762fed47 100644
--- a/engines/agi/picture.h
+++ b/engines/agi/picture.h
@@ -85,7 +85,7 @@ public:
int decodePicture(int16 resourceNr, bool clearScreen, bool agi256 = false, int16 pic_width = _DEFAULT_WIDTH, int16 pic_height = _DEFAULT_HEIGHT);
int decodePicture(byte *data, uint32 length, int clear, int pic_width = _DEFAULT_WIDTH, int pic_height = _DEFAULT_HEIGHT);
- int unloadPicture(int picNr);
+ void unloadPicture(int picNr);
void drawPicture();
private:
void drawPictureC64();
diff --git a/engines/agi/view.cpp b/engines/agi/view.cpp
index 3cb2e2fe213..080ead7b3ac 100644
--- a/engines/agi/view.cpp
+++ b/engines/agi/view.cpp
@@ -396,9 +396,7 @@ void AgiEngine::unloadView(int16 viewNr) {
delete[] loopData->cel;
}
delete[] viewData->loop;
-
- if (viewData->description)
- delete[] viewData->description;
+ delete[] viewData->description;
viewData->headerCycleTime = 0;
viewData->headerStepSize = 0;
Commit: fb35bc6aa97737b8ddc32b9bd17fe05cf8c8c223
https://github.com/scummvm/scummvm/commit/fb35bc6aa97737b8ddc32b9bd17fe05cf8c8c223
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:56:29-07:00
Commit Message:
AGI: Cleanup AgiLoader
Changed paths:
engines/agi/agi.cpp
engines/agi/agi.h
engines/agi/loader_v1.cpp
engines/agi/loader_v2.cpp
engines/agi/loader_v3.cpp
diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index 5cab6a3cabd..dff5499e028 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -148,11 +148,11 @@ int AgiEngine::agiInit() {
int ec = _loader->init(); // load vol files, etc
if (ec == errOK)
- ec = _loader->loadObjects(OBJECTS);
+ ec = _loader->loadObjects();
// note: demogs has no words.tok
if (ec == errOK)
- ec = _loader->loadWords(WORDS);
+ ec = _loader->loadWords();
// Load logic 0 into memory
if (ec == errOK)
@@ -459,12 +459,11 @@ void AgiEngine::initialize() {
_loader = new AgiLoader_v3(this);
}
- debugC(2, kDebugLevelMain, "Detect game");
- int ec = _loader->detectGame();
- if (ec == errOK) {
- debugC(2, kDebugLevelMain, "game loaded");
+ debugC(2, kDebugLevelMain, "Detecting game");
+ if (_loader->detectGame()) {
+ debugC(2, kDebugLevelMain, "Detected game");
} else {
- warning("Could not open AGI game");
+ warning("Could not detect AGI game");
}
// finally set up actual VM opcodes, because we should now have figured out the right AGI version
setupOpCodes(getVersion());
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 9eebdebba49..b2aed3a7541 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -62,12 +62,6 @@ class RandomSource;
*/
namespace Agi {
-typedef signed int Err;
-
-//
-// Version and other definitions
-//
-
#define TITLE "AGI engine"
#define DIR_ "dir"
@@ -103,11 +97,6 @@ typedef signed int Err;
#define CMD_BSIZE 12
-enum {
- NO_GAMEDIR = 0,
- GAMEDIR
-};
-
enum AgiGameType {
GType_PreAGI = 0,
GType_V1 = 1,
@@ -555,20 +544,49 @@ struct AgiGame {
class AgiLoader {
public:
-
- AgiLoader() {}
+ AgiLoader(AgiEngine *vm) : _vm(vm) {}
virtual ~AgiLoader() {}
+ /**
+ * Detects if the game directory appears to contain AGI files.
+ * This must be called before init(), as the V3 loader stores
+ * the game name prefix. Returns true if game files are found.
+ * Implementations do not currently open files, and the return
+ * value currently has no effect on the engine beyond logging.
+ * The engine will call init() even if this fails.
+ */
+ virtual bool detectGame() = 0;
+
+ /**
+ * Reads all AGI directory entries from disk and and populates
+ * the AgiDir arrays in AgiGame (AgiBase::_game) with them.
+ * Must be called after detectGame().
+ */
virtual int init() = 0;
- virtual int detectGame() = 0;
+
+ /**
+ * Loads a resource if it is not already loaded.
+ * The resource is loaded and decoded into its resource array
+ * in AgiGame, and the RES_LOADED flag is set on its AgiDir entry.
+ */
virtual int loadResource(int16 resourceType, int16 resourceNr) = 0;
- virtual int loadObjects(const char *fname) = 0;
- virtual int loadWords(const char *fname) = 0;
+
+ /**
+ * Loads AgiEngine::_objects from disk
+ */
+ virtual int loadObjects() = 0;
+
+ /**
+ * Loads AgiBase::_words from disk
+ */
+ virtual int loadWords() = 0;
+
+protected:
+ AgiEngine *_vm;
};
class AgiLoader_v1 : public AgiLoader {
private:
- AgiEngine *_vm;
Common::Path _filenameDisk0;
Common::Path _filenameDisk1;
@@ -577,18 +595,17 @@ private:
uint8 *loadVolRes(AgiDir *agid);
public:
- AgiLoader_v1(AgiEngine *vm);
+ AgiLoader_v1(AgiEngine *vm) : AgiLoader(vm) {}
+ bool detectGame() override;
int init() override;
- int detectGame() override;
int loadResource(int16 resourceType, int16 resourceNr) override;
- int loadObjects(const char *fname) override;
- int loadWords(const char *fname) override;
+ int loadObjects() override;
+ int loadWords() override;
};
class AgiLoader_v2 : public AgiLoader {
private:
- AgiEngine *_vm;
bool _hasV3VolumeFormat;
int loadDir(AgiDir *agid, const char *fname);
@@ -596,37 +613,28 @@ private:
bool detectV3VolumeFormat();
public:
+ AgiLoader_v2(AgiEngine *vm) : _hasV3VolumeFormat(false), AgiLoader(vm) {}
- AgiLoader_v2(AgiEngine *vm) {
- _vm = vm;
- _hasV3VolumeFormat = false;
- }
-
+ bool detectGame() override;
int init() override;
- int detectGame() override;
int loadResource(int16 resourceType, int16 resourceNr) override;
- int loadObjects(const char *fname) override;
- int loadWords(const char *fname) override;
+ int loadObjects() override;
+ int loadWords() override;
};
class AgiLoader_v3 : public AgiLoader {
private:
- AgiEngine *_vm;
-
int loadDir(AgiDir *agid, Common::File *fp, uint32 offs, uint32 len);
uint8 *loadVolRes(AgiDir *agid);
public:
+ AgiLoader_v3(AgiEngine *vm) : AgiLoader(vm) {}
- AgiLoader_v3(AgiEngine *vm) {
- _vm = vm;
- }
-
+ bool detectGame() override;
int init() override;
- int detectGame() override;
int loadResource(int16 resourceType, int16 resourceNr) override;
- int loadObjects(const char *fname) override;
- int loadWords(const char *fname) override;
+ int loadObjects() override;
+ int loadWords() override;
};
class GfxFont;
diff --git a/engines/agi/loader_v1.cpp b/engines/agi/loader_v1.cpp
index 788d55cc607..7f45780c8dd 100644
--- a/engines/agi/loader_v1.cpp
+++ b/engines/agi/loader_v1.cpp
@@ -50,17 +50,12 @@
namespace Agi {
-
-AgiLoader_v1::AgiLoader_v1(AgiEngine *vm) {
- _vm = vm;
-}
-
-int AgiLoader_v1::detectGame() {
+bool AgiLoader_v1::detectGame() {
// Find filenames for the disk images
_filenameDisk0 = _vm->getDiskName(BooterDisk1);
_filenameDisk1 = _vm->getDiskName(BooterDisk2);
- return errOK;
+ return true;
}
int AgiLoader_v1::loadDir_DDP(AgiDir *agid, int offset, int max) {
@@ -285,7 +280,7 @@ int AgiLoader_v1::loadResource(int16 resourceType, int16 resourceNr) {
return ec;
}
-int AgiLoader_v1::loadObjects(const char *fname) {
+int AgiLoader_v1::loadObjects() {
if (_vm->getGameID() == GID_BC) {
Common::File f;
f.open(_filenameDisk0);
@@ -295,7 +290,7 @@ int AgiLoader_v1::loadObjects(const char *fname) {
return errOK;
}
-int AgiLoader_v1::loadWords(const char *fname) {
+int AgiLoader_v1::loadWords() {
if (_vm->getGameID() == GID_BC) {
Common::File f;
f.open(_filenameDisk0);
diff --git a/engines/agi/loader_v2.cpp b/engines/agi/loader_v2.cpp
index 87c76145d4d..83fd590b7fb 100644
--- a/engines/agi/loader_v2.cpp
+++ b/engines/agi/loader_v2.cpp
@@ -27,14 +27,12 @@
namespace Agi {
-int AgiLoader_v2::detectGame() {
- if (!Common::File::exists(LOGDIR) ||
- !Common::File::exists(PICDIR) ||
- !Common::File::exists(SNDDIR) ||
- !Common::File::exists(VIEWDIR))
- return errInvalidAGIFile;
-
- return errOK;
+bool AgiLoader_v2::detectGame() {
+ return
+ Common::File::exists(LOGDIR) &&
+ Common::File::exists(PICDIR) &&
+ Common::File::exists(SNDDIR) &&
+ Common::File::exists(VIEWDIR);
}
int AgiLoader_v2::loadDir(AgiDir *agid, const char *fname) {
@@ -292,15 +290,15 @@ int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) {
return ec;
}
-int AgiLoader_v2::loadObjects(const char *fname) {
- return _vm->loadObjects(fname);
+int AgiLoader_v2::loadObjects() {
+ return _vm->loadObjects(OBJECTS);
}
-int AgiLoader_v2::loadWords(const char *fname) {
+int AgiLoader_v2::loadWords() {
if (_vm->getFeatures() & GF_EXTCHAR) {
- return _vm->_words->loadExtendedDictionary(fname);
+ return _vm->_words->loadExtendedDictionary(WORDS);
} else {
- return _vm->_words->loadDictionary(fname);
+ return _vm->_words->loadDictionary(WORDS);
}
}
diff --git a/engines/agi/loader_v3.cpp b/engines/agi/loader_v3.cpp
index f3506c6595a..e2980e0c279 100644
--- a/engines/agi/loader_v3.cpp
+++ b/engines/agi/loader_v3.cpp
@@ -29,19 +29,17 @@
namespace Agi {
-int AgiLoader_v3::detectGame() {
- int ec = errUnk;
- bool found = false;
-
+bool AgiLoader_v3::detectGame() {
Common::FSList fslist;
Common::FSNode dir(ConfMan.getPath("path"));
if (!dir.getChildren(fslist, Common::FSNode::kListFilesOnly)) {
warning("AgiLoader_v3: invalid game path '%s'", dir.getPath().toString(Common::Path::kNativeSeparator).c_str());
- return errInvalidAGIFile;
+ return false;
}
- for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end() && !found; ++file) {
+ bool found = false;
+ for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
Common::String f = file->getName();
f.toLowercase();
@@ -49,19 +47,12 @@ int AgiLoader_v3::detectGame() {
memset(_vm->_game.name, 0, 8);
strncpy(_vm->_game.name, f.c_str(), MIN((uint)6, f.size() > 3 ? f.size() - 3 : f.size()));
debugC(3, kDebugLevelMain, "game.name = %s", _vm->_game.name);
-
- ec = errOK;
-
found = true;
+ break;
}
}
- if (!found) {
- debugC(3, kDebugLevelMain, "directory file not found");
- ec = errInvalidAGIFile;
- }
-
- return ec;
+ return found;
}
int AgiLoader_v3::loadDir(AgiDir *agid, Common::File *fp, uint32 offs, uint32 len) {
@@ -291,12 +282,12 @@ int AgiLoader_v3::loadResource(int16 resourceType, int16 resourceNr) {
return ec;
}
-int AgiLoader_v3::loadObjects(const char *fname) {
- return _vm->loadObjects(fname);
+int AgiLoader_v3::loadObjects() {
+ return _vm->loadObjects(OBJECTS);
}
-int AgiLoader_v3::loadWords(const char *fname) {
- return _vm->_words->loadDictionary(fname);
+int AgiLoader_v3::loadWords() {
+ return _vm->_words->loadDictionary(WORDS);
}
} // End of namespace Agi
Commit: 22dc2064760af2f43ce9816a4e5b4fd65bff512f
https://github.com/scummvm/scummvm/commit/22dc2064760af2f43ce9816a4e5b4fd65bff512f
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:56:39-07:00
Commit Message:
AGI: Remove AgiLoader::loadResource implementations
All three implementations were the same
Changed paths:
engines/agi/agi.cpp
engines/agi/agi.h
engines/agi/loader_v1.cpp
engines/agi/loader_v2.cpp
engines/agi/loader_v3.cpp
diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index dff5499e028..ecfa1a96e86 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -156,7 +156,7 @@ int AgiEngine::agiInit() {
// Load logic 0 into memory
if (ec == errOK)
- ec = _loader->loadResource(RESOURCETYPE_LOGIC, 0);
+ ec = loadResource(RESOURCETYPE_LOGIC, 0);
_keyHoldMode = false;
_keyHoldModeLastKey = Common::KEYCODE_INVALID;
@@ -197,7 +197,87 @@ void AgiEngine::agiDeinit() {
}
int AgiEngine::loadResource(int16 resourceType, int16 resourceNr) {
- int ec = _loader->loadResource(resourceType, resourceNr);
+ if (resourceNr >= MAX_DIRECTORY_ENTRIES)
+ return errBadResource;
+
+ int ec = errOK;
+ uint8 *data = nullptr;
+ switch (resourceType) {
+ case RESOURCETYPE_LOGIC:
+ if (~_game.dirLogic[resourceNr].flags & RES_LOADED) {
+ unloadResource(RESOURCETYPE_LOGIC, resourceNr);
+
+ // load raw resource into data
+ data = _loader->loadVolumeResource(&_game.dirLogic[resourceNr]);
+ _game.logics[resourceNr].data = data;
+
+ // uncompressed logic files need to be decrypted
+ if (data != nullptr) {
+ // RES_LOADED flag gets set by decode logic
+ ec = decodeLogic(resourceNr);
+ _game.logics[resourceNr].sIP = 2;
+ } else {
+ ec = errBadResource;
+ }
+ }
+
+ // reset code pointer in case logic was cached
+ _game.logics[resourceNr].cIP = _game.logics[resourceNr].sIP;
+ break;
+
+ case RESOURCETYPE_PICTURE:
+ if (~_game.dirPic[resourceNr].flags & RES_LOADED) {
+ // if loaded but not cached, unload it
+ // if cached but not loaded, etc
+ unloadResource(RESOURCETYPE_PICTURE, resourceNr);
+ data = _loader->loadVolumeResource(&_game.dirPic[resourceNr]);
+
+ if (data != nullptr) {
+ _game.pictures[resourceNr].rdata = data;
+ _game.dirPic[resourceNr].flags |= RES_LOADED;
+ } else {
+ ec = errBadResource;
+ }
+ }
+ break;
+
+ case RESOURCETYPE_SOUND:
+ if (~_game.dirSound[resourceNr].flags & RES_LOADED) {
+ data = _loader->loadVolumeResource(&_game.dirSound[resourceNr]);
+
+ // "data" is freed by objects created by createFromRawResource on success
+ _game.sounds[resourceNr] = AgiSound::createFromRawResource(data, _game.dirSound[resourceNr].len, resourceNr, _soundemu);
+ if (_game.sounds[resourceNr] != nullptr) {
+ _game.dirSound[resourceNr].flags |= RES_LOADED;
+ } else {
+ free(data);
+ ec = errBadResource;
+ }
+ }
+ break;
+
+ case RESOURCETYPE_VIEW:
+ // Load a VIEW resource into memory...
+ // Since VIEWS alter the view table ALL the time
+ // can we cache the view? or must we reload it all
+ // the time?
+ if (~_game.dirView[resourceNr].flags & RES_LOADED) {
+ unloadResource(RESOURCETYPE_VIEW, resourceNr);
+ data = _loader->loadVolumeResource(&_game.dirView[resourceNr]);
+ if (data) {
+ _game.dirView[resourceNr].flags |= RES_LOADED;
+ ec = decodeView(data, _game.dirView[resourceNr].len, resourceNr);
+ free(data);
+ } else {
+ ec = errBadResource;
+ }
+ }
+ break;
+
+ default:
+ ec = errBadResource;
+ break;
+ }
// WORKAROUND: Patches broken picture 147 in a corrupted Amiga version of Gold Rush! (v2.05 1989-03-09).
// The picture can be seen in room 147 after dropping through the outhouse's hole in room 146.
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index b2aed3a7541..054d6a22b59 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -565,11 +565,9 @@ public:
virtual int init() = 0;
/**
- * Loads a resource if it is not already loaded.
- * The resource is loaded and decoded into its resource array
- * in AgiGame, and the RES_LOADED flag is set on its AgiDir entry.
+ * Loads a volume resource from disk
*/
- virtual int loadResource(int16 resourceType, int16 resourceNr) = 0;
+ virtual uint8 *loadVolumeResource(AgiDir *agid) = 0;
/**
* Loads AgiEngine::_objects from disk
@@ -592,14 +590,13 @@ private:
int loadDir_DDP(AgiDir *agid, int offset, int max);
int loadDir_BC(AgiDir *agid, int offset, int max);
- uint8 *loadVolRes(AgiDir *agid);
public:
AgiLoader_v1(AgiEngine *vm) : AgiLoader(vm) {}
bool detectGame() override;
int init() override;
- int loadResource(int16 resourceType, int16 resourceNr) override;
+ uint8 *loadVolumeResource(AgiDir *agid) override;
int loadObjects() override;
int loadWords() override;
};
@@ -609,7 +606,6 @@ private:
bool _hasV3VolumeFormat;
int loadDir(AgiDir *agid, const char *fname);
- uint8 *loadVolRes(AgiDir *agid);
bool detectV3VolumeFormat();
public:
@@ -617,7 +613,7 @@ public:
bool detectGame() override;
int init() override;
- int loadResource(int16 resourceType, int16 resourceNr) override;
+ uint8 *loadVolumeResource(AgiDir *agid) override;
int loadObjects() override;
int loadWords() override;
};
@@ -625,14 +621,13 @@ public:
class AgiLoader_v3 : public AgiLoader {
private:
int loadDir(AgiDir *agid, Common::File *fp, uint32 offs, uint32 len);
- uint8 *loadVolRes(AgiDir *agid);
public:
AgiLoader_v3(AgiEngine *vm) : AgiLoader(vm) {}
bool detectGame() override;
int init() override;
- int loadResource(int16 resourceType, int16 resourceNr) override;
+ uint8 *loadVolumeResource(AgiDir *agid) override;
int loadObjects() override;
int loadWords() override;
};
diff --git a/engines/agi/loader_v1.cpp b/engines/agi/loader_v1.cpp
index 7f45780c8dd..7670b99c6fc 100644
--- a/engines/agi/loader_v1.cpp
+++ b/engines/agi/loader_v1.cpp
@@ -155,7 +155,7 @@ int AgiLoader_v1::init() {
return ec;
}
-uint8 *AgiLoader_v1::loadVolRes(struct AgiDir *agid) {
+uint8 *AgiLoader_v1::loadVolumeResource(AgiDir *agid) {
Common::File fp;
int offset = agid->offset;
@@ -191,95 +191,6 @@ uint8 *AgiLoader_v1::loadVolRes(struct AgiDir *agid) {
return data;
}
-int AgiLoader_v1::loadResource(int16 resourceType, int16 resourceNr) {
- int ec = errOK;
- uint8 *data = nullptr;
-
- debugC(3, kDebugLevelResources, "(t = %d, n = %d)", resourceType, resourceNr);
- if (resourceNr >= MAX_DIRECTORY_ENTRIES)
- return errBadResource;
-
- switch (resourceType) {
- case RESOURCETYPE_LOGIC:
- if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) {
- debugC(3, kDebugLevelResources, "loading logic resource %d", resourceNr);
- _vm->unloadResource(RESOURCETYPE_LOGIC, resourceNr);
-
- // load raw resource into data
- data = loadVolRes(&_vm->_game.dirLogic[resourceNr]);
-
- _vm->_game.logics[resourceNr].data = data;
- ec = data ? _vm->decodeLogic(resourceNr) : errBadResource;
-
- _vm->_game.logics[resourceNr].sIP = 2;
- }
-
- // reset code pointer in case logic was cached
- _vm->_game.logics[resourceNr].cIP = _vm->_game.logics[resourceNr].sIP;
- break;
- case RESOURCETYPE_PICTURE:
- // if picture is currently NOT loaded *OR* cacheing is off,
- // unload the resource (caching == off) and reload it
-
- debugC(3, kDebugLevelResources, "loading picture resource %d", resourceNr);
- if (_vm->_game.dirPic[resourceNr].flags & RES_LOADED)
- break;
-
- // if loaded but not cached, unload it
- // if cached but not loaded, etc
- _vm->unloadResource(RESOURCETYPE_PICTURE, resourceNr);
- data = loadVolRes(&_vm->_game.dirPic[resourceNr]);
-
- if (data != nullptr) {
- _vm->_game.pictures[resourceNr].rdata = data;
- _vm->_game.dirPic[resourceNr].flags |= RES_LOADED;
- } else {
- ec = errBadResource;
- }
- break;
- case RESOURCETYPE_SOUND:
- debugC(3, kDebugLevelResources, "loading sound resource %d", resourceNr);
- if (_vm->_game.dirSound[resourceNr].flags & RES_LOADED)
- break;
-
- data = loadVolRes(&_vm->_game.dirSound[resourceNr]);
-
- // "data" is freed by objects created by createFromRawResource on success
- _vm->_game.sounds[resourceNr] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[resourceNr].len, resourceNr, _vm->_soundemu);
- if (_vm->_game.sounds[resourceNr] != nullptr) {
- _vm->_game.dirSound[resourceNr].flags |= RES_LOADED;
- } else {
- free(data);
- ec = errBadResource;
- }
- break;
- case RESOURCETYPE_VIEW:
- // Load a VIEW resource into memory...
- // Since VIEWS alter the view table ALL the time
- // can we cache the view? or must we reload it all
- // the time?
- if (_vm->_game.dirView[resourceNr].flags & RES_LOADED)
- break;
-
- debugC(3, kDebugLevelResources, "loading view resource %d", resourceNr);
- _vm->unloadResource(RESOURCETYPE_VIEW, resourceNr);
- data = loadVolRes(&_vm->_game.dirView[resourceNr]);
- if (data) {
- _vm->_game.dirView[resourceNr].flags |= RES_LOADED;
- ec = _vm->decodeView(data, _vm->_game.dirView[resourceNr].len, resourceNr);
- free(data);
- } else {
- ec = errBadResource;
- }
- break;
- default:
- ec = errBadResource;
- break;
- }
-
- return ec;
-}
-
int AgiLoader_v1::loadObjects() {
if (_vm->getGameID() == GID_BC) {
Common::File f;
diff --git a/engines/agi/loader_v2.cpp b/engines/agi/loader_v2.cpp
index 83fd590b7fb..3a4d2e97e97 100644
--- a/engines/agi/loader_v2.cpp
+++ b/engines/agi/loader_v2.cpp
@@ -144,7 +144,7 @@ int AgiLoader_v2::init() {
* if further decoding is required, it must be done by another
* routine. NULL is returned if unsuccessful.
*/
-uint8 *AgiLoader_v2::loadVolRes(struct AgiDir *agid) {
+uint8 *AgiLoader_v2::loadVolumeResource(AgiDir *agid) {
uint8 *data = nullptr;
uint8 volumeHeader[7];
Common::File fp;
@@ -195,101 +195,6 @@ uint8 *AgiLoader_v2::loadVolRes(struct AgiDir *agid) {
return data;
}
-/**
- * Loads a resource into memory, a raw resource is loaded in
- * with above routine, then further decoded here.
- */
-int AgiLoader_v2::loadResource(int16 resourceType, int16 resourceNr) {
- int ec = errOK;
- uint8 *data = nullptr;
-
- debugC(3, kDebugLevelResources, "(t = %d, n = %d)", resourceType, resourceNr);
- if (resourceNr >= MAX_DIRECTORY_ENTRIES)
- return errBadResource;
-
- switch (resourceType) {
- case RESOURCETYPE_LOGIC:
- if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) {
- debugC(3, kDebugLevelResources, "loading logic resource %d", resourceNr);
- _vm->unloadResource(RESOURCETYPE_LOGIC, resourceNr);
-
- // load raw resource into data
- data = loadVolRes(&_vm->_game.dirLogic[resourceNr]);
-
- _vm->_game.logics[resourceNr].data = data;
- ec = data ? _vm->decodeLogic(resourceNr) : errBadResource;
-
- _vm->_game.logics[resourceNr].sIP = 2;
- }
-
- // if logic was cached, we get here
- // reset code pointers in case it was cached
-
- _vm->_game.logics[resourceNr].cIP = _vm->_game.logics[resourceNr].sIP;
- break;
- case RESOURCETYPE_PICTURE:
- // if picture is currently NOT loaded *OR* cacheing is off,
- // unload the resource (caching == off) and reload it
-
- debugC(3, kDebugLevelResources, "loading picture resource %d", resourceNr);
- if (_vm->_game.dirPic[resourceNr].flags & RES_LOADED)
- break;
-
- // if loaded but not cached, unload it
- // if cached but not loaded, etc
- _vm->unloadResource(RESOURCETYPE_PICTURE, resourceNr);
- data = loadVolRes(&_vm->_game.dirPic[resourceNr]);
-
- if (data != nullptr) {
- _vm->_game.pictures[resourceNr].rdata = data;
- _vm->_game.dirPic[resourceNr].flags |= RES_LOADED;
- } else {
- ec = errBadResource;
- }
- break;
- case RESOURCETYPE_SOUND:
- debugC(3, kDebugLevelResources, "loading sound resource %d", resourceNr);
- if (_vm->_game.dirSound[resourceNr].flags & RES_LOADED)
- break;
-
- data = loadVolRes(&_vm->_game.dirSound[resourceNr]);
-
- // "data" is freed by objects created by createFromRawResource on success
- _vm->_game.sounds[resourceNr] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[resourceNr].len, resourceNr, _vm->_soundemu);
- if (_vm->_game.sounds[resourceNr] != nullptr) {
- _vm->_game.dirSound[resourceNr].flags |= RES_LOADED;
- } else {
- free(data);
- ec = errBadResource;
- }
- break;
- case RESOURCETYPE_VIEW:
- // Load a VIEW resource into memory...
- // Since VIEWS alter the view table ALL the time
- // can we cache the view? or must we reload it all
- // the time?
- if (_vm->_game.dirView[resourceNr].flags & RES_LOADED)
- break;
-
- debugC(3, kDebugLevelResources, "loading view resource %d", resourceNr);
- _vm->unloadResource(RESOURCETYPE_VIEW, resourceNr);
- data = loadVolRes(&_vm->_game.dirView[resourceNr]);
- if (data) {
- _vm->_game.dirView[resourceNr].flags |= RES_LOADED;
- ec = _vm->decodeView(data, _vm->_game.dirView[resourceNr].len, resourceNr);
- free(data);
- } else {
- ec = errBadResource;
- }
- break;
- default:
- ec = errBadResource;
- break;
- }
-
- return ec;
-}
-
int AgiLoader_v2::loadObjects() {
return _vm->loadObjects(OBJECTS);
}
diff --git a/engines/agi/loader_v3.cpp b/engines/agi/loader_v3.cpp
index e2980e0c279..46b3ac0f01a 100644
--- a/engines/agi/loader_v3.cpp
+++ b/engines/agi/loader_v3.cpp
@@ -136,7 +136,7 @@ int AgiLoader_v3::init() {
*
* NULL is returned if unsuccessful.
*/
-uint8 *AgiLoader_v3::loadVolRes(AgiDir *agid) {
+uint8 *AgiLoader_v3::loadVolumeResource(AgiDir *agid) {
uint8 volumeHeader[7];
uint8 *data = nullptr;
Common::File fp;
@@ -189,99 +189,6 @@ uint8 *AgiLoader_v3::loadVolRes(AgiDir *agid) {
return data;
}
-/**
- * Loads a resource into memory, a raw resource is loaded in
- * with above routine, then further decoded here.
- */
-int AgiLoader_v3::loadResource(int16 resourceType, int16 resourceNr) {
- int ec = errOK;
- uint8 *data = nullptr;
-
- if (resourceNr >= MAX_DIRECTORY_ENTRIES)
- return errBadResource;
-
- switch (resourceType) {
- case RESOURCETYPE_LOGIC:
- // load resource into memory, decrypt messages at the end
- // and build the message list (if logic is in memory)
- if (~_vm->_game.dirLogic[resourceNr].flags & RES_LOADED) {
- // if logic is already in memory, unload it
- _vm->unloadResource(RESOURCETYPE_LOGIC, resourceNr);
-
- // load raw resource into data
- data = loadVolRes(&_vm->_game.dirLogic[resourceNr]);
- _vm->_game.logics[resourceNr].data = data;
-
- // uncompressed logic files need to be decrypted
- if (data != nullptr) {
- // RES_LOADED flag gets set by decode logic
- // needed to build string table
- ec = _vm->decodeLogic(resourceNr);
- _vm->_game.logics[resourceNr].sIP = 2;
- } else {
- ec = errBadResource;
- }
- }
-
- // reset code pointers in case logic was cached
- _vm->_game.logics[resourceNr].cIP = _vm->_game.logics[resourceNr].sIP;
- break;
- case RESOURCETYPE_PICTURE:
- // if picture is currently NOT loaded *OR* cacheing is off,
- // unload the resource (caching==off) and reload it
- if (~_vm->_game.dirPic[resourceNr].flags & RES_LOADED) {
- _vm->unloadResource(RESOURCETYPE_PICTURE, resourceNr);
- data = loadVolRes(&_vm->_game.dirPic[resourceNr]);
- if (data != nullptr) {
- _vm->_game.pictures[resourceNr].rdata = data;
- _vm->_game.dirPic[resourceNr].flags |= RES_LOADED;
- } else {
- ec = errBadResource;
- }
- }
- break;
- case RESOURCETYPE_SOUND:
- if (_vm->_game.dirSound[resourceNr].flags & RES_LOADED)
- break;
-
- data = loadVolRes(&_vm->_game.dirSound[resourceNr]);
-
- // "data" is freed by objects created by createFromRawResource on success
- _vm->_game.sounds[resourceNr] = AgiSound::createFromRawResource(data, _vm->_game.dirSound[resourceNr].len, resourceNr, _vm->_soundemu);
- if (_vm->_game.sounds[resourceNr] != nullptr) {
- _vm->_game.dirSound[resourceNr].flags |= RES_LOADED;
- } else {
- free(data);
- ec = errBadResource;
- }
- break;
- case RESOURCETYPE_VIEW:
- // Load a VIEW resource into memory...
- // Since VIEWS alter the view table ALL the time can we
- // cache the view? or must we reload it all the time?
- //
- // load a raw view from a VOL file into data
- if (_vm->_game.dirView[resourceNr].flags & RES_LOADED)
- break;
-
- _vm->unloadResource(RESOURCETYPE_VIEW, resourceNr);
- data = loadVolRes(&_vm->_game.dirView[resourceNr]);
- if (data != nullptr) {
- _vm->_game.dirView[resourceNr].flags |= RES_LOADED;
- ec = _vm->decodeView(data, _vm->_game.dirView[resourceNr].len, resourceNr);
- free(data);
- } else {
- ec = errBadResource;
- }
- break;
- default:
- ec = errBadResource;
- break;
- }
-
- return ec;
-}
-
int AgiLoader_v3::loadObjects() {
return _vm->loadObjects(OBJECTS);
}
Commit: 4bba0c332e54e1e6d2b42c990b589208bffb6f70
https://github.com/scummvm/scummvm/commit/4bba0c332e54e1e6d2b42c990b589208bffb6f70
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:56:39-07:00
Commit Message:
AGI: Cleanup AgiLoader initialization
Changed paths:
engines/agi/agi.cpp
engines/agi/agi.h
engines/agi/loader_v1.cpp
engines/agi/loader_v2.cpp
engines/agi/loader_v3.cpp
engines/agi/preagi/preagi.cpp
diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index ecfa1a96e86..25d55134744 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -145,12 +145,12 @@ int AgiEngine::agiInit() {
if (getFeatures() & GF_AGDS)
debug(1, "AGDS mode enabled.");
- int ec = _loader->init(); // load vol files, etc
+ int ec = _loader->loadDirs();
if (ec == errOK)
ec = _loader->loadObjects();
- // note: demogs has no words.tok
+ // note: demos has no words.tok
if (ec == errOK)
ec = _loader->loadWords();
@@ -529,8 +529,6 @@ void AgiEngine::initialize() {
_text->charAttrib_Set(15, 0);
- _game.name[0] = '\0';
-
if (getVersion() <= 0x2001) {
_loader = new AgiLoader_v1(this);
} else if (getVersion() <= 0x2999) {
@@ -538,13 +536,8 @@ void AgiEngine::initialize() {
} else {
_loader = new AgiLoader_v3(this);
}
-
- debugC(2, kDebugLevelMain, "Detecting game");
- if (_loader->detectGame()) {
- debugC(2, kDebugLevelMain, "Detected game");
- } else {
- warning("Could not detect AGI game");
- }
+ _loader->init();
+
// finally set up actual VM opcodes, because we should now have figured out the right AGI version
setupOpCodes(getVersion());
}
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 054d6a22b59..bca9053b383 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -144,16 +144,9 @@ enum AgiGameID {
enum AGIErrors {
errOK = 0,
- errDoNothing,
- errBadCLISwitch,
- errInvalidAGIFile,
errBadFileOpen,
errNotEnoughMemory,
errBadResource,
- errUnknownAGIVersion,
- errNoLoopsInView,
- errViewDataError,
- errNoGameList,
errIOError,
errUnk = 127
@@ -381,7 +374,6 @@ struct AgiGame {
int adjMouseX; /**< last given adj.ego.move.to.x.y-command's 1st parameter */
int adjMouseY; /**< last given adj.ego.move.to.x.y-command's 2nd parameter */
- char name[8]; /**< lead in id (e.g. `GR' for goldrush) */
char id[8]; /**< game id */
uint32 crc; /**< game CRC */
@@ -473,7 +465,6 @@ struct AgiGame {
adjMouseX = 0;
adjMouseY = 0;
- memset(name, 0, sizeof(name));
memset(id, 0, sizeof(id));
crc = 0;
memset(flags, 0, sizeof(flags));
@@ -548,34 +539,29 @@ public:
virtual ~AgiLoader() {}
/**
- * Detects if the game directory appears to contain AGI files.
- * This must be called before init(), as the V3 loader stores
- * the game name prefix. Returns true if game files are found.
- * Implementations do not currently open files, and the return
- * value currently has no effect on the engine beyond logging.
- * The engine will call init() even if this fails.
+ * Performs one-time initializations, such as locating files
+ * with dynamic names.
*/
- virtual bool detectGame() = 0;
+ virtual void init() {}
/**
- * Reads all AGI directory entries from disk and and populates
- * the AgiDir arrays in AgiGame (AgiBase::_game) with them.
- * Must be called after detectGame().
+ * Loads all AGI directory entries from disk and and populates
+ * the AgiDir arrays in AgiGame with them.
*/
- virtual int init() = 0;
+ virtual int loadDirs() = 0;
/**
- * Loads a volume resource from disk
+ * Loads a volume resource from disk.
*/
virtual uint8 *loadVolumeResource(AgiDir *agid) = 0;
/**
- * Loads AgiEngine::_objects from disk
+ * Loads AgiEngine::_objects from disk.
*/
virtual int loadObjects() = 0;
/**
- * Loads AgiBase::_words from disk
+ * Loads AgiBase::_words from disk.
*/
virtual int loadWords() = 0;
@@ -594,8 +580,8 @@ private:
public:
AgiLoader_v1(AgiEngine *vm) : AgiLoader(vm) {}
- bool detectGame() override;
- int init() override;
+ void init() override;
+ int loadDirs() override;
uint8 *loadVolumeResource(AgiDir *agid) override;
int loadObjects() override;
int loadWords() override;
@@ -611,8 +597,7 @@ private:
public:
AgiLoader_v2(AgiEngine *vm) : _hasV3VolumeFormat(false), AgiLoader(vm) {}
- bool detectGame() override;
- int init() override;
+ int loadDirs() override;
uint8 *loadVolumeResource(AgiDir *agid) override;
int loadObjects() override;
int loadWords() override;
@@ -620,13 +605,15 @@ public:
class AgiLoader_v3 : public AgiLoader {
private:
+ Common::String _name; /**< prefix in directory and/or volume file names (`GR' for goldrush) */
+
int loadDir(AgiDir *agid, Common::File *fp, uint32 offs, uint32 len);
public:
AgiLoader_v3(AgiEngine *vm) : AgiLoader(vm) {}
- bool detectGame() override;
- int init() override;
+ void init() override;
+ int loadDirs() override;
uint8 *loadVolumeResource(AgiDir *agid) override;
int loadObjects() override;
int loadWords() override;
diff --git a/engines/agi/loader_v1.cpp b/engines/agi/loader_v1.cpp
index 7670b99c6fc..469e25100d5 100644
--- a/engines/agi/loader_v1.cpp
+++ b/engines/agi/loader_v1.cpp
@@ -50,12 +50,10 @@
namespace Agi {
-bool AgiLoader_v1::detectGame() {
+void AgiLoader_v1::init() {
// Find filenames for the disk images
_filenameDisk0 = _vm->getDiskName(BooterDisk1);
_filenameDisk1 = _vm->getDiskName(BooterDisk2);
-
- return true;
}
int AgiLoader_v1::loadDir_DDP(AgiDir *agid, int offset, int max) {
@@ -123,7 +121,7 @@ int AgiLoader_v1::loadDir_BC(AgiDir *agid, int offset, int max) {
return errOK;
}
-int AgiLoader_v1::init() {
+int AgiLoader_v1::loadDirs() {
int ec = errOK;
switch (_vm->getGameID()) {
diff --git a/engines/agi/loader_v2.cpp b/engines/agi/loader_v2.cpp
index 3a4d2e97e97..da2b3762bda 100644
--- a/engines/agi/loader_v2.cpp
+++ b/engines/agi/loader_v2.cpp
@@ -27,14 +27,6 @@
namespace Agi {
-bool AgiLoader_v2::detectGame() {
- return
- Common::File::exists(LOGDIR) &&
- Common::File::exists(PICDIR) &&
- Common::File::exists(SNDDIR) &&
- Common::File::exists(VIEWDIR);
-}
-
int AgiLoader_v2::loadDir(AgiDir *agid, const char *fname) {
debug(0, "Loading directory: %s", fname);
@@ -122,7 +114,7 @@ bool AgiLoader_v2::detectV3VolumeFormat() {
return true;
}
-int AgiLoader_v2::init() {
+int AgiLoader_v2::loadDirs() {
int ec = errOK;
// load directory files
diff --git a/engines/agi/loader_v3.cpp b/engines/agi/loader_v3.cpp
index 46b3ac0f01a..e783cfbbef1 100644
--- a/engines/agi/loader_v3.cpp
+++ b/engines/agi/loader_v3.cpp
@@ -29,30 +29,27 @@
namespace Agi {
-bool AgiLoader_v3::detectGame() {
+void AgiLoader_v3::init() {
+ // Find the game's name by locating a file that ends in "dir".
+ // Amiga games don't use the game's name as a prefix.
+ _name.clear();
Common::FSList fslist;
Common::FSNode dir(ConfMan.getPath("path"));
if (!dir.getChildren(fslist, Common::FSNode::kListFilesOnly)) {
warning("AgiLoader_v3: invalid game path '%s'", dir.getPath().toString(Common::Path::kNativeSeparator).c_str());
- return false;
+ return;
}
- bool found = false;
for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
- Common::String f = file->getName();
- f.toLowercase();
-
- if (f.hasSuffix("dir")) {
- memset(_vm->_game.name, 0, 8);
- strncpy(_vm->_game.name, f.c_str(), MIN((uint)6, f.size() > 3 ? f.size() - 3 : f.size()));
- debugC(3, kDebugLevelMain, "game.name = %s", _vm->_game.name);
- found = true;
+ Common::String fileName = file->getName();
+ if (fileName.size() > 3 && fileName.hasSuffixIgnoreCase("dir")) {
+ _name = fileName.substr(0, fileName.size() - 3);
+ _name.toLowercase();
+ debugC(3, kDebugLevelResources, "game name: %s", _name.c_str());
break;
}
}
-
- return found;
}
int AgiLoader_v3::loadDir(AgiDir *agid, Common::File *fp, uint32 offs, uint32 len) {
@@ -81,17 +78,21 @@ int AgiLoader_v3::loadDir(AgiDir *agid, Common::File *fp, uint32 offs, uint32 le
return errOK;
}
-int AgiLoader_v3::init() {
+int AgiLoader_v3::loadDirs() {
int ec = errOK;
uint8 fileHeader[8];
Common::File fp;
Common::Path path;
if (_vm->getPlatform() == Common::kPlatformAmiga) {
+ // Amiga directory file is always named "dirs"
path = Common::Path("dirs");
- _vm->_game.name[0] = 0; // Empty prefix
} else {
- path = Common::Path(Common::String(_vm->_game.name) + DIR_);
+ if (_name.empty()) {
+ warning("AgiLoader_v3: directory file not found");
+ return errBadResource;
+ }
+ path = Common::Path(_name + DIR_);
}
if (!fp.open(path)) {
@@ -146,7 +147,7 @@ uint8 *AgiLoader_v3::loadVolumeResource(AgiDir *agid) {
if (_vm->getPlatform() == Common::kPlatformMacintosh) {
path = Common::String::format("vol.%i", agid->volume);
} else {
- path = Common::String::format("%svol.%i", _vm->_game.name, agid->volume);
+ path = Common::String::format("%svol.%i", _name.c_str(), agid->volume);
}
if (agid->offset != _EMPTY && fp.open(path)) {
diff --git a/engines/agi/preagi/preagi.cpp b/engines/agi/preagi/preagi.cpp
index 50ece5fdc63..baaacd2aed1 100644
--- a/engines/agi/preagi/preagi.cpp
+++ b/engines/agi/preagi/preagi.cpp
@@ -54,8 +54,6 @@ void PreAgiEngine::initialize() {
_defaultColor = 0xF;
- _game.name[0] = '\0';
-
//_game._vm->_text->configureScreen(0); // hardcoded
_gfx->initVideo();
Commit: 65b606feb7950105da9c9d2d11549398e5580510
https://github.com/scummvm/scummvm/commit/65b606feb7950105da9c9d2d11549398e5580510
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:56:39-07:00
Commit Message:
AGI: Cleanup AgiDir initialization
Changed paths:
engines/agi/agi.h
engines/agi/loader_v1.cpp
engines/agi/loader_v2.cpp
engines/agi/loader_v3.cpp
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index bca9053b383..77e6d89966c 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -324,8 +324,8 @@ struct AgiDir {
uint8 flags;
void reset() {
- volume = 0;
- offset = 0;
+ volume = 0xff;
+ offset = _EMPTY;
len = 0;
clen = 0;
flags = 0;
diff --git a/engines/agi/loader_v1.cpp b/engines/agi/loader_v1.cpp
index 469e25100d5..060cdde39c4 100644
--- a/engines/agi/loader_v1.cpp
+++ b/engines/agi/loader_v1.cpp
@@ -62,12 +62,6 @@ int AgiLoader_v1::loadDir_DDP(AgiDir *agid, int offset, int max) {
if (!fp.open(_filenameDisk0))
return errBadFileOpen;
- // initialize directory entries to empty
- for (int i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
- agid[i].volume = 0xFF;
- agid[i].offset = _EMPTY;
- }
-
fp.seek(offset, SEEK_SET);
for (int i = 0; i <= max; i++) {
int b0 = fp.readByte();
@@ -94,12 +88,6 @@ int AgiLoader_v1::loadDir_BC(AgiDir *agid, int offset, int max) {
if (!fp.open(_filenameDisk0))
return errBadFileOpen;
- // initialize directory entries to empty
- for (int i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
- agid[i].volume = 0xFF;
- agid[i].offset = _EMPTY;
- }
-
fp.seek(offset, SEEK_SET);
for (int i = 0; i <= max; i++) {
int b0 = fp.readByte();
diff --git a/engines/agi/loader_v2.cpp b/engines/agi/loader_v2.cpp
index da2b3762bda..cf686c04822 100644
--- a/engines/agi/loader_v2.cpp
+++ b/engines/agi/loader_v2.cpp
@@ -46,12 +46,6 @@ int AgiLoader_v2::loadDir(AgiDir *agid, const char *fname) {
fp.read(mem, flen);
- // initialize directory entries to empty
- for (int i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
- agid[i].volume = 0xff;
- agid[i].offset = _EMPTY;
- }
-
// read directory entries
for (uint32 i = 0; i + 2 < flen; i += 3) {
agid[i / 3].volume = *(mem + i) >> 4;
diff --git a/engines/agi/loader_v3.cpp b/engines/agi/loader_v3.cpp
index e783cfbbef1..db920bc2e4f 100644
--- a/engines/agi/loader_v3.cpp
+++ b/engines/agi/loader_v3.cpp
@@ -61,12 +61,6 @@ int AgiLoader_v3::loadDir(AgiDir *agid, Common::File *fp, uint32 offs, uint32 le
fp->read(mem, len);
- // initialize directory entries to empty
- for (int i = 0; i < MAX_DIRECTORY_ENTRIES; i++) {
- agid[i].volume = 0xff;
- agid[i].offset = _EMPTY;
- }
-
// read directory entries
for (uint32 i = 0; i + 2 < len; i += 3) {
agid[i / 3].volume = *(mem + i) >> 4;
Commit: ab669cbb6b740290447aac68bde51c2b6468d244
https://github.com/scummvm/scummvm/commit/ab669cbb6b740290447aac68bde51c2b6468d244
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-08-17T17:56:39-07:00
Commit Message:
AGI: Cleanup warning messages
Changed paths:
engines/agi/cycle.cpp
engines/agi/objects.cpp
engines/agi/op_cmd.cpp
engines/agi/picture.cpp
diff --git a/engines/agi/cycle.cpp b/engines/agi/cycle.cpp
index 2b4f5f06e36..f542e724ab4 100644
--- a/engines/agi/cycle.cpp
+++ b/engines/agi/cycle.cpp
@@ -343,7 +343,7 @@ int AgiEngine::playGame() {
_game.gfxMode = true;
_text->promptRow_Set(22);
- debug(0, "Running AGI script.\n");
+ debug(0, "Running AGI script");
setFlag(VM_FLAG_ENTERED_CLI, false);
setFlag(VM_FLAG_SAID_ACCEPTED_INPUT, false);
diff --git a/engines/agi/objects.cpp b/engines/agi/objects.cpp
index b014eaee1bb..22c3d738988 100644
--- a/engines/agi/objects.cpp
+++ b/engines/agi/objects.cpp
@@ -123,7 +123,7 @@ int AgiEngine::readObjects(Common::File &fp, int flen) {
void AgiEngine::objectSetLocation(uint16 objectNr, int location) {
if (objectNr >= _game.numObjects) {
- warning("AgiEngine::objectSetLocation: Can't access object %d.\n", objectNr);
+ warning("AgiEngine::objectSetLocation: Can't access object %d", objectNr);
return;
}
_objects[objectNr].location = location;
@@ -131,7 +131,7 @@ void AgiEngine::objectSetLocation(uint16 objectNr, int location) {
int AgiEngine::objectGetLocation(uint16 objectNr) {
if (objectNr >= _game.numObjects) {
- warning("AgiEngine::objectGetLocation: Can't access object %d.\n", objectNr);
+ warning("AgiEngine::objectGetLocation: Can't access object %d", objectNr);
return 0;
}
return _objects[objectNr].location;
@@ -139,7 +139,7 @@ int AgiEngine::objectGetLocation(uint16 objectNr) {
const char *AgiEngine::objectName(uint16 objectNr) {
if (objectNr >= _game.numObjects) {
- warning("AgiEngine::objectName: Can't access object %d.\n", objectNr);
+ warning("AgiEngine::objectName: Can't access object %d", objectNr);
return "";
}
return _objects[objectNr].name.c_str();
diff --git a/engines/agi/op_cmd.cpp b/engines/agi/op_cmd.cpp
index 21c77d465d9..a8d98d07b5c 100644
--- a/engines/agi/op_cmd.cpp
+++ b/engines/agi/op_cmd.cpp
@@ -2422,7 +2422,7 @@ int AgiEngine::runLogic(int16 logicNr) {
// state->_curLogic = &state->logics[n];
// state->lognum = n;
// ip = 2;
-// warning("running logic %d\n", n);
+// warning("running logic %d", n);
// break;
// }
// _v[13]=0;
@@ -2452,7 +2452,7 @@ int AgiEngine::runLogic(int16 logicNr) {
// state->_curLogic = &state->logics[n];
// state->lognum = n;
// state->_curLogic_cIP = 2;
-// warning("running logic %d\n", n);
+// warning("running logic %d", n);
// }
if (_game.exitAllLogics)
diff --git a/engines/agi/picture.cpp b/engines/agi/picture.cpp
index 93a59702f4c..1f9432c4e1b 100644
--- a/engines/agi/picture.cpp
+++ b/engines/agi/picture.cpp
@@ -618,7 +618,7 @@ void PictureMgr::drawPictureAGI256() {
}
if (_dataSize < maxFlen) {
- warning("Undersized AGI256 picture resource %d, using it anyway. Filling rest with white.", _resourceNr);
+ warning("Undersized AGI256 picture resource %d, using it anyway. Filling rest with white", _resourceNr);
while (_dataSize < maxFlen) {
x++;
if (x >= _width) {
More information about the Scummvm-git-logs
mailing list