Daniele Bartolini 9 anos atrás
pai
commit
2e74de8ed1

+ 16 - 16
src/resource/compile_options.h

@@ -19,26 +19,26 @@
 #include "vector.h"
 #include <setjmp.h>
 
-#define RESOURCE_COMPILER_ASSERT(condition, opts, msg, ...) \
-	do                                                      \
-	{                                                       \
-		if (!(condition))                                   \
-			opts.error(msg, ##__VA_ARGS__);                 \
+#define DATA_COMPILER_ASSERT(condition, opts, msg, ...) \
+	do                                                  \
+	{                                                   \
+		if (!(condition))                               \
+			opts.error(msg, ##__VA_ARGS__);             \
 	} while(0)
 
-#define RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(type, name, opts) \
-	RESOURCE_COMPILER_ASSERT(opts.resource_exists(type, name)      \
-		, opts                                                     \
-		, "Resource does not exist: '%s.%s'"                       \
-		, name                                                     \
-		, type                                                     \
+#define DATA_COMPILER_ASSERT_RESOURCE_EXISTS(type, name, opts) \
+	DATA_COMPILER_ASSERT(opts.resource_exists(type, name)      \
+		, opts                                                 \
+		, "Resource does not exist: '%s.%s'"                   \
+		, name                                                 \
+		, type                                                 \
 		)
 
-#define RESOURCE_COMPILER_ASSERT_FILE_EXISTS(name, opts) \
-	RESOURCE_COMPILER_ASSERT(opts.file_exists(name)      \
-		, opts                                           \
-		, "File does not exist: '%s'"                    \
-		, name                                           \
+#define DATA_COMPILER_ASSERT_FILE_EXISTS(name, opts) \
+	DATA_COMPILER_ASSERT(opts.file_exists(name)      \
+		, opts                                       \
+		, "File does not exist: '%s'"                \
+		, name                                       \
 		)
 
 namespace crown

+ 4 - 4
src/resource/config_resource.cpp

@@ -24,15 +24,15 @@ namespace config_resource_internal
 
 		const char* boot_script_json  = boot["boot_script"];
 		const char* boot_package_json = boot["boot_package"];
-		RESOURCE_COMPILER_ASSERT(boot_script_json != NULL, opts, "'boot_script' must be specified.");
-		RESOURCE_COMPILER_ASSERT(boot_package_json != NULL, opts, "'boot_package' must be specified.");
+		DATA_COMPILER_ASSERT(boot_script_json != NULL, opts, "'boot_script' must be specified.");
+		DATA_COMPILER_ASSERT(boot_package_json != NULL, opts, "'boot_package' must be specified.");
 
 		DynamicString boot_script(ta);
 		DynamicString boot_package(ta);
 		sjson::parse_string(boot_script_json, boot_script);
 		sjson::parse_string(boot_package_json, boot_package);
-		RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_SCRIPT, boot_script.c_str(), opts);
-		RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_PACKAGE, boot_package.c_str(), opts);
+		DATA_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_SCRIPT, boot_script.c_str(), opts);
+		DATA_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_PACKAGE, boot_package.c_str(), opts);
 
 		opts.write(buf);
 	}

+ 1 - 1
src/resource/lua_resource.cpp

@@ -49,7 +49,7 @@ namespace lua_resource_internal
 			NULL
 		};
 		int ec = opts.run_external_compiler(argv, output);
-		RESOURCE_COMPILER_ASSERT(ec == 0
+		DATA_COMPILER_ASSERT(ec == 0
 			, opts
 			, "Failed to compile lua:\n%s"
 			, string_stream::c_str(output)

+ 2 - 2
src/resource/material_resource.cpp

@@ -86,7 +86,7 @@ namespace material_resource_internal
 
 			DynamicString texture(ta);
 			sjson::parse_string(value, texture);
-			RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_TEXTURE, texture.c_str(), opts);
+			DATA_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_TEXTURE, texture.c_str(), opts);
 
 			TextureHandle th;
 			th.sampler_handle = 0;
@@ -129,7 +129,7 @@ namespace material_resource_internal
 			sjson::parse_string(uniform["type"], type);
 
 			const UniformType::Enum ut = name_to_uniform_type(type.c_str());
-			RESOURCE_COMPILER_ASSERT(ut != UniformType::COUNT
+			DATA_COMPILER_ASSERT(ut != UniformType::COUNT
 				, opts
 				, "Unknown uniform type: '%s'"
 				, type.c_str()

+ 1 - 1
src/resource/package_resource.cpp

@@ -29,7 +29,7 @@ namespace package_resource_internal
 			DynamicString name(ta);
 			sjson::parse_string(names[i], name);
 
-			RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(type, name.c_str(), opts);
+			DATA_COMPILER_ASSERT_RESOURCE_EXISTS(type, name.c_str(), opts);
 
 			const StringId64 nameh = sjson::parse_resource_id(names[i]);
 			array::push_back(output, PackageResource::Resource(typeh, nameh));

+ 8 - 8
src/resource/physics_resource.cpp

@@ -130,7 +130,7 @@ namespace physics_resource_internal
 		sjson::parse_string(obj["shape"], type);
 
 		ColliderType::Enum st = shape_type_to_enum(type.c_str());
-		RESOURCE_COMPILER_ASSERT(st != ColliderType::COUNT
+		DATA_COMPILER_ASSERT(st != ColliderType::COUNT
 			, opts
 			, "Unknown shape type: '%s'"
 			, type.c_str()
@@ -148,7 +148,7 @@ namespace physics_resource_internal
 		DynamicString name(ta);
 		sjson::parse_string(obj["scene"], scene);
 		sjson::parse_string(obj["name"], name);
-		RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_MESH, scene.c_str(), opts);
+		DATA_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_MESH, scene.c_str(), opts);
 		scene += "." RESOURCE_EXTENSION_MESH;
 
 		Buffer file = opts.read(scene.c_str());
@@ -159,14 +159,14 @@ namespace physics_resource_internal
 		JsonObject node(ta);
 		sjson::parse(file, json_mesh);
 		sjson::parse(json_mesh["geometries"], geometries);
-		RESOURCE_COMPILER_ASSERT(json_object::has(geometries, name.c_str())
+		DATA_COMPILER_ASSERT(json_object::has(geometries, name.c_str())
 			, opts
 			, "Geometry '%s' does not exist"
 			, name.c_str()
 			);
 		sjson::parse(geometries[name.c_str()], geometry);
 		sjson::parse(json_mesh["nodes"], nodes);
-		RESOURCE_COMPILER_ASSERT(json_object::has(nodes, name.c_str())
+		DATA_COMPILER_ASSERT(json_object::has(nodes, name.c_str())
 			, opts
 			, "Node '%s' does not exist"
 			, name.c_str()
@@ -211,7 +211,7 @@ namespace physics_resource_internal
 		case ColliderType::CONVEX_HULL: break;
 		case ColliderType::MESH:        break;
 		case ColliderType::HEIGHTFIELD:
-			RESOURCE_COMPILER_ASSERT(false, opts, "Not implemented yet");
+			DATA_COMPILER_ASSERT(false, opts, "Not implemented yet");
 			break;
 		}
 
@@ -275,7 +275,7 @@ namespace physics_resource_internal
 		sjson::parse_string(obj["type"], type);
 
 		JointType::Enum jt = joint_type_to_enum(type.c_str());
-		RESOURCE_COMPILER_ASSERT(jt != JointType::COUNT
+		DATA_COMPILER_ASSERT(jt != JointType::COUNT
 			, opts
 			, "Unknown joint type: '%s'"
 			, type.c_str()
@@ -477,7 +477,7 @@ namespace physics_config_resource_internal
 
 		u32 new_filter_mask()
 		{
-			RESOURCE_COMPILER_ASSERT(_filter != 0x80000000u
+			DATA_COMPILER_ASSERT(_filter != 0x80000000u
 				, _opts
 				, "Too many collision filters"
 				);
@@ -489,7 +489,7 @@ namespace physics_config_resource_internal
 
 		u32 filter_to_mask(StringId32 filter)
 		{
-			RESOURCE_COMPILER_ASSERT(map::has(_filter_map, filter)
+			DATA_COMPILER_ASSERT(map::has(_filter_map, filter)
 				, _opts
 				, "Filter not found"
 				);

+ 22 - 22
src/resource/shader_resource.cpp

@@ -749,7 +749,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["depth_func"], depth_func);
 					rs._depth_func = name_to_depth_func(depth_func.c_str());
-					RESOURCE_COMPILER_ASSERT(rs._depth_func != DepthFunction::COUNT
+					DATA_COMPILER_ASSERT(rs._depth_func != DepthFunction::COUNT
 						, _opts
 						, "Unknown depth test: '%s'"
 						, depth_func.c_str()
@@ -760,7 +760,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["blend_src"], blend_src);
 					rs._blend_src = name_to_blend_function(blend_src.c_str());
-					RESOURCE_COMPILER_ASSERT(rs._blend_src != BlendFunction::COUNT
+					DATA_COMPILER_ASSERT(rs._blend_src != BlendFunction::COUNT
 						, _opts
 						, "Unknown blend function: '%s'"
 						, blend_src.c_str()
@@ -771,7 +771,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["blend_dst"], blend_dst);
 					rs._blend_dst = name_to_blend_function(blend_dst.c_str());
-					RESOURCE_COMPILER_ASSERT(rs._blend_dst != BlendFunction::COUNT
+					DATA_COMPILER_ASSERT(rs._blend_dst != BlendFunction::COUNT
 						, _opts
 						, "Unknown blend function: '%s'"
 						, blend_dst.c_str()
@@ -782,7 +782,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["blend_equation"], blend_equation);
 					rs._blend_equation = name_to_blend_equation(blend_equation.c_str());
-					RESOURCE_COMPILER_ASSERT(rs._blend_equation != BlendEquation::COUNT
+					DATA_COMPILER_ASSERT(rs._blend_equation != BlendEquation::COUNT
 						, _opts
 						, "Unknown blend equation: '%s'"
 						, blend_equation.c_str()
@@ -793,7 +793,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["cull_mode"], cull_mode);
 					rs._cull_mode = name_to_cull_mode(cull_mode.c_str());
-					RESOURCE_COMPILER_ASSERT(rs._cull_mode != CullMode::COUNT
+					DATA_COMPILER_ASSERT(rs._cull_mode != CullMode::COUNT
 						, _opts
 						, "Unknown cull mode: '%s'"
 						, cull_mode.c_str()
@@ -804,7 +804,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["primitive_type"], primitive_type);
 					rs._primitive_type = name_to_primitive_type(primitive_type.c_str());
-					RESOURCE_COMPILER_ASSERT(rs._primitive_type != PrimitiveType::COUNT
+					DATA_COMPILER_ASSERT(rs._primitive_type != PrimitiveType::COUNT
 						, _opts
 						, "Unknown primitive type: '%s'"
 						, primitive_type.c_str()
@@ -814,7 +814,7 @@ namespace shader_resource_internal
 				DynamicString key(ta);
 				key = begin->pair.first;
 
-				RESOURCE_COMPILER_ASSERT(!map::has(_render_states, key)
+				DATA_COMPILER_ASSERT(!map::has(_render_states, key)
 					, _opts
 					, "Render state redefined: '%s'"
 					, key.c_str()
@@ -855,7 +855,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["filter_min"], filter_min);
 					ss._filter_min = name_to_sampler_filter(filter_min.c_str());
-					RESOURCE_COMPILER_ASSERT(ss._filter_min != SamplerFilter::COUNT
+					DATA_COMPILER_ASSERT(ss._filter_min != SamplerFilter::COUNT
 						, _opts
 						, "Unknown sampler filter: '%s'"
 						, filter_min.c_str()
@@ -866,7 +866,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["filter_mag"], filter_mag);
 					ss._filter_mag = name_to_sampler_filter(filter_mag.c_str());
-					RESOURCE_COMPILER_ASSERT(ss._filter_mag != SamplerFilter::COUNT
+					DATA_COMPILER_ASSERT(ss._filter_mag != SamplerFilter::COUNT
 						, _opts
 						, "Unknown sampler filter: '%s'"
 						, filter_mag.c_str()
@@ -877,7 +877,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["wrap_u"], wrap_u);
 					ss._wrap_u = name_to_sampler_wrap(wrap_u.c_str());
-					RESOURCE_COMPILER_ASSERT(ss._wrap_u != SamplerWrap::COUNT
+					DATA_COMPILER_ASSERT(ss._wrap_u != SamplerWrap::COUNT
 						, _opts
 						, "Unknown wrap mode: '%s'"
 						, wrap_u.c_str()
@@ -888,7 +888,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["wrap_v"], wrap_v);
 					ss._wrap_v = name_to_sampler_wrap(wrap_v.c_str());
-					RESOURCE_COMPILER_ASSERT(ss._wrap_v != SamplerWrap::COUNT
+					DATA_COMPILER_ASSERT(ss._wrap_v != SamplerWrap::COUNT
 						, _opts
 						, "Unknown wrap mode: '%s'"
 						, wrap_v.c_str()
@@ -899,7 +899,7 @@ namespace shader_resource_internal
 				{
 					sjson::parse_string(obj["wrap_w"], wrap_w);
 					ss._wrap_w = name_to_sampler_wrap(wrap_w.c_str());
-					RESOURCE_COMPILER_ASSERT(ss._wrap_w != SamplerWrap::COUNT
+					DATA_COMPILER_ASSERT(ss._wrap_w != SamplerWrap::COUNT
 						, _opts
 						, "Unknown wrap mode: '%s'"
 						, wrap_w.c_str()
@@ -909,7 +909,7 @@ namespace shader_resource_internal
 				DynamicString key(ta);
 				key = begin->pair.first;
 
-				RESOURCE_COMPILER_ASSERT(!map::has(_sampler_states, key)
+				DATA_COMPILER_ASSERT(!map::has(_sampler_states, key)
 					, _opts
 					, "Sampler state redefined: '%s'"
 					, key.c_str()
@@ -952,7 +952,7 @@ namespace shader_resource_internal
 				DynamicString key(ta);
 				key = begin->pair.first;
 
-				RESOURCE_COMPILER_ASSERT(!map::has(_bgfx_shaders, key)
+				DATA_COMPILER_ASSERT(!map::has(_bgfx_shaders, key)
 					, _opts
 					, "Bgfx shader redefined: '%s'"
 					, key.c_str()
@@ -977,7 +977,7 @@ namespace shader_resource_internal
 				DynamicString sampler_state(ta);
 				sjson::parse_string(sampler["sampler_state"], sampler_state);
 
-				RESOURCE_COMPILER_ASSERT(map::has(_sampler_states, sampler_state)
+				DATA_COMPILER_ASSERT(map::has(_sampler_states, sampler_state)
 					, _opts
 					, "Unknown sampler state: '%s'"
 					, sampler_state.c_str()
@@ -986,7 +986,7 @@ namespace shader_resource_internal
 				DynamicString key(ta);
 				key = begin->pair.first;
 
-				RESOURCE_COMPILER_ASSERT(!map::has(bgfxshader._samplers, key)
+				DATA_COMPILER_ASSERT(!map::has(bgfxshader._samplers, key)
 					, _opts
 					, "Bgfx sampler redefined: '%s'"
 					, key.c_str()
@@ -1015,7 +1015,7 @@ namespace shader_resource_internal
 				DynamicString key(ta);
 				key = begin->pair.first;
 
-				RESOURCE_COMPILER_ASSERT(!map::has(_shaders, key)
+				DATA_COMPILER_ASSERT(!map::has(_shaders, key)
 					, _opts
 					, "Shader redefined: '%s'"
 					, key.c_str()
@@ -1096,7 +1096,7 @@ namespace shader_resource_internal
 				}
 				const StringId32 shader_name(str.c_str());
 
-				RESOURCE_COMPILER_ASSERT(map::has(_shaders, sc._shader)
+				DATA_COMPILER_ASSERT(map::has(_shaders, sc._shader)
 					, _opts
 					, "Unknown shader: '%s'"
 					, shader.c_str()
@@ -1105,12 +1105,12 @@ namespace shader_resource_internal
 				const DynamicString& bgfx_shader  = sp._bgfx_shader;
 				const DynamicString& render_state = sp._render_state;
 
-				RESOURCE_COMPILER_ASSERT(map::has(_bgfx_shaders, sp._bgfx_shader)
+				DATA_COMPILER_ASSERT(map::has(_bgfx_shaders, sp._bgfx_shader)
 					, _opts
 					, "Unknown bgfx shader: '%s'"
 					, bgfx_shader.c_str()
 					);
-				RESOURCE_COMPILER_ASSERT(map::has(_render_states, sp._render_state)
+				DATA_COMPILER_ASSERT(map::has(_render_states, sp._render_state)
 					, _opts
 					, "Unknown render state: '%s'"
 					, render_state.c_str()
@@ -1196,7 +1196,7 @@ namespace shader_resource_internal
 			if (ec)
 			{
 				delete_temp_files();
-				RESOURCE_COMPILER_ASSERT(false
+				DATA_COMPILER_ASSERT(false
 					, _opts
 					, "Failed to compile vertex shader:\n%s"
 					, string_stream::c_str(output)
@@ -1214,7 +1214,7 @@ namespace shader_resource_internal
 			if (ec)
 			{
 				delete_temp_files();
-				RESOURCE_COMPILER_ASSERT(false
+				DATA_COMPILER_ASSERT(false
 					, _opts
 					, "Failed to compile fragment shader:\n%s"
 					, string_stream::c_str(output)

+ 2 - 2
src/resource/texture_resource.cpp

@@ -45,7 +45,7 @@ namespace texture_resource_internal
 
 		DynamicString name(ta);
 		sjson::parse_string(object["source"], name);
-		RESOURCE_COMPILER_ASSERT_FILE_EXISTS(name.c_str(), opts);
+		DATA_COMPILER_ASSERT_FILE_EXISTS(name.c_str(), opts);
 
 		const bool generate_mips = sjson::parse_bool(object["generate_mips"]);
 		const bool is_normalmap  = sjson::parse_bool(object["is_normalmap"]);
@@ -69,7 +69,7 @@ namespace texture_resource_internal
 
 		StringStream output(ta);
 		int ec = opts.run_external_compiler(argv, output);
-		RESOURCE_COMPILER_ASSERT(ec == 0
+		DATA_COMPILER_ASSERT(ec == 0
 			, opts
 			, "Failed to compile texture:\n%s"
 			, string_stream::c_str(output)

+ 7 - 7
src/resource/unit_compiler.cpp

@@ -93,7 +93,7 @@ static Buffer compile_camera(const char* json, CompileOptions& opts)
 	sjson::parse_string(obj["projection"], type);
 
 	ProjectionType::Enum pt = projection_name_to_enum(type.c_str());
-	RESOURCE_COMPILER_ASSERT(pt != ProjectionType::COUNT
+	DATA_COMPILER_ASSERT(pt != ProjectionType::COUNT
 		, opts
 		, "Unknown projection type: '%s'"
 		, type.c_str()
@@ -118,7 +118,7 @@ static Buffer compile_mesh_renderer(const char* json, CompileOptions& opts)
 
 	DynamicString mesh_resource(ta);
 	sjson::parse_string(obj["mesh_resource"], mesh_resource);
-	RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_MESH
+	DATA_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_MESH
 		, mesh_resource.c_str()
 		, opts
 		);
@@ -142,7 +142,7 @@ static Buffer compile_sprite_renderer(const char* json, CompileOptions& opts)
 
 	DynamicString sprite_resource(ta);
 	sjson::parse_string(obj["sprite_resource"], sprite_resource);
-	RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_SPRITE
+	DATA_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_SPRITE
 		, sprite_resource.c_str()
 		, opts
 		);
@@ -167,7 +167,7 @@ static Buffer compile_light(const char* json, CompileOptions& opts)
 	sjson::parse_string(obj["type"], type);
 
 	LightType::Enum lt = light_name_to_enum(type.c_str());
-	RESOURCE_COMPILER_ASSERT(lt != LightType::COUNT
+	DATA_COMPILER_ASSERT(lt != LightType::COUNT
 		, opts
 		, "Unknown light type: '%s'"
 		, type.c_str()
@@ -193,7 +193,7 @@ static Buffer compile_script(const char* json, CompileOptions& opts)
 
 	DynamicString script_resource(ta);
 	sjson::parse_string(obj["script_resource"], script_resource);
-	RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_SCRIPT
+	DATA_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_SCRIPT
 		, script_resource.c_str()
 		, opts
 		);
@@ -257,7 +257,7 @@ void UnitCompiler::compile_unit_from_json(const char* json)
 		TempAllocator512 ta;
 		DynamicString path(ta);
 		sjson::parse_string(prefab["prefab"], path);
-		RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_UNIT
+		DATA_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_UNIT
 			, path.c_str()
 			, _opts
 			);
@@ -415,7 +415,7 @@ void UnitCompiler::register_component_compiler(StringId32 type, CompileFunction
 
 Buffer UnitCompiler::compile_component(StringId32 type, const char* json)
 {
-	RESOURCE_COMPILER_ASSERT(sort_map::has(_component_data, type), _opts, "Unknown component");
+	DATA_COMPILER_ASSERT(sort_map::has(_component_data, type), _opts, "Unknown component");
 
 	return sort_map::get(_component_data, type, ComponentTypeData(default_allocator()))._compiler(json, _opts);
 }