Loading models and other complex data during flecs world deserialization #2131
-
|
Hello! Loving Flecs and its excellent documentation so far. I had a question about how to handle loading complex data when deserializing flecs worlds back into my application. I am working on a custom game engine (primarily as a learning pursuit). In it, I need to load models, configure the physics engine, etc. I think I am grasping how to serialize and deserialize basic nested structs (things like position, rotation). You need to define it with a macro like this. But for more complicated "stateful"(?) things such as models, I am loading them into memory as components and attaching them to entities. When I serialize, I don't want to serialize the model data into the json file, that'd be slow and inefficient. Instead, I'd like to serialize data that tells the engine how to re-import the model, or to find it within flecs if it's already imported. I think what I need is a deserializing "hook" for certain components, so that flecs knows how to handle them. Is this possible today? Am I thinking about the problem correctly? Another idea I just had while writing this: Maybe I could deserialize the world and then "lazy load" the models and everything else on the next frame? Any input or advice is appreciated. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
|
Take a look at hooks: https://www.flecs.dev/flecs/md_docs_2EntitiesComponents.html#hooks You might also want to take a look at flecs script, which is a more feature-rich environment for describing the contents you want to load in a world: https://www.flecs.dev/flecs/md_docs_2FlecsScript.html |
Beta Was this translation helpful? Give feedback.
Take a look at hooks: https://www.flecs.dev/flecs/md_docs_2EntitiesComponents.html#hooks
and observers: https://www.flecs.dev/flecs/md_docs_2ObserversManual.html
You might also want to take a look at flecs script, which is a more feature-rich environment for describing the contents you want to load in a world: https://www.flecs.dev/flecs/md_docs_2FlecsScript.html