vkdoom_m/src/common/utility/r_memory.h
Christoph Oelckers 68630d6782 - sanitized dependencies of the softpoly render backend.
This included half the game state and lots of unneeded parts of the software renderer.
The two modules that are shared between softpoly and the classic software renderer have been moved to a neutral place.
2020-04-29 18:48:15 +02:00

43 lines
828 B
C++

#pragma once
#include <memory>
#include <vector>
// Memory needed for the duration of a frame rendering
class RenderMemory
{
public:
void Clear();
template<typename T>
T *AllocMemory(int size = 1)
{
return (T*)AllocBytes(sizeof(T) * size);
}
template<typename T, typename... Types>
T *NewObject(Types &&... args)
{
void *ptr = AllocBytes(sizeof(T));
return new (ptr)T(std::forward<Types>(args)...);
}
private:
void *AllocBytes(int size);
enum { BlockSize = 1024 * 1024 };
struct MemoryBlock
{
MemoryBlock();
~MemoryBlock();
MemoryBlock(const MemoryBlock &) = delete;
MemoryBlock &operator=(const MemoryBlock &) = delete;
uint8_t *Data;
uint32_t Position;
};
std::vector<std::unique_ptr<MemoryBlock>> UsedBlocks;
std::vector<std::unique_ptr<MemoryBlock>> FreeBlocks;
};