Skip to content

Commit

Permalink
resource: flatten unit right after parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dbartolini committed Feb 25, 2025
1 parent c87178a commit 0c58304
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/resource/unit_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,13 +655,18 @@ namespace unit_compiler
return 0;
}

s32 flatten(UnitCompiler &c, CompileOptions &opts);

s32 parse_unit_from_json(UnitCompiler &c, const char *unit_json, CompileOptions &opts)
{
s32 err = collect_prefabs(c, StringId64(), unit_json, true, opts);
ENSURE_OR_RETURN(err == 0, opts);

u32 original_unit = c._prefab_offsets[array::size(c._prefab_offsets) - 1];
return parse_unit_internal(c, &c._prefab_data[original_unit], NULL, NULL, opts);
err = parse_unit_internal(c, &c._prefab_data[original_unit], NULL, NULL, opts);
ENSURE_OR_RETURN(err == 0, opts);

return flatten(c, opts);
}

s32 parse_unit(UnitCompiler &c, const char *path, CompileOptions &opts)
Expand Down Expand Up @@ -689,7 +694,7 @@ namespace unit_compiler
ENSURE_OR_RETURN(err == 0, opts);
}

return 0;
return flatten(c, opts);
}

s32 flatten_unit(UnitCompiler &c, Unit *unit, u32 parent_unit_index, CompileOptions &opts)
Expand Down Expand Up @@ -803,9 +808,6 @@ namespace unit_compiler
FileBuffer fb(output);
BinaryWriter bw(fb);

s32 err = flatten(c, opts);
ENSURE_OR_RETURN(err == 0, opts);

// Count component types.
u32 num_component_types = 0;
auto cur = hash_map::begin(c._component_data);
Expand Down

0 comments on commit 0c58304

Please sign in to comment.