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;
|
2017-02-09 07:37:00 +00:00
|
|
|
const typename PAKRouter<PAKBridge>::EntryType* savwEntry = pakRouter.lookupEntry(mlvl.saveWorldId, &node);
|
2017-01-31 11:21:45 +00:00
|
|
|
SAVW savw;
|
|
|
|
{
|
2017-02-09 07:37:00 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
athena::io::FileWriter fw(hecl::ProjectPath(areaDir, _S("!memoryid.yaml")).getAbsolutePath());
|
|
|
|
athena::io::YAMLDocWriter w(nullptr);
|
|
|
|
w.writeUint32("memoryid", area.areaId);
|
|
|
|
w.finish(&fw);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
athena::io::FileWriter fw(hecl::ProjectPath(areaDir, _S("!memoryrelays.yaml")).getAbsolutePath());
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
areaIdx++;
|
2016-10-02 22:41:36 +00:00
|
|
|
}
|
|
|
|
|
2016-10-01 23:20:20 +00:00
|
|
|
athena::io::FileWriter writer(outPath.getWithExtension(_S(".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
|
|
|
}
|
|
|
|
|
2018-03-28 08:09:41 +00:00
|
|
|
struct BulkResources
|
|
|
|
{
|
|
|
|
std::unordered_map<hecl::Hash, size_t> addedBulkPaths;
|
|
|
|
bool addBulkPath(const hecl::ProjectPath& path, size_t areaIdx)
|
|
|
|
{
|
|
|
|
auto search = addedBulkPaths.find(path.hash());
|
|
|
|
if (search == addedBulkPaths.cend())
|
|
|
|
{
|
|
|
|
addedBulkPaths.insert(std::make_pair(path.hash(), areaIdx));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LayerResources
|
|
|
|
{
|
|
|
|
BulkResources& bulkResources;
|
|
|
|
std::unordered_map<hecl::Hash, std::pair<size_t, size_t>> addedPaths;
|
2018-04-02 04:27:24 +00:00
|
|
|
std::vector<std::vector<std::pair<hecl::ProjectPath, bool>>> layerPaths;
|
2018-03-28 08:09:41 +00:00
|
|
|
std::unordered_set<hecl::Hash> addedSharedPaths;
|
2018-04-02 04:27:24 +00:00
|
|
|
std::vector<std::pair<hecl::ProjectPath, bool>> sharedPaths;
|
2018-03-28 08:09:41 +00:00
|
|
|
LayerResources(BulkResources& bulkResources) : bulkResources(bulkResources) {}
|
|
|
|
void beginLayer()
|
|
|
|
{
|
|
|
|
layerPaths.resize(layerPaths.size() + 1);
|
|
|
|
}
|
2018-04-02 04:27:24 +00:00
|
|
|
void addSharedPath(const hecl::ProjectPath& path, bool lazy)
|
2018-03-28 08:09:41 +00:00
|
|
|
{
|
|
|
|
auto search = addedSharedPaths.find(path.hash());
|
|
|
|
if (search == addedSharedPaths.cend())
|
|
|
|
{
|
2018-04-02 04:27:24 +00:00
|
|
|
sharedPaths.emplace_back(path, lazy);
|
2018-03-28 08:09:41 +00:00
|
|
|
addedSharedPaths.insert(path.hash());
|
|
|
|
}
|
|
|
|
}
|
2018-04-02 04:27:24 +00:00
|
|
|
void addPath(const hecl::ProjectPath& path, bool lazy)
|
2018-03-28 08:09:41 +00:00
|
|
|
{
|
|
|
|
auto search = addedPaths.find(path.hash());
|
|
|
|
if (search != addedPaths.cend())
|
|
|
|
{
|
|
|
|
if (search->second.first == layerPaths.size() - 1)
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
{
|
2018-04-02 04:27:24 +00:00
|
|
|
auto& toMove = layerPaths[search->second.first][search->second.second];
|
|
|
|
addSharedPath(toMove.first, toMove.second);
|
|
|
|
toMove.first.clear();
|
2018-03-28 08:09:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-02 04:27:24 +00:00
|
|
|
layerPaths.back().emplace_back(path, lazy);
|
2018-03-28 08:09:41 +00:00
|
|
|
addedPaths.insert(std::make_pair(path.hash(),
|
|
|
|
std::make_pair(layerPaths.size() - 1, layerPaths.back().size() - 1)));
|
|
|
|
}
|
|
|
|
}
|
2018-04-02 04:27:24 +00:00
|
|
|
void addBulkPath(const hecl::ProjectPath& path, size_t areaIdx, bool lazy)
|
2018-03-28 08:09:41 +00:00
|
|
|
{
|
|
|
|
if (bulkResources.addBulkPath(path, areaIdx))
|
2018-04-02 04:27:24 +00:00
|
|
|
addPath(path, lazy);
|
2018-03-28 08:09:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 = {};
|
|
|
|
athena::io::FileReader reader(inPath.getWithExtension(_S(".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;
|
2016-10-08 03:41:08 +00:00
|
|
|
hecl::ProjectPath namePath(inPath.getParentPath(), _S("!name.yaml"));
|
|
|
|
if (namePath.isFile())
|
|
|
|
mlvl.worldNameId = namePath;
|
2017-10-25 07:47:49 +00:00
|
|
|
hecl::ProjectPath globPath = inPath.getWithExtension(_S(".*"), true);
|
|
|
|
hecl::ProjectPath savwPath = globPath.ensureAuxInfo(_S("SAVW"));
|
2016-10-02 22:41:36 +00:00
|
|
|
mlvl.saveWorldId = savwPath;
|
2017-10-25 07:47:49 +00:00
|
|
|
hecl::ProjectPath mapwPath = globPath.ensureAuxInfo(_S("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;
|
2018-03-28 08:09:41 +00:00
|
|
|
BulkResources bulkResources;
|
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
|
|
|
|
|
|
|
hecl::ProjectPath areaPath(area.path, _S("/!area.blend"));
|
|
|
|
if (!areaPath.isFile())
|
|
|
|
continue;
|
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
Log.report(logvisor::Info, _S("Visiting %s"), area.path.getRelativePath().data());
|
2017-02-25 07:59:37 +00:00
|
|
|
|
2017-01-31 11:21:45 +00:00
|
|
|
hecl::ProjectPath memRelayPath(area.path, _S("/!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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-03-28 08:09:41 +00:00
|
|
|
LayerResources layerResources(bulkResources);
|
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));
|
|
|
|
|
|
|
|
hecl::ProjectPath objectsPath(area.path, e.m_name + _S("/!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))
|
2016-10-01 23:20:20 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
athena::io::YAMLDocReader reader;
|
|
|
|
if (!reader.parse(&freader))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
layer.read(reader);
|
|
|
|
}
|
|
|
|
|
2018-03-28 08:09:41 +00:00
|
|
|
layerResources.beginLayer();
|
|
|
|
|
2016-10-02 22:41:36 +00:00
|
|
|
/* Set active flag state */
|
2016-10-01 23:20:20 +00:00
|
|
|
hecl::ProjectPath defActivePath(area.path, e.m_name + _S("/!defaultactive"));
|
|
|
|
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
|
|
|
|
|
|
|
hecl::ProjectPath namePath(area.path, _S("/!name.yaml"));
|
|
|
|
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;
|
|
|
|
|
|
|
|
hecl::ProjectPath memIdPath(area.path, _S("/!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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
obj->gatherDependencies(depPaths);
|
2018-04-02 04:27:24 +00:00
|
|
|
obj->gatherLazyDependencies(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-02 04:27:24 +00:00
|
|
|
layerResources.addBulkPath(path, areaIdx, false);
|
|
|
|
for (const hecl::ProjectPath& path : lazyPaths)
|
|
|
|
layerResources.addBulkPath(path, areaIdx, 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-03-28 08:09:41 +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)
|
2018-03-28 08:09:41 +00:00
|
|
|
{
|
|
|
|
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-03-28 08:09:41 +00:00
|
|
|
{
|
2018-04-02 04:27:24 +00:00
|
|
|
if (path.first)
|
2018-03-28 08:09:41 +00:00
|
|
|
{
|
2018-04-02 04:27:24 +00:00
|
|
|
urde::SObjectTag tag = g_curSpec->buildTagFromPath(path.first, btok);
|
2018-03-28 08:09:41 +00:00
|
|
|
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'));
|
2018-03-28 08:09:41 +00:00
|
|
|
areaOut.deps.emplace_back(tag.id.Value(), tag.type);
|
2018-04-02 04:27:24 +00:00
|
|
|
}
|
2018-03-28 08:09:41 +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-03-28 08:09:41 +00:00
|
|
|
|
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);
|
2018-03-28 08:09:41 +00:00
|
|
|
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'));
|
2018-03-28 08:09:41 +00:00
|
|
|
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-02-25 08:23:27 +00:00
|
|
|
hecl::ProjectPath pathPath(areaPath.getParentPath(), _S("!path.blend"));
|
|
|
|
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);
|
2017-02-13 06:51:47 +00:00
|
|
|
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)
|
2017-02-13 06:51:47 +00:00
|
|
|
{
|
|
|
|
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 */
|
|
|
|
hecl::ProjectPath mapPath(area.path, _S("/!map.blend"));
|
|
|
|
if (mapPath.isFile())
|
2017-10-25 07:47:49 +00:00
|
|
|
mapaTags.push_back(g_curSpec->buildTagFromPath(mapPath, btok));
|
2016-10-02 22:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write out MAPW */
|
|
|
|
{
|
2017-02-13 06:51:47 +00:00
|
|
|
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()));
|
2017-02-13 06:51:47 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
hecl::ProjectPath areaPath(area.path, _S("/!area.blend"));
|
|
|
|
if (!areaPath.isFile())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hecl::ProjectPath memRelayPath(area.path, _S("/!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));
|
|
|
|
|
|
|
|
hecl::ProjectPath objectsPath(area.path, e.m_name + _S("/!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))
|
2017-02-13 06:51:47 +00:00
|
|
|
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 */
|
|
|
|
{
|
2017-02-13 06:51:47 +00:00
|
|
|
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();
|
|
|
|
|
2017-02-13 06:51:47 +00:00
|
|
|
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
|
|
|
}
|
2017-02-13 06:51:47 +00:00
|
|
|
|
2016-10-01 23:20:20 +00:00
|
|
|
}
|