From f70af4677c4691df1d8114ad5be20a659f1ca793 Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 9 Dec 2017 16:06:43 +0800 Subject: [PATCH] Add direct conversion to map for xml nodes --- src/config/user_config.cpp | 61 ++++++++------------------------- src/graphics/command_buffer.cpp | 4 ++- src/graphics/command_buffer.hpp | 5 ++- src/graphics/draw_calls.cpp | 4 +-- src/io/xml_node.cpp | 1 - src/io/xml_node.hpp | 23 +++++++++++++ 6 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index 79511fd2a..788efc0dc 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -321,7 +321,7 @@ core::stringc ListUserConfigParam::toString() const return ""; } // toString - // ============================================================================ +// ---------------------------------------------------------------------------- template MapUserConfigParam::MapUserConfigParam(const char* param_name, const char* comment) @@ -331,7 +331,7 @@ MapUserConfigParam::MapUserConfigParam(const char* param_name, if (comment != NULL) m_comment = comment; } // MapUserConfigParam - // ============================================================================ +// ---------------------------------------------------------------------------- template MapUserConfigParam::MapUserConfigParam(const char* param_name, const char* comment, @@ -345,7 +345,7 @@ MapUserConfigParam::MapUserConfigParam(const char* param_name, // add the default list va_list arguments; va_start(arguments, nb_elements); - + struct pair_type { T key; U value; }; for (int i = 0; i < nb_elements; i++) @@ -356,7 +356,7 @@ MapUserConfigParam::MapUserConfigParam(const char* param_name, va_end(arguments); // Cleans up the list } // MapUserConfigParam - // ============================================================================ +// ---------------------------------------------------------------------------- template MapUserConfigParam::MapUserConfigParam(const char* param_name, GroupUserConfigParam* group, @@ -367,7 +367,7 @@ MapUserConfigParam::MapUserConfigParam(const char* param_name, if (comment != NULL) m_comment = comment; } // MapUserConfigParam - // ============================================================================ +// ---------------------------------------------------------------------------- template MapUserConfigParam::MapUserConfigParam(const char* param_name, GroupUserConfigParam* group, @@ -382,30 +382,25 @@ MapUserConfigParam::MapUserConfigParam(const char* param_name, // add the default list va_list arguments; va_start(arguments, nb_elements); - + struct pair_type { T key; U value; }; - for (int i = 0; i < nb_elements; i++) { + for (int i = 0; i < nb_elements; i++) + { pair_type key_value_pair = va_arg(arguments, pair_type); m_elements.insert(std::pair(key_value_pair.key, key_value_pair.value)); } va_end(arguments); // Cleans up the list } // MapUserConfigParam - // ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- template void MapUserConfigParam::write(std::ofstream& stream) const { - const int elts_amount = m_elements.size(); - // comment if (m_comment.size() > 0) stream << " \n <" << m_param_name.c_str() << "\n"; - stream << " Size=\"" << elts_amount << "\"\n"; - // actual elements - //for (int n = 0; n::write(std::ofstream& stream) const stream << " \n\n"; } // write - // ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- template void MapUserConfigParam::findYourDataInAChildOf(const XMLNode* node) @@ -425,56 +420,30 @@ void MapUserConfigParam::findYourDataInAChildOf(const XMLNode* node) //Log::error("User Config", "Couldn't find parameter group %s", m_param_name.c_str()); return; } - - int attr_count = 0; - child->get("Size", &attr_count); - - for (const auto& kv : m_elements) - { - std::pair elt; - elt.first = kv.first; - elt.second = kv.second; - - - bool there = false; - - for (const auto& kvRHS : m_elements) - { - if (elt.second == kvRHS.second) - { - there = true; - break; - } - - } - if (!there) - { - m_elements.insert(elt); - } - } + child->get(&m_elements); } // findYourDataInAChildOf - // ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- template void MapUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node) { } // findYourDataInAnAttributeOf - // ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- template void MapUserConfigParam::addElement(T element, U value) { m_elements[element] = value; } // findYourDataInAnAttributeOf - // ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- template core::stringc MapUserConfigParam::toString() const { return ""; } // toString -// ============================================================================ +// ---------------------------------------------------------------------------- IntUserConfigParam::IntUserConfigParam(int default_value, const char* param_name, const char* comment) diff --git a/src/graphics/command_buffer.cpp b/src/graphics/command_buffer.cpp index 761ae122b..d2f09a962 100644 --- a/src/graphics/command_buffer.cpp +++ b/src/graphics/command_buffer.cpp @@ -166,7 +166,9 @@ void SolidCommandBuffer::fill(MeshMap *mesh_map) fillInstanceData (mesh_map, four_tex_material_list, InstanceTypeFourTex); - + /* glBindBuffer(GL_DRAW_INDIRECT_BUFFER, m_draw_indirect_cmd_id); + glFlushMappedBufferRange(GL_DRAW_INDIRECT_BUFFER, 0,10000 * 20); + glBindBuffer(GL_DRAW_INDIRECT_BUFFER,0);*/ if (!CVS->supportsAsyncInstanceUpload()) glUnmapBuffer(GL_DRAW_INDIRECT_BUFFER); } //SolidCommandBuffer::fill diff --git a/src/graphics/command_buffer.hpp b/src/graphics/command_buffer.hpp index 35021a8f4..23349ff43 100644 --- a/src/graphics/command_buffer.hpp +++ b/src/graphics/command_buffer.hpp @@ -218,7 +218,10 @@ protected: mesh_map, instance_buffer); } - + /*glBindBuffer(GL_ARRAY_BUFFER, + VAOManager::getInstance()->getInstanceBuffer(instance_type)); + glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0,10000 * sizeof(InstanceDataThreeTex)); + glBindBuffer(GL_ARRAY_BUFFER,0);*/ if (!CVS->supportsAsyncInstanceUpload()) { glUnmapBuffer(GL_ARRAY_BUFFER); diff --git a/src/graphics/draw_calls.cpp b/src/graphics/draw_calls.cpp index 58170838d..0073fc73c 100644 --- a/src/graphics/draw_calls.cpp +++ b/src/graphics/draw_calls.cpp @@ -721,8 +721,8 @@ void DrawCalls::prepareDrawCalls( ShadowMatrices& shadow_matrices, solid_poly_count = m_solid_cmd_buffer->getPolyCount(); shadow_poly_count = m_shadow_cmd_buffer->getPolyCount(); - if (CVS->supportsAsyncInstanceUpload()) - glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT); + //if (CVS->supportsAsyncInstanceUpload()) + // glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT); #endif // !defined(USE_GLES2) } diff --git a/src/io/xml_node.cpp b/src/io/xml_node.cpp index cbc8dc21a..12d38c1e7 100644 --- a/src/io/xml_node.cpp +++ b/src/io/xml_node.cpp @@ -18,7 +18,6 @@ #include "io/file_manager.hpp" #include "io/xml_node.hpp" -#include "utils/string_utils.hpp" #include "utils/interpolation_array.hpp" #include "utils/vec3.hpp" diff --git a/src/io/xml_node.hpp b/src/io/xml_node.hpp index ed990dab4..66baea9db 100644 --- a/src/io/xml_node.hpp +++ b/src/io/xml_node.hpp @@ -33,9 +33,11 @@ using namespace irr; #include "utils/leak_check.hpp" #include "utils/no_copy.hpp" +#include "utils/string_utils.hpp" #include "utils/time.hpp" #include "utils/types.hpp" + class InterpolationArray; class Vec3; @@ -95,6 +97,27 @@ public: int getHPR(core::vector3df *value) const; int getHPR(Vec3 *value) const; + template + int get(std::map* out_map) const + { + using namespace StringUtils; + for (auto& p : m_attributes) + { + T val_1; + if (!fromString(p.first, val_1)) + { + return 0; + } + U val_2; + if (!fromString(wideToUtf8(p.second), val_2)) + { + return 0; + } + (*out_map)[val_1] = val_2; + } + return (int)m_attributes.size(); + } + bool hasChildNamed(const char* name) const; /** Handy functions to test the bit pattern returned by get(vector3df*).*/