Replaces legacy ProxyAllocator by AllocatorAdapter

This commit is contained in:
Vladislav Belov committed 2026-10-22 23:22:33 +02:00
1 parent 38dff62cff
commit ddc07f92b9
8 files changed
+36 -36

No files matched your search

+3 -3
View File
@@ -25,12 +25,12 @@
#include "graphics/ParticleManager.h"
#include "graphics/RenderableObject.h"
#include "graphics/TextureManager.h"
#include "lib/allocators/STLAllocators.h"
#include "lib/debug.h"
#include "maths/Matrix3D.h"
#include "ps/memory/LinearAllocator.h"
#include "ps/CStrIntern.h"
#include "ps/CStrInternStatic.h"
#include "ps/memory/AllocatorAdapter.h"
#include "ps/memory/LinearAllocator.h"
#include "renderer/Renderer.h"
#include "renderer/Scene.h"
#include "renderer/SceneRenderer.h"
@@ -183,7 +183,7 @@ void CParticleEmitter::UpdateArrayData(int frameNumber)
PS::Memory::ScopedLinearAllocator scopedLinearAllocator{g_Renderer.GetLinearAllocator()};
using ParticlesVector = std::vector<SParticle, ProxyAllocator<SParticle, PS::Memory::ScopedLinearAllocator>>;
using ParticlesVector = std::vector<SParticle, PS::Memory::AllocatorAdapter<SParticle, PS::Memory::ScopedLinearAllocator>>;
ParticlesVector sortedParticles((ParticlesVector::allocator_type(scopedLinearAllocator)));
m_LastFrameNumber = frameNumber;
+3 -3
View File
@@ -210,9 +210,9 @@ void CTextRenderer::Render(
const CVector2D& transformScale, const CVector2D& translation,
const bool debugFontBox, const CColor& debugBoxColor)
{
std::vector<std::uint16_t, ProxyAllocator<std::uint16_t, PS::Memory::ScopedLinearAllocator>> indices{m_ScopedLinearAllocator};
std::vector<CVector2D, ProxyAllocator<CVector2D, PS::Memory::ScopedLinearAllocator>> positions{m_ScopedLinearAllocator};
std::vector<CVector2D, ProxyAllocator<CVector2D, PS::Memory::ScopedLinearAllocator>> uvs{m_ScopedLinearAllocator};
std::vector<std::uint16_t, PS::Memory::AllocatorAdapter<std::uint16_t, PS::Memory::ScopedLinearAllocator>> indices{m_ScopedLinearAllocator};
std::vector<CVector2D, PS::Memory::AllocatorAdapter<CVector2D, PS::Memory::ScopedLinearAllocator>> positions{m_ScopedLinearAllocator};
std::vector<CVector2D, PS::Memory::AllocatorAdapter<CVector2D, PS::Memory::ScopedLinearAllocator>> uvs{m_ScopedLinearAllocator};
// Try to merge non-consecutive batches that share the same font/color/translate:
// sort the batch list by font, then merge the runs of adjacent compatible batches
+4 -4
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -19,10 +19,10 @@
#define INCLUDED_TEXTRENDERER
#include "graphics/Color.h"
#include "lib/allocators/STLAllocators.h"
#include "maths/Rect.h"
#include "maths/Vector2D.h"
#include "ps/CStrIntern.h"
#include "ps/memory/AllocatorAdapter.h"
#include "ps/memory/LinearAllocator.h"
#include <cstddef>
@@ -161,7 +161,7 @@ private:
CVector2D translate;
CColor color;
CFont* font;
using SBatchRunList = std::list<SBatchRun, ProxyAllocator<SBatchRun, PS::Memory::ScopedLinearAllocator>>;
using SBatchRunList = std::list<SBatchRun, PS::Memory::AllocatorAdapter<SBatchRun, PS::Memory::ScopedLinearAllocator>>;
SBatchRunList runs;
SBatch(PS::Memory::ScopedLinearAllocator& allocator) : runs{allocator} {}
@@ -180,7 +180,7 @@ private:
bool m_Dirty = true;
using SBatchList = std::list<SBatch, ProxyAllocator<SBatch, PS::Memory::ScopedLinearAllocator>>;
using SBatchList = std::list<SBatch, PS::Memory::AllocatorAdapter<SBatch, PS::Memory::ScopedLinearAllocator>>;
SBatchList m_Batches;
};
+2 -2
View File
@@ -23,7 +23,7 @@
#include "gui/ObjectBases/IGUIObject.h"
#include "lib/alignment.h"
#include "lib/allocators/DynamicArena.h"
#include "lib/allocators/STLAllocators.h"
#include "ps/memory/AllocatorAdapter.h"
#include <algorithm>
#include <utility>
@@ -60,7 +60,7 @@ public:
static void RecurseVisibleObject(IGUIObject* object, void(IGUIObject::* callbackFunction)(Args... args), Args&&... args)
{
using Arena = Allocators::DynamicArena<128 * KiB>;
using ObjectListAllocator = ProxyAllocator<VisibleObject, Arena>;
using ObjectListAllocator = PS::Memory::AllocatorAdapter<VisibleObject, Arena>;
Arena arena;
std::vector<VisibleObject, ObjectListAllocator> visibleObjects((ObjectListAllocator(arena)));
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -17,7 +17,7 @@
#include "lib/self_test.h"
#include "lib/allocators/STLAllocators.h"
#include "ps/memory/AllocatorAdapter.h"
#include "ps/memory/LinearAllocator.h"
#include <algorithm>
@@ -67,10 +67,10 @@ public:
{
PS::Memory::ScopedLinearAllocator scopedAllocator1{allocator};
PS::Memory::ScopedLinearAllocator scopedAllocator2{allocator};
ProxyAllocator<int, PS::Memory::ScopedLinearAllocator> proxyAllocator1{scopedAllocator1};
ProxyAllocator<int, PS::Memory::ScopedLinearAllocator> proxyAllocator2{scopedAllocator2};
TS_ASSERT_EQUALS(proxyAllocator1, proxyAllocator1);
TS_ASSERT_DIFFERS(proxyAllocator1, proxyAllocator2);
PS::Memory::AllocatorAdapter<int, PS::Memory::ScopedLinearAllocator> allocatorAdapter1{scopedAllocator1};
PS::Memory::AllocatorAdapter<int, PS::Memory::ScopedLinearAllocator> allocatorAdapter2{scopedAllocator2};
TS_ASSERT_EQUALS(allocatorAdapter1, allocatorAdapter1);
TS_ASSERT_DIFFERS(allocatorAdapter1, allocatorAdapter2);
}
}
+2 -2
View File
@@ -29,13 +29,13 @@
#include "graphics/Terrain.h"
#include "graphics/TextureManager.h"
#include "lib/alignment.h"
#include "lib/allocators/STLAllocators.h"
#include "lib/debug.h"
#include "lib/posix/posix_types.h"
#include "maths/Matrix3D.h"
#include "ps/CLogger.h"
#include "ps/CStrIntern.h"
#include "ps/CStrInternStatic.h"
#include "ps/memory/AllocatorAdapter.h"
#include "ps/memory/LinearAllocator.h"
#include "ps/Profile.h"
#include "renderer/Renderer.h"
@@ -145,7 +145,7 @@ void CDecalRData::RenderDecals(
PS::Memory::ScopedLinearAllocator scopedLinearAllocator{g_Renderer.GetLinearAllocator()};
using Batches = std::vector<SDecalBatch, ProxyAllocator<SDecalBatch, PS::Memory::ScopedLinearAllocator>>;
using Batches = std::vector<SDecalBatch, PS::Memory::AllocatorAdapter<SDecalBatch, PS::Memory::ScopedLinearAllocator>>;
Batches batches((Batches::allocator_type(scopedLinearAllocator)));
batches.reserve(decals.size());
+9 -9
View File
@@ -31,7 +31,6 @@
#include "graphics/Texture.h"
#include "graphics/TextureManager.h"
#include "lib/alignment.h"
#include "lib/allocators/STLAllocators.h"
#include "lib/debug.h"
#include "lib/hash.h"
#include "maths/Matrix3D.h"
@@ -40,6 +39,7 @@
#include "ps/CLogger.h"
#include "ps/CStrIntern.h"
#include "ps/CStrInternStatic.h"
#include "ps/memory/AllocatorAdapter.h"
#include "ps/memory/LinearAllocator.h"
#include "ps/Profile.h"
#include "renderer/MikktspaceWrap.h"
@@ -349,14 +349,14 @@ void ModelRenderer::Render(
PS::Memory::ScopedLinearAllocator scopedLinearAllocator{g_Renderer.GetLinearAllocator()};
using ModelListAllocator = ProxyAllocator<CModel*, PS::Memory::ScopedLinearAllocator>;
using ModelListAllocator = PS::Memory::AllocatorAdapter<CModel*, PS::Memory::ScopedLinearAllocator>;
using ModelList_t = std::vector<CModel*, ModelListAllocator>;
using MaterialBuckets_t = std::unordered_map<
SMRMaterialBucketKey,
ModelList_t,
SMRMaterialBucketKeyHash,
std::equal_to<SMRMaterialBucketKey>,
ProxyAllocator<
PS::Memory::AllocatorAdapter<
std::pair<const SMRMaterialBucketKey, ModelList_t>,
PS::Memory::ScopedLinearAllocator>>;
@@ -387,10 +387,10 @@ void ModelRenderer::Render(
}
}
using SortByDistItemsAllocator = ProxyAllocator<SMRSortByDistItem, PS::Memory::ScopedLinearAllocator>;
using SortByDistItemsAllocator = PS::Memory::AllocatorAdapter<SMRSortByDistItem, PS::Memory::ScopedLinearAllocator>;
std::vector<SMRSortByDistItem, SortByDistItemsAllocator> sortByDistItems((SortByDistItemsAllocator(scopedLinearAllocator)));
using SortByTechItemsAllocator = ProxyAllocator<CShaderTechniquePtr, PS::Memory::ScopedLinearAllocator>;
using SortByTechItemsAllocator = PS::Memory::AllocatorAdapter<CShaderTechniquePtr, PS::Memory::ScopedLinearAllocator>;
std::vector<CShaderTechniquePtr, SortByTechItemsAllocator> sortByDistTechs((SortByTechItemsAllocator(scopedLinearAllocator)));
// indexed by sortByDistItems[i].techIdx
// (which stores indexes instead of CShaderTechniquePtr directly
@@ -398,7 +398,7 @@ void ModelRenderer::Render(
// if we just stored raw CShaderTechnique* and assumed the shader manager
// will keep it alive long enough)
using TechBucketsAllocator = ProxyAllocator<SMRTechBucket, PS::Memory::ScopedLinearAllocator>;
using TechBucketsAllocator = PS::Memory::AllocatorAdapter<SMRTechBucket, PS::Memory::ScopedLinearAllocator>;
std::vector<SMRTechBucket, TechBucketsAllocator> techBuckets((TechBucketsAllocator(scopedLinearAllocator)));
{
@@ -514,18 +514,18 @@ void ModelRenderer::Render(
// This vector keeps track of texture changes during rendering. It is kept outside the
// loops to avoid excessive reallocations. The token allocation of 64 elements
// should be plenty, though it is reallocated below (at a cost) if necessary.
using TextureListAllocator = ProxyAllocator<CTexture*, PS::Memory::ScopedLinearAllocator>;
using TextureListAllocator = PS::Memory::AllocatorAdapter<CTexture*, PS::Memory::ScopedLinearAllocator>;
std::vector<CTexture*, TextureListAllocator> currentTexs((TextureListAllocator(scopedLinearAllocator)));
currentTexs.reserve(64);
// texBindings holds the identifier bindings in the shader, which can no longer be defined
// statically in the ShaderRenderModifier class. texBindingNames uses interned strings to
// keep track of when bindings need to be reevaluated.
using BindingListAllocator = ProxyAllocator<int32_t, PS::Memory::ScopedLinearAllocator>;
using BindingListAllocator = PS::Memory::AllocatorAdapter<int32_t, PS::Memory::ScopedLinearAllocator>;
std::vector<int32_t, BindingListAllocator> texBindings((BindingListAllocator(scopedLinearAllocator)));
texBindings.reserve(64);
using BindingNamesListAllocator = ProxyAllocator<CStrIntern, PS::Memory::ScopedLinearAllocator>;
using BindingNamesListAllocator = PS::Memory::AllocatorAdapter<CStrIntern, PS::Memory::ScopedLinearAllocator>;
std::vector<CStrIntern, BindingNamesListAllocator> texBindingNames((BindingNamesListAllocator(scopedLinearAllocator)));
texBindingNames.reserve(64);
+7 -7
View File
@@ -35,7 +35,6 @@
#include "graphics/TextRenderer.h"
#include "graphics/TextureManager.h"
#include "lib/alignment.h"
#include "lib/allocators/STLAllocators.h"
#include "lib/code_generation.h"
#include "lib/debug.h"
#include "maths/Matrix3D.h"
@@ -44,6 +43,7 @@
#include "ps/CStrIntern.h"
#include "ps/CStrInternStatic.h"
#include "ps/Game.h"
#include "ps/memory/AllocatorAdapter.h"
#include "ps/memory/LinearAllocator.h"
#include "ps/Profile.h"
#include "renderer/AlphaMapCalculator.h"
@@ -846,7 +846,7 @@ void CPatchRData::Update(CSimulation2* simulation)
// std::map types with appropriate arena allocators and default comparison operator
template<class Key, class Value>
using PooledBatchMap = std::map<Key, Value, std::less<Key>, ProxyAllocator<std::pair<Key const, Value>, PS::Memory::ScopedLinearAllocator>>;
using PooledBatchMap = std::map<Key, Value, std::less<Key>, PS::Memory::AllocatorAdapter<std::pair<Key const, Value>, PS::Memory::ScopedLinearAllocator>>;
// Equivalent to "m[k]", when it returns a arena-allocated std::map (since we can't
// use the default constructor in that case)
@@ -870,8 +870,8 @@ typename M::mapped_type& PooledPairGet(M& m, const typename M::key_type& k, PS::
// Each multidraw batch has a list of index counts, and a list of pointers-to-first-indexes
using BatchElements = std::pair<
std::vector<std::uint32_t, ProxyAllocator<std::uint32_t, PS::Memory::ScopedLinearAllocator>>,
std::vector<std::uint32_t, ProxyAllocator<std::uint32_t, PS::Memory::ScopedLinearAllocator>>>;
std::vector<std::uint32_t, PS::Memory::AllocatorAdapter<std::uint32_t, PS::Memory::ScopedLinearAllocator>>,
std::vector<std::uint32_t, PS::Memory::AllocatorAdapter<std::uint32_t, PS::Memory::ScopedLinearAllocator>>>;
// Group batches by index buffer
using IndexBufferBatches = PooledBatchMap<CVertexBuffer*, BatchElements>;
@@ -1042,7 +1042,7 @@ struct SBlendStackItem
{
}
using SplatStack = std::vector<CPatchRData::SSplat, ProxyAllocator<CPatchRData::SSplat, PS::Memory::ScopedLinearAllocator>>;
using SplatStack = std::vector<CPatchRData::SSplat, PS::Memory::AllocatorAdapter<CPatchRData::SSplat, PS::Memory::ScopedLinearAllocator>>;
CVertexBuffer::VBChunk* vertices;
CVertexBuffer::VBChunk* indices;
SplatStack splats;
@@ -1059,7 +1059,7 @@ void CPatchRData::RenderBlends(
PS::Memory::ScopedLinearAllocator scopedLinearAllocator{g_Renderer.GetLinearAllocator()};
using BatchesStack = std::vector<SBlendBatch, ProxyAllocator<SBlendBatch, PS::Memory::ScopedLinearAllocator>>;
using BatchesStack = std::vector<SBlendBatch, PS::Memory::AllocatorAdapter<SBlendBatch, PS::Memory::ScopedLinearAllocator>>;
BatchesStack batches((BatchesStack::allocator_type(scopedLinearAllocator)));
CShaderDefines contextBlend = context;
@@ -1071,7 +1071,7 @@ void CPatchRData::RenderBlends(
// to avoid heavy reallocations
batches.reserve(256);
using BlendStacks = std::vector<SBlendStackItem, ProxyAllocator<SBlendStackItem, PS::Memory::ScopedLinearAllocator>>;
using BlendStacks = std::vector<SBlendStackItem, PS::Memory::AllocatorAdapter<SBlendStackItem, PS::Memory::ScopedLinearAllocator>>;
BlendStacks blendStacks((BlendStacks::allocator_type(scopedLinearAllocator)));
blendStacks.reserve(patches.size());