Formatted EVERYTHING

This commit is contained in:
Dynamitos
2024-06-09 12:20:53 +02:00
parent f18bf8acbe
commit d95dab850c
265 changed files with 8002 additions and 12310 deletions
+15 -36
View File
@@ -1,44 +1,37 @@
#include "ArchiveBuffer.h"
#include "Graphics/Graphics.h"
#include <ostream>
#include <istream>
#include <ostream>
using namespace Seele;
ArchiveBuffer::ArchiveBuffer()
{}
ArchiveBuffer::ArchiveBuffer() {}
ArchiveBuffer::ArchiveBuffer(Gfx::PGraphics graphics)
: graphics(graphics)
{}
ArchiveBuffer::ArchiveBuffer(Gfx::PGraphics graphics) : graphics(graphics) {}
void ArchiveBuffer::writeBytes(const void* data, uint64 size)
{
if (size + position >= memory.size())
{
void ArchiveBuffer::writeBytes(const void* data, uint64 size) {
if (size + position >= memory.size()) {
memory.resize(size + position);
}
std::memcpy(memory.data() + position, data, size);
position += size;
}
void ArchiveBuffer::readBytes(void* dest, uint64 size)
{
void ArchiveBuffer::readBytes(void* dest, uint64 size) {
assert(position + size <= memory.size());
std::memcpy(dest, memory.data() + position, size);
position += size;
}
void ArchiveBuffer::writeToStream(std::ostream& stream)
{
void ArchiveBuffer::writeToStream(std::ostream& stream) {
uint64 bufferLength = memory.size();
stream.write((char*)&version, sizeof(uint64));
stream.write((char*)&bufferLength, sizeof(uint64));
stream.write((char*)memory.data(), memory.size());
}
void ArchiveBuffer::readFromStream(std::istream& stream)
{
void ArchiveBuffer::readFromStream(std::istream& stream) {
stream.read((char*)&version, sizeof(uint64));
uint64 bufferLength = 0;
stream.read((char*)&bufferLength, sizeof(uint64));
@@ -46,11 +39,9 @@ void ArchiveBuffer::readFromStream(std::istream& stream)
stream.read((char*)memory.data(), bufferLength);
}
void ArchiveBuffer::seek(int64 s, SeekOp op)
{
void ArchiveBuffer::seek(int64 s, SeekOp op) {
int64 newPos = position;
switch (op)
{
switch (op) {
case SeekOp::BEGIN:
newPos = s;
break;
@@ -65,22 +56,10 @@ void ArchiveBuffer::seek(int64 s, SeekOp op)
newPos = position;
}
bool ArchiveBuffer::eof() const
{
return position == memory.size();
}
bool ArchiveBuffer::eof() const { return position == memory.size(); }
size_t Seele::ArchiveBuffer::size() const
{
return memory.size();
}
size_t Seele::ArchiveBuffer::size() const { return memory.size(); }
void ArchiveBuffer::rewind()
{
position = 0;
}
void ArchiveBuffer::rewind() { position = 0; }
Gfx::PGraphics& ArchiveBuffer::getGraphics()
{
return graphics;
}
Gfx::PGraphics& ArchiveBuffer::getGraphics() { return graphics; }
+9 -10
View File
@@ -1,23 +1,21 @@
#pragma once
#include "MinimalEngine.h"
#include "Containers/Array.h"
#include "Concepts.h"
#include "Containers/Array.h"
#include "MinimalEngine.h"
#include <string>
namespace Seele
{
namespace Seele {
DECLARE_NAME_REF(Gfx, Graphics)
class ArchiveBuffer
{
public:
class ArchiveBuffer {
public:
ArchiveBuffer();
ArchiveBuffer(Gfx::PGraphics graphics);
void writeBytes(const void* data, uint64 size);
void readBytes(void* dest, uint64 size);
void writeToStream(std::ostream& stream);
void readFromStream(std::istream& stream);
enum class SeekOp
{
enum class SeekOp {
CURRENT,
BEGIN,
END,
@@ -27,7 +25,8 @@ public:
size_t size() const;
void rewind();
Gfx::PGraphics& getGraphics();
private:
private:
Gfx::PGraphics graphics;
uint64 version = 0;
uint64 position = 0;
+105 -146
View File
@@ -1,156 +1,115 @@
#pragma once
#include "ArchiveBuffer.h"
#include "Math/Vector.h"
#include "Math/Matrix.h"
#include "Math/Vector.h"
namespace Seele
namespace Seele {
namespace Serialization {
template <std::integral T> static void save(ArchiveBuffer& buffer, const T& type) { buffer.writeBytes(&type, sizeof(type)); }
template <std::integral T> static void load(ArchiveBuffer& buffer, T& type) { buffer.readBytes(&type, sizeof(type)); }
template <std::floating_point T> static void save(ArchiveBuffer& buffer, const T& type) { buffer.writeBytes(&type, sizeof(type)); }
template <std::floating_point T> static void load(ArchiveBuffer& buffer, T& type) { buffer.readBytes(&type, sizeof(type)); }
static void save(ArchiveBuffer& buffer, const IVector2& vec) {
save(buffer, vec.x);
save(buffer, vec.y);
}
static void load(ArchiveBuffer& buffer, IVector2& vec) {
load(buffer, vec.x);
load(buffer, vec.y);
}
static void save(ArchiveBuffer& buffer, const Vector2& vec) {
save(buffer, vec.x);
save(buffer, vec.y);
}
static void load(ArchiveBuffer& buffer, Vector2& vec) {
load(buffer, vec.x);
load(buffer, vec.y);
}
static void save(ArchiveBuffer& buffer, const Vector& vec) {
save(buffer, vec.x);
save(buffer, vec.y);
save(buffer, vec.z);
}
static void load(ArchiveBuffer& buffer, Matrix4& mat) { buffer.readBytes(&mat, sizeof(Matrix4)); }
static void save(ArchiveBuffer& buffer, const Matrix4& mat) { buffer.writeBytes(&mat, sizeof(Matrix4)); }
static void load(ArchiveBuffer& buffer, Vector& vec) {
load(buffer, vec.x);
load(buffer, vec.y);
load(buffer, vec.z);
}
template <enumeration T> static void save(ArchiveBuffer& buffer, const T& type) { buffer.writeBytes(&type, sizeof(type)); }
template <enumeration T> static void load(ArchiveBuffer& buffer, T& type) { buffer.readBytes(&type, sizeof(type)); }
template <typename T>
static void save(ArchiveBuffer& buffer, const T& type)
requires(serializable<ArchiveBuffer, T>)
{
namespace Serialization
type.save(buffer);
}
template <typename T>
static void load(ArchiveBuffer& buffer, T& type)
requires(serializable<ArchiveBuffer, T>)
{
template<std::integral T>
static void save(ArchiveBuffer& buffer, const T& type)
{
buffer.writeBytes(&type, sizeof(type));
type.load(buffer);
}
template <typename T> static void save(ArchiveBuffer& buffer, const OwningPtr<T>& ptr);
template <typename T> static void load(ArchiveBuffer& buffer, OwningPtr<T>& ptr);
static void save(ArchiveBuffer& buffer, const std::string& type) {
uint64 length = type.size();
buffer.writeBytes(&length, sizeof(uint64));
buffer.writeBytes(type.data(), type.size() * sizeof(char));
}
static void load(ArchiveBuffer& buffer, std::string& type) {
uint64 length = 0;
buffer.readBytes(&length, sizeof(uint64));
type.resize(length);
buffer.readBytes(type.data(), length * sizeof(char));
}
template <typename T>
static void save(ArchiveBuffer& buffer, const Array<T>& type)
requires(std::is_trivially_copyable_v<T>)
{
uint64 length = type.size();
buffer.writeBytes(&length, sizeof(uint64));
buffer.writeBytes(type.data(), sizeof(T) * type.size());
}
template <typename T>
static void load(ArchiveBuffer& buffer, Array<T>& type)
requires(std::is_trivially_copyable_v<T>)
{
uint64 length = 0;
buffer.readBytes(&length, sizeof(uint64));
type.resize(length);
buffer.readBytes(type.data(), sizeof(T) * type.size());
}
template <typename T, size_t N>
static void save(ArchiveBuffer& buffer, const StaticArray<T, N>& type)
requires(std::is_trivially_copyable_v<T>)
{
buffer.writeBytes(type.data(), sizeof(T) * N);
}
template <typename T, size_t N>
static void load(ArchiveBuffer& buffer, StaticArray<T, N>& type)
requires(std::is_trivially_copyable_v<T>)
{
buffer.readBytes(type.data(), sizeof(T) * N);
}
template <typename T> static void save(ArchiveBuffer& buffer, const Array<T>& type) {
uint64 length = type.size();
buffer.writeBytes(&length, sizeof(uint64));
for (const T& x : type) {
save(buffer, x);
}
template<std::integral T>
static void load(ArchiveBuffer& buffer, T& type)
{
buffer.readBytes(&type, sizeof(type));
}
template<std::floating_point T>
static void save(ArchiveBuffer& buffer, const T& type)
{
buffer.writeBytes(&type, sizeof(type));
}
template<std::floating_point T>
static void load(ArchiveBuffer& buffer, T& type)
{
buffer.readBytes(&type, sizeof(type));
}
static void save(ArchiveBuffer& buffer, const IVector2& vec)
{
save(buffer, vec.x);
save(buffer, vec.y);
}
static void load(ArchiveBuffer& buffer, IVector2& vec)
{
load(buffer, vec.x);
load(buffer, vec.y);
}
static void save(ArchiveBuffer& buffer, const Vector2& vec)
{
save(buffer, vec.x);
save(buffer, vec.y);
}
static void load(ArchiveBuffer& buffer, Vector2& vec)
{
load(buffer, vec.x);
load(buffer, vec.y);
}
static void save(ArchiveBuffer& buffer, const Vector& vec)
{
save(buffer, vec.x);
save(buffer, vec.y);
save(buffer, vec.z);
}
static void load(ArchiveBuffer& buffer, Matrix4& mat)
{
buffer.readBytes(&mat, sizeof(Matrix4));
}
static void save(ArchiveBuffer& buffer, const Matrix4& mat)
{
buffer.writeBytes(&mat, sizeof(Matrix4));
}
static void load(ArchiveBuffer& buffer, Vector& vec)
{
load(buffer, vec.x);
load(buffer, vec.y);
load(buffer, vec.z);
}
template<enumeration T>
static void save(ArchiveBuffer& buffer, const T& type)
{
buffer.writeBytes(&type, sizeof(type));
}
template<enumeration T>
static void load(ArchiveBuffer& buffer, T& type)
{
buffer.readBytes(&type, sizeof(type));
}
template<typename T>
static void save(ArchiveBuffer& buffer, const T& type) requires(serializable<ArchiveBuffer, T>)
{
type.save(buffer);
}
template<typename T>
static void load(ArchiveBuffer& buffer, T& type) requires(serializable<ArchiveBuffer, T>)
{
type.load(buffer);
}
template<typename T>
static void save(ArchiveBuffer& buffer, const OwningPtr<T>& ptr);
template<typename T>
static void load(ArchiveBuffer& buffer, OwningPtr<T>& ptr);
static void save(ArchiveBuffer& buffer, const std::string& type)
{
uint64 length = type.size();
buffer.writeBytes(&length, sizeof(uint64));
buffer.writeBytes(type.data(), type.size() * sizeof(char));
}
static void load(ArchiveBuffer& buffer, std::string& type)
{
uint64 length = 0;
buffer.readBytes(&length, sizeof(uint64));
type.resize(length);
buffer.readBytes(type.data(), length * sizeof(char));
}
template<typename T>
static void save(ArchiveBuffer& buffer, const Array<T>& type) requires (std::is_trivially_copyable_v<T>)
{
uint64 length = type.size();
buffer.writeBytes(&length, sizeof(uint64));
buffer.writeBytes(type.data(), sizeof(T) * type.size());
}
template<typename T>
static void load(ArchiveBuffer& buffer, Array<T>& type) requires (std::is_trivially_copyable_v<T>)
{
uint64 length = 0;
buffer.readBytes(&length, sizeof(uint64));
type.resize(length);
buffer.readBytes(type.data(), sizeof(T) * type.size());
}
template<typename T, size_t N>
static void save(ArchiveBuffer& buffer, const StaticArray<T, N>& type) requires (std::is_trivially_copyable_v<T>)
{
buffer.writeBytes(type.data(), sizeof(T) * N);
}
template<typename T, size_t N>
static void load(ArchiveBuffer& buffer, StaticArray<T, N>& type) requires (std::is_trivially_copyable_v<T>)
{
buffer.readBytes(type.data(), sizeof(T) * N);
}
template<typename T>
static void save(ArchiveBuffer& buffer, const Array<T>& type)
{
uint64 length = type.size();
buffer.writeBytes(&length, sizeof(uint64));
for (const T& x : type)
{
save(buffer, x);
}
}
template<typename T>
static void load(ArchiveBuffer& buffer, Array<T>& type)
{
uint64 length = 0;
buffer.readBytes(&length, sizeof(uint64));
type.reserve(length);
for (uint32 i = 0; i < length; ++i)
{
T t = T();
load(buffer, t);
type.add(std::move(t));
}
}
template <typename T> static void load(ArchiveBuffer& buffer, Array<T>& type) {
uint64 length = 0;
buffer.readBytes(&length, sizeof(uint64));
type.reserve(length);
for (uint32 i = 0; i < length; ++i) {
T t = T();
load(buffer, t);
type.add(std::move(t));
}
}
} // namespace Serialization
} // namespace Seele