Просмотр исходного кода

resource: unit with children must have a transform component

Daniele Bartolini 1 год назад
Родитель
Сommit
2340c508b6

+ 3 - 2
src/resource/level_resource.cpp

@@ -86,8 +86,9 @@ namespace level_resource_internal
 		s32 err = unit_compiler::parse_unit_array_from_json(uc, obj["units"]);
 		DATA_COMPILER_ENSURE(err == 0, opts);
 
-		Buffer units_blob = unit_compiler::blob(uc);
-		DATA_COMPILER_ENSURE(array::size(units_blob) > 0, opts);
+		Buffer units_blob(default_allocator());
+		err = unit_compiler::blob(units_blob, uc);
+		DATA_COMPILER_ENSURE(err == 0, opts);
 
 		// Write
 		LevelResource lr;

+ 12 - 4
src/resource/unit_compiler.cpp

@@ -687,6 +687,7 @@ namespace unit_compiler
 	s32 flatten_unit(UnitCompiler &c, Unit *unit, u32 parent_unit_index)
 	{
 		const u32 unit_index = c._num_units;
+		bool unit_has_transform = false;
 
 		// Compile component data for each component type found
 		// in the tree of units.
@@ -704,6 +705,9 @@ namespace unit_compiler
 				comp_type = sjson::parse_string_id(component["_type"]);
 			}
 
+			if (comp_type == STRING_ID_32("transform", UINT32_C(0xad9b5315)))
+				unit_has_transform = true;
+
 			// Append data to the component data for the given type.
 			ComponentTypeData ctd_deffault(default_allocator());
 			ComponentTypeData &ctd = const_cast<ComponentTypeData &>(hash_map::get(c._component_data, comp_type, ctd_deffault));
@@ -741,6 +745,10 @@ namespace unit_compiler
 		for (; cur != end; ++cur) {
 			HASH_MAP_SKIP_HOLE(unit->_children, cur);
 
+			DATA_COMPILER_ASSERT(unit_has_transform
+				, c._opts
+				, "Units with children must have 'transform' component"
+				);
 			s32 err = flatten_unit(c, cur->second, unit_index);
 			DATA_COMPILER_ENSURE(err == 0, c._opts);
 		}
@@ -782,13 +790,13 @@ namespace unit_compiler
 		return 0;
 	}
 
-	Buffer blob(UnitCompiler &c)
+	s32 blob(Buffer &output, UnitCompiler &c)
 	{
-		Buffer output(default_allocator());
 		FileBuffer fb(output);
 		BinaryWriter bw(fb);
 
-		flatten(c);
+		s32 err = flatten(c);
+		DATA_COMPILER_ENSURE(err == 0, c._opts);
 
 		// Count component types.
 		u32 num_component_types = 0;
@@ -844,7 +852,7 @@ namespace unit_compiler
 			bw.write(array::begin(ctd._data), array::size(ctd._data));
 		}
 
-		return output;
+		return 0;
 	}
 
 } // namespace unit_compiler

+ 1 - 1
src/resource/unit_compiler.h

@@ -89,7 +89,7 @@ namespace unit_compiler
 	s32 parse_unit_array_from_json(UnitCompiler &c, const char *units_array_json);
 
 	///
-	Buffer blob(UnitCompiler &c);
+	s32 blob(Buffer &output, UnitCompiler &c);
 
 } // namespace unit_compiler
 

+ 3 - 2
src/resource/unit_resource.cpp

@@ -21,8 +21,9 @@ namespace unit_resource_internal
 		UnitCompiler uc(default_allocator(), opts);
 		s32 err = unit_compiler::parse_unit(uc, opts.source_path());
 		DATA_COMPILER_ENSURE(err == 0, opts);
-		Buffer blob = unit_compiler::blob(uc);
-		DATA_COMPILER_ENSURE(array::size(blob) > 0, opts);
+		Buffer blob(default_allocator());
+		err = unit_compiler::blob(blob, uc);
+		DATA_COMPILER_ENSURE(err == 0, opts);
 		opts.write(blob);
 		return 0;
 	}