aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/10-common/RapidJsonHelper.hpp4
-rw-r--r--source/10-common/RingBuffer.hpp10
-rw-r--r--source/20-codegen-compiler/main.cpp2
-rw-r--r--source/30-game/Ires.cpp49
-rw-r--r--source/30-game/main.cpp4
5 files changed, 47 insertions, 22 deletions
diff --git a/source/10-common/RapidJsonHelper.hpp b/source/10-common/RapidJsonHelper.hpp
index 008c6bb..a992dbc 100644
--- a/source/10-common/RapidJsonHelper.hpp
+++ b/source/10-common/RapidJsonHelper.hpp
@@ -108,3 +108,7 @@ bool ReadVectorPrimitives(const rapidjson::Value& value, TContainer& list) {
}
} // namespace rapidjson
+
+inline rapidjson::GenericStringRef<char> operator""_rj_sv(const char* str, size_t len) {
+ return rapidjson::StringRef(str, len);
+}
diff --git a/source/10-common/RingBuffer.hpp b/source/10-common/RingBuffer.hpp
index de8227c..4eaa007 100644
--- a/source/10-common/RingBuffer.hpp
+++ b/source/10-common/RingBuffer.hpp
@@ -72,7 +72,7 @@ public:
RingBuffer() noexcept = default;
~RingBuffer() noexcept {
- delete mRing;
+ delete[] mRing;
}
RingBuffer(const RingBuffer&) noexcept = delete;
@@ -128,6 +128,7 @@ public:
[[nodiscard]] T& operator[](size_type i) { return const_cast<T&>(const_cast<const RingBuffer&>(*this)[i]); }
[[nodiscard]] const T& operator[](size_type i) const {
+ assert(mRing != nullptr);
size_type idx = mHeadIdx + i;
if (idx >= mCapacity) {
idx -= mCapacity;
@@ -136,6 +137,7 @@ public:
}
void push_back(T t) {
+ assert(mRing != nullptr);
if (mTailIdx == mCapacity) {
// Ring buffer is filled to the right, warp around to the beginning
// mHeadIdx > 0 must be true, since we checked that as condition (1) above
@@ -177,8 +179,10 @@ public:
auto oldRing = mRing;
auto newRing = mRing = new T[newCapacity];
- std::rotate_copy(oldRing, oldRing + mHeadIdx, oldRing + mCapacity, newRing);
- delete oldRing;
+ if (oldRing != nullptr) {
+ std::rotate_copy(oldRing, oldRing + mHeadIdx, oldRing + mCapacity, newRing);
+ delete[] oldRing;
+ }
mCapacity = newCapacity;
mHeadIdx = 0;
diff --git a/source/20-codegen-compiler/main.cpp b/source/20-codegen-compiler/main.cpp
index 6e4f9a0..a2e50f5 100644
--- a/source/20-codegen-compiler/main.cpp
+++ b/source/20-codegen-compiler/main.cpp
@@ -670,7 +670,7 @@ CodegenLexer LexInputFile(AppState& as, std::string_view source) {
void ParseInputFileAndGenerate(AppState& as, CodegenLexer& /*lexingState*/ ls, std::string_view filenameStem) {
#if CODEGEN_DEBUG_PRINT
printf("BEGIN tokens\n");
- for (auto& token : lexer.tokens) {
+ for (auto& token : ls.tokens) {
switch (token.type) {
case CLEX_intlit: {
printf(" token %-32s = %ld\n", FSTR_LUT_LOOKUP(ClexNames, token.type), token.lexerIntNumber);
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));
diff --git a/source/30-game/main.cpp b/source/30-game/main.cpp
index 77c4674..30ba9a6 100644
--- a/source/30-game/main.cpp
+++ b/source/30-game/main.cpp
@@ -133,8 +133,8 @@ int main(int argc, char* argv[]) {
constexpr auto kOpenGLDebug = "opengl-debug";
constexpr auto kImGuiBackend = "imgui-backend";
- constexpr auto kGameDataDir = "game-data-directory";
- constexpr auto kGameAssetDir = "game-asset-directory";
+ constexpr auto kGameDataDir = "game-data-dir";
+ constexpr auto kGameAssetDir = "game-asset-dir";
cxxopts::Options options(std::string(AppConfig::kAppName), "");
// clang-format off