diff --git a/include/IAnimatedMeshMD3.h b/include/IAnimatedMeshMD3.h index 8aa3ba93..50ad4480 100644 --- a/include/IAnimatedMeshMD3.h +++ b/include/IAnimatedMeshMD3.h @@ -213,10 +213,7 @@ namespace scene //! holds a associative list of named quaternions struct SMD3QuaternionTagList { - SMD3QuaternionTagList () - { - Container.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE ); - } + SMD3QuaternionTagList () {} // construct copy constructor SMD3QuaternionTagList( const SMD3QuaternionTagList & copyMe ) @@ -273,7 +270,7 @@ namespace scene } private: - core::array < SMD3QuaternionTag > Container; + core::array < SMD3QuaternionTag, core::irrAllocator, core::irrAllocStrategySafe > Container; }; diff --git a/include/IQ3Shader.h b/include/IQ3Shader.h index e00b57b1..3d8236c4 100644 --- a/include/IQ3Shader.h +++ b/include/IQ3Shader.h @@ -77,7 +77,7 @@ namespace quake3 // some useful typedefs typedef core::array< core::stringc > tStringList; - typedef core::array< video::ITexture* > tTexArray; + typedef core::array< video::ITexture*, core::irrAllocator, core::irrAllocStrategySafe > tTexArray; // string helper.. TODO: move to generic files inline s16 isEqual ( const core::stringc &string, u32 &pos, const c8 *list[], u16 listSize ) @@ -573,7 +573,7 @@ namespace quake3 // string database. "a" = "Hello", "b" = "1234.6" struct SVarGroup { - SVarGroup () { Variable.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE ); } + SVarGroup () {} virtual ~SVarGroup () {} u32 isDefined ( const c8 * name, const c8 * content = 0 ) const @@ -617,19 +617,16 @@ namespace quake3 } - core::array < SVariable > Variable; + core::array < SVariable, core::irrAllocator, core::irrAllocStrategySafe > Variable; }; //! holding a group a variable struct SVarGroupList: public IReferenceCounted { - SVarGroupList () - { - VariableGroup.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE ); - } + SVarGroupList () {} virtual ~SVarGroupList () {} - core::array < SVarGroup > VariableGroup; + core::array < SVarGroup, core::irrAllocator, core::irrAllocStrategySafe > VariableGroup; }; diff --git a/include/irrAllocator.h b/include/irrAllocator.h index fffd4409..4698d5fe 100644 --- a/include/irrAllocator.h +++ b/include/irrAllocator.h @@ -109,11 +109,62 @@ public: #endif //! defines an allocation strategy -enum eAllocStrategy +enum EAllocStrategy { ALLOC_STRATEGY_SAFE = 0, ALLOC_STRATEGY_DOUBLE = 1, - ALLOC_STRATEGY_SQRT = 2 + ALLOC_STRATEGY_SQ = 2 +}; + +class irrAllocStrategyDouble +{ +public: + + //! Returns the new size of the buffer based on the current size. + const u32 getNewSize(const u32 oldSize) const + { + return oldSize + oldSize + 1; + } + + //! Returns the EAllocStrategy enum of this allocation strategist. + EAllocStrategy getAllocationStrategy() const + { + return ALLOC_STRATEGY_DOUBLE; + } +}; + +class irrAllocStrategySafe +{ +public: + + //! Returns the new size of the buffer based on the current size. + const u32 getNewSize(const u32 oldSize) const + { + return oldSize + 1; + } + + //! Returns the EAllocStrategy enum of this allocation strategist. + EAllocStrategy getAllocationStrategy() const + { + return ALLOC_STRATEGY_SAFE; + } +}; + +class irrAllocStrategySq +{ +public: + + //! Returns the new size of the buffer based on the current size. + const u32 getNewSize(const u32 oldSize) const + { + return oldSize * oldSize + 1; + } + + //! Returns the EAllocStrategy enum of this allocation strategist. + EAllocStrategy getAllocationStrategy() const + { + return ALLOC_STRATEGY_SQ; + } }; diff --git a/include/irrArray.h b/include/irrArray.h index 3f74faa8..c363ba42 100644 --- a/include/irrArray.h +++ b/include/irrArray.h @@ -17,7 +17,7 @@ namespace core //! Self reallocating template array (like stl vector) with additional features. /** Some features are: Heap sorting, binary search methods, easier debugging. */ -template > +template , typename TAllocStrategy = irrAllocStrategyDouble > class array { @@ -25,8 +25,7 @@ public: //! Default constructor for empty array. array() - : data(0), allocated(0), used(0), - strategy(ALLOC_STRATEGY_DOUBLE), free_when_destroyed(true), is_sorted(true) + : data(0), allocated(0), used(0), free_when_destroyed(true), is_sorted(true) { } @@ -34,8 +33,7 @@ public: //! Constructs an array and allocates an initial chunk of memory. /** \param start_count Amount of elements to pre-allocate. */ array(u32 start_count) - : data(0), allocated(0), used(0), - strategy(ALLOC_STRATEGY_DOUBLE), free_when_destroyed(true), is_sorted(true) + : data(0), allocated(0), used(0), free_when_destroyed(true), is_sorted(true) { reallocate(start_count); } @@ -85,17 +83,6 @@ public: allocator.deallocate(old_data); //delete [] old_data; } - - //! set a new allocation strategy - /** if the maximum size of the array is unknown, you can define how big the - allocation should happen. - \param newStrategy New strategy to apply to this array. */ - void setAllocStrategy ( eAllocStrategy newStrategy = ALLOC_STRATEGY_DOUBLE ) - { - strategy = newStrategy; - } - - //! Adds an element at back of array. /** If the array is too small to add this new element it is made bigger. \param element: Element to add at the back of the array. */ @@ -134,18 +121,7 @@ public: const T e(element); // increase data block - u32 newAlloc; - switch ( strategy ) - { - case ALLOC_STRATEGY_DOUBLE: - newAlloc = used + 1 + (allocated < 500 ? - (allocated < 5 ? 5 : used) : used >> 2); - break; - default: - case ALLOC_STRATEGY_SAFE: - newAlloc = used + 1; - break; - } + const u32 newAlloc = allocatorStrategy.getNewSize(used); reallocate( newAlloc); // move array content and construct new element @@ -249,8 +225,6 @@ public: //! Assignment operator void operator=(const array& other) { - strategy = other.strategy; - if (data) clear(); @@ -568,7 +542,7 @@ private: u32 allocated; u32 used; TAlloc allocator; - eAllocStrategy strategy:4; + TAllocStrategy allocatorStrategy; bool free_when_destroyed:1; bool is_sorted:1; }; diff --git a/source/Irrlicht/CQuake3ShaderSceneNode.cpp b/source/Irrlicht/CQuake3ShaderSceneNode.cpp index 5e466f93..e23be3ef 100644 --- a/source/Irrlicht/CQuake3ShaderSceneNode.cpp +++ b/source/Irrlicht/CQuake3ShaderSceneNode.cpp @@ -147,7 +147,6 @@ void CQuake3ShaderSceneNode::loadTextures( io::IFileSystem * fileSystem ) } // clear all stages and prefill empty - Q3Texture.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE ); Q3Texture.clear(); for ( i = 0; i != Shader->VarGroup->VariableGroup.size(); ++i ) { diff --git a/source/Irrlicht/CQuake3ShaderSceneNode.h b/source/Irrlicht/CQuake3ShaderSceneNode.h index fde277a7..356d6006 100644 --- a/source/Irrlicht/CQuake3ShaderSceneNode.h +++ b/source/Irrlicht/CQuake3ShaderSceneNode.h @@ -59,10 +59,7 @@ private: SQ3Texture () : TextureIndex ( 0 ), TextureFrequency(0.f), - TextureAddressMode( video::ETC_REPEAT ) - { - Texture.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE ); - } + TextureAddressMode( video::ETC_REPEAT ) {} quake3::tTexArray Texture; @@ -71,7 +68,7 @@ private: video::E_TEXTURE_CLAMP TextureAddressMode; // Wrapping/Clamping }; - core::array< SQ3Texture > Q3Texture; + core::array< SQ3Texture, core::irrAllocator, core::irrAllocStrategySafe > Q3Texture; void loadTextures ( io::IFileSystem * fileSystem ); void addBuffer ( scene::SMeshBufferLightMap * buffer );