diff --git a/CMakeLists.txt b/CMakeLists.txt index f3848b29..879c09e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ set(RESOURCE_HEADERS src/resource/ltrfile.h src/resource/lytfile.h src/resource/pefile.h + src/resource/resourceprovider.h src/resource/resources.h src/resource/rimfile.h src/resource/tlkfile.h diff --git a/src/game/blueprint/blueprints.cpp b/src/game/blueprint/blueprints.cpp index 726a1ae6..93bf4ce9 100644 --- a/src/game/blueprint/blueprints.cpp +++ b/src/game/blueprint/blueprints.cpp @@ -43,7 +43,7 @@ void Blueprints::invalidateCache() { } shared_ptr Blueprints::getCreature(const string &resRef) { - return get(resRef, ResourceType::CreatureBlueprint, _creatureCache); + return get(resRef, ResourceType::Utc, _creatureCache); } template @@ -66,23 +66,23 @@ shared_ptr Blueprints::doGet(const string &resRef, ResourceType type) { } shared_ptr Blueprints::getDoor(const string &resRef) { - return get(resRef, ResourceType::DoorBlueprint, _doorCache); + return get(resRef, ResourceType::Utd, _doorCache); } shared_ptr Blueprints::getItem(const string &resRef) { - return get(resRef, ResourceType::ItemBlueprint, _itemCache); + return get(resRef, ResourceType::Uti, _itemCache); } shared_ptr Blueprints::getPlaceable(const string &resRef) { - return get(resRef, ResourceType::PlaceableBlueprint, _placeableCache); + return get(resRef, ResourceType::Utp, _placeableCache); } shared_ptr Blueprints::getSound(const string &resRef) { - return get(resRef, ResourceType::SoundBlueprint, _soundCache); + return get(resRef, ResourceType::Uts, _soundCache); } shared_ptr Blueprints::getTrigger(const string &resRef) { - return get(resRef, ResourceType::TriggerBlueprint, _triggerCache); + return get(resRef, ResourceType::Utt, _triggerCache); } } // namespace game diff --git a/src/game/game.cpp b/src/game/game.cpp index ae782a6b..50e8a5f0 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -221,7 +221,7 @@ void Game::loadModule(const string &name, string entry) { if (maybeModule != _loadedModules.end()) { _module = maybeModule->second; } else { - shared_ptr ifo(Resources::instance().getGFF("module", ResourceType::ModuleInfo)); + shared_ptr ifo(Resources::instance().getGFF("module", ResourceType::Ifo)); _module = _objectFactory->newModule(); _module->load(name, *ifo); diff --git a/src/game/gui/chargen/nameentry.cpp b/src/game/gui/chargen/nameentry.cpp index 4ec8745d..7136d680 100644 --- a/src/game/gui/chargen/nameentry.cpp +++ b/src/game/gui/chargen/nameentry.cpp @@ -56,7 +56,7 @@ void NameEntry::load() { } void NameEntry::loadLtrFile(const string &resRef, LtrFile <r) { - shared_ptr data(Resources::instance().get(resRef, ResourceType::LetterComboProbability)); + shared_ptr data(Resources::instance().get(resRef, ResourceType::Ltr)); ltr.load(wrap(data)); } diff --git a/src/game/gui/dialog.cpp b/src/game/gui/dialog.cpp index 8596eecf..5fccb28d 100644 --- a/src/game/gui/dialog.cpp +++ b/src/game/gui/dialog.cpp @@ -169,7 +169,7 @@ void DialogGUI::onListBoxItemClick(const string &control, const string &item) { } void DialogGUI::startDialog(const shared_ptr &owner, const string &resRef) { - shared_ptr dlg(Resources::instance().getGFF(resRef, ResourceType::Conversation)); + shared_ptr dlg(Resources::instance().getGFF(resRef, ResourceType::Dlg)); if (!dlg) { _game->openInGame(); return; diff --git a/src/game/object/area.cpp b/src/game/object/area.cpp index b3ce7c37..28248dc9 100644 --- a/src/game/object/area.cpp +++ b/src/game/object/area.cpp @@ -105,7 +105,7 @@ void Area::load(const string &name, const GffStruct &are, const GffStruct &git) void Area::loadLYT() { LytFile lyt; - lyt.load(wrap(Resources::instance().get(_name, ResourceType::AreaLayout))); + lyt.load(wrap(Resources::instance().get(_name, ResourceType::Lyt))); for (auto &lytRoom : lyt.rooms()) { shared_ptr model(Models::instance().get(lytRoom.name)); @@ -117,7 +117,7 @@ void Area::loadLYT() { sceneNode->setLocalTransform(glm::translate(glm::mat4(1.0f), position)); sceneNode->playAnimation("animloop1", kAnimationLoop); - shared_ptr walkmesh(Walkmeshes::instance().get(lytRoom.name, ResourceType::Walkmesh)); + shared_ptr walkmesh(Walkmeshes::instance().get(lytRoom.name, ResourceType::Wok)); unique_ptr room(new Room(lytRoom.name, position, sceneNode, walkmesh)); _rooms.insert(make_pair(room->name(), move(room))); @@ -141,7 +141,7 @@ Visibility Area::fixVisibility(const Visibility &visibility) { } void Area::loadPTH() { - shared_ptr pth(Resources::instance().getGFF(_name, ResourceType::Path)); + shared_ptr pth(Resources::instance().getGFF(_name, ResourceType::Pth)); Path path; path.load(*pth); diff --git a/src/game/object/door.cpp b/src/game/object/door.cpp index 8bb3480c..381b988f 100644 --- a/src/game/object/door.cpp +++ b/src/game/object/door.cpp @@ -82,7 +82,7 @@ void Door::loadBlueprint(const GffStruct &gffs) { string modelName(boost::to_lower_copy(table->getString(_genericType, "modelname"))); _model = make_unique(_sceneGraph, Models::instance().get(modelName)); - _walkmesh = Walkmeshes::instance().get(modelName + "0", ResourceType::DoorWalkmesh); + _walkmesh = Walkmeshes::instance().get(modelName + "0", ResourceType::Dwk); } void Door::open(const shared_ptr &triggerrer) { diff --git a/src/game/object/module.cpp b/src/game/object/module.cpp index 2aca163a..ee8e6360 100644 --- a/src/game/object/module.cpp +++ b/src/game/object/module.cpp @@ -91,8 +91,8 @@ void Module::loadInfo(const GffStruct &ifo) { void Module::loadArea(const GffStruct &ifo) { reone::info("Module: load area: " + _info.entryArea); - shared_ptr are(Resources::instance().getGFF(_info.entryArea, ResourceType::Area)); - shared_ptr git(Resources::instance().getGFF(_info.entryArea, ResourceType::GameInstance)); + shared_ptr are(Resources::instance().getGFF(_info.entryArea, ResourceType::Are)); + shared_ptr git(Resources::instance().getGFF(_info.entryArea, ResourceType::Git)); shared_ptr area(_game->objectFactory().newArea()); area->load(_info.entryArea, *are, *git); diff --git a/src/game/object/placeable.cpp b/src/game/object/placeable.cpp index a3d45a02..c8db6a2d 100644 --- a/src/game/object/placeable.cpp +++ b/src/game/object/placeable.cpp @@ -86,7 +86,7 @@ void Placeable::load(const shared_ptr &blueprint) { _model = make_unique(_sceneGraph, Models::instance().get(modelName)); _model->setLightingEnabled(true); - _walkmesh = Walkmeshes::instance().get(modelName, ResourceType::PlaceableWalkmesh); + _walkmesh = Walkmeshes::instance().get(modelName, ResourceType::Pwk); } bool Placeable::hasInventory() const { diff --git a/src/render/models.cpp b/src/render/models.cpp index 11fb82b7..b0435c8f 100644 --- a/src/render/models.cpp +++ b/src/render/models.cpp @@ -54,7 +54,7 @@ shared_ptr Models::get(const string &resRef) { } shared_ptr Models::doGet(const string &resRef) { - shared_ptr mdlData(Resources::instance().get(resRef, ResourceType::Model)); + shared_ptr mdlData(Resources::instance().get(resRef, ResourceType::Mdl)); shared_ptr mdxData(Resources::instance().get(resRef, ResourceType::Mdx)); shared_ptr model; diff --git a/src/render/textures.cpp b/src/render/textures.cpp index cfc1b49e..e9f60b1a 100644 --- a/src/render/textures.cpp +++ b/src/render/textures.cpp @@ -69,7 +69,7 @@ shared_ptr Textures::doGet(const string &resRef, TextureType type) { tga.load(wrap(tgaData)); texture = tga.texture(); - shared_ptr txiData(Resources::instance().get(resRef, ResourceType::ExtraTextureInfo, false)); + shared_ptr txiData(Resources::instance().get(resRef, ResourceType::Txi, false)); if (txiData) { TxiFile txi; txi.load(wrap(txiData)); @@ -78,7 +78,7 @@ shared_ptr Textures::doGet(const string &resRef, TextureType type) { } if (!texture) { - shared_ptr tpcData(Resources::instance().get(resRef, ResourceType::Texture, false)); + shared_ptr tpcData(Resources::instance().get(resRef, ResourceType::Tpc, false)); if (tpcData) { TpcFile tpc(resRef, type); tpc.load(wrap(tpcData)); diff --git a/src/resource/erffile.h b/src/resource/erffile.h index 2f7b098b..ca0789bf 100644 --- a/src/resource/erffile.h +++ b/src/resource/erffile.h @@ -18,6 +18,7 @@ #pragma once #include "binfile.h" +#include "resourceprovider.h" #include "types.h" namespace reone { diff --git a/src/resource/folder.h b/src/resource/folder.h index d7b5e218..3e400c49 100644 --- a/src/resource/folder.h +++ b/src/resource/folder.h @@ -23,6 +23,7 @@ #include "../common/types.h" +#include "resourceprovider.h" #include "types.h" namespace reone { diff --git a/src/resource/resourceprovider.h b/src/resource/resourceprovider.h new file mode 100644 index 00000000..80ddb229 --- /dev/null +++ b/src/resource/resourceprovider.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020-2021 The reone project contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include + +#include "../common/types.h" + +#include "types.h" + +namespace reone { + +namespace resource { + +/** + * Common interface to query for game resources. + */ +class IResourceProvider { +public: + virtual ~IResourceProvider() { + } + + virtual std::shared_ptr find(const std::string &resRef, ResourceType type) = 0; + + /** + * @return true if this resource provider supports the specified ResType, + * false otherwise + */ + virtual bool supports(ResourceType type) const = 0; +}; + +} // namespace resource + +} // namespace reone diff --git a/src/resource/resources.cpp b/src/resource/resources.cpp index b247ed03..0354a7b7 100644 --- a/src/resource/resources.cpp +++ b/src/resource/resources.cpp @@ -330,7 +330,7 @@ shared_ptr Resources::getGFF(const string &resRef, ResourceType type) shared_ptr Resources::getTalkTable(const string &resRef) { return findResource(resRef, g_talkTableCache, [this, &resRef]() { - shared_ptr data(get(resRef, ResourceType::Conversation)); + shared_ptr data(get(resRef, ResourceType::Dlg)); shared_ptr table; if (data) { diff --git a/src/resource/resources.h b/src/resource/resources.h index ffbed128..475caf9d 100644 --- a/src/resource/resources.h +++ b/src/resource/resources.h @@ -34,6 +34,7 @@ #include "gfffile.h" #include "keyfile.h" #include "pefile.h" +#include "resourceprovider.h" #include "tlkfile.h" namespace reone { diff --git a/src/resource/rimfile.h b/src/resource/rimfile.h index edcdb4e1..d5924c57 100644 --- a/src/resource/rimfile.h +++ b/src/resource/rimfile.h @@ -18,6 +18,7 @@ #pragma once #include "binfile.h" +#include "resourceprovider.h" #include "types.h" namespace reone { diff --git a/src/resource/types.h b/src/resource/types.h index b8c109c6..45c2c019 100644 --- a/src/resource/types.h +++ b/src/resource/types.h @@ -17,12 +17,10 @@ #pragma once +#include #include -#include #include -#include "../common/types.h" - namespace reone { namespace resource { @@ -32,74 +30,69 @@ enum class GameVersion { TheSithLords }; +/** + * Used together with a ResRef to locate game resources. + */ enum class ResourceType : uint16_t { - Invalid = 0xffff, - Inventory = 0, + Res = 0, Bmp = 1, Tga = 3, Wav = 4, - PackedLayerTexture = 6, + Plt = 6, Ini = 7, - Text = 10, - Model = 2002, - ScriptSource = 2009, - CompiledScript = 2010, - Area = 2012, - Tileset = 2013, - ModuleInfo = 2014, - Creature = 2015, - Walkmesh = 2016, + Txt = 10, + Mdl = 2002, + Nss = 2009, + Ncs = 2010, + Are = 2012, + Set = 2013, + Ifo = 2014, + Bic = 2015, + Wok = 2016, TwoDa = 2017, - ExtraTextureInfo = 2022, - GameInstance = 2023, + Txi = 2022, + Git = 2023, Bti = 2024, - ItemBlueprint = 2025, + Uti = 2025, Btc = 2026, - CreatureBlueprint = 2027, - Conversation = 2029, - TilePalette = 2030, - TriggerBlueprint = 2032, + Utc = 2027, + Dlg = 2029, + Itp = 2030, + Utt = 2032, Dds = 2033, - SoundBlueprint = 2035, - LetterComboProbability = 2036, + Uts = 2035, + Ltr = 2036, Gff = 2037, - Faction = 2038, - EncounterBlueprint = 2040, - DoorBlueprint = 2042, - PlaceableBlueprint = 2044, - DefaultValues = 2045, - GameInstanceComments = 2046, + Fac = 2038, + Ute = 2040, + Utd = 2042, + Utp = 2044, + Dft = 2045, + Gic = 2046, Gui = 2047, - MerchantBlueprint = 2051, - DoorWalkmesh = 2052, - PlaceableWalkmesh = 2053, - Journal = 2056, + Utm = 2051, + Dwk = 2052, + Pwk = 2053, + Jrl = 2056, Mod = 2057, - WaypointBlueprint = 2058, - SoundSet = 2060, - ScriptDebugger = 2064, - PlotManager = 2065, - PlotWizardBlueprint = 2066, - AreaLayout = 3000, + Utw = 2058, + Ssf = 2060, + Ndb = 2064, + Ptm = 2065, + Ptt = 2066, + Lyt = 3000, Vis = 3001, - Path = 3003, + Pth = 3003, Lip = 3004, - Texture = 3007, + Tpc = 3007, Mdx = 3008, - Mp3 = 4000 + Mp3 = 4000, + + Invalid = 0xffff }; typedef std::multimap Visibility; -class IResourceProvider { -public: - virtual ~IResourceProvider() { - } - - virtual bool supports(ResourceType type) const = 0; - virtual std::shared_ptr find(const std::string &resRef, ResourceType type) = 0; -}; - } // namespace resource } // namespace reone diff --git a/src/resource/util.cpp b/src/resource/util.cpp index 2f4d8ff1..6b3401cd 100644 --- a/src/resource/util.cpp +++ b/src/resource/util.cpp @@ -30,57 +30,57 @@ namespace reone { namespace resource { static map g_extByType = { - { ResourceType::Inventory, "inv" }, + { ResourceType::Res, "inv" }, { ResourceType::Bmp, "bmp" }, { ResourceType::Tga, "tga" }, { ResourceType::Wav, "wav" }, - { ResourceType::PackedLayerTexture, "plt" }, + { ResourceType::Plt, "plt" }, { ResourceType::Ini, "init" }, - { ResourceType::Text, "txt" }, - { ResourceType::Model, "mdl" }, - { ResourceType::ScriptSource, "nss" }, - { ResourceType::CompiledScript, "ncs" }, - { ResourceType::Area, "are" }, - { ResourceType::Tileset, "set" }, - { ResourceType::ModuleInfo, "ifo" }, - { ResourceType::Creature, "bic" }, - { ResourceType::Walkmesh, "wok" }, + { ResourceType::Txt, "txt" }, + { ResourceType::Mdl, "mdl" }, + { ResourceType::Nss, "nss" }, + { ResourceType::Ncs, "ncs" }, + { ResourceType::Are, "are" }, + { ResourceType::Set, "set" }, + { ResourceType::Ifo, "ifo" }, + { ResourceType::Bic, "bic" }, + { ResourceType::Wok, "wok" }, { ResourceType::TwoDa, "2da" }, - { ResourceType::ExtraTextureInfo, "txi" }, - { ResourceType::GameInstance, "git" }, + { ResourceType::Txi, "txi" }, + { ResourceType::Git, "git" }, { ResourceType::Bti, "bti" }, - { ResourceType::ItemBlueprint, "uti" }, + { ResourceType::Uti, "uti" }, { ResourceType::Btc, "btc" }, - { ResourceType::CreatureBlueprint, "utc" }, - { ResourceType::Conversation, "dlg" }, - { ResourceType::TilePalette, "itp" }, - { ResourceType::TriggerBlueprint, "utt" }, + { ResourceType::Utc, "utc" }, + { ResourceType::Dlg, "dlg" }, + { ResourceType::Itp, "itp" }, + { ResourceType::Utt, "utt" }, { ResourceType::Dds, "dds" }, - { ResourceType::SoundBlueprint, "uts" }, - { ResourceType::LetterComboProbability, "ltr" }, + { ResourceType::Uts, "uts" }, + { ResourceType::Ltr, "ltr" }, { ResourceType::Gff, "gff" }, - { ResourceType::Faction, "fac" }, - { ResourceType::EncounterBlueprint, "ute" }, - { ResourceType::DoorBlueprint, "utd" }, - { ResourceType::PlaceableBlueprint, "utp" }, - { ResourceType::DefaultValues, "dft" }, - { ResourceType::GameInstanceComments, "gic" }, + { ResourceType::Fac, "fac" }, + { ResourceType::Ute, "ute" }, + { ResourceType::Utd, "utd" }, + { ResourceType::Utp, "utp" }, + { ResourceType::Dft, "dft" }, + { ResourceType::Gic, "gic" }, { ResourceType::Gui, "gui" }, - { ResourceType::MerchantBlueprint, "utm" }, - { ResourceType::DoorWalkmesh, "dwk" }, - { ResourceType::PlaceableWalkmesh, "pwk" }, - { ResourceType::Journal, "jrl" }, + { ResourceType::Utm, "utm" }, + { ResourceType::Dwk, "dwk" }, + { ResourceType::Pwk, "pwk" }, + { ResourceType::Jrl, "jrl" }, { ResourceType::Mod, "mod" }, - { ResourceType::WaypointBlueprint, "utw" }, - { ResourceType::SoundSet, "ssf" }, - { ResourceType::ScriptDebugger, "ndb" }, - { ResourceType::PlotManager, "ptm" }, - { ResourceType::PlotWizardBlueprint, "ptt" }, - { ResourceType::AreaLayout, "lyt" }, + { ResourceType::Utw, "utw" }, + { ResourceType::Ssf, "ssf" }, + { ResourceType::Ndb, "ndb" }, + { ResourceType::Ptm, "ptm" }, + { ResourceType::Ptt, "ptt" }, + { ResourceType::Lyt, "lyt" }, { ResourceType::Vis, "vis" }, - { ResourceType::Path, "pth" }, + { ResourceType::Pth, "pth" }, { ResourceType::Lip, "lip" }, - { ResourceType::Texture, "tpc" }, + { ResourceType::Tpc, "tpc" }, { ResourceType::Mdx, "mdx" }, { ResourceType::Mp3, "mp3" } }; diff --git a/src/script/scripts.cpp b/src/script/scripts.cpp index d70dddf7..9241d3d2 100644 --- a/src/script/scripts.cpp +++ b/src/script/scripts.cpp @@ -50,7 +50,7 @@ shared_ptr Scripts::get(const string &resRef) { } shared_ptr Scripts::doGet(const string &resRef) { - shared_ptr data(Resources::instance().get(resRef, ResourceType::CompiledScript)); + shared_ptr data(Resources::instance().get(resRef, ResourceType::Ncs)); shared_ptr program; if (data) { diff --git a/tools/moduleprobe.cpp b/tools/moduleprobe.cpp index 35766a5b..2e21867f 100644 --- a/tools/moduleprobe.cpp +++ b/tools/moduleprobe.cpp @@ -86,7 +86,7 @@ pt::ptree ModuleProbe::describeModule() { pt::ptree description; GffFile ifo; - ifo.load(wrap(_rimMain.find("module", ResourceType::ModuleInfo))); + ifo.load(wrap(_rimMain.find("module", ResourceType::Ifo))); auto ifoGffs = ifo.top(); // Entry @@ -148,15 +148,15 @@ pt::ptree ModuleProbe::describeModule() { pt::ptree ModuleProbe::describeArea(const string &name, const TwoDaTable &appearance, const resource::TwoDaTable &placeables) { GffFile are; - are.load(wrap(_rimMain.find(name, ResourceType::Area))); + are.load(wrap(_rimMain.find(name, ResourceType::Are))); auto areGffs = are.top(); GffFile git; - git.load(wrap(_rimMain.find(name, ResourceType::GameInstance))); + git.load(wrap(_rimMain.find(name, ResourceType::Git))); auto gitGffs = git.top(); LytFile lyt; - lyt.load(wrap(getResource(name, ResourceType::AreaLayout))); + lyt.load(wrap(getResource(name, ResourceType::Lyt))); // Rooms @@ -311,7 +311,7 @@ pt::ptree ModuleProbe::describeCreature(const GffStruct &gitCreature, const TwoD orientation.put("y", gitCreature.getFloat("YOrientation")); GffFile utc; - utc.load(wrap(getResource(gitCreature.getString("TemplateResRef"), ResourceType::CreatureBlueprint))); + utc.load(wrap(getResource(gitCreature.getString("TemplateResRef"), ResourceType::Utc))); auto utcGffs = utc.top(); pt::ptree equipment; @@ -372,7 +372,7 @@ pt::ptree ModuleProbe::describeCreature(const GffStruct &gitCreature, const TwoD pt::ptree ModuleProbe::describeDoor(const GffStruct &gitDoor) { GffFile utd; - utd.load(wrap(getResource(gitDoor.getString("TemplateResRef"), ResourceType::DoorBlueprint))); + utd.load(wrap(getResource(gitDoor.getString("TemplateResRef"), ResourceType::Utd))); auto utdGffs = utd.top(); pt::ptree scripts; @@ -417,7 +417,7 @@ pt::ptree ModuleProbe::describeDoor(const GffStruct &gitDoor) { pt::ptree ModuleProbe::describePlaceable(const GffStruct &gitPlaceable, const TwoDaTable &placeables) { GffFile utp; - utp.load(wrap(getResource(gitPlaceable.getString("TemplateResRef"), ResourceType::PlaceableBlueprint))); + utp.load(wrap(getResource(gitPlaceable.getString("TemplateResRef"), ResourceType::Utp))); auto utpGffs = utp.top(); pt::ptree items; @@ -472,7 +472,7 @@ pt::ptree ModuleProbe::describePlaceable(const GffStruct &gitPlaceable, const Tw pt::ptree ModuleProbe::describeTrigger(const GffStruct &gitTrigger) { GffFile utt; - utt.load(wrap(getResource(gitTrigger.getString("TemplateResRef"), ResourceType::TriggerBlueprint))); + utt.load(wrap(getResource(gitTrigger.getString("TemplateResRef"), ResourceType::Utt))); auto uttGffs = utt.top(); pt::ptree position; @@ -542,7 +542,7 @@ pt::ptree ModuleProbe::describeWaypoint(const GffStruct &gitWaypoint) { pt::ptree ModuleProbe::describeSound(const GffStruct &gitSound) { GffFile uts; - uts.load(wrap(getResource(gitSound.getString("TemplateResRef"), ResourceType::SoundBlueprint))); + uts.load(wrap(getResource(gitSound.getString("TemplateResRef"), ResourceType::Uts))); auto utsGffs = uts.top(); pt::ptree position;