From 445ac3cdef6d98cd9a60545a1409a4d7a47c6d9e Mon Sep 17 00:00:00 2001 From: Terri00 Date: Sun, 24 Mar 2019 00:27:52 +0000 Subject: [PATCH] VDF parsing fix for stray '{', overlapping buyzone/bombsite support --- MCDV/main.cpp | 29 ++++++++++++++++++++++++--- MCDV/shaders/ss_precomp_objectives.fs | 7 +++++-- MCDV/util.h | 11 ++++++++++ MCDV/vdf.hpp | 4 ++-- MCDV/vmf.hpp | 25 +++++++++++++++-------- 5 files changed, 61 insertions(+), 15 deletions(-) diff --git a/MCDV/main.cpp b/MCDV/main.cpp index 9749100..74e0283 100644 --- a/MCDV/main.cpp +++ b/MCDV/main.cpp @@ -51,13 +51,30 @@ void save_to_dds(int x, int y, const char* filepath) { free(data); } +/* Renders opengl in opaque mode (normal) */ +void opengl_render_opaque() { + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); +} + +/* Renders opengl in addative mode */ +void opengl_render_additive() { + glDepthMask(GL_TRUE); + glEnable(GL_BLEND); + + // I still do not fully understand OPENGL blend modes. However these equations looks nice for the grid floor. + glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); + glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ZERO, GL_ONE); +} + /* Command line variables */ #ifndef _DEBUG std::string m_mapfile_path; std::string m_game_path; #endif #ifdef _DEBUG -std::string m_mapfile_path = "sample_stuff/de_tavr_test"; +std::string m_mapfile_path = "sample_stuff/de_crimson_v16"; std::string m_game_path = "D:/SteamLibrary/steamapps/common/Counter-Strike Global Offensive/csgo"; #endif @@ -129,14 +146,14 @@ int app(int argc, const char** argv) { auto result = options.parse(argc, argv); /* Check required parameters */ - if (result.count("game")) m_game_path = result["game"].as(); + if (result.count("game")) m_game_path = sutil::ReplaceAll(result["game"].as(), "\n", ""); else throw cxxopts::option_required_exception("game"); if(result.count("mapfile")) m_mapfile_path = result["mapfile"].as(); else if (result.count("positional")) { auto& positional = result["positional"].as>(); - m_mapfile_path = positional[0]; + m_mapfile_path = sutil::ReplaceAll(positional[0], "\n", ""); } else throw cxxopts::option_required_exception("mapfile"); // We need a map file @@ -547,6 +564,9 @@ int app(int argc, const char** argv) { s_solid->mesh->Draw(); } + fb_comp_1.Bind(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + shader_unlit.setVec3("color", 1.0f, 0.0f, 0.0f); for (auto && s_solid : tavr_bombtargets) { @@ -566,6 +586,9 @@ int app(int argc, const char** argv) { fb_comp.BindRTtoTexSlot(0); shader_precomp_objectives.setInt("tex_in", 0); + fb_comp_1.BindRTtoTexSlot(1); + shader_precomp_objectives.setInt("tex_in_1", 1); + mesh_screen_quad->Draw(); if (m_outputMasks) diff --git a/MCDV/shaders/ss_precomp_objectives.fs b/MCDV/shaders/ss_precomp_objectives.fs index 7edeb08..ece1763 100644 --- a/MCDV/shaders/ss_precomp_objectives.fs +++ b/MCDV/shaders/ss_precomp_objectives.fs @@ -6,7 +6,8 @@ out vec4 FragColor; // SAMPLER UNIFORMS // Image Inputs _______________________________________________________________________________ -uniform sampler2D tex_in; // Background texture +uniform sampler2D tex_in; // Buyzones +uniform sampler2D tex_in_1; // Bombtargets // SHADER PROGRAM // ____________________________________________________________________________________________ @@ -15,5 +16,7 @@ uniform sampler2D tex_in; // Background texture void main() { vec4 sample = vec4(texture(tex_in, TexCoords)); - FragColor = vec4(sample.r, sample.g, 0, sample.r + sample.g); + vec4 sample1 = vec4(texture(tex_in_1, TexCoords)); + vec4 o = sample + sample1; + FragColor = vec4(o.r, o.g, 0, o.r + o.g); } \ No newline at end of file diff --git a/MCDV/util.h b/MCDV/util.h index 77bf955..368ac94 100644 --- a/MCDV/util.h +++ b/MCDV/util.h @@ -73,6 +73,17 @@ std::vector split(std::string s, std::string delimiter) namespace sutil { + std::string get_unquoted_material(std::string in) { + std::vector sgts = split(in, '\"'); + std::string u = ""; + int i = 0; + for (auto && s : sgts) { + if (i++ % 2 != 0) continue; + u += s; + } + return u; + } + std::string pad0(std::string in, int count) { int zerosNeeded = count - in.size(); std::string out = ""; diff --git a/MCDV/vdf.hpp b/MCDV/vdf.hpp index 1053001..a4bc875 100644 --- a/MCDV/vdf.hpp +++ b/MCDV/vdf.hpp @@ -45,13 +45,13 @@ namespace kv line = split(line, "//")[0]; - if (line.find("{") != std::string::npos) { + if (sutil::get_unquoted_material(line).find("{") != std::string::npos) { std::string pname = prev; prev.erase(std::remove(prev.begin(), prev.end(), '"'), prev.end()); this->SubBlocks.push_back(DataBlock(stream, pname, progress_callback)); continue; } - if (line.find("}") != std::string::npos) { + if (sutil::get_unquoted_material(line).find("}") != std::string::npos) { return; } diff --git a/MCDV/vmf.hpp b/MCDV/vmf.hpp index e2f3962..beba806 100644 --- a/MCDV/vmf.hpp +++ b/MCDV/vmf.hpp @@ -238,6 +238,10 @@ namespace vmf { for (int i = 0; i < SolidList.size(); i++){ std::cout << "Solid " << i + 1 << "/" << total << "\r"; + if (i >= SolidList.size() - 1) + { + std::cout << "last\n"; + } kv::DataBlock cBlock = SolidList[i]; Solid solid; @@ -308,16 +312,21 @@ namespace vmf { kv::DataBlock* editorValues = cBlock.GetFirstByName("editor"); - //Gather up the visgroups - int viscount = -1; - while (editorValues->Values.count("visgroupid" + (++viscount > 0 ? std::to_string(viscount) : ""))) - solid.visgroupids.push_back(std::stoi(editorValues->Values["visgroupid" + (viscount > 0 ? std::to_string(viscount) : "")])); + if (editorValues != NULL) { + //Gather up the visgroups + int viscount = -1; + while (editorValues->Values.count("visgroupid" + (++viscount > 0 ? std::to_string(viscount) : ""))) + solid.visgroupids.push_back(std::stoi(editorValues->Values["visgroupid" + (viscount > 0 ? std::to_string(viscount) : "")])); - glm::vec3 color; - if (vmf_parse::Vector3f(editorValues->Values["color"], &color)) - solid.color = glm::vec3(color.x / 255.0f, color.y / 255.0f, color.z / 255.0f); - else + glm::vec3 color; + if (vmf_parse::Vector3f(editorValues->Values["color"], &color)) + solid.color = glm::vec3(color.x / 255.0f, color.y / 255.0f, color.z / 255.0f); + else solid.color = glm::vec3(1, 0, 0); + } + else { + std::cout << "Editor values was null!\n"; + } this->solids.push_back(solid); } -- 2.25.1