Browse Source

update serialize code, remove garbage template nonsense

master
Nick Hayashi 1 year ago
parent
commit
8371c364a7
  1. 41
      serialize.cpp
  2. 24
      serialize.h
  3. 13
      ule.h

41
serialize.cpp

@ -34,13 +34,13 @@ static inline const char* getFormatStringOut(char* v) { ULE_TYPES_H_FTAG;
static inline const char* getFormatStringOut(const char* v) { ULE_TYPES_H_FTAG; return "\"%s\"\n"; }
#ifdef ULE_CONFIG_OPTION_USE_GLM
static inline const char* getFormatStringOut(glm::vec<2, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f\n"; }
static inline const char* getFormatStringOut(glm::vec<3, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f\n"; }
static inline const char* getFormatStringOut(glm::vec<4, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f %f\n"; }
static inline const char* getFormatStringOut(glm::vec2 v) { ULE_TYPES_H_FTAG; return "%f %f\n"; }
static inline const char* getFormatStringOut(glm::vec3 v) { ULE_TYPES_H_FTAG; return "%f %f %f\n"; }
static inline const char* getFormatStringOut(glm::vec4 v) { ULE_TYPES_H_FTAG; return "%f %f %f %f\n"; }
static inline const char* getFormatStringOut(glm::mat<2, 2, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f %f\n"; }
static inline const char* getFormatStringOut(glm::mat<3, 3, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f %f %f %f %f %f %f\n"; }
static inline const char* getFormatStringOut(glm::mat<4, 4, float, (glm::qualifier) 3> v) { ULE_TYPES_H_FTAG; return "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n"; }
static inline const char* getFormatStringOut(glm::mat2 v) { ULE_TYPES_H_FTAG; return "%f %f %f %f\n"; }
static inline const char* getFormatStringOut(glm::mat3 v) { ULE_TYPES_H_FTAG; return "%f %f %f %f %f %f %f %f %f\n"; }
static inline const char* getFormatStringOut(glm::mat4 v) { ULE_TYPES_H_FTAG; return "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n"; }
#endif
#define SERIALIZE_H_FUNC_BODY str->appendf(getFormatStringOut(v), v);
@ -231,37 +231,33 @@ void deserialize(char** buffer, const char** v) {
}
#ifdef ULE_CONFIG_OPTION_USE_GLM
// I have no fucking idea why, but the declarations of glm types here resolve to a type,
// that has a template parameter == 0, but all other instances of those types in my program
// have that template parameter == 3, so everything below becomes unresolved symbols if
// I don't do the nasty template garbage here
void serialize(String* str, glm::vec<2, float, (glm::qualifier) (glm::qualifier) 3> v) {
void serialize(String* str, glm::vec2 v) {
ULE_TYPES_H_FTAG;
str->appendf(getFormatStringOut(v), v[0], v[1]);
}
void serialize(String* str, glm::vec<3, float, (glm::qualifier) (glm::qualifier) 3> v) {
void serialize(String* str, glm::vec3 v) {
ULE_TYPES_H_FTAG;
str->appendf(getFormatStringOut(v), v[0], v[1], v[2]);
}
void serialize(String* str, glm::vec<4, float, (glm::qualifier) 3> v) {
void serialize(String* str, glm::vec4 v) {
ULE_TYPES_H_FTAG;
str->appendf(getFormatStringOut(v), v[0], v[1], v[2], v[3]);
}
void serialize(String* str, glm::mat<2, 2, float, (glm::qualifier) 3> v) {
void serialize(String* str, glm::mat2 v) {
ULE_TYPES_H_FTAG;
str->appendf(getFormatStringOut(v)
, v[0][0], v[0][1]
, v[1][0], v[1][1]);
}
void serialize(String* str, glm::mat<3, 3, float, (glm::qualifier) 3> v) {
void serialize(String* str, glm::mat3 v) {
ULE_TYPES_H_FTAG;
str->appendf(getFormatStringOut(v)
, v[0][0], v[0][1], v[0][2]
, v[1][0], v[1][1], v[1][2]
, v[2][0], v[2][1], v[2][2]);
}
void serialize(String* str, glm::mat<4, 4, float, (glm::qualifier) 3> v) {
void serialize(String* str, glm::mat4 v) {
ULE_TYPES_H_FTAG;
str->appendf(getFormatStringOut(v)
, v[0][0], v[0][1], v[0][2], v[0][3]
@ -270,21 +266,21 @@ void serialize(String* str, glm::mat<4, 4, float, (glm::qualifier) 3> v) {
, v[3][0], v[3][1], v[3][2], v[3][3]);
}
void deserialize(char** buffer, glm::vec<2, float, (glm::qualifier) 3>* v) {
void deserialize(char** buffer, glm::vec2* v) {
ULE_TYPES_H_FTAG;
float* _v = (float*) v;
for (u32 i = 0; i < 2; i++) {
deserialize(buffer, _v + i);
}
}
void deserialize(char** buffer, glm::vec<3, float, (glm::qualifier) 3>* v) {
void deserialize(char** buffer, glm::vec3* v) {
ULE_TYPES_H_FTAG;
float* _v = (float*) v;
for (u32 i = 0; i < 3; i++) {
deserialize(buffer, _v + i);
}
}
void deserialize(char** buffer, glm::vec<4, float, (glm::qualifier) 3>* v) {
void deserialize(char** buffer, glm::vec4* v) {
ULE_TYPES_H_FTAG;
float* _v = (float*) v;
for (u32 i = 0; i < 4; i++) {
@ -292,21 +288,21 @@ void deserialize(char** buffer, glm::vec<4, float, (glm::qualifier) 3>* v) {
}
}
void deserialize(char** buffer, glm::mat<2, 2, float, (glm::qualifier) 3>* v) {
void deserialize(char** buffer, glm::mat2* v) {
ULE_TYPES_H_FTAG;
float* m = (float*) v;
for (u32 i = 0; i < 4; i++) {
deserialize(buffer, m + i);
}
}
void deserialize(char** buffer, glm::mat<3, 3, float, (glm::qualifier) 3>* v) {
void deserialize(char** buffer, glm::mat3* v) {
ULE_TYPES_H_FTAG;
float* m = (float*) v;
for (u32 i = 0; i < 9; i++) {
deserialize(buffer, m + i);
}
}
void deserialize(char** buffer, glm::mat<4, 4, float, (glm::qualifier) 3>* v) {
void deserialize(char** buffer, glm::mat4* v) {
ULE_TYPES_H_FTAG;
float* m = (float*) v;
for (u32 i = 0; i < 16; i++) {
@ -320,4 +316,3 @@ void deserialize(char** buffer, glm::mat<4, 4, float, (glm::qualifier) 3>* v) {
#endif

24
serialize.h

@ -191,21 +191,21 @@ extern void deserialize(char** buffer, size_t* v);
#endif
#ifdef ULE_CONFIG_OPTION_USE_GLM
extern void serialize(String* str, glm::vec<2, float, (glm::qualifier) 3> v);
extern void serialize(String* str, glm::vec<3, float, (glm::qualifier) 3> v);
extern void serialize(String* str, glm::vec<4, float, (glm::qualifier) 3> v);
extern void serialize(String* str, glm::vec2 v);
extern void serialize(String* str, glm::vec3 v);
extern void serialize(String* str, glm::vec4 v);
extern void serialize(String* str, glm::mat<2, 2, float, (glm::qualifier) 3> v);
extern void serialize(String* str, glm::mat<3, 3, float, (glm::qualifier) 3> v);
extern void serialize(String* str, glm::mat<4, 4, float, (glm::qualifier) 3> v);
extern void serialize(String* str, glm::mat2 v);
extern void serialize(String* str, glm::mat3 v);
extern void serialize(String* str, glm::mat4 v);
extern void deserialize(char** buffer, glm::vec<2, float, (glm::qualifier) 3>* v);
extern void deserialize(char** buffer, glm::vec<3, float, (glm::qualifier) 3>* v);
extern void deserialize(char** buffer, glm::vec<4, float, (glm::qualifier) 3>* v);
extern void deserialize(char** buffer, glm::vec2* v);
extern void deserialize(char** buffer, glm::vec3* v);
extern void deserialize(char** buffer, glm::vec4* v);
extern void deserialize(char** buffer, glm::mat<2, 2, float, (glm::qualifier) 3>* v);
extern void deserialize(char** buffer, glm::mat<3, 3, float, (glm::qualifier) 3>* v);
extern void deserialize(char** buffer, glm::mat<4, 4, float, (glm::qualifier) 3>* v);
extern void deserialize(char** buffer, glm::mat2* v);
extern void deserialize(char** buffer, glm::mat3* v);
extern void deserialize(char** buffer, glm::mat4* v);
#endif
#endif

13
ule.h

@ -0,0 +1,13 @@
#pragma once
#ifndef ULE_H
#define ULE_H
#endif
Loading…
Cancel
Save