aboutsummaryrefslogtreecommitdiff
path: root/source/30-game/Ires.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2023-06-15 18:14:02 -0700
committerrtk0c <[email protected]>2023-06-15 18:14:02 -0700
commit1717c62f258c3cad297e9d066da7cbe57f8be200 (patch)
tree5864784122bb413a79b088da0e093ec419903007 /source/30-game/Ires.cpp
parent434a274cc8b85cfb37309c0ac1b1470ed930d30f (diff)
Changeset: 98 Cleanup and prepare for rewriting shader system
Diffstat (limited to 'source/30-game/Ires.cpp')
-rw-r--r--source/30-game/Ires.cpp49
1 files changed, 33 insertions, 16 deletions
diff --git a/source/30-game/Ires.cpp b/source/30-game/Ires.cpp
index 4f8da85..0529395 100644
--- a/source/30-game/Ires.cpp
+++ b/source/30-game/Ires.cpp
@@ -148,17 +148,26 @@ std::unique_ptr<IresObject> IresObject::ReadFull(IresLoadingContext& ctx, const
}
std::unique_ptr<IresObject> IresObject::ReadBasic(const rapidjson::Value& value) {
- auto rvType = rapidjson::GetProperty(value, rapidjson::kStringType, "Type"sv);
- if (!rvType) return nullptr;
- auto kind = Metadata::EnumFromString<Kind>(rapidjson::AsStringView(*rvType));
- assert(kind.has_value());
- auto ires = Create(kind.value());
- if (!ires) return nullptr;
-
- auto rvUid = rapidjson::GetProperty(value, rapidjson::kArrayType, "Uid"sv);
- if (!rvUid) return nullptr;
- ires->mUid.Read(*rvUid);
+ std::unique_ptr<IresObject> ires;
+ Uid uid;
+ for (auto it = value.MemberBegin(); it != value.MemberEnd(); ++it) {
+ if (it->name == "Type"_rj_sv) {
+ if (it->value.GetType() != rapidjson::kStringType)
+ return nullptr;
+ auto kind = Metadata::EnumFromString<Kind>(rapidjson::AsStringView(it->value));
+ if (!kind.has_value())
+ return nullptr;
+ if ((ires = Create(*kind)) == nullptr)
+ return nullptr;
+ } else if (it->name == "Uid"_rj_sv) {
+ // FIXME this needs to do type checks
+ uid.Read(it->value);
+ }
+ }
+ if (ires == nullptr || uid.IsNull())
+ return nullptr;
+ ires->mUid = uid;
return ires;
}
@@ -226,7 +235,9 @@ void IresManager::DiscoverFiles(const fs::path& dir) {
fprintf(stderr, "Ires file [" PLATFORM_PATH_STR "] Failed to open file.", item.path().c_str());
continue;
}
- DEFER { fclose(file); };
+ DEFER {
+ fclose(file);
+ };
char readerBuffer[65536];
rapidjson::FileReadStream stream(file, readerBuffer, sizeof(readerBuffer));
@@ -236,7 +247,7 @@ void IresManager::DiscoverFiles(const fs::path& dir) {
auto ires = IresObject::ReadBasic(root);
if (!ires) {
- fprintf(stderr, "Ires file: [" PLATFORM_PATH_STR "] Failed to parse header.", item.path().c_str());
+ fprintf(stderr, "Ires file: [" PLATFORM_PATH_STR "] Failed to parse header.\n", item.path().c_str());
continue;
}
@@ -271,7 +282,7 @@ void IresManager::DiscoverFiles(const fs::path& dir) {
auto& ires = cand->ires;
if (!IresObject::ReadPartial(ctx, ires.Get(), cand->data)) {
- fprintf(stderr, "Ires file: [" PLATFORM_PATH_STR "] Failed to parse object data.", cand->path.c_str());
+ fprintf(stderr, "Ires file: [" PLATFORM_PATH_STR "] Failed to parse object data.\n", cand->path.c_str());
continue;
}
@@ -305,7 +316,9 @@ std::pair<IresObject*, bool> IresManager::Add(IresObject* ires) {
IresObject* IresManager::Load(const fs::path& filePath) {
auto file = Utils::OpenCstdioFile(filePath, Utils::Read);
if (!file) return nullptr;
- DEFER { fclose(file); };
+ DEFER {
+ fclose(file);
+ };
char readerBuffer[65536];
rapidjson::FileReadStream stream(file, readerBuffer, sizeof(readerBuffer));
@@ -366,7 +379,9 @@ bool IresManager::Rename(IresObject* ires, std::string newName) {
void IresManager::Reload(IresObject* ires) {
auto file = Utils::OpenCstdioFile(GetDesignatedPath(ires), Utils::Read);
if (!file) return;
- DEFER { fclose(file); };
+ DEFER {
+ fclose(file);
+ };
char readerBuffer[65536];
rapidjson::FileReadStream stream(file, readerBuffer, sizeof(readerBuffer));
@@ -388,7 +403,9 @@ void IresManager::Save(IresObject* ires, const fs::path& filePath) {
auto file = Utils::OpenCstdioFile(filePath, Utils::WriteTruncate);
if (!file) return;
- DEFER { fclose(file); };
+ DEFER {
+ fclose(file);
+ };
char writerBuffer[65536];
rapidjson::FileWriteStream stream(file, writerBuffer, sizeof(writerBuffer));