Add direct conversion to map for xml nodes

This commit is contained in:
Benau 2017-12-09 16:06:43 +08:00
parent eea6196231
commit f70af4677c
6 changed files with 47 additions and 51 deletions

View File

@ -321,7 +321,7 @@ core::stringc ListUserConfigParam<T, U>::toString() const
return "";
} // toString
// ============================================================================
// ----------------------------------------------------------------------------
template<typename T, typename U>
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
const char* comment)
@ -331,7 +331,7 @@ MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
if (comment != NULL) m_comment = comment;
} // MapUserConfigParam
// ============================================================================
// ----------------------------------------------------------------------------
template<typename T, typename U>
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
const char* comment,
@ -345,7 +345,7 @@ MapUserConfigParam<T, U>::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<T, U>::MapUserConfigParam(const char* param_name,
va_end(arguments); // Cleans up the list
} // MapUserConfigParam
// ============================================================================
// ----------------------------------------------------------------------------
template<typename T, typename U>
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
GroupUserConfigParam* group,
@ -367,7 +367,7 @@ MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
if (comment != NULL) m_comment = comment;
} // MapUserConfigParam
// ============================================================================
// ----------------------------------------------------------------------------
template<typename T, typename U>
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
GroupUserConfigParam* group,
@ -382,30 +382,25 @@ MapUserConfigParam<T, U>::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<T, U>(key_value_pair.key, key_value_pair.value));
}
va_end(arguments); // Cleans up the list
} // MapUserConfigParam
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
template<typename T, typename U>
void MapUserConfigParam<T, U>::write(std::ofstream& stream) const
{
const int elts_amount = m_elements.size();
// comment
if (m_comment.size() > 0) stream << " <!-- " << m_comment.c_str();
stream << " -->\n <" << m_param_name.c_str() << "\n";
stream << " Size=\"" << elts_amount << "\"\n";
// actual elements
//for (int n = 0; n<elts_amount; n++)
for (const auto& kv : m_elements)
{
stream << " " << kv.first << "=\"" << kv.second << "\"\n";
@ -414,7 +409,7 @@ void MapUserConfigParam<T, U>::write(std::ofstream& stream) const
stream << " </" << m_param_name.c_str() << ">\n\n";
} // write
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
template<typename T, typename U>
void MapUserConfigParam<T, U>::findYourDataInAChildOf(const XMLNode* node)
@ -425,56 +420,30 @@ void MapUserConfigParam<T, U>::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<T,U> 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<typename T, typename U>
void MapUserConfigParam<T, U>::findYourDataInAnAttributeOf(const XMLNode* node)
{
} // findYourDataInAnAttributeOf
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
template<typename T, typename U>
void MapUserConfigParam<T, U>::addElement(T element, U value)
{
m_elements[element] = value;
} // findYourDataInAnAttributeOf
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
template<typename T, typename U>
core::stringc MapUserConfigParam<T, U>::toString() const
{
return "";
} // toString
// ============================================================================
// ----------------------------------------------------------------------------
IntUserConfigParam::IntUserConfigParam(int default_value,
const char* param_name,
const char* comment)

View File

@ -166,7 +166,9 @@ void SolidCommandBuffer::fill(MeshMap *mesh_map)
fillInstanceData<InstanceDataFourTex, MeshMap>
(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

View File

@ -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);

View File

@ -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)
}

View File

@ -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"

View File

@ -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<typename T, typename U>
int get(std::map<T, U>* 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*).*/