Giter Club home page Giter Club logo

Comments (1)

felixguendling avatar felixguendling commented on May 23, 2024

The only struct that requires custom serialization, deserialization (and hash if you want to use type hashing for versioning) is mat4 because C arrays are not supported. But I would just use cista::array<float, 16> which has exactly the same properties as a C array (inside, it is a C array) but it's supported by Cista out of the box.

With this change, there is nothing you need to do. You can just call serialize and deserialize. I made a test case from your code:

cista/test/mesh_test.cc

Lines 13 to 79 in 2855eee

struct vec3 {
float x, y, z;
};
struct mat4 {
data::array<float, 16> d;
};
struct Vertex {
vec3 position;
vec3 normal;
};
struct Mesh {
data::vector<mat4> transforms;
data::vector<Vertex> vertices;
};
using Meshes = data::vector<Mesh>;
struct Staging {
int stepIndex;
data::vector<float> distances;
data::vector<vec3> translations;
data::vector<vec3> rotations;
};
using Stagings = data::vector<Staging>;
struct Group {
Meshes meshes;
Stagings stagings;
};
TEST_CASE("mesh test") {
constexpr auto const FILENAME = "group.bin";
std::remove(FILENAME);
{
Group g;
Mesh m;
m.transforms.emplace_back(mat4{0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 0.0,
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0});
g.meshes.emplace_back(m);
cista::buf<cista::mmap> mmap{cista::mmap{FILENAME}};
cista::serialize(mmap, g);
} // EOL graph
auto b = cista::file(FILENAME, "r").content();
auto const g = cista::deserialize<Group>(b);
CHECK(g->meshes[0].transforms[0].d[0] == 0.0);
CHECK(g->meshes[0].transforms[0].d[1] == 1.0);
CHECK(g->meshes[0].transforms[0].d[2] == 2.0);
CHECK(g->meshes[0].transforms[0].d[3] == 3.0);
CHECK(g->meshes[0].transforms[0].d[4] == 4.0);
CHECK(g->meshes[0].transforms[0].d[5] == 5.0);
CHECK(g->meshes[0].transforms[0].d[6] == 6.0);
CHECK(g->meshes[0].transforms[0].d[7] == 7.0);
CHECK(g->meshes[0].transforms[0].d[8] == 0.0);
CHECK(g->meshes[0].transforms[0].d[9] == 1.0);
CHECK(g->meshes[0].transforms[0].d[10] == 2.0);
CHECK(g->meshes[0].transforms[0].d[11] == 3.0);
CHECK(g->meshes[0].transforms[0].d[12] == 4.0);
CHECK(g->meshes[0].transforms[0].d[13] == 5.0);
CHECK(g->meshes[0].transforms[0].d[14] == 6.0);
CHECK(g->meshes[0].transforms[0].d[15] == 7.0);
}

from cista.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.