Athena YAML refactor

This commit is contained in:
Jack Andersen 2016-08-21 17:47:48 -10:00
parent bf049843e1
commit f8fb72250a
36 changed files with 124 additions and 187 deletions

View File

@ -305,13 +305,12 @@ template struct CRSM<UniqueID64>;
template <class IDType> template <class IDType>
bool ExtractCRSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) bool ExtractCRSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getAbsolutePath());
if (fp) if (writer.isOpen())
{ {
CRSM<IDType> crsm; CRSM<IDType> crsm;
crsm.read(rs); crsm.read(rs);
crsm.toYAMLFile(fp); crsm.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
return false; return false;

View File

@ -110,13 +110,12 @@ template struct DGRP<UniqueID64>;
template <class IDType> template <class IDType>
bool ExtractDGRP(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) bool ExtractDGRP(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getAbsolutePath());
if (fp) if (writer.isOpen())
{ {
DGRP<IDType> dgrp; DGRP<IDType> dgrp;
dgrp.read(rs); dgrp.read(rs);
dgrp.toYAMLFile(fp); dgrp.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
return false; return false;

View File

@ -3,6 +3,8 @@
#include <stdio.h> #include <stdio.h>
#include <athena/DNAYaml.hpp> #include <athena/DNAYaml.hpp>
#include <athena/FileReader.hpp>
#include <athena/FileWriter.hpp>
#include <nod/DiscBase.hpp> #include <nod/DiscBase.hpp>
#include "hecl/hecl.hpp" #include "hecl/hecl.hpp"
#include "hecl/Database.hpp" #include "hecl/Database.hpp"

View File

@ -410,13 +410,12 @@ template struct DPSM<UniqueID64>;
template <class IDType> template <class IDType>
bool ExtractDPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) bool ExtractDPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getAbsolutePath());
if (fp) if (writer.isOpen())
{ {
DPSM<IDType> dpsm; DPSM<IDType> dpsm;
dpsm.read(rs); dpsm.read(rs);
dpsm.toYAMLFile(fp); dpsm.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
return false; return false;

View File

@ -450,13 +450,12 @@ template struct ELSM<UniqueID64>;
template <class IDType> template <class IDType>
bool ExtractELSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) bool ExtractELSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getAbsolutePath());
if (fp) if (writer.isOpen())
{ {
ELSM<IDType> elsm; ELSM<IDType> elsm;
elsm.read(rs); elsm.read(rs);
elsm.toYAMLFile(fp); elsm.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
return false; return false;

View File

@ -547,13 +547,12 @@ template struct FONT<UniqueID64>;
template <class IDType> template <class IDType>
bool ExtractFONT(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) bool ExtractFONT(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getAbsolutePath());
if (fp) if (writer.isOpen())
{ {
FONT<IDType> font; FONT<IDType> font;
font.read(rs); font.read(rs);
font.toYAMLFile(fp); font.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
return false; return false;

View File

@ -984,13 +984,12 @@ template struct FSM2<UniqueID64>;
template <class IDType> template <class IDType>
bool ExtractFSM2(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) bool ExtractFSM2(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getAbsolutePath());
if (fp) if (writer.isOpen())
{ {
FSM2<IDType> fsm2; FSM2<IDType> fsm2;
fsm2.read(rs); fsm2.read(rs);
fsm2.toYAMLFile(fp); fsm2.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
return false; return false;

View File

@ -214,10 +214,8 @@ void PAKRouter<BRIDGETYPE>::build(std::vector<BRIDGETYPE>& bridges, std::functio
intptr_t curBridgeIdx = reinterpret_cast<intptr_t>(m_curBridgeIdx.get()); intptr_t curBridgeIdx = reinterpret_cast<intptr_t>(m_curBridgeIdx.get());
const hecl::ProjectPath& pakPath = m_bridgePaths[curBridgeIdx].first; const hecl::ProjectPath& pakPath = m_bridgePaths[curBridgeIdx].first;
hecl::SystemString catalogPath = hecl::ProjectPath(pakPath, "catalog.yaml").getAbsolutePath(); hecl::SystemString catalogPath = hecl::ProjectPath(pakPath, "catalog.yaml").getAbsolutePath();
FILE* catalog = hecl::Fopen(catalogPath.c_str(), _S("w")); athena::io::FileWriter writer(catalogPath);
yaml_emitter_set_output_file(catalogWriter.getEmitter(), catalog); catalogWriter.finish(&writer);
catalogWriter.finish();
fclose(catalog);
} }
} }

View File

@ -1538,13 +1538,12 @@ template struct GPSM<UniqueID64>;
template <class IDType> template <class IDType>
bool ExtractGPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) bool ExtractGPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getAbsolutePath());
if (fp) if (writer.isOpen())
{ {
GPSM<IDType> gpsm; GPSM<IDType> gpsm;
gpsm.read(rs); gpsm.read(rs);
gpsm.toYAMLFile(fp); gpsm.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
return false; return false;

View File

@ -45,9 +45,8 @@ static bool ExtractSAVW(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath
{ {
SAVW savw; SAVW savw;
savw.read(rs); savw.read(rs);
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(outPath.getAbsolutePath());
savw.toYAMLFile(fp); savw.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }

View File

@ -544,13 +544,12 @@ template struct SWSH<UniqueID64>;
template <class IDType> template <class IDType>
bool ExtractSWSH(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) bool ExtractSWSH(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getAbsolutePath());
if (fp) if (writer.isOpen())
{ {
SWSH<IDType> swsh; SWSH<IDType> swsh;
swsh.read(rs); swsh.read(rs);
swsh.toYAMLFile(fp); swsh.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
return false; return false;

View File

@ -725,13 +725,12 @@ template struct WPSM<UniqueID64>;
template <class IDType> template <class IDType>
bool ExtractWPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) bool ExtractWPSM(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getAbsolutePath());
if (fp) if (writer.isOpen())
{ {
WPSM<IDType> wpsm; WPSM<IDType> wpsm;
wpsm.read(rs); wpsm.read(rs);
wpsm.toYAMLFile(fp); wpsm.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
return false; return false;

View File

@ -159,9 +159,8 @@ struct AFSM : public BigYAML
{ {
AFSM afsm; AFSM afsm;
afsm.read(rs); afsm.read(rs);
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(outPath.getAbsolutePath());
afsm.toYAMLFile(fp); afsm.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
}; };

View File

@ -1031,9 +1031,8 @@ bool ANCS::Extract(const SpecBase& dataSpec,
{ {
if (force || yamlType == hecl::ProjectPath::Type::None) if (force || yamlType == hecl::ProjectPath::Type::None)
{ {
FILE* fp = hecl::Fopen(yamlPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(yamlPath.getAbsolutePath());
ancs.toYAMLFile(fp); ancs.toYAMLStream(writer);
fclose(fp);
} }
if (force || blendType == hecl::ProjectPath::Type::None) if (force || blendType == hecl::ProjectPath::Type::None)
@ -1062,9 +1061,8 @@ bool ANCS::Extract(const SpecBase& dataSpec,
EVNT evnt; EVNT evnt;
if (pakRouter.lookupAndReadDNA(res.second.evntId, evnt, true)) if (pakRouter.lookupAndReadDNA(res.second.evntId, evnt, true))
{ {
FILE* fp = hecl::Fopen(evntYamlPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(evntYamlPath.getAbsolutePath());
evnt.toYAMLFile(fp); evnt.toYAMLStream(writer);
fclose(fp);
} }
} }
} }
@ -1085,25 +1083,23 @@ bool ANCS::Cook(const hecl::ProjectPath& outPath,
Log.report(logvisor::Fatal, _S("'%s' not found as file"), Log.report(logvisor::Fatal, _S("'%s' not found as file"),
yamlPath.getRelativePath().c_str()); yamlPath.getRelativePath().c_str());
FILE* yamlFp = hecl::Fopen(yamlPath.getAbsolutePath().c_str(), _S("r")); athena::io::FileReader reader(yamlPath.getAbsolutePath());
if (!yamlFp) if (!reader.isOpen())
Log.report(logvisor::Fatal, _S("can't open '%s' for reading"), Log.report(logvisor::Fatal, _S("can't open '%s' for reading"),
yamlPath.getRelativePath().c_str()); yamlPath.getRelativePath().c_str());
if (!BigYAML::ValidateFromYAMLFile<ANCS>(yamlFp)) if (!BigYAML::ValidateFromYAMLStream<ANCS>(reader))
{ {
Log.report(logvisor::Fatal, _S("'%s' is not urde::DNAMP1::ANCS type"), Log.report(logvisor::Fatal, _S("'%s' is not urde::DNAMP1::ANCS type"),
yamlPath.getRelativePath().c_str()); yamlPath.getRelativePath().c_str());
} }
athena::io::YAMLDocReader yamlReader; athena::io::YAMLDocReader yamlReader;
yaml_parser_set_input_file(yamlReader.getParser(), yamlFp); if (!yamlReader.parse(&reader))
if (!yamlReader.parse())
{ {
Log.report(logvisor::Fatal, _S("unable to parse '%s'"), Log.report(logvisor::Fatal, _S("unable to parse '%s'"),
yamlPath.getRelativePath().c_str()); yamlPath.getRelativePath().c_str());
} }
fclose(yamlFp);
ANCS ancs; ANCS ancs;
ancs.read(yamlReader); ancs.read(yamlReader);
@ -1263,12 +1259,11 @@ bool ANCS::Cook(const hecl::ProjectPath& outPath,
_S(".evnt.yaml")).c_str(), true); _S(".evnt.yaml")).c_str(), true);
if (evntYamlPath.getPathType() == hecl::ProjectPath::Type::File) if (evntYamlPath.getPathType() == hecl::ProjectPath::Type::File)
{ {
FILE* fp = hecl::Fopen(evntYamlPath.getAbsolutePath().c_str(), _S("r")); athena::io::FileReader reader(evntYamlPath.getAbsolutePath());
if (fp) if (reader.isOpen())
{ {
EVNT evnt; EVNT evnt;
evnt.fromYAMLFile(fp); evnt.fromYAMLStream(reader);
fclose(fp);
anim.m_anim->evnt = evntYamlPath; anim.m_anim->evnt = evntYamlPath;
hecl::ProjectPath evntYamlOut = cookedOut.getWithExtension(_S(".evnt")); hecl::ProjectPath evntYamlOut = cookedOut.getWithExtension(_S(".evnt"));

View File

@ -85,9 +85,8 @@ struct EVNT : BigYAML
{ {
EVNT evnt; EVNT evnt;
evnt.read(rs); evnt.read(rs);
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(outPath.getAbsolutePath());
evnt.toYAMLFile(fp); evnt.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
}; };

View File

@ -117,9 +117,8 @@ struct MLVL : BigYAML
{ {
MLVL mlvl; MLVL mlvl;
mlvl.read(rs); mlvl.read(rs);
FILE* fp = hecl::Fopen(outPath.getWithExtension(_S(".yaml"), true).getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(outPath.getWithExtension(_S(".yaml"), true).getAbsolutePath());
mlvl.toYAMLFile(fp); mlvl.toYAMLStream(writer);
fclose(fp);
hecl::BlenderConnection& conn = btok.getBlenderConnection(); hecl::BlenderConnection& conn = btok.getBlenderConnection();
return DNAMLVL::ReadMLVLToBlender(conn, mlvl, outPath, pakRouter, return DNAMLVL::ReadMLVLToBlender(conn, mlvl, outPath, pakRouter,
entry, force, fileChanged); entry, force, fileChanged);

View File

@ -341,23 +341,15 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath,
sclyData.version = 1; sclyData.version = 1;
for (const hecl::ProjectPath& layer : layerScriptPaths) for (const hecl::ProjectPath& layer : layerScriptPaths)
{ {
FILE* yamlFile = hecl::Fopen(layer.getAbsolutePath().c_str(), _S("r")); athena::io::FileReader freader(layer.getAbsolutePath());
if (!yamlFile) if (!freader.isOpen())
continue; continue;
if (!BigYAML::ValidateFromYAMLFile<DNAMP1::SCLY::ScriptLayer>(yamlFile)) if (!BigYAML::ValidateFromYAMLStream<DNAMP1::SCLY::ScriptLayer>(freader))
{
fclose(yamlFile);
continue; continue;
}
athena::io::YAMLDocReader reader; athena::io::YAMLDocReader reader;
yaml_parser_set_input_file(reader.getParser(), yamlFile); if (!reader.parse(&freader))
if (!reader.parse())
{
fclose(yamlFile);
continue; continue;
}
fclose(yamlFile);
sclyData.layers.emplace_back(); sclyData.layers.emplace_back();
sclyData.layers.back().read(reader); sclyData.layers.back().read(reader);

View File

@ -156,18 +156,16 @@ struct SCAN : BigYAML
{ {
SCAN scan; SCAN scan;
scan.read(rs); scan.read(rs);
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(outPath.getAbsolutePath());
scan.toYAMLFile(fp); scan.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
static bool Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath) static bool Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath)
{ {
SCAN scan; SCAN scan;
FILE* fp = hecl::Fopen(inPath.getAbsolutePath().c_str(), _S("rb")); athena::io::FileReader reader(inPath.getAbsolutePath());
scan.fromYAMLFile(fp); scan.fromYAMLStream(reader);
fclose(fp);
athena::io::FileWriter ws(outPath.getAbsolutePath()); athena::io::FileWriter ws(outPath.getAbsolutePath());
scan.write(ws); scan.write(ws);
return true; return true;

View File

@ -54,9 +54,8 @@ void SCLY::exportToLayerDirectories(const PAK::Entry& entry, PAKRouter<PAKBridge
hecl::ProjectPath yamlFile(layerPath, _S("objects.yaml")); hecl::ProjectPath yamlFile(layerPath, _S("objects.yaml"));
if (force || yamlFile.getPathType() == hecl::ProjectPath::Type::None) if (force || yamlFile.getPathType() == hecl::ProjectPath::Type::None)
{ {
FILE* yaml = hecl::Fopen(yamlFile.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(yamlFile.getAbsolutePath());
layers[i].toYAMLFile(yaml); layers[i].toYAMLStream(writer);
fclose(yaml);
} }
} }
} }

View File

@ -62,18 +62,16 @@ struct STRG : ISTRG
{ {
STRG strg; STRG strg;
strg.read(rs); strg.read(rs);
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(outPath.getAbsolutePath());
strg.toYAMLFile(fp); strg.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
static bool Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath) static bool Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath)
{ {
STRG strg; STRG strg;
FILE* fp = hecl::Fopen(inPath.getAbsolutePath().c_str(), _S("rb")); athena::io::FileReader reader(inPath.getAbsolutePath());
strg.fromYAMLFile(fp); strg.fromYAMLStream(reader);
fclose(fp);
athena::io::FileWriter ws(outPath.getAbsolutePath()); athena::io::FileWriter ws(outPath.getAbsolutePath());
strg.write(ws); strg.write(ws);
return true; return true;

View File

@ -240,9 +240,8 @@ struct ANCS : BigYAML
if (force || yamlType == hecl::ProjectPath::Type::None) if (force || yamlType == hecl::ProjectPath::Type::None)
{ {
FILE* fp = hecl::Fopen(yamlPath.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(yamlPath.getAbsolutePath());
ancs.toYAMLFile(fp); ancs.toYAMLStream(writer);
fclose(fp);
} }
if (force || blendType == hecl::ProjectPath::Type::None) if (force || blendType == hecl::ProjectPath::Type::None)

View File

@ -105,9 +105,8 @@ struct MLVL : BigYAML
{ {
MLVL mlvl; MLVL mlvl;
mlvl.read(rs); mlvl.read(rs);
FILE* fp = hecl::Fopen(outPath.getWithExtension(_S(".yaml"), true).getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(outPath.getWithExtension(_S(".yaml"), true).getAbsolutePath());
mlvl.toYAMLFile(fp); mlvl.toYAMLStream(writer);
fclose(fp);
hecl::BlenderConnection& conn = btok.getBlenderConnection(); hecl::BlenderConnection& conn = btok.getBlenderConnection();
return DNAMLVL::ReadMLVLToBlender(conn, mlvl, outPath, pakRouter, return DNAMLVL::ReadMLVLToBlender(conn, mlvl, outPath, pakRouter,
entry, force, fileChanged); entry, force, fileChanged);

View File

@ -68,18 +68,16 @@ struct STRG : ISTRG
{ {
STRG strg; STRG strg;
strg.read(rs); strg.read(rs);
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(outPath.getAbsolutePath());
strg.toYAMLFile(fp); strg.toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
static bool Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath) static bool Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath)
{ {
STRG strg; STRG strg;
FILE* fp = hecl::Fopen(inPath.getAbsolutePath().c_str(), _S("rb")); athena::io::FileReader reader(inPath.getAbsolutePath());
strg.fromYAMLFile(fp); strg.fromYAMLStream(reader);
fclose(fp);
athena::io::FileWriter ws(outPath.getAbsolutePath()); athena::io::FileWriter ws(outPath.getAbsolutePath());
strg.write(ws); strg.write(ws);
return true; return true;

View File

@ -329,9 +329,8 @@ struct CHAR : BigYAML
if (force || yamlType == hecl::ProjectPath::Type::None) if (force || yamlType == hecl::ProjectPath::Type::None)
{ {
FILE* fp = hecl::Fopen(yamlPath.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(yamlPath.getAbsolutePath());
aChar.toYAMLFile(fp); aChar.toYAMLStream(writer);
fclose(fp);
} }
if (force || blendType == hecl::ProjectPath::Type::None) if (force || blendType == hecl::ProjectPath::Type::None)

View File

@ -94,9 +94,8 @@ struct MLVL : BigYAML
{ {
MLVL mlvl; MLVL mlvl;
mlvl.read(rs); mlvl.read(rs);
FILE* fp = hecl::Fopen(outPath.getWithExtension(_S(".yaml"), true).getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(outPath.getWithExtension(_S(".yaml"), true).getAbsolutePath());
mlvl.toYAMLFile(fp); mlvl.toYAMLStream(writer);
fclose(fp);
hecl::BlenderConnection& conn = btok.getBlenderConnection(); hecl::BlenderConnection& conn = btok.getBlenderConnection();
return DNAMLVL::ReadMLVLToBlender(conn, mlvl, outPath, pakRouter, return DNAMLVL::ReadMLVLToBlender(conn, mlvl, outPath, pakRouter,
entry, force, fileChanged); entry, force, fileChanged);

View File

@ -67,18 +67,16 @@ struct STRG : ISTRG
static bool Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) static bool Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath)
{ {
std::unique_ptr<ISTRG> strg = LoadSTRG(rs); std::unique_ptr<ISTRG> strg = LoadSTRG(rs);
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().c_str(), _S("wb")); athena::io::FileWriter writer(outPath.getAbsolutePath());
strg->toYAMLFile(fp); strg->toYAMLStream(writer);
fclose(fp);
return true; return true;
} }
static bool Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath) static bool Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath)
{ {
STRG strg; STRG strg;
FILE* fp = hecl::Fopen(inPath.getAbsolutePath().c_str(), _S("rb")); athena::io::FileReader reader(inPath.getAbsolutePath());
strg.fromYAMLFile(fp); strg.fromYAMLStream(reader);
fclose(fp);
athena::io::FileWriter ws(outPath.getAbsolutePath()); athena::io::FileWriter ws(outPath.getAbsolutePath());
strg.write(ws); strg.write(ws);
return true; return true;

View File

@ -141,9 +141,8 @@ bool SpecBase::canCook(const hecl::ProjectPath& path, hecl::BlenderToken& btok)
} }
else if (hecl::IsPathYAML(path)) else if (hecl::IsPathYAML(path))
{ {
FILE* fp = hecl::Fopen(path.getAbsolutePath().c_str(), _S("r")); athena::io::FileReader reader(path.getAbsolutePath());
bool retval = validateYAMLDNAType(fp); bool retval = validateYAMLDNAType(reader);
fclose(fp);
return retval; return retval;
} }
return false; return false;
@ -217,9 +216,8 @@ void SpecBase::doCook(const hecl::ProjectPath& path, const hecl::ProjectPath& co
} }
else if (hecl::IsPathYAML(path)) else if (hecl::IsPathYAML(path))
{ {
FILE* fp = hecl::Fopen(path.getAbsolutePath().c_str(), _S("r")); athena::io::FileReader reader(path.getAbsolutePath());
cookYAML(cookedPath, path, fp, progress); cookYAML(cookedPath, path, reader, progress);
fclose(fp);
} }
} }

View File

@ -49,7 +49,7 @@ struct SpecBase : hecl::Database::IDataSpec
virtual bool checkPathPrefix(const hecl::ProjectPath& path)=0; virtual bool checkPathPrefix(const hecl::ProjectPath& path)=0;
/* Pre-cook handlers */ /* Pre-cook handlers */
virtual bool validateYAMLDNAType(FILE* fp) const=0; virtual bool validateYAMLDNAType(athena::io::IStreamReader& fp) const=0;
/* Cook handlers */ /* Cook handlers */
using BlendStream = hecl::BlenderConnection::DataStream; using BlendStream = hecl::BlenderConnection::DataStream;
@ -68,7 +68,7 @@ struct SpecBase : hecl::Database::IDataSpec
BlendStream& ds, bool fast, hecl::BlenderToken& btok, BlendStream& ds, bool fast, hecl::BlenderToken& btok,
FCookProgress progress)=0; FCookProgress progress)=0;
virtual void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in, virtual void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
FILE* fin, FCookProgress progress)=0; athena::io::IStreamReader& fin, FCookProgress progress)=0;
const hecl::ProjectPath& getMasterShaderPath() const {return m_masterShader;} const hecl::ProjectPath& getMasterShaderPath() const {return m_masterShader;}

View File

@ -320,10 +320,10 @@ struct SpecMP1 : SpecBase
return path.getRelativePath().compare(0, 4, _S("MP1/")) == 0; return path.getRelativePath().compare(0, 4, _S("MP1/")) == 0;
} }
bool validateYAMLDNAType(FILE* fp) const bool validateYAMLDNAType(athena::io::IStreamReader& fp) const
{ {
athena::io::YAMLDocReader reader; athena::io::YAMLDocReader reader;
yaml_parser_set_input_file(reader.getParser(), fp); yaml_parser_set_input(reader.getParser(), (yaml_read_handler_t*)athena::io::YAMLAthenaReader, &fp);
return reader.ClassTypeOperation([](const char* classType) return reader.ClassTypeOperation([](const char* classType)
{ {
if (!strcmp(classType, DNAMP1::MLVL::DNAType())) if (!strcmp(classType, DNAMP1::MLVL::DNAType()))
@ -422,11 +422,10 @@ struct SpecMP1 : SpecBase
} }
void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in, void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
FILE* fin, FCookProgress progress) athena::io::IStreamReader& fin, FCookProgress progress)
{ {
athena::io::YAMLDocReader reader; athena::io::YAMLDocReader reader;
yaml_parser_set_input_file(reader.getParser(), fin); if (reader.parse(&fin))
if (reader.parse())
{ {
std::string classStr = reader.readString("DNAType"); std::string classStr = reader.readString("DNAType");
if (classStr.empty()) if (classStr.empty())

View File

@ -285,11 +285,11 @@ struct SpecMP2 : SpecBase
return path.getRelativePath().compare(0, 4, _S("MP2/")) == 0; return path.getRelativePath().compare(0, 4, _S("MP2/")) == 0;
} }
bool validateYAMLDNAType(FILE* fp) const bool validateYAMLDNAType(athena::io::IStreamReader& fp) const
{ {
if (BigYAML::ValidateFromYAMLFile<DNAMP2::MLVL>(fp)) if (BigYAML::ValidateFromYAMLStream<DNAMP2::MLVL>(fp))
return true; return true;
if (BigYAML::ValidateFromYAMLFile<DNAMP2::STRG>(fp)) if (BigYAML::ValidateFromYAMLStream<DNAMP2::STRG>(fp))
return true; return true;
return false; return false;
} }
@ -313,7 +313,7 @@ struct SpecMP2 : SpecBase
} }
void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in, void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
FILE* fin, FCookProgress progress) athena::io::IStreamReader& fin, FCookProgress progress)
{ {
} }
}; };

View File

@ -478,13 +478,13 @@ struct SpecMP3 : SpecBase
return path.getRelativePath().compare(0, 4, _S("MP3/")) == 0; return path.getRelativePath().compare(0, 4, _S("MP3/")) == 0;
} }
bool validateYAMLDNAType(FILE* fp) const bool validateYAMLDNAType(athena::io::IStreamReader& fp) const
{ {
if (BigYAML::ValidateFromYAMLFile<DNAMP3::MLVL>(fp)) if (BigYAML::ValidateFromYAMLStream<DNAMP3::MLVL>(fp))
return true; return true;
if (BigYAML::ValidateFromYAMLFile<DNAMP3::STRG>(fp)) if (BigYAML::ValidateFromYAMLStream<DNAMP3::STRG>(fp))
return true; return true;
if (BigYAML::ValidateFromYAMLFile<DNAMP2::STRG>(fp)) if (BigYAML::ValidateFromYAMLStream<DNAMP2::STRG>(fp))
return true; return true;
return false; return false;
} }
@ -508,7 +508,7 @@ struct SpecMP3 : SpecBase
} }
void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in, void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in,
FILE* fin, FCookProgress progress) athena::io::IStreamReader& fin, FCookProgress progress)
{ {
} }
}; };

View File

@ -96,34 +96,30 @@ bool ProjectManager::openProject(const hecl::SystemString& path)
} }
hecl::ProjectPath urdeSpacesPath(*m_proj, _S(".hecl/urde_spaces.yaml")); hecl::ProjectPath urdeSpacesPath(*m_proj, _S(".hecl/urde_spaces.yaml"));
FILE* fp = hecl::Fopen(urdeSpacesPath.getAbsolutePath().c_str(), _S("r")); athena::io::FileReader reader(urdeSpacesPath.getAbsolutePath());
bool needsSave = false; bool needsSave = false;
athena::io::YAMLDocReader r; athena::io::YAMLDocReader r;
if (!fp) if (!reader.isOpen())
{ {
needsSave = true; needsSave = true;
goto makeProj; goto makeProj;
} }
yaml_parser_set_input_file(r.getParser(), fp); yaml_parser_set_input(r.getParser(), (yaml_read_handler_t*)athena::io::YAMLAthenaReader, &reader);
if (!r.ValidateClassType("UrdeSpacesState")) if (!r.ValidateClassType("UrdeSpacesState"))
{ {
needsSave = true; needsSave = true;
fclose(fp);
goto makeProj; goto makeProj;
} }
r.reset(); r.reset();
fseek(fp, 0, SEEK_SET); reader.seek(0, athena::Begin);
yaml_parser_set_input_file(r.getParser(), fp); if (!r.parse(&reader))
if (!r.parse())
{ {
needsSave = true; needsSave = true;
fclose(fp);
goto makeProj; goto makeProj;
} }
fclose(fp);
makeProj: makeProj:
m_vm.ProjectChanged(*m_proj); m_vm.ProjectChanged(*m_proj);
@ -163,19 +159,14 @@ bool ProjectManager::saveProject()
return false; return false;
hecl::ProjectPath oldSpacesPath(*m_proj, _S(".hecl/~urde_spaces.yaml")); hecl::ProjectPath oldSpacesPath(*m_proj, _S(".hecl/~urde_spaces.yaml"));
FILE* fp = hecl::Fopen(oldSpacesPath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter writer(oldSpacesPath.getAbsolutePath());
if (!fp) if (!writer.isOpen())
return false; return false;
athena::io::YAMLDocWriter w("UrdeSpacesState"); athena::io::YAMLDocWriter w("UrdeSpacesState");
yaml_emitter_set_output_file(w.getEmitter(), fp);
m_vm.SaveEditorView(w); m_vm.SaveEditorView(w);
if (!w.finish()) if (!w.finish(&writer))
{
fclose(fp);
return false; return false;
}
fclose(fp);
hecl::ProjectPath newSpacesPath(*m_proj, _S(".hecl/urde_spaces.yaml")); hecl::ProjectPath newSpacesPath(*m_proj, _S(".hecl/urde_spaces.yaml"));

View File

@ -16,14 +16,12 @@ void ProjectResourceFactoryBase::Clear()
void ProjectResourceFactoryBase::ReadCatalog(const hecl::ProjectPath& catalogPath, void ProjectResourceFactoryBase::ReadCatalog(const hecl::ProjectPath& catalogPath,
athena::io::YAMLDocWriter& nameWriter) athena::io::YAMLDocWriter& nameWriter)
{ {
FILE* fp = hecl::Fopen(catalogPath.getAbsolutePath().c_str(), _S("r")); athena::io::FileReader freader(catalogPath.getAbsolutePath());
if (!fp) if (!freader.isOpen())
return; return;
athena::io::YAMLDocReader reader; athena::io::YAMLDocReader reader;
yaml_parser_set_input_file(reader.getParser(), fp); bool res = reader.parse(&freader);
bool res = reader.parse();
fclose(fp);
if (!res) if (!res)
return; return;
@ -208,13 +206,12 @@ void ProjectResourceFactoryBase::BackgroundIndexProc()
/* Read in tag cache */ /* Read in tag cache */
if (tagCachePath.getPathType() == hecl::ProjectPath::Type::File) if (tagCachePath.getPathType() == hecl::ProjectPath::Type::File)
{ {
FILE* cacheFile = hecl::Fopen(tagCachePath.getAbsolutePath().c_str(), _S("r")); athena::io::FileReader reader(tagCachePath.getAbsolutePath());
if (cacheFile) if (reader.isOpen())
{ {
Log.report(logvisor::Info, _S("Cache index of '%s' loading"), m_origSpec->m_name); Log.report(logvisor::Info, _S("Cache index of '%s' loading"), m_origSpec->m_name);
athena::io::YAMLDocReader cacheReader; athena::io::YAMLDocReader cacheReader;
yaml_parser_set_input_file(cacheReader.getParser(), cacheFile); if (cacheReader.parse(&reader))
if (cacheReader.parse())
{ {
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex); std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
m_tagToPath.reserve(cacheReader.getRootNode()->m_mapChildren.size()); m_tagToPath.reserve(cacheReader.getRootNode()->m_mapChildren.size());
@ -231,7 +228,6 @@ void ProjectResourceFactoryBase::BackgroundIndexProc()
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
fclose(cacheFile);
Log.report(logvisor::Info, _S("Cache index of '%s' loaded; %d tags"), Log.report(logvisor::Info, _S("Cache index of '%s' loaded; %d tags"),
m_origSpec->m_name, m_tagToPath.size()); m_origSpec->m_name, m_tagToPath.size());
@ -239,10 +235,9 @@ void ProjectResourceFactoryBase::BackgroundIndexProc()
{ {
/* Read in name cache */ /* Read in name cache */
Log.report(logvisor::Info, _S("Name index of '%s' loading"), m_origSpec->m_name); Log.report(logvisor::Info, _S("Name index of '%s' loading"), m_origSpec->m_name);
FILE* nameFile = hecl::Fopen(nameCachePath.getAbsolutePath().c_str(), _S("r")); athena::io::FileReader nreader(nameCachePath.getAbsolutePath());
athena::io::YAMLDocReader nameReader; athena::io::YAMLDocReader nameReader;
yaml_parser_set_input_file(nameReader.getParser(), nameFile); if (nameReader.parse(&nreader))
if (nameReader.parse())
{ {
std::unique_lock<std::mutex> lk(m_backgroundIndexMutex); std::unique_lock<std::mutex> lk(m_backgroundIndexMutex);
m_catalogNameToTag.reserve(nameReader.getRootNode()->m_mapChildren.size()); m_catalogNameToTag.reserve(nameReader.getRootNode()->m_mapChildren.size());
@ -254,7 +249,6 @@ void ProjectResourceFactoryBase::BackgroundIndexProc()
m_catalogNameToTag[child.first] = search->first; m_catalogNameToTag[child.first] = search->first;
} }
} }
fclose(nameFile);
Log.report(logvisor::Info, _S("Name index of '%s' loaded; %d names"), Log.report(logvisor::Info, _S("Name index of '%s' loaded; %d names"),
m_origSpec->m_name, m_catalogNameToTag.size()); m_origSpec->m_name, m_catalogNameToTag.size());
} }
@ -264,10 +258,8 @@ void ProjectResourceFactoryBase::BackgroundIndexProc()
Log.report(logvisor::Info, _S("Name index of '%s' started"), m_origSpec->m_name); Log.report(logvisor::Info, _S("Name index of '%s' started"), m_origSpec->m_name);
athena::io::YAMLDocWriter nameWriter(nullptr); athena::io::YAMLDocWriter nameWriter(nullptr);
BackgroundIndexRecursiveCatalogs(specRoot, nameWriter, 0); BackgroundIndexRecursiveCatalogs(specRoot, nameWriter, 0);
FILE* nameFile = hecl::Fopen(nameCachePath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter nwriter(nameCachePath.getAbsolutePath());
yaml_emitter_set_output_file(nameWriter.getEmitter(), nameFile); nameWriter.finish(&nwriter);
nameWriter.finish();
fclose(nameFile);
Log.report(logvisor::Info, _S("Name index of '%s' complete; %d names"), Log.report(logvisor::Info, _S("Name index of '%s' complete; %d names"),
m_origSpec->m_name, m_catalogNameToTag.size()); m_origSpec->m_name, m_catalogNameToTag.size());
} }
@ -282,15 +274,11 @@ void ProjectResourceFactoryBase::BackgroundIndexProc()
BackgroundIndexRecursiveProc(specRoot, cacheWriter, nameWriter, 0); BackgroundIndexRecursiveProc(specRoot, cacheWriter, nameWriter, 0);
tagCachePath.makeDirChain(false); tagCachePath.makeDirChain(false);
FILE* cacheFile = hecl::Fopen(tagCachePath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter twriter(tagCachePath.getAbsolutePath());
yaml_emitter_set_output_file(cacheWriter.getEmitter(), cacheFile); cacheWriter.finish(&twriter);
cacheWriter.finish();
fclose(cacheFile);
FILE* nameFile = hecl::Fopen(nameCachePath.getAbsolutePath().c_str(), _S("w")); athena::io::FileWriter nwriter(nameCachePath.getAbsolutePath());
yaml_emitter_set_output_file(nameWriter.getEmitter(), nameFile); nameWriter.finish(&nwriter);
nameWriter.finish();
fclose(nameFile);
m_backgroundBlender.shutdown(); m_backgroundBlender.shutdown();
Log.report(logvisor::Info, _S("Background index of '%s' complete; %d tags, %d names"), Log.report(logvisor::Info, _S("Background index of '%s' complete; %d tags, %d names"),

View File

@ -32,7 +32,7 @@ void ViewManager::BuildTestPART(urde::IObjectStore& objStore)
SObjectTag samusCharSet = m_projManager.TagFromPath(_S("MP1/Shared/ANCS_77289A4A.blend")); SObjectTag samusCharSet = m_projManager.TagFromPath(_S("MP1/Shared/ANCS_77289A4A.blend"));
SObjectTag platModel = m_projManager.TagFromPath(_S("MP1/Shared/CMDL_6FA561D0.blend")); SObjectTag platModel = m_projManager.TagFromPath(_S("MP1/Shared/CMDL_6FA561D0.blend"));
SObjectTag bgModel = m_projManager.TagFromPath(_S("MP1/Shared/CMDL_BC34D54C.blend")); SObjectTag bgModel = m_projManager.TagFromPath(_S("MP1/Shared/CMDL_BC34D54C.blend"));
CAnimRes samusAnimRes(samusCharSet.id, -1, zeus::CVector3f::skOne, -1, true); CAnimRes samusAnimRes(samusCharSet.id, 2, zeus::CVector3f::skOne, 0, true);
g_GameState->GetWorldTransitionManager()->EnableTransition(samusAnimRes, g_GameState->GetWorldTransitionManager()->EnableTransition(samusAnimRes,
platModel.id, zeus::CVector3f::skOne, platModel.id, zeus::CVector3f::skOne,
bgModel.id, zeus::CVector3f::skOne, false); bgModel.id, zeus::CVector3f::skOne, false);

2
hecl

@ -1 +1 @@
Subproject commit 3bc81a3fe2711d9d7817e6f24afe7e29ca5e99d3 Subproject commit 9b9dae61566460086a51ccf371fc1bdf682ee5cb

@ -1 +1 @@
Subproject commit 5e695dab622d5095120224297b3c2fea4b3b85ca Subproject commit 4c675e2e0512c911b76da84b0073396392c7f3a3