0ad/source/tools/atlas/DatafileIO/Stream/Stream.cpp
Ykkrosh aa118403bb Terrain: CalcFromPosition, to convert world-space to tile-space.
ScEd: Compilation fixes.
Atlas: Screen-space to world-space conversion when editing terrain.
Wireframe option. Minor wxWidgets 2.6.1 fixes. AoE3Ed.

This was SVN commit r2698.
2005-09-12 20:04:26 +00:00

35 lines
726 B
C++

#include "stdafx.h"
#include "Stream.h"
#include <cassert>
#include <string>
using namespace DatafileIO;
bool InputStream::AcquireBuffer(void*& buffer, size_t& size, size_t max_size)
{
std::string data;
const size_t tempBufSize = 65536;
static char tempBuffer[tempBufSize];
size = 0;
size_t bytesLeft = max_size;
size_t bytesRead;
while (bytesLeft > 0 && (bytesRead = Read(tempBuffer, std::min(bytesLeft, tempBufSize))) != 0)
{
size += bytesRead;
bytesLeft -= bytesRead;
data += std::string(tempBuffer, bytesRead);
}
buffer = new char[size];
memcpy(buffer, data.data(), size);
return true;
}
void InputStream::ReleaseBuffer(void* buffer)
{
delete[] (char*)buffer;
}