summaryrefslogtreecommitdiff
path: root/src/serialization.cpp
blob: d7dd312ddc4f0f4f29e35d181d493ed1e4f57d04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

#include "serialization.hpp"
#include "serialization-component.hpp"
#include "serialization-camera.hpp"
#include "camera.hpp"
#include "ecs.hpp"

srlztn_serialize_helper *pke_serialize_init(pk_membucket *bkt) {
	srlztn_serialize_helper *helper = pk_new<srlztn_serialize_helper>(bkt);
	// TODO custom allocator
	helper->o = {};
	helper->bkt = bkt;
	return helper;
}

srlztn_deserialize_helper *pke_deserialize_init(pk_membucket *bkt) {
	srlztn_deserialize_helper *helper = pk_new<srlztn_deserialize_helper>(bkt);
	helper->bkt = bkt;
	helper->read_line = nullptr;
	// TODO custom allocator
	helper->i = {};
	helper->mapping = {bkt};
	return helper;
}

void pke_serialize_teardown(srlztn_serialize_helper *helper) {
	(void)helper;
}

void pke_deserialize_teardown(srlztn_deserialize_helper *helper) {
	(void)helper;
}

void pke_serialize_file_project(srlztn_serialize_helper *h) {
	(void)h;
}

void pke_deserialize_file_project(srlztn_deserialize_helper *h) {
	(void)h;
}

void pke_serialize_file_scene(srlztn_serialize_helper *h) {
	h->o << SRLZTN_FILE_BEGIN << std::endl;
	h->o << SRLZTN_FILE_VERSION << std::endl;
	h->o << "" << std::endl;

	pk_handle_bucket_index_T instanceBucketCount = ECS_GetInstances_BucketCount();
	for (pk_handle_bucket_index_T b = 0; b < instanceBucketCount; ++b) {
		pk_handle_item_index_T count;
		auto *instances = ECS_GetInstances(b, count);
		for (pk_handle_item_index_T i = 0; i < count; ++i) {
			const auto &instance = instances[i];
			if (instance.entHandle == EntityHandle_MAX)
				continue;
			if (instance.flags & COMPONENT_INSTANCE_FLAG_DO_NOT_SERIALIZE) {
				continue;
			}
			h->o << SRLZTN_OBJ_INSTANCE << std::endl;
			pke_serialize_instance(h, &instance);
			h->o << SRLZTN_OBJ_END << std::endl;
		}
	}

	pk_handle_bucket_index_T cameraBucketCount = PkeCamera_GetBucketCount();
	for (pk_handle_bucket_index_T b = 0; b < cameraBucketCount; ++b) {
		pk_handle_item_index_T count;
		auto *cameras = PkeCamera_GetCameras(b, count);
		for (pk_handle_item_index_T i = 0; i < count; ++i) {
			const auto &cam = cameras[i];
			if (cam.handle == CameraHandle_MAX)
				continue;
			h->o << SRLZTN_OBJ_CAMERA << std::endl;
			pke_serialize_camera(h, &cam);
			h->o << SRLZTN_OBJ_END << std::endl;
		}
	}

	h->o << SRLZTN_FILE_END << std::endl;
}
void pke_deserialize_file_scene(srlztn_deserialize_helper *h) {
	h->read_line = pk_new<char>(h->read_line_len, h->bkt);
	memset(h->read_line, '\0', h->read_line_len);

	while (h->i.getline(h->read_line, h->read_line_len)) {
		if (strcmp(SRLZTN_OBJ_INSTANCE, h->read_line) == 0) {
			pke_deserialize_instance(h);
			continue;
		}
		if (strcmp(SRLZTN_OBJ_CAMERA, h->read_line) == 0) {
			pke_deserialize_camera(h);
			continue;
		}
	}
}

void pke_serialize_file_level(srlztn_serialize_helper *h) {
	(void)h;
}
void pke_deserialize_file_level(srlztn_deserialize_helper *h) {
	(void)h;
}