From ff94c74142a8d5e10586145b3cc82af2fca62e43 Mon Sep 17 00:00:00 2001 From: Mattia Basaglia Date: Mon, 20 Jul 2015 23:15:28 +0200 Subject: [PATCH] Replace custom Array with std::vector - friendly version --- libs/container/array.h | 9 +++++++++ libs/memory/allocator.h | 9 +++++++++ radiant/patch.cpp | 12 ++++++------ radiant/patch.h | 14 +++++++------- radiant/renderstate.cpp | 2 +- radiant/selection.cpp | 2 +- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/libs/container/array.h b/libs/container/array.h index c359df15..57d2f6b0 100644 --- a/libs/container/array.h +++ b/libs/container/array.h @@ -22,6 +22,14 @@ #if !defined( INCLUDED_CONTAINER_ARRAY_H ) #define INCLUDED_CONTAINER_ARRAY_H +#include +/// \todo remove the custom allocator +#include "memory/allocator.h" +template > +using Array = std::vector; +/// \todo replace Array with std::string + +#if 0 #include #include @@ -166,5 +174,6 @@ inline void swap( Array& self, Array& ot self.swap( other ); } } +#endif #endif diff --git a/libs/memory/allocator.h b/libs/memory/allocator.h index bef7d7cb..67961206 100644 --- a/libs/memory/allocator.h +++ b/libs/memory/allocator.h @@ -93,6 +93,15 @@ inline bool operator==( const DefaultAllocator&, const OtherAllocator& ){ return false; } +template +inline bool operator!=( const DefaultAllocator&, const DefaultAllocator& ){ + return false; +} +template +inline bool operator!=( const DefaultAllocator&, const OtherAllocator& ){ + return true; +} + #endif diff --git a/radiant/patch.cpp b/radiant/patch.cpp index dca55b79..98425be8 100644 --- a/radiant/patch.cpp +++ b/radiant/patch.cpp @@ -215,13 +215,13 @@ bool Patch::isValid() const { return false; } - for ( const_iterator i = m_ctrl.begin(); i != m_ctrl.end(); ++i ) + for ( const auto& i : m_ctrl ) { - if ( !float_valid( ( *i ).m_vertex.x() ) - || !float_valid( ( *i ).m_vertex.y() ) - || !float_valid( ( *i ).m_vertex.z() ) - || !float_valid( ( *i ).m_texcoord.x() ) - || !float_valid( ( *i ).m_texcoord.y() ) ) { + if ( !float_valid( i.m_vertex.x() ) + || !float_valid( i.m_vertex.y() ) + || !float_valid( i.m_vertex.z() ) + || !float_valid( i.m_texcoord.x() ) + || !float_valid( i.m_texcoord.y() ) ) { globalErrorStream() << "patch has invalid control points\n"; return false; } diff --git a/radiant/patch.h b/radiant/patch.h index cadb0e13..9e1bb16d 100644 --- a/radiant/patch.h +++ b/radiant/patch.h @@ -861,20 +861,20 @@ int getShaderFlags() const { return 0; } -typedef PatchControl* iterator; -typedef const PatchControl* const_iterator; +typedef PatchControlArray::iterator iterator; +typedef PatchControlArray::const_iterator const_iterator; iterator begin(){ - return m_ctrl.data(); + return m_ctrl.begin(); } const_iterator begin() const { - return m_ctrl.data(); + return m_ctrl.begin(); } iterator end(){ - return m_ctrl.data() + m_ctrl.size(); + return m_ctrl.end(); } const_iterator end() const { - return m_ctrl.data() + m_ctrl.size(); + return m_ctrl.end(); } PatchControlArray& getControlPoints(){ @@ -1557,7 +1557,7 @@ bool selectedVertices(){ void transformComponents( const Matrix4& matrix ){ if ( selectedVertices() ) { - PatchControlIter ctrl = m_patch.getControlPointsTransformed().begin(); + PatchControlIter ctrl = m_patch.getControlPointsTransformed().data(); for ( PatchControlInstances::iterator i = m_ctrl_instances.begin(); i != m_ctrl_instances.end(); ++i, ++ctrl ) { if ( ( *i ).m_selectable.isSelected() ) { diff --git a/radiant/renderstate.cpp b/radiant/renderstate.cpp index 11c7b64b..ede25740 100644 --- a/radiant/renderstate.cpp +++ b/radiant/renderstate.cpp @@ -132,7 +132,7 @@ void printShaderLog( GLhandleARB object ){ Array log( log_length ); glGetInfoLogARB( object, log_length, &log_length, log.data() ); - globalErrorStream() << StringRange( log.begin(), log.begin() + log_length ) << "\n"; + globalErrorStream() << StringRange( log.data(), log.data() + log_length ) << "\n"; } void createShader( GLhandleARB program, const char* filename, GLenum type ){ diff --git a/radiant/selection.cpp b/radiant/selection.cpp index 5013af7b..2e481b40 100644 --- a/radiant/selection.cpp +++ b/radiant/selection.cpp @@ -684,7 +684,7 @@ struct FlatShadedVertex }; -typedef FlatShadedVertex* FlatShadedVertexIterator; +typedef Array::iterator FlatShadedVertexIterator; void Triangles_BestPoint( const Matrix4& local2view, clipcull_t cull, FlatShadedVertexIterator first, FlatShadedVertexIterator last, SelectionIntersection& best ){ for ( FlatShadedVertexIterator x( first ), y( first + 1 ), z( first + 2 ); x != last; x += 3, y += 3, z += 3 ) { -- 2.39.2