metaforce/DataSpec/DNAMP1/MLVL.cpp

578 lines
22 KiB
C++
Raw Normal View History

2016-10-01 23:20:20 +00:00
#include "MLVL.hpp"
#include "SCLY.hpp"
2016-10-02 22:41:36 +00:00
#include "SAVW.hpp"
#include "SCAN.hpp"
#include "ScriptObjects/MemoryRelay.hpp"
#include "ScriptObjects/SpecialFunction.hpp"
#include "ScriptObjects/DoorArea.hpp"
#include "Runtime/RetroTypes.hpp"
2017-01-24 07:41:33 +00:00
#include "Runtime/World/ScriptObjectSupport.hpp"
2017-12-29 08:08:12 +00:00
#include "hecl/Blender/Connection.hpp"
2016-10-01 23:20:20 +00:00
2017-12-29 08:08:12 +00:00
namespace DataSpec::DNAMP1
2016-10-01 23:20:20 +00:00
{
2017-01-31 11:21:45 +00:00
bool MLVL::Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath,
2017-12-29 08:08:12 +00:00
PAKRouter<PAKBridge>& pakRouter, const PAK::Entry& entry, bool force, hecl::blender::Token& btok,
2016-10-01 23:20:20 +00:00
std::function<void(const hecl::SystemChar*)> fileChanged)
{
MLVL mlvl;
mlvl.read(rs);
2017-01-31 11:21:45 +00:00
const nod::Node* node;
const typename PAKRouter<PAKBridge>::EntryType* savwEntry = pakRouter.lookupEntry(mlvl.saveWorldId, &node);
2017-01-31 11:21:45 +00:00
SAVW savw;
{
PAKEntryReadStream rs = savwEntry->beginReadStream(*node);
2017-01-31 11:21:45 +00:00
savw.read(rs);
}
2016-10-02 22:41:36 +00:00
2017-01-31 11:21:45 +00:00
atUint32 areaIdx = 0;
2016-10-02 22:41:36 +00:00
for (const MLVL::Area& area : mlvl.areas)
{
hecl::ProjectPath areaDir = pakRouter.getWorking(area.areaMREAId).getParentPath();
2017-01-31 11:21:45 +00:00
{
2018-10-14 20:16:21 +00:00
athena::io::FileWriter fw(hecl::ProjectPath(areaDir, _SYS_STR("!memoryid.yaml")).getAbsolutePath());
2017-01-31 11:21:45 +00:00
athena::io::YAMLDocWriter w(nullptr);
w.writeUint32("memoryid", area.areaId);
w.finish(&fw);
}
{
2018-10-14 20:16:21 +00:00
athena::io::FileWriter fw(hecl::ProjectPath(areaDir, _SYS_STR("!memoryrelays.yaml")).getAbsolutePath());
2017-01-31 11:21:45 +00:00
athena::io::YAMLDocWriter w(nullptr);
std::vector<atUint32> relayIds;
for (const atUint32& relay : savw.relays)
{
atUint16 aIdx = ((relay >> 16) & 0x3ff);
if (aIdx == areaIdx && std::find(relayIds.begin(), relayIds.end(), relay) == relayIds.end())
relayIds.push_back(relay);
}
w.enumerate<atUint32>("memrelays", relayIds);
w.finish(&fw);
}
2018-04-07 20:55:57 +00:00
if (pakRouter.mreaHasDupeResources(area.areaMREAId))
2018-10-14 20:16:21 +00:00
athena::io::FileWriter(hecl::ProjectPath(areaDir, _SYS_STR("!duperes")).getAbsolutePath());
2017-01-31 11:21:45 +00:00
areaIdx++;
2016-10-02 22:41:36 +00:00
}
2018-10-14 20:16:21 +00:00
athena::io::FileWriter writer(outPath.getWithExtension(_SYS_STR(".yaml"), true).getAbsolutePath());
2018-02-22 07:24:51 +00:00
athena::io::ToYAMLStream(mlvl, writer, &MLVL::writeMeta);
2017-12-29 08:08:12 +00:00
hecl::blender::Connection& conn = btok.getBlenderConnection();
2017-01-31 11:21:45 +00:00
return DNAMLVL::ReadMLVLToBlender(conn, mlvl, outPath, pakRouter, entry, force, fileChanged);
2016-10-01 23:20:20 +00:00
}
struct LayerResources
{
2018-04-07 20:55:57 +00:00
std::unordered_set<hecl::Hash> addedPaths;
2018-04-02 04:27:24 +00:00
std::vector<std::vector<std::pair<hecl::ProjectPath, bool>>> layerPaths;
std::unordered_set<hecl::Hash> addedSharedPaths;
2018-04-02 04:27:24 +00:00
std::vector<std::pair<hecl::ProjectPath, bool>> sharedPaths;
void beginLayer()
{
layerPaths.resize(layerPaths.size() + 1);
2018-04-07 20:55:57 +00:00
addedPaths.clear();
}
2018-04-02 04:27:24 +00:00
void addSharedPath(const hecl::ProjectPath& path, bool lazy)
{
auto search = addedSharedPaths.find(path.hash());
if (search == addedSharedPaths.cend())
{
2018-04-02 04:27:24 +00:00
sharedPaths.emplace_back(path, lazy);
addedSharedPaths.insert(path.hash());
}
}
2018-04-02 04:27:24 +00:00
void addPath(const hecl::ProjectPath& path, bool lazy)
{
auto search = addedPaths.find(path.hash());
2018-04-07 20:55:57 +00:00
if (search == addedPaths.cend())
{
2018-04-02 04:27:24 +00:00
layerPaths.back().emplace_back(path, lazy);
2018-04-07 20:55:57 +00:00
addedPaths.insert(path.hash());
}
}
};
2017-01-31 11:21:45 +00:00
bool MLVL::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath, const World& wld,
2017-12-29 08:08:12 +00:00
hecl::blender::Token& btok)
2016-10-01 23:20:20 +00:00
{
MLVL mlvl = {};
2018-10-14 20:16:21 +00:00
athena::io::FileReader reader(inPath.getWithExtension(_SYS_STR(".yaml"), true).getAbsolutePath());
2018-02-22 07:24:51 +00:00
athena::io::FromYAMLStream(mlvl, reader, &MLVL::readMeta);
2016-10-01 23:20:20 +00:00
mlvl.magic = 0xDEAFBABE;
mlvl.version = 0x11;
2018-10-14 20:16:21 +00:00
hecl::ProjectPath namePath(inPath.getParentPath(), _SYS_STR("!name.yaml"));
2016-10-08 03:41:08 +00:00
if (namePath.isFile())
mlvl.worldNameId = namePath;
2018-10-14 20:16:21 +00:00
hecl::ProjectPath globPath = inPath.getWithExtension(_SYS_STR(".*"), true);
hecl::ProjectPath savwPath = globPath.ensureAuxInfo(_SYS_STR("SAVW"));
2016-10-02 22:41:36 +00:00
mlvl.saveWorldId = savwPath;
2018-10-14 20:16:21 +00:00
hecl::ProjectPath mapwPath = globPath.ensureAuxInfo(_SYS_STR("MAPW"));
2016-10-02 22:41:36 +00:00
mlvl.worldMap = mapwPath;
2016-10-01 23:20:20 +00:00
size_t areaIdx = 0;
2016-10-02 22:41:36 +00:00
size_t nameOffset = 0;
2016-10-01 23:20:20 +00:00
for (const World::Area& area : wld.areas)
{
if (area.path.getPathType() != hecl::ProjectPath::Type::Directory)
continue;
2016-10-02 22:41:36 +00:00
2018-10-14 20:16:21 +00:00
hecl::ProjectPath areaPath(area.path, _SYS_STR("!area.blend"));
2016-10-02 22:41:36 +00:00
if (!areaPath.isFile())
continue;
2018-10-14 20:16:21 +00:00
Log.report(logvisor::Info, _SYS_STR("Visiting %s"), area.path.getRelativePath().data());
2017-02-25 07:59:37 +00:00
2018-10-14 20:16:21 +00:00
hecl::ProjectPath memRelayPath(area.path, _SYS_STR("!memoryrelays.yaml"));
2017-01-31 11:21:45 +00:00
std::vector<atUint32> memRelays;
if (memRelayPath.isFile())
{
athena::io::FileReader fr(memRelayPath.getAbsolutePath());
athena::io::YAMLDocReader r;
if (r.parse(&fr))
r.enumerate<atUint32>("memrelays", memRelays);
}
/* Bare minimum we'll need exactly the same number of links as relays */
std::vector<MemRelayLink> memRelayLinks(memRelays.size());
hecl::DirectoryEnumerator dEnum(area.path.getAbsolutePath(), hecl::DirectoryEnumerator::Mode::DirsSorted);
2016-10-01 23:20:20 +00:00
bool areaInit = false;
2016-10-02 22:41:36 +00:00
size_t layerIdx = 0;
2018-04-07 20:55:57 +00:00
LayerResources layerResources;
2016-10-01 23:20:20 +00:00
for (const hecl::DirectoryEnumerator::Entry& e : dEnum)
{
hecl::SystemString layerName;
hecl::SystemChar* endCh = nullptr;
hecl::StrToUl(e.m_name.c_str(), &endCh, 0);
if (!endCh)
2016-10-02 22:41:36 +00:00
layerName = hecl::StringUtils::TrimWhitespace(e.m_name);
2016-10-01 23:20:20 +00:00
else
layerName = hecl::StringUtils::TrimWhitespace(hecl::SystemString(endCh));
2018-10-14 20:16:21 +00:00
hecl::ProjectPath objectsPath(area.path, e.m_name + _SYS_STR("/!objects.yaml"));
2016-10-01 23:20:20 +00:00
if (objectsPath.isNone())
continue;
SCLY::ScriptLayer layer;
{
athena::io::FileReader freader(objectsPath.getAbsolutePath());
if (!freader.isOpen())
continue;
2018-02-22 07:24:51 +00:00
if (!athena::io::ValidateFromYAMLStream<DNAMP1::SCLY::ScriptLayer>(freader))
2016-10-01 23:20:20 +00:00
continue;
athena::io::YAMLDocReader reader;
if (!reader.parse(&freader))
continue;
layer.read(reader);
}
layerResources.beginLayer();
2016-10-02 22:41:36 +00:00
/* Set active flag state */
2018-10-14 20:16:21 +00:00
hecl::ProjectPath defActivePath(area.path, e.m_name + _SYS_STR("/!defaultactive"));
2016-10-01 23:20:20 +00:00
bool active = defActivePath.isNone() ? false : true;
if (!areaInit)
{
2016-10-02 22:41:36 +00:00
/* Finish last area */
2016-10-08 03:41:08 +00:00
mlvl.finishLastArea();
2016-10-02 22:41:36 +00:00
/* Populate area record */
2016-10-01 23:20:20 +00:00
mlvl.areas.emplace_back();
MLVL::Area& areaOut = mlvl.areas.back();
2016-10-02 22:41:36 +00:00
2018-10-14 20:16:21 +00:00
hecl::ProjectPath namePath(area.path, _SYS_STR("!name.yaml"));
2016-10-02 22:41:36 +00:00
if (namePath.isFile())
areaOut.areaNameId = namePath;
areaOut.transformMtx[0] = area.transform[0];
areaOut.transformMtx[1] = area.transform[1];
areaOut.transformMtx[2] = area.transform[2];
areaOut.aabb[0] = area.aabb[0];
areaOut.aabb[1] = area.aabb[1];
areaOut.areaMREAId = areaPath;
areaOut.areaId = 0xffffffff;
2018-10-14 20:16:21 +00:00
hecl::ProjectPath memIdPath(area.path, _SYS_STR("!memoryid.yaml"));
2016-10-08 03:41:08 +00:00
if (memIdPath.isFile())
2016-10-02 22:41:36 +00:00
{
athena::io::FileReader fr(memIdPath.getAbsolutePath());
athena::io::YAMLDocReader r;
if (r.parse(&fr))
areaOut.areaId = r.readUint32("memoryid");
}
/* Attached Areas and Docks */
{
std::unordered_set<uint32_t> addedAreas;
areaOut.dockCount = area.docks.size();
for (const World::Area::Dock& dock : area.docks)
{
areaOut.docks.emplace_back();
MLVL::Area::Dock& dockOut = areaOut.docks.back();
2016-10-08 03:41:08 +00:00
if (dock.targetArea != -1 && dock.targetDock != -1)
{
dockOut.endpointCount = 1;
dockOut.endpoints.emplace_back();
MLVL::Area::Dock::Endpoint& ep = dockOut.endpoints.back();
ep.areaIdx = dock.targetArea;
ep.dockIdx = dock.targetDock;
if (addedAreas.find(dock.targetArea) == addedAreas.cend())
{
addedAreas.insert(dock.targetArea);
areaOut.attachedAreas.push_back(dock.targetArea);
}
}
else
{
dockOut.endpointCount = 0;
}
2016-10-02 22:41:36 +00:00
dockOut.planeVertCount = 4;
dockOut.planeVerts.push_back(dock.verts[0]);
dockOut.planeVerts.push_back(dock.verts[1]);
dockOut.planeVerts.push_back(dock.verts[2]);
dockOut.planeVerts.push_back(dock.verts[3]);
}
areaOut.attachedAreaCount = areaOut.attachedAreas.size();
}
/* Layer flags */
mlvl.layerFlags.emplace_back();
mlvl.layerFlags.back().layerCount = 0;
mlvl.layerFlags.back().flags = ~0;
/* Layer name offset */
mlvl.layerNameOffsets.push_back(nameOffset);
2016-10-01 23:20:20 +00:00
areaInit = true;
}
2016-10-02 22:41:36 +00:00
/* Gather memory relays, scans, and dependencies */
{
2016-12-25 01:36:42 +00:00
g_ThreadBlenderToken.reset(&btok);
2016-10-02 22:41:36 +00:00
std::vector<hecl::ProjectPath> depPaths;
2018-04-02 04:27:24 +00:00
std::vector<hecl::ProjectPath> lazyPaths;
2016-10-02 22:41:36 +00:00
for (std::unique_ptr<IScriptObject>& obj : layer.objects)
{
2017-01-24 07:41:33 +00:00
if (obj->type == int(urde::EScriptObjectType::MemoryRelay))
2016-10-02 22:41:36 +00:00
{
MemoryRelay& memRelay = static_cast<MemoryRelay&>(*obj);
for (IScriptObject::Connection& conn : memRelay.connections)
{
2017-01-31 11:21:45 +00:00
MemRelayLink linkOut;
2016-10-02 22:41:36 +00:00
linkOut.memRelayId = memRelay.id;
linkOut.targetId = conn.target;
linkOut.msg = conn.msg;
linkOut.active = memRelay.active;
2017-01-31 11:21:45 +00:00
auto iter = std::find(memRelays.begin(), memRelays.end(), linkOut.memRelayId);
if (iter == memRelays.end())
{
/* We must have a new relay, let's track it */
memRelayLinks.push_back(linkOut);
memRelays.push_back(memRelay.id);
}
else /* Lets insert this in it's appropriate location, target order doesn't matter */
{
atUint32 idx = iter - memRelays.begin();
if (idx >= memRelayLinks.size())
memRelayLinks.push_back(linkOut);
else
memRelayLinks.insert(memRelayLinks.begin() + idx, linkOut);
}
2016-10-02 22:41:36 +00:00
}
}
2018-05-08 02:11:07 +00:00
obj->gatherDependencies(depPaths, lazyPaths);
2016-10-02 22:41:36 +00:00
}
/* Cull duplicate paths and add typed hash to list */
for (const hecl::ProjectPath& path : depPaths)
2018-04-07 20:55:57 +00:00
layerResources.addPath(path, false);
2018-04-02 04:27:24 +00:00
for (const hecl::ProjectPath& path : lazyPaths)
2018-04-07 20:55:57 +00:00
layerResources.addPath(path, true);
2016-10-02 22:41:36 +00:00
}
2017-11-13 06:19:18 +00:00
hecl::SystemUTF8Conv layerU8(layerName);
mlvl.layerNames.emplace_back(layerU8.str());
2016-10-02 22:41:36 +00:00
nameOffset += layerName.size() + 1;
MLVL::LayerFlags& thisLayFlags = mlvl.layerFlags.back();
++thisLayFlags.layerCount;
if (!active)
thisLayFlags.flags &= ~(1 << layerIdx);
++layerIdx;
2016-10-01 23:20:20 +00:00
}
2016-10-08 03:41:08 +00:00
2018-04-07 20:55:57 +00:00
if (!areaInit)
2018-10-14 20:16:21 +00:00
Log.report(logvisor::Info, _SYS_STR("No layer directories for area %s"), area.path.getRelativePath().data());
2018-04-07 20:55:57 +00:00
/* Build deplist */
MLVL::Area& areaOut = mlvl.areas.back();
2018-04-02 04:27:24 +00:00
for (const std::vector<std::pair<hecl::ProjectPath, bool>>& layer : layerResources.layerPaths)
{
areaOut.depLayers.push_back(areaOut.deps.size());
2018-04-02 04:27:24 +00:00
for (const std::pair<hecl::ProjectPath, bool>& path : layer)
{
2018-04-02 04:27:24 +00:00
if (path.first)
{
2018-04-02 04:27:24 +00:00
urde::SObjectTag tag = g_curSpec->buildTagFromPath(path.first, btok);
if (tag.id.IsValid())
2018-04-02 04:27:24 +00:00
{
if (path.second)
areaOut.lazyDeps.emplace_back(tag.id.Value(), tag.type);
else
areaOut.lazyDeps.emplace_back(0, FOURCC('NONE'));
areaOut.deps.emplace_back(tag.id.Value(), tag.type);
2018-04-02 04:27:24 +00:00
}
}
}
}
2017-01-31 11:21:45 +00:00
/* Append Memory Relays */
mlvl.memRelayLinks.insert(mlvl.memRelayLinks.end(), memRelayLinks.begin(), memRelayLinks.end());
2016-10-08 03:41:08 +00:00
/* Cull duplicate area paths and add typed hash to list */
2017-01-19 09:03:43 +00:00
auto& conn = btok.getBlenderConnection();
2016-10-08 03:41:08 +00:00
if (conn.openBlend(areaPath))
{
areaOut.depLayers.push_back(areaOut.deps.size());
auto ds = conn.beginData();
std::vector<hecl::ProjectPath> texs = ds.getTextures();
ds.close();
for (const hecl::ProjectPath& path : texs)
2018-04-02 04:27:24 +00:00
layerResources.addSharedPath(path, false);
2018-04-02 04:27:24 +00:00
for (const std::pair<hecl::ProjectPath, bool>& path : layerResources.sharedPaths)
2016-10-08 03:41:08 +00:00
{
2018-04-02 04:27:24 +00:00
urde::SObjectTag tag = g_curSpec->buildTagFromPath(path.first, btok);
if (tag.id.IsValid())
2018-04-02 04:27:24 +00:00
{
if (path.second)
areaOut.lazyDeps.emplace_back(tag.id.Value(), tag.type);
else
areaOut.lazyDeps.emplace_back(0, FOURCC('NONE'));
areaOut.deps.emplace_back(tag.id.Value(), tag.type);
2018-04-02 04:27:24 +00:00
}
2016-10-08 03:41:08 +00:00
}
2018-10-14 20:16:21 +00:00
hecl::ProjectPath pathPath(areaPath.getParentPath(), _SYS_STR("!path.blend"));
2018-02-25 08:23:27 +00:00
urde::SObjectTag pathTag = g_curSpec->buildTagFromPath(pathPath, btok);
2017-10-26 05:37:46 +00:00
if (pathTag.id.IsValid())
2018-04-02 04:27:24 +00:00
{
2017-10-26 05:37:46 +00:00
areaOut.deps.emplace_back(pathTag.id.Value(), pathTag.type);
2018-04-02 04:27:24 +00:00
areaOut.lazyDeps.emplace_back(0, FOURCC('NONE'));
}
2016-10-08 03:41:08 +00:00
}
2016-10-01 23:20:20 +00:00
++areaIdx;
}
2016-10-02 22:41:36 +00:00
2016-10-08 03:41:08 +00:00
/* Finish last area */
mlvl.finishLastArea();
2016-10-01 23:20:20 +00:00
mlvl.memRelayLinkCount = mlvl.memRelayLinks.size();
mlvl.areaCount = mlvl.areas.size();
2016-10-02 22:41:36 +00:00
mlvl.layerFlagCount = mlvl.layerFlags.size();
mlvl.layerNameCount = mlvl.layerNames.size();
mlvl.layerNameOffsetCount = mlvl.layerNameOffsets.size();
/* Write out */
{
athena::io::FileWriter fo(outPath.getAbsolutePath());
mlvl.write(fo);
int64_t rem = fo.position() % 32;
if (rem)
for (int64_t i=0 ; i<32-rem ; ++i)
fo.writeBytes((atInt8*)"\xff", 1);
}
return true;
}
bool MLVL::CookMAPW(const hecl::ProjectPath& outPath,
const World& wld,
2017-12-29 08:08:12 +00:00
hecl::blender::Token& btok)
{
std::vector<urde::SObjectTag> mapaTags;
mapaTags.reserve(wld.areas.size());
for (const World::Area& area : wld.areas)
{
if (area.path.getPathType() != hecl::ProjectPath::Type::Directory)
continue;
/* Area map */
2018-10-14 20:16:21 +00:00
hecl::ProjectPath mapPath(area.path, _SYS_STR("/!map.blend"));
if (mapPath.isFile())
mapaTags.push_back(g_curSpec->buildTagFromPath(mapPath, btok));
2016-10-02 22:41:36 +00:00
}
/* Write out MAPW */
{
athena::io::FileWriter fo(outPath.getAbsolutePath());
2016-10-02 22:41:36 +00:00
fo.writeUint32Big(0xDEADF00D);
fo.writeUint32Big(1);
fo.writeUint32Big(mapaTags.size());
for (const urde::SObjectTag& mapa : mapaTags)
2017-08-13 05:26:14 +00:00
fo.writeUint32Big(u32(mapa.id.Value()));
int64_t rem = fo.position() % 32;
if (rem)
for (int64_t i=0 ; i<32-rem ; ++i)
fo.writeBytes((atInt8*)"\xff", 1);
}
return true;
}
bool MLVL::CookSAVW(const hecl::ProjectPath& outPath,
const World& wld)
{
SAVW savw = {};
savw.header.magic = 0xC001D00D;
savw.header.version = 0x3;
std::unordered_set<UniqueID32> addedScans;
for (const World::Area& area : wld.areas)
{
if (area.path.getPathType() != hecl::ProjectPath::Type::Directory)
continue;
2018-10-14 20:16:21 +00:00
hecl::ProjectPath areaPath(area.path, _SYS_STR("/!area.blend"));
if (!areaPath.isFile())
continue;
2018-10-14 20:16:21 +00:00
hecl::ProjectPath memRelayPath(area.path, _SYS_STR("/!memoryrelays.yaml"));
std::vector<atUint32> memRelays;
if (memRelayPath.isFile())
{
athena::io::FileReader fr(memRelayPath.getAbsolutePath());
athena::io::YAMLDocReader r;
if (r.parse(&fr))
r.enumerate<atUint32>("memrelays", memRelays);
}
savw.relays.insert(savw.relays.end(), memRelays.begin(), memRelays.end());
hecl::DirectoryEnumerator dEnum(area.path.getAbsolutePath(), hecl::DirectoryEnumerator::Mode::DirsSorted);
for (const hecl::DirectoryEnumerator::Entry& e : dEnum)
{
hecl::SystemString layerName;
hecl::SystemChar* endCh = nullptr;
hecl::StrToUl(e.m_name.c_str(), &endCh, 0);
if (!endCh)
layerName = hecl::StringUtils::TrimWhitespace(e.m_name);
else
layerName = hecl::StringUtils::TrimWhitespace(hecl::SystemString(endCh));
2018-10-14 20:16:21 +00:00
hecl::ProjectPath objectsPath(area.path, e.m_name + _SYS_STR("/!objects.yaml"));
if (objectsPath.isNone())
continue;
SCLY::ScriptLayer layer;
{
athena::io::FileReader freader(objectsPath.getAbsolutePath());
if (!freader.isOpen())
continue;
2018-02-22 07:24:51 +00:00
if (!athena::io::ValidateFromYAMLStream<DNAMP1::SCLY::ScriptLayer>(freader))
continue;
athena::io::YAMLDocReader reader;
if (!reader.parse(&freader))
continue;
layer.read(reader);
}
/* Gather memory relays, scans, and dependencies */
{
std::vector<Scan> scans;
for (std::unique_ptr<IScriptObject>& obj : layer.objects)
{
if (obj->type == int(urde::EScriptObjectType::MemoryRelay))
{
MemoryRelay& memRelay = static_cast<MemoryRelay&>(*obj);
auto iter = std::find(memRelays.begin(), memRelays.end(), memRelay.id);
if (iter == memRelays.end())
{
/* We must have a new relay, let's track it */
savw.relays.push_back(memRelay.id);
memRelays.push_back(memRelay.id);
}
}
else if (obj->type == int(urde::EScriptObjectType::SpecialFunction))
{
SpecialFunction& specialFunc = static_cast<SpecialFunction&>(*obj);
if (specialFunc.function == ESpecialFunctionType::CinematicSkip)
savw.skippableCutscenes.push_back(specialFunc.id);
else if (specialFunc.function == ESpecialFunctionType::ScriptLayerController)
{
savw.layers.emplace_back();
SAVWCommon::Layer& layer = savw.layers.back();
layer.areaId = specialFunc.layerSwitch.area;
layer.layer = specialFunc.layerSwitch.layerIdx;
}
}
else if (obj->type == int(urde::EScriptObjectType::Door))
{
DoorArea& doorArea = static_cast<DoorArea&>(*obj);
savw.doors.push_back(doorArea.id);
}
obj->gatherScans(scans);
}
/* Cull duplicate scans and add to list */
for (const Scan& scan : scans)
{
if (!scan.scanId)
continue;
if (addedScans.find(scan.scanId) == addedScans.cend())
{
addedScans.insert(scan.scanId);
hecl::ProjectPath scanPath = UniqueIDBridge::TranslatePakIdToPath(scan.scanId);
savw.scans.emplace_back();
Scan& scanOut = savw.scans.back();
scanOut.scanId = scan.scanId;
scanOut.category = SAVWCommon::EScanCategory(SCAN::GetCategory(scanPath));
}
}
}
}
2016-10-02 22:41:36 +00:00
}
/* Write out SAVW */
{
savw.header.areaCount = wld.areas.size();
2016-10-02 22:41:36 +00:00
savw.skippableCutsceneCount = savw.skippableCutscenes.size();
savw.relayCount = savw.relays.size();
savw.layerCount = savw.layers.size();
savw.doorCount = savw.doors.size();
savw.scanCount = savw.scans.size();
athena::io::FileWriter fo(outPath.getAbsolutePath());
2016-10-02 22:41:36 +00:00
savw.write(fo);
2017-02-06 03:32:06 +00:00
int64_t rem = fo.position() % 32;
if (rem)
for (int64_t i=0 ; i<32-rem ; ++i)
fo.writeBytes((atInt8*)"\xff", 1);
2016-10-02 22:41:36 +00:00
}
2016-10-01 23:20:20 +00:00
2016-10-02 22:41:36 +00:00
return true;
2016-10-01 23:20:20 +00:00
}
2016-10-01 23:20:20 +00:00
}