nicopap / cuicui_layout

The dumbest and simplest layouting algorithm for bevy
40 stars 2 forks source link

Add serialization of built-up DSLs #109

Open nicopap opened 1 year ago

nicopap commented 1 year ago

The idea is to keep and store constructed DslBundle for each Entity. To keep track of the hierarchy, we could use the child_count method, similarly to how the AST is handled, and how scenes are loaded in https://github.com/nicopap/bvyfst/tree/main/hollow_scene.

Basically, it's just pre-processing the scene file and save it as an array of the relevant DslBundle.

struct SerializedDslNode<D: SerializableDsl> {
  children_count: usize,
  dsl: D,
}

The primary use case would be obfuscation, but it has a legitimate perf concern:

  1. No need to parse the arguments to each method (using ReflectSerialize), nor run each method. The DslBundle is pre-build.
  2. No need to have each and every concerned component be Reflect or Serialize, the only thing that maters is the DslBundle type.
  3. No need to interpret the AST into a DslBundle, it is pre-built. This means: no need for loading several files, executing templates etc. Although with #94, we would probably need to have a solution for dynamic queries.
  4. Although depending on the serialization format, we might still have considerable parsing overhead. With something like rkvy or bincode, it is likely the parsing overhead is lower
  5. Running a zip compression pass is trivial and could potentially greatly reduce asset sizes
  6. Obfuscation: Preprocessing into a binary format allows delivering files that require more work than just opening with Notepad++
  7. We could eventually gate the parser/AST/interpreter behind a feature flag so that games can be shipped without it.