forked from Green-Sky/tomato
refactoring, add to mainscreen
This commit is contained in:
@@ -2,101 +2,24 @@
|
||||
|
||||
#include "./fragment_store_i.hpp"
|
||||
|
||||
#include <entt/core/fwd.hpp>
|
||||
#include "./types.hpp"
|
||||
#include "./meta_components.hpp"
|
||||
|
||||
#include "./serializer.hpp"
|
||||
|
||||
#include <entt/core/type_info.hpp>
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <entt/container/dense_map.hpp>
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
|
||||
enum class Encryption : uint8_t {
|
||||
NONE = 0x00,
|
||||
};
|
||||
enum class Compression : uint8_t {
|
||||
NONE = 0x00,
|
||||
};
|
||||
enum class MetaFileType : uint8_t {
|
||||
TEXT_JSON,
|
||||
//BINARY_ARB,
|
||||
BINARY_MSGPACK,
|
||||
};
|
||||
|
||||
namespace Components {
|
||||
|
||||
// TODO: is this special and should this be saved to meta or not (its already in the file name on disk)
|
||||
struct ID {
|
||||
std::vector<uint8_t> v;
|
||||
};
|
||||
|
||||
struct DataEncryptionType {
|
||||
Encryption enc {Encryption::NONE};
|
||||
};
|
||||
|
||||
struct DataCompressionType {
|
||||
Compression comp {Compression::NONE};
|
||||
};
|
||||
|
||||
|
||||
// meta that is not written to (meta-)file
|
||||
namespace Ephemeral {
|
||||
|
||||
// excluded from file meta
|
||||
struct FilePath {
|
||||
// contains store path, if any
|
||||
std::string path;
|
||||
};
|
||||
|
||||
// TODO: seperate into remote and local?
|
||||
// (remote meaning eg. the file on disk was changed by another program)
|
||||
struct DirtyTag {};
|
||||
|
||||
|
||||
// type as comp
|
||||
struct MetaFileType {
|
||||
::MetaFileType type {::MetaFileType::TEXT_JSON};
|
||||
};
|
||||
|
||||
struct MetaEncryptionType {
|
||||
Encryption enc {Encryption::NONE};
|
||||
};
|
||||
|
||||
struct MetaCompressionType {
|
||||
Compression comp {Compression::NONE};
|
||||
};
|
||||
|
||||
} // Ephemeral
|
||||
|
||||
} // Components
|
||||
|
||||
struct SerializerCallbacks {
|
||||
// nlohmann
|
||||
// json/msgpack
|
||||
using serialize_json_fn = bool(*)(void* comp, nlohmann::json& out);
|
||||
entt::dense_map<entt::id_type, serialize_json_fn> _serl_json;
|
||||
|
||||
using deserialize_json_fn = bool(*)(void* comp, const nlohmann::json& in);
|
||||
entt::dense_map<entt::id_type, deserialize_json_fn> _deserl_json;
|
||||
|
||||
void registerSerializerJson(serialize_json_fn fn, const entt::type_info& type_info) {
|
||||
_serl_json[type_info.hash()] = fn;
|
||||
}
|
||||
template<typename CompType>
|
||||
void registerSerializerJson(serialize_json_fn fn, const entt::type_info& type_info = entt::type_id<CompType>()) { registerSerializerJson(fn, type_info); }
|
||||
|
||||
void registerDeSerializerJson(deserialize_json_fn fn, const entt::type_info& type_info) {
|
||||
_deserl_json[type_info.hash()] = fn;
|
||||
}
|
||||
template<typename CompType>
|
||||
void registerDeSerializerJson(deserialize_json_fn fn, const entt::type_info& type_info = entt::type_id<CompType>()) { registerDeSerializerJson(fn, type_info); }
|
||||
};
|
||||
|
||||
struct FragmentStore : public FragmentStoreI {
|
||||
using FragmentHandle = entt::basic_handle<entt::basic_registry<FragmentID>>;
|
||||
|
||||
entt::basic_registry<FragmentID> _reg;
|
||||
|
||||
std::minstd_rand _rng{std::random_device{}()};
|
||||
@@ -113,10 +36,11 @@ struct FragmentStore : public FragmentStoreI {
|
||||
FragmentStore(std::array<uint8_t, 8> session_uuid_namespace);
|
||||
|
||||
// HACK: get access to the reg
|
||||
entt::basic_handle<entt::basic_registry<FragmentID>> fragmentHandle(FragmentID fid);
|
||||
FragmentHandle fragmentHandle(FragmentID fid);
|
||||
|
||||
// TODO: make the frags ref counted
|
||||
|
||||
// TODO: check for exising
|
||||
std::vector<uint8_t> generateNewUID(std::array<uint8_t, 8>& uuid_namespace);
|
||||
std::vector<uint8_t> generateNewUID(void);
|
||||
|
||||
@@ -154,21 +78,20 @@ struct FragmentStore : public FragmentStoreI {
|
||||
);
|
||||
|
||||
// remove fragment?
|
||||
// unload?
|
||||
|
||||
// syncs fragment to file
|
||||
|
||||
// ========== sync fragment to storage ==========
|
||||
using write_to_storage_fetch_data_cb = uint64_t(uint8_t* request_buffer, uint64_t buffer_size);
|
||||
// calls data_cb with a buffer to be filled in, cb returns actual count of data. if returned < max, its the last buffer.
|
||||
bool syncToStorage(FragmentID fid, std::function<write_to_storage_fetch_data_cb>& data_cb);
|
||||
|
||||
// unload frags?
|
||||
// if frags are file backed, we can close the file if not needed
|
||||
bool syncToStorage(FragmentID fid, const uint8_t* data, const uint64_t data_size);
|
||||
|
||||
// fragment discovery?
|
||||
|
||||
private:
|
||||
void registerSerializers(void); // internal comps
|
||||
// internal actual backends
|
||||
// TODO: seperate out
|
||||
bool syncToMemory(FragmentID fid, std::function<write_to_storage_fetch_data_cb>& data_cb);
|
||||
bool syncToFile(FragmentID fid, std::function<write_to_storage_fetch_data_cb>& data_cb);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user