rodecomp/Source/Render/Primitives/RenderVertexPool.cpp
ragnarok-clanker 7dc67400be Confirm 2 functions in Source/Render/DX9/RendererFrameDX9.cpp, Source/Render/Primitives/LightmappedPrimitive.cpp, ...
Batch #11872 by StrawberrysherbetIX: 1 byte-identical, 1 confirmed by peer review.

- fn_02079 CRenderer::ClearFrame: byte-identical (already on main)
- fn_17537 RenderVertexPool::Acquire: logic confirmed by peer review (already on main)

Peer-reviewed-by: Yommy, KWDev
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-05 07:26:19 +00:00

101 lines
2.3 KiB
C++

#include "Render/Primitives/RenderVertexPool.h"
#include <algorithm>
namespace {
// INLINED
void Append(std::vector<RenderVertex>& block, unsigned count) {
const unsigned first = static_cast<unsigned>(block.size());
block.resize(first + count);
for (unsigned index = first; index < block.size(); ++index) {
block[index].specular = 0xFF000000u;
}
}
}
// OFFSET: 0x00561690
// FUNCTION: fn_02162
RenderVertexPool::~RenderVertexPool() {
this->Release();
}
// OFFSET: 0x00562290
// FUNCTION: fn_02177
__declspec(noinline) void RenderVertexPool::Release() {
for (Block* block : this->m_active) {
delete block;
}
this->m_active.clear();
for (Block* block : this->m_unused) {
delete block;
}
this->m_unused.clear();
}
// OFFSET: 0x00559AA0
// FUNCTION: fn_02070
RenderVertexPool::Block& RenderVertexPool::Activate(unsigned capacity) {
Block* block = nullptr;
auto previous = this->m_unused.before_begin();
for (auto current = this->m_unused.begin(); current != this->m_unused.end(); ++current) {
if ((*current)->capacity() >= capacity) {
block = *current;
this->m_active.splice_after(this->m_active.before_begin(), this->m_unused, previous);
break;
}
previous = current;
}
if (!block) {
block = new Block();
block->reserve(capacity);
this->m_active.push_front(block);
}
return *block;
}
// OFFSET: 0x00ABC950
// FUNCTION: fn_17537
RenderVertex* RenderVertexPool::Acquire(unsigned count) {
if (count == 0) {
return nullptr;
}
for (auto& block : this->m_active) {
if (block->capacity() - block->size() >= count) {
const unsigned first = static_cast<unsigned>(block->size());
Append(*block, count);
this->m_used += count;
return block->data() + first;
}
}
Block& block = this->Activate(std::max(this->m_minimum, count));
Append(block, count);
this->m_used += count;
return block.data();
}
// OFFSET: 0x00AB77A0
// FUNCTION: fn_17486
RenderVertex* RenderVertexPool::Block::Append(unsigned count) {
const unsigned first = static_cast<unsigned>(this->size());
if (first + count > this->capacity()) {
return nullptr;
}
this->resize(first + count);
for (unsigned index = first; index < this->size(); ++index) {
(*this)[index].specular = 0xFF000000u;
}
return this->data() + (this->size() - count);
}