Przeglądaj źródła

resource: add add_requirement_glob()

Daniele Bartolini 1 rok temu
rodzic
commit
3f4a5b9cd6

+ 10 - 0
src/resource/compile_options.cpp

@@ -59,6 +59,7 @@ CompileOptions::CompileOptions(File &output
 	, _binary_writer(_file)
 	, _new_dependencies(new_dependencies)
 	, _new_requirements(new_requirements)
+	, _new_requirement_globs(default_allocator())
 	, _data_compiler(dc)
 	, _output_filesystem(output_filesystem)
 	, _data_filesystem(data_filesystem)
@@ -189,6 +190,15 @@ void CompileOptions::add_requirement(const char *type, const char *name)
 	hash_map::set(_new_requirements, path, 0u);
 }
 
+void CompileOptions::add_requirement_glob(const char *glob)
+{
+	TempAllocator256 ta;
+	DynamicString str(ta);
+	str = glob;
+
+	vector::push_back(_new_requirement_globs, str);
+}
+
 void CompileOptions::absolute_path(DynamicString &abs, const char *path)
 {
 	TempAllocator256 ta;

+ 4 - 0
src/resource/compile_options.h

@@ -28,6 +28,7 @@ struct CompileOptions
 	BinaryWriter _binary_writer;
 	HashMap<DynamicString, u32> &_new_dependencies;
 	HashMap<DynamicString, u32> &_new_requirements;
+	Vector<DynamicString> _new_requirement_globs;
 	DataCompiler &_data_compiler;
 	Filesystem &_output_filesystem;
 	Filesystem &_data_filesystem;
@@ -98,6 +99,9 @@ struct CompileOptions
 	///
 	void add_requirement(const char *type, const char *name);
 
+	/// Adds all the resources matching @a glob to the requirements.
+	void add_requirement_glob(const char *glob);
+
 	///
 	void absolute_path(DynamicString &abs, const char *path);
 

+ 14 - 0
src/resource/data_compiler.cpp

@@ -1127,6 +1127,20 @@ bool DataCompiler::compile(const char *data_dir, const char *platform_name)
 			HashMap<DynamicString, u32> requirements_deffault(default_allocator());
 			hash_map::clear(hash_map::get(_data_requirements, id, requirements_deffault));
 			hash_map::set(_data_dependencies, id, new_dependencies);
+			{
+				// Add requirements from globs.
+				auto cur = hash_map::begin(_source_index._paths);
+				auto end = hash_map::end(_source_index._paths);
+				for (; cur != end; ++cur) {
+					HASH_MAP_SKIP_HOLE(_source_index._paths, cur);
+
+					const DynamicString &path = cur->first;
+					for (u32 ii = 0, nn = vector::size(opts._new_requirement_globs); ii < nn; ++ii) {
+						if (wildcmp(opts._new_requirement_globs[ii].c_str(), path.c_str()))
+							hash_map::set(new_requirements, path, 0u);
+					}
+				}
+			}
 			hash_map::set(_data_requirements, id, new_requirements);
 
 			// Write data to disk.