Skip to content

Commit

Permalink
TETRAEDGE: Cache FSNode lookups
Browse files Browse the repository at this point in the history
This is based on @andrewglass's work in PR scummvm#5714, and allows us to
cache the remaining cases where Common::FSNode is used
  • Loading branch information
bluegr committed Aug 4, 2024
1 parent eb0f20a commit bc92a10
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
17 changes: 16 additions & 1 deletion engines/tetraedge/te/te_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

namespace Tetraedge {

TeCore::TeCore() : _loc(nullptr), _coreNotReady(true) {
TeCore::TeCore() : _loc(nullptr), _coreNotReady(true), _resourcesRoot("") {
create();
}

Expand All @@ -61,6 +61,21 @@ void TeCore::create() {
_coreNotReady = false;
_activityTrackingTimer.alarmSignal().add(this, &TeCore::onActivityTrackingAlarm);
warning("TODO: TeCore::create: Finish implementing me.");

const Common::FSNode gameRoot(ConfMan.getPath("path"));
if (!gameRoot.isDirectory())
error("Game directory should be a directory");
const Common::FSNode resNode = (g_engine->getGamePlatform() == Common::kPlatformMacintosh
? gameRoot.getChild("Resources")
: gameRoot);
if (!resNode.isDirectory())
error("Resources directory should exist in game");

_resourcesRoot = Common::FSDirectory(resNode, 5, false, false, true);
}

Common::FSNode TeCore::getFSNode(const Common::Path &path) const {
return Common::FSNode(Common::Path(_resourcesRoot.getFSNode().getPath()).join(path));
}

TeICodec *TeCore::createVideoCodec(const Common::String &extn) {
Expand Down
2 changes: 2 additions & 0 deletions engines/tetraedge/te/te_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ class TeCore {
// adds things like "PC-MacOSX" to the path, and there is not clear logic
// to them, so here we are.
Common::Path findFile(const Common::Path &path) const;
Common::FSNode getFSNode(const Common::Path &path) const;

bool _coreNotReady;

private:
TeILoc *_loc;

Common::HashMap<Common::String, Common::String, Common::CaseSensitiveString_Hash, Common::CaseSensitiveString_EqualTo> _fileSystemFlags;
Common::FSDirectory _resourcesRoot;

TeTimer _activityTrackingTimer;
};
Expand Down
6 changes: 3 additions & 3 deletions engines/tetraedge/te/te_images_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
*/

#include "common/file.h"
#include "common/config-manager.h"
#include "image/png.h"
#include "graphics/surface.h"
#include "graphics/managed_surface.h"

#include "tetraedge/tetraedge.h"
#include "tetraedge/te/te_core.h"
#include "tetraedge/te/te_images_sequence.h"

namespace Tetraedge {
Expand All @@ -49,8 +50,7 @@ static bool compareNodes(const Common::FSNode &left, const Common::FSNode &right
}

bool TeImagesSequence::load(const Common::Path &directory) {
const Common::FSNode gameRoot(ConfMan.getPath("path"));
Common::FSNode dir(gameRoot.getChild("Resources").getPath().joinInPlace(directory));
Common::FSNode dir = g_engine->getCore()->getFSNode(directory);

const Common::String path = directory.toString('/');
if (!dir.isDirectory()) {
Expand Down
4 changes: 1 addition & 3 deletions engines/tetraedge/te/te_sprite_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*
*/

#include "common/config-manager.h"
#include "common/file.h"

#include "tetraedge/tetraedge.h"
Expand Down Expand Up @@ -83,8 +82,7 @@ bool TeSpriteLayout::load(const Common::Path &path) {
}

TeCore *core = g_engine->getCore();
const Common::FSNode gameRoot(ConfMan.getPath("path"));
Common::FSNode spriteNode(gameRoot.getChild("Resources").getPath().joinInPlace(path));
Common::FSNode spriteNode = core->getFSNode(path);
Common::Path spritePath(path);

// The path can point to a single file, or a folder with files
Expand Down

0 comments on commit bc92a10

Please sign in to comment.