]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
Replace custom Array with std::vector - friendly version
authorMattia Basaglia <mattia.basaglia@gmail.com>
Mon, 20 Jul 2015 21:15:28 +0000 (23:15 +0200)
committerMattia Basaglia <mattia.basaglia@gmail.com>
Mon, 20 Jul 2015 21:15:28 +0000 (23:15 +0200)
libs/container/array.h
libs/memory/allocator.h
radiant/patch.cpp
radiant/patch.h
radiant/renderstate.cpp
radiant/selection.cpp

index c359df15f2dea4392cf273ab1ea7dc32662e71b7..57d2f6b0b73b22a3dcf9e4bb7b24ca6e1513e5d2 100644 (file)
 #if !defined( INCLUDED_CONTAINER_ARRAY_H )
 #define INCLUDED_CONTAINER_ARRAY_H
 
+#include <vector>
+/// \todo remove the custom allocator
+#include "memory/allocator.h"
+template<typename Element, typename Allocator = DefaultAllocator<Element> >
+using Array = std::vector<Element, Allocator>;
+/// \todo replace Array<char> with std::string
+
+#if 0
 #include <cstddef>
 #include <algorithm>
 
@@ -166,5 +174,6 @@ inline void swap( Array<Element, Allocator>& self, Array<Element, Allocator>& ot
        self.swap( other );
 }
 }
+#endif
 
 #endif
index bef7d7cb4c2a3eb02c0c30d3c9ab776cabb21d3d..6796120695f0bb919622b13cde2ec49f00a364ee 100644 (file)
@@ -93,6 +93,15 @@ inline bool operator==( const DefaultAllocator<Type>&, const OtherAllocator& ){
        return false;
 }
 
+template<typename Type, typename Other>
+inline bool operator!=( const DefaultAllocator<Type>&, const DefaultAllocator<Other>& ){
+       return false;
+}
+template<typename Type, typename OtherAllocator>
+inline bool operator!=( const DefaultAllocator<Type>&, const OtherAllocator& ){
+       return true;
+}
+
 #endif
 
 
index dca55b79b2176b13bf33f80df1151fda5e82dad3..98425be8e4554835ba074248e712fba792b4d163 100644 (file)
@@ -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;
                }
index cadb0e13bf9de03696f902615d67ba4510af09df..9e1bb16d99f085cf74b131ab63c25898ed5e3fe2 100644 (file)
@@ -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() ) {
index 11c7b64bf7a0beb4e07e4f5aeeb7505cf196ab37..ede257409220ab10441ae02bc28127788b8d1e0b 100644 (file)
@@ -132,7 +132,7 @@ void printShaderLog( GLhandleARB object ){
        Array<char> 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 ){
index 5013af7ba466d3b66840e10fbcb02cd6b54df667..2e481b409c0de96474f825615bea2d476c0dfe42 100644 (file)
@@ -684,7 +684,7 @@ struct FlatShadedVertex
 };
 
 
-typedef FlatShadedVertex* FlatShadedVertexIterator;
+typedef Array<FlatShadedVertex>::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 )
        {