diff options
-rw-r--r-- | assets/Ires/M_BasicWall.json | 4 | ||||
-rw-r--r-- | assets/Ires/M_DebugWireframe.json | 4 | ||||
-rw-r--r-- | assets/Ires/M_Default.json | 4 | ||||
-rw-r--r-- | assets/Ires/M_Player.json | 4 | ||||
-rw-r--r-- | assets/Ires/SS_Player.json | 10 | ||||
-rw-r--r-- | assets/Ires/S_Default.json | 67 | ||||
-rw-r--r-- | assets/Ires/S_SimpleLine.json | 30 | ||||
-rw-r--r-- | source/10-common/Uid.cpp | 28 | ||||
-rw-r--r-- | source/10-common/Uid.hpp | 4 | ||||
-rw-r--r-- | source/30-game/EditorCorePrivate.cpp | 11 | ||||
-rw-r--r-- | source/30-game/Ires.cpp | 12 | ||||
-rw-r--r-- | source/30-game/Ires.hpp | 2 | ||||
-rw-r--r-- | source/30-game/main.cpp | 86 |
13 files changed, 143 insertions, 123 deletions
diff --git a/assets/Ires/M_BasicWall.json b/assets/Ires/M_BasicWall.json index a0e2395..a48e6a5 100644 --- a/assets/Ires/M_BasicWall.json +++ b/assets/Ires/M_BasicWall.json @@ -1,8 +1,8 @@ { "Type": "IresMaterial", - "Uid": [2568492772925683063, 3783268081215530432], + "Uid": "23a51e918a64b577-3480de4676ece5c0", "Value": { - "Shader": [10239352483866045204, 2308094336962663863], + "Shader": "8e197cd56ad96b14-2007ff9216c015b7", "Fields": [{ "Name": "taint", "Type": "Vector", diff --git a/assets/Ires/M_DebugWireframe.json b/assets/Ires/M_DebugWireframe.json index c610011..8caf5ed 100644 --- a/assets/Ires/M_DebugWireframe.json +++ b/assets/Ires/M_DebugWireframe.json @@ -1,8 +1,8 @@ { "Type": "IresMaterial", - "Uid": [8765761170342665863, 6245907801943875283], + "Uid": "79a63d57682fde87-56adec0dbab49ed3", "Value": { - "Shader": [677745099593877908, 15625205469120742998], + "Shader": "0967d593c58e0994-d8d7e196996ec656", "Fields": [] } }
\ No newline at end of file diff --git a/assets/Ires/M_Default.json b/assets/Ires/M_Default.json index 0422e94..fcc9fe0 100644 --- a/assets/Ires/M_Default.json +++ b/assets/Ires/M_Default.json @@ -1,8 +1,8 @@ { "Type": "IresMaterial", - "Uid": [1173927873865027620, 6990602806197486151], + "Uid": "104aa12e79a79024-61039c36e5400247", "Value": { - "Shader": [10239352483866045204, 2308094336962663863], + "Shader": "8e197cd56ad96b14-2007ff9216c015b7", "Fields": [{ "Name": "taint", "Type": "Vector", diff --git a/assets/Ires/M_Player.json b/assets/Ires/M_Player.json index b2494dc..e9b9de9 100644 --- a/assets/Ires/M_Player.json +++ b/assets/Ires/M_Player.json @@ -1,8 +1,8 @@ { "Type": "IresMaterial", - "Uid": [8784140338803637141, 14601353797962284625], + "Uid": "79e789190791fb95-caa26deaff57be51", "Value": { - "Shader": [10239352483866045204, 2308094336962663863], + "Shader": "8e197cd56ad96b14-2007ff9216c015b7", "Fields": [{ "Name": "taint", "Type": "Vector", diff --git a/assets/Ires/SS_Player.json b/assets/Ires/SS_Player.json index b413317..c2920ed 100644 --- a/assets/Ires/SS_Player.json +++ b/assets/Ires/SS_Player.json @@ -1 +1,9 @@ -{"Type":"IresSpritesheet","Uid":[15827420425478528881,8130926596581515031],"Value":{"SpriteSheet":"S_Player.png","WSplit":6,"HSplit":4}}
\ No newline at end of file +{ + "Type": "IresSpritesheet", + "Uid": "dba64b050b68df71-70d6daa8fc045f17", + "Value": { + "SpriteSheet": "S_Player.png", + "WSplit": 6, + "HSplit": 4 + } +}
\ No newline at end of file diff --git a/assets/Ires/S_Default.json b/assets/Ires/S_Default.json index 0bfcb1b..442603b 100644 --- a/assets/Ires/S_Default.json +++ b/assets/Ires/S_Default.json @@ -1,70 +1,41 @@ { "Type": "IresShader", - "Uid": [10239352483866045204, 2308094336962663863], + "Uid": "8e197cd56ad96b14-2007ff9216c015b7", "Value": { "SourceFile": ".stationary/Shaders/Default.glsl", - "Inputs": [ - { - "Semantic": "VES_Position", + "Inputs": [{ "Name": "pos", + "Semantic": "VES_Position", + "OpenGLLocation": 0, "ScalarType": "float", "Width": 1, "Height": 3, - "OpenGLLocation": 0 - }, - { - "Semantic": "VES_TexCoords1", + "ArrayLength": 1 + }, { "Name": "texcoord", + "Semantic": "VES_TexCoords1", + "OpenGLLocation": 1, "ScalarType": "float", "Width": 1, "Height": 2, - "OpenGLLocation": 1 - }, - { - "Semantic": "VES_Color1", + "ArrayLength": 1 + }, { "Name": "color", + "Semantic": "VES_Color1", + "OpenGLLocation": 2, "ScalarType": "float", "Width": 1, "Height": 4, - "OpenGLLocation": 2 - } - ], - "Outputs": [ - { + "ArrayLength": 1 + }], + "Outputs": [{ "Name": "fragColor", + "Semantic": "VES_Generic", + "OpenGLLocation": 0, "ScalarType": "float", "Width": 1, "Height": 4, - "OpenGLLocation": 0 - } - ], - "Uniforms": [ - { - "Type": "Math", - "AutoFill": true, - "Value": { - "Name": "transformation", - "ScalarType": "float", - "Width": 4, - "Height": 4 - } - }, - { - "Type": "Math", - "Value": { - "Name": "taint", - "Semantic": "VES_Color1", - "ScalarType": "float", - "Width": 1, - "Height": 4 - } - }, - { - "Type": "Sampler", - "Value": { - "Name": "textureAtlas" - } - } - ] + "ArrayLength": 1 + }] } }
\ No newline at end of file diff --git a/assets/Ires/S_SimpleLine.json b/assets/Ires/S_SimpleLine.json index c20538d..b2dc464 100644 --- a/assets/Ires/S_SimpleLine.json +++ b/assets/Ires/S_SimpleLine.json @@ -1,41 +1,25 @@ { "Type": "IresShader", - "Uid": [677745099593877908, 15625205469120742998], + "Uid": "0967d593c58e0994-d8d7e196996ec656", "Value": { "SourceFile": ".stationary/Shaders/SimpleLine.glsl", - "Inputs": [ - { + "Inputs": [{ "Name": "pos", - "Semantic": "Position", + "Semantic": "VES_Generic", "OpenGLLocation": 0, "ScalarType": "float", "Width": 1, "Height": 3, "ArrayLength": 1 - } - ], - "Outputs": [ - { + }], + "Outputs": [{ "Name": "fragColor", - "Semantic": "Generic", + "Semantic": "VES_Generic", "OpenGLLocation": 0, "ScalarType": "float", "Width": 1, "Height": 4, "ArrayLength": 1 - } - ], - "Uniforms": [ - { - "Type": "Math", - "AutoFill": true, - "Value": { - "Name": "transformation", - "ScalarType": "float", - "Width": 4, - "Height": 4 - } - } - ] + }] } }
\ No newline at end of file diff --git a/source/10-common/Uid.cpp b/source/10-common/Uid.cpp index 7f8fd9d..58dfffd 100644 --- a/source/10-common/Uid.cpp +++ b/source/10-common/Uid.cpp @@ -34,21 +34,33 @@ std::string Uid::WriteString() { } void Uid::Read(const rapidjson::Value& value) { - assert(value.IsArray()); - assert(value.Size() == 2); - auto& upper = value[0]; - assert(upper.IsUint64()); - auto& lower = value[1]; - assert(lower.IsUint64()); + if (value.IsString()) { + ReadString(rapidjson::AsStringView(value)); + } else if (value.IsArray()) { + // Compatibility support + assert(value.Size() == 2); + auto& upper = value[0]; + assert(upper.IsUint64()); + auto& lower = value[1]; + assert(lower.IsUint64()); - this->upper = upper.GetUint64(); - this->lower = lower.GetUint64(); + this->upper = upper.GetUint64(); + this->lower = lower.GetUint64(); + } else { + assert(false); + } } void Uid::WriteInto(rapidjson::Value& value, rapidjson::Document& root) const { +#if BRUSSEL_Uid_WRITE_USE_ARRAY value.Reserve(2, root.GetAllocator()); value.PushBack((uint64_t)upper, root.GetAllocator()); value.PushBack((uint64_t)lower, root.GetAllocator()); +#else + char buf[256]; + int len = snprintf(buf, sizeof(buf), BRUSSEL_Uid_FORMAT_STR, upper, lower); + value.SetString(buf, len, root.GetAllocator()); +#endif } rapidjson::Value Uid::Write(rapidjson::Document& root) const { diff --git a/source/10-common/Uid.hpp b/source/10-common/Uid.hpp index 539de03..a691911 100644 --- a/source/10-common/Uid.hpp +++ b/source/10-common/Uid.hpp @@ -13,10 +13,14 @@ #define BRUSSEL_Uid_FORMAT_STR "%016" PRIx64 "-%016" PRIx64 #define BRUSSEL_Uid_FORMAT_EXPAND(uid) (uid).upper, (uid).lower +// Serialize Uid object as an array with two elements, instead of the simple string format +#define BRUSSEL_Uid_WRITE_USE_ARRAY 0 + struct Uid { uint64_t upper = 0; uint64_t lower = 0; + // Generate a random Uid static Uid Create(); bool IsNull() const; diff --git a/source/30-game/EditorCorePrivate.cpp b/source/30-game/EditorCorePrivate.cpp index e52c795..3efa33c 100644 --- a/source/30-game/EditorCorePrivate.cpp +++ b/source/30-game/EditorCorePrivate.cpp @@ -212,6 +212,17 @@ void EditorContentBrowser::Show(bool* open) { ImGui::EndPopup(); } + ImGui::SameLine(); + if (ImGui::Button("...")) { + ImGui::OpenPopup("More Actions"); + } + if (ImGui::BeginPopup("More Actions")) { + if (ImGui::MenuItem("Rewrite all Ires to disk")) { + IresManager::instance->OverwriteAllToDisk(); + } + ImGui::EndPopup(); + } + auto& objects = IresManager::instance->GetObjects(); for (auto it = objects.begin(); it != objects.end(); ++it) { auto ires = it->second.Get(); diff --git a/source/30-game/Ires.cpp b/source/30-game/Ires.cpp index bfa4cdf..4f8da85 100644 --- a/source/30-game/Ires.cpp +++ b/source/30-game/Ires.cpp @@ -393,10 +393,20 @@ void IresManager::Save(IresObject* ires, const fs::path& filePath) { char writerBuffer[65536]; rapidjson::FileWriteStream stream(file, writerBuffer, sizeof(writerBuffer)); rapidjson::PrettyWriter<rapidjson::FileWriteStream> writer(stream); - writer.SetFormatOptions(rapidjson::PrettyFormatOptions::kFormatSingleLineArray); + // We no longer need this after disabling BRUSSEL_Uid_WRITE_USE_ARRAY +// writer.SetFormatOptions(rapidjson::PrettyFormatOptions::kFormatSingleLineArray); +#if BRUSSEL_Uid_WRITE_USE_ARRAY +# warning "Writing Uid in array format but single line formatting isn't enabled, this might cause excessively long ires files." +#endif root.Accept(writer); } +void IresManager::OverwriteAllToDisk() { + for (const auto& [DISCARD, ires] : mObjByUid) { + Save(ires.Get()); + } +} + IresObject* IresManager::FindIres(const Uid& uid) const { auto iter = mObjByUid.find(uid); if (iter != mObjByUid.end()) { diff --git a/source/30-game/Ires.hpp b/source/30-game/Ires.hpp index 22018cd..e2e79bd 100644 --- a/source/30-game/Ires.hpp +++ b/source/30-game/Ires.hpp @@ -121,6 +121,8 @@ public: void Save(IresObject* ires); void Save(IresObject* ires, const std::filesystem::path& filePath); + void OverwriteAllToDisk(); + const auto& GetObjects() const { return mObjByUid; } virtual IresObject* FindIres(const Uid& uid) const override; }; diff --git a/source/30-game/main.cpp b/source/30-game/main.cpp index 55d2586..77c4674 100644 --- a/source/30-game/main.cpp +++ b/source/30-game/main.cpp @@ -98,6 +98,7 @@ void GlfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int } } +// For platform data path selection below // https://stackoverflow.com/questions/54499256/how-to-find-the-saved-games-folder-programmatically-in-c-c #if defined(_WIN32) # if defined(__MINGW32__) @@ -173,46 +174,53 @@ int main(int argc, char* argv[]) { AppConfig::assetDir = std::move(assetDir); AppConfig::assetDirPath = std::move(assetDirPath); } else { -#if defined(_WIN32) - fs::path dataDir; + AppConfig::assetDir = "."; + AppConfig::assetDirPath = fs::path("."); + } + + if (args.count(kGameDataDir) > 0) { + auto dataDir = args[kGameDataDir].as<std::string>(); + + fs::path dataDirPath(dataDir); + fs::create_directories(dataDir); + + AppConfig::dataDir = std::move(dataDir); + AppConfig::dataDirPath = std::move(dataDirPath); + } else { +#if BRUSSEL_DEV_ENV + AppConfig::dataDir = "."; + AppConfig::dataDirPath = fs::path("."); +#else +// In a regular build, use default platform data paths +# if defined(_WIN32) + fs::path dataDirPath; PWSTR path = nullptr; HRESULT hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE, nullptr, &path); if (SUCCEEDED(hr)) { - dataDir = fs::path(path) / AppConfig::kAppName; + dataDirPath = fs::path(path) / AppConfig::kAppName; CoTaskMemFree(path); - fs::create_directories(dataDir); + fs::create_directories(dataDirPath); } else { std::string msg; msg += "Failed to find/create the default user data directory at %APPDATA%. Error code: "; msg += hr; throw std::runtime_error(msg); } -#elif defined(__APPLE__) +# elif defined(__APPLE__) // MacOS programming guide recommends apps to hardcode the path - user customization of "where data are stored" is done in Finder - auto dataDir = fs::path("~/Library/Application Support/") / AppConfig::kAppName; - fs::create_directories(dataDir); -#elif defined(__linux__) - auto dataDir = GetEnvVar("XDG_DATA_HOME", "~/.local/share") / AppConfig::kAppName; - fs::create_directories(dataDir); + auto dataDirPath = fs::path("~/Library/Application Support/") / AppConfig::kAppName; + fs::create_directories(dataDirPath); +# elif defined(__linux__) + auto dataDirPath = GetEnvVar("XDG_DATA_HOME", "~/.local/share") / AppConfig::kAppName; + fs::create_directories(dataDirPath); +# endif + AppConfig::dataDir = dataDirPath.string(); + AppConfig::dataDirPath = dataDirPath; #endif } - if (args.count(kGameDataDir) > 0) { - auto dataDir = args[kGameDataDir].as<std::string>(); - - fs::path dataDirPath(dataDir); - fs::create_directories(dataDir); - - AppConfig::dataDir = std::move(dataDir); - AppConfig::dataDirPath = std::move(dataDirPath); - } else { - // TODO platform default path - AppConfig::dataDir = "."; - AppConfig::dataDirPath = fs::path("."); - } - if (!glfwInit()) { return -1; } @@ -237,7 +245,7 @@ int main(int argc, char* argv[]) { GlfwUserData glfwUserData; - GLFWwindow* window = glfwCreateWindow(1280, 720, "Project Brussel", nullptr, nullptr); + GLFWwindow* window = glfwCreateWindow(1280, 720, AppConfig::kAppNameC, nullptr, nullptr); if (window == nullptr) { return -2; } @@ -264,17 +272,15 @@ int main(int argc, char* argv[]) { } #if defined(BRUSSEL_DEV_ENV) - { - auto glVersionString = glGetString(GL_VERSION); + auto glVersionString = glGetString(GL_VERSION); - int glMajorVersion; - glGetIntegerv(GL_MAJOR_VERSION, &glMajorVersion); - int glMinorVersion; - glGetIntegerv(GL_MINOR_VERSION, &glMinorVersion); + int glMajorVersion; + glGetIntegerv(GL_MAJOR_VERSION, &glMajorVersion); + int glMinorVersion; + glGetIntegerv(GL_MINOR_VERSION, &glMinorVersion); - printf("OpenGL version (via glGetString(GL_VERSION)): %s\n", glVersionString); - printf("OpenGL version (via glGetIntegerv() with GL_MAJOR_VERSION and GL_MINOR_VERSION): %d.%d\n", glMajorVersion, glMinorVersion); - } + printf("OpenGL version (via glGetString(GL_VERSION)): %s\n", glVersionString); + printf("OpenGL version (via glGetIntegerv() with GL_MAJOR_VERSION and GL_MINOR_VERSION): %d.%d\n", glMajorVersion, glMinorVersion); #endif bool useOpenGLDebug = args[kOpenGLDebug].as<bool>(); @@ -351,6 +357,18 @@ int main(int argc, char* argv[]) { .semantic = VES_Color1, }); + gVformatLines.Attach(new VertexFormat()); + gVformatLines->AddElement(VertexElementFormat{ + .bindingIndex = 0, + .type = VET_Float3, + .semantic = VES_Position, + }); + gVformatLines->AddElement(VertexElementFormat{ + .bindingIndex = 0, + .type = VET_Ubyte4Norm, + .semantic = VES_Color1, + }); + // Matches gVformatStandard gDefaultShader.Attach(new Shader()); gDefaultShader->InitFromSources(Shader::ShaderSources{ |