mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 08:35:43 +00:00
ZoneLoading: When using the temp block multiple times after another when for example loading nested assets, remember the last position of the temp block and return to there when popping it
This commit is contained in:
parent
0d801948bc
commit
21f395ab7d
@ -6,13 +6,13 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include "Loading/Exception/OutOfBlockBoundsException.h"
|
#include "Loading/Exception/OutOfBlockBoundsException.h"
|
||||||
|
|
||||||
XBlockInputStream::XBlockInputStream(std::vector<XBlock*>& blocks, ILoadingStream* stream, const int blockBitCount, const block_t insertBlock) : m_blocks(blocks)
|
XBlockInputStream::XBlockInputStream(std::vector<XBlock*>& blocks, ILoadingStream* stream, const int blockBitCount,
|
||||||
|
const block_t insertBlock) : m_blocks(blocks)
|
||||||
{
|
{
|
||||||
m_stream = stream;
|
m_stream = stream;
|
||||||
|
|
||||||
const unsigned int blockCount = blocks.size();
|
const unsigned int blockCount = blocks.size();
|
||||||
m_block_offsets = new size_t[blockCount]{0};
|
m_block_offsets = new size_t[blockCount]{0};
|
||||||
m_block_in_stack = new unsigned int[blockCount]{0};
|
|
||||||
|
|
||||||
m_block_bit_count = blockBitCount;
|
m_block_bit_count = blockBitCount;
|
||||||
|
|
||||||
@ -25,9 +25,6 @@ XBlockInputStream::~XBlockInputStream()
|
|||||||
delete[] m_block_offsets;
|
delete[] m_block_offsets;
|
||||||
m_block_offsets = nullptr;
|
m_block_offsets = nullptr;
|
||||||
|
|
||||||
delete[] m_block_in_stack;
|
|
||||||
m_block_in_stack = nullptr;
|
|
||||||
|
|
||||||
assert(m_block_stack.empty());
|
assert(m_block_stack.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +48,11 @@ void XBlockInputStream::PushBlock(const block_t block)
|
|||||||
assert(newBlock->m_index == block);
|
assert(newBlock->m_index == block);
|
||||||
|
|
||||||
m_block_stack.push(newBlock);
|
m_block_stack.push(newBlock);
|
||||||
m_block_in_stack[newBlock->m_index]++;
|
|
||||||
|
if(newBlock->m_type == XBlock::Type::BLOCK_TYPE_TEMP)
|
||||||
|
{
|
||||||
|
m_temp_offsets.push(m_block_offsets[newBlock->m_index]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
block_t XBlockInputStream::PopBlock()
|
block_t XBlockInputStream::PopBlock()
|
||||||
@ -64,12 +65,12 @@ block_t XBlockInputStream::PopBlock()
|
|||||||
const XBlock* poppedBlock = m_block_stack.top();
|
const XBlock* poppedBlock = m_block_stack.top();
|
||||||
|
|
||||||
m_block_stack.pop();
|
m_block_stack.pop();
|
||||||
m_block_in_stack[poppedBlock->m_index]--;
|
|
||||||
|
|
||||||
// If the temp block is not used anymore right now, reset it to the buffer start since as the name suggests, the data inside is temporary.
|
// If the temp block is not used anymore right now, reset it to the buffer start since as the name suggests, the data inside is temporary.
|
||||||
if(poppedBlock->m_type == XBlock::Type::BLOCK_TYPE_TEMP && m_block_in_stack[poppedBlock->m_index] == 0)
|
if (poppedBlock->m_type == XBlock::Type::BLOCK_TYPE_TEMP)
|
||||||
{
|
{
|
||||||
m_block_offsets[poppedBlock->m_index] = 0;
|
m_block_offsets[poppedBlock->m_index] = m_temp_offsets.top();
|
||||||
|
m_temp_offsets.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
return poppedBlock->m_index;
|
return poppedBlock->m_index;
|
||||||
@ -165,8 +166,8 @@ void XBlockInputStream::LoadNullTerminated(void* dst)
|
|||||||
|
|
||||||
m_stream->Load(&byte, 1);
|
m_stream->Load(&byte, 1);
|
||||||
block->m_buffer[offset++] = byte;
|
block->m_buffer[offset++] = byte;
|
||||||
|
}
|
||||||
} while(byte != 0);
|
while (byte != 0);
|
||||||
|
|
||||||
m_block_offsets[block->m_index] = offset;
|
m_block_offsets[block->m_index] = offset;
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ class XBlockInputStream final : public IZoneInputStream
|
|||||||
{
|
{
|
||||||
std::vector<XBlock*>& m_blocks;
|
std::vector<XBlock*>& m_blocks;
|
||||||
size_t* m_block_offsets;
|
size_t* m_block_offsets;
|
||||||
unsigned int* m_block_in_stack;
|
|
||||||
|
|
||||||
std::stack<XBlock*> m_block_stack;
|
std::stack<XBlock*> m_block_stack;
|
||||||
|
std::stack<size_t> m_temp_offsets;
|
||||||
ILoadingStream* m_stream;
|
ILoadingStream* m_stream;
|
||||||
|
|
||||||
int m_block_bit_count;
|
int m_block_bit_count;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user