diff options
author | rtk0c <[email protected]> | 2023-06-15 18:14:02 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2023-06-15 18:14:02 -0700 |
commit | 1717c62f258c3cad297e9d066da7cbe57f8be200 (patch) | |
tree | 5864784122bb413a79b088da0e093ec419903007 | |
parent | 434a274cc8b85cfb37309c0ac1b1470ed930d30f (diff) |
Changeset: 98 Cleanup and prepare for rewriting shader system
-rw-r--r-- | assets/Ires/M_BasicWall.json | 12 | ||||
-rw-r--r-- | assets/Ires/M_DebugWireframe.json | 8 | ||||
-rw-r--r-- | assets/Ires/M_Default.json | 12 | ||||
-rw-r--r-- | assets/Ires/M_Player.json | 12 | ||||
-rw-r--r-- | assets/Ires/S_Default.json | 41 | ||||
-rw-r--r-- | assets/Ires/S_SimpleLine.json | 22 | ||||
-rw-r--r-- | source/10-common/RapidJsonHelper.hpp | 4 | ||||
-rw-r--r-- | source/10-common/RingBuffer.hpp | 10 | ||||
-rw-r--r-- | source/20-codegen-compiler/main.cpp | 2 | ||||
-rw-r--r-- | source/30-game/Ires.cpp | 49 | ||||
-rw-r--r-- | source/30-game/main.cpp | 4 |
11 files changed, 50 insertions, 126 deletions
diff --git a/assets/Ires/M_BasicWall.json b/assets/Ires/M_BasicWall.json deleted file mode 100644 index a48e6a5..0000000 --- a/assets/Ires/M_BasicWall.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Type": "IresMaterial", - "Uid": "23a51e918a64b577-3480de4676ece5c0", - "Value": { - "Shader": "8e197cd56ad96b14-2007ff9216c015b7", - "Fields": [{ - "Name": "taint", - "Type": "Vector", - "Value": [0.03868706524372101, 0.6346951127052307, 0.7892156839370728, 0.0] - }] - } -}
\ No newline at end of file diff --git a/assets/Ires/M_DebugWireframe.json b/assets/Ires/M_DebugWireframe.json deleted file mode 100644 index 8caf5ed..0000000 --- a/assets/Ires/M_DebugWireframe.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Type": "IresMaterial", - "Uid": "79a63d57682fde87-56adec0dbab49ed3", - "Value": { - "Shader": "0967d593c58e0994-d8d7e196996ec656", - "Fields": [] - } -}
\ No newline at end of file diff --git a/assets/Ires/M_Default.json b/assets/Ires/M_Default.json deleted file mode 100644 index fcc9fe0..0000000 --- a/assets/Ires/M_Default.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Type": "IresMaterial", - "Uid": "104aa12e79a79024-61039c36e5400247", - "Value": { - "Shader": "8e197cd56ad96b14-2007ff9216c015b7", - "Fields": [{ - "Name": "taint", - "Type": "Vector", - "Value": [1.0, 1.0, 1.0, 0.0] - }] - } -}
\ No newline at end of file diff --git a/assets/Ires/M_Player.json b/assets/Ires/M_Player.json deleted file mode 100644 index e9b9de9..0000000 --- a/assets/Ires/M_Player.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Type": "IresMaterial", - "Uid": "79e789190791fb95-caa26deaff57be51", - "Value": { - "Shader": "8e197cd56ad96b14-2007ff9216c015b7", - "Fields": [{ - "Name": "taint", - "Type": "Vector", - "Value": [1.0, 1.0, 1.0, 0.0] - }] - } -}
\ No newline at end of file diff --git a/assets/Ires/S_Default.json b/assets/Ires/S_Default.json deleted file mode 100644 index 442603b..0000000 --- a/assets/Ires/S_Default.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "Type": "IresShader", - "Uid": "8e197cd56ad96b14-2007ff9216c015b7", - "Value": { - "SourceFile": ".stationary/Shaders/Default.glsl", - "Inputs": [{ - "Name": "pos", - "Semantic": "VES_Position", - "OpenGLLocation": 0, - "ScalarType": "float", - "Width": 1, - "Height": 3, - "ArrayLength": 1 - }, { - "Name": "texcoord", - "Semantic": "VES_TexCoords1", - "OpenGLLocation": 1, - "ScalarType": "float", - "Width": 1, - "Height": 2, - "ArrayLength": 1 - }, { - "Name": "color", - "Semantic": "VES_Color1", - "OpenGLLocation": 2, - "ScalarType": "float", - "Width": 1, - "Height": 4, - "ArrayLength": 1 - }], - "Outputs": [{ - "Name": "fragColor", - "Semantic": "VES_Generic", - "OpenGLLocation": 0, - "ScalarType": "float", - "Width": 1, - "Height": 4, - "ArrayLength": 1 - }] - } -}
\ No newline at end of file diff --git a/assets/Ires/S_SimpleLine.json b/assets/Ires/S_SimpleLine.json index b2dc464..5b62b0e 100644 --- a/assets/Ires/S_SimpleLine.json +++ b/assets/Ires/S_SimpleLine.json @@ -1,25 +1,9 @@ { "Type": "IresShader", - "Uid": "0967d593c58e0994-d8d7e196996ec656", + "Uid": "1d6ae0953c91b56f-333f006389f662d9", "Value": { "SourceFile": ".stationary/Shaders/SimpleLine.glsl", - "Inputs": [{ - "Name": "pos", - "Semantic": "VES_Generic", - "OpenGLLocation": 0, - "ScalarType": "float", - "Width": 1, - "Height": 3, - "ArrayLength": 1 - }], - "Outputs": [{ - "Name": "fragColor", - "Semantic": "VES_Generic", - "OpenGLLocation": 0, - "ScalarType": "float", - "Width": 1, - "Height": 4, - "ArrayLength": 1 - }] + "Inputs": [], + "Outputs": [] } }
\ No newline at end of file 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 |