summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compile-time-assert.hpp10
-rw-r--r--src/serialization-camera.cpp3
-rw-r--r--src/serialization-component.cpp3
-rw-r--r--src/serialization-font.cpp5
-rw-r--r--src/serialization-static-ui.cpp5
5 files changed, 26 insertions, 0 deletions
diff --git a/src/compile-time-assert.hpp b/src/compile-time-assert.hpp
new file mode 100644
index 0000000..bc325d7
--- /dev/null
+++ b/src/compile-time-assert.hpp
@@ -0,0 +1,10 @@
+#ifndef PKE_COMPILE_TIME_ASSERT_HPP
+#define PKE_COMPILE_TIME_ASSERT_HPP
+
+/* Compile-time assertion.
+ * Useful for detecting changes in well-known data
+ */
+template <bool b> class compt_a;
+template <> class compt_a<true>{static const bool value = true;};
+
+#endif /* PKE_COMPILE_TIME_ASSERT_HPP */
diff --git a/src/serialization-camera.cpp b/src/serialization-camera.cpp
index 92a8e81..d8593e1 100644
--- a/src/serialization-camera.cpp
+++ b/src/serialization-camera.cpp
@@ -2,6 +2,7 @@
#include "serialization-camera.hpp"
#include "camera.hpp"
+#include "compile-time-assert.hpp"
#include "pk.h"
#include "serialization-component.hpp"
#include "ecs.hpp"
@@ -56,6 +57,7 @@ pk_handle pke_serialize_camera(srlztn_serialize_helper *h, const PkeCamera *cam)
h->handle_head.itemIndex++;
pk_arr_append_t<pk_handle>(&kvec.child_handles, inst_pos_handle);
+ compt_a<128==sizeof(PkeCamera)>();
if (cam->uuid != pk_uuid_zed && cam->uuid != pk_uuid_max) {
kve.key = SRLZTN_CAMERA_UUID;
s = pk_new<char>(37, h->bkt);
@@ -126,6 +128,7 @@ void pke_deserialize_camera(srlztn_deserialize_helper *h, pke_kve_container *kve
}
}
+ compt_a<128==sizeof(PkeCamera)>();
for (i = 0; i < kvec->arr.next; ++i) {
if (strncmp(kvec->arr[i].key, SRLZTN_CAMERA_UUID, strlen(SRLZTN_CAMERA_TYPE)) == 0) {
kvec->arr[i].val >> cam.uuid;
diff --git a/src/serialization-component.cpp b/src/serialization-component.cpp
index 34d4708..dac8d35 100644
--- a/src/serialization-component.cpp
+++ b/src/serialization-component.cpp
@@ -1,6 +1,7 @@
#include "serialization-component.hpp"
+#include "compile-time-assert.hpp"
#include "ecs.hpp"
#include "entities.hpp"
#include "serialization.hpp"
@@ -169,6 +170,7 @@ pk_handle pke_serialize_instance(srlztn_serialize_helper *h, const CompInstance
}
*/
+ compt_a<128==sizeof(CompInstance)>();
if (comp->uuid != pk_uuid_zed && comp->uuid != pk_uuid_max) {
kve.key = SRLZTN_INSTANCE_COMPONENT_UUID;
s = pk_new<char>(37, h->bkt);
@@ -238,6 +240,7 @@ void pke_deserialize_instance(srlztn_deserialize_helper *h, pke_kve_container *k
glm::vec3 scale = glm::vec3(1);
comp.collisionCallback.name[0] = '\0';
+ compt_a<128==sizeof(CompInstance)>();
for (i = 0; i < kvec->children.next; ++i) {
pke_kve_container *child_kvec = kvec->children[i];
if (strncmp(child_kvec->type_code.val, SRLZTN_OBJ_INSTANCE_POSITION, strlen(SRLZTN_OBJ_INSTANCE_POSITION)) == 0) {
diff --git a/src/serialization-font.cpp b/src/serialization-font.cpp
index c0a9471..4ccc55e 100644
--- a/src/serialization-font.cpp
+++ b/src/serialization-font.cpp
@@ -1,6 +1,7 @@
#include "serialization-font.hpp"
+#include "compile-time-assert.hpp"
#include "ecs.hpp"
#include "font.hpp"
#include "pk.h"
@@ -30,6 +31,7 @@ pk_handle pke_serialize_font_render(srlztn_serialize_helper *h, FontRender *fr)
h->handle_head.itemIndex++;
pk_arr_append_t(&kvec.child_handles, font_render_settings_handle);
+ compt_a<128==sizeof(FontRender)>();
{
kve.key = SRLZTN_UI_FONT_RENDER_UUID;
s = pk_new<char>(37, h->bkt);
@@ -78,6 +80,7 @@ void pke_deserialize_font_render(srlztn_deserialize_helper *h, pke_kve_container
uint32_t i;
char *s;
+ compt_a<128==sizeof(FontRender)>();
for (i = 0; i < kvec->arr.next; ++i) {
kve = &kvec->arr[i];
if (strcmp(kve->key, SRLZTN_UI_FONT_RENDER_UUID) == 0) {
@@ -124,6 +127,7 @@ pk_handle pke_serialize_font_render_settings(srlztn_serialize_helper *h, FontRen
kvec.child_handles.bkt = h->bkt;
h->handle_head.itemIndex++;
+ compt_a<32==sizeof(FontRenderSettings)>();
{
kve.key = SRLZTN_UI_FONT_RENDER_SETTINGS_CHAR_SCALE;
len = snprintf(NULL, 0, "%f", frs->char_scale);
@@ -191,6 +195,7 @@ void pke_deserialize_font_render_settings(srlztn_deserialize_helper *h, pke_kve_
const char *starting_char;
PK_STN_RES stn_res;
char *str_end;
+ compt_a<32==sizeof(FontRenderSettings)>();
for (i = 0; i < kvec->arr.next; ++i) {
if (strncmp(kvec->arr[i].key, SRLZTN_UI_FONT_RENDER_SETTINGS_CHAR_SCALE, strlen(SRLZTN_UI_FONT_RENDER_SETTINGS_CHAR_SCALE)) == 0) {
stn_res = pk_stn(&frs->char_scale, kvec->arr[i].val, &str_end);
diff --git a/src/serialization-static-ui.cpp b/src/serialization-static-ui.cpp
index 7f15b10..e68f2ed 100644
--- a/src/serialization-static-ui.cpp
+++ b/src/serialization-static-ui.cpp
@@ -1,5 +1,6 @@
#include "serialization-static-ui.hpp"
+#include "compile-time-assert.hpp"
#include "ecs.hpp"
#include "font.hpp"
#include "pk.h"
@@ -18,6 +19,7 @@ pk_handle pke_serialize_ui_box_internal(srlztn_serialize_helper *h, pke_ui_box_t
kvec.child_handles.bkt = h->bkt;
h->handle_head.itemIndex++;
+ compt_a<4==sizeof(pke_ui_box_type_data::pke_ui_box_type_data_text)>();
{
kve.key = SRLZTN_UI_BOX_DATA_TEXT_FONT_RENDER_UUID;
s = pk_new<char>(37, h->bkt);
@@ -42,6 +44,7 @@ void pke_deserialize_ui_box_internal(srlztn_deserialize_helper *h, pke_kve_conta
assert(kvec->arr.next == 1);
pk_uuid font_render_uuid = pk_uuid_zed;
+ compt_a<4==sizeof(pke_ui_box_type_data::pke_ui_box_type_data_text)>();
if (strstr(SRLZTN_UI_BOX_DATA_TEXT_FONT_RENDER_UUID, kvec->arr[0].key)) {
kvec->arr[0].val >> font_render_uuid;
}
@@ -72,6 +75,7 @@ pk_handle pke_serialize_ui_box(srlztn_serialize_helper *h, pke_ui_box *box) {
kvec.children.bkt = h->bkt;
h->handle_head.itemIndex++;
+ compt_a<160==sizeof(pke_ui_box)>();
if (box->uuid != pk_uuid_zed && box->uuid != pk_uuid_max) {
kve.key = SRLZTN_UI_BOX_UUID;
s = pk_new<char>(37, h->bkt);
@@ -192,6 +196,7 @@ void pke_deserialize_ui_box(srlztn_deserialize_helper *h, pke_kve_container *kve
pke_ui_box *parent_box = nullptr;
bx.type_data = nullptr;
+ compt_a<160==sizeof(pke_ui_box)>();
for (i = 0; i < kvec->arr.next; ++i) {
kve = &kvec->arr[i];
if (strstr(SRLZTN_UI_BOX_UUID, kve->key)) {